[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 6 17:48:34 PST 2022
owenpan added inline comments.
================
Comment at: clang/lib/Format/DefinitionBlockSeparator.cpp:50-64
FormatToken *CurrentToken = Line->First;
+ int BracketLevel = 0;
while (CurrentToken) {
- if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct) ||
- (Style.isJavaScript() && CurrentToken->is(ExtraKeywords.kw_function)))
- return true;
- if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
- return true;
+ if (BracketLevel == 0) {
+ if ((CurrentToken->isOneOf(tok::kw_class, tok::kw_struct,
+ tok::kw_union) ||
+ (Style.isJavaScript() &&
----------------
Please use a `for` loop instead:
```
for (const FormatToken *CurrentToken = Line->First; CurrentToken;
CurrentToken = CurrentToken->Next) {
...;
}
```
================
Comment at: clang/lib/Format/DefinitionBlockSeparator.cpp:121-130
while (CurrentToken) {
- if (CurrentToken->is(tok::kw_enum))
- FoundEnumKeyword = true;
- else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
- return true;
+ if (BracketLevel == 0) {
+ if (CurrentToken->is(tok::kw_enum))
+ FoundEnumKeyword = true;
+ else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
+ return true;
+ }
----------------
Use a `for` loop with the `const FormatToken *CurrentToken` loop variable similar to the above.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119067/new/
https://reviews.llvm.org/D119067
More information about the cfe-commits
mailing list