Skip to content

Commit e737f67

Browse files
yuhaouyfmayer
andauthored
[clang][transformer] Fix node range-selector to include type name qualifiers of type locs. (#167619)
Previously, e.g. for TypeLoc "MyNamespace::MyClass", `node()` selects only "MyClass" without the qualifier. With this change, it now selects "MyNamespace::MyClass". --------- Co-authored-by: Florian Mayer <[email protected]>
1 parent 8a431db commit e737f67

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Tooling/Transformer/RangeSelector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ RangeSelector transformer::node(std::string ID) {
139139
(Node->get<Stmt>() != nullptr && Node->get<Expr>() == nullptr))
140140
? tooling::getExtendedRange(*Node, tok::TokenKind::semi,
141141
*Result.Context)
142-
: CharSourceRange::getTokenRange(Node->getSourceRange());
142+
: CharSourceRange::getTokenRange(
143+
Node->getSourceRange(/*IncludeQualifier=*/true));
143144
};
144145
}
145146

clang/unittests/Tooling/RangeSelectorTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ TEST(RangeSelectorTest, NodeOpExpression) {
339339
EXPECT_THAT_EXPECTED(select(node("id"), Match), HasValue("3"));
340340
}
341341

342+
TEST(RangeSelectorTest, NodeOpTypeLoc) {
343+
StringRef Code = "namespace ns {struct Foo{};} ns::Foo a;";
344+
TestMatch Match =
345+
matchCode(Code, varDecl(hasTypeLoc(typeLoc().bind("typeloc"))));
346+
EXPECT_THAT_EXPECTED(select(node("typeloc"), Match), HasValue("ns::Foo"));
347+
}
348+
342349
TEST(RangeSelectorTest, StatementOp) {
343350
StringRef Code = "int f() { return 3; }";
344351
TestMatch Match = matchCode(Code, expr().bind("id"));

0 commit comments

Comments
 (0)