diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp index a20f74372bbaed46686be888b93b0476a7c2560d..987c6a1664b125f051d4c06948b7f62682472200 100644 --- a/src/shared/cplusplus/AST.cpp +++ b/src/shared/cplusplus/AST.cpp @@ -1175,10 +1175,8 @@ unsigned NewTypeIdAST::firstToken() const unsigned NewTypeIdAST::lastToken() const { - for (NewArrayDeclaratorAST *it = new_array_declarators; it; it = it->next) { - if (! it->next) - return it->lastToken(); - } + if (new_array_declarators) + return new_array_declarators->lastToken(); for (PtrOperatorAST *it = ptr_operators; it; it = it->next) { if (it->next) diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h index 3dd95c5e531b2cb9e3d2df950a146ed00e63a258..310b3d39e2be8fe27ac57c02b52dcb3d5a204d8b 100644 --- a/src/shared/cplusplus/AST.h +++ b/src/shared/cplusplus/AST.h @@ -1333,7 +1333,6 @@ public: unsigned lbracket_token; ExpressionAST *expression; unsigned rbracket_token; - NewArrayDeclaratorAST *next; public: virtual NewArrayDeclaratorAST *asNewArrayDeclarator() { return this; } @@ -1392,7 +1391,7 @@ class CPLUSPLUS_EXPORT NewTypeIdAST: public AST public: SpecifierAST *type_specifier; PtrOperatorAST *ptr_operators; - NewArrayDeclaratorAST *new_array_declarators; + NewArrayDeclaratorListAST *new_array_declarators; public: virtual NewTypeIdAST *asNewTypeId() { return this; } diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp index 1188eb0991c430f8f864d7b201a21eefe6ff67f4..c9e86fb07fb1e528a94cfd91664c88f5f93382db 100644 --- a/src/shared/cplusplus/ASTVisit.cpp +++ b/src/shared/cplusplus/ASTVisit.cpp @@ -565,8 +565,7 @@ void NewTypeIdAST::accept0(ASTVisitor *visitor) accept(it, visitor); for (PtrOperatorAST *it = ptr_operators; it; it = it->next) accept(it, visitor); - for (NewArrayDeclaratorAST *it = new_array_declarators; it; it = it->next) - accept(it, visitor); + accept(new_array_declarators, visitor); } visitor->endVisit(this); } diff --git a/src/shared/cplusplus/ASTfwd.h b/src/shared/cplusplus/ASTfwd.h index fbf3743faccb7c04606b736d01fb8e3abd7969de..1eae7c3fff62be4531f555e6cb1875fee3a58943 100644 --- a/src/shared/cplusplus/ASTfwd.h +++ b/src/shared/cplusplus/ASTfwd.h @@ -198,6 +198,7 @@ typedef List<DeclaratorAST *> DeclaratorListAST; typedef List<BaseSpecifierAST *> BaseSpecifierListAST; typedef List<EnumeratorAST *> EnumeratorListAST; typedef List<MemInitializerAST *> MemInitializerListAST; +typedef List<NewArrayDeclaratorAST *> NewArrayDeclaratorListAST; typedef List<NameAST *> ObjCIdentifierListAST; typedef List<ObjCMessageArgumentAST *> ObjCMessageArgumentListAST; diff --git a/src/shared/cplusplus/CheckExpression.cpp b/src/shared/cplusplus/CheckExpression.cpp index 14ced9509a68d222c245ff55ddc10092853f00bf..763258dfda79b617a66b79f682cb0072492876d9 100644 --- a/src/shared/cplusplus/CheckExpression.cpp +++ b/src/shared/cplusplus/CheckExpression.cpp @@ -207,8 +207,10 @@ bool CheckExpression::visit(NewExpressionAST *ast) if (ast->new_type_id) { FullySpecifiedType ty = semantic()->check(ast->new_type_id->type_specifier, _scope); - for (NewArrayDeclaratorAST *it = ast->new_type_id->new_array_declarators; it; it = it->next) { - FullySpecifiedType exprTy = semantic()->check(it->expression, _scope); + for (NewArrayDeclaratorListAST *it = ast->new_type_id->new_array_declarators; it; it = it->next) { + if (NewArrayDeclaratorAST *declarator = it->value) { + FullySpecifiedType exprTy = semantic()->check(declarator->expression, _scope); + } } } diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp index 86f046b9c5d9ab625a8894d6d8e730c08b5ad27a..9179f21db1386dce1424ddffa5f6fd940a603fe3 100644 --- a/src/shared/cplusplus/Parser.cpp +++ b/src/shared/cplusplus/Parser.cpp @@ -3810,7 +3810,7 @@ bool Parser::parseNewTypeId(NewTypeIdAST *&node) PtrOperatorAST **ptrop_it = &ast->ptr_operators; while (parsePtrOperator(*ptrop_it)) ptrop_it = &(*ptrop_it)->next; - NewArrayDeclaratorAST **it = &ast->new_array_declarators; + NewArrayDeclaratorListAST **it = &ast->new_array_declarators; while (parseNewArrayDeclarator(*it)) it = &(*it)->next; node = ast; @@ -3818,7 +3818,7 @@ bool Parser::parseNewTypeId(NewTypeIdAST *&node) } -bool Parser::parseNewArrayDeclarator(NewArrayDeclaratorAST *&node) +bool Parser::parseNewArrayDeclarator(NewArrayDeclaratorListAST *&node) { DEBUG_THIS_RULE(); if (LA() != T_LBRACKET) @@ -3828,7 +3828,9 @@ bool Parser::parseNewArrayDeclarator(NewArrayDeclaratorAST *&node) ast->lbracket_token = consumeToken(); parseExpression(ast->expression); match(T_RBRACKET, &ast->rbracket_token); - node = ast; + + node = new (_pool) NewArrayDeclaratorListAST; + node->value = ast; return true; } diff --git a/src/shared/cplusplus/Parser.h b/src/shared/cplusplus/Parser.h index 40f2f7e558c38535d12f68a5f1cc3e8ebc1870a0..57a7eaf760a130e12d38a4b75a4424eca5330a14 100644 --- a/src/shared/cplusplus/Parser.h +++ b/src/shared/cplusplus/Parser.h @@ -146,7 +146,7 @@ public: bool parseNestedNameSpecifierOpt(NestedNameSpecifierAST *&name, bool acceptTemplateId); bool parseNamespace(DeclarationAST *&node); bool parseNamespaceAliasDefinition(DeclarationAST *&node); - bool parseNewArrayDeclarator(NewArrayDeclaratorAST *&node); + bool parseNewArrayDeclarator(NewArrayDeclaratorListAST *&node); bool parseNewExpression(ExpressionAST *&node); bool parseNewPlacement(NewPlacementAST *&node); bool parseNewInitializer(NewInitializerAST *&node);