forked from qt-creator/qt-creator
Fixed throw expression parsing.
This commit is contained in:
@@ -182,7 +182,10 @@ inline bool isRightAssociative(int tokenKind)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PARSE_EXPRESSION_WITH_OPERATOR_PRECEDENCE(node, minPrecedence) { \
|
#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; \
|
return false; \
|
||||||
\
|
\
|
||||||
parseExpressionWithOperatorPrecedence(node, minPrecedence); \
|
parseExpressionWithOperatorPrecedence(node, minPrecedence); \
|
||||||
@@ -2322,14 +2325,27 @@ bool Parser::parseStringLiteral(ExpressionAST *&node)
|
|||||||
bool Parser::parseExpressionStatement(StatementAST *&node)
|
bool Parser::parseExpressionStatement(StatementAST *&node)
|
||||||
{
|
{
|
||||||
DEBUG_THIS_RULE();
|
DEBUG_THIS_RULE();
|
||||||
ExpressionAST *expression = 0;
|
if (LA() == T_SEMICOLON) {
|
||||||
if (LA() == T_SEMICOLON || parseExpression(expression)) {
|
|
||||||
ExpressionStatementAST *ast = new (_pool) ExpressionStatementAST;
|
ExpressionStatementAST *ast = new (_pool) ExpressionStatementAST;
|
||||||
ast->expression = expression;
|
|
||||||
match(T_SEMICOLON, &ast->semicolon_token);
|
match(T_SEMICOLON, &ast->semicolon_token);
|
||||||
node = ast;
|
node = ast;
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ private slots:
|
|||||||
void condition_1();
|
void condition_1();
|
||||||
void init_1();
|
void init_1();
|
||||||
void conditional_1();
|
void conditional_1();
|
||||||
|
void throw_1();
|
||||||
|
|
||||||
// statements
|
// statements
|
||||||
void if_statement_1();
|
void if_statement_1();
|
||||||
@@ -341,6 +342,14 @@ void tst_AST::conditional_1()
|
|||||||
QCOMPARE(unit->spell(one->literal_token), "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()
|
void tst_AST::function_call_1()
|
||||||
{
|
{
|
||||||
QSharedPointer<TranslationUnit> unit(parseStatement("retranslateUi(blah);"));
|
QSharedPointer<TranslationUnit> unit(parseStatement("retranslateUi(blah);"));
|
||||||
|
|||||||
Reference in New Issue
Block a user