[cfe-commits] r38835 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp include/clang/Basic/DiagnosticKinds.def

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:25:03 PDT 2007


Author: sabre
Date: Wed Jul 11 11:25:02 2007
New Revision: 38835

URL: http://llvm.org/viewvc/llvm-project?rev=38835&view=rev
Log:
Implement some more error recovery

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=38835&r1=38834&r2=38835&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:25:02 2007
@@ -436,6 +436,8 @@
   // NOTE: better to only create a scope if not '()'
   bool isVariadic;
   bool HasPrototype;
+  bool ErrorEmitted = false;
+
   if (Tok.getKind() == tok::r_paren) {
     // int() -> no prototype, no '...'.
     isVariadic   = false;
@@ -459,17 +461,18 @@
       // Eat the comma.
       ConsumeToken();
       
-      // FIXME: if not identifier, consume until ')' then break.
-      assert(Tok.getKind() == tok::identifier);
+      if (Tok.getKind() != tok::identifier) {
+        // If not identifier, diagnose the error.
+        Diag(Tok, diag::err_expected_ident);
+        ErrorEmitted = true;
+        break;
+      }
 
       // Eat the id.
       // FIXME: remember it!
       ConsumeToken();
     }
     
-    // FIXME: if not identifier, consume until ')' then break.
-    assert(Tok.getKind() == tok::r_paren);
-
     // K&R 'prototype'.
     isVariadic = false;
     HasPrototype = false;
@@ -519,10 +522,17 @@
   
   // FIXME: pop the scope.  
   
-  // expected ')': skip until we find ')'.
-  if (Tok.getKind() != tok::r_paren)
-    assert(0 && "Recover!");
-  ConsumeParen();
+  
+  // If we have the closing ')', eat it and we're done.
+  if (Tok.getKind() == tok::r_paren) {
+    ConsumeParen();
+  } else {
+    // If an error happened earlier parsing something else in the proto, don't
+    // issue another error.
+    if (!ErrorEmitted)
+      Diag(Tok, diag::err_expected_rparen);
+    SkipUntil(tok::r_paren);
+  }
 }
 
 

Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=38835&r1=38834&r2=38835&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:25:02 2007
@@ -258,6 +258,8 @@
 // Generic errors.
 DIAG(err_parse_error, ERROR,
      "parse error")
+DIAG(err_expected_ident, ERROR,
+     "expected identifier")
 DIAG(err_expected_ident_lparen, ERROR,
      "expected identifier or '('")
 DIAG(err_expected_rparen, ERROR,





More information about the cfe-commits mailing list