[cfe-commits] r39419 - in /cfe/cfe/trunk: Parse/Parser.cpp include/clang/Parse/Parser.h

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:44:09 PDT 2007


Author: clattner
Date: Wed Jul 11 11:44:09 2007
New Revision: 39419

URL: http://llvm.org/viewvc/llvm-project?rev=39419&view=rev
Log:
Generalize the skipping logic to allow skipping until any one of a set of
tokens is found.

Modified:
    cfe/cfe/trunk/Parse/Parser.cpp
    cfe/cfe/trunk/include/clang/Parse/Parser.h

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

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:44:09 2007
@@ -92,19 +92,22 @@
 /// 
 /// If SkipUntil finds the specified token, it returns true, otherwise it
 /// returns false.  
-bool Parser::SkipUntil(tok::TokenKind T, bool StopAtSemi, bool DontConsume) {
+bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
+                       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) {
-      if (DontConsume) {
-        // Noop, don't consume the token.
-      } else {
-        ConsumeAnyToken();
+    // If we found one of the tokens, stop and return true.
+    for (unsigned i = 0; i != NumToks; ++i) {
+      if (Tok.getKind() == Toks[i]) {
+        if (DontConsume) {
+          // Noop, don't consume the token.
+        } else {
+          ConsumeAnyToken();
+        }
+        return true;
       }
-      return true;
     }
     
     switch (Tok.getKind()) {

Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=39419&r1=39418&r2=39419&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:44:09 2007
@@ -228,8 +228,17 @@
   /// If SkipUntil finds the specified token, it returns true, otherwise it
   /// returns false.  
   bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
-                 bool DontConsume = false);
-    
+                 bool DontConsume = false) {
+    return SkipUntil(&T, 1, StopAtSemi, DontConsume);
+  }
+  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
+                 bool DontConsume = false) {
+    tok::TokenKind TokArray[] = {T1, T2};
+    return SkipUntil(TokArray, 2, StopAtSemi, DontConsume);
+  }
+  bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
+                 bool StopAtSemi = true, bool DontConsume = false);
+   
   //===--------------------------------------------------------------------===//
   // C99 6.9: External Definitions.
   DeclTy *ParseExternalDeclaration();





More information about the cfe-commits mailing list