AST.h 117 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

Erik Verbruggen's avatar
Erik Verbruggen committed
30
template <typename Tptr>
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()
Erik Verbruggen's avatar
Erik Verbruggen committed
38
        : value(Tptr()), next(0)
Roberto Raggi's avatar
Roberto Raggi committed
39 40
    { }

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

45 46 47 48 49
    unsigned firstToken() const
    {
        if (value)
            return value->firstToken();

50
        // ### CPP_CHECK(0);
51 52 53 54
        return 0;
    }

    unsigned lastToken() const
55
    {
Erik Verbruggen's avatar
Erik Verbruggen committed
56
        Tptr lv = lastValue();
57 58 59 60

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

61
        // ### CPP_CHECK(0);
62 63 64
        return 0;
    }

Erik Verbruggen's avatar
Erik Verbruggen committed
65
    Tptr lastValue() const
66
    {
Erik Verbruggen's avatar
Erik Verbruggen committed
67
        Tptr 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

Erik Verbruggen's avatar
Erik Verbruggen committed
77
    Tptr value;
Roberto Raggi's avatar
Roberto Raggi committed
78 79 80
    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); }

Erik Verbruggen's avatar
Erik Verbruggen committed
95 96
    template <typename Tptr>
    static void accept(List<Tptr> *it, ASTVisitor *visitor)
97 98 99 100 101
    {
        for (; it; it = it->next)
            accept(it->value, visitor);
    }

102 103 104
    static bool match(AST *ast, AST *pattern, ASTMatcher *matcher);
    bool match(AST *pattern, ASTMatcher *matcher);

Erik Verbruggen's avatar
Erik Verbruggen committed
105 106
    template <typename Tptr>
    static bool match(List<Tptr> *it, List<Tptr> *patternIt, ASTMatcher *matcher)
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    {
        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
    virtual AccessDeclarationAST *asAccessDeclaration() { return 0; }
128
    virtual AliasDeclarationAST *asAliasDeclaration() { return 0; }
129
    virtual AlignmentSpecifierAST *asAlignmentSpecifier() { return 0; }
130
    virtual AlignofExpressionAST *asAlignofExpression() { return 0; }
131
    virtual AnonymousNameAST *asAnonymousName() { return 0; }
132 133 134 135 136 137 138 139
    virtual ArrayAccessAST *asArrayAccess() { return 0; }
    virtual ArrayDeclaratorAST *asArrayDeclarator() { return 0; }
    virtual ArrayInitializerAST *asArrayInitializer() { return 0; }
    virtual AsmDefinitionAST *asAsmDefinition() { 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
140
    virtual BracedInitializerAST *asBracedInitializer() { return 0; }
Orgad Shaneh's avatar
Orgad Shaneh committed
141
    virtual BracketDesignatorAST *asBracketDesignator() { return 0; }
142 143
    virtual BreakStatementAST *asBreakStatement() { return 0; }
    virtual CallAST *asCall() { return 0; }
144
    virtual CaptureAST *asCapture() { return 0; }
145 146 147 148
    virtual CaseStatementAST *asCaseStatement() { return 0; }
    virtual CastExpressionAST *asCastExpression() { return 0; }
    virtual CatchClauseAST *asCatchClause() { return 0; }
    virtual ClassSpecifierAST *asClassSpecifier() { return 0; }
149
    virtual CompoundExpressionAST *asCompoundExpression() { return 0; }
150 151 152 153 154 155 156 157 158 159 160 161 162
    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; }
163
    virtual DecltypeSpecifierAST *asDecltypeSpecifier() { return 0; }
164
    virtual DeleteExpressionAST *asDeleteExpression() { return 0; }
165 166
    virtual DesignatedInitializerAST *asDesignatedInitializer() { return 0; }
    virtual DesignatorAST *asDesignator() { return 0; }
167 168
    virtual DestructorNameAST *asDestructorName() { return 0; }
    virtual DoStatementAST *asDoStatement() { return 0; }
Orgad Shaneh's avatar
Orgad Shaneh committed
169
    virtual DotDesignatorAST *asDotDesignator() { return 0; }
170
    virtual DynamicExceptionSpecificationAST *asDynamicExceptionSpecification() { return 0; }
171 172 173 174 175 176 177
    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; }
178
    virtual ExpressionListParenAST *asExpressionListParen() { return 0; }
