[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
Sat Nov 12 23:23:07 PST 2022


owenpan added a comment.

In D137181#3918715 <https://reviews.llvm.org/D137181#3918715>, @goldstein.w.n wrote:

> In D137181#3918673 <https://reviews.llvm.org/D137181#3918673>, @owenpan wrote:
>
>> Below is how I defined `PPLevel`:
>>
>>   $ git diff UnwrappedLineParser.h
>>   diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h
>>   index b9b106bcc89a..a234f6852e0c 100644
>>   --- a/clang/lib/Format/UnwrappedLineParser.h
>>   +++ b/clang/lib/Format/UnwrappedLineParser.h
>>   @@ -43,6 +43,9 @@ struct UnwrappedLine {
>>    
>>      /// The indent level of the \c UnwrappedLine.
>>      unsigned Level;
>>   +  /// The \c PPBranchLevel (adjusted for header guards) of the macro definition
>>   +  /// this line belongs to.
>>   +  unsigned PPLevel;
>>    
>>      /// Whether this \c UnwrappedLine is part of a preprocessor directive.
>>      bool InPPDirective;
>>   @@ -358,7 +361,7 @@ struct UnwrappedLineNode {
>>    };
>>    
>>    inline UnwrappedLine::UnwrappedLine()
>>   -    : Level(0), InPPDirective(false), InPragmaDirective(false),
>>   +    : Level(0), PPLevel(0), InPPDirective(false), InPragmaDirective(false),
>>          InMacroBody(false), MustBeDeclaration(false),
>>          MatchingOpeningBlockLineIndex(kInvalidIndex) {}
>>    
>>
>> Conceptually, I think it's more accurate to make `PPLevel` to mean the PP branching level of the `#define` line, not the first line of the macro body. IMO it may simplify the changes you made to the formatter.
>
> Hmm? Not sure what you mean.

Does the comments above `unsigned PPLevel;` in the above `git diff` output help? Anyway, you already addressed my comment by decreasing `PPLevel` by 1, so it's ok now.


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