[PATCH] D137909: [Support] Allow complex names for annotation points and ranges via $()
Tom Praschan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 13 07:52:34 PST 2022
tom-anders created this revision.
tom-anders added reviewers: sammccall, ilya-biryukov, gribozavr2, ymandel.
Herald added subscribers: kadircet, hiraditya.
Herald added a project: All.
tom-anders requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is useful when tests encode information in these names. Currently,
this is pretty limited because names consist of only alphanumeric
characters and '_'.
Arguably, writing foo$(name)^bar instead of foo$name^bar might also be a
bit more readable in general.
The new syntax should be fully backwards compatible (if I haven't missed
anything). I tested this against clangd unit tests and everything still passes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137909
Files:
llvm/include/llvm/Testing/Support/Annotations.h
llvm/lib/Testing/Support/Annotations.cpp
llvm/unittests/Support/AnnotationsTest.cpp
Index: llvm/unittests/Support/AnnotationsTest.cpp
===================================================================
--- llvm/unittests/Support/AnnotationsTest.cpp
+++ llvm/unittests/Support/AnnotationsTest.cpp
@@ -109,13 +109,18 @@
// A single named point or range.
EXPECT_EQ(llvm::Annotations("a$foo^b").point("foo"), 1u);
EXPECT_EQ(llvm::Annotations("a$foo[[b]]cdef").range("foo"), range(1, 2));
+ EXPECT_EQ(llvm::Annotations("a$(foo)[[b]]cdef").range("foo"), range(1, 2));
+ EXPECT_EQ(llvm::Annotations("a$(foo->bar)[[b]]cdef").range("foo->bar"),
+ range(1, 2));
// Empty names should also work.
EXPECT_EQ(llvm::Annotations("a$^b").point(""), 1u);
+ EXPECT_EQ(llvm::Annotations("a$()^b").point(""), 1u);
EXPECT_EQ(llvm::Annotations("a$[[b]]cdef").range(""), range(1, 2));
+ EXPECT_EQ(llvm::Annotations("a$()[[b]]cdef").range(""), range(1, 2));
// Multiple named points.
- llvm::Annotations Annotated("a$p1^bcd$p2^123$p1^345");
+ llvm::Annotations Annotated("a$(p1)^bcd$p2^123$p1^345");
EXPECT_THAT(Annotated.points(), IsEmpty());
EXPECT_THAT(Annotated.points("p1"), ElementsAre(1u, 7u));
EXPECT_EQ(Annotated.point("p2"), 4u);
@@ -144,6 +149,7 @@
EXPECT_DEATH(llvm::Annotations("ff[[fdfd"), "unmatched \\[\\[");
EXPECT_DEATH(llvm::Annotations("ff[[fdjsfjd]]xxx]]"), "unmatched \\]\\]");
EXPECT_DEATH(llvm::Annotations("ff$fdsfd"), "unterminated \\$name");
+ EXPECT_DEATH(llvm::Annotations("ff$(hkhhk"), "unterminated \\$name");
#endif
}
} // namespace
Index: llvm/lib/Testing/Support/Annotations.cpp
===================================================================
--- llvm/lib/Testing/Support/Annotations.cpp
+++ llvm/lib/Testing/Support/Annotations.cpp
@@ -53,9 +53,15 @@
continue;
}
if (Text.consume_front("$")) {
- Name =
- Text.take_while([](char C) { return llvm::isAlnum(C) || C == '_'; });
- Text = Text.drop_front(Name->size());
+ if (Text.consume_front("(")) {
+ Name = Text.take_while([](char C) { return C != ')'; });
+ Require(Text.size() > Name->size(), "unterminated $name");
+ Text = Text.drop_front(Name->size() + 1);
+ } else {
+ Name = Text.take_while(
+ [](char C) { return llvm::isAlnum(C) || C == '_'; });
+ Text = Text.drop_front(Name->size());
+ }
continue;
}
Code.push_back(Text.front());
Index: llvm/include/llvm/Testing/Support/Annotations.h
===================================================================
--- llvm/include/llvm/Testing/Support/Annotations.h
+++ llvm/include/llvm/Testing/Support/Annotations.h
@@ -21,10 +21,11 @@
/// Annotations lets you mark points and ranges inside source code, for tests:
///
/// Annotations Example(R"cpp(
-/// int complete() { x.pri^ } // ^ indicates a point
-/// void err() { [["hello" == 42]]; } // [[this is a range]]
-/// $definition^class Foo{}; // points can be named: "definition"
-/// $fail[[static_assert(false, "")]] // ranges can be named too: "fail"
+/// int complete() { x.pri^ } // ^ indicates a point
+/// void err() { [["hello" == 42]]; } // [[this is a range]]
+/// $definition^class Foo{}; // points can be named: "definition"
+/// $(very,complex::name)^class Foo{}; // names inside $() can contain any characters
+/// $fail[[static_assert(false, "")]] // ranges can be named too: "fail"
/// )cpp");
///
/// StringRef Code = Example.code(); // annotations stripped.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137909.475000.patch
Type: text/x-patch
Size: 3558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221113/e884a320/attachment.bin>
More information about the llvm-commits
mailing list