179 180 181
    virtual ExpressionOrDeclarationStatementAST *asExpressionOrDeclarationStatement() { return 0; }
    virtual ExpressionStatementAST *asExpressionStatement() { return 0; }
    virtual ForStatementAST *asForStatement() { return 0; }
182
    virtual ForeachStatementAST *asForeachStatement() { return 0; }
183 184
    virtual FunctionDeclaratorAST *asFunctionDeclarator() { return 0; }
    virtual FunctionDefinitionAST *asFunctionDefinition() { return 0; }
185 186
    virtual GnuAttributeAST *asGnuAttribute() { return 0; }
    virtual GnuAttributeSpecifierAST *asGnuAttributeSpecifier() { return 0; }
187
    virtual GotoStatementAST *asGotoStatement() { return 0; }
Roberto Raggi's avatar
Roberto Raggi committed
188
    virtual IdExpressionAST *asIdExpression() { return 0; }
189 190
    virtual IfStatementAST *asIfStatement() { return 0; }
    virtual LabeledStatementAST *asLabeledStatement() { return 0; }
191 192 193 194
    virtual LambdaCaptureAST *asLambdaCapture() { return 0; }
    virtual LambdaDeclaratorAST *asLambdaDeclarator() { return 0; }
    virtual LambdaExpressionAST *asLambdaExpression() { return 0; }
    virtual LambdaIntroducerAST *asLambdaIntroducer() { return 0; }
195 196 197 198 199 200 201 202 203 204 205
    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; }
206
    virtual NewArrayDeclaratorAST *asNewArrayDeclarator() { return 0; }
207 208
    virtual NewExpressionAST *asNewExpression() { return 0; }
    virtual NewTypeIdAST *asNewTypeId() { return 0; }
209
    virtual NoExceptSpecificationAST *asNoExceptSpecification() { return 0; }
210
    virtual NumericLiteralAST *asNumericLiteral() { return 0; }
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
    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; }
236 237 238 239 240
    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
241
    virtual PointerLiteralAST *asPointerLiteral() { return 0; }
242 243 244 245 246
    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; }
247 248
    virtual QtEnumDeclarationAST *asQtEnumDeclaration() { return 0; }
    virtual QtFlagsDeclarationAST *asQtFlagsDeclaration() { return 0; }
249 250
    virtual QtInterfaceNameAST *asQtInterfaceName() { return 0; }
    virtual QtInterfacesDeclarationAST *asQtInterfacesDeclaration() { return 0; }
251
    virtual QtMemberDeclarationAST *asQtMemberDeclaration() { return 0; }
252
    virtual QtMethodAST *asQtMethod() { return 0; }
253 254
    virtual QtObjectTagAST *asQtObjectTag() { return 0; }
    virtual QtPrivateSlotAST *asQtPrivateSlot() { return 0; }
255
    virtual QtPropertyDeclarationAST *asQtPropertyDeclaration() { return 0; }
256
    virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return 0; }
257
    virtual QualifiedNameAST *asQualifiedName() { return 0; }
258
    virtual RangeBasedForStatementAST *asRangeBasedForStatement() { return 0; }
259 260 261 262 263 264 265 266
    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; }
267
    virtual StaticAssertDeclarationAST *asStaticAssertDeclaration() { return 0; }
268 269 270 271 272 273 274
    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; }
275
    virtual TrailingReturnTypeAST *asTrailingReturnType() { return 0; }
276 277 278 279 280 281 282 283 284 285 286 287
    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; }
288

con's avatar
con committed
289 290
protected:
    virtual void accept0(ASTVisitor *visitor) = 0;
291
    virtual bool match0(AST *, ASTMatcher *) = 0;
con's avatar
con committed
292 293
};

294 295 296
class CPLUSPLUS_EXPORT StatementAST: public AST
{
public:
297 298 299
    StatementAST()
    {}

300
    virtual StatementAST *asStatement() { return this; }
301 302

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

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

311
    virtual ExpressionAST *asExpression() { return this; }
312 313

    virtual ExpressionAST *clone(MemoryPool *pool) const = 0;
314 315 316 317 318
};

class CPLUSPLUS_EXPORT DeclarationAST: public AST
{
public:
319 320 321
    DeclarationAST()
    {}

322
    virtual DeclarationAST *asDeclaration() { return this; }
323 324

