AST.h 111 KB
Newer Older
con's avatar
con committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
// 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.

#ifndef CPLUSPLUS_AST_H
#define CPLUSPLUS_AST_H

#include "CPlusPlusForwardDeclarations.h"
#include "ASTfwd.h"
Roberto Raggi's avatar
Roberto Raggi committed
26
#include "MemoryPool.h"
con's avatar
con committed
27

Roberto Raggi's avatar
Roberto Raggi committed
28
namespace CPlusPlus {
con's avatar
con committed
29

Roberto Raggi's avatar
Roberto Raggi committed
30
template <typename _Tp>
31
class CPLUSPLUS_EXPORT List: public Managed
Roberto Raggi's avatar
Roberto Raggi committed
32 33 34 35 36 37
{
    List(const List &other);
    void operator =(const List &other);

public:
    List()
38
        : value(_Tp()), next(0)
Roberto Raggi's avatar
Roberto Raggi committed
39 40
    { }

Roberto Raggi's avatar
Roberto Raggi committed
41 42 43 44
    List(const _Tp &value)
        : value(value), next(0)
    { }

45 46 47 48 49 50 51 52 53 54
    unsigned firstToken() const
    {
        if (value)
            return value->firstToken();

        // ### assert(0);
        return 0;
    }

    unsigned lastToken() const
55 56 57 58 59 60 61 62 63 64 65
    {
        _Tp lv = lastValue();

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

        // ### assert(0);
        return 0;
    }

    _Tp lastValue() const
66
    {
Roberto Raggi's avatar
Roberto Raggi committed
67
        _Tp lastValue = 0;
68 69 70

        for (const List *it = this; it; it = it->next) {
            if (it->value)
Roberto Raggi's avatar
Roberto Raggi committed
71
                lastValue = it->value;
72 73
        }

74
        return lastValue;
75
    }
76

Roberto Raggi's avatar
Roberto Raggi committed
77 78 79 80
    _Tp value;
    List *next;
};

Roberto Raggi's avatar
Roberto Raggi committed
81
class CPLUSPLUS_EXPORT AST: public Managed
con's avatar
con committed
82 83 84 85 86 87 88 89 90 91 92 93 94
{
    AST(const AST &other);
    void operator =(const AST &other);

public:
    AST();
    virtual ~AST();

    void accept(ASTVisitor *visitor);

    static void accept(AST *ast, ASTVisitor *visitor)
    { if (ast) ast->accept(visitor); }

95 96 97 98 99 100 101
    template <typename _Tp>
    static void accept(List<_Tp> *it, ASTVisitor *visitor)
    {
        for (; it; it = it->next)
            accept(it->value, visitor);
    }

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    static bool match(AST *ast, AST *pattern, ASTMatcher *matcher);
    bool match(AST *pattern, ASTMatcher *matcher);

    template <typename _Tp>
    static bool match(List<_Tp> *it, List<_Tp> *patternIt, ASTMatcher *matcher)
    {
        while (it && patternIt) {
            if (! match(it->value, patternIt->value, matcher))
                return false;

            it = it->next;
            patternIt = patternIt->next;
        }

        if (! it && ! patternIt)
            return true;

        return false;
    }

con's avatar
con committed
122 123 124
    virtual unsigned firstToken() const = 0;
    virtual unsigned lastToken() const = 0;

125 126
    virtual AST *clone(MemoryPool *pool) const = 0;

127 128 129 130 131 132 133 134 135 136
    virtual AccessDeclarationAST *asAccessDeclaration() { return 0; }
    virtual ArrayAccessAST *asArrayAccess() { return 0; }
    virtual ArrayDeclaratorAST *asArrayDeclarator() { return 0; }
    virtual ArrayInitializerAST *asArrayInitializer() { return 0; }
    virtual AsmDefinitionAST *asAsmDefinition() { return 0; }
    virtual AttributeAST *asAttribute() { return 0; }
    virtual AttributeSpecifierAST *asAttributeSpecifier() { return 0; }
    virtual BaseSpecifierAST *asBaseSpecifier() { return 0; }
    virtual BinaryExpressionAST *asBinaryExpression() { return 0; }
    virtual BoolLiteralAST *asBoolLiteral() { return 0; }
Roberto Raggi's avatar
Roberto Raggi committed
137
    virtual BracedInitializerAST *asBracedInitializer() { return 0; }
138 139
    virtual BreakStatementAST *asBreakStatement() { return 0; }
    virtual CallAST *asCall() { return 0; }
140
    virtual CaptureAST *asCapture() { return 0; }
141 142 143 144
    virtual CaseStatementAST *asCaseStatement() { return 0; }
    virtual CastExpressionAST *asCastExpression() { return 0; }
    virtual CatchClauseAST *asCatchClause() { return 0; }
    virtual ClassSpecifierAST *asClassSpecifier() { return 0; }
145
    virtual CompoundExpressionAST *asCompoundExpression() { return 0; }
146 147 148 149 150 151 152 153 154 155 156 157 158
    virtual CompoundLiteralAST *asCompoundLiteral() { return 0; }
    virtual CompoundStatementAST *asCompoundStatement() { return 0; }
    virtual ConditionAST *asCondition() { return 0; }
    virtual ConditionalExpressionAST *asConditionalExpression() { return 0; }
    virtual ContinueStatementAST *asContinueStatement() { return 0; }
    virtual ConversionFunctionIdAST *asConversionFunctionId() { return 0; }
    virtual CoreDeclaratorAST *asCoreDeclarator() { return 0; }
    virtual CppCastExpressionAST *asCppCastExpression() { return 0; }
    virtual CtorInitializerAST *asCtorInitializer() { return 0; }
    virtual DeclarationAST *asDeclaration() { return 0; }
    virtual DeclarationStatementAST *asDeclarationStatement() { return 0; }
    virtual DeclaratorAST *asDeclarator() { return 0; }
    virtual DeclaratorIdAST *asDeclaratorId() { return 0; }
159
    virtual DecltypeSpecifierAST *asDecltypeSpecifier() { return 0; }
160 161 162
    virtual DeleteExpressionAST *asDeleteExpression() { return 0; }
    virtual DestructorNameAST *asDestructorName() { return 0; }
    virtual DoStatementAST *asDoStatement() { return 0; }
163
    virtual DynamicExceptionSpecificationAST *asDynamicExceptionSpecification() { return 0; }
164 165 166 167 168 169 170 171 172 173
    virtual ElaboratedTypeSpecifierAST *asElaboratedTypeSpecifier() { return 0; }
    virtual EmptyDeclarationAST *asEmptyDeclaration() { return 0; }
    virtual EnumSpecifierAST *asEnumSpecifier() { return 0; }
    virtual EnumeratorAST *asEnumerator() { return 0; }
    virtual ExceptionDeclarationAST *asExceptionDeclaration() { return 0; }
    virtual ExceptionSpecificationAST *asExceptionSpecification() { return 0; }
    virtual ExpressionAST *asExpression() { return 0; }
    virtual ExpressionOrDeclarationStatementAST *asExpressionOrDeclarationStatement() { return 0; }
    virtual ExpressionStatementAST *asExpressionStatement() { return 0; }
    virtual ForStatementAST *asForStatement() { return 0; }
174
    virtual ForeachStatementAST *asForeachStatement() { return 0; }
175 176 177
    virtual FunctionDeclaratorAST *asFunctionDeclarator() { return 0; }
    virtual FunctionDefinitionAST *asFunctionDefinition() { return 0; }
    virtual GotoStatementAST *asGotoStatement() { return 0; }
Roberto Raggi's avatar
Roberto Raggi committed
178
    virtual IdExpressionAST *asIdExpression() { return 0; }
179 180
    virtual IfStatementAST *asIfStatement() { return 0; }
    virtual LabeledStatementAST *asLabeledStatement() { return 0; }
181 182 183 184
    virtual LambdaCaptureAST *asLambdaCapture() { return 0; }
    virtual LambdaDeclaratorAST *asLambdaDeclarator() { return 0; }
    virtual LambdaExpressionAST *asLambdaExpression() { return 0; }
    virtual LambdaIntroducerAST *asLambdaIntroducer() { return 0; }
185 186 187 188 189 190 191 192 193 194 195
    virtual LinkageBodyAST *asLinkageBody() { return 0; }
    virtual LinkageSpecificationAST *asLinkageSpecification() { return 0; }
    virtual MemInitializerAST *asMemInitializer() { return 0; }
    virtual MemberAccessAST *asMemberAccess() { return 0; }
    virtual NameAST *asName() { return 0; }
    virtual NamedTypeSpecifierAST *asNamedTypeSpecifier() { return 0; }
    virtual NamespaceAST *asNamespace() { return 0; }
    virtual NamespaceAliasDefinitionAST *asNamespaceAliasDefinition() { return 0; }
    virtual NestedDeclaratorAST *asNestedDeclarator() { return 0; }
    virtual NestedExpressionAST *asNestedExpression() { return 0; }
    virtual NestedNameSpecifierAST *asNestedNameSpecifier() { return 0; }
196
    virtual NewArrayDeclaratorAST *asNewArrayDeclarator() { return 0; }
197 198
    virtual NewExpressionAST *asNewExpression() { return 0; }
    virtual NewInitializerAST *asNewInitializer() { return 0; }
199
    virtual NewPlacementAST *asNewPlacement() { return 0; }
200
    virtual NewTypeIdAST *asNewTypeId() { return 0; }
201
    virtual NoExceptSpecificationAST *asNoExceptSpecification() { return 0; }
202
    virtual NumericLiteralAST *asNumericLiteral() { return 0; }
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
    virtual ObjCClassDeclarationAST *asObjCClassDeclaration() { return 0; }
    virtual ObjCClassForwardDeclarationAST *asObjCClassForwardDeclaration() { return 0; }
    virtual ObjCDynamicPropertiesDeclarationAST *asObjCDynamicPropertiesDeclaration() { return 0; }
    virtual ObjCEncodeExpressionAST *asObjCEncodeExpression() { return 0; }
    virtual ObjCFastEnumerationAST *asObjCFastEnumeration() { return 0; }
    virtual ObjCInstanceVariablesDeclarationAST *asObjCInstanceVariablesDeclaration() { return 0; }
    virtual ObjCMessageArgumentAST *asObjCMessageArgument() { return 0; }
    virtual ObjCMessageArgumentDeclarationAST *asObjCMessageArgumentDeclaration() { return 0; }
    virtual ObjCMessageExpressionAST *asObjCMessageExpression() { return 0; }
    virtual ObjCMethodDeclarationAST *asObjCMethodDeclaration() { return 0; }
    virtual ObjCMethodPrototypeAST *asObjCMethodPrototype() { return 0; }
    virtual ObjCPropertyAttributeAST *asObjCPropertyAttribute() { return 0; }
    virtual ObjCPropertyDeclarationAST *asObjCPropertyDeclaration() { return 0; }
    virtual ObjCProtocolDeclarationAST *asObjCProtocolDeclaration() { return 0; }
    virtual ObjCProtocolExpressionAST *asObjCProtocolExpression() { return 0; }
    virtual ObjCProtocolForwardDeclarationAST *asObjCProtocolForwardDeclaration() { return 0; }
    virtual ObjCProtocolRefsAST *asObjCProtocolRefs() { return 0; }
    virtual ObjCSelectorAST *asObjCSelector() { return 0; }
    virtual ObjCSelectorArgumentAST *asObjCSelectorArgument() { return 0; }
    virtual ObjCSelectorExpressionAST *asObjCSelectorExpression() { return 0; }
    virtual ObjCSynchronizedStatementAST *asObjCSynchronizedStatement() { return 0; }
    virtual ObjCSynthesizedPropertiesDeclarationAST *asObjCSynthesizedPropertiesDeclaration() { return 0; }
    virtual ObjCSynthesizedPropertyAST *asObjCSynthesizedProperty() { return 0; }
    virtual ObjCTypeNameAST *asObjCTypeName() { return 0; }
    virtual ObjCVisibilityDeclarationAST *asObjCVisibilityDeclaration() { return 0; }
228 229 230 231 232
    virtual OperatorAST *asOperator() { return 0; }
    virtual OperatorFunctionIdAST *asOperatorFunctionId() { return 0; }
    virtual ParameterDeclarationAST *asParameterDeclaration() { return 0; }
    virtual ParameterDeclarationClauseAST *asParameterDeclarationClause() { return 0; }
    virtual PointerAST *asPointer() { return 0; }
Leandro Melo's avatar
Leandro Melo committed
233
    virtual PointerLiteralAST *asPointerLiteral() { return 0; }
234 235 236 237 238
    virtual PointerToMemberAST *asPointerToMember() { return 0; }
    virtual PostIncrDecrAST *asPostIncrDecr() { return 0; }
    virtual PostfixAST *asPostfix() { return 0; }
    virtual PostfixDeclaratorAST *asPostfixDeclarator() { return 0; }
    virtual PtrOperatorAST *asPtrOperator() { return 0; }
239 240
    virtual QtEnumDeclarationAST *asQtEnumDeclaration() { return 0; }
    virtual QtFlagsDeclarationAST *asQtFlagsDeclaration() { return 0; }
241 242
    virtual QtInterfaceNameAST *asQtInterfaceName() { return 0; }
    virtual QtInterfacesDeclarationAST *asQtInterfacesDeclaration() { return 0; }
243
    virtual QtMemberDeclarationAST *asQtMemberDeclaration() { return 0; }
244
    virtual QtMethodAST *asQtMethod() { return 0; }
245 246
    virtual QtObjectTagAST *asQtObjectTag() { return 0; }
    virtual QtPrivateSlotAST *asQtPrivateSlot() { return 0; }
247
    virtual QtPropertyDeclarationAST *asQtPropertyDeclaration() { return 0; }
248
    virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return 0; }
249
    virtual QualifiedNameAST *asQualifiedName() { return 0; }
250
    virtual RangeBasedForStatementAST *asRangeBasedForStatement() { return 0; }
251 252 253 254 255 256 257 258
    virtual ReferenceAST *asReference() { return 0; }
    virtual ReturnStatementAST *asReturnStatement() { return 0; }
    virtual SimpleDeclarationAST *asSimpleDeclaration() { return 0; }
    virtual SimpleNameAST *asSimpleName() { return 0; }
    virtual SimpleSpecifierAST *asSimpleSpecifier() { return 0; }
    virtual SizeofExpressionAST *asSizeofExpression() { return 0; }
    virtual SpecifierAST *asSpecifier() { return 0; }
    virtual StatementAST *asStatement() { return 0; }
259
    virtual StaticAssertDeclarationAST *asStaticAssertDeclaration() { return 0; }
260 261 262 263 264 265 266
    virtual StringLiteralAST *asStringLiteral() { return 0; }
    virtual SwitchStatementAST *asSwitchStatement() { return 0; }
    virtual TemplateDeclarationAST *asTemplateDeclaration() { return 0; }
    virtual TemplateIdAST *asTemplateId() { return 0; }
    virtual TemplateTypeParameterAST *asTemplateTypeParameter() { return 0; }
    virtual ThisExpressionAST *asThisExpression() { return 0; }
    virtual ThrowExpressionAST *asThrowExpression() { return 0; }
267
    virtual TrailingReturnTypeAST *asTrailingReturnType() { return 0; }
268 269 270 271 272 273 274 275 276 277 278 279
    virtual TranslationUnitAST *asTranslationUnit() { return 0; }
    virtual TryBlockStatementAST *asTryBlockStatement() { return 0; }
    virtual TypeConstructorCallAST *asTypeConstructorCall() { return 0; }
    virtual TypeIdAST *asTypeId() { return 0; }
    virtual TypeidExpressionAST *asTypeidExpression() { return 0; }
    virtual TypenameCallExpressionAST *asTypenameCallExpression() { return 0; }
    virtual TypenameTypeParameterAST *asTypenameTypeParameter() { return 0; }
    virtual TypeofSpecifierAST *asTypeofSpecifier() { return 0; }
    virtual UnaryExpressionAST *asUnaryExpression() { return 0; }
    virtual UsingAST *asUsing() { return 0; }
    virtual UsingDirectiveAST *asUsingDirective() { return 0; }
    virtual WhileStatementAST *asWhileStatement() { return 0; }
280

con's avatar
con committed
281 282
protected:
    virtual void accept0(ASTVisitor *visitor) = 0;
283
    virtual bool match0(AST *, ASTMatcher *) = 0;
con's avatar
con committed
284 285
};

