[cfe-commits] r38872 - /cfe/cfe/trunk/Parse/Parser.cpp

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


Author: sabre
Date: Wed Jul 11 11:25:22 2007
New Revision: 38872

URL: http://llvm.org/viewvc/llvm-project?rev=38872&view=rev
Log:
Significant improvements to error recovery

Modified:
    cfe/cfe/trunk/Parse/Parser.cpp

Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=38872&r1=38871&r2=38872&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:25:22 2007
@@ -73,6 +73,9 @@
 /// If SkipUntil finds the specified token, it returns true, otherwise it
 /// returns false.  
 bool Parser::SkipUntil(tok::TokenKind T, bool StopAtSemi, bool DontConsume) {
+  // We always want this function to skip at least one token if the first token
+  // isn't T and if not at EOF.
+  bool isFirstTokenSkipped = true;
   while (1) {
     // If we found the token, stop and return true.
     if (Tok.getKind() == T) {
@@ -84,7 +87,7 @@
         ConsumeBracket();
       } else if (isTokenBrace()) {
         ConsumeBrace();
-      } else if (T == tok::string_literal) {
+      } else if (isTokenStringLiteral()) {
         ConsumeStringToken();
       } else {
         ConsumeToken();
@@ -100,17 +103,17 @@
     case tok::l_paren:
       // Recursively skip properly-nested parens.
       ConsumeParen();
-      SkipUntil(tok::r_paren);
+      SkipUntil(tok::r_paren, false);
       break;
     case tok::l_square:
       // Recursively skip properly-nested square brackets.
       ConsumeBracket();
-      SkipUntil(tok::r_square);
+      SkipUntil(tok::r_square, false);
       break;
     case tok::l_brace:
       // Recursively skip properly-nested braces.
       ConsumeBrace();
-      SkipUntil(tok::r_brace);
+      SkipUntil(tok::r_brace, false);
       break;
       
     // Okay, we found a ']' or '}' or ')', which we think should be balanced.
@@ -119,15 +122,18 @@
     // higher level, we will assume that this matches the unbalanced token
     // and return it.  Otherwise, this is a spurious RHS token, which we skip.
     case tok::r_paren:
-      if (ParenCount) return false;  // Matches something.
+      if (ParenCount && !isFirstTokenSkipped)
+        return false;  // Matches something.
       ConsumeParen();
       break;
     case tok::r_square:
-      if (BracketCount) return false;  // Matches something.
+      if (BracketCount && !isFirstTokenSkipped)
+        return false;  // Matches something.
       ConsumeBracket();
       break;
     case tok::r_brace:
-      if (BraceCount) return false;  // Matches something.
+      if (BraceCount && !isFirstTokenSkipped)
+        return false;  // Matches something.
       ConsumeBrace();
       break;
       
@@ -143,6 +149,7 @@
       ConsumeToken();
       break;
     }
+    isFirstTokenSkipped = false;
   }  
 }
 





More information about the cfe-commits mailing list