AST.cpp 91.9 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6 7 8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25 26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
27
**
28
**************************************************************************/
con's avatar
con committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include "AST.h"
#include "ASTVisitor.h"
#include "MemoryPool.h"

#include <cassert>
#include <cstddef>
#include <algorithm>

CPLUSPLUS_BEGIN_NAMESPACE

AST::AST()
{ }

AST::~AST()
{ assert(0); }

void AST::accept(ASTVisitor *visitor)
{
    if (visitor->preVisit(this))
        accept0(visitor);
    visitor->postVisit(this);
}

unsigned AttributeSpecifierAST::firstToken() const
{
    return attribute_token;
}

unsigned AttributeSpecifierAST::lastToken() const
{
    if (second_rparen_token)
        return second_rparen_token + 1;
    else if (first_rparen_token)
        return first_rparen_token + 1;
    else if (attributes)
        return attributes->lastToken();
85 86 87 88 89
    else if (second_lparen_token)
        return second_lparen_token + 1;
    else if (first_lparen_token)
        return first_lparen_token + 1;
    return attribute_token + 1;
con's avatar
con committed
90 91
}

92 93 94 95 96 97 98 99 100 101 102 103 104
AttributeSpecifierAST *AttributeSpecifierAST::clone(MemoryPool *pool) const
{
    AttributeSpecifierAST *ast = new (pool) AttributeSpecifierAST;
    ast->attribute_token = attribute_token;
    ast->first_lparen_token = first_lparen_token;
    ast->second_lparen_token = second_lparen_token;
    if (attributes)
        ast->attributes = attributes->clone(pool);
    ast->first_rparen_token = first_rparen_token;
    ast->second_rparen_token = second_rparen_token;
    return ast;
}

con's avatar
con committed
105 106 107 108 109 110
void AttributeSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (AttributeAST *attr = attributes; attr; attr = attr->next)
            accept(attr, visitor);
    }
111
    visitor->endVisit(this);
con's avatar
con committed
112 113 114 115 116 117 118 119 120
}

unsigned AttributeAST::firstToken() const
{
    return identifier_token;
}

unsigned AttributeAST::lastToken() const
{
121 122 123 124 125 126 127 128 129 130 131
    if (rparen_token)
        return rparen_token + 1;

    for (ExpressionListAST *it = expression_list;
            it->expression && it->next; it = it->next) {
        if (! it->next && it->expression) {
            return it->expression->lastToken();
        }
    }

    if (tag_token)
con's avatar
con committed
132
        return tag_token + 1;
133 134 135 136

    if (lparen_token)
        return lparen_token + 1;

con's avatar
con committed
137 138 139
    return identifier_token + 1;
}

140 141 142 143 144 145 146 147 148 149 150 151 152 153
AttributeAST *AttributeAST::clone(MemoryPool *pool) const
{
    AttributeAST *ast = new (pool) AttributeAST;
    ast->identifier_token = identifier_token;
    ast->lparen_token = lparen_token;
    ast->tag_token = tag_token;
    if (expression_list)
        ast->expression_list = expression_list->clone(pool);
    ast->rparen_token = rparen_token;
    if (next)
        ast->next = next->clone(pool);
    return ast;
}

con's avatar
con committed
154 155 156 157 158 159
void AttributeAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (ExpressionListAST *it = expression_list; it; it = it->next)
            accept(it->expression, visitor);
    }
160
    visitor->endVisit(this);
con's avatar
con committed
161 162
}

163 164 165 166 167 168 169 170 171
AccessDeclarationAST *AccessDeclarationAST::clone(MemoryPool *pool) const
{
    AccessDeclarationAST *ast = new (pool) AccessDeclarationAST;
    ast->access_specifier_token = access_specifier_token;
    ast->slots_token = slots_token;
    ast->colon_token = colon_token;
    return ast;
}

con's avatar
con committed
172 173 174 175
void AccessDeclarationAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
176
    visitor->endVisit(this);
con's avatar
con committed
177 178 179 180 181 182 183 184 185
}

unsigned AccessDeclarationAST::firstToken() const
{
    return access_specifier_token;
}

unsigned AccessDeclarationAST::lastToken() const
{
186 187 188 189 190
    if (colon_token)
        return colon_token + 1;
    else if (slots_token)
        return slots_token + 1;
    return access_specifier_token + 1;
con's avatar
con committed
191 192
}

193 194 195 196 197 198 199 200 201 202
ArrayAccessAST *ArrayAccessAST::clone(MemoryPool *pool) const
{
    ArrayAccessAST *ast = new (pool) ArrayAccessAST;
    ast->lbracket_token = lbracket_token;
    if (expression)
        ast->expression = expression->clone(pool);
    ast->rbracket_token = rbracket_token;
    return ast;
}

con's avatar
con committed
203 204 205 206 207
void ArrayAccessAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
208
    visitor->endVisit(this);
con's avatar
con committed
209 210 211 212 213 214 215 216 217
}

unsigned ArrayAccessAST::firstToken() const
{
    return lbracket_token;
}

unsigned ArrayAccessAST::lastToken() const
{
218 219 220 221 222
    if (rbracket_token)
        return rbracket_token + 1;
    else if (expression)
        return expression->lastToken();
    return lbracket_token + 1;
con's avatar
con committed
223 224
}

225 226 227 228 229 230 231 232 233 234
ArrayDeclaratorAST *ArrayDeclaratorAST::clone(MemoryPool *pool) const
{
    ArrayDeclaratorAST *ast = new (pool) ArrayDeclaratorAST;
    ast->lbracket_token = lbracket_token;
    if (expression)
        ast->expression = expression->clone(pool);
    ast->rbracket_token = rbracket_token;
    return ast;
}

