[PATCH] D31334: [clang-format] Add options for indenting preprocessor directives

Daniel Jasper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 27 22:47:32 PDT 2017


djasper added a comment.

Thank you for working on this. Unfortunately, this is done at the wrong level:

- You are using a separate pass, which means that as soon as the preprocessor directives exceed the column limit, they won't be wrapped correctly.
- You aren't using Clang's Lexer to separate PP directives into tokens, which might work in the short term, but seems really fragile and a maintenance headache.

The approach to do this properly would be to:

- Extend UnwrappedLineParser to properly report the level of preprocessor directives. My guess is that it might suffice to initialize Parser.Line->Level with PPBranchLevel in the constructor of ScopedLineState.
- Once the level is reported correctly, UnwrappedLineFormatter's formatFirstToken function can be changed to add the spaces required for that level either before or after the "#" for preprocessor directives.

Happy to help more if you are up for taking this on.


https://reviews.llvm.org/D31334





More information about the cfe-commits mailing list