forked from OSchip/llvm-project
[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:
parent
5450db5f54
commit
749fb33e82
|
@ -930,6 +930,7 @@ struct AdditionalKeywords {
|
|||
kw___has_include_next = &IdentTable.get("__has_include_next");
|
||||
|
||||
kw_mark = &IdentTable.get("mark");
|
||||
kw_region = &IdentTable.get("region");
|
||||
|
||||
kw_extend = &IdentTable.get("extend");
|
||||
kw_option = &IdentTable.get("option");
|
||||
|
@ -1053,6 +1054,7 @@ struct AdditionalKeywords {
|
|||
|
||||
// Pragma keywords.
|
||||
IdentifierInfo *kw_mark;
|
||||
IdentifierInfo *kw_region;
|
||||
|
||||
// Proto keywords.
|
||||
IdentifierInfo *kw_extend;
|
||||
|
|
|
@ -1251,9 +1251,9 @@ private:
|
|||
void parsePragma() {
|
||||
next(); // Consume "pragma".
|
||||
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);
|
||||
next(); // Consume "mark".
|
||||
next();
|
||||
next(); // Consume first token (so we fix leading whitespace).
|
||||
while (CurrentToken) {
|
||||
if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))
|
||||
|
|
|
@ -19597,6 +19597,13 @@ TEST_F(FormatTest, UnderstandPragmaOption) {
|
|||
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) {
|
||||
FormatStyle Style = getLLVMStyleWithColumns(20);
|
||||
|
||||
|
|
Loading…
Reference in New Issue