[PATCH] D121103: [clang] Adjust LookupTest for UsingTypeLocs

2022-03-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd65952b9bd80: [clang] Adjust LookupTest for UsingTypeLocs 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121103/new/

https://reviews.llvm.org/D121103

Files:
  clang/unittests/Tooling/LookupTest.cpp


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), 
Visitor.DeclStack.back()->getDeclContext(),
-FD, ReplacementString);
+nullptr, Loc, Visitor.DeclStack.back()->getDeclContext(), ND,
+ReplacementString);
   };
 
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("x::Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+  EXPECT_EQ("x::Bar", replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(),
+ "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b {\n"
@@ -201,12 +210,13 @@
   "namespace c { Foo f();; }\n"
   "} }\n");
 
-  Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
+  Visitor.OnUsingTypeLoc = [&](UsingTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 // `a::b::Foo` in using shadow decl is not `TypeLoc`.
-if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+auto *TD = Type.getFoundDecl()->getTargetDecl();
+if (TD->getQualifiedNameAsString() == "a::b::Foo") {
+  EXPECT_EQ("Bar", replaceTypeLoc(TD, Type.getBeginLoc(), "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b { class Foo {}; } }\n"
@@ -218,7 +228,8 @@
   // it's not visible at [0].
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 if (Type.getDecl()->getQualifiedNameAsString() == "x::y::Old") {
-  EXPECT_EQ("Foo", replaceRecordTypeLoc(Type, "::x::Foo"));
+  EXPECT_EQ("Foo",
+replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(), 
"::x::Foo"));
 }
   };
   Visitor.runOver(R"(


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), 

[PATCH] D121103: [clang] Adjust LookupTest for UsingTypeLocs

2022-03-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We no longer traverse the underlying RecordTypeLoc directly, but rather
visit the UsingTypeLoc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121103

Files:
  clang/unittests/Tooling/LookupTest.cpp


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), 
Visitor.DeclStack.back()->getDeclContext(),
-FD, ReplacementString);
+nullptr, Loc, Visitor.DeclStack.back()->getDeclContext(), ND,
+ReplacementString);
   };
 
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("x::Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+  EXPECT_EQ("x::Bar", replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(),
+ "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b {\n"
@@ -201,12 +210,13 @@
   "namespace c { Foo f();; }\n"
   "} }\n");
 
-  Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
+  Visitor.OnUsingTypeLoc = [&](UsingTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 // `a::b::Foo` in using shadow decl is not `TypeLoc`.
-if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+auto *TD = Type.getFoundDecl()->getTargetDecl();
+if (TD->getQualifiedNameAsString() == "a::b::Foo") {
+  EXPECT_EQ("Bar", replaceTypeLoc(TD, Type.getBeginLoc(), "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b { class Foo {}; } }\n"
@@ -218,7 +228,8 @@
   // it's not visible at [0].
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 if (Type.getDecl()->getQualifiedNameAsString() == "x::y::Old") {
-  EXPECT_EQ("Foo", replaceRecordTypeLoc(Type, "::x::Foo"));
+  EXPECT_EQ("Foo",
+replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(), 
"::x::Foo"));
 }
   };
   Visitor.runOver(R"(


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(),