]> granicus.if.org Git - clang/commitdiff
Simple parsing of exception specifications, with no semantic analysis yet
authorDouglas Gregor <dgregor@apple.com>
Tue, 25 Nov 2008 03:22:00 +0000 (03:22 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 25 Nov 2008 03:22:00 +0000 (03:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60005 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseDeclCXX.cpp
test/Parser/cxx-exception-spec.cpp [new file with mode: 0644]

index e505e4d9cafb42d2a462f165dd3af7542701a216..47b1191818219c4cd476c29cf8d26dc483ce9c35 100644 (file)
@@ -492,6 +492,7 @@ private:
   //===--------------------------------------------------------------------===//
   // C++ 15: C++ Throw Expression
   ExprResult ParseThrowExpression();
+  bool ParseExceptionSpecification();
 
   //===--------------------------------------------------------------------===//
   // C++ 2.13.5: C++ Boolean Literals
index 1b5a0a5e7a3592d7ee73a7b52e6658562f09d628..eaf9f8b0f98a91bced3bf188de2e69b7ad804ce7 100644 (file)
@@ -1653,7 +1653,10 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
     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 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
   // 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.
index 17f5763c1d60b71b7cbbc085865a403d6bf43285..9e380c903694a01e140b60e119fb6bae94dc8792 100644 (file)
@@ -760,3 +760,36 @@ Parser::MemInitResult Parser::ParseMemInitializer(DeclTy *ConstructorDecl) {
                                      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;
+}
diff --git a/test/Parser/cxx-exception-spec.cpp b/test/Parser/cxx-exception-spec.cpp
new file mode 100644 (file)
index 0000000..47e9ffb
--- /dev/null
@@ -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) { }
+};