Commit 9bd86e7d authored by Christian Kamm's avatar Christian Kamm Committed by hjk
Browse files

C++11: Allow brace-init-list in range-for statement.



Also drop the unused 'initializer' member from
RangeBasedForStatementAST.

Change-Id: I078ebbc85cafa643af4bfe62d698bf7de71360e4
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent ecd54059
......@@ -4362,9 +4362,6 @@ unsigned RangeBasedForStatementAST::firstToken() const
if (declarator)
if (unsigned candidate = declarator->firstToken())
return candidate;
if (initializer)
if (unsigned candidate = initializer->firstToken())
return candidate;
if (colon_token)
return colon_token;
if (expression)
......@@ -4391,9 +4388,6 @@ unsigned RangeBasedForStatementAST::lastToken() const
return candidate;
if (colon_token)
return colon_token + 1;
if (initializer)
if (unsigned candidate = initializer->lastToken())
return candidate;
if (declarator)
if (unsigned candidate = declarator->lastToken())
return candidate;
......
......@@ -1921,7 +1921,6 @@ public:
SpecifierListAST *type_specifier_list;
DeclaratorAST *declarator;
// or an expression
ExpressionAST *initializer;
unsigned colon_token;
ExpressionAST *expression;
unsigned rparen_token;
......@@ -1936,7 +1935,6 @@ public:
, lparen_token(0)
, type_specifier_list(0)
, declarator(0)
, initializer(0)
, colon_token(0)
, expression(0)
, rparen_token(0)
......
......@@ -681,8 +681,6 @@ RangeBasedForStatementAST *RangeBasedForStatementAST::clone(MemoryPool *pool) co
*ast_iter = new (pool) SpecifierListAST((iter->value) ? iter->value->clone(pool) : 0);
if (declarator)
ast->declarator = declarator->clone(pool);
if (initializer)
ast->initializer = initializer->clone(pool);
ast->colon_token = colon_token;
if (expression)
ast->expression = expression->clone(pool);
......
......@@ -1154,11 +1154,6 @@ bool ASTMatcher::match(RangeBasedForStatementAST *node, RangeBasedForStatementAS
else if (! AST::match(node->declarator, pattern->declarator, this))
return false;
if (! pattern->initializer)
pattern->initializer = node->initializer;
else if (! AST::match(node->initializer, pattern->initializer, this))
return false;
pattern->colon_token = node->colon_token;
if (! pattern->expression)
......
......@@ -447,12 +447,11 @@ public:
return __ast;
}
RangeBasedForStatementAST *RangeBasedForStatement(SpecifierListAST *type_specifier_list = 0, DeclaratorAST *declarator = 0, ExpressionAST *initializer = 0, ExpressionAST *expression = 0, StatementAST *statement = 0)
RangeBasedForStatementAST *RangeBasedForStatement(SpecifierListAST *type_specifier_list = 0, DeclaratorAST *declarator = 0, ExpressionAST *expression = 0, StatementAST *statement = 0)
{
RangeBasedForStatementAST *__ast = new (&pool) RangeBasedForStatementAST;
__ast->type_specifier_list = type_specifier_list;
__ast->declarator = declarator;
__ast->initializer = initializer;
__ast->expression = expression;
__ast->statement = statement;
return __ast;
......
......@@ -493,7 +493,6 @@ void RangeBasedForStatementAST::accept0(ASTVisitor *visitor)
if (visitor->visit(this)) {
accept(type_specifier_list, visitor);
accept(declarator, visitor);
accept(initializer, visitor);
accept(expression, visitor);
accept(statement, visitor);
}
......
......@@ -1332,7 +1332,6 @@ bool Bind::visit(RangeBasedForStatementAST *ast)
block->addMember(decl);
}
/*ExpressionTy initializer =*/ this->expression(ast->initializer);
/*ExpressionTy expression =*/ this->expression(ast->expression);
this->statement(ast->statement);
(void) switchScope(previousScope);
......
......@@ -3429,7 +3429,11 @@ bool Parser::parseForStatement(StatementAST *&node)
ast->colon_token = consumeToken();
blockErrors(blocked);
parseExpression(ast->expression);
if (LA() == T_LBRACE) {
parseBracedInitList0x(ast->expression);
} else {
parseExpression(ast->expression);
}
match(T_RPAREN, &ast->rparen_token);
parseStatement(ast->statement);
......
......@@ -1025,7 +1025,6 @@ bool FindUsages::visit(RangeBasedForStatementAST *ast)
this->specifier(it->value);
}
this->declarator(ast->declarator);
this->expression(ast->initializer);
// unsigned comma_token = ast->comma_token;
this->expression(ast->expression);
// unsigned rparen_token = ast->rparen_token;
......
int main() {
for (int x : {1, 2, 3}) {}
for (int x : foo) ;
for (int& x : array) x += 2;
}
......@@ -141,6 +141,7 @@ void tst_cxx11::parse_data()
QTest::newRow("defaultdeleteInitializer.1") << "defaultdeleteInitializer.1.cpp" << "";
QTest::newRow("refQualifier.1") << "refQualifier.1.cpp" << "";
QTest::newRow("alignofAlignas.1") << "alignofAlignas.1.cpp" << "";
QTest::newRow("rangeFor.1") << "rangeFor.1.cpp" << "";
}
void tst_cxx11::parse()
......
......@@ -662,7 +662,6 @@ virtual bool visit(RangeBasedForStatementAST *ast)
for (SpecifierListAST *iter = ast->type_specifier_list; iter; iter = iter->next)
nonterminal(iter->value);
nonterminal(ast->declarator);
nonterminal(ast->initializer);
if (ast->colon_token)
terminal(ast->colon_token, ast);
nonterminal(ast->expression);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment