AST.cpp 91.3 KB
Newer Older
con's avatar
con committed
1
2
3
4
/***************************************************************************
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2008-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
10
11
**
** Non-Open Source Usage
**
con's avatar
con committed
12
13
14
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
15
16
17
18
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
con's avatar
con committed
19
20
21
22
23
24
25
26
27
28
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
29
** rights. These rights are described in the Nokia Qt GPL Exception
30
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
31
32
**
***************************************************************************/
con's avatar
con committed
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
85
86
87
88
// 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();
89
90
91
92
93
    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
94
95
}

96
97
98
99
100
101
102
103
104
105
106
107
108
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
109
110
111
112
113
114
void AttributeSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (AttributeAST *attr = attributes; attr; attr = attr->next)
            accept(attr, visitor);
    }
115
    visitor->endVisit(this);
con's avatar
con committed
116
117
118
119
120
121
122
123
124
}

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

unsigned AttributeAST::lastToken() const
{
125
126
127
128
129
130
131
132
133
134
135
    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
136
        return tag_token + 1;
137
138
139
140

    if (lparen_token)
        return lparen_token + 1;

con's avatar
con committed
141
142
143
    return identifier_token + 1;
}

144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
158
159
160
161
162
163
void AttributeAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (ExpressionListAST *it = expression_list; it; it = it->next)
            accept(it->expression, visitor);
    }
164
    visitor->endVisit(this);
con's avatar
con committed
165
166
}

167
168
169
170
171
172
173
174
175
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
176
177
178
179
void AccessDeclarationAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
180
    visitor->endVisit(this);
con's avatar
con committed
181
182
183
184
185
186
187
188
189
}

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

unsigned AccessDeclarationAST::lastToken() const
{
190
191
192
193
194
    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
195
196
}

197
198
199
200
201
202
203
204
205
206
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
207
208
209
210
211
void ArrayAccessAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
212
    visitor->endVisit(this);
con's avatar
con committed
213
214
215
216
217
218
219
220
221
}

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

unsigned ArrayAccessAST::lastToken() const
{
222
223
224
225
226
    if (rbracket_token)
        return rbracket_token + 1;
    else if (expression)
        return expression->lastToken();
    return lbracket_token + 1;
con's avatar
con committed
227
228
}

229
230
231
232
233
234
235
236
237
238
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
239
240
241
242
243
void ArrayDeclaratorAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(this->expression, visitor);
    }
244
    visitor->endVisit(this);
con's avatar
con committed
245
246
247
248
249
250
251
252
253
}

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

unsigned ArrayDeclaratorAST::lastToken() const
{
254
255
256
257
258
    if (rbracket_token)
        return rbracket_token + 1;
    else if (expression)
        return expression->lastToken();
    return lbracket_token + 1;
con's avatar
con committed
259
260
}

261
262
263
264
265
266
267
268
269
270
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
271
272
273
void ArrayInitializerAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
274
        for (ExpressionListAST *expr = expression_list; expr; expr = expr->next)
con's avatar
con committed
275
276
            accept(expr->expression, visitor);
    }
277
    visitor->endVisit(this);
con's avatar
con committed
278
279
280
281
282
283
284
285
286
}

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

unsigned ArrayInitializerAST::lastToken() const
{
287
288
289
290
291
292
293
294
295
    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
296
297
}

298
299
300
301
AsmDefinitionAST *AsmDefinitionAST::clone(MemoryPool *pool) const
{
    AsmDefinitionAST *ast = new (pool) AsmDefinitionAST;
    ast->asm_token = asm_token;
302
    ast->volatile_token = volatile_token;
303
304
305
306
307
308
    ast->lparen_token = lparen_token;
    ast->rparen_token = rparen_token;
    ast->semicolon_token = semicolon_token;
    return ast;
}

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

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

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

335
336
337
338
339
340
341
342
343
344
345
346
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
347
348
349
350
351
void BaseSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
    }
352
    visitor->endVisit(this);
con's avatar
con committed
353
354
355
356
357
358
359
360
361
362
363
}

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
{
364
365
366
367
368
369
370
371
372
373
    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
374
375
376
377
378
379
380
}

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

unsigned QtMethodAST::lastToken() const
{
381
382
383
384
385
386
387
    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
388
389
}

390
391
392
393
394
395
396
397
398
399
400
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
401
402
403
404
405
void QtMethodAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(declarator, visitor);
    }
406
    visitor->endVisit(this);
con's avatar
con committed
407
408
}

409
410
411
412
413
414
415
416
417
418
419
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
420
421
422
423
424
425
void BinaryExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(left_expression, visitor);
        accept(right_expression, visitor);
    }
426
    visitor->endVisit(this);
con's avatar
con committed
427
428
429
430
431
432
433
434
435
}

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

unsigned BinaryExpressionAST::lastToken() const
{
436
437
438
439
440
    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
441
442
}

443
444
445
446
447
448
449
BoolLiteralAST *BoolLiteralAST::clone(MemoryPool *pool) const
{
    BoolLiteralAST *ast = new (pool) BoolLiteralAST;
    ast->token = token;
    return ast;
}

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

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

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

467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
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);
    }
485
    visitor->endVisit(this);
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
}

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;
}

504
505
506
507
508
509
510
511
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
512
513
514
515
void BreakStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
516
    visitor->endVisit(this);
con's avatar
con committed
517
518
519
520
521
522
523
524
525
}

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

unsigned BreakStatementAST::lastToken() const
{
526
527
528
    if (semicolon_token)
        return semicolon_token + 1;
    return break_token + 1;
con's avatar
con committed
529
530
}

531
532
533
534
535
536
537
538
539
540
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
541
542
543
544
545
546
547
void CallAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (ExpressionListAST *expr = expression_list;
                 expr; expr = expr->next)
            accept(expr->expression, visitor);
    }
548
    visitor->endVisit(this);
con's avatar
con committed
549
550
551
552
553
554
555
556
557
}

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

unsigned CallAST::lastToken() const
{
558
559
560
561
562
563
564
    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
565
566
}

567
568
569
570
571
572
573
574
575
576
577
578
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
579
580
581
void CaseStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
582
583
        accept(expression, visitor);
        accept(statement, visitor);
con's avatar
con committed
584
    }
585
    visitor->endVisit(this);
con's avatar
con committed
586
587
588
589
590
591
592
593
594
595
596
}

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

unsigned CaseStatementAST::lastToken() const
{
    if (statement)
        return statement->lastToken();
597
598
599
600
601
    else if (colon_token)
        return colon_token + 1;
    else if (expression)
        return expression->lastToken();
    return case_token + 1;
con's avatar
con committed
602
603
}

604
605
606
607
608
609
610
611
612
613
614
615
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
616
617
618
619
void CastExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
620
    visitor->endVisit(this);
con's avatar
con committed
621
622
623
624
625
626
627
628
629
}

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

unsigned CastExpressionAST::lastToken() const
{
630
631
632
633
634
635
636
    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
637
638
}

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
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
654
655
656
657
658
659
void CatchClauseAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(exception_declaration, visitor);
        accept(statement, visitor);
    }
660
    visitor->endVisit(this);
con's avatar
con committed
661
662
663
664
665
666
667
668
669
670
671
}

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

unsigned CatchClauseAST::lastToken() const
{
    if (statement)
        return statement->lastToken();
672
673
674
675
676
677
678
679
680
681
    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
682
683
}

684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
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
702
703
704
705
706
707
708
709
710
711
712
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);
    }
713
    visitor->endVisit(this);
con's avatar
con committed
714
715
716
717
718
719
720
721
722
}

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

unsigned ClassSpecifierAST::lastToken() const
{
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
    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
751
752
}

753
754
755
756
757
758
759
760
761
762
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
763
764
765
766
767
768
void CompoundStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (StatementAST *stmt = statements; stmt; stmt = stmt->next)
            accept(stmt, visitor);
    }
769
    visitor->endVisit(this);
con's avatar
con committed
770
771
772
773
774
775
776
777
778
}

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

unsigned CompoundStatementAST::lastToken() const
{
779
780
781
782
783
784
785
786
787
    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
788
789
}