con's avatar
con committed
235 236 237 238 239
void ArrayDeclaratorAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(this->expression, visitor);
    }
240
    visitor->endVisit(this);
con's avatar
con committed
241 242 243 244 245 246 247 248 249
}

unsigned ArrayDeclaratorAST::firstToken() const
{
    return lbracket_token;
}

unsigned ArrayDeclaratorAST::lastToken() const
{
250 251 252 253 254
    if (rbracket_token)
        return rbracket_token + 1;
    else if (expression)
        return expression->lastToken();
    return lbracket_token + 1;
con's avatar
con committed
255 256
}

257 258 259 260 261 262 263 264 265 266
ArrayInitializerAST *ArrayInitializerAST::clone(MemoryPool *pool) const
{
    ArrayInitializerAST *ast = new (pool) ArrayInitializerAST;
    ast->lbrace_token = lbrace_token;
    if (expression_list)
        ast->expression_list = expression_list->clone(pool);
    ast->rbrace_token = rbrace_token;
    return ast;
}

con's avatar
con committed
267 268 269
void ArrayInitializerAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
270
        for (ExpressionListAST *expr = expression_list; expr; expr = expr->next)
con's avatar
con committed
271 272
            accept(expr->expression, visitor);
    }
273
    visitor->endVisit(this);
con's avatar
con committed
274 275 276 277 278 279 280 281 282
}

unsigned ArrayInitializerAST::firstToken() const
{
    return lbrace_token;
}

unsigned ArrayInitializerAST::lastToken() const
{
283 284 285 286 287 288 289 290 291
    if (rbrace_token)
        return rbrace_token + 1;

    for (ExpressionListAST *it = expression_list; it; it = it->next) {
        if (! it->next && it->expression)
            return it->expression->lastToken();
    }

    return lbrace_token + 1;
con's avatar
con committed
292 293
}

294 295 296 297
AsmDefinitionAST *AsmDefinitionAST::clone(MemoryPool *pool) const
{
    AsmDefinitionAST *ast = new (pool) AsmDefinitionAST;
    ast->asm_token = asm_token;
298
    ast->volatile_token = volatile_token;
299 300 301 302 303 304
    ast->lparen_token = lparen_token;
    ast->rparen_token = rparen_token;
    ast->semicolon_token = semicolon_token;
    return ast;
}

con's avatar
con committed
305 306 307
void AsmDefinitionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
308
        // ### accept the asm operand list.
con's avatar
con committed
309
    }
310
    visitor->endVisit(this);
con's avatar
con committed
311 312 313 314 315 316 317 318 319
}

unsigned AsmDefinitionAST::firstToken() const
{
    return asm_token;
}

unsigned AsmDefinitionAST::lastToken() const
{
320 321 322 323 324 325
    if (semicolon_token)
        return semicolon_token + 1;
    else if (rparen_token)
        return rparen_token + 1;
    else if (lparen_token)
        return lparen_token + 1;
326 327
    else if (volatile_token)
        return volatile_token + 1;
328
    return asm_token + 1;
con's avatar
con committed
329 330
}

331 332 333 334 335 336 337 338 339 340 341 342
BaseSpecifierAST *BaseSpecifierAST::clone(MemoryPool *pool) const
{
    BaseSpecifierAST *ast = new (pool) BaseSpecifierAST;
    ast->token_virtual = token_virtual;
    ast->token_access_specifier = token_access_specifier;
    if (name)
        ast->name = name->clone(pool);
    if (next)
        ast->next = next->clone(pool);
    return ast;
}

con's avatar
con committed
343 344 345 346 347
void BaseSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
    }
348
    visitor->endVisit(this);
con's avatar
con committed
349 350 351 352 353 354 355 356 357 358 359
}

unsigned BaseSpecifierAST::firstToken() const
{
    if (token_virtual && token_access_specifier)
        return std::min(token_virtual, token_access_specifier);
    return name->firstToken();
}

unsigned BaseSpecifierAST::lastToken() const
{
360 361 362 363 364 365 366 367 368 369
    if (name)
        return name->lastToken();
    else if (token_virtual && token_access_specifier)
        return std::min(token_virtual, token_access_specifier) + 1;
    else if (token_virtual)
        return token_virtual + 1;
    else if (token_access_specifier)
        return token_access_specifier + 1;
    // assert?
    return 0;
con's avatar
con committed
370 371 372 373 374 375 376
}

unsigned QtMethodAST::firstToken() const
{ return method_token; }

unsigned QtMethodAST::lastToken() const
{
377 378 379 380 381 382 383
    if (rparen_token)
        return rparen_token + 1;
    else if (declarator)
        return declarator->lastToken();
    else if (lparen_token)
        return lparen_token + 1;
    return method_token + 1;
con's avatar
con committed
384 385
}

386 387 388 389 390 391 392 393 394 395 396
QtMethodAST *QtMethodAST::clone(MemoryPool *pool) const
{
    QtMethodAST *ast = new (pool) QtMethodAST;
    ast->method_token = method_token;
    ast->lparen_token = lparen_token;
    if (declarator)
        ast->declarator = declarator->clone(pool);
    ast->rparen_token = rparen_token;
    return ast;
}

con's avatar
con committed
397 398 399 400 401
void QtMethodAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(declarator, visitor);
    }
402
    visitor->endVisit(this);
con's avatar
con committed
403 404
}

405 406 407 408 409 410 411 412 413 414 415
BinaryExpressionAST *BinaryExpressionAST::clone(MemoryPool *pool) const
{
    BinaryExpressionAST *ast = new (pool) BinaryExpressionAST;
    if (left_expression)
        ast->left_expression = left_expression->clone(pool);
    ast->binary_op_token = binary_op_token;
    if (right_expression)
        ast->right_expression = right_expression->clone(pool);
    return ast;
}

