This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Match all block braces
AbandonedPublic

Authored by HazardyKnusperkeks on Nov 19 2022, 8:57 AM.

Details

Summary

Now every left and right brace of any block (even the block macros) point to each other through the MatchingParen.

This commit on it self is NFC (as far as I can see), it is a preparation for other change(s).

The brace removing part has been rewritten, because that took advantage of the MatchingParen field.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2022, 8:57 AM
HazardyKnusperkeks requested review of this revision.Nov 19 2022, 8:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2022, 8:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This wouldn't work for deeply nested loops:

$ cat test.cpp
for (;;) {
  for (;;) {
    for (;;) {
      a;
    }
  }
}
$ clang-format -style='{RemoveBracesLLVM: true}' test.cpp
for (;;)
  for (;;)
    for (;;)
      a;

Expected output:

for (;;) {
  for (;;)
    for (;;)
      a;
}

Please see D139257 for a different approach.

Please see D139257 for a different approach.

All my hard work... *sniff*.

Please see D139257 for a different approach.

All my hard work... *sniff*.

I can definitely sympathise as I've abandoned a lot patches, the vast majority of which were never even submitted.

I had spent a lot of time playing with your patch but couldn't decide if it would break removing optional braces. Because I liked your idea of linking block braces early in the parser instead but wanted to avoid changing the signature of parseBlock() in doing so, I came up with a different approach. It was only then that I found the litmus test.