diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index 5d7f34132ab7613d437ae2d2658f95080fecf167..659d25b25adbaca957bcd051425fd740b216f327 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -409,8 +409,9 @@ bool FindUsages::visit(ParameterDeclarationAST *ast) for (SpecifierAST *attr = declarator->attributes; attr; attr = attr->next) accept(attr); - for (PtrOperatorAST *ptr_op = declarator->ptr_operators; ptr_op; ptr_op = ptr_op->next) - accept(ptr_op); + for (PtrOperatorListAST *it = declarator->ptr_operators; it; it = it->next) { + accept(it->value); + } if (! _inSimpleDeclaration) // visit the core declarator only if we are not in simple-declaration. accept(declarator->core_declarator); diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp index 03531c481a5e08bb307a74c4bec697b10d5402a6..8785ad6f097095839121af0083f55485ef4e6a57 100644 --- a/src/shared/cplusplus/AST.cpp +++ b/src/shared/cplusplus/AST.cpp @@ -483,10 +483,8 @@ unsigned ConversionFunctionIdAST::firstToken() const unsigned ConversionFunctionIdAST::lastToken() const { - for (PtrOperatorAST *it = ptr_operators; it; it = it->next) { - if (! it->next) - return it->lastToken(); - } + if (ptr_operators) + return ptr_operators->lastToken(); for (SpecifierAST *it = type_specifier; it; it = it->next) { if (! it->next) @@ -566,10 +564,8 @@ unsigned DeclaratorAST::lastToken() const if (core_declarator) return core_declarator->lastToken(); - for (PtrOperatorAST *it = ptr_operators; it; it = it->next) { - if (! it->next) - return it->lastToken(); - } + if (ptr_operators) + return ptr_operators->lastToken(); for (SpecifierAST *it = attributes; it; it = it->next) { if (! it->next) @@ -1176,12 +1172,10 @@ unsigned NewTypeIdAST::lastToken() const if (new_array_declarators) return new_array_declarators->lastToken(); - for (PtrOperatorAST *it = ptr_operators; it; it = it->next) { - if (it->next) - return it->lastToken(); - } + else if (ptr_operators) + return ptr_operators->lastToken(); - if (type_specifier) + else if (type_specifier) return type_specifier->lastToken(); // ### assert? diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h index 2e858bd5f577d943893f29d5e7c90ecc0f90733f..e4a61e332baa5fcf58b56e5220bfefff24362d0c 100644 --- a/src/shared/cplusplus/AST.h +++ b/src/shared/cplusplus/AST.h @@ -371,7 +371,7 @@ class CPLUSPLUS_EXPORT DeclaratorAST: public AST { public: SpecifierAST *attributes; - PtrOperatorAST *ptr_operators; + PtrOperatorListAST *ptr_operators; CoreDeclaratorAST *core_declarator; PostfixDeclaratorListAST *postfix_declarators; SpecifierAST *post_attributes; @@ -1198,7 +1198,7 @@ class CPLUSPLUS_EXPORT ConversionFunctionIdAST: public NameAST public: unsigned operator_token; SpecifierAST *type_specifier; - PtrOperatorAST *ptr_operators; + PtrOperatorListAST *ptr_operators; public: virtual ConversionFunctionIdAST *asConversionFunctionId() { return this; } @@ -1379,7 +1379,7 @@ class CPLUSPLUS_EXPORT NewTypeIdAST: public AST { public: SpecifierAST *type_specifier; - PtrOperatorAST *ptr_operators; + PtrOperatorListAST *ptr_operators; NewArrayDeclaratorListAST *new_array_declarators; public: @@ -1591,12 +1591,8 @@ protected: class CPLUSPLUS_EXPORT PtrOperatorAST: public AST { -public: - PtrOperatorAST *next; - public: virtual PtrOperatorAST *asPtrOperator() { return this; } - }; class CPLUSPLUS_EXPORT PointerToMemberAST: public PtrOperatorAST diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp index 7469388d4cf365598d6ab8d466ce41f4946533d1..f6d1d9184f84fb671f3712aed15ee06bc9c4af4d 100644 --- a/src/shared/cplusplus/ASTVisit.cpp +++ b/src/shared/cplusplus/ASTVisit.cpp @@ -69,8 +69,7 @@ void DeclaratorAST::accept0(ASTVisitor *visitor) if (visitor->visit(this)) { for (SpecifierAST *it = attributes; it; it = it->next) accept(it, visitor); - for (PtrOperatorAST *it = ptr_operators; it; it = it->next) - accept(it, visitor); + accept(ptr_operators, visitor); accept(core_declarator, visitor); accept(postfix_declarators, visitor); for (SpecifierAST *it = post_attributes; it; it = it->next) @@ -472,8 +471,7 @@ void ConversionFunctionIdAST::accept0(ASTVisitor *visitor) if (visitor->visit(this)) { for (SpecifierAST *it = type_specifier; it; it = it->next) accept(it, visitor); - for (PtrOperatorAST *it = ptr_operators; it; it = it->next) - accept(it, visitor); + accept(ptr_operators, visitor); } visitor->endVisit(this); } @@ -560,8 +558,7 @@ void NewTypeIdAST::accept0(ASTVisitor *visitor) if (visitor->visit(this)) { for (SpecifierAST *it = type_specifier; it; it = it->next) accept(it, visitor); - for (PtrOperatorAST *it = ptr_operators; it; it = it->next) - accept(it, visitor); + accept(ptr_operators, visitor); accept(new_array_declarators, visitor); } visitor->endVisit(this); diff --git a/src/shared/cplusplus/ASTfwd.h b/src/shared/cplusplus/ASTfwd.h index 4c04800c1819157c86635fd2ae08da48d18dfdc9..483708356bad344000d0102f896bcc869f965235 100644 --- a/src/shared/cplusplus/ASTfwd.h +++ b/src/shared/cplusplus/ASTfwd.h @@ -204,6 +204,7 @@ typedef List<PostfixDeclaratorAST *> PostfixDeclaratorListAST; typedef List<AttributeAST *> AttributeListAST; typedef List<NestedNameSpecifierAST *> NestedNameSpecifierListAST; typedef List<CatchClauseAST *> CatchClauseListAST; +typedef List<PtrOperatorAST *> PtrOperatorListAST; typedef List<NameAST *> ObjCIdentifierListAST; typedef List<ObjCMessageArgumentAST *> ObjCMessageArgumentListAST; diff --git a/src/shared/cplusplus/CheckDeclarator.cpp b/src/shared/cplusplus/CheckDeclarator.cpp index be1319d5c88de980120149eda55a66fb73affa89..0874c1bfa1fa7a24db4663116c433015f3592566 100644 --- a/src/shared/cplusplus/CheckDeclarator.cpp +++ b/src/shared/cplusplus/CheckDeclarator.cpp @@ -68,9 +68,9 @@ CheckDeclarator::~CheckDeclarator() { } FullySpecifiedType CheckDeclarator::check(DeclaratorAST *declarator, - FullySpecifiedType type, - Scope *scope, - Name **name) + const FullySpecifiedType &type, + Scope *scope, + Name **name) { FullySpecifiedType previousType = switchFullySpecifiedType(type); Scope *previousScope = switchScope(scope); @@ -83,9 +83,9 @@ FullySpecifiedType CheckDeclarator::check(DeclaratorAST *declarator, return switchFullySpecifiedType(previousType); } -FullySpecifiedType CheckDeclarator::check(PtrOperatorAST *ptrOperators, - FullySpecifiedType type, - Scope *scope) +FullySpecifiedType CheckDeclarator::check(PtrOperatorListAST *ptrOperators, + const FullySpecifiedType &type, + Scope *scope) { FullySpecifiedType previousType = switchFullySpecifiedType(type); Scope *previousScope = switchScope(scope); @@ -110,7 +110,7 @@ DeclaratorAST *CheckDeclarator::switchDeclarator(DeclaratorAST *declarator) return previousDeclarator; } -FullySpecifiedType CheckDeclarator::switchFullySpecifiedType(FullySpecifiedType type) +FullySpecifiedType CheckDeclarator::switchFullySpecifiedType(const FullySpecifiedType &type) { FullySpecifiedType previousType = _fullySpecifiedType; _fullySpecifiedType = type; diff --git a/src/shared/cplusplus/CheckDeclarator.h b/src/shared/cplusplus/CheckDeclarator.h index b676abfacd8cceab058fd372aef551df698c310f..c24d4a5c3846ff8776dc01543d4e44b1b7b15101 100644 --- a/src/shared/cplusplus/CheckDeclarator.h +++ b/src/shared/cplusplus/CheckDeclarator.h @@ -63,20 +63,20 @@ public: virtual ~CheckDeclarator(); FullySpecifiedType check(DeclaratorAST *declarator, - FullySpecifiedType type, - Scope *scope, - Name **name); + const FullySpecifiedType &type, + Scope *scope, + Name **name); - FullySpecifiedType check(PtrOperatorAST *ptrOperators, - FullySpecifiedType type, - Scope *scope); + FullySpecifiedType check(PtrOperatorListAST *ptrOperators, + const FullySpecifiedType &type, + Scope *scope); FullySpecifiedType check(ObjCMethodPrototypeAST *methodPrototype, Scope *scope); protected: DeclaratorAST *switchDeclarator(DeclaratorAST *declarator); - FullySpecifiedType switchFullySpecifiedType(FullySpecifiedType type); + FullySpecifiedType switchFullySpecifiedType(const FullySpecifiedType &type); Scope *switchScope(Scope *scope); Name **switchName(Name **name); diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp index 394074e594a042f19e30962124d1cd586bb7f7a9..27de8b6c6a7a970676ebe35027143b0eb56e0482 100644 --- a/src/shared/cplusplus/Parser.cpp +++ b/src/shared/cplusplus/Parser.cpp @@ -661,7 +661,7 @@ bool Parser::parseConversionFunctionId(NameAST *&node) if (! parseTypeSpecifier(type_specifier)) { return false; } - PtrOperatorAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators; + PtrOperatorListAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators; while (parsePtrOperator(*ptr_operators_tail)) ptr_operators_tail = &(*ptr_operators_tail)->next; @@ -956,19 +956,19 @@ bool Parser::parseCvQualifiers(SpecifierAST *&node) return start != cursor(); } -bool Parser::parsePtrOperator(PtrOperatorAST *&node) +bool Parser::parsePtrOperator(PtrOperatorListAST *&node) { DEBUG_THIS_RULE(); if (LA() == T_AMPER) { ReferenceAST *ast = new (_pool) ReferenceAST; ast->amp_token = consumeToken(); - node = ast; + node = new (_pool) PtrOperatorListAST(ast); return true; } else if (LA() == T_STAR) { PointerAST *ast = new (_pool) PointerAST; ast->star_token = consumeToken(); parseCvQualifiers(ast->cv_qualifier_seq); - node = ast; + node = new (_pool) PtrOperatorListAST(ast); return true; } else if (LA() == T_COLON_COLON || LA() == T_IDENTIFIER) { unsigned scope_or_identifier_token = cursor(); @@ -985,7 +985,7 @@ bool Parser::parsePtrOperator(PtrOperatorAST *&node) ast->nested_name_specifier = nested_name_specifiers; ast->star_token = consumeToken(); parseCvQualifiers(ast->cv_qualifier_seq); - node = ast; + node = new (_pool) PtrOperatorListAST(ast); return true; } rewind(scope_or_identifier_token); @@ -1082,7 +1082,7 @@ bool Parser::parseCoreDeclarator(DeclaratorAST *&node) attribute_ptr = &(*attribute_ptr)->next; } - PtrOperatorAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators; + PtrOperatorListAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators; while (parsePtrOperator(*ptr_operators_tail)) ptr_operators_tail = &(*ptr_operators_tail)->next; @@ -1219,7 +1219,8 @@ bool Parser::parseDeclarator(DeclaratorAST *&node, bool stopAtCppInitializer) bool Parser::parseAbstractCoreDeclarator(DeclaratorAST *&node) { DEBUG_THIS_RULE(); - PtrOperatorAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators; + + PtrOperatorListAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators; while (parsePtrOperator(*ptr_operators_tail)) ptr_operators_tail = &(*ptr_operators_tail)->next; @@ -3799,12 +3800,15 @@ bool Parser::parseNewTypeId(NewTypeIdAST *&node) NewTypeIdAST *ast = new (_pool) NewTypeIdAST; ast->type_specifier = typeSpec; - PtrOperatorAST **ptrop_it = &ast->ptr_operators; + + PtrOperatorListAST **ptrop_it = &ast->ptr_operators; while (parsePtrOperator(*ptrop_it)) ptrop_it = &(*ptrop_it)->next; + NewArrayDeclaratorListAST **it = &ast->new_array_declarators; while (parseNewArrayDeclarator(*it)) it = &(*it)->next; + node = ast; return true; } diff --git a/src/shared/cplusplus/Parser.h b/src/shared/cplusplus/Parser.h index 15f768b3cf22af42e0e2bde495d033b3146c34e9..6ac28e58a7ba6a8de4876838d2f789e23fd60e5d 100644 --- a/src/shared/cplusplus/Parser.h +++ b/src/shared/cplusplus/Parser.h @@ -165,7 +165,7 @@ public: bool parsePostfixExpressionInternal(ExpressionAST *&node); bool parsePrimaryExpression(ExpressionAST *&node); bool parseNestedExpression(ExpressionAST *&node); - bool parsePtrOperator(PtrOperatorAST *&node); + bool parsePtrOperator(PtrOperatorListAST *&node); bool parseRelationalExpression(ExpressionAST *&node); bool parseShiftExpression(ExpressionAST *&node); bool parseStatement(StatementAST *&node); diff --git a/src/shared/cplusplus/Semantic.cpp b/src/shared/cplusplus/Semantic.cpp index c2dfa42ff7c9f58580861d0b832707c5b63a0f85..8c01a3ee8006bbf218c21ce4ba733df157f9b493 100644 --- a/src/shared/cplusplus/Semantic.cpp +++ b/src/shared/cplusplus/Semantic.cpp @@ -130,7 +130,7 @@ FullySpecifiedType Semantic::check(DeclaratorAST *declarator, FullySpecifiedType Scope *scope, Name **name) { return d->checkDeclarator->check(declarator, type, scope, name); } -FullySpecifiedType Semantic::check(PtrOperatorAST *ptrOperators, FullySpecifiedType type, +FullySpecifiedType Semantic::check(PtrOperatorListAST *ptrOperators, FullySpecifiedType type, Scope *scope) { return d->checkDeclarator->check(ptrOperators, type, scope); } diff --git a/src/shared/cplusplus/Semantic.h b/src/shared/cplusplus/Semantic.h index b42b13efed5387aeeb03bca1350407ff45446152..3e2d8c4baccdc5c551547be9a1547ad17bcb2fae 100644 --- a/src/shared/cplusplus/Semantic.h +++ b/src/shared/cplusplus/Semantic.h @@ -71,7 +71,7 @@ public: FullySpecifiedType check(DeclaratorAST *declarator, FullySpecifiedType type, Scope *scope, Name **name = 0); // ### ugly - FullySpecifiedType check(PtrOperatorAST *ptrOperators, FullySpecifiedType type, + FullySpecifiedType check(PtrOperatorListAST *ptrOperators, FullySpecifiedType type, Scope *scope); FullySpecifiedType check(ObjCMethodPrototypeAST *methodPrototype, Scope *scope); diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp index 9dc3d872a73150dbf946cef87524cbe720e506e8..e2fe27e8e5fe7e7278d7a5522cf5df5244f4eb4b 100644 --- a/tests/auto/cplusplus/ast/tst_ast.cpp +++ b/tests/auto/cplusplus/ast/tst_ast.cpp @@ -668,7 +668,9 @@ void tst_AST::objc_msg_send_expression() QVERIFY(declarator); QVERIFY(!declarator->attributes); - QVERIFY(declarator->ptr_operators && !declarator->ptr_operators->next && declarator->ptr_operators->asPointer() && !declarator->ptr_operators->asPointer()->cv_qualifier_seq); + QVERIFY(declarator->ptr_operators && !declarator->ptr_operators->next + && declarator->ptr_operators->value->asPointer() + && ! declarator->ptr_operators->value->asPointer()->cv_qualifier_seq); QVERIFY(declarator->core_declarator && declarator->core_declarator->asDeclaratorId()); NameAST *objNameId = declarator->core_declarator->asDeclaratorId()->name;