ymandel updated this revision to Diff 553455. ymandel marked 2 inline comments as done. ymandel added a comment.
address comments Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158771/new/ https://reviews.llvm.org/D158771 Files: clang/lib/Tooling/Transformer/RangeSelector.cpp clang/unittests/Tooling/RangeSelectorTest.cpp Index: clang/unittests/Tooling/RangeSelectorTest.cpp =================================================================== --- clang/unittests/Tooling/RangeSelectorTest.cpp +++ clang/unittests/Tooling/RangeSelectorTest.cpp @@ -486,6 +486,22 @@ EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchC), HasValue("Foo")); } +TEST(RangeSelectorTest, NameOpTemplateSpecializationTypeLoc) { + StringRef Code = R"cc( + namespace ns { + template <typename T> + struct Foo {}; + } // namespace ns + + ns::Foo<int> a; + )cc"; + const char *Loc = "tyloc"; + // Matches declaration of `a` + TestMatch MatchA = matchCode( + Code, varDecl(hasName("a"), hasTypeLoc(typeLoc().bind(Loc)))); + EXPECT_THAT_EXPECTED(select(name(Loc), MatchA), HasValue("Foo")); +} + TEST(RangeSelectorTest, NameOpErrors) { EXPECT_THAT_EXPECTED(selectFromTrivial(name("unbound_id")), Failed<StringError>(withUnboundNodeMessage())); Index: clang/lib/Tooling/Transformer/RangeSelector.cpp =================================================================== --- clang/lib/Tooling/Transformer/RangeSelector.cpp +++ clang/lib/Tooling/Transformer/RangeSelector.cpp @@ -232,9 +232,11 @@ if (const auto *T = Node.get<TypeLoc>()) { TypeLoc Loc = *T; auto ET = Loc.getAs<ElaboratedTypeLoc>(); - if (!ET.isNull()) { + if (!ET.isNull()) Loc = ET.getNamedTypeLoc(); - } + if (auto SpecLoc = Loc.getAs<TemplateSpecializationTypeLoc>(); + !SpecLoc.isNull()) + return CharSourceRange::getTokenRange(SpecLoc.getTemplateNameLoc()); return CharSourceRange::getTokenRange(Loc.getSourceRange()); } return typeError(ID, Node.getNodeKind(),
Index: clang/unittests/Tooling/RangeSelectorTest.cpp =================================================================== --- clang/unittests/Tooling/RangeSelectorTest.cpp +++ clang/unittests/Tooling/RangeSelectorTest.cpp @@ -486,6 +486,22 @@ EXPECT_THAT_EXPECTED(select(name(CtorTy), MatchC), HasValue("Foo")); } +TEST(RangeSelectorTest, NameOpTemplateSpecializationTypeLoc) { + StringRef Code = R"cc( + namespace ns { + template <typename T> + struct Foo {}; + } // namespace ns + + ns::Foo<int> a; + )cc"; + const char *Loc = "tyloc"; + // Matches declaration of `a` + TestMatch MatchA = matchCode( + Code, varDecl(hasName("a"), hasTypeLoc(typeLoc().bind(Loc)))); + EXPECT_THAT_EXPECTED(select(name(Loc), MatchA), HasValue("Foo")); +} + TEST(RangeSelectorTest, NameOpErrors) { EXPECT_THAT_EXPECTED(selectFromTrivial(name("unbound_id")), Failed<StringError>(withUnboundNodeMessage())); Index: clang/lib/Tooling/Transformer/RangeSelector.cpp =================================================================== --- clang/lib/Tooling/Transformer/RangeSelector.cpp +++ clang/lib/Tooling/Transformer/RangeSelector.cpp @@ -232,9 +232,11 @@ if (const auto *T = Node.get<TypeLoc>()) { TypeLoc Loc = *T; auto ET = Loc.getAs<ElaboratedTypeLoc>(); - if (!ET.isNull()) { + if (!ET.isNull()) Loc = ET.getNamedTypeLoc(); - } + if (auto SpecLoc = Loc.getAs<TemplateSpecializationTypeLoc>(); + !SpecLoc.isNull()) + return CharSourceRange::getTokenRange(SpecLoc.getTemplateNameLoc()); return CharSourceRange::getTokenRange(Loc.getSourceRange()); } return typeError(ID, Node.getNodeKind(),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits