AST.cpp 98.5 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 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); }

AccessDeclarationAST *AST::asAccessDeclaration()
{ return dynamic_cast<AccessDeclarationAST *>(this); }

ArrayAccessAST *AST::asArrayAccess()
{ return dynamic_cast<ArrayAccessAST *>(this); }

ArrayDeclaratorAST *AST::asArrayDeclarator()
{ return dynamic_cast<ArrayDeclaratorAST *>(this); }

ArrayInitializerAST *AST::asArrayInitializer()
{ return dynamic_cast<ArrayInitializerAST *>(this); }

AsmDefinitionAST *AST::asAsmDefinition()
{ return dynamic_cast<AsmDefinitionAST *>(this); }

AttributeAST *AST::asAttribute()
{ return dynamic_cast<AttributeAST *>(this); }

AttributeSpecifierAST *AST::asAttributeSpecifier()
{ return dynamic_cast<AttributeSpecifierAST *>(this); }

BaseSpecifierAST *AST::asBaseSpecifier()
{ return dynamic_cast<BaseSpecifierAST *>(this); }

QtMethodAST *AST::asQtMethod()
{ return dynamic_cast<QtMethodAST *>(this); }

BinaryExpressionAST *AST::asBinaryExpression()
{ return dynamic_cast<BinaryExpressionAST *>(this); }

BoolLiteralAST *AST::asBoolLiteral()
{ return dynamic_cast<BoolLiteralAST *>(this); }

BreakStatementAST *AST::asBreakStatement()
{ return dynamic_cast<BreakStatementAST *>(this); }

CallAST *AST::asCall()
{ return dynamic_cast<CallAST *>(this); }

CaseStatementAST *AST::asCaseStatement()
{ return dynamic_cast<CaseStatementAST *>(this); }

CastExpressionAST *AST::asCastExpression()
{ return dynamic_cast<CastExpressionAST *>(this); }

CatchClauseAST *AST::asCatchClause()
{ return dynamic_cast<CatchClauseAST *>(this); }

ClassSpecifierAST *AST::asClassSpecifier()
{ return dynamic_cast<ClassSpecifierAST *>(this); }

120
121
122
CompoundLiteralAST *AST::asCompoundLiteral()
{ return dynamic_cast<CompoundLiteralAST *>(this); }

con's avatar
con committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
CompoundStatementAST *AST::asCompoundStatement()
{ return dynamic_cast<CompoundStatementAST *>(this); }

ConditionAST *AST::asCondition()
{ return dynamic_cast<ConditionAST *>(this); }

ConditionalExpressionAST *AST::asConditionalExpression()
{ return dynamic_cast<ConditionalExpressionAST *>(this); }

ContinueStatementAST *AST::asContinueStatement()
{ return dynamic_cast<ContinueStatementAST *>(this); }

ConversionFunctionIdAST *AST::asConversionFunctionId()
{ return dynamic_cast<ConversionFunctionIdAST *>(this); }

CoreDeclaratorAST *AST::asCoreDeclarator()
{ return dynamic_cast<CoreDeclaratorAST *>(this); }

CppCastExpressionAST *AST::asCppCastExpression()
{ return dynamic_cast<CppCastExpressionAST *>(this); }

CtorInitializerAST *AST::asCtorInitializer()
{ return dynamic_cast<CtorInitializerAST *>(this); }

DeclarationAST *AST::asDeclaration()
{ return dynamic_cast<DeclarationAST *>(this); }

DeclarationStatementAST *AST::asDeclarationStatement()
{ return dynamic_cast<DeclarationStatementAST *>(this); }

DeclaratorAST *AST::asDeclarator()
{ return dynamic_cast<DeclaratorAST *>(this); }

DeclaratorIdAST *AST::asDeclaratorId()
{ return dynamic_cast<DeclaratorIdAST *>(this); }

DeclaratorListAST *AST::asDeclaratorList()
{ return dynamic_cast<DeclaratorListAST *>(this); }

DeleteExpressionAST *AST::asDeleteExpression()
{ return dynamic_cast<DeleteExpressionAST *>(this); }

DestructorNameAST *AST::asDestructorName()
{ return dynamic_cast<DestructorNameAST *>(this); }

DoStatementAST *AST::asDoStatement()
{ return dynamic_cast<DoStatementAST *>(this); }

ElaboratedTypeSpecifierAST *AST::asElaboratedTypeSpecifier()
{ return dynamic_cast<ElaboratedTypeSpecifierAST *>(this); }

EmptyDeclarationAST *AST::asEmptyDeclaration()
{ return dynamic_cast<EmptyDeclarationAST *>(this); }

EnumSpecifierAST *AST::asEnumSpecifier()
{ return dynamic_cast<EnumSpecifierAST *>(this); }

EnumeratorAST *AST::asEnumerator()
{ return dynamic_cast<EnumeratorAST *>(this); }

ExceptionDeclarationAST *AST::asExceptionDeclaration()
{ return dynamic_cast<ExceptionDeclarationAST *>(this); }

ExceptionSpecificationAST *AST::asExceptionSpecification()
{ return dynamic_cast<ExceptionSpecificationAST *>(this); }

ExpressionAST *AST::asExpression()
{ return dynamic_cast<ExpressionAST *>(this); }

ExpressionListAST *AST::asExpressionList()
{ return dynamic_cast<ExpressionListAST *>(this); }

ExpressionOrDeclarationStatementAST *AST::asExpressionOrDeclarationStatement()
{ return dynamic_cast<ExpressionOrDeclarationStatementAST *>(this); }

ExpressionStatementAST *AST::asExpressionStatement()
{ return dynamic_cast<ExpressionStatementAST *>(this); }

ForStatementAST *AST::asForStatement()
{ return dynamic_cast<ForStatementAST *>(this); }

FunctionDeclaratorAST *AST::asFunctionDeclarator()
{ return dynamic_cast<FunctionDeclaratorAST *>(this); }

FunctionDefinitionAST *AST::asFunctionDefinition()
{ return dynamic_cast<FunctionDefinitionAST *>(this); }

GotoStatementAST *AST::asGotoStatement()
{ return dynamic_cast<GotoStatementAST *>(this); }

IfStatementAST *AST::asIfStatement()
{ return dynamic_cast<IfStatementAST *>(this); }

LabeledStatementAST *AST::asLabeledStatement()
{ return dynamic_cast<LabeledStatementAST *>(this); }

LinkageBodyAST *AST::asLinkageBody()
{ return dynamic_cast<LinkageBodyAST *>(this); }

LinkageSpecificationAST *AST::asLinkageSpecification()
{ return dynamic_cast<LinkageSpecificationAST *>(this); }

MemInitializerAST *AST::asMemInitializer()
{ return dynamic_cast<MemInitializerAST *>(this); }

MemberAccessAST *AST::asMemberAccess()
{ return dynamic_cast<MemberAccessAST *>(this); }

NameAST *AST::asName()
{ return dynamic_cast<NameAST *>(this); }

NamedTypeSpecifierAST *AST::asNamedTypeSpecifier()
{ return dynamic_cast<NamedTypeSpecifierAST *>(this); }

NamespaceAST *AST::asNamespace()
{ return dynamic_cast<NamespaceAST *>(this); }

NamespaceAliasDefinitionAST *AST::asNamespaceAliasDefinition()
{ return dynamic_cast<NamespaceAliasDefinitionAST *>(this); }

NestedDeclaratorAST *AST::asNestedDeclarator()
{ return dynamic_cast<NestedDeclaratorAST *>(this); }

NestedExpressionAST *AST::asNestedExpression()
{ return dynamic_cast<NestedExpressionAST *>(this); }

NestedNameSpecifierAST *AST::asNestedNameSpecifier()
{ return dynamic_cast<NestedNameSpecifierAST *>(this); }

NewDeclaratorAST *AST::asNewDeclarator()
{ return dynamic_cast<NewDeclaratorAST *>(this); }