con's avatar
con committed
416 417 418 419 420 421
void BinaryExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(left_expression, visitor);
        accept(right_expression, visitor);
    }
422
    visitor->endVisit(this);
con's avatar
con committed
423 424 425 426 427 428 429 430 431
}

unsigned BinaryExpressionAST::firstToken() const
{
    return left_expression->firstToken();
}

unsigned BinaryExpressionAST::lastToken() const
{
432 433 434 435 436
    if (right_expression)
        return right_expression->lastToken();
    else if (binary_op_token)
        return binary_op_token + 1;
    return left_expression->lastToken();
con's avatar
con committed
437 438
}

439 440 441 442 443 444 445
BoolLiteralAST *BoolLiteralAST::clone(MemoryPool *pool) const
{
    BoolLiteralAST *ast = new (pool) BoolLiteralAST;
    ast->token = token;
    return ast;
}

con's avatar
con committed
446 447 448 449
void BoolLiteralAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
450
    visitor->endVisit(this);
con's avatar
con committed
451 452 453 454 455 456 457 458 459 460 461 462
}

unsigned BoolLiteralAST::firstToken() const
{
    return token;
}

unsigned BoolLiteralAST::lastToken() const
{
    return token + 1;
}

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
CompoundLiteralAST *CompoundLiteralAST::clone(MemoryPool *pool) const
{
    CompoundLiteralAST *ast = new (pool) CompoundLiteralAST;
    ast->lparen_token = lparen_token;
    if (type_id)
        ast->type_id = type_id->clone(pool);
    ast->rparen_token = rparen_token;
    if (initializer)
        ast->initializer = initializer->clone(pool);
    return ast;
}

void CompoundLiteralAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(type_id, visitor);
        accept(initializer, visitor);
    }
481
    visitor->endVisit(this);
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
}

unsigned CompoundLiteralAST::firstToken() const
{
    return lparen_token;
}

unsigned CompoundLiteralAST::lastToken() const
{
    if (initializer)
        return initializer->lastToken();
    else if (rparen_token)
        return rparen_token + 1;
    else if (type_id)
        return type_id->lastToken();
    return lparen_token + 1;
}

500 501 502 503 504 505 506 507
BreakStatementAST *BreakStatementAST::clone(MemoryPool *pool) const
{
    BreakStatementAST *ast = new (pool) BreakStatementAST;
    ast->break_token = break_token;
    ast->semicolon_token = semicolon_token;
    return ast;
}

con's avatar
con committed
508 509 510 511
void BreakStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
512
    visitor->endVisit(this);
con's avatar
con committed
513 514 515 516 517 518 519 520 521
}

unsigned BreakStatementAST::firstToken() const
{
    return break_token;
}

unsigned BreakStatementAST::lastToken() const
{
522 523 524
    if (semicolon_token)
        return semicolon_token + 1;
    return break_token + 1;
con's avatar
con committed
525 526
}

527 528 529 530 531 532 533 534 535 536
CallAST *CallAST::clone(MemoryPool *pool) const
{
    CallAST *ast = new (pool) CallAST;
    ast->lparen_token = lparen_token;
    if (expression_list)
        ast->expression_list = expression_list;
    ast->rparen_token = rparen_token;
    return ast;
}

con's avatar
con committed
537 538 539 540 541 542 543
void CallAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (ExpressionListAST *expr = expression_list;
                 expr; expr = expr->next)
            accept(expr->expression, visitor);
    }
544
    visitor->endVisit(this);
con's avatar
con committed
545 546 547 548 549 550 551 552 553
}

unsigned CallAST::firstToken() const
{
    return lparen_token;
}

unsigned CallAST::lastToken() const
{
554 555 556 557 558 559 560
    if (rparen_token)
        return rparen_token + 1;
    for (ExpressionListAST *it = expression_list; it; it = it->next) {
        if (! it->next && it->expression)
            return it->expression->lastToken();
    }
    return lparen_token + 1;
con's avatar
con committed
561 562
}

563 564 565 566 567 568 569 570 571 572 573 574
CaseStatementAST *CaseStatementAST::clone(MemoryPool *pool) const
{
    CaseStatementAST *ast = new (pool) CaseStatementAST;
    ast->case_token = case_token;
    if (expression)
        ast->expression = expression->clone(pool);
    ast->colon_token = colon_token;
    if (statement)
        ast->statement = statement->clone(pool);
    return ast;
}

con's avatar
con committed
575 576 577
void CaseStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
578 579
        accept(expression, visitor);
        accept(statement, visitor);
con's avatar
con committed
580
    }
581
    visitor->endVisit(this);
con's avatar
con committed
582 583 584 585 586 587 588 589 590 591 592
}

unsigned CaseStatementAST::firstToken() const
{
    return case_token;
}

unsigned CaseStatementAST::lastToken() const
{
    if (statement)
        return statement->lastToken();
593 594 595 596 597
    else if (colon_token)
        return colon_token + 1;
    else if (expression)
        return expression->lastToken();
    return case_token + 1;
con's avatar
con committed
598 599
}

600 601 602 603 604 605 606 607 608 609 610 611
CastExpressionAST *CastExpressionAST::clone(MemoryPool *pool) const
{
    CastExpressionAST *ast = new (pool) CastExpressionAST;
    ast->lparen_token = lparen_token;
    if (type_id)
        ast->type_id = type_id->clone(pool);
    ast->rparen_token = rparen_token;
    if (expression)
        ast->expression = expression->clone(pool);
    return ast;
}

con's avatar
con committed
612 613 614 615
void CastExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
616
    visitor->endVisit(this);
con's avatar
con committed
617 618 619 620 621 622 623 624 625
}

