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

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 18 01:48:12 PDT 2022


MyDeveloperDay requested changes to this revision.
MyDeveloperDay added a comment.
This revision now requires changes to proceed.

Sorry I don't believe we've covered the changes with unit tests.



================
Comment at: clang/lib/Format/FormatToken.h:528
+  /// to be handled separately.
+  bool isConditionLParen(bool IncludeSpecial) const {
+    if (!is(tok::l_paren))
----------------
IncludeSpecial  seems confusing at best if not obtuse.


================
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));
----------------
What about MacroIf


================
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;
----------------
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?


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