[clang-format] Don't break lines after pragma region

We have autogenerated pragma regions in our code
which where awkwardly broken up like this:

```
#pragma region foo(bar : hello)
```
becomes

```
#pragma region foo(bar \
                   : hello)
```

This fixes the problem by adding region as a keyword
and handling it the same way as pragma mark

Reviewed By: curdeius

Differential Revision: https://reviews.llvm.org/D125961
This commit is contained in:
Tobias Hieta 2022-05-20 16:11:02 +02:00 committed by Tobias Hieta
parent 5450db5f54
commit 749fb33e82
3 changed files with 11 additions and 2 deletions

View File

@ -930,6 +930,7 @@ struct AdditionalKeywords {
kw___has_include_next = &IdentTable.get("__has_include_next"); kw___has_include_next = &IdentTable.get("__has_include_next");
kw_mark = &IdentTable.get("mark"); kw_mark = &IdentTable.get("mark");
kw_region = &IdentTable.get("region");
kw_extend = &IdentTable.get("extend"); kw_extend = &IdentTable.get("extend");
kw_option = &IdentTable.get("option"); kw_option = &IdentTable.get("option");
@ -1053,6 +1054,7 @@ struct AdditionalKeywords {
// Pragma keywords. // Pragma keywords.
IdentifierInfo *kw_mark; IdentifierInfo *kw_mark;
IdentifierInfo *kw_region;
// Proto keywords. // Proto keywords.
IdentifierInfo *kw_extend; IdentifierInfo *kw_extend;

View File

@ -1251,9 +1251,9 @@ private:
void parsePragma() { void parsePragma() {
next(); // Consume "pragma". next(); // Consume "pragma".
if (CurrentToken && if (CurrentToken &&
CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option)) { CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option, Keywords.kw_region)) {
bool IsMark = CurrentToken->is(Keywords.kw_mark); bool IsMark = CurrentToken->is(Keywords.kw_mark);
next(); // Consume "mark". next();
next(); // Consume first token (so we fix leading whitespace). next(); // Consume first token (so we fix leading whitespace).
while (CurrentToken) { while (CurrentToken) {
if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator)) if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))

View File

@ -19597,6 +19597,13 @@ TEST_F(FormatTest, UnderstandPragmaOption) {
EXPECT_EQ("#pragma option -C -A", format("#pragma option -C -A")); EXPECT_EQ("#pragma option -C -A", format("#pragma option -C -A"));
} }
TEST_F(FormatTest, UnderstandPragmaRegion) {
auto Style = getLLVMStyleWithColumns(0);
verifyFormat("#pragma region TEST(FOO : BAR)", Style);
EXPECT_EQ("#pragma region TEST(FOO : BAR)", format("#pragma region TEST(FOO : BAR)", Style));
}
TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) {
FormatStyle Style = getLLVMStyleWithColumns(20); FormatStyle Style = getLLVMStyleWithColumns(20);