-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][transformer] Fix node range-selector to include type name qualifiers of type locs.
#167619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…nstead of an invalid range. Previously, when the text in selected range was different from the decl's name, `name` returned an invalid range, which could cause crashes if `name` was nested in other range selectors that assumed always valid ranges. With this change, `name` returns an `Error` if it can't get the range.
…ualifiers of type locs. Previously, e.g. for TypeLoc "MyNamespace::MyClass", `node()` selects only "MyClass" without the qualifier. With this change, it now selects "MyNamespace::MyClass".
|
@llvm/pr-subscribers-clang Author: Yu Hao (yuhaouy) ChangesPreviously, e.g. for TypeLoc "MyNamespace::MyClass", Full diff: https://github.com/llvm/llvm-project/pull/167619.diff 2 Files Affected:
diff --git a/clang/lib/Tooling/Transformer/RangeSelector.cpp b/clang/lib/Tooling/Transformer/RangeSelector.cpp
index b4bdec1fcdd69..d669be2ca0409 100644
--- a/clang/lib/Tooling/Transformer/RangeSelector.cpp
+++ b/clang/lib/Tooling/Transformer/RangeSelector.cpp
@@ -139,7 +139,7 @@ RangeSelector transformer::node(std::string ID) {
(Node->get<Stmt>() != nullptr && Node->get<Expr>() == nullptr))
? tooling::getExtendedRange(*Node, tok::TokenKind::semi,
*Result.Context)
- : CharSourceRange::getTokenRange(Node->getSourceRange());
+ : CharSourceRange::getTokenRange(Node->getSourceRange(true));
};
}
diff --git a/clang/unittests/Tooling/RangeSelectorTest.cpp b/clang/unittests/Tooling/RangeSelectorTest.cpp
index a1fcbb023832f..d441da165b09b 100644
--- a/clang/unittests/Tooling/RangeSelectorTest.cpp
+++ b/clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -339,6 +339,13 @@ TEST(RangeSelectorTest, NodeOpExpression) {
EXPECT_THAT_EXPECTED(select(node("id"), Match), HasValue("3"));
}
+TEST(RangeSelectorTest, NodeOpTypeLoc) {
+ StringRef Code = "namespace ns {struct Foo{};} ns::Foo a;";
+ TestMatch Match =
+ matchCode(Code, varDecl(hasTypeLoc(typeLoc().bind("typeloc"))));
+ EXPECT_THAT_EXPECTED(select(node("typeloc"), Match), HasValue("ns::Foo"));
+}
+
TEST(RangeSelectorTest, StatementOp) {
StringRef Code = "int f() { return 3; }";
TestMatch Match = matchCode(Code, expr().bind("id"));
|
ymand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, but see my request for clarification.
🐧 Linux x64 Test Results
|
Previously, e.g. for TypeLoc "MyNamespace::MyClass",
node()selects only "MyClass" without the qualifier. With this change, it now selects "MyNamespace::MyClass".