NewExpressionAST *AST::asNewExpression()
{ return dynamic_cast<NewExpressionAST *>(this); }

NewInitializerAST *AST::asNewInitializer()
{ return dynamic_cast<NewInitializerAST *>(this); }

NewTypeIdAST *AST::asNewTypeId()
{ return dynamic_cast<NewTypeIdAST *>(this); }

NumericLiteralAST *AST::asNumericLiteral()
{ return dynamic_cast<NumericLiteralAST *>(this); }

OperatorAST *AST::asOperator()
{ return dynamic_cast<OperatorAST *>(this); }

OperatorFunctionIdAST *AST::asOperatorFunctionId()
{ return dynamic_cast<OperatorFunctionIdAST *>(this); }

ParameterDeclarationAST *AST::asParameterDeclaration()
{ return dynamic_cast<ParameterDeclarationAST *>(this); }

ParameterDeclarationClauseAST *AST::asParameterDeclarationClause()
{ return dynamic_cast<ParameterDeclarationClauseAST *>(this); }

PointerAST *AST::asPointer()
{ return dynamic_cast<PointerAST *>(this); }

PointerToMemberAST *AST::asPointerToMember()
{ return dynamic_cast<PointerToMemberAST *>(this); }

PostIncrDecrAST *AST::asPostIncrDecr()
{ return dynamic_cast<PostIncrDecrAST *>(this); }

PostfixAST *AST::asPostfix()
{ return dynamic_cast<PostfixAST *>(this); }

PostfixDeclaratorAST *AST::asPostfixDeclarator()
{ return dynamic_cast<PostfixDeclaratorAST *>(this); }

PostfixExpressionAST *AST::asPostfixExpression()
{ return dynamic_cast<PostfixExpressionAST *>(this); }

PtrOperatorAST *AST::asPtrOperator()
{ return dynamic_cast<PtrOperatorAST *>(this); }

QualifiedNameAST *AST::asQualifiedName()
{ return dynamic_cast<QualifiedNameAST *>(this); }

ReferenceAST *AST::asReference()
{ return dynamic_cast<ReferenceAST *>(this); }

ReturnStatementAST *AST::asReturnStatement()
{ return dynamic_cast<ReturnStatementAST *>(this); }

SimpleDeclarationAST *AST::asSimpleDeclaration()
{ return dynamic_cast<SimpleDeclarationAST *>(this); }

SimpleNameAST *AST::asSimpleName()
{ return dynamic_cast<SimpleNameAST *>(this); }

SimpleSpecifierAST *AST::asSimpleSpecifier()
{ return dynamic_cast<SimpleSpecifierAST *>(this); }

SizeofExpressionAST *AST::asSizeofExpression()
{ return dynamic_cast<SizeofExpressionAST *>(this); }

SpecifierAST *AST::asSpecifier()
{ return dynamic_cast<SpecifierAST *>(this); }

StatementAST *AST::asStatement()
{ return dynamic_cast<StatementAST *>(this); }

StringLiteralAST *AST::asStringLiteral()
{ return dynamic_cast<StringLiteralAST *>(this); }

SwitchStatementAST *AST::asSwitchStatement()
{ return dynamic_cast<SwitchStatementAST *>(this); }

TemplateArgumentListAST *AST::asTemplateArgumentList()
{ return dynamic_cast<TemplateArgumentListAST *>(this); }

TemplateDeclarationAST *AST::asTemplateDeclaration()
{ return dynamic_cast<TemplateDeclarationAST *>(this); }

TemplateIdAST *AST::asTemplateId()
{ return dynamic_cast<TemplateIdAST *>(this); }

TemplateTypeParameterAST *AST::asTemplateTypeParameter()
{ return dynamic_cast<TemplateTypeParameterAST *>(this); }

ThisExpressionAST *AST::asThisExpression()
{ return dynamic_cast<ThisExpressionAST *>(this); }