unsigned CastExpressionAST::firstToken() const
{
    return lparen_token;
}

unsigned CastExpressionAST::lastToken() const
{
626 627 628 629 630 631 632
    if (expression)
        return expression->lastToken();
    else if (rparen_token)
        return rparen_token + 1;
    else if (type_id)
        return type_id->lastToken();
    return lparen_token + 1;
con's avatar
con committed
633 634
}

635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
CatchClauseAST *CatchClauseAST::clone(MemoryPool *pool) const
{
    CatchClauseAST *ast = new (pool) CatchClauseAST;
    ast->catch_token = catch_token;
    ast->lparen_token = lparen_token;
    if (exception_declaration)
        ast->exception_declaration = exception_declaration->clone(pool);
    ast->rparen_token = rparen_token;
    if (statement)
        ast->statement = statement->clone(pool);
    if (next)
        ast->next = next->clone(pool);
    return ast;
}

con's avatar
con committed
650 651 652 653 654 655
void CatchClauseAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(exception_declaration, visitor);
        accept(statement, visitor);
    }
656
    visitor->endVisit(this);
con's avatar
con committed
657 658 659 660 661 662 663 664 665 666 667
}

unsigned CatchClauseAST::firstToken() const
{
    return catch_token;
}

unsigned CatchClauseAST::lastToken() const
{
    if (statement)
        return statement->lastToken();
668 669 670 671 672 673 674 675 676 677
    else if (rparen_token)
        return rparen_token + 1;
    for (DeclarationAST *it = exception_declaration; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }
    if (lparen_token)
        return lparen_token + 1;

    return catch_token + 1;
con's avatar
con committed
678 679
}

680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
ClassSpecifierAST *ClassSpecifierAST::clone(MemoryPool *pool) const
{
    ClassSpecifierAST *ast = new (pool) ClassSpecifierAST;
    ast->classkey_token = classkey_token;
    if (attributes)
        ast->attributes = attributes->clone(pool);
    if (name)
        ast->name = name->clone(pool);
    ast->colon_token = colon_token;
    if (base_clause)
        ast->base_clause = base_clause->clone(pool);
    ast->lbrace_token = lbrace_token;
    if (member_specifiers)
        ast->member_specifiers = member_specifiers->clone(pool);
    ast->rbrace_token = rbrace_token;
    return ast;
}

con's avatar
con committed
698 699 700 701 702 703 704 705 706 707 708
void ClassSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (SpecifierAST *spec = attributes; spec; spec = spec->next)
            accept(spec, visitor);
        accept(name, visitor);
        for (BaseSpecifierAST *spec = base_clause; spec; spec = spec->next)
            accept(spec, visitor);
        for (DeclarationAST *decl = member_specifiers; decl; decl = decl->next)
            accept(decl, visitor);
    }
709
    visitor->endVisit(this);
con's avatar
con committed
710 711 712 713 714 715 716 717 718
}

unsigned ClassSpecifierAST::firstToken() const
{
    return classkey_token;
}

unsigned ClassSpecifierAST::lastToken() const
{
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
    if (rbrace_token)
        return rbrace_token + 1;

    for (DeclarationAST *it = member_specifiers; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

    if (lbrace_token)
        return lbrace_token + 1;

    for (BaseSpecifierAST *it = base_clause; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

    if (colon_token)
        return colon_token + 1;

    if (name)
        return name->lastToken();

    for (SpecifierAST *it = attributes; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

    return classkey_token + 1;
con's avatar
con committed
747 748
}

749 750 751 752 753 754 755 756 757 758
CompoundStatementAST *CompoundStatementAST::clone(MemoryPool *pool) const
{
    CompoundStatementAST *ast = new (pool) CompoundStatementAST;
    ast->lbrace_token = lbrace_token;
    if (statements)
        ast->statements = statements->clone(pool);
    ast->rbrace_token = rbrace_token;
    return ast;
}

con's avatar
con committed
759 760 761 762 763 764
void CompoundStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (StatementAST *stmt = statements; stmt; stmt = stmt->next)
            accept(stmt, visitor);
    }
765
    visitor->endVisit(this);
con's avatar
con committed
766 767 768 769 770 771 772 773 774
}

unsigned CompoundStatementAST::firstToken() const
{
    return lbrace_token;
}

unsigned CompoundStatementAST::lastToken() const
{
775 776 777 778 779 780 781 782 783
    if (rbrace_token)
        return rbrace_token + 1;

    for (StatementAST *it = statements; it ; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

    return lbrace_token + 1;
con's avatar
con committed
784 785
}

786 787 788 789 790 791 792 793 794 795
ConditionAST *ConditionAST::clone(MemoryPool *pool) const
{
    ConditionAST *ast = new (pool) ConditionAST;
    if (type_specifier)
        ast->type_specifier = type_specifier->clone(pool);
    if (declarator)
        ast->declarator = declarator->clone(pool);
    return ast;
}

con's avatar
con committed
796 797 798 799 800 801 802
void ConditionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (SpecifierAST *spec = type_specifier; spec; spec = spec->next)
            accept(spec, visitor);
        accept(declarator, visitor);
    }
803
    visitor->endVisit(this);
con's avatar
con committed
804 805 806 807 808 809
}

unsigned ConditionAST::firstToken() const
{
    if (type_specifier)
        return type_specifier->firstToken();
810

con's avatar
con committed
811 812 813 814 815
    return declarator->firstToken();
}