790
791
792
793
794
795
796
797
798
799
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
800
801
802
803
804
805
806
void ConditionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (SpecifierAST *spec = type_specifier; spec; spec = spec->next)
            accept(spec, visitor);
        accept(declarator, visitor);
    }
807
    visitor->endVisit(this);
con's avatar
con committed
808
809
810
811
812
813
}

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

con's avatar
con committed
815
816
817
818
819
    return declarator->firstToken();
}

unsigned ConditionAST::lastToken() const
{
820
821
822
823
824
825
826
827
828
829
    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
830
831
}

832
833
834
835
836
837
838
839
840
841
842
843
844
845
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
846
847
848
849
850
851
852
void ConditionalExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(condition, visitor);
        accept(left_expression, visitor);
        accept(right_expression, visitor);
    }
853
    visitor->endVisit(this);
con's avatar
con committed
854
855
856
857
858
859
860
861
862
863
864
}

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

unsigned ConditionalExpressionAST::lastToken() const
{
    if (right_expression)
        return right_expression->lastToken();
865
866
867
868
869
870
871
872
873
874
    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
875
876
}

877
878
879
880
881
882
883
884
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
885
886
887
888
void ContinueStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
889
    visitor->endVisit(this);
con's avatar
con committed
890
891
892
893
894
895
896
897
898
}

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

unsigned ContinueStatementAST::lastToken() const
{
899
900
901
    if (semicolon_token)
        return semicolon_token + 1;
    return continue_token + 1;
con's avatar
con committed
902
903
}

904
905
906
907
908
909
910
911
912
913
914
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
915
916
917
918
919
920
921
922
923
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);
    }
924
    visitor->endVisit(this);
con's avatar
con committed
925
926
927
928
929
930
931
932
933
}

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

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

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

con's avatar
con committed
944
945
946
    return operator_token + 1;
}

947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
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
962
963
964
965
966
967
void CppCastExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(type_id, visitor);
        accept(expression, visitor);
    }
968
    visitor->endVisit(this);
con's avatar
con committed
969
970
971
972
973
974
975
976
977
}

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

unsigned CppCastExpressionAST::lastToken() const
{
978
979
980
981
982
983
984
985
986
987
988
989
990
    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
991
992
}

993
994
995
996
997
998
999
1000
1001
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
1002
1003
1004
1005
1006
1007
1008
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);
    }
1009
    visitor->endVisit(this);
con's avatar
con committed
1010
1011
1012
1013
1014
1015
1016
1017
1018
}

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

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

1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
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
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
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);
    }
1055
    visitor->endVisit(this);
con's avatar
con committed
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
}

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();
1066
1067
1068
1069
1070
    else if (attributes)
        return attributes->firstToken();
    else if (initializer)
        return initializer->firstToken();
    // ### assert?
con's avatar
con committed
1071
1072
1073
1074
1075
    return 0;
}

unsigned DeclaratorAST::lastToken() const
{
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
    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
1087
    }
1088

con's avatar
con committed
1089
1090
    if (core_declarator)
        return core_declarator->lastToken();
1091
1092
1093
1094

    for (PtrOperatorAST *it = ptr_operators; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
con's avatar
con committed
1095
    }
1096
1097

    // ### assert?
con's avatar
con committed
1098
1099
1100
    return 0;
}

1101
1102
1103
1104
1105
1106
1107
1108
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
1109
1110
1111
1112
1113
void DeclarationStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(declaration, visitor);
    }
1114
    visitor->endVisit(this);
con's avatar
con committed
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
}

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

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

1127
1128
1129
1130
1131
1132
1133
1134
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
1135
1136
1137
1138
1139
void DeclaratorIdAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
    }
1140
    visitor->endVisit(this);
con's avatar
con committed
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
}

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

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

1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
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
1163
1164
1165
1166
1167
1168
void DeclaratorListAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (DeclaratorListAST *it = this; it; it = it->next)
            accept(it->declarator, visitor);
    }
1169
    visitor->endVisit(this);
con's avatar
con committed
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
}

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

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

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
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
1198
1199
1200
1201
1202
void DeleteExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
1203
    visitor->endVisit(this);
con's avatar
con committed
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
}

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;
1219
1220
1221
1222
1223
    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
