[PATCH] Replaced bool parameters in SkipUntil function with single bit-based parameter.

Alexey Bataev a.bataev at hotmail.com
Wed Nov 6 23:47:18 PST 2013



================
Comment at: include/clang/Parse/Parser.h:755-762
@@ -746,12 +754,10 @@
   /// returns false.
-  bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
-                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
-    return SkipUntil(llvm::makeArrayRef(T), StopAtSemi, DontConsume,
-                     StopAtCodeCompletion);
+  bool SkipUntil(tok::TokenKind T, unsigned Flags = 0) {
+    return SkipUntil(llvm::makeArrayRef(T), Flags);
   }
-  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
-                 bool DontConsume = false, bool StopAtCodeCompletion = false) {
+  bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2,
+                 unsigned Flags = 0) {
     tok::TokenKind TokArray[] = {T1, T2};
-    return SkipUntil(TokArray, StopAtSemi, DontConsume,StopAtCodeCompletion);
+    return SkipUntil(TokArray, Flags);
   }
   bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3,
----------------
Richard Smith wrote:
> This is a somewhat scary overload set.
> 
>   unsigned Tok = thing ? tok::foo : tok::bar;
>   SkipUntil(tok::baz, Tok);
> 
> ... will call the first overload. Oops.
> 
> Please add
> 
>   LLVM_CONSTEXPR SkipUntilFlags operator|(SkipUntilFlags L, SkipUntilFlags R) {
>     return SkipUntilFlags(int(L) | int(R));
>   }
> 
> and make these functions take `SkipUntilFlags` not `unsigned`.
Ok

================
Comment at: lib/Parse/ParseCXXInlineMethods.cpp:76
@@ -75,3 +75,3 @@
     if (!FnD) {
-      SkipUntil(tok::semi);
+      SkipUntil(tok::semi, StopAtSemi);
       return 0;
----------------
Richard Smith wrote:
> Remove the `StopAtSemi` here, and on all other calls that are passed `tok::semi`: it's meaningless in that case.
Ok

================
Comment at: lib/Parse/ParseDecl.cpp:1628
@@ -1622,3 +1627,3 @@
         Diag(Tok, diag::err_function_definition_not_allowed);
-        SkipUntil(tok::r_brace, true, true);
+        SkipUntil(tok::r_brace, StopAtSemi | DontConsume);
       }
----------------
Richard Smith wrote:
> Hm, this looks bogus (both before and after this change). This should instead be:
> 
>   ConsumeBrace();
>   SkipUntil(tok::r_brace);
No, your solution does not work. It stops right after the first found right brace, but the original code continues to scan tokens until the next right brace is found and does not consume it.

================
Comment at: lib/Parse/ParseDecl.cpp:2307
@@ -2301,3 +2306,3 @@
   if (ArgExpr.isInvalid()) {
-    SkipUntil(tok::r_paren);
+    SkipUntil(tok::r_paren, StopAtSemi);
     return;
----------------
Richard Smith wrote:
> Should be `T.skipToEnd();`
Ok


http://llvm-reviews.chandlerc.com/D2108



More information about the cfe-commits mailing list