unsigned ConditionAST::lastToken() const
{
816 817 818 819 820 821 822 823 824 825
    if (declarator)
        return declarator->lastToken();

    for (SpecifierAST *it = type_specifier; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

    // ### assert?
    return 0;
con's avatar
con committed
826 827
}

828 829 830 831 832 833 834 835 836 837 838 839 840 841
ConditionalExpressionAST *ConditionalExpressionAST::clone(MemoryPool *pool) const
{
    ConditionalExpressionAST *ast = new (pool) ConditionalExpressionAST;
    if (condition)
        ast->condition = condition->clone(pool);
    ast->question_token = question_token;
    if (left_expression)
        ast->left_expression = left_expression->clone(pool);
    ast->colon_token = colon_token;
    if (right_expression)
        ast->right_expression = right_expression->clone(pool);
    return ast;
}

con's avatar
con committed
842 843 844 845 846 847 848
void ConditionalExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(condition, visitor);
        accept(left_expression, visitor);
        accept(right_expression, visitor);
    }
849
    visitor->endVisit(this);
con's avatar
con committed
850 851 852 853 854 855 856 857 858 859 860
}

unsigned ConditionalExpressionAST::firstToken() const
{
    return condition->firstToken();
}

unsigned ConditionalExpressionAST::lastToken() const
{
    if (right_expression)
        return right_expression->lastToken();
861 862 863 864 865 866 867 868 869 870
    else if (colon_token)
        return colon_token + 1;
    else if (left_expression)
        return left_expression->lastToken();
    else if (question_token)
        return question_token + 1;
    else if (condition)
        return condition->lastToken();
    // ### assert?
    return 0;
con's avatar
con committed
871 872
}

873 874 875 876 877 878 879 880
ContinueStatementAST *ContinueStatementAST::clone(MemoryPool *pool) const
{
    ContinueStatementAST *ast = new (pool) ContinueStatementAST;
    ast->continue_token = continue_token;
    ast->semicolon_token = semicolon_token;
    return ast;
}

con's avatar
con committed
881 882 883 884
void ContinueStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
885
    visitor->endVisit(this);
con's avatar
con committed
886 887 888 889 890 891 892 893 894
}

unsigned ContinueStatementAST::firstToken() const
{
    return continue_token;
}

unsigned ContinueStatementAST::lastToken() const
{
895 896 897
    if (semicolon_token)
        return semicolon_token + 1;
    return continue_token + 1;
con's avatar
con committed
898 899
}

900 901 902 903 904 905 906 907 908 909 910
ConversionFunctionIdAST *ConversionFunctionIdAST::clone(MemoryPool *pool) const
{
    ConversionFunctionIdAST *ast = new (pool) ConversionFunctionIdAST;
    ast->operator_token = operator_token;
    if (type_specifier)
        ast->type_specifier = type_specifier->clone(pool);
    if (ptr_operators)
        ast->ptr_operators = ptr_operators->clone(pool);
    return ast;
}

con's avatar
con committed
911 912 913 914 915 916 917 918 919
void ConversionFunctionIdAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (SpecifierAST *spec = type_specifier; spec; spec = spec->next)
            accept(spec, visitor);
        for (PtrOperatorAST *ptr_op = ptr_operators; ptr_op;
                 ptr_op = static_cast<PtrOperatorAST *>(ptr_op->next))
            accept(ptr_op, visitor);
    }
920
    visitor->endVisit(this);
con's avatar
con committed
921 922 923 924 925 926 927 928 929
}

unsigned ConversionFunctionIdAST::firstToken() const
{
    return operator_token;
}

unsigned ConversionFunctionIdAST::lastToken() const
{
930 931 932
    for (PtrOperatorAST *it = ptr_operators; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
con's avatar
con committed
933
    }
934 935 936 937 938 939

    for (SpecifierAST *it = type_specifier; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

con's avatar
con committed
940 941 942
    return operator_token + 1;
}

943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
CppCastExpressionAST *CppCastExpressionAST::clone(MemoryPool *pool) const
{
    CppCastExpressionAST *ast = new (pool) CppCastExpressionAST;
    ast->cast_token = cast_token;
    ast->less_token = less_token;
    if (type_id)
        ast->type_id = type_id->clone(pool);
    ast->greater_token = greater_token;
    ast->lparen_token = lparen_token;
    if (expression)
        ast->expression = expression->clone(pool);
    ast->rparen_token = rparen_token;
    return ast;
}

con's avatar
con committed
958 959 960 961 962 963
void CppCastExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(type_id, visitor);
        accept(expression, visitor);
    }
964
    visitor->endVisit(this);
con's avatar
con committed
965 966 967 968 969 970 971 972 973
}

unsigned CppCastExpressionAST::firstToken() const
{
    return cast_token;
}

unsigned CppCastExpressionAST::lastToken() const
{
974 975 976 977 978 979 980 981 982 983 984 985 986
    if (rparen_token)
        return rparen_token + 1;
    else if (expression)
        return expression->lastToken();
    else if (lparen_token)
        return lparen_token + 1;
    else if (greater_token)
        return greater_token + 1;
    else if (type_id)
        return type_id->lastToken();
    else if (less_token)
        return less_token + 1;
    return cast_token + 1;
con's avatar
con committed
987 988
}

989 990 991 992 993 994 995 996 997
CtorInitializerAST *CtorInitializerAST::clone(MemoryPool *pool) const
{
    CtorInitializerAST *ast = new (pool) CtorInitializerAST;
    ast->colon_token = colon_token;
    if (member_initializers)
        ast->member_initializers = member_initializers->clone(pool);
    return ast;
}

con's avatar
con committed
998 999 1000 1001 1002 1003 1004
void CtorInitializerAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (MemInitializerAST *mem_init = member_initializers;
                 mem_init; mem_init = mem_init->next)
            accept(mem_init, visitor);
    }
1005
    visitor->endVisit(this);
con's avatar
con committed
1006 1007 1008 1009 1010 1011 1012 1013 1014
}

