[PATCH] D121756: [clang-format] Clean up code looking for if statements

sstwcw via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 16:24:54 PDT 2022


sstwcw marked 5 inline comments as done.
sstwcw added inline comments.


================
Comment at: clang/lib/Format/ContinuationIndenter.cpp:749
+  if (Current.isNot(tok::comment) &&
+      Previous.isConditionLParen(/*IncludeSpecial=*/true)) {
     // Treat the condition inside an if as if it was a second function
----------------
owenpan wrote:
> We only checked `for` and `if` before. Now you are also checking `while` and `switch`?
Yes, I am.  Please see the diff and tell me whether `while` and `switch` should be checked here.


================
Comment at: clang/lib/Format/FormatToken.h:538
+                                             tok::kw_for, tok::kw_catch)) ||
+            Prev->isOneOf(tok::kw_if, tok::kw_while, tok::kw_switch,
+                          tok::kw_case, tok::kw_constexpr));
----------------
MyDeveloperDay wrote:
> What about MacroIf
What's that?


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:2988
     return 100;
-  if (Left.is(tok::l_paren) && Left.Previous &&
-      (Left.Previous->is(tok::kw_for) || Left.Previous->isIf()))
+  if (Left.isConditionLParen(/*IncludeSpecial=*/true))
     return 1000;
----------------
MyDeveloperDay wrote:
> There has to be a missed unit test here..this condition before only handled if and for
> 
> Did you run the regression suite as well as the unit tests?
I added a test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121756/new/

https://reviews.llvm.org/D121756



More information about the cfe-commits mailing list