    virtual DeclarationAST *clone(MemoryPool *pool) const = 0;
325 326
};

Roberto Raggi's avatar
Roberto Raggi committed
327
class CPLUSPLUS_EXPORT NameAST: public AST
328 329
{
public: // annotations
Roberto Raggi's avatar
Roberto Raggi committed
330
    const Name *name;
331 332

public:
333 334 335 336
    NameAST()
        : name(0)
    {}

337
    virtual NameAST *asName() { return this; }
338 339

    virtual NameAST *clone(MemoryPool *pool) const = 0;
340 341
};

con's avatar
con committed
342 343
class CPLUSPLUS_EXPORT SpecifierAST: public AST
{
344
public:
345 346 347
    SpecifierAST()
    {}

348
    virtual SpecifierAST *asSpecifier() { return this; }
349 350

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

353 354 355
class CPLUSPLUS_EXPORT PtrOperatorAST: public AST
{
public:
356 357 358
    PtrOperatorAST()
    {}

359
    virtual PtrOperatorAST *asPtrOperator() { return this; }
360 361

    virtual PtrOperatorAST *clone(MemoryPool *pool) const = 0;
362 363
};

364
class CPLUSPLUS_EXPORT PostfixAST: public ExpressionAST
365 366
{
public:
367 368 369
    PostfixAST()
    {}

370
    virtual PostfixAST *asPostfix() { return this; }
371 372

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

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

381
    virtual CoreDeclaratorAST *asCoreDeclarator() { return this; }
382 383

    virtual CoreDeclaratorAST *clone(MemoryPool *pool) const = 0;
384 385 386 387 388
};

class CPLUSPLUS_EXPORT PostfixDeclaratorAST: public AST
{
public:
389 390 391
    PostfixDeclaratorAST()
    {}

392
    virtual PostfixDeclaratorAST *asPostfixDeclarator() { return this; }
393 394

    virtual PostfixDeclaratorAST *clone(MemoryPool *pool) const = 0;
395 396
};

397
class CPLUSPLUS_EXPORT ObjCSelectorArgumentAST: public AST
398
{
399 400 401 402 403
public:
    unsigned name_token;
    unsigned colon_token;

public:
404 405 406 407 408
    ObjCSelectorArgumentAST()
        : name_token(0)
        , colon_token(0)
    {}

409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
    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;
425 426

public:
427 428 429 430
    ObjCSelectorAST()
        : selector_argument_list(0)
    {}

431
    virtual ObjCSelectorAST *asObjCSelector() { return this; }
432

433 434 435 436 437 438 439 440
    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 *);
441 442
};

con's avatar
con committed
443 444 445 446 447 448
class CPLUSPLUS_EXPORT SimpleSpecifierAST: public SpecifierAST
{
public:
    unsigned specifier_token;

public:
449 450 451 452
    SimpleSpecifierAST()
        : specifier_token(0)
    {}

453
    virtual SimpleSpecifierAST *asSimpleSpecifier() { return this; }
454

con's avatar
con committed
455 456 457
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

458 459
    virtual SimpleSpecifierAST *clone(MemoryPool *pool) const;

con's avatar
con committed
460 461
protected:
    virtual void accept0(ASTVisitor *visitor);
462
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
463 464 465 466
};

class CPLUSPLUS_EXPORT AttributeSpecifierAST: public SpecifierAST
{
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
public:
    AttributeSpecifierAST()
    {}

    virtual AttributeSpecifierAST *asAttributeSpecifier() { return this; }

    virtual AttributeSpecifierAST *clone(MemoryPool *pool) const = 0;
};

class CPLUSPLUS_EXPORT AlignmentSpecifierAST: public AttributeSpecifierAST
{
public:
    unsigned align_token;
    unsigned lparen_token;
    ExpressionAST *typeIdExprOrAlignmentExpr;
    unsigned ellipses_token;
    unsigned rparen_token;

public:
    AlignmentSpecifierAST()
        : align_token(0)
        , lparen_token(0)
        , typeIdExprOrAlignmentExpr(0)
        , ellipses_token(0)
        , rparen_token(0)
    {}

    virtual AlignmentSpecifierAST *asAlignmentSpecifier() { return this; }

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

