Commit a3d0406d authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed throw expression parsing.

parent fac977a5
......@@ -182,7 +182,10 @@ inline bool isRightAssociative(int tokenKind)
#endif
#define PARSE_EXPRESSION_WITH_OPERATOR_PRECEDENCE(node, minPrecedence) { \
if (!parseCastExpression(node)) \
if (LA() == T_THROW) { \
if (!parseThrowExpression(node)) \
return false; \
} else if (!parseCastExpression(node)) \
return false; \
\
parseExpressionWithOperatorPrecedence(node, minPrecedence); \
......@@ -2322,14 +2325,27 @@ bool Parser::parseStringLiteral(ExpressionAST *&node)
bool Parser::parseExpressionStatement(StatementAST *&node)
{
DEBUG_THIS_RULE();
ExpressionAST *expression = 0;
if (LA() == T_SEMICOLON || parseExpression(expression)) {
if (LA() == T_SEMICOLON) {
ExpressionStatementAST *ast = new (_pool) ExpressionStatementAST;
ast->expression = expression;
match(T_SEMICOLON, &ast->semicolon_token);
node = ast;
return true;
}
ExpressionAST *expression = 0;
MemoryPool *oldPool = _pool;
MemoryPool tmp;
_pool = &tmp;
if (parseExpression(expression)) {
ExpressionStatementAST *ast = new (oldPool) ExpressionStatementAST;
ast->expression = expression->clone(oldPool);
match(T_SEMICOLON, &ast->semicolon_token);
node = ast;
_pool = oldPool;
return true;
}
_pool = oldPool;
return false;
}
......
......@@ -51,6 +51,7 @@ private slots:
void condition_1();
void init_1();
void conditional_1();
void throw_1();
// statements
void if_statement_1();
......@@ -341,6 +342,14 @@ void tst_AST::conditional_1()
QCOMPARE(unit->spell(one->literal_token), "1");
}
void tst_AST::throw_1()
{
QSharedPointer<TranslationUnit> unit(parseStatement("throw 1;"));
AST *ast = unit->ast();
QVERIFY(ast != 0);
QVERIFY(ast->asExpressionStatement());
}
void tst_AST::function_call_1()
{
QSharedPointer<TranslationUnit> unit(parseStatement("retranslateUi(blah);"));
......
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