thieta created this revision. thieta added reviewers: MyDeveloperDay, curdeius, owenpan. Herald added a project: All. thieta requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
In our code-base we auto-generate pragma regions the regions look like method signatures like: `#pragma region MYREGION(Foo: bar)` The problem here was that the rest of the line after region was not marked as stringliteral as in the case of pragma mark so clang-format tried to change the formatting based on the method signature. Added test and mark it similar as pragma mark. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D136336 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -19968,6 +19968,11 @@ EXPECT_EQ("#pragma region TEST(FOO : BAR)", format("#pragma region TEST(FOO : BAR)", Style)); + + verifyFormat("#pragma region TEST(FOO: NOSPACE)", Style); + EXPECT_EQ("#pragma region TEST(FOO: NOSPACE)", + format("#pragma region TEST(FOO: NOSPACE)", Style)); + } TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1337,11 +1337,11 @@ if (CurrentToken && CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option, Keywords.kw_region)) { - bool IsMark = CurrentToken->is(Keywords.kw_mark); + bool IsMarkOrRegion = CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_region); next(); next(); // Consume first token (so we fix leading whitespace). while (CurrentToken) { - if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator)) + if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) CurrentToken->setType(TT_ImplicitStringLiteral); next(); }
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -19968,6 +19968,11 @@ EXPECT_EQ("#pragma region TEST(FOO : BAR)", format("#pragma region TEST(FOO : BAR)", Style)); + + verifyFormat("#pragma region TEST(FOO: NOSPACE)", Style); + EXPECT_EQ("#pragma region TEST(FOO: NOSPACE)", + format("#pragma region TEST(FOO: NOSPACE)", Style)); + } TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1337,11 +1337,11 @@ if (CurrentToken && CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option, Keywords.kw_region)) { - bool IsMark = CurrentToken->is(Keywords.kw_mark); + bool IsMarkOrRegion = CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_region); next(); next(); // Consume first token (so we fix leading whitespace). while (CurrentToken) { - if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator)) + if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) CurrentToken->setType(TT_ImplicitStringLiteral); next(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits