Commit 52786e1e authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Improved parsing of expression-or-declaration statements.

Done-with: Erik Verbruggen
parent be82d9dd
...@@ -2936,8 +2936,14 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) ...@@ -2936,8 +2936,14 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
const bool blocked = blockErrors(true); const bool blocked = blockErrors(true);
ExpressionAST *expression = 0; ExpressionAST *expression = 0;
if (parseExpression(expression) && LA() == T_SEMICOLON) { const bool hasExpression = parseExpression(expression);
const unsigned semicolon_token = consumeToken(); const unsigned afterExpression = cursor();
if (hasExpression/* && LA() == T_SEMICOLON*/) {
//const unsigned semicolon_token = consumeToken();
unsigned semicolon_token = 0;
if (LA() == T_SEMICOLON)
semicolon_token = cursor();
ExpressionStatementAST *as_expression = new (_pool) ExpressionStatementAST; ExpressionStatementAST *as_expression = new (_pool) ExpressionStatementAST;
as_expression->expression = expression; as_expression->expression = expression;
...@@ -2951,6 +2957,7 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) ...@@ -2951,6 +2957,7 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
if (! binary->left_expression->asBinaryExpression()) { if (! binary->left_expression->asBinaryExpression()) {
(void) blockErrors(blocked); (void) blockErrors(blocked);
node = as_expression; node = as_expression;
match(T_SEMICOLON, &as_expression->semicolon_token);
return true; return true;
} else { } else {
invalidAssignment = true; invalidAssignment = true;
...@@ -2960,6 +2967,7 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) ...@@ -2960,6 +2967,7 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
if (call->base_expression->asIdExpression() != 0) { if (call->base_expression->asIdExpression() != 0) {
(void) blockErrors(blocked); (void) blockErrors(blocked);
node = as_expression; node = as_expression;
match(T_SEMICOLON, &as_expression->semicolon_token);
return true; return true;
} }
} }
...@@ -2968,12 +2976,12 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) ...@@ -2968,12 +2976,12 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
DeclarationAST *declaration = 0; DeclarationAST *declaration = 0;
if (parseSimpleDeclaration(declaration)) { if (parseSimpleDeclaration(declaration)) {
SimpleDeclarationAST *simple = declaration->asSimpleDeclaration();
if (simple->semicolon_token == semicolon_token && simple->decl_specifier_list && simple->declarator_list) {
DeclarationStatementAST *as_declaration = new (_pool) DeclarationStatementAST; DeclarationStatementAST *as_declaration = new (_pool) DeclarationStatementAST;
as_declaration->declaration = declaration; as_declaration->declaration = declaration;
if (invalidAssignment || (simple->decl_specifier_list != 0 && simple->declarator_list != 0)) { SimpleDeclarationAST *simple = declaration->asSimpleDeclaration();
if (! semicolon_token || invalidAssignment || semicolon_token != simple->semicolon_token ||
(simple->decl_specifier_list != 0 && simple->declarator_list != 0)) {
node = as_declaration; node = as_declaration;
(void) blockErrors(blocked); (void) blockErrors(blocked);
return true; return true;
...@@ -2983,15 +2991,20 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node) ...@@ -2983,15 +2991,20 @@ bool Parser::parseExpressionOrDeclarationStatement(StatementAST *&node)
ast->declaration = as_declaration; ast->declaration = as_declaration;
ast->expression = as_expression; ast->expression = as_expression;
node = ast; node = ast;
(void) blockErrors(blocked);
return true;
} }
}
rewind(semicolon_token + 1);
(void) blockErrors(blocked); (void) blockErrors(blocked);
rewind(afterExpression);
match(T_SEMICOLON, &as_expression->semicolon_token);
return true; return true;
} }
rewind(start); rewind(start);
(void) blockErrors(blocked); (void) blockErrors(blocked);
return parseDeclarationStatement(node); return parseDeclarationStatement(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