    virtual AlignmentSpecifierAST *clone(MemoryPool *pool) const;

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


class CPLUSPLUS_EXPORT GnuAttributeSpecifierAST: public AttributeSpecifierAST
{
con's avatar
con committed
509 510 511 512
public:
    unsigned attribute_token;
    unsigned first_lparen_token;
    unsigned second_lparen_token;
513
    GnuAttributeListAST *attribute_list;
con's avatar
con committed
514 515 516 517
    unsigned first_rparen_token;
    unsigned second_rparen_token;

public:
518
    GnuAttributeSpecifierAST()
519 520 521 522 523 524 525 526
        : attribute_token(0)
        , first_lparen_token(0)
        , second_lparen_token(0)
        , attribute_list(0)
        , first_rparen_token(0)
        , second_rparen_token(0)
    {}

527
    virtual GnuAttributeSpecifierAST *asGnuAttributeSpecifier() { return this; }
528

con's avatar
con committed
529 530 531
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

532
    virtual GnuAttributeSpecifierAST *clone(MemoryPool *pool) const;
533

con's avatar
con committed
534 535
protected:
    virtual void accept0(ASTVisitor *visitor);
536
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
537 538
};

539
class CPLUSPLUS_EXPORT GnuAttributeAST: public AST
con's avatar
con committed
540 541 542 543 544 545 546 547 548
{
public:
    unsigned identifier_token;
    unsigned lparen_token;
    unsigned tag_token;
    ExpressionListAST *expression_list;
    unsigned rparen_token;

public:
549
    GnuAttributeAST()
550 551 552 553 554 555 556
        : identifier_token(0)
        , lparen_token(0)
        , tag_token(0)
        , expression_list(0)
        , rparen_token(0)
    {}

557
    virtual GnuAttributeAST *asGnuAttribute() { return this; }
558

con's avatar
con committed
559 560 561
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

562
    virtual GnuAttributeAST *clone(MemoryPool *pool) const;
563

con's avatar
con committed
564 565
protected:
    virtual void accept0(ASTVisitor *visitor);
566
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
567 568 569 570 571 572
};

class CPLUSPLUS_EXPORT TypeofSpecifierAST: public SpecifierAST
{
public:
    unsigned typeof_token;
573
    unsigned lparen_token;
con's avatar
con committed
574
    ExpressionAST *expression;
575
    unsigned rparen_token;
con's avatar
con committed
576 577

public:
578 579 580 581 582 583 584
    TypeofSpecifierAST()
        : typeof_token(0)
        , lparen_token(0)
        , expression(0)
        , rparen_token(0)
    {}

585
    virtual TypeofSpecifierAST *asTypeofSpecifier() { return this; }
586

con's avatar
con committed
587 588 589
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

590 591
    virtual TypeofSpecifierAST *clone(MemoryPool *pool) const;

con's avatar
con committed
592 593
protected:
    virtual void accept0(ASTVisitor *visitor);
594
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
595 596
};

597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
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
625 626 627
class CPLUSPLUS_EXPORT DeclaratorAST: public AST
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
628 629
    SpecifierListAST *attribute_list;
    PtrOperatorListAST *ptr_operator_list;
con's avatar
con committed
630
    CoreDeclaratorAST *core_declarator;
Roberto Raggi's avatar
Roberto Raggi committed
631 632
    PostfixDeclaratorListAST *postfix_declarator_list;
    SpecifierListAST *post_attribute_list;
633
    unsigned equal_token;
con's avatar
con committed
634 635 636
    ExpressionAST *initializer;

public:
637 638 639 640 641 642
    DeclaratorAST()
        : attribute_list(0)
        , ptr_operator_list(0)
        , core_declarator(0)
        , postfix_declarator_list(0)
        , post_attribute_list(0)
643
        , equal_token(0)
644 645 646
        , initializer(0)
    {}

647
    virtual DeclaratorAST *asDeclarator() { return this; }
648

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

652 653
    virtual DeclaratorAST *clone(MemoryPool *pool) const;

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

class CPLUSPLUS_EXPORT SimpleDeclarationAST: public DeclarationAST
{
public:
662
    unsigned qt_invokable_token;
Roberto Raggi's avatar
Roberto Raggi committed
663 664
    SpecifierListAST *decl_specifier_list;
    DeclaratorListAST *declarator_list;
con's avatar
con committed
665 666
    unsigned semicolon_token;

Roberto Raggi's avatar
Roberto Raggi committed
667
public:
668
    List<Symbol *> *symbols;
Roberto Raggi's avatar
Roberto Raggi committed
669

con's avatar
con committed
670
public:
671 672 673 674 675 676 677 678
    SimpleDeclarationAST()
        : qt_invokable_token(0)
        , decl_specifier_list(0)
        , declarator_list(0)
        , semicolon_token(0)
        , symbols(0)
    {}

679
    virtual SimpleDeclarationAST *asSimpleDeclaration() { return this; }
680

con's avatar
con committed
681 682 683
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

684 685
    virtual SimpleDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
686 687
protected:
    virtual void accept0(ASTVisitor *visitor);
688
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
689 690 691 692 693 694 695 696
};

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

public:
697 698 699 700
    EmptyDeclarationAST()
        : semicolon_token(0)
    {}

701
    virtual EmptyDeclarationAST *asEmptyDeclaration() { return this; }
702

con's avatar
con committed
703 704 705
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

706 707
    virtual EmptyDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
708 709
protected:
    virtual void accept0(ASTVisitor *visitor);
710
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
711 712 713 714 715 716 717 718 719 720
};

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

