AST.h 109 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 159 160 161
    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; }
    virtual DeleteExpressionAST *asDeleteExpression() { return 0; }
    virtual DestructorNameAST *asDestructorName() { return 0; }
    virtual DoStatementAST *asDoStatement() { return 0; }
162
    virtual DynamicExceptionSpecificationAST *asDynamicExceptionSpecification() { return 0; }
163 164 165 166 167 168 169 170 171 172
    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; }
173
    virtual ForeachStatementAST *asForeachStatement() { return 0; }
174 175 176
    virtual FunctionDeclaratorAST *asFunctionDeclarator() { return 0; }
    virtual FunctionDefinitionAST *asFunctionDefinition() { return 0; }
    virtual GotoStatementAST *asGotoStatement() { return 0; }
Roberto Raggi's avatar
Roberto Raggi committed
177
    virtual IdExpressionAST *asIdExpression() { return 0; }
178 179
    virtual IfStatementAST *asIfStatement() { return 0; }
    virtual LabeledStatementAST *asLabeledStatement() { return 0; }
180 181 182 183
    virtual LambdaCaptureAST *asLambdaCapture() { return 0; }
    virtual LambdaDeclaratorAST *asLambdaDeclarator() { return 0; }
    virtual LambdaExpressionAST *asLambdaExpression() { return 0; }
    virtual LambdaIntroducerAST *asLambdaIntroducer() { return 0; }
184 185 186 187 188 189 190 191 192 193 194
    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; }
195
    virtual NewArrayDeclaratorAST *asNewArrayDeclarator() { return 0; }
196 197
    virtual NewExpressionAST *asNewExpression() { return 0; }
    virtual NewInitializerAST *asNewInitializer() { return 0; }
198
    virtual NewPlacementAST *asNewPlacement() { return 0; }
199
    virtual NewTypeIdAST *asNewTypeId() { return 0; }
200
    virtual NoExceptSpecificationAST *asNoExceptSpecification() { return 0; }
201
    virtual NumericLiteralAST *asNumericLiteral() { return 0; }
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
    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; }
227 228 229 230 231
    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
232
    virtual PointerLiteralAST *asPointerLiteral() { return 0; }
233 234 235 236 237
    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; }
238 239
    virtual QtEnumDeclarationAST *asQtEnumDeclaration() { return 0; }
    virtual QtFlagsDeclarationAST *asQtFlagsDeclaration() { return 0; }
240 241
    virtual QtInterfaceNameAST *asQtInterfaceName() { return 0; }
    virtual QtInterfacesDeclarationAST *asQtInterfacesDeclaration() { return 0; }
242
    virtual QtMemberDeclarationAST *asQtMemberDeclaration() { return 0; }
243
    virtual QtMethodAST *asQtMethod() { return 0; }
244 245
    virtual QtObjectTagAST *asQtObjectTag() { return 0; }
    virtual QtPrivateSlotAST *asQtPrivateSlot() { return 0; }
246
    virtual QtPropertyDeclarationAST *asQtPropertyDeclaration() { return 0; }
247
    virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return 0; }
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    virtual QualifiedNameAST *asQualifiedName() { return 0; }
    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; }
    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; }
264
    virtual TrailingReturnTypeAST *asTrailingReturnType() { return 0; }
265 266 267 268 269 270 271 272 273 274 275 276
    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; }
277

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

283 284 285
class CPLUSPLUS_EXPORT StatementAST: public AST
{
public:
286 287 288
    StatementAST()
    {}

289
    virtual StatementAST *asStatement() { return this; }
290 291

    virtual StatementAST *clone(MemoryPool *pool) const = 0;
292 293 294 295 296
};

class CPLUSPLUS_EXPORT ExpressionAST: public AST
{
public:
297 298 299
    ExpressionAST()
    {}

300
    virtual ExpressionAST *asExpression() { return this; }
301 302

    virtual ExpressionAST *clone(MemoryPool *pool) const = 0;
303 304 305 306 307
};

class CPLUSPLUS_EXPORT DeclarationAST: public AST
{
public:
308 309 310
    DeclarationAST()
    {}

311
    virtual DeclarationAST *asDeclaration() { return this; }
312 313

    virtual DeclarationAST *clone(MemoryPool *pool) const = 0;
314 315
};