286 287 288
class CPLUSPLUS_EXPORT StatementAST: public AST
{
public:
289 290 291
    StatementAST()
    {}

292
    virtual StatementAST *asStatement() { return this; }
293 294

    virtual StatementAST *clone(MemoryPool *pool) const = 0;
295 296 297 298 299
};

class CPLUSPLUS_EXPORT ExpressionAST: public AST
{
public:
300 301 302
    ExpressionAST()
    {}

303
    virtual ExpressionAST *asExpression() { return this; }
304 305

    virtual ExpressionAST *clone(MemoryPool *pool) const = 0;
306 307 308 309 310
};

class CPLUSPLUS_EXPORT DeclarationAST: public AST
{
public:
311 312 313
    DeclarationAST()
    {}

314
    virtual DeclarationAST *asDeclaration() { return this; }
315 316

    virtual DeclarationAST *clone(MemoryPool *pool) const = 0;
317 318
};

Roberto Raggi's avatar
Roberto Raggi committed
319
class CPLUSPLUS_EXPORT NameAST: public AST
320 321
{
public: // annotations
Roberto Raggi's avatar
Roberto Raggi committed
322
    const Name *name;
323 324

public:
325 326 327 328
    NameAST()
        : name(0)
    {}

329
    virtual NameAST *asName() { return this; }
330 331

    virtual NameAST *clone(MemoryPool *pool) const = 0;
332 333
};