public:
721 722 723 724 725 726
    AccessDeclarationAST()
        : access_specifier_token(0)
        , slots_token(0)
        , colon_token(0)
    {}

727
    virtual AccessDeclarationAST *asAccessDeclaration() { return this; }
728

con's avatar
con committed
729 730 731
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

732 733
    virtual AccessDeclarationAST *clone(MemoryPool *pool) const;

con's avatar
con committed
734 735
protected:
    virtual void accept0(ASTVisitor *visitor);
736
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
737 738
};

739 740 741 742 743 744
class CPLUSPLUS_EXPORT QtObjectTagAST: public DeclarationAST
{
public:
    unsigned q_object_token;

public:
745 746 747 748
    QtObjectTagAST()
        : q_object_token(0)
    {}

749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
    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
770
    SpecifierListAST *type_specifier_list;
771 772 773 774
    DeclaratorAST *declarator;
    unsigned rparen_token;

public:
775 776 777 778 779 780 781
    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
782
        , type_specifier_list(0)
783 784 785 786
        , declarator(0)
        , rparen_token(0)
    {}

787 788 789 790 791 792 793 794 795 796 797 798
    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 *);
};

799 800 801 802
class QtPropertyDeclarationItemAST: public AST
{
public:
    unsigned item_name_token;
803
    ExpressionAST *expression;
804 805

public:
806 807 808 809 810
    QtPropertyDeclarationItemAST()
        : item_name_token(0)
        , expression(0)
    {}

811 812 813 814 815
    virtual QtPropertyDeclarationItemAST *asQtPropertyDeclarationItem() { return this; }

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

816
    virtual QtPropertyDeclarationItemAST *clone(MemoryPool *pool) const;
817 818 819 820 821 822

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

823
class CPLUSPLUS_EXPORT QtPropertyDeclarationAST: public DeclarationAST
824 825 826 827
{
public:
    unsigned property_specifier_token;
    unsigned lparen_token;
828 829
    ExpressionAST *expression; // for Q_PRIVATE_PROPERTY(expression, ...)
    unsigned comma_token;
830
    ExpressionAST *type_id;
831
    NameAST *property_name;
Roberto Raggi's avatar
Roberto Raggi committed
832
    QtPropertyDeclarationItemListAST *property_declaration_item_list;
833 834 835
    unsigned rparen_token;

public:
836 837 838
    QtPropertyDeclarationAST()
        : property_specifier_token(0)
        , lparen_token(0)
839 840
        , expression(0)
        , comma_token(0)
841 842
        , type_id(0)
        , property_name(0)
Roberto Raggi's avatar
Roberto Raggi committed
843
        , property_declaration_item_list(0)
844 845 846
        , rparen_token(0)
    {}

847
    virtual QtPropertyDeclarationAST *asQtPropertyDeclaration() { return this; }
848 849 850 851

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

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

854 855 856 857 858
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

859
class CPLUSPLUS_EXPORT QtEnumDeclarationAST: public DeclarationAST
860 861 862 863
{
public:
    unsigned enum_specifier_token;
    unsigned lparen_token;
864
    NameListAST *enumerator_list;
865 866 867
    unsigned rparen_token;

public:
868 869 870 871 872 873 874
    QtEnumDeclarationAST()
        : enum_specifier_token(0)
        , lparen_token(0)
        , enumerator_list(0)
        , rparen_token(0)
    {}

875
    virtual QtEnumDeclarationAST *asQtEnumDeclaration() { return this; }
876 877 878 879

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

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

882 883 884 885 886
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

887
class CPLUSPLUS_EXPORT QtFlagsDeclarationAST: public DeclarationAST
888 889 890 891
{
public:
    unsigned flags_specifier_token;
    unsigned lparen_token;
892
    NameListAST *flag_enums_list;
893 894 895
    unsigned rparen_token;

public:
896 897 898 899 900 901 902
    QtFlagsDeclarationAST()
        : flags_specifier_token(0)
        , lparen_token(0)
        , flag_enums_list(0)
        , rparen_token(0)
    {}

903
    virtual QtFlagsDeclarationAST *asQtFlagsDeclaration() { return this; }
904 905 906 907

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

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

910 911 912 913 914
protected:
    virtual void accept0(ASTVisitor *visitor);
    virtual bool match0(AST *, ASTMatcher *);
};

915 916 917 918 919 920 921
class CPLUSPLUS_EXPORT QtInterfaceNameAST: public AST
{
public:
    NameAST *interface_name;
    NameListAST *constraint_list;

public:
922 923 924 925 926
    QtInterfaceNameAST()
        : interface_name(0)
        , constraint_list(0)
    {}

927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
    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:
948 949 950 951 952 953 954
    QtInterfacesDeclarationAST()
        : interfaces_token(0)
        , lparen_token(0)
        , interface_name_list(0)
        , rparen_token(0)
    {}

955 956 957 958 959 960 961 962 963 964 965 966
    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
967 968 969 970
class CPLUSPLUS_EXPORT AsmDefinitionAST: public DeclarationAST
{
public:
    unsigned asm_token;
971
    unsigned volatile_token;
con's avatar
con committed
972
    unsigned lparen_token;
973 974
    // ### string literals
    // ### asm operand list
con's avatar
con committed
975 976 977 978
    unsigned rparen_token;
    unsigned semicolon_token;

public:
979 980 981 982 983 984 985 986
    AsmDefinitionAST()
        : asm_token(0)
        , volatile_token(0)
        , lparen_token(0)
        , rparen_token(0)
        , semicolon_token(0)
    {}

987
    virtual AsmDefinitionAST *asAsmDefinition() { return this; }
988

con's avatar
con committed
989 990 991
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

992 993
    virtual AsmDefinitionAST *clone(MemoryPool *pool) const;

con's avatar
con committed
994 995
protected:
    virtual void accept0(ASTVisitor *visitor);
996
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
997 998 999 1000 1001
};

class CPLUSPLUS_EXPORT BaseSpecifierAST: public AST
{
public:
Roberto Raggi's avatar
cleanup  
Roberto Raggi committed
1002 1003
    unsigned virtual_token;
    unsigned access_specifier_token;
con's avatar
con committed
1004 1005
    NameAST *name;

Roberto Raggi's avatar
Roberto Raggi committed
1006
public: // annotations
Roberto Raggi's avatar
Roberto Raggi committed
1007
    BaseClass *symbol;
Roberto Raggi's avatar
Roberto Raggi committed
1008

con's avatar
con committed
1009
public:
1010 1011 1012 1013 1014 1015 1016
    BaseSpecifierAST()
        : virtual_token(0)
        , access_specifier_token(0)
        , name(0)
        , symbol(0)
    {}

1017
    virtual BaseSpecifierAST *asBaseSpecifier() { return this; }
1018

con's avatar
con committed
1019 1020 1021
    virtual unsigned firstToken() const;
    virtual unsigned lastToken() const;

1022 1023
    virtual BaseSpecifierAST *clone(MemoryPool *pool) const;

con's avatar
con committed
1024 1025
protected:
    virtual void accept0(ASTVisitor *visitor);
1026
    virtual bool match0(AST *, ASTMatcher *);
con's avatar
con committed
1027 1028
};

Roberto Raggi's avatar
Roberto Raggi committed
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
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 *);
};

1051 1052 1053 1054
class CPLUSPLUS_EXPORT CompoundExpressionAST: public ExpressionAST
{
public:
    unsigned lparen_token;