unsigned CtorInitializerAST::firstToken() const
{
    return colon_token;
}

unsigned CtorInitializerAST::lastToken() const
{
1015
    for (MemInitializerAST *it = member_initializers; it; it = it->next) {
con's avatar
con committed
1016 1017
        if (! it->next)
            return it->lastToken();
1018
    }
con's avatar
con committed
1019 1020 1021
    return colon_token + 1;
}

1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
DeclaratorAST *DeclaratorAST::clone(MemoryPool *pool) const
{
    DeclaratorAST *ast = new (pool) DeclaratorAST;
    if (ptr_operators)
        ast->ptr_operators = ptr_operators->clone(pool);
    if (core_declarator)
        ast->core_declarator = core_declarator->clone(pool);
    if (postfix_declarators)
        ast->postfix_declarators = postfix_declarators->clone(pool);
    if (attributes)
        ast->attributes = attributes->clone(pool);
    if (initializer)
        ast->initializer = initializer->clone(pool);
    return ast;
}

con's avatar
con committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
void DeclaratorAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (PtrOperatorAST *ptr_op = ptr_operators; ptr_op; ptr_op = ptr_op->next) {
            accept(ptr_op, visitor);
        }
        accept(core_declarator, visitor);
        for (PostfixDeclaratorAST *fx = postfix_declarators; fx; fx = fx->next) {
            accept(fx, visitor);
        }
        accept(attributes, visitor);
        accept(initializer, visitor);
    }
1051
    visitor->endVisit(this);
con's avatar
con committed
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
}

unsigned DeclaratorAST::firstToken() const
{
    if (ptr_operators)
        return ptr_operators->firstToken();
    else if (core_declarator)
        return core_declarator->firstToken();
    else if (postfix_declarators)
        return postfix_declarators->firstToken();
1062 1063 1064 1065 1066
    else if (attributes)
        return attributes->firstToken();
    else if (initializer)
        return initializer->firstToken();
    // ### assert?
con's avatar
con committed
1067 1068 1069 1070 1071
    return 0;
}

unsigned DeclaratorAST::lastToken() const
{
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
    if (initializer)
        return initializer->lastToken();

    for (SpecifierAST *it = attributes; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

    for (PostfixDeclaratorAST *it = postfix_declarators; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
con's avatar
con committed
1083
    }
1084

con's avatar
con committed
1085 1086
    if (core_declarator)
        return core_declarator->lastToken();
1087 1088 1089 1090

    for (PtrOperatorAST *it = ptr_operators; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
con's avatar
con committed
1091
    }
1092 1093

    // ### assert?
con's avatar
con committed
1094 1095 1096
    return 0;
}

1097 1098 1099 1100 1101 1102 1103 1104
DeclarationStatementAST *DeclarationStatementAST::clone(MemoryPool *pool) const
{
    DeclarationStatementAST *ast = new (pool) DeclarationStatementAST;
    if (declaration)
        ast->declaration = declaration->clone(pool);
    return ast;
}

con's avatar
con committed
1105 1106 1107 1108 1109
void DeclarationStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(declaration, visitor);
    }
1110
    visitor->endVisit(this);
con's avatar
con committed
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
}

unsigned DeclarationStatementAST::firstToken() const
{
    return declaration->firstToken();
}

unsigned DeclarationStatementAST::lastToken() const
{
    return declaration->lastToken();
}

1123 1124 1125 1126 1127 1128 1129 1130
DeclaratorIdAST *DeclaratorIdAST::clone(MemoryPool *pool) const
{
    DeclaratorIdAST *ast = new (pool) DeclaratorIdAST;
    if (name)
        ast->name = name->clone(pool);
    return ast;
}

con's avatar
con committed
1131 1132 1133 1134 1135
void DeclaratorIdAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
    }
1136
    visitor->endVisit(this);
con's avatar
con committed
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
}

unsigned DeclaratorIdAST::firstToken() const
{
    return name->firstToken();
}

unsigned DeclaratorIdAST::lastToken() const
{
    return name->lastToken();
}

1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
DeclaratorListAST *DeclaratorListAST::clone(MemoryPool *pool) const
{
    DeclaratorListAST *ast = new (pool) DeclaratorListAST;
    if (declarator)
        ast->declarator = declarator->clone(pool);
    if (next)
        ast->next = next->clone(pool);
    return ast;
}

con's avatar
con committed
1159 1160 1161 1162 1163 1164
void DeclaratorListAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (DeclaratorListAST *it = this; it; it = it->next)
            accept(it->declarator, visitor);
    }
1165
    visitor->endVisit(this);
con's avatar
con committed
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
}

unsigned DeclaratorListAST::firstToken() const
{
    return declarator->firstToken();
}

unsigned DeclaratorListAST::lastToken() const
{
    for (const DeclaratorListAST *it = this; it; it = it->next) {
        if (! it->next)
1177
            return it->declarator->lastToken();
con's avatar
con committed
1178 1179 1180 1181
    }
    return 0;
}

1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
DeleteExpressionAST *DeleteExpressionAST::clone(MemoryPool *pool) const
{
    DeleteExpressionAST *ast = new (pool) DeleteExpressionAST;
    ast->scope_token = scope_token;
    ast->delete_token = delete_token;
    ast->lbracket_token = lbracket_token;
    ast->rbracket_token = rbracket_token;
    if (expression)
        ast->expression = expression->clone(pool);
    return ast;
}

con's avatar
con committed
1194 1195 1196 1197 1198
void DeleteExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
1199
    visitor->endVisit(this);
con's avatar
con committed
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
}

unsigned DeleteExpressionAST::firstToken() const
{
    if (scope_token)
        return scope_token;
    return delete_token;
}

