add parsing, ast building and pretty printing support for C++ throw expressions.
Patch by Mike Stump!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47582 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Parse/ParseExpr.cpp b/Parse/ParseExpr.cpp
index 67ce5f1..46714b7 100644
--- a/Parse/ParseExpr.cpp
+++ b/Parse/ParseExpr.cpp
@@ -157,6 +157,7 @@
/// assignment-expression: [C99 6.5.16]
/// conditional-expression
/// unary-expression assignment-operator assignment-expression
+/// [C++] throw-expression [C++ 15]
///
/// assignment-operator: one of
/// = *= /= %= += -= <<= >>= &= ^= |=
@@ -166,6 +167,9 @@
/// expression ',' assignment-expression
///
Parser::ExprResult Parser::ParseExpression() {
+ if (Tok.is(tok::kw_throw))
+ return ParseThrowExpression();
+
ExprResult LHS = ParseCastExpression(false);
if (LHS.isInvalid) return LHS;
@@ -187,6 +191,9 @@
/// ParseAssignmentExpression - Parse an expr that doesn't include commas.
///
Parser::ExprResult Parser::ParseAssignmentExpression() {
+ if (Tok.is(tok::kw_throw))
+ return ParseThrowExpression();
+
ExprResult LHS = ParseCastExpression(false);
if (LHS.isInvalid) return LHS;
diff --git a/Parse/ParseExprCXX.cpp b/Parse/ParseExprCXX.cpp
index adf4f8d..6b42fb5 100644
--- a/Parse/ParseExprCXX.cpp
+++ b/Parse/ParseExprCXX.cpp
@@ -76,3 +76,24 @@
tok::TokenKind Kind = Tok.getKind();
return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind);
}
+
+/// ParseThrowExpression - This handles the C++ throw expression.
+///
+/// throw-expression: [C++ 15]
+/// 'throw' assignment-expression[opt]
+Parser::ExprResult Parser::ParseThrowExpression() {
+ assert(Tok.is(tok::kw_throw) && "Not throw!");
+
+ ExprResult Expr;
+
+ SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token.
+ // FIXME: Anything that isn't an assignment-expression should bail out now.
+ if (Tok.is(tok::semi) || Tok.is(tok::r_paren) || Tok.is(tok::colon) ||
+ Tok.is(tok::comma))
+ return Actions.ActOnCXXThrow(ThrowLoc);
+
+ Expr = ParseAssignmentExpression();
+ if (!Expr.isInvalid)
+ Expr = Actions.ActOnCXXThrow(ThrowLoc, Expr.Val);
+ return Expr;
+}