[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 <fmayer@google.com>
This commit is contained in:
Yu Hao 2025-11-24 13:46:29 -08:00 committed by GitHub
parent 8a431db004
commit e737f67fcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -139,7 +139,8 @@ 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(/*IncludeQualifier=*/true));
};
}

View File

@ -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"));