[cfe-commits] r60005 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp test/Parser/cxx-exception-spec.cpp
Douglas Gregor
doug.gregor at gmail.com
Mon Nov 24 19:22:00 PST 2008
Author: dgregor
Date: Mon Nov 24 21:22:00 2008
New Revision: 60005
URL: http://llvm.org/viewvc/llvm-project?rev=60005&view=rev
Log:
Simple parsing of exception specifications, with no semantic analysis yet
Added:
cfe/trunk/test/Parser/cxx-exception-spec.cpp
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=60005&r1=60004&r2=60005&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Nov 24 21:22:00 2008
@@ -492,6 +492,7 @@
//===--------------------------------------------------------------------===//
// C++ 15: C++ Throw Expression
ExprResult ParseThrowExpression();
+ bool ParseExceptionSpecification();
//===--------------------------------------------------------------------===//
// C++ 2.13.5: C++ Boolean Literals
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=60005&r1=60004&r2=60005&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Nov 24 21:22:00 2008
@@ -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.
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=60005&r1=60004&r2=60005&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Nov 24 21:22:00 2008
@@ -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;
+}
Added: cfe/trunk/test/Parser/cxx-exception-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-exception-spec.cpp?rev=60005&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-exception-spec.cpp (added)
+++ cfe/trunk/test/Parser/cxx-exception-spec.cpp Mon Nov 24 21:22:00 2008
@@ -0,0 +1,15 @@
+// RUN: clang -fsyntax-only %s
+
+struct X { };
+
+struct Y { };
+
+void f() throw() { }
+
+void g(int) throw(X) { }
+
+void h() throw(X, Y) { }
+
+class Class {
+ void foo() throw (X, Y) { }
+};
More information about the cfe-commits
mailing list