ThrowExpressionAST *AST::asThrowExpression()
{ return dynamic_cast<ThrowExpressionAST *>(this); }

TranslationUnitAST *AST::asTranslationUnit()
{ return dynamic_cast<TranslationUnitAST *>(this); }

TryBlockStatementAST *AST::asTryBlockStatement()
{ return dynamic_cast<TryBlockStatementAST *>(this); }

TypeConstructorCallAST *AST::asTypeConstructorCall()
{ return dynamic_cast<TypeConstructorCallAST *>(this); }

TypeIdAST *AST::asTypeId()
{ return dynamic_cast<TypeIdAST *>(this); }

TypeidExpressionAST *AST::asTypeidExpression()
{ return dynamic_cast<TypeidExpressionAST *>(this); }

TypenameCallExpressionAST *AST::asTypenameCallExpression()
{ return dynamic_cast<TypenameCallExpressionAST *>(this); }

TypenameTypeParameterAST *AST::asTypenameTypeParameter()
{ return dynamic_cast<TypenameTypeParameterAST *>(this); }

TypeofSpecifierAST *AST::asTypeofSpecifier()
{ return dynamic_cast<TypeofSpecifierAST *>(this); }

UnaryExpressionAST *AST::asUnaryExpression()
{ return dynamic_cast<UnaryExpressionAST *>(this); }

UsingAST *AST::asUsing()
{ return dynamic_cast<UsingAST *>(this); }

UsingDirectiveAST *AST::asUsingDirective()
{ return dynamic_cast<UsingDirectiveAST *>(this); }

WhileStatementAST *AST::asWhileStatement()
{ return dynamic_cast<WhileStatementAST *>(this); }

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();
407
408
409
410
411
    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
412
413
}

414
415
416
417
418
419
420
421
422
423
424
425
426
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
void AttributeSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (AttributeAST *attr = attributes; attr; attr = attr->next)
            accept(attr, visitor);
    }
}

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

unsigned AttributeAST::lastToken() const
{
442
443
444
445
446
447
448
449
450
451
452
    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
453
        return tag_token + 1;
454
455
456
457

    if (lparen_token)
        return lparen_token + 1;

con's avatar
con committed
458
459
460
    return identifier_token + 1;
}

461
462
463
464
465
466
467
468
469
470
471
472
473
474
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
475
476
477
478
479
480
481
482
void AttributeAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (ExpressionListAST *it = expression_list; it; it = it->next)
            accept(it->expression, visitor);
    }
}

483
484
485
486
487
488
489
490
491
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
492
493
494
495
496
497
498
499
500
501
502
503
504
void AccessDeclarationAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
}

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

unsigned AccessDeclarationAST::lastToken() const
{
505
506
507
508
509
    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
510
511
}

512
513
514
515
516
517
518
519
520
521
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
void ArrayAccessAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(expression, visitor);
    }
}

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

unsigned ArrayAccessAST::lastToken() const
{
536
537
538
539
540
    if (rbracket_token)
        return rbracket_token + 1;
    else if (expression)
        return expression->lastToken();
    return lbracket_token + 1;
con's avatar
con committed
541
542
}

543
544
545
546
547
548
549
550
551
552
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
553
554
555
556
557
558
559
560
561
562
563
564
565
566
void ArrayDeclaratorAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(this->expression, visitor);
    }
}

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

unsigned ArrayDeclaratorAST::lastToken() const
{
567
568
569
570
571
    if (rbracket_token)
        return rbracket_token + 1;
    else if (expression)
        return expression->lastToken();
    return lbracket_token + 1;
con's avatar
con committed
572
573
}

574
575
576
577
578
579
580
581
582
583
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
584
585
586
void ArrayInitializerAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
587
        for (ExpressionListAST *expr = expression_list; expr; expr = expr->next)
con's avatar
con committed
588
589
590
591
592
593
594
595
596
597
598
            accept(expr->expression, visitor);
    }
}

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

unsigned ArrayInitializerAST::lastToken() const
{
599
600
601
602
603
604
605
606
607
    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
608
609
}