unsigned DeleteExpressionAST::lastToken() const
{
    if (expression)
        return expression->lastToken();
    else if (rbracket_token)
        return rbracket_token + 1;
1215 1216 1217 1218 1219
    else if (lbracket_token)
        return lbracket_token + 1;
    else if (delete_token)
        return delete_token + 1;
    return scope_token + 1;
con's avatar
con committed
1220 1221
}

1222 1223 1224 1225 1226 1227 1228 1229
DestructorNameAST *DestructorNameAST::clone(MemoryPool *pool) const
{
    DestructorNameAST *ast = new (pool) DestructorNameAST;
    ast->tilde_token = tilde_token;
    ast->identifier_token = identifier_token;
    return ast;
}

con's avatar
con committed
1230 1231 1232 1233
void DestructorNameAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
1234
    visitor->endVisit(this);
con's avatar
con committed
1235 1236 1237 1238 1239 1240 1241 1242 1243
}

unsigned DestructorNameAST::firstToken() const
{
    return tilde_token;
}

unsigned DestructorNameAST::lastToken() const
{
1244 1245 1246
    if (identifier_token)
        return identifier_token + 1;
    return tilde_token + 1;
con's avatar
con committed
1247 1248
}

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
DoStatementAST *DoStatementAST::clone(MemoryPool *pool) const
{
    DoStatementAST *ast = new (pool) DoStatementAST;
    ast->do_token = do_token;
    if (statement)
        ast->statement = statement->clone(pool);
    ast->while_token = while_token;
    ast->lparen_token = lparen_token;
    if (expression)
        ast->expression = expression->clone(pool);
    ast->rparen_token = rparen_token;
    ast->semicolon_token = semicolon_token;
    return ast;
}

con's avatar
con committed
1264 1265 1266 1267 1268 1269
void DoStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(statement, visitor);
        accept(expression, visitor);
    }
1270
    visitor->endVisit(this);
con's avatar
con committed
1271 1272 1273 1274 1275 1276 1277 1278 1279
}

unsigned DoStatementAST::firstToken() const
{
    return do_token;
}

unsigned DoStatementAST::lastToken() const
{
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
    if (semicolon_token)
        return semicolon_token + 1;
    else if (rparen_token)
        return rparen_token + 1;
    else if (expression)
        return expression->lastToken();
    else if (lparen_token)
        return lparen_token + 1;
    else if (while_token)
        return while_token + 1;
    else if (statement)
        return statement->lastToken();
    return do_token + 1;
con's avatar
con committed
1293 1294
}

1295 1296 1297 1298 1299 1300 1301 1302 1303
ElaboratedTypeSpecifierAST *ElaboratedTypeSpecifierAST::clone(MemoryPool *pool) const
{
    ElaboratedTypeSpecifierAST *ast = new (pool) ElaboratedTypeSpecifierAST;
    ast->classkey_token = classkey_token;
    if (name)
        ast->name = name->clone(pool);
    return ast;
}

con's avatar
con committed
1304 1305 1306 1307 1308
void ElaboratedTypeSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
    }
1309
    visitor->endVisit(this);
con's avatar
con committed
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
}

unsigned ElaboratedTypeSpecifierAST::firstToken() const
{
    return classkey_token;
}

unsigned ElaboratedTypeSpecifierAST::lastToken() const
{
    if (name)
        return name->lastToken();
    return classkey_token + 1;
}

1324 1325 1326 1327 1328 1329 1330
EmptyDeclarationAST *EmptyDeclarationAST::clone(MemoryPool *pool) const
{
    EmptyDeclarationAST *ast = new (pool) EmptyDeclarationAST;
    ast->semicolon_token = semicolon_token;
    return ast;
}

con's avatar
con committed
1331 1332 1333 1334
void EmptyDeclarationAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
1335
    visitor->endVisit(this);
con's avatar
con committed
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
}

unsigned EmptyDeclarationAST::firstToken() const
{
    return semicolon_token;
}

unsigned EmptyDeclarationAST::lastToken() const
{
    return semicolon_token + 1;
}

1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
EnumSpecifierAST *EnumSpecifierAST::clone(MemoryPool *pool) const
{
    EnumSpecifierAST *ast = new (pool) EnumSpecifierAST;
    ast->enum_token = enum_token;
    if (name)
        ast->name = name->clone(pool);
    ast->lbrace_token = lbrace_token;
    if (enumerators)
        ast->enumerators = enumerators->clone(pool);
    ast->rbrace_token = rbrace_token;
    return ast;
}

con's avatar
con committed
1361 1362 1363 1364 1365 1366 1367 1368
void EnumSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
        for (EnumeratorAST *enumerator = enumerators; enumerator;
                 enumerator = enumerator->next)
            accept(enumerator, visitor);
    }
1369
    visitor->endVisit(this);
con's avatar
con committed
1370 1371 1372 1373 1374 1375 1376 1377 1378
}

unsigned EnumSpecifierAST::firstToken() const
{
    return enum_token;
}

unsigned EnumSpecifierAST::lastToken() const
{
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
    if (rbrace_token)
        return rbrace_token + 1;

    for (EnumeratorAST *it = enumerators; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
    }

    if (lbrace_token)
        return lbrace_token + 1;
    if (name)
        return name->lastToken();

    return enum_token + 1;
con's avatar
con committed
1393 1394
}

1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
EnumeratorAST *EnumeratorAST::clone(MemoryPool *pool) const
{
    EnumeratorAST *ast = new (pool) EnumeratorAST;
    ast->identifier_token = identifier_token;
    ast->equal_token = equal_token;
    if (expression)
        ast->expression = expression->clone(pool);
    if (next)
        ast->next = next->clone(pool);
    return ast;
}

con's avatar
con committed
1407 1408 1409 1410 1411
void EnumeratorAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
1412
    visitor->endVisit(this);
