From aff9a743668575898d5eafe30e8e240e4a53342a Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 10 Nov 2009 14:16:39 +0100 Subject: Cleanup NewArrayDeclaratorAST --- src/shared/cplusplus/AST.cpp | 6 ++---- src/shared/cplusplus/AST.h | 3 +-- src/shared/cplusplus/ASTVisit.cpp | 3 +-- src/shared/cplusplus/ASTfwd.h | 1 + src/shared/cplusplus/CheckExpression.cpp | 6 ++++-- src/shared/cplusplus/Parser.cpp | 8 +++++--- src/shared/cplusplus/Parser.h | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src/shared/cplusplus') diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp index a20f74372b..987c6a1664 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 3dd95c5e53..310b3d39e2 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 1188eb0991..c9e86fb07f 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 fbf3743fac..1eae7c3fff 100644 --- a/src/shared/cplusplus/ASTfwd.h +++ b/src/shared/cplusplus/ASTfwd.h @@ -198,6 +198,7 @@ typedef List DeclaratorListAST; typedef List BaseSpecifierListAST; typedef List EnumeratorListAST; typedef List MemInitializerListAST; +typedef List NewArrayDeclaratorListAST; typedef List ObjCIdentifierListAST; typedef List ObjCMessageArgumentListAST; diff --git a/src/shared/cplusplus/CheckExpression.cpp b/src/shared/cplusplus/CheckExpression.cpp index 14ced9509a..763258dfda 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 86f046b9c5..9179f21db1 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 40f2f7e558..57a7eaf760 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); -- cgit v1.2.1