1224
1225
}

1226
1227
1228
1229
1230
1231
1232
1233
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
1234
1235
1236
1237
void DestructorNameAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
1238
    visitor->endVisit(this);
con's avatar
con committed
1239
1240
1241
1242
1243
1244
1245
1246
1247
}

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

unsigned DestructorNameAST::lastToken() const
{
1248
1249
1250
    if (identifier_token)
        return identifier_token + 1;
    return tilde_token + 1;
con's avatar
con committed
1251
1252
}

1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
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
1268
1269
1270
1271
1272
1273
void DoStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(statement, visitor);
        accept(expression, visitor);
    }
1274
    visitor->endVisit(this);
con's avatar
con committed
1275
1276
1277
1278
1279
1280
1281
1282
1283
}

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

unsigned DoStatementAST::lastToken() const
{
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
    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
1297
1298
}

1299
1300
1301
1302
1303
1304
1305
1306
1307
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
1308
1309
1310
1311
1312
void ElaboratedTypeSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
    }
1313
    visitor->endVisit(this);
con's avatar
con committed
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
}

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

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

1328
1329
1330
1331
1332
1333
1334
EmptyDeclarationAST *EmptyDeclarationAST::clone(MemoryPool *pool) const
{
    EmptyDeclarationAST *ast = new (pool) EmptyDeclarationAST;
    ast->semicolon_token = semicolon_token;
    return ast;
}

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

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

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

1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
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
1365
1366
1367
1368
1369
1370
1371
1372
void EnumSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
        for (EnumeratorAST *enumerator = enumerators; enumerator;
                 enumerator = enumerator->next)
            accept(enumerator, visitor);
    }
1373
    visitor->endVisit(this);
con's avatar
con committed
1374
1375
1376
1377
1378
1379
1380
1381
1382
}

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

unsigned EnumSpecifierAST::lastToken() const
{
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
    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
1397
1398
}

1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
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
1411
1412
1413
1414
1415
void EnumeratorAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
1416
    visitor->endVisit(this);
con's avatar
con committed
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
}

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

unsigned EnumeratorAST::lastToken() const
{
    if (expression)
        return expression->lastToken();
1428
    else if (equal_token)
con's avatar
con committed
1429
1430
1431
1432
        return equal_token + 1;
    return identifier_token + 1;
}

1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
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
1444
1445
1446
1447
1448
1449
1450
void ExceptionDeclarationAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (SpecifierAST *spec = type_specifier; spec; spec = spec->next)
            accept(spec, visitor);
        accept(declarator, visitor);
    }
1451
    visitor->endVisit(this);
con's avatar
con committed
1452
1453
1454
1455
}

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

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)
1471
            return it->lastToken();
con's avatar
con committed
1472
1473
1474
1475
    }
    return 0;
}

1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
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
1488
1489
1490
1491
1492
1493
1494
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);
    }
1495
    visitor->endVisit(this);
con's avatar
con committed
1496
1497
1498
1499
1500
1501
1502
1503
1504
}

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

unsigned ExceptionSpecificationAST::lastToken() const
{
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
    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
1519
1520
}

1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
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;
}

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

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;
}

1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
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
1565
1566
1567
1568
1569
1570
void ExpressionOrDeclarationStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(declaration, visitor);
        accept(expression, visitor);
    }
1571
    visitor->endVisit(this);
con's avatar
con committed
1572
1573
1574
1575
}

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

unsigned ExpressionOrDeclarationStatementAST::lastToken() const
{
1581
    return declaration->lastToken();
con's avatar
con committed
1582
1583
}

1584
1585
1586
1587
1588
1589
1590
1591
1592
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
1593
1594
1595
1596
1597
void ExpressionStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
1598
    visitor->endVisit(this);
con's avatar
con committed
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
}

unsigned ExpressionStatementAST::firstToken() const
{
    if (expression)
        return expression->firstToken();
    return semicolon_token;
}

unsigned ExpressionStatementAST::lastToken() const
{
1610
1611
1612
1613
1614
1615
    if (semicolon_token)
        return semicolon_token + 1;
    else if (expression)
        return expression->lastToken();
    // ### assert?
    return 0;
con's avatar
con committed
1616
1617
}

