[PATCH] D144296: [clang-format] Rewrite how indent is reduced for compacted namespaces

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 19 18:45:17 PST 2023


owenpan added a comment.

In D144296#4136133 <https://reviews.llvm.org/D144296#4136133>, @rymiel wrote:

> Note: this patch also makes `LevelIndentTracker::skipLine` obsolete. I suppose I could clean that up in a following patch

I'd delete it in this patch.



================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:369
     if (Style.CompactNamespaces) {
-      if (auto nsToken = TheLine->First->getNamespaceToken()) {
-        int i = 0;
-        unsigned closingLine = TheLine->MatchingClosingBlockLineIndex - 1;
-        for (; I + 1 + i != E &&
-               nsToken->TokenText == getNamespaceTokenText(I[i + 1]) &&
-               closingLine == I[i + 1]->MatchingClosingBlockLineIndex &&
-               I[i + 1]->Last->TotalLength < Limit;
-             i++, --closingLine) {
-          // No extra indent for compacted namespaces.
-          IndentTracker.skipLine(*I[i + 1]);
+      if (auto *nsToken = TheLine->First->getNamespaceToken()) {
+        int j = 1;
----------------



================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:371-373
+        unsigned closingLineIndex = TheLine->MatchingClosingBlockLineIndex - 1;
 
+        for (; I + j != E &&
----------------



================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:377
+               I[j]->Last->TotalLength < Limit;
+             j++, --closingLineIndex) {
+          Limit -= I[j]->Last->TotalLength;
----------------



================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:381
+          // Reduce indent level for bodies of namespaces which were compacted,
+          // but only if their content was indented in the first place
+          auto *closingLine = AnnotatedLines.begin() + closingLineIndex + 1;
----------------



================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:383
+          auto *closingLine = AnnotatedLines.begin() + closingLineIndex + 1;
+          auto dedentBy = I[j]->Level - TheLine->Level;
+          for (auto *compactedLine = I + j; compactedLine <= closingLine;
----------------
`outdentBy`?


================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:385
+          for (auto *compactedLine = I + j; compactedLine <= closingLine;
+               compactedLine++) {
+            if (!(*compactedLine)->InPPDirective)
----------------



================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:387
+            if (!(*compactedLine)->InPPDirective)
+              (*compactedLine)->Level-= dedentBy;
+          }
----------------
Did git-clang-format miss this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144296



More information about the cfe-commits mailing list