[PATCH] D151761: clang-format: Add AlignConsecutiveShortCaseStatements

Galen Elias via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 5 09:24:47 PDT 2023


galenelias updated this revision to Diff 537383.
galenelias edited the summary of this revision.
galenelias added a comment.

I re-wrote the alignment to stop using AlignTokens so that I can now handle all the edge cases that came up.  Specifically:

- Allowing empty case labels (implicit fall through) to not break the alignment, but only if they are sandwiched by short case statements.
- Don't align the colon of a non-short case label that follows short case labels when using 'AlignCaseColons=true'.
- Empty case labels will also now push out the alignment of the statements when using AlignCaseColons=false.

Also, this now avoids having to add the `IgnoreNestedScopes` parameter to `AlignTokens` which didn't feel great.

I refactored `AlignMacroSequence` so I could re-use the core aligning method, since it's the same logic I need, but I removed some of the dead code just to simplify things along the way.  But even with that, this version is quite a bit more code (~100 lines vs. ~30 lines).


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

https://reviews.llvm.org/D151761

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/lib/Format/WhitespaceManager.h
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151761.537383.patch
Type: text/x-patch
Size: 29006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/9b9cd1b0/attachment-0001.bin>


More information about the cfe-commits mailing list