[PATCH] D35955: clang-format: Add preprocessor directive indentation
Erik Uhlmann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 15:03:45 PDT 2017
euhlmann added inline comments.
Comment at: lib/Format/ContinuationIndenter.cpp:387
+ // hash. This causes second-level indents onward to have an extra space
+ // after the tabs. We set the state to column 0 to avoid this misalignment.
+ if (Style.UseTab != FormatStyle::UT_Never)
> I don't understand this comment. Could you please give an example?
When tabs are enabled, extra spaces would be added because of the column offset caused by the `#` token.
Let me know if there's a better way to fix that.
Comment at: lib/Format/UnwrappedLineParser.cpp:732
+ // then we count it as a real include guard and subtract one from every
+ // preprocessor indent.
+ unsigned TokenPosition = Tokens->getPosition();
> Why do we need to subtract one from every preprocessor indent?
This only knows for sure when something is an include guard at the end of the file. By that time, everything inside the include guard has already been indented one extra level since we didn't know about the guard yet, so it would look like
# define FILE_H
# other directives
Subtracting one is the action taken when we decide that there's a valid include guard, so it looks like
Comment at: lib/Format/UnwrappedLineParser.cpp:760
+ PPMaybeIncludeGuard = nullptr;
> Why do we reset `PPMaybeIncludeGuard` here?
The idea is if there's any preprocessor lines between the #ifndef and the #define, it doesn't treat it as an include guard. This is the same reason for the other PPMaybeIncludeGuard reset.
Comment at: lib/Format/UnwrappedLineParser.cpp:770
- Line->Level = 1;
> Why do we `++Line->Level` here?
This sets correct indent for multi-line macros, so they are indented one level more than the indent of the #define instead of always at level 1.
More information about the cfe-commits