Roberto Raggi's avatar
Roberto Raggi committed
316
class CPLUSPLUS_EXPORT NameAST: public AST
317 318
{
public: // annotations
Roberto Raggi's avatar
Roberto Raggi committed
319
    const Name *name;
320 321

public:
322 323 324 325
    NameAST()
        : name(0)
    {}

326
    virtual NameAST *asName() { return this; }
327 328

    virtual NameAST *clone(MemoryPool *pool) const = 0;
329 330
};

con's avatar
con committed
331 332
class CPLUSPLUS_EXPORT SpecifierAST: public AST
{
333
public:
334 335 336
    SpecifierAST()
    {}

337
    virtual SpecifierAST *asSpecifier() { return this; }
338 339

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

342 343 344
class CPLUSPLUS_EXPORT PtrOperatorAST: public AST
{
public:
345 346 347
    PtrOperatorAST()
    {}

348
    virtual PtrOperatorAST *asPtrOperator() { return this; }
349 350

    virtual PtrOperatorAST *clone(MemoryPool *pool) const = 0;
351 352
};

353
class CPLUSPLUS_EXPORT PostfixAST: public ExpressionAST
354 355
{
public:
356 357 358
    PostfixAST()
    {}

359
    virtual PostfixAST *asPostfix() { return this; }
360 361

    virtual PostfixAST *clone(MemoryPool *pool) const = 0;
362 363 364 365 366
};

class CPLUSPLUS_EXPORT CoreDeclaratorAST: public AST
{
public:
367 368 369
    CoreDeclaratorAST()
    {}

370
    virtual CoreDeclaratorAST *asCoreDeclarator() { return this; }
371 372

    virtual CoreDeclaratorAST *clone(MemoryPool *pool) const = 0;
373 374 375 376 377
};

class CPLUSPLUS_EXPORT PostfixDeclaratorAST: public AST
{
public:
378 379 380
    PostfixDeclaratorAST()
    {}

381
    virtual PostfixDeclaratorAST *asPostfixDeclarator() { return this; }
382 383

    virtual PostfixDeclaratorAST *clone(MemoryPool *pool) const = 0;
384 385
};

386
class CPLUSPLUS_EXPORT ObjCSelectorArgumentAST: public AST
387
{
388 389 390 391 392
public:
    unsigned name_token;
    unsigned colon_token;

public:
393 394 395 396 397
    ObjCSelectorArgumentAST()
        : name_token(0)
        , colon_token(0)
    {}

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
    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;
414 415

public:
416 417 418 419
    ObjCSelectorAST()
        : selector_argument_list(0)
    {}

420
    virtual ObjCSelectorAST *asObjCSelector() { return this; }
421

422 423 424 425 426 427 428 429
    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 *);
430 431
};