610
611
612
613
AsmDefinitionAST *AsmDefinitionAST::clone(MemoryPool *pool) const
{
    AsmDefinitionAST *ast = new (pool) AsmDefinitionAST;
    ast->asm_token = asm_token;
614
    ast->volatile_token = volatile_token;
615
616
617
618
619
620
    ast->lparen_token = lparen_token;
    ast->rparen_token = rparen_token;
    ast->semicolon_token = semicolon_token;
    return ast;
}

con's avatar
con committed
621
622
623
void AsmDefinitionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
624
        // ### accept the asm operand list.
con's avatar
con committed
625
626
627
628
629
630
631
632
633
634
    }
}

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

unsigned AsmDefinitionAST::lastToken() const
{
635
636
637
638
639
640
    if (semicolon_token)
        return semicolon_token + 1;
    else if (rparen_token)
        return rparen_token + 1;
    else if (lparen_token)
        return lparen_token + 1;
641
642
    else if (volatile_token)
        return volatile_token + 1;
643
    return asm_token + 1;
con's avatar
con committed
644
645
}

646
647
648
649
650
651
652
653
654
655
656
657
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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
void BaseSpecifierAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(name, visitor);
    }
}

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
{
674
675
676
677
678
679
680
681
682
683
    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
684
685
686
687
688
689
690
}

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

unsigned QtMethodAST::lastToken() const
{
691
692
693
694
695
696
697
    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
698
699
}

700
701
702
703
704
705
706
707
708
709
710
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
711
712
713
714
715
716
717
void QtMethodAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(declarator, visitor);
    }
}

718
719
720
721
722
723
724
725
726
727
728
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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
void BinaryExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(left_expression, visitor);
        accept(right_expression, visitor);
    }
}

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

unsigned BinaryExpressionAST::lastToken() const
{
744
745
746
747
748
    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
749
750
}

751
752
753
754
755
756
757
BoolLiteralAST *BoolLiteralAST::clone(MemoryPool *pool) const
{
    BoolLiteralAST *ast = new (pool) BoolLiteralAST;
    ast->token = token;
    return ast;
}

con's avatar
con committed
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
void BoolLiteralAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
}

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

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

774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
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);
    }
}

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

810
811
812
813
814
815
816
817
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
818
819
820
821
822
823
824
825
826
827
828
829
830
void BreakStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
}

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

unsigned BreakStatementAST::lastToken() const
{
831
832
833
    if (semicolon_token)
        return semicolon_token + 1;
    return break_token + 1;
con's avatar
con committed
834
835
}

836
837
838
839
840
841
842
843
844
845
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
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
void CallAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (ExpressionListAST *expr = expression_list;
                 expr; expr = expr->next)
            accept(expr->expression, visitor);
    }
}

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

unsigned CallAST::lastToken() const
{
862
863
864
865
866
867
868
    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
869
870
}

871
872
873
874
875
876
877
878
879
880
881
882
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
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
void CaseStatementAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
}

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

unsigned CaseStatementAST::lastToken() const
{
    if (statement)
        return statement->lastToken();
898
899
900
901
902
    else if (colon_token)
        return colon_token + 1;
    else if (expression)
        return expression->lastToken();
    return case_token + 1;
con's avatar
con committed
903
904
}

905
906
907
908
909
910
911
912
913
914
915
916
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
917
918
919
920
921
922
923
924
925
926
927
928
929
void CastExpressionAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
}

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

unsigned CastExpressionAST::lastToken() const
{
930
931
932
933
934
935
936
    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
937
938
}

939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
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
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
void CatchClauseAST::accept0(ASTVisitor *visitor)
{
    if (visitor->visit(this)) {
        accept(exception_declaration, visitor);
        accept(statement, visitor);
    }
}

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

unsigned CatchClauseAST::lastToken() const
{
    if (statement)
        return statement->lastToken();
971
972
973
974
975
976
977
978
979
980
    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
981
982
}

983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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;
}