[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:
parent
8a431db004
commit
e737f67fcf
@ -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));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -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"));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user