Commit c2d21739 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar
Browse files

C++: Add parser support for @throw statements.



Change-Id: I366733ec821ee264f182f4d4a3cf69cdada20cfc
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent a32343b9
......@@ -335,6 +335,7 @@ bool Parser::skipUntilStatement()
case T_AT_TRY:
case T_AT_SYNCHRONIZED:
case T_AT_THROW:
if (objCEnabled())
return true;
......@@ -3113,6 +3114,9 @@ bool Parser::parseStatement(StatementAST *&node)
case T_AT_SYNCHRONIZED:
return objCEnabled() && parseObjCSynchronizedStatement(node);
case T_AT_THROW:
return objCEnabled() && parseObjCThrowStatement(node);
case T_Q_D:
case T_Q_Q: {
QtMemberDeclarationAST *ast = new (_pool) QtMemberDeclarationAST;
......@@ -4452,6 +4456,8 @@ bool Parser::parseObjCTryStatement(StatementAST *& /*node*/)
return true;
}
/// objc-synchronized-statement:
/// @synchronized expression ;
bool Parser::parseObjCSynchronizedStatement(StatementAST *&node)
{
DEBUG_THIS_RULE();
......@@ -4470,6 +4476,23 @@ bool Parser::parseObjCSynchronizedStatement(StatementAST *&node)
return true;
}
/// objc-throw-statement:
/// @ throw expression ;
bool Parser::parseObjCThrowStatement(StatementAST *&/*node*/)
{
DEBUG_THIS_RULE();
if (LA() != T_AT_THROW)
return false;
/*throw_token =*/ consumeToken();
ExpressionAST *thrown_expression;
parseExpression(thrown_expression);
unsigned semicolon_token;
match(T_SEMICOLON, &semicolon_token);
return true;
}
bool Parser::parseObjCEncodeExpression(ExpressionAST *&node)
{
DEBUG_THIS_RULE();
......
......@@ -224,6 +224,7 @@ public:
bool parseObjCTryStatement(StatementAST *&node);
bool parseObjCSynchronizedStatement(StatementAST *&node);
bool parseObjCThrowStatement(StatementAST *&node);
bool parseObjCEncodeExpression(ExpressionAST *&node);
bool parseObjCProtocolExpression(ExpressionAST *&node);
bool parseObjCSelectorExpression(ExpressionAST *&node);
......
......@@ -162,6 +162,7 @@ private slots:
void objc_try_statement_1();
void objc_try_statement_2();
void objc_try_statement_3();
void objc_throw_statement();
// expressions with (square) brackets
void normal_array_access();
......@@ -1437,6 +1438,22 @@ void tst_AST::objc_try_statement_3()
QCOMPARE(diag.errorCount, 0);
}
void tst_AST::objc_throw_statement()
{
QSharedPointer<TranslationUnit> unit(
parseDeclaration(
"void tst() {\n"
" NSException *up = [NSException exceptionWithName:@\"NoException\"\n"
" reason:@\"No Reason :-)\"\n"
" userInfo:nil];\n"
" @throw up;\n"
"}\n"
));
AST *ast = unit->ast();
QVERIFY(ast);
QCOMPARE(diag.errorCount, 0);
}
void tst_AST::normal_array_access()
{
QSharedPointer<TranslationUnit> unit(parseDeclaration("\n"
......
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