[PATCH] D136336: [clang-format] Mark pragma region lines as StringLiterals
Tobias Hieta via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 20 04:34:29 PDT 2022
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();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136336.469163.patch
Type: text/x-patch
Size: 1431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221020/6c4820c2/attachment.bin>
More information about the llvm-commits
mailing list