[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 8 21:44:03 PST 2022


owenpan added a comment.

You can still simply the changes to UnwrappedLineParser.cpp a lot. In fact, instead of adjusting `PPLevel` at various places, you only need to set it once when `InMacroBody` is set.



================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:92-94
+  if (Line.Level >= IndentForLevel.size())
+    IndentForLevel.resize(Line.Level + 1, UnknownIndent ? -1 : Indent);
+}
----------------
Please run git-clang-format.


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:112
       : Line(Line), TokenSource(TokenSource), ResetToken(ResetToken),
-        PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource),
-        Token(nullptr), PreviousToken(nullptr) {
+        PreviousLineLevel(Line.Level), PreviousLinePPLevel(Line.PPLevel),
+        PreviousTokenSource(TokenSource), Token(nullptr),
----------------
Do you need to add `PreviousLinePPLevel` here? If yes, can you add test cases for it? Otherwise, you don't need to make any changes to `ScopedMacroState`.


================
Comment at: clang/lib/Format/UnwrappedLineParser.h:66
+  /// #endif                PPLevel still at : 0
+  int PPLevel;
+
----------------
You need to initialize `PPLevel` in the constructor. FWIW I'd use `unsigned` to be consistent with `Level` above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181



More information about the cfe-commits mailing list