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



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D31334: [clang-forma... Daniel Jasper via Phabricator via cfe-commits

Reply via email to