con's avatar
con committed
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
}

unsigned EnumeratorAST::firstToken() const
{
    return identifier_token;
}

unsigned EnumeratorAST::lastToken() const
{
    if (expression)
        return expression->lastToken();
1424
    else if (equal_token)
con's avatar
con committed
1425 1426 1427 1428
        return equal_token + 1;
    return identifier_token + 1;
}

1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
ExceptionDeclarationAST *ExceptionDeclarationAST::clone(MemoryPool *pool) const
{
    ExceptionDeclarationAST *ast = new (pool) ExceptionDeclarationAST;
    if (type_specifier)
        ast->type_specifier = type_specifier->clone(pool);
    if (declarator)
        ast->declarator = declarator->clone(pool);
    ast->dot_dot_dot_token = dot_dot_dot_token;
    return ast;
}

con's avatar
con committed
1440 1441 1442 1443 1444 1445 1446
void ExceptionDeclarationAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (SpecifierAST *spec = type_specifier; spec; spec = spec->next)
            accept(spec, visitor);
        accept(declarator, visitor);
    }
1447
    visitor->endVisit(this);
con's avatar
con committed
1448 1449 1450 1451
}

unsigned ExceptionDeclarationAST::firstToken() const
{
1452 1453 1454 1455 1456
    if (type_specifier)
        return type_specifier->firstToken();
    if (declarator)
        return declarator->firstToken();
    return dot_dot_dot_token;
con's avatar
con committed
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
}

unsigned ExceptionDeclarationAST::lastToken() const
{
    if (dot_dot_dot_token)
        return dot_dot_dot_token + 1;
    else if (declarator)
        return declarator->lastToken();
    for (SpecifierAST *it = type_specifier; it; it = it->next) {
        if (! it->next)
1467
            return it->lastToken();
con's avatar
con committed
1468 1469 1470 1471
    }
    return 0;
}

1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
ExceptionSpecificationAST *ExceptionSpecificationAST::clone(MemoryPool *pool) const
{
    ExceptionSpecificationAST *ast = new (pool) ExceptionSpecificationAST;
    ast->throw_token = throw_token;
    ast->lparen_token = lparen_token;
    ast->dot_dot_dot_token = dot_dot_dot_token;
    if (type_ids)
        ast->type_ids = type_ids->clone(pool);
    ast->rparen_token = rparen_token;
    return ast;
}

con's avatar
con committed
1484 1485 1486 1487 1488 1489 1490
void ExceptionSpecificationAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (ExpressionListAST *type_id = type_ids; type_id;
                 type_id = type_id->next)
            accept(type_id->expression, visitor);
    }
1491
    visitor->endVisit(this);
con's avatar
con committed
1492 1493 1494 1495 1496 1497 1498 1499 1500
}

unsigned ExceptionSpecificationAST::firstToken() const
{
    return throw_token;
}

unsigned ExceptionSpecificationAST::lastToken() const
{
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
    if (rparen_token)
        return rparen_token + 1;

    for (ExpressionListAST *it = type_ids; it; it = it->next) {
        if (! it->next && it->expression)
            return it->expression->lastToken();
    }

    if (dot_dot_dot_token)
        return dot_dot_dot_token + 1;
    else if (lparen_token)
        return lparen_token + 1;

    return throw_token + 1;
con's avatar
con committed
1515 1516
}

1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
ExpressionListAST *ExpressionListAST::clone(MemoryPool *pool) const
{
    ExpressionListAST *ast = new (pool) ExpressionListAST;
    if (expression)
        ast->expression = expression->clone(pool);
    if (next)
        ast->next = next->clone(pool);
    return ast;
}

1527 1528
void ExpressionListAST::accept0(ASTVisitor *visitor)
{
1529 1530 1531 1532
    if (visitor->visit(this)) {
        for (const ExpressionListAST *it = this; it; it = it->next) {
            accept(it->expression, visitor);
        }
1533
    }
1534
    visitor->endVisit(this);
1535
}
con's avatar
con committed
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550

unsigned ExpressionListAST::firstToken() const
{
    return expression->firstToken();
}

unsigned ExpressionListAST::lastToken() const
{
    for (const ExpressionListAST *it = this; it; it = it->next) {
        if (! it->next)
            return it->expression->lastToken();
    }
    return 0;
}

1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
ExpressionOrDeclarationStatementAST *ExpressionOrDeclarationStatementAST::clone(MemoryPool *pool) const
{
    ExpressionOrDeclarationStatementAST *ast = new (pool) ExpressionOrDeclarationStatementAST;
    if (expression)
        ast->expression = expression->clone(pool);
    if (declaration)
        ast->declaration = declaration->clone(pool);
    return ast;
}

con's avatar
con committed
1561 1562 1563 1564 1565 1566
void ExpressionOrDeclarationStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(declaration, visitor);
        accept(expression, visitor);
    }
1567
    visitor->endVisit(this);
con's avatar
con committed
1568 1569 1570 1571
}

unsigned ExpressionOrDeclarationStatementAST::firstToken() const
{
1572
    return declaration->firstToken();
con's avatar
con committed
1573 1574 1575 1576
}

unsigned ExpressionOrDeclarationStatementAST::lastToken() const
{
1577
    return declaration->lastToken();
con's avatar
con committed
1578 1579
}

1580 1581 1582 1583 1584 1585 1586 1587 1588
ExpressionStatementAST *ExpressionStatementAST::clone(MemoryPool *pool) const
{
    ExpressionStatementAST *ast = new (pool) ExpressionStatementAST;
    if (expression)
        ast->expression = expression->clone(pool);
    ast->semicolon_token = semicolon_token;
    return ast;
}

con's avatar
con committed