[PATCH] D150452: [clang-format] Recognize nested blocks

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 12 13:04:19 PDT 2023


HazardyKnusperkeks added a comment.

On this change I like the token annotator tests, and reusing the same stack instead of adding a second one which always has the same size.
But the code changes in D150403 <https://reviews.llvm.org/D150403> seem to be better, at least I couldn't think directly on something which may not work.



================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:492
+  // A rough guess at whether a block is a lambda expression.
+  bool ProbablyLambda = false;
   // Keep a stack of positions of lbrace tokens. We will
----------------
Shouldn't it be called `NextBraceIsProbablyLambda` (or similar)?


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:659
+    case tok::l_square:
+      ProbablyLambda = true;
       break;
----------------
How does this work on
```
{
int foo[]={2,5};
int bar[]{2};
}
```
or
```
{
SomeClass foo[]={{arg1, whatever}, {arg2, dontcare}};
SomeClass foo[]{{arg1, whatever}, {arg2, dontcare}};
}
```
?


================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:43
   EXPECT_EQ((FormatTok)->getPrecedence(), Prec) << *(FormatTok)
+#define EXPECT_BRACE_KIND(FormatTok, Kind)                                     \
+  EXPECT_EQ(FormatTok->getBlockKind(), Kind)
----------------
Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150452



More information about the cfe-commits mailing list