con's avatar
con committed
334 335
class CPLUSPLUS_EXPORT SpecifierAST: public AST
{
336
public:
337 338 339
    SpecifierAST()
    {}

340
    virtual SpecifierAST *asSpecifier() { return this; }
341 342

    virtual SpecifierAST *clone(MemoryPool *pool) const = 0;
con's avatar
con committed
343 344
};

345 346 347
class CPLUSPLUS_EXPORT PtrOperatorAST: public AST
{
public:
348 349 350
    PtrOperatorAST()
    {}

351
    virtual PtrOperatorAST *asPtrOperator() { return this; }
352 353

    virtual PtrOperatorAST *clone(MemoryPool *pool) const = 0;
354 355
};

356
class CPLUSPLUS_EXPORT PostfixAST: public ExpressionAST
357 358
{
public:
359 360 361
    PostfixAST()
    {}

362
    virtual PostfixAST *asPostfix() { return this; }
363 364

    virtual PostfixAST *clone(MemoryPool *pool) const = 0;
365 366 367 368 369
};

class CPLUSPLUS_EXPORT CoreDeclaratorAST: public AST
{
public:
370 371 372
    CoreDeclaratorAST()
    {}

373
    virtual CoreDeclaratorAST *asCoreDeclarator() { return this; }
374 375

