[AST] Fix location call storage with common last-invocation
authorStephen Kelly <steveire@gmail.com>
Thu, 15 Apr 2021 11:18:34 +0000 (12:18 +0100)
committerStephen Kelly <steveire@gmail.com>
Thu, 15 Apr 2021 22:15:11 +0000 (23:15 +0100)
Differential Revision: https://reviews.llvm.org/D100548

clang/lib/Tooling/NodeIntrospection.cpp
clang/unittests/Introspection/IntrospectionTest.cpp

index 2ee0b1c..0e3ef3c 100644 (file)
@@ -66,13 +66,15 @@ bool RangeLessThan::operator()(
   else if (LHS.first.getEnd() != RHS.first.getEnd())
     return false;
 
-  return LHS.second->name() < RHS.second->name();
+  return LocationCallFormatterCpp::format(*LHS.second) <
+         LocationCallFormatterCpp::format(*RHS.second);
 }
 bool RangeLessThan::operator()(
     std::pair<SourceLocation, SharedLocationCall> const &LHS,
     std::pair<SourceLocation, SharedLocationCall> const &RHS) const {
   if (LHS.first == RHS.first)
-    return LHS.second->name() < RHS.second->name();
+    return LocationCallFormatterCpp::format(*LHS.second) <
+           LocationCallFormatterCpp::format(*RHS.second);
   return LHS.first < RHS.first;
 }
 } // namespace internal
index 880068c..2df401c 100644 (file)
@@ -45,6 +45,31 @@ FormatExpected(const MapType &Accessors) {
 
 #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<LocationCall>(Prefix, "getSourceRange")));
+  EXPECT_EQ(slm.size(), 1u);
+
+  auto callTypeLoc =
+      llvm::makeIntrusiveRefCnt<LocationCall>(Prefix, "getTypeLoc");
+  slm.insert(std::make_pair(
+      SourceLocation(),
+      llvm::makeIntrusiveRefCnt<LocationCall>(callTypeLoc, "getSourceRange")));
+  EXPECT_EQ(slm.size(), 2u);
+}
+
+TEST(Introspection, SourceLocations_CallChainFormatting) {
+  SharedLocationCall Prefix;
+  auto chainedCall = llvm::makeIntrusiveRefCnt<LocationCall>(
+      llvm::makeIntrusiveRefCnt<LocationCall>(Prefix, "getTypeLoc"),
+      "getSourceRange");
+  EXPECT_EQ(LocationCallFormatterCpp::format(*chainedCall),
+            "getTypeLoc().getSourceRange()");
+}
+
 TEST(Introspection, SourceLocations_Stmt) {
   if (!NodeIntrospection::hasIntrospectionSupport())
     return;