con's avatar
con committed
432 433 434 435 436 437
class CPLUSPLUS_EXPORT SimpleSpecifierAST: public SpecifierAST
{
public:
    unsigned specifier_token;

public:
438 439 440 441
    SimpleSpecifierAST()
        : specifier_token(0)
    {}

442
    virtual SimpleSpecifierAST *asSimpleSpecifier() { return this; }
443

con's avatar
con committed
444 445 446
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

447 448
    virtual SimpleSpecifierAST *clone(MemoryPool *pool) const;

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

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
460
    AttributeListAST *attribute_list;
con's avatar
con committed
461 462 463 464
    unsigned first_rparen_token;
    unsigned second_rparen_token;

public:
465 466 467 468 469 470 471 472 473
    AttributeSpecifierAST()
        : attribute_token(0)
        , first_lparen_token(0)
        , second_lparen_token(0)
        , attribute_list(0)
        , first_rparen_token(0)
        , second_rparen_token(0)
    {}

474
    virtual AttributeSpecifierAST *asAttributeSpecifier() { return this; }
475

con's avatar
con committed
476 477 478
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

479 480
    virtual AttributeSpecifierAST *clone(MemoryPool *pool) const;

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

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

public:
496 497 498 499 500 501 502 503
    AttributeAST()
        : identifier_token(0)
        , lparen_token(0)
        , tag_token(0)
        , expression_list(0)
        , rparen_token(0)
    {}

504
    virtual AttributeAST *asAttribute() { return this; }
505

con's avatar
con committed
506 507 508
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

509 510
    virtual AttributeAST *clone(MemoryPool *pool) const;

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

class CPLUSPLUS_EXPORT TypeofSpecifierAST: public SpecifierAST
{
public:
    unsigned typeof_token;
520
    unsigned lparen_token;
con's avatar
con committed
521
    ExpressionAST *expression;
522
    unsigned rparen_token;
con's avatar
con committed
523 524

public:
525 526 527 528 529 530 531
    TypeofSpecifierAST()
        : typeof_token(0)
        , lparen_token(0)
        , expression(0)
        , rparen_token(0)
    {}

532
    virtual TypeofSpecifierAST *asTypeofSpecifier() { return this; }
533

con's avatar
con committed
534 535 536
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

537 538
    virtual TypeofSpecifierAST *clone(MemoryPool *pool) const;

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

class CPLUSPLUS_EXPORT DeclaratorAST: public AST
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
547 548
    SpecifierListAST *attribute_list;
    PtrOperatorListAST *ptr_operator_list;
con's avatar
con committed
549
    CoreDeclaratorAST *core_declarator;
Roberto Raggi's avatar
Roberto Raggi committed
550 551
    PostfixDeclaratorListAST *postfix_declarator_list;
    SpecifierListAST *post_attribute_list;
552
    unsigned equal_token;
con's avatar
con committed
553 554 555
    ExpressionAST *initializer;

public:
556 557 558 559 560 561
    DeclaratorAST()
        : attribute_list(0)
        , ptr_operator_list(0)
        , core_declarator(0)
        , postfix_declarator_list(0)
        , post_attribute_list(0)
562
        , equal_token(0)
563 564 565
        , initializer(0)
    {}

566
    virtual DeclaratorAST *asDeclarator() { return this; }
567

con's avatar
con committed
568 569 570
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

571 572
    virtual DeclaratorAST *clone(MemoryPool *pool) const;

con's avatar
con committed
573 574
protected:
    virtual void accept0(ASTVisitor *visitor);
575
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
576 577 578 579 580
};

class CPLUSPLUS_EXPORT SimpleDeclarationAST: public DeclarationAST
{
public:
581
    unsigned qt_invokable_token;
Roberto Raggi's avatar
Roberto Raggi committed
582 583
    SpecifierListAST *decl_specifier_list;
    DeclaratorListAST *declarator_list;
con's avatar
con committed
584 585
    unsigned semicolon_token;

Roberto Raggi's avatar
Roberto Raggi committed
586
public:
587
    List<Symbol *> *symbols;
Roberto Raggi's avatar
Roberto Raggi committed
588

con's avatar
con committed
589
public:
590 591 592 593 594 595 596 597
    SimpleDeclarationAST()
        : qt_invokable_token(0)
        , decl_specifier_list(0)
        , declarator_list(0)
        , semicolon_token(0)
        , symbols(0)
    {}

598
    virtual SimpleDeclarationAST *asSimpleDeclaration() { return this; }
599

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

603 604
    virtual SimpleDeclarationAST *clone(MemoryPool *pool) const;

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

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

public:
616 617 618 619
    EmptyDeclarationAST()
        : semicolon_token(0)
    {}

620
    virtual EmptyDeclarationAST *asEmptyDeclaration() { return this; }
621

con's avatar
con committed
622 623 624
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

625 626
    virtual EmptyDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
627 628
protected:
    virtual void accept0(ASTVisitor *visitor);
629
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
630 631 632 633 634 635 636 637 638 639
};

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

public:
640 641 642 643 644 645
    AccessDeclarationAST()
        : access_specifier_token(0)
        , slots_token(0)
        , colon_token(0)
    {}

646
    virtual AccessDeclarationAST *asAccessDeclaration() { return this; }
647

con's avatar
con committed
648 649 650
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

651 652
    virtual AccessDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
653 654
protected:
    virtual void accept0(ASTVisitor *visitor);
655
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
656 657
};

658 659 660 661 662 663
class CPLUSPLUS_EXPORT QtObjectTagAST: public DeclarationAST
{
public:
    unsigned q_object_token;

public:
664 665 666 667
    QtObjectTagAST()
        : q_object_token(0)
    {}

668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
    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
689
    SpecifierListAST *type_specifier_list;
690 691 692 693
    DeclaratorAST *declarator;
    unsigned rparen_token;

public:
694 695 696 697 698 699 700
    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
701
        , type_specifier_list(0)
702 703 704 705
        , declarator(0)
        , rparen_token(0)
    {}

706 707 708 709 710 711 712 713 714 715 716 717
    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 *);
};

