diff --git a/clang/lib/Tooling/NodeIntrospection.cpp b/clang/lib/Tooling/NodeIntrospection.cpp --- a/clang/lib/Tooling/NodeIntrospection.cpp +++ b/clang/lib/Tooling/NodeIntrospection.cpp @@ -30,7 +30,7 @@ (VecCall->name() + "()" + (VecCall->returnsPointer() ? "->" : ".")) .str(); } - result += (vec.back()->name() + "()").str(); + result += (vec.front()->name() + "()").str(); return result; } @@ -51,13 +51,15 @@ else if (LHS.first.getEnd() != RHS.first.getEnd()) return false; - return LHS.second->name() < RHS.second->name(); + return LocationCallFormatterCpp::format(LHS.second.get()) < + LocationCallFormatterCpp::format(RHS.second.get()); } bool RangeLessThan::operator()( std::pair const &LHS, std::pair const &RHS) const { if (LHS.first == RHS.first) - return LHS.second->name() < RHS.second->name(); + return LocationCallFormatterCpp::format(LHS.second.get()) < + LocationCallFormatterCpp::format(RHS.second.get()); return LHS.first < RHS.first; } } // namespace internal diff --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp --- a/clang/unittests/Introspection/IntrospectionTest.cpp +++ b/clang/unittests/Introspection/IntrospectionTest.cpp @@ -45,6 +45,31 @@ #define STRING_LOCATION_PAIR(INSTANCE, LOC) Pair(#LOC, INSTANCE->LOC) +TEST(Introspection, SourceLocations_CallContainer) { + SourceLocationMap slm; + SharedLocationCall Prefix; + slm.insert(std::make_pair( + SourceLocation(), + llvm::makeIntrusiveRefCnt(Prefix, "getSourceRange"))); + EXPECT_EQ(slm.size(), 1u); + + auto callTypeLoc = + llvm::makeIntrusiveRefCnt(Prefix, "getTypeLoc"); + slm.insert(std::make_pair( + SourceLocation(), + llvm::makeIntrusiveRefCnt(callTypeLoc, "getSourceRange"))); + EXPECT_EQ(slm.size(), 2u); +} + +TEST(Introspection, SourceLocations_CallChainFormatting) { + SharedLocationCall Prefix; + auto chainedCall = llvm::makeIntrusiveRefCnt( + llvm::makeIntrusiveRefCnt(Prefix, "getTypeLoc"), + "getSourceRange"); + EXPECT_EQ(LocationCallFormatterCpp::format(chainedCall.get()), + "getTypeLoc().getSourceRange()"); +} + TEST(Introspection, SourceLocations_Stmt) { auto AST = buildASTFromCode("void foo() {} void bar() { foo(); }", "foo.cpp", std::make_shared());