diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp index 570bcd9711c931aa01d25f0d1a15839e4317db42..084334a9ab4ca396cb3fd1b07daf67d8e8b4f7bc 100644 --- a/src/shared/cplusplus/AST.cpp +++ b/src/shared/cplusplus/AST.cpp @@ -2226,8 +2226,8 @@ unsigned ObjCFastEnumerationAST::firstToken() const unsigned ObjCFastEnumerationAST::lastToken() const { - if (body_statement) - return body_statement->lastToken(); + if (statement) + return statement->lastToken(); else if (rparen_token) return rparen_token + 1; else if (fast_enumeratable_expression) diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h index f21d9042fd46177307ef8d6d66228c386db1237a..a26384b74fd8074aa66416944e511ad3a1745ddc 100644 --- a/src/shared/cplusplus/AST.h +++ b/src/shared/cplusplus/AST.h @@ -2690,7 +2690,7 @@ public: unsigned in_token; ExpressionAST *fast_enumeratable_expression; unsigned rparen_token; - StatementAST *body_statement; + StatementAST *statement; public: // annotations Block *symbol; diff --git a/src/shared/cplusplus/ASTMatcher.cpp b/src/shared/cplusplus/ASTMatcher.cpp index b7920f767f4395fbf2a046abdb73f2f58dd32546..138950c2309307b761cf1c61ddd794db4e678f63 100644 --- a/src/shared/cplusplus/ASTMatcher.cpp +++ b/src/shared/cplusplus/ASTMatcher.cpp @@ -2439,9 +2439,9 @@ bool ASTMatcher::match(ObjCFastEnumerationAST *node, ObjCFastEnumerationAST *pat pattern->rparen_token = node->rparen_token; - if (! pattern->body_statement) - pattern->body_statement = node->body_statement; - else if (! AST::match(node->body_statement, pattern->body_statement, this)) + if (! pattern->statement) + pattern->statement = node->statement; + else if (! AST::match(node->statement, pattern->statement, this)) return false; return true; diff --git a/src/shared/cplusplus/ASTPatternBuilder.h b/src/shared/cplusplus/ASTPatternBuilder.h index 5fedf7f909083ff52e2cb09c48c790e8a49b993f..aa95d8fe35246dc682853ee9403e3c86cf36f1e3 100644 --- a/src/shared/cplusplus/ASTPatternBuilder.h +++ b/src/shared/cplusplus/ASTPatternBuilder.h @@ -880,13 +880,13 @@ public: return __ast; } - ObjCFastEnumerationAST *ObjCFastEnumeration(DeclaratorAST *declarator = 0, ExpressionAST *initializer = 0, ExpressionAST *fast_enumeratable_expression = 0, StatementAST *body_statement = 0) + ObjCFastEnumerationAST *ObjCFastEnumeration(DeclaratorAST *declarator = 0, ExpressionAST *initializer = 0, ExpressionAST *fast_enumeratable_expression = 0, StatementAST *statement = 0) { ObjCFastEnumerationAST *__ast = new (&pool) ObjCFastEnumerationAST; __ast->declarator = declarator; __ast->initializer = initializer; __ast->fast_enumeratable_expression = fast_enumeratable_expression; - __ast->body_statement = body_statement; + __ast->statement = statement; return __ast; } diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp index 877dd8df743ef74181c108784d51cf6600d89a13..070cf7fd8569854c44067d89d3dd71b970a76002 100644 --- a/src/shared/cplusplus/ASTVisit.cpp +++ b/src/shared/cplusplus/ASTVisit.cpp @@ -1066,7 +1066,7 @@ void ObjCFastEnumerationAST::accept0(ASTVisitor *visitor) accept(declarator, visitor); accept(initializer, visitor); accept(fast_enumeratable_expression, visitor); - accept(body_statement, visitor); + accept(statement, visitor); } visitor->endVisit(this); } diff --git a/src/shared/cplusplus/CheckStatement.cpp b/src/shared/cplusplus/CheckStatement.cpp index b02ba83749fd202ff236b497ce7aaf96067e504b..878d3fbbeb36a553fb911cc534c0e6cf8ab598e8 100644 --- a/src/shared/cplusplus/CheckStatement.cpp +++ b/src/shared/cplusplus/CheckStatement.cpp @@ -155,61 +155,64 @@ bool CheckStatement::visit(ExpressionStatementAST *ast) return false; } -bool CheckStatement::visit(ForeachStatementAST *ast) +bool CheckStatement::forEachFastEnum(unsigned firstToken, + unsigned lastToken, + SpecifierListAST *type_specifier_list, + DeclaratorAST *declarator, + ExpressionAST *initializer, + ExpressionAST *expression, + StatementAST *statement, + Block *&symbol) { - Block *block = control()->newBlock(ast->foreach_token); - block->setStartOffset(tokenAt(ast->firstToken()).offset); - block->setEndOffset(tokenAt(ast->lastToken()).offset); - ast->symbol = block; + Block *block = control()->newBlock(firstToken); + block->setStartOffset(tokenAt(firstToken).offset); + block->setEndOffset(tokenAt(lastToken).offset); + symbol = block; _scope->enterSymbol(block); Scope *previousScope = switchScope(block->members()); - if (ast->type_specifier_list && ast->declarator) { - FullySpecifiedType ty = semantic()->check(ast->type_specifier_list, _scope); + if (type_specifier_list && declarator) { + FullySpecifiedType ty = semantic()->check(type_specifier_list, _scope); const Name *name = 0; - ty = semantic()->check(ast->declarator, ty, _scope, &name); - unsigned location = ast->declarator->firstToken(); - if (CoreDeclaratorAST *core_declarator = ast->declarator->core_declarator) + ty = semantic()->check(declarator, ty, _scope, &name); + unsigned location = declarator->firstToken(); + if (CoreDeclaratorAST *core_declarator = declarator->core_declarator) location = core_declarator->firstToken(); Declaration *decl = control()->newDeclaration(location, name); decl->setType(ty); _scope->enterSymbol(decl); } else { - FullySpecifiedType exprTy = semantic()->check(ast->initializer, _scope); + FullySpecifiedType exprTy = semantic()->check(initializer, _scope); (void) exprTy; } - FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope); - semantic()->check(ast->statement, _scope); + FullySpecifiedType exprTy = semantic()->check(expression, _scope); + semantic()->check(statement, _scope); (void) switchScope(previousScope); return false; } -bool CheckStatement::visit(ObjCFastEnumerationAST *ast) +bool CheckStatement::visit(ForeachStatementAST *ast) { - Block *block = control()->newBlock(ast->for_token); - block->setStartOffset(tokenAt(ast->firstToken()).offset); - block->setEndOffset(tokenAt(ast->lastToken()).offset); - ast->symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); - if (ast->type_specifier_list && ast->declarator) { - FullySpecifiedType ty = semantic()->check(ast->type_specifier_list, _scope); - const Name *name = 0; - ty = semantic()->check(ast->declarator, ty, _scope, &name); - unsigned location = ast->declarator->firstToken(); - if (CoreDeclaratorAST *core_declarator = ast->declarator->core_declarator) - location = core_declarator->firstToken(); - Declaration *decl = control()->newDeclaration(location, name); - decl->setType(ty); - _scope->enterSymbol(decl); - } else { - FullySpecifiedType exprTy = semantic()->check(ast->initializer, _scope); - (void) exprTy; - } + return forEachFastEnum(ast->firstToken(), + ast->lastToken(), + ast->type_specifier_list, + ast->declarator, + ast->initializer, + ast->expression, + ast->statement, + ast->symbol); +} - semantic()->check(ast->body_statement, _scope); - (void) switchScope(previousScope); - return false; +bool CheckStatement::visit(ObjCFastEnumerationAST *ast) +{ + return forEachFastEnum(ast->firstToken(), + ast->lastToken(), + ast->type_specifier_list, + ast->declarator, + ast->initializer, + ast->fast_enumeratable_expression, + ast->statement, + ast->symbol); } bool CheckStatement::visit(ForStatementAST *ast) diff --git a/src/shared/cplusplus/CheckStatement.h b/src/shared/cplusplus/CheckStatement.h index e31d507a5efb35d581c097577890a6c939f7bac2..5c1b1ff02d845158de4ee25e7e379912aed3be97 100644 --- a/src/shared/cplusplus/CheckStatement.h +++ b/src/shared/cplusplus/CheckStatement.h @@ -90,6 +90,14 @@ protected: virtual bool visit(WhileStatementAST *ast); virtual bool visit(QtMemberDeclarationAST *ast); + bool forEachFastEnum(unsigned firstToken, + unsigned lastToken, + SpecifierListAST *type_specifier_list, + DeclaratorAST *declarator, + ExpressionAST *initializer, + ExpressionAST *expression, + StatementAST *statement, + Block *&symbol); private: StatementAST *_statement; Scope *_scope; diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp index d66457ea9e70585ff60ae27f9f52dffea97d4bbe..b40c59c4b7db8ed9bff472669b4bccce986a80d2 100644 --- a/src/shared/cplusplus/Parser.cpp +++ b/src/shared/cplusplus/Parser.cpp @@ -2433,7 +2433,7 @@ bool Parser::parseForStatement(StatementAST *&node) parseExpression(ast->fast_enumeratable_expression); match(T_RPAREN, &ast->rparen_token); - parseStatement(ast->body_statement); + parseStatement(ast->statement); node = ast; return true;