forked from qt-creator/qt-creator
C++: Add support for C++11 range-based 'for' loops
Change-Id: I7eef048a7952a79f031ae3d0abba68e3c5ffbfb8 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
committed by
Roberto Raggi
parent
7f943caedb
commit
da2aa0df72
27
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
27
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -3230,6 +3230,32 @@ bool Parser::parseForStatement(StatementAST *&node)
|
||||
rewind(startOfTypeSpecifier);
|
||||
}
|
||||
|
||||
if (cxx0xEnabled()) {
|
||||
RangeBasedForStatementAST *ast = new (_pool) RangeBasedForStatementAST;
|
||||
ast->for_token = for_token;
|
||||
ast->lparen_token = lparen_token;
|
||||
|
||||
if (parseTypeSpecifier(ast->type_specifier_list))
|
||||
parseDeclarator(ast->declarator, ast->type_specifier_list);
|
||||
|
||||
if ((ast->type_specifier_list || ast->declarator) && LA() == T_COLON) {
|
||||
ast->colon_token = consumeToken();
|
||||
blockErrors(blocked);
|
||||
|
||||
parseExpression(ast->expression);
|
||||
match(T_RPAREN, &ast->rparen_token);
|
||||
parseStatement(ast->statement);
|
||||
|
||||
// We need both type specifier and declarator for C++11 range-based for
|
||||
if (!ast->type_specifier_list || !ast->declarator)
|
||||
error(for_token, "expected declaration with type specifier");
|
||||
|
||||
node = ast;
|
||||
return true;
|
||||
}
|
||||
rewind(startOfTypeSpecifier);
|
||||
}
|
||||
|
||||
blockErrors(blocked);
|
||||
|
||||
// Normal C/C++ for-statement parsing
|
||||
@@ -6108,4 +6134,3 @@ void Parser::fatal(unsigned index, const char *format, ...)
|
||||
va_end(ap);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user