Simple parsing of exception specifications, with no semantic analysis yet
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60005 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 1b5a0a5..eaf9f8b 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1653,7 +1653,10 @@
DeclSpec DS;
if (getLang().CPlusPlus) {
ParseTypeQualifierListOpt(DS);
- // FIXME: Parse exception-specification[opt].
+
+ // Parse exception-specification[opt].
+ if (Tok.is(tok::kw_throw))
+ ParseExceptionSpecification();
}
// Remember that we parsed a function type, and remember the attributes.
@@ -1783,11 +1786,14 @@
// If we have the closing ')', eat it.
MatchRHSPunctuation(tok::r_paren, LParenLoc);
- // cv-qualifier-seq[opt].
DeclSpec DS;
if (getLang().CPlusPlus) {
+ // Parse cv-qualifier-seq[opt].
ParseTypeQualifierListOpt(DS);
- // FIXME: Parse exception-specification[opt].
+
+ // Parse exception-specification[opt].
+ if (Tok.is(tok::kw_throw))
+ ParseExceptionSpecification();
}
// Remember that we parsed a function type, and remember the attributes.
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index 17f5763..9e380c9 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -760,3 +760,36 @@
LParenLoc, &ArgExprs[0], ArgExprs.size(),
&CommaLocs[0], RParenLoc);
}
+
+/// ParseExceptionSpecification - Parse a C++ exception-specification
+/// (C++ [except.spec]).
+///
+/// exception-specification:
+/// 'throw' '(' type-id-list [opt] ')'
+///
+/// type-id-list:
+/// type-id
+/// type-id-list ',' type-id
+///
+bool Parser::ParseExceptionSpecification() {
+ assert(Tok.is(tok::kw_throw) && "expected throw");
+
+ SourceLocation ThrowLoc = ConsumeToken();
+
+ if (!Tok.is(tok::l_paren)) {
+ return Diag(Tok, diag::err_expected_lparen_after) << "throw";
+ }
+ SourceLocation LParenLoc = ConsumeParen();
+
+ // Parse the sequence of type-ids.
+ while (Tok.isNot(tok::r_paren)) {
+ ParseTypeName();
+ if (Tok.is(tok::comma))
+ ConsumeToken();
+ else
+ break;
+ }
+
+ SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
+ return false;
+}