Commit 2aa27e6d authored by Christian Kamm's avatar Christian Kamm Committed by hjk

C++11: Make expression-list expand to initializer-list.

This will fix a couple more places where brace-init-lists and
pack expansions are allowed but are not currently accepted by
the parser. For example:

foo(abc...);

now parses correctly.

Change-Id: I93710cef35154fea8437329f3174e4a2d56637b8
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 0c3acb80
......@@ -2651,7 +2651,7 @@ bool Parser::parseInitializer0x(ExpressionAST *&node, unsigned *equals_token)
}
else if (LA() == T_LPAREN) {
return parseExpressionListParen0x(node);
return parseExpressionListParen(node);
}
return false;
......@@ -2787,7 +2787,7 @@ bool Parser::parseMemInitializer(MemInitializerListAST *&node)
ast->name = name;
if (LA() == T_LPAREN) {
parseExpressionListParen0x(ast->expression);
parseExpressionListParen(ast->expression);
} else if (_cxx0xEnabled && LA() == T_LBRACE) {
parseBracedInitList0x(ast->expression);
} else {
......@@ -2834,18 +2834,13 @@ bool Parser::parseTypeIdList(ExpressionListAST *&node)
return false;
}
// Note that this function doesn't parse a C++11-style expression-list
// yet, so it doesn't allow for brace-initializers.
bool Parser::parseExpressionList(ExpressionListAST *&node)
{
DEBUG_THIS_RULE();
#ifdef CPLUSPLUS_WITH_CXXOX_INITIALIZER_LIST
if (_cxx0xEnabled)
return parseInitializerList0x(node);
#endif
// ### remove me
ExpressionListAST **expression_list_ptr = &node;
ExpressionAST *expression = 0;
if (parseAssignmentExpression(expression)) {
......@@ -4959,7 +4954,7 @@ bool Parser::parseUnaryExpression(ExpressionAST *&node)
}
// new-placement ::= T_LPAREN expression-list T_RPAREN
bool Parser::parseExpressionListParen(ExpressionListParenAST *&node)
bool Parser::parseExpressionListParen(ExpressionAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_LPAREN) {
......@@ -4979,28 +4974,6 @@ bool Parser::parseExpressionListParen(ExpressionListParenAST *&node)
return false;
}
// like above, but for C++11 where expression-list expands to initializer-list
// and can contain braced-init-list members
bool Parser::parseExpressionListParen0x(ExpressionAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_LPAREN) {
unsigned lparen_token = consumeToken();
ExpressionListAST *expression_list = 0;
if (parseInitializerList0x(expression_list) && expression_list && LA() == T_RPAREN) {
unsigned rparen_token = consumeToken();
ExpressionListParenAST *ast = new (_pool) ExpressionListParenAST;
ast->lparen_token = lparen_token;
ast->expression_list = expression_list;
ast->rparen_token = rparen_token;
node = ast;
return true;
}
}
return false;
}
// new-expression ::= T_COLON_COLON? T_NEW new-placement.opt
// new-type-id new-initializer.opt
......@@ -5018,14 +4991,14 @@ bool Parser::parseNewExpression(ExpressionAST *&node)
ast->new_token = consumeToken();
ExpressionListParenAST *parenExpressionList = 0;
ExpressionAST *parenExpressionList = 0;
if (parseExpressionListParen(parenExpressionList)) {
unsigned after_new_placement = cursor();
NewTypeIdAST *new_type_id = 0;
if (parseNewTypeId(new_type_id)) {
ast->new_placement = parenExpressionList;
ast->new_placement = parenExpressionList->asExpressionListParen();
ast->new_type_id = new_type_id;
parseNewInitializer(ast->new_initializer);
// recognized new-placement.opt new-type-id new-initializer.opt
......@@ -5038,7 +5011,7 @@ bool Parser::parseNewExpression(ExpressionAST *&node)
unsigned lparen_token = consumeToken();
ExpressionAST *type_id = 0;
if (parseTypeId(type_id) && LA() == T_RPAREN) {
ast->new_placement = parenExpressionList;
ast->new_placement = parenExpressionList->asExpressionListParen();
ast->lparen_token = lparen_token;
ast->type_id = type_id;
ast->rparen_token = consumeToken();
......
......@@ -132,8 +132,7 @@ public:
bool parseNamespaceAliasDefinition(DeclarationAST *&node);
bool parseNewArrayDeclarator(NewArrayDeclaratorListAST *&node);
bool parseNewExpression(ExpressionAST *&node);
bool parseExpressionListParen(ExpressionListParenAST *&node);
bool parseExpressionListParen0x(ExpressionAST *&node);
bool parseExpressionListParen(ExpressionAST *&node);
bool parseNewInitializer(NewInitializerAST *&node);
bool parseNewTypeId(NewTypeIdAST *&node);
bool parseOperator(OperatorAST *&node);
......
template <class ... Args>
int foo(Args args...) {
bar(args..., {args...}, e, f);
}
......@@ -145,6 +145,7 @@ void tst_cxx11::parse_data()
QTest::newRow("aliasDecl.1") << "aliasDecl.1.cpp" << "";
QTest::newRow("enums.1") << "enums.1.cpp" << "";
QTest::newRow("templateGreaterGreater.1") << "templateGreaterGreater.1.cpp" << "";
QTest::newRow("packExpansion.1") << "packExpansion.1.cpp" << "";
}
void tst_cxx11::parse()
......
Markdown is supported
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