Commit e3baca2e authored by Roberto Raggi's avatar Roberto Raggi

Prefer C++ Initializer when parsing init-declarators.

parent f9a3df18
......@@ -977,7 +977,7 @@ bool Parser::parseCoreDeclarator(DeclaratorAST *&node)
return false;
}
bool Parser::parseDeclarator(DeclaratorAST *&node)
bool Parser::parseDeclarator(DeclaratorAST *&node, bool stopAtCppInitializer)
{
if (! parseCoreDeclarator(node))
return false;
......@@ -988,6 +988,25 @@ bool Parser::parseDeclarator(DeclaratorAST *&node)
unsigned startOfPostDeclarator = cursor();
if (LA() == T_LPAREN) {
if (stopAtCppInitializer) {
unsigned lparen_token = cursor();
ExpressionAST *initializer = 0;
bool blocked = blockErrors(true);
if (parseInitializer(initializer)) {
if (NestedExpressionAST *expr = initializer->asNestedExpression()) {
if (expr->expression && expr->rparen_token && (LA() == T_COMMA || LA() == T_SEMICOLON)) {
rewind(lparen_token);
blockErrors(blocked);
return true;
}
}
}
blockErrors(blocked);
rewind(lparen_token);
}
FunctionDeclaratorAST *ast = new (_pool) FunctionDeclaratorAST;
ast->lparen_token = consumeToken();
parseParameterDeclarationClause(ast->parameters);
......@@ -1494,7 +1513,7 @@ bool Parser::parseInitDeclarator(DeclaratorAST *&node,
if (acceptStructDeclarator && LA() == T_COLON) {
// anonymous bit-field declaration.
// ### TODO create the AST
} else if (! parseDeclarator(node)) {
} else if (! parseDeclarator(node, /*stopAtCppInitializer = */ ! acceptStructDeclarator)) {
return false;
}
......
......@@ -107,7 +107,7 @@ public:
bool parseSimpleDeclaration(DeclarationAST *&node, bool acceptStructDeclarator = false);
bool parseDeclarationStatement(StatementAST *&node);
bool parseCoreDeclarator(DeclaratorAST *&node);
bool parseDeclarator(DeclaratorAST *&node);
bool parseDeclarator(DeclaratorAST *&node, bool stopAtCppInitializer = false);
bool parseDeleteExpression(ExpressionAST *&node);
bool parseDoStatement(StatementAST *&node);
bool parseElaboratedTypeSpecifier(SpecifierAST *&node);
......
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