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

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 16 13:53:20 PDT 2022


HazardyKnusperkeks added a comment.

Please add tests in TokenAnnotatorTests for `TT_ConditionLParen`.



================
Comment at: clang/lib/Format/FormatToken.h:521
+  /// statement's condition like if or while.
+  bool isConditionLParen(bool IncludeSpecial) const {
+    if (!is(tok::l_paren))
----------------
Please document what this means.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:133
             Left->ParentBracket != tok::less &&
-            (isKeywordWithCondition(*Line.First) ||
-             CurrentToken->getStartOfNonWhitespace() ==
----------------
Any reason why one doesn't need this check anymore?


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:1431-1442
+            TT_AttributeMacro, TT_BracedListLBrace, TT_ClassLBrace,
+            TT_CompoundRequirementLBrace, TT_ConditionLParen, TT_EnumLBrace,
+            TT_FatArrow, TT_ForEachMacro, TT_FunctionLBrace,
+            TT_FunctionLikeOrFreestandingMacro, TT_IfMacro,
+            TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_LambdaArrow,
+            TT_LambdaLBrace, TT_LambdaLSquare, TT_NamespaceMacro,
+            TT_ObjCStringLiteral, TT_OverloadedOperator, TT_RecordLBrace,
----------------
Unrelated Change.


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2426
+    if (FormatTok->Tok.is(tok::l_paren)) {
+      FormatTok->setType(TT_ConditionLParen);
       parseParens();
----------------
Please use `setFixedType`.
Then you don't need to add `TT_ConditionLParen` to the exclude list in the continuation indenter.


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