[clang-format] Link the braces of a block in UnwrappedLineParser
authorOwen Pan <owenpiano@gmail.com>
Sat, 3 Dec 2022 15:16:32 +0000 (07:16 -0800)
committerOwen Pan <owenpiano@gmail.com>
Sun, 4 Dec 2022 20:01:26 +0000 (12:01 -0800)
commite33243c950ac40d027ad8facbf7ccf0624604a16
tree421e3474aaced49f538b6255b3a4371575a14fa0
parent4f33339fb4d9420230fbc6b297d8b1e54c41d011
[clang-format] Link the braces of a block in UnwrappedLineParser

This includes TT_MacroBlockBegin and TT_MacroBlockEnd as well.

We can no longer use MatchingParen of FormatToken as an indicator
to mark optional braces. Instead, we directly set Optional of an
l_brace first and reset it later if it turns out that the braces
are not optional.

Also added a test case for deeply nested loops.

Differential Revision: https://reviews.llvm.org/D139257
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/BracesRemoverTest.cpp