    virtual CoreDeclaratorAST *clone(MemoryPool *pool) const = 0;
376 377 378 379 380
};

class CPLUSPLUS_EXPORT PostfixDeclaratorAST: public AST
{
public:
381 382 383
    PostfixDeclaratorAST()
    {}

384
    virtual PostfixDeclaratorAST *asPostfixDeclarator() { return this; }
385 386

    virtual PostfixDeclaratorAST *clone(MemoryPool *pool) const = 0;
387 388
};

389
class CPLUSPLUS_EXPORT ObjCSelectorArgumentAST: public AST
390
{
391 392 393 394 395
public:
    unsigned name_token;
    unsigned colon_token;

public:
396 397 398 399 400
    ObjCSelectorArgumentAST()
        : name_token(0)
        , colon_token(0)
    {}

401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
    virtual ObjCSelectorArgumentAST *asObjCSelectorArgument() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual ObjCSelectorArgumentAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

class CPLUSPLUS_EXPORT ObjCSelectorAST: public NameAST
{
public:
    ObjCSelectorArgumentListAST *selector_argument_list;
417 418

public:
419 420 421 422
    ObjCSelectorAST()
        : selector_argument_list(0)
    {}

423
    virtual ObjCSelectorAST *asObjCSelector() { return this; }
424

425 426 427 428 429 430 431 432
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual ObjCSelectorAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
433 434
};

con's avatar
con committed
435 436 437 438 439 440
class CPLUSPLUS_EXPORT SimpleSpecifierAST: public SpecifierAST
{
public:
    unsigned specifier_token;

public:
441 442 443 444
    SimpleSpecifierAST()
        : specifier_token(0)
    {}

445
    virtual SimpleSpecifierAST *asSimpleSpecifier() { return this; }
446

con's avatar
con committed
447 448 449
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

450 451
    virtual SimpleSpecifierAST *clone(MemoryPool *pool) const;

con's avatar
con committed
452 453
protected:
    virtual void accept0(ASTVisitor *visitor);
454
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
455 456 457 458 459 460 461 462
};

class CPLUSPLUS_EXPORT AttributeSpecifierAST: public SpecifierAST
{
public:
    unsigned attribute_token;
    unsigned first_lparen_token;
    unsigned second_lparen_token;
Roberto Raggi's avatar
Roberto Raggi committed
463
    AttributeListAST *attribute_list;
con's avatar
con committed
464 465 466 467
    unsigned first_rparen_token;
    unsigned second_rparen_token;

public:
468 469 470 471 472 473 474 475 476
    AttributeSpecifierAST()
        : attribute_token(0)
        , first_lparen_token(0)
        , second_lparen_token(0)
        , attribute_list(0)
        , first_rparen_token(0)
        , second_rparen_token(0)
    {}

477
    virtual AttributeSpecifierAST *asAttributeSpecifier() { return this; }
478

con's avatar
con committed
479 480 481
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

482 483
    virtual AttributeSpecifierAST *clone(MemoryPool *pool) const;

con's avatar
con committed
484 485
protected:
    virtual void accept0(ASTVisitor *visitor);
486
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
487 488 489 490 491 492 493 494 495 496 497 498
};

class CPLUSPLUS_EXPORT AttributeAST: public AST
{
public:
    unsigned identifier_token;
    unsigned lparen_token;
    unsigned tag_token;
    ExpressionListAST *expression_list;
    unsigned rparen_token;

public:
499 500 501 502 503 504 505 506
    AttributeAST()
        : identifier_token(0)
        , lparen_token(0)
        , tag_token(0)
        , expression_list(0)
        , rparen_token(0)
    {}

507
    virtual AttributeAST *asAttribute() { return this; }
508

con's avatar
con committed
509 510 511
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

512 513
    virtual AttributeAST *clone(MemoryPool *pool) const;

con's avatar
con committed
514 515
protected:
    virtual void accept0(ASTVisitor *visitor);
516
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
517 518 519 520 521 522
};

class CPLUSPLUS_EXPORT TypeofSpecifierAST: public SpecifierAST
{
public:
    unsigned typeof_token;
523
    unsigned lparen_token;
con's avatar
con committed
524
    ExpressionAST *expression;
525
    unsigned rparen_token;
con's avatar
con committed
526 527

public:
528 529 530 531 532 533 534
    TypeofSpecifierAST()
        : typeof_token(0)
        , lparen_token(0)
        , expression(0)
        , rparen_token(0)
    {}

535
    virtual TypeofSpecifierAST *asTypeofSpecifier() { return this; }
536

con's avatar
con committed
537 538 539
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

540 541
    virtual TypeofSpecifierAST *clone(MemoryPool *pool) const;

con's avatar
con committed
542 543
protected:
    virtual void accept0(ASTVisitor *visitor);
544
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
545 546
};

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
class CPLUSPLUS_EXPORT DecltypeSpecifierAST: public SpecifierAST
{
public:
    unsigned decltype_token;
    unsigned lparen_token;
    ExpressionAST *expression;
    unsigned rparen_token;

public:
    DecltypeSpecifierAST()
        : decltype_token(0)
        , lparen_token(0)
        , expression(0)
        , rparen_token(0)
    {}

    virtual DecltypeSpecifierAST *asDecltypeSpecifier() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual DecltypeSpecifierAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

con's avatar
con committed
575 576 577
class CPLUSPLUS_EXPORT DeclaratorAST: public AST
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
578 579
    SpecifierListAST *attribute_list;
    PtrOperatorListAST *ptr_operator_list;
con's avatar
con committed
580
    CoreDeclaratorAST *core_declarator;
Roberto Raggi's avatar
Roberto Raggi committed
581 582
    PostfixDeclaratorListAST *postfix_declarator_list;
    SpecifierListAST *post_attribute_list;
583
    unsigned equal_token;
con's avatar
con committed
584 585 586
    ExpressionAST *initializer;

public:
587 588 589 590 591 592
    DeclaratorAST()
        : attribute_list(0)
        , ptr_operator_list(0)
        , core_declarator(0)
        , postfix_declarator_list(0)
        , post_attribute_list(0)
593
        , equal_token(0)
594 595 596
        , initializer(0)
    {}

597
    virtual DeclaratorAST *asDeclarator() { return this; }
598

con's avatar
con committed
599 600 601
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

602 603
    virtual DeclaratorAST *clone(MemoryPool *pool) const;

con's avatar
con committed
604 605
protected:
    virtual void accept0(ASTVisitor *visitor);
606
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
607 608 609 610 611
};

class CPLUSPLUS_EXPORT SimpleDeclarationAST: public DeclarationAST
{
public:
612
    unsigned qt_invokable_token;
Roberto Raggi's avatar
Roberto Raggi committed
613 614
    SpecifierListAST *decl_specifier_list;
    DeclaratorListAST *declarator_list;
con's avatar
con committed
615 616
    unsigned semicolon_token;

Roberto Raggi's avatar
Roberto Raggi committed
617
public:
618
    List<Symbol *> *symbols;
Roberto Raggi's avatar
Roberto Raggi committed
619

con's avatar
con committed
620
public:
621 622 623 624 625 626 627 628
    SimpleDeclarationAST()
        : qt_invokable_token(0)
        , decl_specifier_list(0)
        , declarator_list(0)
        , semicolon_token(0)
        , symbols(0)
    {}

629
    virtual SimpleDeclarationAST *asSimpleDeclaration() { return this; }
630

con's avatar
con committed
631 632 633
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

634 635
    virtual SimpleDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
636 637
protected:
    virtual void accept0(ASTVisitor *visitor);
638
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
639 640 641 642 643 644 645 646
};

class CPLUSPLUS_EXPORT EmptyDeclarationAST: public DeclarationAST
{
public:
    unsigned semicolon_token;

public:
647 648 649 650
    EmptyDeclarationAST()
        : semicolon_token(0)
    {}

651
    virtual EmptyDeclarationAST *asEmptyDeclaration() { return this; }
652

con's avatar
con committed
653 654 655
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

656 657
    virtual EmptyDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
658 659
protected:
    virtual void accept0(ASTVisitor *visitor);
660
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
661 662 663 664 665 666 667 668 669 670
};

class CPLUSPLUS_EXPORT AccessDeclarationAST: public DeclarationAST
{
public:
    unsigned access_specifier_token;
    unsigned slots_token;
    unsigned colon_token;

public:
671 672 673 674 675 676
    AccessDeclarationAST()
        : access_specifier_token(0)
        , slots_token(0)
        , colon_token(0)
    {}

677
    virtual AccessDeclarationAST *asAccessDeclaration() { return this; }
678

con's avatar
con committed
679 680 681
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

682 683
    virtual AccessDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
684 685
protected:
    virtual void accept0(ASTVisitor *visitor);
686
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
687 688
};

689 690 691 692 693 694
class CPLUSPLUS_EXPORT QtObjectTagAST: public DeclarationAST
{
public:
    unsigned q_object_token;

public:
695 696 697 698
    QtObjectTagAST()
        : q_object_token(0)
    {}

699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
    virtual QtObjectTagAST *asQtObjectTag() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual QtObjectTagAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

class CPLUSPLUS_EXPORT QtPrivateSlotAST: public DeclarationAST
{
public:
    unsigned q_private_slot_token;
    unsigned lparen_token;
    unsigned dptr_token;
    unsigned dptr_lparen_token;
    unsigned dptr_rparen_token;
    unsigned comma_token;
Roberto Raggi's avatar
Roberto Raggi committed
720
    SpecifierListAST *type_specifier_list;
721 722 723 724
    DeclaratorAST *declarator;
    unsigned rparen_token;

public:
725 726 727 728 729 730 731
    QtPrivateSlotAST()
        : q_private_slot_token(0)
        , lparen_token(0)
        , dptr_token(0)
        , dptr_lparen_token(0)
        , dptr_rparen_token(0)
        , comma_token(0)
Roberto Raggi's avatar
Roberto Raggi committed
732
        , type_specifier_list(0)
733 734 735 736
        , declarator(0)
        , rparen_token(0)
    {}

737 738 739 740 741 742 743 744 745 746 747 748
    virtual QtPrivateSlotAST *asQtPrivateSlot() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual QtPrivateSlotAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

749 750 751 752
class QtPropertyDeclarationItemAST: public AST
{
public:
    unsigned item_name_token;
753
    ExpressionAST *expression;
754 755

public:
756 757 758 759 760
    QtPropertyDeclarationItemAST()
        : item_name_token(0)
        , expression(0)
    {}

761 762 763 764 765
    virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

766
    virtual QtPropertyDeclarationItemAST *clone(MemoryPool *pool) const;
767 768 769 770 771 772

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

773
class CPLUSPLUS_EXPORT QtPropertyDeclarationAST: public DeclarationAST
774 775 776 777
{
public:
    unsigned property_specifier_token;
    unsigned lparen_token;
778 779
    ExpressionAST *expression; // for Q_PRIVATE_PROPERTY(expression, ...)
    unsigned comma_token;
780
    ExpressionAST *type_id;
781
    NameAST *property_name;
Roberto Raggi's avatar
Roberto Raggi committed
782
    QtPropertyDeclarationItemListAST *property_declaration_item_list;
783 784 785
    unsigned rparen_token;

public:
786 787 788
    QtPropertyDeclarationAST()
        : property_specifier_token(0)
        , lparen_token(0)
789 790
        , expression(0)
        , comma_token(0)
791 792
        , type_id(0)
        , property_name(0)
Roberto Raggi's avatar
Roberto Raggi committed
793
        , property_declaration_item_list(0)
794 795 796
        , rparen_token(0)
    {}

797
    virtual QtPropertyDeclarationAST *asQtPropertyDeclaration() { return this; }
798 799 800 801

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

802
    virtual QtPropertyDeclarationAST *clone(MemoryPool *pool) const;
Wolfgang Beck's avatar
Wolfgang Beck committed
803

804 805 806 807 808
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

809
class CPLUSPLUS_EXPORT QtEnumDeclarationAST: public DeclarationAST
810 811 812 813
{
public:
    unsigned enum_specifier_token;
    unsigned lparen_token;
814
    NameListAST *enumerator_list;
815 816 817
    unsigned rparen_token;

public:
818 819 820 821 822 823 824
    QtEnumDeclarationAST()
        : enum_specifier_token(0)
        , lparen_token(0)
        , enumerator_list(0)
        , rparen_token(0)
    {}

825
    virtual QtEnumDeclarationAST *asQtEnumDeclaration() { return this; }
826 827 828 829

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

830
    virtual QtEnumDeclarationAST *clone(MemoryPool *pool) const;
Wolfgang Beck's avatar
Wolfgang Beck committed
831

832 833 834 835 836
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

837
class CPLUSPLUS_EXPORT QtFlagsDeclarationAST: public DeclarationAST
838 839 840 841
{
public:
    unsigned flags_specifier_token;
    unsigned lparen_token;
842
    NameListAST *flag_enums_list;
843 844 845
    unsigned rparen_token;

public:
846 847 848 849 850 851 852
    QtFlagsDeclarationAST()
        : flags_specifier_token(0)
        , lparen_token(0)
        , flag_enums_list(0)
        , rparen_token(0)
    {}

853
    virtual QtFlagsDeclarationAST *asQtFlagsDeclaration() { return this; }
854 855 856 857

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

858
    virtual QtFlagsDeclarationAST *clone(MemoryPool *pool) const;
Wolfgang Beck's avatar
Wolfgang Beck committed
859

860 861 862 863 864
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

865 866 867 868 869 870 871
class CPLUSPLUS_EXPORT QtInterfaceNameAST: public AST
{
public:
    NameAST *interface_name;
    NameListAST *constraint_list;

public:
872 873 874 875 876
    QtInterfaceNameAST()
        : interface_name(0)
        , constraint_list(0)
    {}

877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
    virtual QtInterfaceNameAST *asQtInterfaceName() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual QtInterfaceNameAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

class CPLUSPLUS_EXPORT QtInterfacesDeclarationAST: public DeclarationAST
{
public:
    unsigned interfaces_token;
    unsigned lparen_token;
    QtInterfaceNameListAST *interface_name_list;
    unsigned rparen_token;

public:
898 899 900 901 902 903 904
    QtInterfacesDeclarationAST()
        : interfaces_token(0)
        , lparen_token(0)
        , interface_name_list(0)
        , rparen_token(0)
    {}

905 906 907 908 909 910 911 912 913 914 915 916
    virtual QtInterfacesDeclarationAST *asQtInterfacesDeclaration() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual QtInterfacesDeclarationAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

con's avatar
con committed
917 918 919 920
class CPLUSPLUS_EXPORT AsmDefinitionAST: public DeclarationAST
{
public:
    unsigned asm_token;
921
    unsigned volatile_token;
con's avatar
con committed
922
    unsigned lparen_token;
923 924
    // ### string literals
    // ### asm operand list
con's avatar
con committed
925 926 927 928
    unsigned rparen_token;
    unsigned semicolon_token;

public:
929 930 931 932 933 934 935 936
    AsmDefinitionAST()
        : asm_token(0)
        , volatile_token(0)
        , lparen_token(0)
        , rparen_token(0)
        , semicolon_token(0)
    {}

937
    virtual AsmDefinitionAST *asAsmDefinition() { return this; }
938

con's avatar
con committed
939 940 941
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

942 943
    virtual AsmDefinitionAST *clone(MemoryPool *pool) const;

con's avatar
con committed
944 945
protected:
    virtual void accept0(ASTVisitor *visitor);
946
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
947 948 949 950 951
};

class CPLUSPLUS_EXPORT BaseSpecifierAST: public AST
{
public:
Roberto Raggi's avatar
cleanup  
Roberto Raggi committed
952 953
    unsigned virtual_token;
    unsigned access_specifier_token;
con's avatar
con committed
954 955
    NameAST *name;

Roberto Raggi's avatar
Roberto Raggi committed
956
public: // annotations
Roberto Raggi's avatar
Roberto Raggi committed
957
    BaseClass *symbol;
Roberto Raggi's avatar
Roberto Raggi committed
958

con's avatar
con committed
959
public:
960 961 962 963 964 965 966
    BaseSpecifierAST()
        : virtual_token(0)
        , access_specifier_token(0)
        , name(0)
        , symbol(0)
    {}

967
    virtual BaseSpecifierAST *asBaseSpecifier() { return this; }
968

con's avatar
con committed
969 970 971
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

972 973
    virtual BaseSpecifierAST *clone(MemoryPool *pool) const;

con's avatar
con committed
974 975
protected:
    virtual void accept0(ASTVisitor *visitor);
976
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
977 978
};

Roberto Raggi's avatar
Roberto Raggi committed
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
class CPLUSPLUS_EXPORT IdExpressionAST: public ExpressionAST
{
public:
    NameAST *name;

public:
    IdExpressionAST()
        : name(0)
    {}

    virtual IdExpressionAST *asIdExpression() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual IdExpressionAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

1001 1002 1003 1004
class CPLUSPLUS_EXPORT CompoundExpressionAST: public ExpressionAST
{
public:
    unsigned lparen_token;
1005
    CompoundStatementAST *statement;
1006 1007 1008
    unsigned rparen_token;

public:
1009 1010
    CompoundExpressionAST()
        : lparen_token(0)
1011
        , statement(0)
1012 1013 1014
        , rparen_token(0)
    {}

1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
    virtual CompoundExpressionAST *asCompoundExpression() { return this; }

    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

    virtual CompoundExpressionAST *clone(MemoryPool *pool) const;

protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

1027 1028 1029 1030 1031 1032 1033 1034 1035
class CPLUSPLUS_EXPORT CompoundLiteralAST: public ExpressionAST
{
public:
    unsigned lparen_token;
    ExpressionAST *type_id;
    unsigned rparen_token;
    ExpressionAST *initializer;

public:
1036 1037 1038 1039 1040 1041 1042
    CompoundLiteralAST()
        : lparen_token(0)
        , type_id(0)
        , rparen_token(0)
        , initializer(0)
    {}

1043
    virtual CompoundLiteralAST *asCompoundLiteral() { return this; }
1044

1045 1046 1047
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

1048 1049
    virtual CompoundLiteralAST *clone(MemoryPool *pool) const;

1050 1051
protected:
    virtual void accept0(ASTVisitor *visitor);
1052
    virtual bool match0(AST *, ASTMatcher *);
1053 1054
};

con's avatar
con committed
1055 1056 1057 1058 1059 1060 1061 1062 1063
class CPLUSPLUS_EXPORT QtMethodAST: public ExpressionAST
{
public:
    unsigned method_token;
    unsigned lparen_token;
    DeclaratorAST *declarator;
    unsigned rparen_token;

public:
1064 1065 1066 1067 1068 1069 1070
    QtMethodAST()
        : method_token(0)
        , lparen_token(0)
        , declarator(0)
        , rparen_token(0)
    {}

1071
    virtual QtMethodAST *asQtMethod() { return this; }
1072

con's avatar
con committed
1073 1074 1075
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

1076 1077
    virtual QtMethodAST *clone(MemoryPool *pool) const;

con's avatar
con committed
1078 1079
protected:
    virtual void accept0(ASTVisitor *visitor);
1080
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
1081 1082
};