718 719 720 721
class QtPropertyDeclarationItemAST: public AST
{
public:
    unsigned item_name_token;
722
    ExpressionAST *expression;
723 724

public:
725 726 727 728 729
    QtPropertyDeclarationItemAST()
        : item_name_token(0)
        , expression(0)
    {}

730 731 732 733 734
    virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return this; }

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

735
    virtual QtPropertyDeclarationItemAST *clone(MemoryPool *pool) const;
736 737 738 739 740 741

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

742
class CPLUSPLUS_EXPORT QtPropertyDeclarationAST: public DeclarationAST
743 744 745 746
{
public:
    unsigned property_specifier_token;
    unsigned lparen_token;
747 748
    ExpressionAST *expression; // for Q_PRIVATE_PROPERTY(expression, ...)
    unsigned comma_token;
749
    ExpressionAST *type_id;
750
    NameAST *property_name;
Roberto Raggi's avatar
Roberto Raggi committed
751
    QtPropertyDeclarationItemListAST *property_declaration_item_list;
752 753 754
    unsigned rparen_token;

public:
755 756 757
    QtPropertyDeclarationAST()
        : property_specifier_token(0)
        , lparen_token(0)
758 759
        , expression(0)
        , comma_token(0)
760 761
        , type_id(0)
        , property_name(0)
Roberto Raggi's avatar
Roberto Raggi committed
762
        , property_declaration_item_list(0)
763 764 765
        , rparen_token(0)
    {}

766
    virtual QtPropertyDeclarationAST *asQtPropertyDeclaration() { return this; }
767 768 769 770

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

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

773 774 775 776 777
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

778
class CPLUSPLUS_EXPORT QtEnumDeclarationAST: public DeclarationAST
779 780 781 782
{
public:
    unsigned enum_specifier_token;
    unsigned lparen_token;
783
    NameListAST *enumerator_list;
784 785 786
    unsigned rparen_token;

public:
787 788 789 790 791 792 793
    QtEnumDeclarationAST()
        : enum_specifier_token(0)
        , lparen_token(0)
        , enumerator_list(0)
        , rparen_token(0)
    {}

794
    virtual QtEnumDeclarationAST *asQtEnumDeclaration() { return this; }
795 796 797 798

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

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

801 802 803 804 805
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

806
class CPLUSPLUS_EXPORT QtFlagsDeclarationAST: public DeclarationAST
807 808 809 810
{
public:
    unsigned flags_specifier_token;
    unsigned lparen_token;
811
    NameListAST *flag_enums_list;
812 813 814
    unsigned rparen_token;

public:
815 816 817 818 819 820 821
    QtFlagsDeclarationAST()
        : flags_specifier_token(0)
        , lparen_token(0)
        , flag_enums_list(0)
        , rparen_token(0)
    {}

822
    virtual QtFlagsDeclarationAST *asQtFlagsDeclaration() { return this; }
823 824 825 826

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

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

829 830 831 832 833
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

834 835 836 837 838 839 840
class CPLUSPLUS_EXPORT QtInterfaceNameAST: public AST
{
public:
    NameAST *interface_name;
    NameListAST *constraint_list;

public:
841 842 843 844 845
    QtInterfaceNameAST()
        : interface_name(0)
        , constraint_list(0)
    {}

846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
    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:
867 868 869 870 871 872 873
    QtInterfacesDeclarationAST()
        : interfaces_token(0)
        , lparen_token(0)
        , interface_name_list(0)
        , rparen_token(0)
    {}

874 875 876 877 878 879 880 881 882 883 884 885
    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
886 887 888 889
class CPLUSPLUS_EXPORT AsmDefinitionAST: public DeclarationAST
{
public:
    unsigned asm_token;
890
    unsigned volatile_token;
con's avatar
con committed
891
    unsigned lparen_token;
892 893
    // ### string literals
    // ### asm operand list
con's avatar
con committed
894 895 896 897
    unsigned rparen_token;
    unsigned semicolon_token;

public:
898 899 900 901 902 903 904 905
    AsmDefinitionAST()
        : asm_token(0)
        , volatile_token(0)
        , lparen_token(0)
        , rparen_token(0)
        , semicolon_token(0)
    {}

906
    virtual AsmDefinitionAST *asAsmDefinition() { return this; }
907

con's avatar
con committed
908 909 910
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

911 912
    virtual AsmDefinitionAST *clone(MemoryPool *pool) const;

con's avatar
con committed
913 914
protected:
    virtual void accept0(ASTVisitor *visitor);
915
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
916 917 918 919 920
};

class CPLUSPLUS_EXPORT BaseSpecifierAST: public AST
{
public:
Roberto Raggi's avatar
cleanup  
Roberto Raggi committed
921 922
    unsigned virtual_token;
    unsigned access_specifier_token;
con's avatar
con committed
923 924
    NameAST *name;

Roberto Raggi's avatar
Roberto Raggi committed
925
public: // annotations
Roberto Raggi's avatar
Roberto Raggi committed
926
    BaseClass *symbol;
Roberto Raggi's avatar
Roberto Raggi committed
927

con's avatar
con committed
928
public:
929 930 931 932 933 934 935
    BaseSpecifierAST()
        : virtual_token(0)
        , access_specifier_token(0)
        , name(0)
        , symbol(0)
    {}

936
    virtual BaseSpecifierAST *asBaseSpecifier() { return this; }
937

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

941 942
    virtual BaseSpecifierAST *clone(MemoryPool *pool) const;

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

Roberto Raggi's avatar
Roberto Raggi committed
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
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 *);
};

970 971 972 973
class CPLUSPLUS_EXPORT CompoundExpressionAST: public ExpressionAST
{
public:
    unsigned lparen_token;
974
    CompoundStatementAST *statement;
975 976 977
    unsigned rparen_token;

public:
978 979
    CompoundExpressionAST()
        : lparen_token(0)
980
        , statement(0)
981 982 983
        , rparen_token(0)
    {}

984 985 986 987 988 989 990 991 992 993 994 995
    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 *);
};

996 997 998 999 1000 1001 1002 1003 1004
class CPLUSPLUS_EXPORT CompoundLiteralAST: public ExpressionAST
{
public:
    unsigned lparen_token;
    ExpressionAST *type_id;
    unsigned rparen_token;
    ExpressionAST *initializer;

public:
1005 1006 1007 1008 1009 1010 1011
    CompoundLiteralAST()
        : lparen_token(0)
        , type_id(0)
        , rparen_token(0)
        , initializer(0)
    {}

1012
    virtual CompoundLiteralAST *asCompoundLiteral() { return this; }
1013

1014 1015 1016
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

1017 1018
    virtual CompoundLiteralAST *clone(MemoryPool *pool) const;

1019 1020
protected:
    virtual void accept0(ASTVisitor *visitor);
1021
    virtual bool match0(AST *, ASTMatcher *);
1022 1023
};

con's avatar
con committed
1024 1025 1026 1027 1028 1029 1030 1031 1032
class CPLUSPLUS_EXPORT QtMethodAST: public ExpressionAST
{
public:
    unsigned method_token;
    unsigned lparen_token;
    DeclaratorAST *declarator;
    unsigned rparen_token;

public:
1033 1034 1035 1036 1037 1038 1039
    QtMethodAST()
        : method_token(0)
        , lparen_token(0)
        , declarator(0)
        , rparen_token(0)
    {}

1040
    virtual QtMethodAST *asQtMethod() { return this; }
1041

con's avatar
con committed
1042 1043 1044
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

1045 1046
    virtual QtMethodAST *clone(MemoryPool *pool) const;

con's avatar
con committed
1047 1048
protected:
    virtual void accept0(ASTVisitor *visitor);
1049
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
1050 1051
};

1052 1053 1054 1055 1056 1057 1058 1059 1060
class CPLUSPLUS_EXPORT QtMemberDeclarationAST: public StatementAST
{
public:
    unsigned q_token;
    unsigned lparen_token;
    ExpressionAST *type_id;
    unsigned rparen_token;

public:
1061 1062 1063 1064 1065 1066 1067
    QtMemberDeclarationAST()
        : q_token(0)
        , lparen_token(0)
        , type_id(0)
        , rparen_token(0)
    {}

1068 1069 1070 1071 1072
    virtual QtMemberDeclarationAST *asQtMemberDeclaration() { return this; }

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

1073 1074
    virtual QtMemberDeclarationAST *clone(MemoryPool *pool) const;

1075 1076 1077 1078 1079
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

con's avatar
con committed
1080 1081 1082 1083
class CPLUSPLUS_EXPORT BinaryExpressionAST: public ExpressionAST
{
public:
    ExpressionAST *left_expression;
1084
    unsigned binary_op_token;
con's avatar
con committed
1085 1086 1087
    ExpressionAST *right_expression;

public:
Erik Verbruggen's avatar