1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
ForStatementAST *ForStatementAST::clone(MemoryPool *pool) const
{
    ForStatementAST *ast = new (pool) ForStatementAST;
    ast->for_token = for_token;
    ast->lparen_token = lparen_token;
    if (initializer)
        ast->initializer = initializer->clone(pool);
    if (condition)
        ast->condition = condition->clone(pool);
    ast->semicolon_token = semicolon_token;
    if (expression)
        ast->expression = expression->clone(pool);
    ast->rparen_token = rparen_token;
    if (statement)
        ast->statement = statement->clone(pool);
    return ast;
}

con's avatar
con committed
1636
1637
1638
1639
1640
1641
1642
1643
void ForStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(initializer, visitor);
        accept(condition, visitor);
        accept(expression, visitor);
        accept(statement, visitor);
    }
1644
    visitor->endVisit(this);
con's avatar
con committed
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
}

unsigned ForStatementAST::firstToken() const
{
    return for_token;
}

unsigned ForStatementAST::lastToken() const
{
    if (statement)
        return statement->lastToken();
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
    else if (rparen_token)
        return rparen_token + 1;
    else if (expression)
        return expression->lastToken();
    else if (semicolon_token)
        return semicolon_token + 1;
    else if (condition)
        return condition->lastToken();
    else if (initializer)
        return initializer->lastToken();
    else if (lparen_token)
        return lparen_token + 1;

    return for_token + 1;
con's avatar
con committed
1670
1671
}

1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
FunctionDeclaratorAST *FunctionDeclaratorAST::clone(MemoryPool *pool) const
{
    FunctionDeclaratorAST *ast = new (pool) FunctionDeclaratorAST;
    ast->lparen_token = lparen_token;
    if (parameters)
        ast->parameters = parameters->clone(pool);
    ast->rparen_token = rparen_token;
    if (cv_qualifier_seq)
        ast->cv_qualifier_seq = cv_qualifier_seq->clone(pool);
    if (exception_specification)
        ast->exception_specification = exception_specification->clone(pool);
    return ast;
}

con's avatar
con committed
1686
1687
1688
1689
void FunctionDeclaratorAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
1690
    visitor->endVisit(this);
con's avatar
con committed
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
}

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

unsigned FunctionDeclaratorAST::lastToken() const
{
    if (exception_specification)
        return exception_specification->lastToken();
1702
1703
1704
1705

    for (SpecifierAST *it = cv_qualifier_seq; it; it = it->next) {
        if (! it->next)
            return it->lastToken();
con's avatar
con committed
1706
    }
1707
1708
1709
1710
1711
1712
1713

    if (rparen_token)
        return rparen_token + 1;
    else if (parameters)
        return parameters->lastToken();

    return lparen_token + 1;
con's avatar
con committed
1714
1715
}

1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
FunctionDefinitionAST *FunctionDefinitionAST::clone(MemoryPool *pool) const
{
    FunctionDefinitionAST *ast = new (pool) FunctionDefinitionAST;
    if (decl_specifier_seq)
        ast->decl_specifier_seq = decl_specifier_seq->clone(pool);
    if (declarator)
        ast->declarator = declarator->clone(pool);
    if (ctor_initializer)
        ast->ctor_initializer = ctor_initializer->clone(pool);
    if (function_body)
        ast->function_body = function_body->clone(pool);
    return ast;
}

con's avatar
con committed
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
void FunctionDefinitionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (SpecifierAST *spec = decl_specifier_seq; spec;
                 spec = spec->next)
            accept(spec, visitor);
        accept(declarator, visitor);
        accept(ctor_initializer, visitor);
        accept(function_body, visitor);
    }
1740
    visitor->endVisit(this);
con's avatar
con committed
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
}

unsigned FunctionDefinitionAST::firstToken() const
{
    if (decl_specifier_seq)
        return decl_specifier_seq->firstToken();
    else if (declarator)
        return declarator->firstToken();
    else if (ctor_initializer)
        return ctor_initializer->firstToken();
    return function_body->firstToken();
}

unsigned FunctionDefinitionAST::lastToken() const
{
    if (