aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/RefactoringTest.cpp
diff options
context:
space:
mode:
authorSirraide <aeternalmail@gmail.com>2024-11-15 06:17:20 +0100
committerGitHub <noreply@github.com>2024-11-15 06:17:20 +0100
commit4e600751d2f7e8e7b85a71b7128b68444bdde91b (patch)
tree12b33f165946df519496b4594997167d9ab7092e /clang/unittests/Tooling/RefactoringTest.cpp
parentc2a9bba4a30349f5411f3b3f9cbe4a6f379816bc (diff)
downloadllvm-4e600751d2f7e8e7b85a71b7128b68444bdde91b.zip
llvm-4e600751d2f7e8e7b85a71b7128b68444bdde91b.tar.gz
llvm-4e600751d2f7e8e7b85a71b7128b68444bdde91b.tar.bz2
[Clang] [Tests] Refactor most unit tests to use DynamicRecursiveASTVisitor (#115132)
This pr refactors most tests that use RAV to use DRAV instead; this also has the nice effect of testing both the RAV and DRAV implementations at the same time w/o having to duplicate all of our AST visitor tests. Some tests rely on features that DRAV doesn’t support (mainly post-order traversal), so those haven’t been migrated. At the same time, `TestVisitor` is now a DRAV, so I’ve had to introduce a new `CTRPTestVisitor` for any tests that need to use RAV directly.
Diffstat (limited to 'clang/unittests/Tooling/RefactoringTest.cpp')
-rw-r--r--clang/unittests/Tooling/RefactoringTest.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp
index 4f0cccdc..254d95b 100644
--- a/clang/unittests/Tooling/RefactoringTest.cpp
+++ b/clang/unittests/Tooling/RefactoringTest.cpp
@@ -13,7 +13,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclGroup.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
@@ -647,8 +647,7 @@ TEST_F(FlushRewrittenFilesTest, StoresChangesOnDisk) {
}
namespace {
-template <typename T>
-class TestVisitor : public clang::RecursiveASTVisitor<T> {
+class TestVisitor : public DynamicRecursiveASTVisitor {
public:
bool runOver(StringRef Code) {
return runToolOnCode(std::make_unique<TestAction>(this), Code);
@@ -698,9 +697,9 @@ void expectReplacementAt(const Replacement &Replace,
EXPECT_EQ(Length, Replace.getLength());
}
-class ClassDeclXVisitor : public TestVisitor<ClassDeclXVisitor> {
+class ClassDeclXVisitor : public TestVisitor {
public:
- bool VisitCXXRecordDecl(CXXRecordDecl *Record) {
+ bool VisitCXXRecordDecl(CXXRecordDecl *Record) override {
if (Record->getName() == "X") {
Replace = Replacement(*SM, Record, "");
}
@@ -721,9 +720,9 @@ TEST(Replacement, ReplacesAtSpellingLocation) {
expectReplacementAt(ClassDeclX.Replace, "input.cc", 17, 7);
}
-class CallToFVisitor : public TestVisitor<CallToFVisitor> {
+class CallToFVisitor : public TestVisitor {
public:
- bool VisitCallExpr(CallExpr *Call) {
+ bool VisitCallExpr(CallExpr *Call) override {
if (Call->getDirectCallee()->getName() == "F") {
Replace = Replacement(*SM, Call, "");
}
@@ -745,10 +744,9 @@ TEST(Replacement, TemplatedFunctionCall) {
expectReplacementAt(CallToF.Replace, "input.cc", 43, 8);
}
-class NestedNameSpecifierAVisitor
- : public TestVisitor<NestedNameSpecifierAVisitor> {
+class NestedNameSpecifierAVisitor : public TestVisitor {
public:
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLoc) {
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLoc) override {
if (NNSLoc.getNestedNameSpecifier()) {
if (const NamespaceDecl* NS = NNSLoc.getNestedNameSpecifier()->getAsNamespace()) {
if (NS->getName() == "a") {
@@ -756,8 +754,7 @@ public:
}
}
}
- return TestVisitor<NestedNameSpecifierAVisitor>::TraverseNestedNameSpecifierLoc(
- NNSLoc);
+ return TestVisitor::TraverseNestedNameSpecifierLoc(NNSLoc);
}
Replacement Replace;
};