[PATCH] D136336: [clang-format] Mark pragma region lines as StringLiterals
Tobias Hieta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 24 02:17:05 PDT 2022
thieta updated this revision to Diff 470092.
thieta added a comment.
Added TokenAnnotatorTest and removed reduntant FormatTests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136336/new/
https://reviews.llvm.org/D136336
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Basic/TokenKinds.h"
#include "clang/Format/Format.h"
#include "FormatTestUtils.h"
@@ -649,6 +650,23 @@
EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace);
}
+TEST_F(TokenAnnotatorTest, UnderstandsPragmaRegion) {
+ // Everything after #pragma region should be ImplicitStringLiteral
+ auto Tokens = annotate("#pragma region Foo(Bar: Hello)");
+ ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+ EXPECT_TOKEN(Tokens[5], tok::identifier, TT_ImplicitStringLiteral);
+ EXPECT_TOKEN(Tokens[6], tok::colon, TT_ImplicitStringLiteral);
+ EXPECT_TOKEN(Tokens[7], tok::identifier, TT_ImplicitStringLiteral);
+
+ // Make sure it's annotated correctly inside a function as well
+ Tokens = annotate("void test(){\n#pragma region Foo(Bar: Hello)\n}");
+ ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+ EXPECT_TOKEN(Tokens[10], tok::identifier, TT_ImplicitStringLiteral);
+ EXPECT_TOKEN(Tokens[11], tok::colon, TT_ImplicitStringLiteral);
+ EXPECT_TOKEN(Tokens[12], tok::identifier, TT_ImplicitStringLiteral);
+
+}
+
TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
const char *BaseCode = nullptr;
const char *ConstrainedCode = nullptr;
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19965,9 +19965,7 @@
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));
+ verifyFormat("#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.470092.patch
Type: text/x-patch
Size: 2972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221024/a64e6121/attachment.bin>
More information about the cfe-commits
mailing list