[clang] [clang-tools-extra] [Clang] [NFC] Migrate more AST visitors (PR #160290)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 23 06:41:22 PDT 2025
https://github.com/Sirraide updated https://github.com/llvm/llvm-project/pull/160290
>From a5e88513c234f4345c197394c7e0a00d19440844 Mon Sep 17 00:00:00 2001
From: Sirraide <aeternalmail at gmail.com>
Date: Tue, 23 Sep 2025 13:34:55 +0200
Subject: [PATCH 1/3] [Clang] [NFC] Refactor more AST visitors
---
clang-tools-extra/clang-doc/Mapper.h | 22 ++---
.../bugprone/AssignmentInIfConditionCheck.cpp | 17 ++--
.../EasilySwappableParametersCheck.cpp | 18 ++--
.../modernize/DeprecatedHeadersCheck.cpp | 14 +--
.../clang-tidy/modernize/LoopConvertUtils.cpp | 50 +++++------
.../clang-tidy/modernize/LoopConvertUtils.h | 89 ++++++++-----------
.../clang-tidy/modernize/PassByValueCheck.cpp | 11 +--
.../modernize/UseTrailingReturnTypeCheck.cpp | 19 ++--
.../ConvertMemberFunctionsToStatic.cpp | 8 +-
.../FunctionCognitiveComplexityCheck.cpp | 35 +++++---
.../readability/FunctionSizeCheck.cpp | 26 +++---
.../MakeMemberFunctionConstCheck.cpp | 10 +--
.../readability/SimplifyBooleanExprCheck.cpp | 32 +++----
.../utils/RenamerClangTidyCheck.cpp | 47 +++++-----
clang-tools-extra/clangd/AST.cpp | 49 +++++-----
clang-tools-extra/clangd/AST.h | 2 +-
clang-tools-extra/clangd/DumpAST.cpp | 59 ++++++------
clang-tools-extra/clangd/FindTarget.cpp | 41 +++++----
clang-tools-extra/clangd/InlayHints.cpp | 54 +++++------
.../clangd/SemanticHighlighting.cpp | 85 +++++++++---------
clang-tools-extra/clangd/XRefs.cpp | 26 +++---
.../clangd/refactor/tweaks/AddUsing.cpp | 10 +--
.../refactor/tweaks/ExtractFunction.cpp | 32 ++++---
.../refactor/tweaks/ExtractVariable.cpp | 20 ++---
.../refactor/tweaks/RemoveUsingNamespace.cpp | 6 +-
.../clangd/unittests/ASTTests.cpp | 6 +-
.../clangd/unittests/PrintASTTests.cpp | 6 +-
clang-tools-extra/clangd/unittests/TestTU.cpp | 6 +-
.../unittests/FindHeadersTest.cpp | 14 +--
.../unittests/LocateSymbolTest.cpp | 6 +-
clang-tools-extra/modularize/Modularize.cpp | 72 ++++++++-------
.../unittests/clang-doc/SerializeTest.cpp | 19 ++--
.../OverlappingReplacementsTest.cpp | 8 +-
.../clang/AST/DynamicRecursiveASTVisitor.h | 3 +-
clang/include/clang/AST/RecursiveASTVisitor.h | 2 +
clang/include/clang/InstallAPI/Visitor.h | 20 +++--
clang/lib/AST/ASTImporterLookupTable.cpp | 21 ++---
clang/lib/CodeGen/CGDebugInfo.cpp | 21 +++--
clang/lib/CodeGen/CGHLSLRuntime.cpp | 8 +-
clang/lib/CodeGen/CodeGenModule.cpp | 23 ++---
clang/lib/CodeGen/CodeGenPGO.cpp | 50 +++++------
.../CodeGen/ObjectFilePCHContainerWriter.cpp | 14 +--
clang/lib/Frontend/ASTConsumers.cpp | 29 +++---
.../InterfaceStubFunctionsConsumer.cpp | 8 +-
clang/lib/Index/IndexBody.cpp | 86 +++++++++---------
clang/lib/Index/IndexTypeSourceInfo.cpp | 39 ++++----
.../Checkers/WebKit/ForwardDeclChecker.cpp | 29 +++---
.../WebKit/RetainPtrCtorAdoptChecker.cpp | 33 ++++---
clang/lib/Tooling/ASTDiff/ASTDiff.cpp | 19 ++--
.../Tooling/Refactoring/Rename/USRFinder.cpp | 8 +-
.../Refactoring/Rename/USRFindingAction.cpp | 13 ++-
.../Refactoring/Rename/USRLocFinder.cpp | 23 +++--
.../unittests/AST/RecursiveASTVisitorTest.cpp | 33 ++++---
.../Frontend/NoAlterCodeGenActionTest.cpp | 8 +-
54 files changed, 691 insertions(+), 718 deletions(-)
diff --git a/clang-tools-extra/clang-doc/Mapper.h b/clang-tools-extra/clang-doc/Mapper.h
index 322df6d594b3d..3d2e505515715 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -18,7 +18,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
#include "Representation.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Tooling/Execution.h"
using namespace clang::comments;
@@ -27,22 +27,22 @@ using namespace clang::tooling;
namespace clang {
namespace doc {
-class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>,
+class MapASTVisitor : public ConstDynamicRecursiveASTVisitor,
public ASTConsumer {
public:
explicit MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx)
: CDCtx(CDCtx) {}
void HandleTranslationUnit(ASTContext &Context) override;
- bool VisitNamespaceDecl(const NamespaceDecl *D);
- bool VisitRecordDecl(const RecordDecl *D);
- bool VisitEnumDecl(const EnumDecl *D);
- bool VisitCXXMethodDecl(const CXXMethodDecl *D);
- bool VisitFunctionDecl(const FunctionDecl *D);
- bool VisitTypedefDecl(const TypedefDecl *D);
- bool VisitTypeAliasDecl(const TypeAliasDecl *D);
- bool VisitConceptDecl(const ConceptDecl *D);
- bool VisitVarDecl(const VarDecl *D);
+ bool VisitNamespaceDecl(const NamespaceDecl *D) override;
+ bool VisitRecordDecl(const RecordDecl *D) override;
+ bool VisitEnumDecl(const EnumDecl *D) override;
+ bool VisitCXXMethodDecl(const CXXMethodDecl *D) override;
+ bool VisitFunctionDecl(const FunctionDecl *D) override;
+ bool VisitTypedefDecl(const TypedefDecl *D) override;
+ bool VisitTypeAliasDecl(const TypeAliasDecl *D) override;
+ bool VisitConceptDecl(const ConceptDecl *D) override;
+ bool VisitVarDecl(const VarDecl *D) override;
private:
template <typename T> bool mapDecl(const T *D, bool IsDefinition);
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index 2c8856298e7be..d3b0b7c0f0a61 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -8,7 +8,7 @@
#include "AssignmentInIfConditionCheck.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
@@ -21,13 +21,13 @@ void AssignmentInIfConditionCheck::registerMatchers(MatchFinder *Finder) {
void AssignmentInIfConditionCheck::check(
const ast_matchers::MatchFinder::MatchResult &Result) {
- class Visitor : public RecursiveASTVisitor<Visitor> {
+ class Visitor : public ConstDynamicRecursiveASTVisitor {
AssignmentInIfConditionCheck &Check;
public:
explicit Visitor(AssignmentInIfConditionCheck &Check) : Check(Check) {}
- bool VisitIfStmt(IfStmt *If) {
- class ConditionVisitor : public RecursiveASTVisitor<ConditionVisitor> {
+ bool VisitIfStmt(const IfStmt *If) override {
+ class ConditionVisitor : public ConstDynamicRecursiveASTVisitor {
AssignmentInIfConditionCheck &Check;
public:
@@ -35,23 +35,22 @@ void AssignmentInIfConditionCheck::check(
: Check(Check) {}
// Dont traverse into any lambda expressions.
- bool TraverseLambdaExpr(LambdaExpr *, DataRecursionQueue * = nullptr) {
+ bool TraverseLambdaExpr(const LambdaExpr *) override {
return true;
}
// Dont traverse into any requires expressions.
- bool TraverseRequiresExpr(RequiresExpr *,
- DataRecursionQueue * = nullptr) {
+ bool TraverseRequiresExpr(const RequiresExpr *) override {
return true;
}
- bool VisitBinaryOperator(BinaryOperator *BO) {
+ bool VisitBinaryOperator(const BinaryOperator *BO) override {
if (BO->isAssignmentOp())
Check.report(BO);
return true;
}
- bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *OCE) {
+ bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE) override {
if (OCE->isAssignmentOp())
Check.report(OCE);
return true;
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index d8207b30f1b5e..1a677b512320c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -9,7 +9,7 @@
#include "EasilySwappableParametersCheck.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/SmallSet.h"
@@ -1600,8 +1600,8 @@ static bool lazyMapOfSetsIntersectionExists(const MapTy &Map, const ElemTy &E1,
/// a usage for both in the same strict expression subtree. A strict
/// expression subtree is a tree which only includes Expr nodes, i.e. no
/// Stmts and no Decls.
-class AppearsInSameExpr : public RecursiveASTVisitor<AppearsInSameExpr> {
- using Base = RecursiveASTVisitor<AppearsInSameExpr>;
+class AppearsInSameExpr : public ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
const FunctionDecl *FD;
const Expr *CurrentExprOnlyTreeRoot = nullptr;
@@ -1612,7 +1612,7 @@ class AppearsInSameExpr : public RecursiveASTVisitor<AppearsInSameExpr> {
public:
void setup(const FunctionDecl *FD) {
this->FD = FD;
- TraverseFunctionDecl(const_cast<FunctionDecl *>(FD));
+ TraverseFunctionDecl(FD);
}
bool operator()(const ParmVarDecl *Param1, const ParmVarDecl *Param2) const {
@@ -1620,13 +1620,13 @@ class AppearsInSameExpr : public RecursiveASTVisitor<AppearsInSameExpr> {
Param2);
}
- bool TraverseDecl(Decl *D) {
+ bool TraverseDecl(const Decl *D) override {
CurrentExprOnlyTreeRoot = nullptr;
return Base::TraverseDecl(D);
}
- bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr) {
- if (auto *E = dyn_cast_or_null<Expr>(S)) {
+ bool TraverseStmt(const Stmt *S) override {
+ if (const auto *E = dyn_cast_or_null<Expr>(S)) {
bool RootSetInCurrentStackFrame = false;
if (!CurrentExprOnlyTreeRoot) {
CurrentExprOnlyTreeRoot = E;
@@ -1646,11 +1646,11 @@ class AppearsInSameExpr : public RecursiveASTVisitor<AppearsInSameExpr> {
return Base::TraverseStmt(S);
}
- bool VisitDeclRefExpr(DeclRefExpr *DRE) {
+ bool VisitDeclRefExpr(const DeclRefExpr *DRE) override {
if (!CurrentExprOnlyTreeRoot)
return true;
- if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
+ if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
if (llvm::find(FD->parameters(), PVD))
ParentExprsForParamRefs[PVD].insert(CurrentExprOnlyTreeRoot);
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 9f4c215614287..fa772b8da07d9 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "DeprecatedHeadersCheck.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
@@ -44,19 +44,19 @@ class IncludeModernizePPCallbacks : public PPCallbacks {
bool CheckHeaderFile;
};
-class ExternCRefutationVisitor
- : public RecursiveASTVisitor<ExternCRefutationVisitor> {
+class ExternCRefutationVisitor : public ConstDynamicRecursiveASTVisitor{
std::vector<IncludeMarker> &IncludesToBeProcessed;
const SourceManager &SM;
public:
ExternCRefutationVisitor(std::vector<IncludeMarker> &IncludesToBeProcessed,
SourceManager &SM)
- : IncludesToBeProcessed(IncludesToBeProcessed), SM(SM) {}
- bool shouldWalkTypesOfTypeLocs() const { return false; }
- bool shouldVisitLambdaBody() const { return false; }
+ : IncludesToBeProcessed(IncludesToBeProcessed), SM(SM) {
+ ShouldWalkTypesOfTypeLocs = false;
+ ShouldVisitLambdaBody = false;
+ }
- bool VisitLinkageSpecDecl(LinkageSpecDecl *LinkSpecDecl) const {
+ bool VisitLinkageSpecDecl(const LinkageSpecDecl *LinkSpecDecl) override {
if (LinkSpecDecl->getLanguage() != LinkageSpecLanguageIDs::C ||
!LinkSpecDecl->hasBraces())
return true;
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 286c39be44ce4..8c23c7c6fa0a5 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -34,10 +34,10 @@ namespace clang::tidy::modernize {
/// RecursiveASTVisitor::TraverseStmt() and pop_back() afterwards. The Stmt atop
/// the stack is the parent of the current statement (NULL for the topmost
/// statement).
-bool StmtAncestorASTVisitor::TraverseStmt(Stmt *Statement) {
+bool StmtAncestorASTVisitor::TraverseStmt(const Stmt *Statement) {
StmtAncestors.insert(std::make_pair(Statement, StmtStack.back()));
StmtStack.push_back(Statement);
- RecursiveASTVisitor<StmtAncestorASTVisitor>::TraverseStmt(Statement);
+ ConstDynamicRecursiveASTVisitor::TraverseStmt(Statement);
StmtStack.pop_back();
return true;
}
@@ -47,7 +47,7 @@ bool StmtAncestorASTVisitor::TraverseStmt(Stmt *Statement) {
/// Combined with StmtAncestors, this provides roughly the same information as
/// Scope, as we can map a VarDecl to its DeclStmt, then walk up the parent tree
/// using StmtAncestors.
-bool StmtAncestorASTVisitor::VisitDeclStmt(DeclStmt *Statement) {
+bool StmtAncestorASTVisitor::VisitDeclStmt(const DeclStmt *Statement) {
for (const auto *Decl : Statement->decls()) {
if (const auto *V = dyn_cast<VarDecl>(Decl))
DeclParents.insert(std::make_pair(V, Statement));
@@ -56,27 +56,27 @@ bool StmtAncestorASTVisitor::VisitDeclStmt(DeclStmt *Statement) {
}
/// record the DeclRefExpr as part of the parent expression.
-bool ComponentFinderASTVisitor::VisitDeclRefExpr(DeclRefExpr *E) {
+bool ComponentFinderASTVisitor::VisitDeclRefExpr(const DeclRefExpr *E) {
Components.push_back(E);
return true;
}
/// record the MemberExpr as part of the parent expression.
-bool ComponentFinderASTVisitor::VisitMemberExpr(MemberExpr *Member) {
+bool ComponentFinderASTVisitor::VisitMemberExpr(const MemberExpr *Member) {
Components.push_back(Member);
return true;
}
/// Forward any DeclRefExprs to a check on the referenced variable
/// declaration.
-bool DependencyFinderASTVisitor::VisitDeclRefExpr(DeclRefExpr *DeclRef) {
+bool DependencyFinderASTVisitor::VisitDeclRefExpr(const DeclRefExpr *DeclRef) {
if (auto *V = dyn_cast_or_null<VarDecl>(DeclRef->getDecl()))
return VisitVarDecl(V);
return true;
}
/// Determine if any this variable is declared inside the ContainingStmt.
-bool DependencyFinderASTVisitor::VisitVarDecl(VarDecl *V) {
+bool DependencyFinderASTVisitor::VisitVarDecl(const VarDecl *V) {
const Stmt *Curr = DeclParents->lookup(V);
// First, see if the variable was declared within an inner scope of the loop.
while (Curr != nullptr) {
@@ -100,7 +100,7 @@ bool DependencyFinderASTVisitor::VisitVarDecl(VarDecl *V) {
/// If we already created a variable for TheLoop, check to make sure
/// that the name was not already taken.
-bool DeclFinderASTVisitor::VisitForStmt(ForStmt *TheLoop) {
+bool DeclFinderASTVisitor::VisitForStmt(const ForStmt *TheLoop) {
StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(TheLoop);
if (I != GeneratedDecls->end() && I->second == Name) {
Found = true;
@@ -111,7 +111,7 @@ bool DeclFinderASTVisitor::VisitForStmt(ForStmt *TheLoop) {
/// If any named declaration within the AST subtree has the same name,
/// then consider Name already taken.
-bool DeclFinderASTVisitor::VisitNamedDecl(NamedDecl *D) {
+bool DeclFinderASTVisitor::VisitNamedDecl(const NamedDecl *D) {
const IdentifierInfo *Ident = D->getIdentifier();
if (Ident && Ident->getName() == Name) {
Found = true;
@@ -122,7 +122,7 @@ bool DeclFinderASTVisitor::VisitNamedDecl(NamedDecl *D) {
/// Forward any declaration references to the actual check on the
/// referenced declaration.
-bool DeclFinderASTVisitor::VisitDeclRefExpr(DeclRefExpr *DeclRef) {
+bool DeclFinderASTVisitor::VisitDeclRefExpr(const DeclRefExpr *DeclRef) {
if (auto *D = dyn_cast<NamedDecl>(DeclRef->getDecl()))
return VisitNamedDecl(D);
return true;
@@ -497,7 +497,7 @@ void ForLoopIndexUseVisitor::addUsage(const Usage &U) {
/// int k = *i + 2;
/// }
/// \endcode
-bool ForLoopIndexUseVisitor::TraverseUnaryOperator(UnaryOperator *Uop) {
+bool ForLoopIndexUseVisitor::TraverseUnaryOperator(const UnaryOperator *Uop) {
// If we dereference an iterator that's actually a pointer, count the
// occurrence.
if (isDereferenceOfUop(Uop, IndexVar)) {
@@ -533,7 +533,7 @@ bool ForLoopIndexUseVisitor::TraverseUnaryOperator(UnaryOperator *Uop) {
/// }
/// \endcode
/// will not.
-bool ForLoopIndexUseVisitor::TraverseMemberExpr(MemberExpr *Member) {
+bool ForLoopIndexUseVisitor::TraverseMemberExpr(const MemberExpr *Member) {
const Expr *Base = Member->getBase();
const DeclRefExpr *Obj = getDeclRef(Base);
const Expr *ResultExpr = Member;
@@ -593,8 +593,8 @@ bool ForLoopIndexUseVisitor::TraverseMemberExpr(MemberExpr *Member) {
/// Calls on the iterator object are not permitted, unless done through
/// operator->(). The one exception is allowing vector::at() for pseudoarrays.
bool ForLoopIndexUseVisitor::TraverseCXXMemberCallExpr(
- CXXMemberCallExpr *MemberCall) {
- auto *Member =
+ const CXXMemberCallExpr *MemberCall) {
+ const auto *Member =
dyn_cast<MemberExpr>(MemberCall->getCallee()->IgnoreParenImpCasts());
if (!Member)
return VisitorBase::TraverseCXXMemberCallExpr(MemberCall);
@@ -638,7 +638,7 @@ bool ForLoopIndexUseVisitor::TraverseCXXMemberCallExpr(
/// }
/// \endcode
bool ForLoopIndexUseVisitor::TraverseCXXOperatorCallExpr(
- CXXOperatorCallExpr *OpCall) {
+ const CXXOperatorCallExpr *OpCall) {
switch (OpCall->getOperator()) {
case OO_Star:
if (isDereferenceOfOpCall(OpCall, IndexVar)) {
@@ -683,8 +683,8 @@ bool ForLoopIndexUseVisitor::TraverseCXXOperatorCallExpr(
/// \endcode
/// and further checking needs to be done later to ensure that exactly one array
/// is referenced.
-bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr(ArraySubscriptExpr *E) {
- Expr *Arr = E->getBase();
+bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr(const ArraySubscriptExpr *E) {
+ const Expr *Arr = E->getBase();
if (!isIndexInSubscriptExpr(E->getIdx(), IndexVar))
return VisitorBase::TraverseArraySubscriptExpr(E);
@@ -737,7 +737,7 @@ bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr(ArraySubscriptExpr *E) {
/// for (int i = 0; i < obj.getVector().size(); ++i)
/// obj.foo(10); // using `obj` is considered risky
/// \endcode
-bool ForLoopIndexUseVisitor::VisitDeclRefExpr(DeclRefExpr *E) {
+bool ForLoopIndexUseVisitor::VisitDeclRefExpr(const DeclRefExpr *E) {
const ValueDecl *TheDecl = E->getDecl();
if (areSameVariable(IndexVar, TheDecl) ||
exprReferencesVariable(IndexVar, E) || areSameVariable(EndVar, TheDecl) ||
@@ -770,9 +770,9 @@ bool ForLoopIndexUseVisitor::VisitDeclRefExpr(DeclRefExpr *E) {
/// f(elem);
/// }
/// \endcode
-bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
+bool ForLoopIndexUseVisitor::TraverseLambdaCapture(const LambdaExpr *LE,
const LambdaCapture *C,
- Expr *Init) {
+ const Expr *Init) {
if (C->capturesVariable()) {
ValueDecl *VDecl = C->getCapturedVar();
if (areSameVariable(IndexVar, VDecl)) {
@@ -785,7 +785,7 @@ bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
C->getLocation()));
}
if (VDecl->isInitCapture())
- TraverseStmtImpl(cast<VarDecl>(VDecl)->getInit());
+ traverseStmtImpl(cast<VarDecl>(VDecl)->getInit());
}
return VisitorBase::TraverseLambdaCapture(LE, C, Init);
}
@@ -794,7 +794,7 @@ bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
/// element, note it for reuse as the loop variable.
///
/// See the comments for isAliasDecl.
-bool ForLoopIndexUseVisitor::VisitDeclStmt(DeclStmt *S) {
+bool ForLoopIndexUseVisitor::VisitDeclStmt(const DeclStmt *S) {
if (!AliasDecl && S->isSingleDecl() &&
isAliasDecl(Context, S->getSingleDecl(), IndexVar)) {
AliasDecl = S;
@@ -815,7 +815,7 @@ bool ForLoopIndexUseVisitor::VisitDeclStmt(DeclStmt *S) {
return true;
}
-bool ForLoopIndexUseVisitor::TraverseStmtImpl(Stmt *S) {
+bool ForLoopIndexUseVisitor::traverseStmtImpl(const Stmt *S) {
// All this pointer swapping is a mechanism for tracking immediate parentage
// of Stmts.
const Stmt *OldNextParent = NextStmtParent;
@@ -826,7 +826,7 @@ bool ForLoopIndexUseVisitor::TraverseStmtImpl(Stmt *S) {
return Result;
}
-bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
+bool ForLoopIndexUseVisitor::TraverseStmt(const Stmt *S) {
// If this is an initialization expression for a lambda capture, prune the
// traversal so that we don't end up diagnosing the contained DeclRefExpr as
// inconsistent usage. No need to record the usage here -- this is done in
@@ -838,7 +838,7 @@ bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
return true;
}
}
- return TraverseStmtImpl(S);
+ return traverseStmtImpl(S);
}
std::string VariableNamer::createIndexName() {
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
index 306eca7140d1a..29bbd9cd6f6af 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
@@ -10,7 +10,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_LOOP_CONVERT_UTILS_H
#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/DenseMap.h"
@@ -53,8 +53,7 @@ using ComponentVector = llvm::SmallVector<const clang::Expr *, 16>;
/// Class used build the reverse AST properties needed to detect
/// name conflicts and free variables.
-class StmtAncestorASTVisitor
- : public clang::RecursiveASTVisitor<StmtAncestorASTVisitor> {
+class StmtAncestorASTVisitor : public ConstDynamicRecursiveASTVisitor {
public:
StmtAncestorASTVisitor() { StmtStack.push_back(nullptr); }
@@ -72,45 +71,39 @@ class StmtAncestorASTVisitor
/// Accessor for DeclParents.
const DeclParentMap &getDeclToParentStmtMap() { return DeclParents; }
- friend class clang::RecursiveASTVisitor<StmtAncestorASTVisitor>;
-
private:
StmtParentMap StmtAncestors;
DeclParentMap DeclParents;
llvm::SmallVector<const clang::Stmt *, 16> StmtStack;
- bool TraverseStmt(clang::Stmt *Statement);
- bool VisitDeclStmt(clang::DeclStmt *Statement);
+ bool TraverseStmt(const Stmt *Statement) override;
+ bool VisitDeclStmt(const DeclStmt *Statement) override;
};
/// Class used to find the variables and member expressions on which an
/// arbitrary expression depends.
-class ComponentFinderASTVisitor
- : public clang::RecursiveASTVisitor<ComponentFinderASTVisitor> {
+class ComponentFinderASTVisitor : public ConstDynamicRecursiveASTVisitor {
public:
ComponentFinderASTVisitor() = default;
/// Find the components of an expression and place them in a ComponentVector.
- void findExprComponents(const clang::Expr *SourceExpr) {
- TraverseStmt(const_cast<clang::Expr *>(SourceExpr));
+ void findExprComponents(const Expr *SourceExpr) {
+ TraverseStmt(SourceExpr);
}
/// Accessor for Components.
const ComponentVector &getComponents() { return Components; }
- friend class clang::RecursiveASTVisitor<ComponentFinderASTVisitor>;
-
private:
ComponentVector Components;
- bool VisitDeclRefExpr(clang::DeclRefExpr *E);
- bool VisitMemberExpr(clang::MemberExpr *Member);
+ bool VisitDeclRefExpr(const DeclRefExpr *E) override;
+ bool VisitMemberExpr(const MemberExpr *Member) override;
};
/// Class used to determine if an expression is dependent on a variable declared
/// inside of the loop where it would be used.
-class DependencyFinderASTVisitor
- : public clang::RecursiveASTVisitor<DependencyFinderASTVisitor> {
+class DependencyFinderASTVisitor : public ConstDynamicRecursiveASTVisitor {
public:
DependencyFinderASTVisitor(const StmtParentMap *StmtParents,
const DeclParentMap *DeclParents,
@@ -149,14 +142,12 @@ class DependencyFinderASTVisitor
/// In order to avoid this, this class looks at the container expression
/// `arr[k]` and decides whether or not it contains a sub-expression declared
/// within the loop body.
- bool dependsOnInsideVariable(const clang::Stmt *Body) {
+ bool dependsOnInsideVariable(const Stmt *Body) {
DependsOnInsideVariable = false;
- TraverseStmt(const_cast<clang::Stmt *>(Body));
+ TraverseStmt(Body);
return DependsOnInsideVariable;
}
- friend class clang::RecursiveASTVisitor<DependencyFinderASTVisitor>;
-
private:
const StmtParentMap *StmtParents;
const DeclParentMap *DeclParents;
@@ -164,16 +155,15 @@ class DependencyFinderASTVisitor
const ReplacedVarsMap *ReplacedVars;
bool DependsOnInsideVariable;
- bool VisitVarDecl(clang::VarDecl *V);
- bool VisitDeclRefExpr(clang::DeclRefExpr *D);
+ bool VisitVarDecl(const VarDecl *V) override;
+ bool VisitDeclRefExpr(const DeclRefExpr *D) override;
};
/// Class used to determine if any declarations used in a Stmt would conflict
/// with a particular identifier. This search includes the names that don't
/// actually appear in the AST (i.e. created by a refactoring tool) by including
/// a map from Stmts to generated names associated with those stmts.
-class DeclFinderASTVisitor
- : public clang::RecursiveASTVisitor<DeclFinderASTVisitor> {
+class DeclFinderASTVisitor : public ConstDynamicRecursiveASTVisitor {
public:
DeclFinderASTVisitor(const StringRef &Name,
const StmtGeneratedVarNameMap *GeneratedDecls)
@@ -182,14 +172,12 @@ class DeclFinderASTVisitor
/// Attempts to find any usages of variables name Name in Body, returning
/// true when it is used in Body. This includes the generated loop variables
/// of ForStmts which have already been transformed.
- bool findUsages(const clang::Stmt *Body) {
+ bool findUsages(const Stmt *Body) {
Found = false;
- TraverseStmt(const_cast<clang::Stmt *>(Body));
+ TraverseStmt(Body);
return Found;
}
- friend class clang::RecursiveASTVisitor<DeclFinderASTVisitor>;
-
private:
std::string Name;
/// GeneratedDecls keeps track of ForStmts which have been transformed,
@@ -197,10 +185,10 @@ class DeclFinderASTVisitor
const StmtGeneratedVarNameMap *GeneratedDecls;
bool Found = false;
- bool VisitForStmt(clang::ForStmt *);
- bool VisitNamedDecl(clang::NamedDecl *);
- bool VisitDeclRefExpr(clang::DeclRefExpr *);
- bool VisitTypeLoc(clang::TypeLoc);
+ bool VisitForStmt(const ForStmt *) override;
+ bool VisitNamedDecl(const NamedDecl *) override;
+ bool VisitDeclRefExpr(const DeclRefExpr *) override;
+ bool VisitTypeLoc(TypeLoc) override;
};
/// The information needed to describe a valid convertible usage
@@ -283,8 +271,7 @@ bool areSameVariable(const ValueDecl *First, const ValueDecl *Second);
///
/// Given an index variable, recursively crawls a for loop to discover if the
/// index variable is used in a way consistent with range-based for loop access.
-class ForLoopIndexUseVisitor
- : public RecursiveASTVisitor<ForLoopIndexUseVisitor> {
+class ForLoopIndexUseVisitor : public ConstDynamicRecursiveASTVisitor {
public:
ForLoopIndexUseVisitor(ASTContext *Context, const VarDecl *IndexVar,
const VarDecl *EndVar, const Expr *ContainerExpr,
@@ -338,23 +325,21 @@ class ForLoopIndexUseVisitor
bool aliasFromForInit() const { return AliasFromForInit; }
private:
- /// Typedef used in CRTP functions.
- using VisitorBase = RecursiveASTVisitor<ForLoopIndexUseVisitor>;
- friend class RecursiveASTVisitor<ForLoopIndexUseVisitor>;
-
- /// Overriden methods for RecursiveASTVisitor's traversal.
- bool TraverseArraySubscriptExpr(ArraySubscriptExpr *E);
- bool TraverseCXXMemberCallExpr(CXXMemberCallExpr *MemberCall);
- bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *OpCall);
- bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
- Expr *Init);
- bool TraverseMemberExpr(MemberExpr *Member);
- bool TraverseUnaryOperator(UnaryOperator *Uop);
- bool VisitDeclRefExpr(DeclRefExpr *E);
- bool VisitDeclStmt(DeclStmt *S);
- bool TraverseStmt(Stmt *S);
-
- bool TraverseStmtImpl(Stmt *S);
+ /// Typedef used in derived functions.
+ using VisitorBase = ConstDynamicRecursiveASTVisitor;
+
+ /// Overridden methods for RecursiveASTVisitor's traversal.
+ bool TraverseArraySubscriptExpr(const ArraySubscriptExpr *E) override;
+ bool TraverseCXXMemberCallExpr(const CXXMemberCallExpr *MemberCall) override;
+ bool TraverseCXXOperatorCallExpr(const CXXOperatorCallExpr *OpCall) override;
+ bool TraverseLambdaCapture(const LambdaExpr *LE, const LambdaCapture *C, const Expr *Init) override;
+ bool TraverseMemberExpr(const MemberExpr *Member) override;
+ bool TraverseUnaryOperator(const UnaryOperator *Uop) override;
+ bool VisitDeclRefExpr(const DeclRefExpr *E) override;
+ bool VisitDeclStmt(const DeclStmt *S) override;
+ bool TraverseStmt(const Stmt *S) override;
+
+ bool traverseStmtImpl(const Stmt *S);
/// Add an expression to the list of expressions on which the container
/// expression depends.
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index d5ccbb73735ec..f9b6b6a3b4f89 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -8,7 +8,7 @@
#include "PassByValueCheck.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Frontend/CompilerInstance.h"
@@ -93,10 +93,7 @@ static bool paramReferredExactlyOnce(const CXXConstructorDecl *Ctor,
/// \c ParmVarDecl is used exactly one time.
///
/// \see ExactlyOneUsageVisitor::hasExactlyOneUsageIn()
- class ExactlyOneUsageVisitor
- : public RecursiveASTVisitor<ExactlyOneUsageVisitor> {
- friend class RecursiveASTVisitor<ExactlyOneUsageVisitor>;
-
+ class ExactlyOneUsageVisitor : public ConstDynamicRecursiveASTVisitor {
public:
ExactlyOneUsageVisitor(const ParmVarDecl *ParamDecl)
: ParamDecl(ParamDecl) {}
@@ -106,7 +103,7 @@ static bool paramReferredExactlyOnce(const CXXConstructorDecl *Ctor,
/// given constructor.
bool hasExactlyOneUsageIn(const CXXConstructorDecl *Ctor) {
Count = 0U;
- TraverseDecl(const_cast<CXXConstructorDecl *>(Ctor));
+ TraverseDecl(Ctor);
return Count == 1U;
}
@@ -114,7 +111,7 @@ static bool paramReferredExactlyOnce(const CXXConstructorDecl *Ctor,
/// Counts the number of references to a variable.
///
/// Stops the AST traversal if more than one usage is found.
- bool VisitDeclRefExpr(DeclRefExpr *D) {
+ bool VisitDeclRefExpr(const DeclRefExpr *D) override {
if (const ParmVarDecl *To = dyn_cast<ParmVarDecl>(D->getDecl())) {
if (To == ParamDecl) {
++Count;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 3e27d8fa1fe42..9f9de5ab0131d 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -8,7 +8,7 @@
#include "UseTrailingReturnTypeCheck.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/FixIt.h"
@@ -45,14 +45,13 @@ using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
namespace {
-struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {
-public:
- UnqualNameVisitor(const FunctionDecl &F) : F(F) {}
+struct UnqualNameVisitor : ConstDynamicRecursiveASTVisitor {
+ UnqualNameVisitor(const FunctionDecl &F) : F(F) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
bool Collision = false;
- bool shouldWalkTypesOfTypeLocs() const { return false; }
-
bool visitUnqualName(StringRef UnqualName) {
// Check for collisions with function arguments.
for (ParmVarDecl *Param : F.parameters())
@@ -64,7 +63,7 @@ struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {
return false;
}
- bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier = true) {
+ bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier = true) override {
if (TL.isNull())
return true;
@@ -115,17 +114,17 @@ struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {
break;
}
- return RecursiveASTVisitor<UnqualNameVisitor>::TraverseTypeLoc(
+ return ConstDynamicRecursiveASTVisitor::TraverseTypeLoc(
TL, TraverseQualifier);
}
// Replace the base method in order to call our own
// TraverseTypeLoc().
- bool TraverseQualifiedTypeLoc(QualifiedTypeLoc TL, bool TraverseQualifier) {
+ bool TraverseQualifiedTypeLoc(QualifiedTypeLoc TL, bool TraverseQualifier) override {
return TraverseTypeLoc(TL.getUnqualifiedLoc(), TraverseQualifier);
}
- bool VisitDeclRefExpr(DeclRefExpr *S) {
+ bool VisitDeclRefExpr(const DeclRefExpr *S) override {
DeclarationName Name = S->getNameInfo().getName();
return S->getQualifierLoc() || Name.isEmpty() || !Name.isIdentifier() ||
!visitUnqualName(Name.getAsIdentifierInfo()->getName());
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
index 6da4cf7c6bf94..dd5a3dcf08e79 100644
--- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -9,7 +9,7 @@
#include "ConvertMemberFunctionsToStatic.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Lexer.h"
@@ -55,18 +55,18 @@ AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
}
AST_MATCHER(CXXMethodDecl, usesThis) {
- class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
+ class FindUsageOfThis : public ConstDynamicRecursiveASTVisitor {
public:
bool Used = false;
- bool VisitCXXThisExpr(const CXXThisExpr *E) {
+ bool VisitCXXThisExpr(const CXXThisExpr *E) override {
Used = true;
return false; // Stop traversal.
}
// If we enter a class declaration, don't traverse into it as any usages of
// `this` will correspond to the nested class.
- bool TraverseCXXRecordDecl(CXXRecordDecl *RD) { return true; }
+ bool TraverseCXXRecordDecl(const CXXRecordDecl *RD) override { return true; }
} UsageOfThis;
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 4791df037d77d..748246242b961 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -11,7 +11,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -207,9 +207,8 @@ void CognitiveComplexity::account(SourceLocation Loc, unsigned short Nesting,
namespace {
-class FunctionASTVisitor final
- : public RecursiveASTVisitor<FunctionASTVisitor> {
- using Base = RecursiveASTVisitor<FunctionASTVisitor>;
+class FunctionASTVisitor final : public ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
// If set to true, macros are ignored during analysis.
const bool IgnoreMacros;
@@ -227,21 +226,25 @@ class FunctionASTVisitor final
explicit FunctionASTVisitor(const bool IgnoreMacros)
: IgnoreMacros(IgnoreMacros) {}
- bool traverseStmtWithIncreasedNestingLevel(Stmt *Node) {
+ bool traverseStmtWithIncreasedNestingLevel(const Stmt *Node) {
++CurrentNestingLevel;
bool ShouldContinue = Base::TraverseStmt(Node);
--CurrentNestingLevel;
return ShouldContinue;
}
- bool traverseDeclWithIncreasedNestingLevel(Decl *Node) {
+ bool traverseDeclWithIncreasedNestingLevel(const Decl *Node) {
++CurrentNestingLevel;
bool ShouldContinue = Base::TraverseDecl(Node);
--CurrentNestingLevel;
return ShouldContinue;
}
- bool TraverseIfStmt(IfStmt *Node, bool InElseIf = false) {
+ bool TraverseIfStmt(const IfStmt *Node) override {
+ return traverseIfStmt(Node);
+ }
+
+ bool traverseIfStmt(const IfStmt *Node, bool InElseIf = false) {
if (!Node)
return Base::TraverseIfStmt(Node);
@@ -290,7 +293,7 @@ class FunctionASTVisitor final
return true;
if (auto *E = dyn_cast<IfStmt>(Node->getElse()))
- return TraverseIfStmt(E, true);
+ return traverseIfStmt(E, true);
{
CognitiveComplexity::Criteria Reasons =
@@ -315,7 +318,7 @@ class FunctionASTVisitor final
// In a sequence of binary logical operators, if the new operator is different
// from the previous one, then the cognitive complexity is increased.
- bool TraverseBinaryOperator(BinaryOperator *Op) {
+ bool TraverseBinaryOperator(const BinaryOperator *Op) override {
if (!Op || !Op->isLogicalOp())
return Base::TraverseBinaryOperator(Op);
@@ -346,7 +349,7 @@ class FunctionASTVisitor final
// It would make sense for the function call to start the new binary
// operator sequence, thus let's make sure that it creates a new stack frame.
- bool TraverseCallExpr(CallExpr *Node) {
+ bool TraverseCallExpr(const CallExpr *Node) override {
// If we are not currently processing any binary operator sequence, then
// no Node-handling is needed.
if (!Node || BinaryOperatorsStack.empty() || !CurrentBinaryOperator)
@@ -363,7 +366,7 @@ class FunctionASTVisitor final
#undef CurrentBinaryOperator
- bool TraverseStmt(Stmt *Node) {
+ bool TraverseStmt(const Stmt *Node) override {
if (!Node)
return Base::TraverseStmt(Node);
@@ -464,7 +467,11 @@ class FunctionASTVisitor final
// function is the entry point, then the Nesting level should not be
// increased. Thus that parameter is there and is used to fall-through
// directly to traversing if this is the main function that is being analyzed.
- bool TraverseDecl(Decl *Node, bool MainAnalyzedFunction = false) {
+ bool TraverseDecl(const Decl *Node) override {
+ return traverseDecl(Node);
+ }
+
+ bool traverseDecl(const Decl *Node, bool MainAnalyzedFunction = false) {
if (!Node || MainAnalyzedFunction)
return Base::TraverseDecl(Node);
@@ -530,10 +537,10 @@ void FunctionCognitiveComplexityCheck::check(
"The matchers should only match the functions that "
"have user-provided body.");
Loc = TheDecl->getLocation();
- Visitor.TraverseDecl(const_cast<FunctionDecl *>(TheDecl), true);
+ Visitor.traverseDecl(TheDecl, true);
} else {
Loc = TheLambdaExpr->getBeginLoc();
- Visitor.TraverseLambdaExpr(const_cast<LambdaExpr *>(TheLambdaExpr));
+ Visitor.TraverseLambdaExpr(TheLambdaExpr);
}
if (Visitor.CC.Total <= Threshold)
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
index 8c58346ede3fa..d34920c39ceb1 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "FunctionSizeCheck.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/BitVector.h"
@@ -16,11 +16,11 @@ using namespace clang::ast_matchers;
namespace clang::tidy::readability {
namespace {
-class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
- using Base = RecursiveASTVisitor<FunctionASTVisitor>;
+class FunctionASTVisitor : public ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
public:
- bool VisitVarDecl(VarDecl *VD) {
+ bool VisitVarDecl(const VarDecl *VD) override {
// Do not count function params.
// Do not count decomposition declarations (C++17's structured bindings).
if (StructNesting == 0 &&
@@ -28,14 +28,14 @@ class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
++Info.Variables;
return true;
}
- bool VisitBindingDecl(BindingDecl *BD) {
+ bool VisitBindingDecl(const BindingDecl *BD) override {
// Do count each of the bindings (in the decomposition declaration).
if (StructNesting == 0)
++Info.Variables;
return true;
}
- bool TraverseStmt(Stmt *Node) {
+ bool TraverseStmt(const Stmt *Node) override {
if (!Node)
return Base::TraverseStmt(Node);
@@ -66,7 +66,7 @@ class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
return true;
}
- bool TraverseCompoundStmt(CompoundStmt *Node) {
+ bool TraverseCompoundStmt(const CompoundStmt *Node) override {
// If this new compound statement is located in a compound statement, which
// is already nested NestingThreshold levels deep, record the start location
// of this new compound statement.
@@ -80,35 +80,35 @@ class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> {
return true;
}
- bool TraverseDecl(Decl *Node) {
+ bool TraverseDecl(const Decl *Node) override {
TrackedParent.push_back(false);
Base::TraverseDecl(Node);
TrackedParent.pop_back();
return true;
}
- bool TraverseLambdaExpr(LambdaExpr *Node) {
+ bool TraverseLambdaExpr(const LambdaExpr *Node) override {
++StructNesting;
Base::TraverseLambdaExpr(Node);
--StructNesting;
return true;
}
- bool TraverseCXXRecordDecl(CXXRecordDecl *Node) {
+ bool TraverseCXXRecordDecl(const CXXRecordDecl *Node) override {
++StructNesting;
Base::TraverseCXXRecordDecl(Node);
--StructNesting;
return true;
}
- bool TraverseStmtExpr(StmtExpr *SE) {
+ bool TraverseStmtExpr(const StmtExpr *SE) override {
++StructNesting;
Base::TraverseStmtExpr(SE);
--StructNesting;
return true;
}
- bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override {
if (CountMemberInitAsStmt)
++Info.Statements;
@@ -173,7 +173,7 @@ void FunctionSizeCheck::check(const MatchFinder::MatchResult &Result) {
FunctionASTVisitor Visitor;
Visitor.Info.NestingThreshold = NestingThreshold.value_or(-1);
Visitor.CountMemberInitAsStmt = CountMemberInitAsStmt;
- Visitor.TraverseDecl(const_cast<FunctionDecl *>(Func));
+ Visitor.TraverseDecl(Func);
auto &FI = Visitor.Info;
if (FI.Statements == 0)
diff --git a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
index bea68884e3bda..2ffb2e2bb348a 100644
--- a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
@@ -9,7 +9,7 @@
#include "MakeMemberFunctionConstCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ParentMapContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
@@ -51,7 +51,7 @@ AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
enum UsageKind { Unused, Const, NonConst };
-class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
+class FindUsageOfThis : public ConstDynamicRecursiveASTVisitor {
ASTContext &Ctxt;
public:
@@ -73,14 +73,14 @@ class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
return Parent;
}
- bool VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *) {
+ bool VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *) override {
// An UnresolvedMemberExpr might resolve to a non-const non-static
// member function.
Usage = NonConst;
return false; // Stop traversal.
}
- bool VisitCXXConstCastExpr(const CXXConstCastExpr *) {
+ bool VisitCXXConstCastExpr(const CXXConstCastExpr *) override {
// Workaround to support the pattern
// class C {
// const S *get() const;
@@ -171,7 +171,7 @@ class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
return false; // Stop traversal.
}
- bool VisitCXXThisExpr(const CXXThisExpr *E) {
+ bool VisitCXXThisExpr(const CXXThisExpr *E) override {
Usage = Const;
const auto *Parent = getParentExprIgnoreParens(E);
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 4184c295b5f0a..65a8365453e45 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -8,7 +8,7 @@
#include "SimplifyBooleanExprCheck.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Lex/Lexer.h"
#include "llvm/Support/SaveAndRestore.h"
@@ -258,8 +258,8 @@ static bool containsDiscardedTokens(const ASTContext &Context,
return false;
}
-class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
- using Base = RecursiveASTVisitor<Visitor>;
+class SimplifyBooleanExprCheck::Visitor : public ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
public:
Visitor(SimplifyBooleanExprCheck *Check, ASTContext &Context)
@@ -267,7 +267,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
bool traverse() { return TraverseAST(Context); }
- static bool shouldIgnore(Stmt *S) {
+ static bool shouldIgnore(const Stmt *S) {
switch (S->getStmtClass()) {
case Stmt::ImplicitCastExprClass:
case Stmt::MaterializeTemporaryExprClass:
@@ -278,7 +278,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
}
}
- bool dataTraverseStmtPre(Stmt *S) {
+ bool dataTraverseStmtPre(const Stmt *S) override {
if (!S) {
return true;
}
@@ -289,7 +289,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
return true;
}
- bool dataTraverseStmtPost(Stmt *S) {
+ bool dataTraverseStmtPost(const Stmt *S) override {
if (S && !shouldIgnore(S)) {
assert(StmtStack.back() == S);
StmtStack.pop_back();
@@ -297,7 +297,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
return true;
}
- bool VisitBinaryOperator(const BinaryOperator *Op) const {
+ bool VisitBinaryOperator(const BinaryOperator *Op) override {
Check->reportBinOp(Context, Op);
return true;
}
@@ -346,8 +346,8 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
/// only 1 statement in the \c CompoundStmt, applies F on that single
/// statement.
template <typename Functor>
- static auto checkSingleStatement(Stmt *S, Functor F) -> decltype(F(S)) {
- if (auto *CS = dyn_cast<CompoundStmt>(S)) {
+ static auto checkSingleStatement(const Stmt *S, Functor F) -> decltype(F(S)) {
+ if (const auto *CS = dyn_cast<CompoundStmt>(S)) {
if (CS->size() == 1)
return F(CS->body_front());
return {};
@@ -355,11 +355,11 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
return F(S);
}
- Stmt *parent() const {
+ const Stmt *parent() const {
return StmtStack.size() < 2 ? nullptr : StmtStack[StmtStack.size() - 2];
}
- bool VisitIfStmt(IfStmt *If) {
+ bool VisitIfStmt(const IfStmt *If) override {
// Skip any if's that have a condition var or an init statement, or are
// "if consteval" statements.
if (If->hasInitStorage() || If->hasVarStorage() || If->isConsteval())
@@ -369,7 +369,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
* if (false) ThenStmt(); -> <Empty>;
* if (false) ThenStmt(); else ElseStmt() -> ElseStmt();
*/
- Expr *Cond = If->getCond()->IgnoreImplicit();
+ const Expr *Cond = If->getCond()->IgnoreImplicit();
if (std::optional<bool> Bool = getAsBoolLiteral(Cond, true)) {
if (*Bool)
Check->replaceWithThenStatement(Context, If, Cond);
@@ -439,7 +439,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
return true;
}
- bool VisitConditionalOperator(ConditionalOperator *Cond) {
+ bool VisitConditionalOperator(const ConditionalOperator *Cond) override {
/*
* Condition ? true : false; -> Condition
* Condition ? false : true; -> !Condition;
@@ -455,7 +455,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
return true;
}
- bool VisitCompoundStmt(CompoundStmt *CS) {
+ bool VisitCompoundStmt(const CompoundStmt *CS) override {
if (CS->size() < 2)
return true;
bool CurIf = false, PrevIf = false;
@@ -558,7 +558,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
}
}
- bool TraverseUnaryOperator(UnaryOperator *Op) {
+ bool TraverseUnaryOperator(const UnaryOperator *Op) override {
if (!Check->SimplifyDeMorgan || Op->getOpcode() != UO_LNot)
return Base::TraverseUnaryOperator(Op);
const Expr *SubImp = Op->getSubExpr()->IgnoreImplicit();
@@ -587,7 +587,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
private:
bool IsProcessing = false;
SimplifyBooleanExprCheck *Check;
- SmallVector<Stmt *, 32> StmtStack;
+ SmallVector<const Stmt *, 32> StmtStack;
ASTContext &Context;
};
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 70f6092a5e4bc..953818a186a52 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -9,7 +9,7 @@
#include "RenamerClangTidyCheck.h"
#include "ASTUtils.h"
#include "clang/AST/CXXInheritance.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Frontend/CompilerInstance.h"
@@ -211,19 +211,17 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks {
RenamerClangTidyCheck *Check;
};
-class RenamerClangTidyVisitor
- : public RecursiveASTVisitor<RenamerClangTidyVisitor> {
+class RenamerClangTidyVisitor : public ConstDynamicRecursiveASTVisitor {
public:
RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager &SM,
bool AggressiveDependentMemberLookup)
: Check(Check), SM(SM),
- AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {}
-
- bool shouldVisitTemplateInstantiations() const { return true; }
-
- bool shouldVisitImplicitCode() const { return false; }
+ AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {
+ ShouldVisitTemplateInstantiations = true;
+ ShouldVisitImplicitCode = false;
+ }
- bool VisitCXXConstructorDecl(CXXConstructorDecl *Decl) {
+ bool VisitCXXConstructorDecl(const CXXConstructorDecl *Decl) override {
if (Decl->isImplicit())
return true;
Check->addUsage(Decl->getParent(), Decl->getNameInfo().getSourceRange(),
@@ -241,7 +239,7 @@ class RenamerClangTidyVisitor
return true;
}
- bool VisitCXXDestructorDecl(CXXDestructorDecl *Decl) {
+ bool VisitCXXDestructorDecl(const CXXDestructorDecl *Decl) override {
if (Decl->isImplicit())
return true;
SourceRange Range = Decl->getNameInfo().getSourceRange();
@@ -255,20 +253,20 @@ class RenamerClangTidyVisitor
return true;
}
- bool VisitUsingDecl(UsingDecl *Decl) {
+ bool VisitUsingDecl(const UsingDecl *Decl) override {
for (const auto *Shadow : Decl->shadows())
Check->addUsage(Shadow->getTargetDecl(),
Decl->getNameInfo().getSourceRange(), SM);
return true;
}
- bool VisitUsingDirectiveDecl(UsingDirectiveDecl *Decl) {
+ bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *Decl) override {
Check->addUsage(Decl->getNominatedNamespaceAsWritten(),
Decl->getIdentLocation(), SM);
return true;
}
- bool VisitNamedDecl(NamedDecl *Decl) {
+ bool VisitNamedDecl(const NamedDecl *Decl) override {
SourceRange UsageRange =
DeclarationNameInfo(Decl->getDeclName(), Decl->getLocation())
.getSourceRange();
@@ -276,13 +274,13 @@ class RenamerClangTidyVisitor
return true;
}
- bool VisitDeclRefExpr(DeclRefExpr *DeclRef) {
+ bool VisitDeclRefExpr(const DeclRefExpr *DeclRef) override {
SourceRange Range = DeclRef->getNameInfo().getSourceRange();
Check->addUsage(DeclRef->getDecl(), Range, SM);
return true;
}
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Loc) {
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Loc) override {
if (NestedNameSpecifier Spec = Loc.getNestedNameSpecifier();
Spec.getKind() == NestedNameSpecifier::Kind::Namespace) {
if (const auto *Decl =
@@ -290,18 +288,17 @@ class RenamerClangTidyVisitor
Check->addUsage(Decl, Loc.getLocalSourceRange(), SM);
}
- using Base = RecursiveASTVisitor<RenamerClangTidyVisitor>;
- return Base::TraverseNestedNameSpecifierLoc(Loc);
+ return ConstDynamicRecursiveASTVisitor::TraverseNestedNameSpecifierLoc(Loc);
}
- bool VisitMemberExpr(MemberExpr *MemberRef) {
+ bool VisitMemberExpr(const MemberExpr *MemberRef) override {
SourceRange Range = MemberRef->getMemberNameInfo().getSourceRange();
Check->addUsage(MemberRef->getMemberDecl(), Range, SM);
return true;
}
bool
- VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *DepMemberRef) {
+ VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *DepMemberRef) override {
QualType BaseType = DepMemberRef->isArrow()
? DepMemberRef->getBaseType()->getPointeeType()
: DepMemberRef->getBaseType();
@@ -325,28 +322,28 @@ class RenamerClangTidyVisitor
return true;
}
- bool VisitTypedefTypeLoc(const TypedefTypeLoc &Loc) {
+ bool VisitTypedefTypeLoc(TypedefTypeLoc Loc) override {
Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
return true;
}
- bool VisitTagTypeLoc(const TagTypeLoc &Loc) {
+ bool VisitTagTypeLoc(TagTypeLoc Loc) override {
Check->addUsage(Loc.getOriginalDecl(), Loc.getNameLoc(), SM);
return true;
}
- bool VisitUnresolvedUsingTypeLoc(const UnresolvedUsingTypeLoc &Loc) {
+ bool VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc Loc) override {
Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
return true;
}
- bool VisitTemplateTypeParmTypeLoc(const TemplateTypeParmTypeLoc &Loc) {
+ bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc Loc) override {
Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
return true;
}
bool
- VisitTemplateSpecializationTypeLoc(const TemplateSpecializationTypeLoc &Loc) {
+ VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc Loc) override {
const TemplateDecl *Decl =
Loc.getTypePtr()->getTemplateName().getAsTemplateDecl(
/*IgnoreDeduced=*/true);
@@ -360,7 +357,7 @@ class RenamerClangTidyVisitor
return true;
}
- bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) {
+ bool VisitDesignatedInitExpr(const DesignatedInitExpr *Expr) override {
for (const DesignatedInitExpr::Designator &D : Expr->designators()) {
if (!D.isFieldDesignator())
continue;
diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 0dcff2eae05e7..8d7ba84ca774b 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -20,7 +20,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/TypeLoc.h"
@@ -479,7 +479,7 @@ namespace {
/// not have the deduced type set. Instead, we have to go to the appropriate
/// DeclaratorDecl/FunctionDecl and work our back to the AutoType that does have
/// a deduced type set. The AST should be improved to simplify this scenario.
-class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
+class DeducedTypeVisitor : public ConstDynamicRecursiveASTVisitor {
SourceLocation SearchedLocation;
const HeuristicResolver *Resolver;
@@ -493,7 +493,7 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
//- decltype(auto) i = 1;
//- auto& i = 1;
//- auto* i = &a;
- bool VisitDeclaratorDecl(DeclaratorDecl *D) {
+ bool VisitDeclaratorDecl(const DeclaratorDecl *D) override {
if (!D->getTypeSourceInfo() ||
!D->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc() ||
D->getTypeSourceInfo()
@@ -522,7 +522,7 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
//- auto foo() -> int {}
//- auto foo() -> decltype(1+1) {}
//- operator auto() const { return 10; }
- bool VisitFunctionDecl(FunctionDecl *D) {
+ bool VisitFunctionDecl(const FunctionDecl *D) override {
if (!D->getTypeSourceInfo())
return true;
// Loc of auto in return type (c++14).
@@ -553,7 +553,7 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
// Handle non-auto decltype, e.g.:
// - auto foo() -> decltype(expr) {}
// - decltype(expr);
- bool VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
+ bool VisitDecltypeTypeLoc(DecltypeTypeLoc TL) override {
if (TL.getBeginLoc() != SearchedLocation)
return true;
@@ -571,7 +571,7 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
// Handle functions/lambdas with `auto` typed parameters.
// We deduce the type if there's exactly one instantiation visible.
- bool VisitParmVarDecl(ParmVarDecl *PVD) {
+ bool VisitParmVarDecl(const ParmVarDecl *PVD) override {
if (!PVD->getType()->isDependentType())
return true;
// 'auto' here does not name an AutoType, but an implicit template param.
@@ -659,13 +659,13 @@ static NamedDecl *getOnlyInstantiationImpl(TemplateDeclTy *TD) {
return Only;
}
-NamedDecl *getOnlyInstantiation(NamedDecl *TemplatedDecl) {
- if (TemplateDecl *TD = TemplatedDecl->getDescribedTemplate()) {
- if (auto *CTD = llvm::dyn_cast<ClassTemplateDecl>(TD))
+const NamedDecl *getOnlyInstantiation(const NamedDecl *TemplatedDecl) {
+ if (const TemplateDecl *TD = TemplatedDecl->getDescribedTemplate()) {
+ if (const auto *CTD = llvm::dyn_cast<ClassTemplateDecl>(TD))
return getOnlyInstantiationImpl(CTD);
- if (auto *FTD = llvm::dyn_cast<FunctionTemplateDecl>(TD))
+ if (const auto *FTD = llvm::dyn_cast<FunctionTemplateDecl>(TD))
return getOnlyInstantiationImpl(FTD);
- if (auto *VTD = llvm::dyn_cast<VarTemplateDecl>(TD))
+ if (const auto *VTD = llvm::dyn_cast<VarTemplateDecl>(TD))
return getOnlyInstantiationImpl(VTD);
}
return nullptr;
@@ -810,23 +810,22 @@ const TemplateTypeParmType *getUnderlyingPackType(const ParmVarDecl *Param) {
// resolved parameters (passed as argument to a parameter that is not an
// expanded template type parameter pack) and forwarding parameters (passed to a
// parameter that is an expanded template type parameter pack).
-class ForwardingCallVisitor
- : public RecursiveASTVisitor<ForwardingCallVisitor> {
+class ForwardingCallVisitor : public ConstDynamicRecursiveASTVisitor {
public:
ForwardingCallVisitor(ArrayRef<const ParmVarDecl *> Parameters)
: Parameters{Parameters},
PackType{getUnderlyingPackType(Parameters.front())} {}
- bool VisitCallExpr(CallExpr *E) {
- auto *Callee = getCalleeDeclOrUniqueOverload(E);
+ bool VisitCallExpr(const CallExpr *E) override {
+ const auto *Callee = getCalleeDeclOrUniqueOverload(E);
if (Callee) {
handleCall(Callee, E->arguments());
}
return !Info.has_value();
}
- bool VisitCXXConstructExpr(CXXConstructExpr *E) {
- auto *Callee = E->getConstructor();
+ bool VisitCXXConstructExpr(const CXXConstructExpr *E) override {
+ const auto *Callee = E->getConstructor();
if (Callee) {
handleCall(Callee, E->arguments());
}
@@ -853,7 +852,7 @@ class ForwardingCallVisitor
ArrayRef<const ParmVarDecl *> Tail;
// If the parameters were resolved to another forwarding FunctionDecl, this
// is it.
- std::optional<FunctionDecl *> PackTarget;
+ std::optional<const FunctionDecl *> PackTarget;
};
// The output of this visitor
@@ -862,7 +861,7 @@ class ForwardingCallVisitor
private:
// inspects the given callee with the given args to check whether it
// contains Parameters, and sets Info accordingly.
- void handleCall(FunctionDecl *Callee, typename CallExpr::arg_range Args) {
+ void handleCall(const FunctionDecl *Callee, typename CallExpr::const_arg_range Args) {
// Skip functions with less parameters, they can't be the target.
if (Callee->parameters().size() < Parameters.size())
return;
@@ -899,7 +898,7 @@ class ForwardingCallVisitor
// Returns the beginning of the expanded pack represented by Parameters
// in the given arguments, if it is there.
- std::optional<size_t> findPack(typename CallExpr::arg_range Args) {
+ std::optional<size_t> findPack(typename CallExpr::const_arg_range Args) {
// find the argument directly referring to the first parameter
assert(Parameters.size() <= static_cast<size_t>(llvm::size(Args)));
for (auto Begin = Args.begin(), End = Args.end() - Parameters.size() + 1;
@@ -920,9 +919,9 @@ class ForwardingCallVisitor
return std::nullopt;
}
- static FunctionDecl *getCalleeDeclOrUniqueOverload(CallExpr *E) {
- Decl *CalleeDecl = E->getCalleeDecl();
- auto *Callee = dyn_cast_or_null<FunctionDecl>(CalleeDecl);
+ static const FunctionDecl *getCalleeDeclOrUniqueOverload(const CallExpr *E) {
+ const Decl *CalleeDecl = E->getCalleeDecl();
+ const auto *Callee = dyn_cast_or_null<FunctionDecl>(CalleeDecl);
if (!Callee) {
if (auto *Lookup = dyn_cast<UnresolvedLookupExpr>(E->getCallee())) {
Callee = resolveOverload(Lookup, E);
@@ -934,8 +933,8 @@ class ForwardingCallVisitor
return nullptr;
}
- static FunctionDecl *resolveOverload(UnresolvedLookupExpr *Lookup,
- CallExpr *E) {
+ static FunctionDecl *resolveOverload(const UnresolvedLookupExpr *Lookup,
+ const CallExpr *E) {
FunctionDecl *MatchingDecl = nullptr;
if (!Lookup->requiresADL()) {
// Check whether there is a single overload with this number of
diff --git a/clang-tools-extra/clangd/AST.h b/clang-tools-extra/clangd/AST.h
index 2b83595e5b8e9..44b94020206ab 100644
--- a/clang-tools-extra/clangd/AST.h
+++ b/clang-tools-extra/clangd/AST.h
@@ -180,7 +180,7 @@ TemplateTypeParmTypeLoc getContainedAutoParamType(TypeLoc TL);
// If TemplatedDecl is the generic body of a template, and the template has
// exactly one visible instantiation, return the instantiated body.
-NamedDecl *getOnlyInstantiation(NamedDecl *TemplatedDecl);
+const NamedDecl *getOnlyInstantiation(const NamedDecl *TemplatedDecl);
/// Return attributes attached directly to a node.
std::vector<const Attr *> getAttributes(const DynTypedNode &);
diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp
index 9a8d41d870929..d3f384f3351cf 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -15,7 +15,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/TextNodeDumper.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
@@ -37,14 +37,14 @@ template <typename Print> std::string toString(const Print &C) {
return std::move(OS.str());
}
-bool isInjectedClassName(Decl *D) {
+bool isInjectedClassName(const Decl *D) {
if (const auto *CRD = llvm::dyn_cast<CXXRecordDecl>(D))
return CRD->isInjectedClassName();
return false;
}
-class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
- using Base = RecursiveASTVisitor<DumpVisitor>;
+class DumpVisitor : public ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
const syntax::TokenBuffer &Tokens;
const ASTContext &Ctx;
@@ -337,68 +337,68 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
// Override traversal to record the nodes we care about.
// Generally, these are nodes with position information (TypeLoc, not Type).
- bool TraverseDecl(Decl *D) {
+ bool TraverseDecl(const Decl *D) override {
return !D || isInjectedClassName(D) ||
traverseNode("declaration", D, [&] { Base::TraverseDecl(D); });
}
- bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier = true) {
+ bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier = true) override {
return !TL || traverseNode("type", TL, [&] {
Base::TraverseTypeLoc(TL, TraverseQualifier);
});
}
- bool TraverseTemplateName(const TemplateName &TN) {
+ bool TraverseTemplateName(TemplateName TN) override {
return traverseNode("template name", TN,
[&] { Base::TraverseTemplateName(TN); });
}
- bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &TAL) {
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &TAL) override {
return traverseNode("template argument", TAL,
[&] { Base::TraverseTemplateArgumentLoc(TAL); });
}
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSL) {
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSL) override {
return !NNSL || traverseNode("specifier", NNSL, [&] {
Base::TraverseNestedNameSpecifierLoc(NNSL);
});
}
- bool TraverseConstructorInitializer(CXXCtorInitializer *CCI) {
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *CCI) override {
return !CCI || traverseNode("constructor initializer", CCI, [&] {
Base::TraverseConstructorInitializer(CCI);
});
}
- bool TraverseAttr(Attr *A) {
+ bool TraverseAttr(const Attr *A) override {
return !A || traverseNode("attribute", A, [&] { Base::TraverseAttr(A); });
}
- bool TraverseConceptReference(ConceptReference *C) {
+ bool TraverseConceptReference(const ConceptReference *C) override {
return !C || traverseNode("reference", C,
[&] { Base::TraverseConceptReference(C); });
}
- bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &CBS) {
+ bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &CBS) override {
return traverseNode("base", CBS,
[&] { Base::TraverseCXXBaseSpecifier(CBS); });
}
// Stmt is the same, but this form allows the data recursion optimization.
- bool dataTraverseStmtPre(Stmt *S) {
+ bool dataTraverseStmtPre(const Stmt *S) override {
return S && traverseNodePre(isa<Expr>(S) ? "expression" : "statement", S);
}
- bool dataTraverseStmtPost(Stmt *X) { return traverseNodePost(); }
+ bool dataTraverseStmtPost(const Stmt *X) override { return traverseNodePost(); }
// QualifiedTypeLoc is handled strangely in RecursiveASTVisitor: the derived
// TraverseTypeLoc is not called for the inner UnqualTypeLoc.
// This means we'd never see 'int' in 'const int'! Work around that here.
// (The reason for the behavior is to avoid traversing the nested Type twice,
// but we ignore TraverseType anyway).
- bool TraverseQualifiedTypeLoc(QualifiedTypeLoc QTL, bool TraverseQualifier) {
+ bool TraverseQualifiedTypeLoc(QualifiedTypeLoc QTL, bool TraverseQualifier) override {
return TraverseTypeLoc(QTL.getUnqualifiedLoc());
}
// Uninteresting parts of the AST that don't have locations within them.
- bool TraverseNestedNameSpecifier(NestedNameSpecifier) { return true; }
- bool TraverseType(QualType) { return true; }
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier) override { return true; }
+ bool TraverseType(QualType, bool TraverseQualifier = true) override { return true; }
// OpaqueValueExpr blocks traversal, we must explicitly traverse it.
- bool TraverseOpaqueValueExpr(OpaqueValueExpr *E) {
+ bool TraverseOpaqueValueExpr(const OpaqueValueExpr *E) override {
return TraverseStmt(E->getSourceExpr());
}
// We only want to traverse the *syntactic form* to understand the selection.
- bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
+ bool TraversePseudoObjectExpr(const PseudoObjectExpr *E) override {
return TraverseStmt(E->getSyntacticForm());
}
};
@@ -410,26 +410,25 @@ ASTNode dumpAST(const DynTypedNode &N, const syntax::TokenBuffer &Tokens,
DumpVisitor V(Tokens, Ctx);
// DynTypedNode only works with const, RecursiveASTVisitor only non-const :-(
if (const auto *D = N.get<Decl>())
- V.TraverseDecl(const_cast<Decl *>(D));
+ V.TraverseDecl(D);
else if (const auto *S = N.get<Stmt>())
- V.TraverseStmt(const_cast<Stmt *>(S));
+ V.TraverseStmt(S);
else if (const auto *NNSL = N.get<NestedNameSpecifierLoc>())
- V.TraverseNestedNameSpecifierLoc(
- *const_cast<NestedNameSpecifierLoc *>(NNSL));
+ V.TraverseNestedNameSpecifierLoc(*NNSL);
else if (const auto *NNS = N.get<NestedNameSpecifier>())
V.TraverseNestedNameSpecifier(*NNS);
else if (const auto *TL = N.get<TypeLoc>())
- V.TraverseTypeLoc(*const_cast<TypeLoc *>(TL));
+ V.TraverseTypeLoc(*TL);
else if (const auto *QT = N.get<QualType>())
- V.TraverseType(*const_cast<QualType *>(QT));
+ V.TraverseType(*QT);
else if (const auto *CCI = N.get<CXXCtorInitializer>())
- V.TraverseConstructorInitializer(const_cast<CXXCtorInitializer *>(CCI));
+ V.TraverseConstructorInitializer(CCI);
else if (const auto *TAL = N.get<TemplateArgumentLoc>())
- V.TraverseTemplateArgumentLoc(*const_cast<TemplateArgumentLoc *>(TAL));
+ V.TraverseTemplateArgumentLoc(*TAL);
else if (const auto *CBS = N.get<CXXBaseSpecifier>())
- V.TraverseCXXBaseSpecifier(*const_cast<CXXBaseSpecifier *>(CBS));
+ V.TraverseCXXBaseSpecifier(*CBS);
else if (const auto *CR = N.get<ConceptReference>())
- V.TraverseConceptReference(const_cast<ConceptReference *>(CR));
+ V.TraverseConceptReference(CR);
else
elog("dumpAST: unhandled DynTypedNode kind {0}",
N.getNodeKind().asStringRef());
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 8aae41420b83e..1b9e84cc460ac 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -23,7 +23,7 @@
#include "clang/AST/ExprObjC.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/Type.h"
@@ -923,8 +923,7 @@ refInTypeLoc(TypeLoc L, const HeuristicResolver *Resolver) {
return V.Refs;
}
-class ExplicitReferenceCollector
- : public RecursiveASTVisitor<ExplicitReferenceCollector> {
+class ExplicitReferenceCollector : public ConstDynamicRecursiveASTVisitor {
public:
ExplicitReferenceCollector(llvm::function_ref<void(ReferenceLoc)> Out,
const HeuristicResolver *Resolver)
@@ -932,36 +931,36 @@ class ExplicitReferenceCollector
assert(Out);
}
- bool VisitTypeLoc(TypeLoc TTL) {
+ bool VisitTypeLoc(TypeLoc TTL) override {
if (TypeLocsToSkip.count(TTL.getBeginLoc()))
return true;
visitNode(DynTypedNode::create(TTL));
return true;
}
- bool VisitStmt(Stmt *S) {
+ bool VisitStmt(const Stmt *S) override {
visitNode(DynTypedNode::create(*S));
return true;
}
- bool TraverseOpaqueValueExpr(OpaqueValueExpr *OVE) {
+ bool TraverseOpaqueValueExpr(const OpaqueValueExpr *OVE) override {
visitNode(DynTypedNode::create(*OVE));
// Not clear why the source expression is skipped by default...
// FIXME: can we just make RecursiveASTVisitor do this?
- return RecursiveASTVisitor::TraverseStmt(OVE->getSourceExpr());
+ return ConstDynamicRecursiveASTVisitor::TraverseStmt(OVE->getSourceExpr());
}
- bool TraversePseudoObjectExpr(PseudoObjectExpr *POE) {
+ bool TraversePseudoObjectExpr(const PseudoObjectExpr *POE) override {
visitNode(DynTypedNode::create(*POE));
// Traverse only the syntactic form to find the *written* references.
// (The semantic form also contains lots of duplication)
- return RecursiveASTVisitor::TraverseStmt(POE->getSyntacticForm());
+ return ConstDynamicRecursiveASTVisitor::TraverseStmt(POE->getSyntacticForm());
}
// We re-define Traverse*, since there's no corresponding Visit*.
// TemplateArgumentLoc is the only way to get locations for references to
// template template parameters.
- bool TraverseTemplateArgumentLoc(TemplateArgumentLoc A) {
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &A) override {
switch (A.getArgument().getKind()) {
case TemplateArgument::Template:
case TemplateArgument::TemplateExpansion:
@@ -985,36 +984,36 @@ class ExplicitReferenceCollector
case TemplateArgument::StructuralValue:
break; // Handled by VisitType and VisitExpression.
};
- return RecursiveASTVisitor::TraverseTemplateArgumentLoc(A);
+ return ConstDynamicRecursiveASTVisitor::TraverseTemplateArgumentLoc(A);
}
- bool VisitDecl(Decl *D) {
+ bool VisitDecl(const Decl *D) override {
visitNode(DynTypedNode::create(*D));
return true;
}
// We have to use Traverse* because there is no corresponding Visit*.
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc L) {
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc L) override {
if (!L.getNestedNameSpecifier())
return true;
visitNode(DynTypedNode::create(L));
// Inner type is missing information about its qualifier, skip it.
if (auto TL = L.getAsTypeLoc())
TypeLocsToSkip.insert(TL.getBeginLoc());
- return RecursiveASTVisitor::TraverseNestedNameSpecifierLoc(L);
+ return ConstDynamicRecursiveASTVisitor::TraverseNestedNameSpecifierLoc(L);
}
- bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc) {
+ bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc) override {
visitNode(DynTypedNode::create(ProtocolLoc));
return true;
}
- bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override {
visitNode(DynTypedNode::create(*Init));
- return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
+ return ConstDynamicRecursiveASTVisitor::TraverseConstructorInitializer(Init);
}
- bool VisitConceptReference(const ConceptReference *CR) {
+ bool VisitConceptReference(const ConceptReference *CR) override {
visitNode(DynTypedNode::create(*CR));
return true;
}
@@ -1115,19 +1114,19 @@ void findExplicitReferences(const Stmt *S,
llvm::function_ref<void(ReferenceLoc)> Out,
const HeuristicResolver *Resolver) {
assert(S);
- ExplicitReferenceCollector(Out, Resolver).TraverseStmt(const_cast<Stmt *>(S));
+ ExplicitReferenceCollector(Out, Resolver).TraverseStmt(S);
}
void findExplicitReferences(const Decl *D,
llvm::function_ref<void(ReferenceLoc)> Out,
const HeuristicResolver *Resolver) {
assert(D);
- ExplicitReferenceCollector(Out, Resolver).TraverseDecl(const_cast<Decl *>(D));
+ ExplicitReferenceCollector(Out, Resolver).TraverseDecl(D);
}
void findExplicitReferences(const ASTContext &AST,
llvm::function_ref<void(ReferenceLoc)> Out,
const HeuristicResolver *Resolver) {
ExplicitReferenceCollector(Out, Resolver)
- .TraverseAST(const_cast<ASTContext &>(AST));
+ .TraverseAST(AST);
}
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, DeclRelation R) {
diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index d56b93e5f36dc..4a1395df7753d 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -18,7 +18,7 @@
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/Type.h"
@@ -373,7 +373,7 @@ struct Callee {
FunctionProtoTypeLoc Loc;
};
-class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
+class InlayHintVisitor : public ConstDynamicRecursiveASTVisitor {
public:
InlayHintVisitor(std::vector<InlayHint> &Results, ParsedAST &AST,
const Config &Cfg, std::optional<Range> RestrictRange,
@@ -397,14 +397,14 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
// SuppressDefaultTemplateArgs (set by default) to have an effect.
}
- bool VisitTypeLoc(TypeLoc TL) {
+ bool VisitTypeLoc(TypeLoc TL) override {
if (const auto *DT = llvm::dyn_cast<DecltypeType>(TL.getType()))
if (QualType UT = DT->getUnderlyingType(); !UT->isDependentType())
addTypeHint(TL.getSourceRange(), UT, ": ");
return true;
}
- bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+ bool VisitCXXConstructExpr(const CXXConstructExpr *E) override {
// Weed out constructor calls that don't look like a function call with
// an argument list, by checking the validity of getParenOrBraceRange().
// Also weed out std::initializer_list constructors as there are no names
@@ -425,8 +425,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
// Carefully recurse into PseudoObjectExprs, which typically incorporate
// a syntactic expression and several semantic expressions.
- bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
- Expr *SyntacticExpr = E->getSyntacticForm();
+ bool TraversePseudoObjectExpr(const PseudoObjectExpr *E) override {
+ const Expr *SyntacticExpr = E->getSyntacticForm();
if (isa<CallExpr>(SyntacticExpr))
// Since the counterpart semantics usually get the identical source
// locations as the syntactic one, visiting those would end up presenting
@@ -434,7 +434,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
// Thus, only traverse the syntactic forms if this is written as a
// CallExpr. This leaves the door open in case the arguments in the
// syntactic form could possibly get parameter names.
- return RecursiveASTVisitor<InlayHintVisitor>::TraverseStmt(SyntacticExpr);
+ return ConstDynamicRecursiveASTVisitor::TraverseStmt(SyntacticExpr);
// We don't want the hints for some of the MS property extensions.
// e.g.
// struct S {
@@ -445,10 +445,10 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
if (isa<BinaryOperator>(SyntacticExpr))
return true;
// FIXME: Handle other forms of a pseudo object expression.
- return RecursiveASTVisitor<InlayHintVisitor>::TraversePseudoObjectExpr(E);
+ return ConstDynamicRecursiveASTVisitor::TraversePseudoObjectExpr(E);
}
- bool VisitCallExpr(CallExpr *E) {
+ bool VisitCallExpr(const CallExpr *E) override {
if (!Cfg.InlayHints.Parameters)
return true;
@@ -497,7 +497,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return true;
}
- bool VisitFunctionDecl(FunctionDecl *D) {
+ bool VisitFunctionDecl(const FunctionDecl *D) override {
if (auto *FPT =
llvm::dyn_cast<FunctionProtoType>(D->getType().getTypePtr())) {
if (!FPT->hasTrailingReturn()) {
@@ -514,7 +514,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return true;
}
- bool VisitForStmt(ForStmt *S) {
+ bool VisitForStmt(const ForStmt *S) override {
if (Cfg.InlayHints.BlockEnd) {
std::string Name;
// Common case: for (int I = 0; I < N; I++). Use "I" as the name.
@@ -528,19 +528,19 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return true;
}
- bool VisitCXXForRangeStmt(CXXForRangeStmt *S) {
+ bool VisitCXXForRangeStmt(const CXXForRangeStmt *S) override {
if (Cfg.InlayHints.BlockEnd)
markBlockEnd(S->getBody(), "for", getSimpleName(*S->getLoopVariable()));
return true;
}
- bool VisitWhileStmt(WhileStmt *S) {
+ bool VisitWhileStmt(const WhileStmt *S) override {
if (Cfg.InlayHints.BlockEnd)
markBlockEnd(S->getBody(), "while", summarizeExpr(S->getCond()));
return true;
}
- bool VisitSwitchStmt(SwitchStmt *S) {
+ bool VisitSwitchStmt(const SwitchStmt *S) override {
if (Cfg.InlayHints.BlockEnd)
markBlockEnd(S->getBody(), "switch", summarizeExpr(S->getCond()));
return true;
@@ -553,7 +553,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
// For now, the answer is neither, just mark as "if".
// The ElseIf is a different IfStmt that doesn't know about the outer one.
llvm::DenseSet<const IfStmt *> ElseIfs; // not eligible for names
- bool VisitIfStmt(IfStmt *S) {
+ bool VisitIfStmt(const IfStmt *S) override {
if (Cfg.InlayHints.BlockEnd) {
if (const auto *ElseIf = llvm::dyn_cast_or_null<IfStmt>(S->getElse()))
ElseIfs.insert(ElseIf);
@@ -574,7 +574,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
addBlockEndHint(CS->getSourceRange(), Label, Name, "");
}
- bool VisitTagDecl(TagDecl *D) {
+ bool VisitTagDecl(const TagDecl *D) override {
if (Cfg.InlayHints.BlockEnd && D->isThisDeclarationADefinition()) {
std::string DeclPrefix = D->getKindName().str();
if (const auto *ED = dyn_cast<EnumDecl>(D)) {
@@ -586,7 +586,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return true;
}
- bool VisitNamespaceDecl(NamespaceDecl *D) {
+ bool VisitNamespaceDecl(const NamespaceDecl *D) override {
if (Cfg.InlayHints.BlockEnd) {
// For namespace, the range actually starts at the namespace keyword. But
// it should be fine since it's usually very short.
@@ -595,7 +595,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return true;
}
- bool VisitLambdaExpr(LambdaExpr *E) {
+ bool VisitLambdaExpr(const LambdaExpr *E) override {
FunctionDecl *D = E->getCallOperator();
if (!E->hasExplicitResultType()) {
SourceLocation TypeHintLoc;
@@ -609,14 +609,14 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return true;
}
- void addReturnTypeHint(FunctionDecl *D, SourceRange Range) {
+ void addReturnTypeHint(const FunctionDecl *D, SourceRange Range) {
auto *AT = D->getReturnType()->getContainedAutoType();
if (!AT || AT->getDeducedType().isNull())
return;
addTypeHint(Range, D->getReturnType(), /*Prefix=*/"-> ");
}
- bool VisitVarDecl(VarDecl *D) {
+ bool VisitVarDecl(const VarDecl *D) override {
// Do not show hints for the aggregate in a structured binding,
// but show hints for the individual bindings.
if (auto *DD = dyn_cast<DecompositionDecl>(D)) {
@@ -661,11 +661,11 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
}
// Handle templates like `int foo(auto x)` with exactly one instantiation.
- if (auto *PVD = llvm::dyn_cast<ParmVarDecl>(D)) {
+ if (const auto *PVD = llvm::dyn_cast<ParmVarDecl>(D)) {
if (D->getIdentifier() && PVD->getType()->isDependentType() &&
!getContainedAutoParamType(D->getTypeSourceInfo()->getTypeLoc())
.isNull()) {
- if (auto *IPVD = getOnlyParamInstantiation(PVD))
+ if (const auto *IPVD = getOnlyParamInstantiation(PVD))
addTypeHint(D->getLocation(), IPVD->getType(), /*Prefix=*/": ");
}
}
@@ -673,11 +673,11 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return true;
}
- ParmVarDecl *getOnlyParamInstantiation(ParmVarDecl *D) {
+ const ParmVarDecl *getOnlyParamInstantiation(const ParmVarDecl *D) {
auto *TemplateFunction = llvm::dyn_cast<FunctionDecl>(D->getDeclContext());
if (!TemplateFunction)
return nullptr;
- auto *InstantiatedFunction = llvm::dyn_cast_or_null<FunctionDecl>(
+ const auto *InstantiatedFunction = llvm::dyn_cast_or_null<FunctionDecl>(
getOnlyInstantiation(TemplateFunction));
if (!InstantiatedFunction)
return nullptr;
@@ -699,7 +699,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return InstantiatedFunction->getParamDecl(ParamIdx);
}
- bool VisitInitListExpr(InitListExpr *Syn) {
+ bool VisitInitListExpr(const InitListExpr *Syn) override {
// We receive the syntactic form here (shouldVisitImplicitCode() is false).
// This is the one we will ultimately attach designators to.
// It may have subobject initializers inlined without braces. The *semantic*
@@ -1150,8 +1150,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
return Range{HintStart, HintEnd};
}
- static bool isFunctionObjectCallExpr(CallExpr *E) noexcept {
- if (auto *CallExpr = dyn_cast<CXXOperatorCallExpr>(E))
+ static bool isFunctionObjectCallExpr(const CallExpr *E) noexcept {
+ if (const auto *CallExpr = dyn_cast<CXXOperatorCallExpr>(E))
return CallExpr->getOperator() == OverloadedOperatorKind::OO_Call;
return false;
}
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index ab720ebe6b47f..01caf981f2b55 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -20,7 +20,7 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/ExprCXX.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/LangOptions.h"
@@ -637,34 +637,33 @@ std::optional<HighlightingModifier> scopeModifier(const Type *T) {
/// Produces highlightings, which are not captured by findExplicitReferences,
/// e.g. highlights dependent names and 'auto' as the underlying type.
-class CollectExtraHighlightings
- : public RecursiveASTVisitor<CollectExtraHighlightings> {
- using Base = RecursiveASTVisitor<CollectExtraHighlightings>;
+class CollectExtraHighlightings : public ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
public:
CollectExtraHighlightings(HighlightingsBuilder &H) : H(H) {}
- bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+ bool VisitCXXConstructExpr(const CXXConstructExpr *E) override {
highlightMutableReferenceArguments(E->getConstructor(),
{E->getArgs(), E->getNumArgs()});
return true;
}
- bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override {
if (Init->isMemberInitializer())
if (auto *Member = Init->getMember())
highlightMutableReferenceArgument(Member->getType(), Init->getInit());
return Base::TraverseConstructorInitializer(Init);
}
- bool TraverseTypeConstraint(const TypeConstraint *C) {
+ bool TraverseTypeConstraint(const TypeConstraint *C) override {
if (auto *Args = C->getTemplateArgsAsWritten())
H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
return Base::TraverseTypeConstraint(C);
}
- bool VisitPredefinedExpr(PredefinedExpr *E) {
+ bool VisitPredefinedExpr(const PredefinedExpr *E) override {
H.addToken(E->getLocation(), HighlightingKind::LocalVariable)
.addModifier(HighlightingModifier::Static)
.addModifier(HighlightingModifier::Readonly)
@@ -672,19 +671,19 @@ class CollectExtraHighlightings
return true;
}
- bool VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) {
+ bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E) override {
if (auto *Args = E->getTemplateArgsAsWritten())
H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
return true;
}
- bool VisitTemplateDecl(TemplateDecl *D) {
+ bool VisitTemplateDecl(const TemplateDecl *D) override {
if (auto *TPL = D->getTemplateParameters())
H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
return true;
}
- bool VisitTagDecl(TagDecl *D) {
+ bool VisitTagDecl(const TagDecl *D) override {
for (unsigned i = 0; i < D->getNumTemplateParameterLists(); ++i) {
if (auto *TPL = D->getTemplateParameterList(i))
H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
@@ -693,42 +692,42 @@ class CollectExtraHighlightings
}
bool
- VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D) {
+ VisitClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl *D) override {
if (auto *Args = D->getTemplateArgsAsWritten())
H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
return true;
}
bool VisitClassTemplatePartialSpecializationDecl(
- ClassTemplatePartialSpecializationDecl *D) {
+ const ClassTemplatePartialSpecializationDecl *D) override {
if (auto *TPL = D->getTemplateParameters())
H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
return true;
}
- bool VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) {
+ bool VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *D) override {
if (auto *Args = D->getTemplateArgsAsWritten())
H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
return true;
}
bool VisitVarTemplatePartialSpecializationDecl(
- VarTemplatePartialSpecializationDecl *D) {
+ const VarTemplatePartialSpecializationDecl *D) override {
if (auto *TPL = D->getTemplateParameters())
H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
return true;
}
- bool VisitDeclRefExpr(DeclRefExpr *E) {
+ bool VisitDeclRefExpr(const DeclRefExpr *E) override {
H.addAngleBracketTokens(E->getLAngleLoc(), E->getRAngleLoc());
return true;
}
- bool VisitMemberExpr(MemberExpr *E) {
+ bool VisitMemberExpr(const MemberExpr *E) override {
H.addAngleBracketTokens(E->getLAngleLoc(), E->getRAngleLoc());
return true;
}
- bool VisitFunctionDecl(FunctionDecl *D) {
+ bool VisitFunctionDecl(const FunctionDecl *D) override {
if (D->isOverloadedOperator()) {
const auto AddOpDeclToken = [&](SourceLocation Loc) {
auto &Token = H.addToken(Loc, HighlightingKind::Operator)
@@ -747,7 +746,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+ bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *E) override {
const auto AddOpToken = [&](SourceLocation Loc) {
H.addToken(Loc, HighlightingKind::Operator)
.addModifier(HighlightingModifier::UserDefined);
@@ -761,47 +760,47 @@ class CollectExtraHighlightings
return true;
}
- bool VisitUnaryOperator(UnaryOperator *Op) {
+ bool VisitUnaryOperator(const UnaryOperator *Op) override {
auto &Token = H.addToken(Op->getOperatorLoc(), HighlightingKind::Operator);
if (Op->getSubExpr()->isTypeDependent())
Token.addModifier(HighlightingModifier::UserDefined);
return true;
}
- bool VisitBinaryOperator(BinaryOperator *Op) {
+ bool VisitBinaryOperator(const BinaryOperator *Op) override {
auto &Token = H.addToken(Op->getOperatorLoc(), HighlightingKind::Operator);
if (Op->getLHS()->isTypeDependent() || Op->getRHS()->isTypeDependent())
Token.addModifier(HighlightingModifier::UserDefined);
return true;
}
- bool VisitConditionalOperator(ConditionalOperator *Op) {
+ bool VisitConditionalOperator(const ConditionalOperator *Op) override {
H.addToken(Op->getQuestionLoc(), HighlightingKind::Operator);
H.addToken(Op->getColonLoc(), HighlightingKind::Operator);
return true;
}
- bool VisitCXXNewExpr(CXXNewExpr *E) {
+ bool VisitCXXNewExpr(const CXXNewExpr *E) override {
auto &Token = H.addToken(E->getBeginLoc(), HighlightingKind::Operator);
if (isa_and_present<CXXMethodDecl>(E->getOperatorNew()))
Token.addModifier(HighlightingModifier::UserDefined);
return true;
}
- bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+ bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) override {
auto &Token = H.addToken(E->getBeginLoc(), HighlightingKind::Operator);
if (isa_and_present<CXXMethodDecl>(E->getOperatorDelete()))
Token.addModifier(HighlightingModifier::UserDefined);
return true;
}
- bool VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
+ bool VisitCXXNamedCastExpr(const CXXNamedCastExpr *E) override {
const auto &B = E->getAngleBrackets();
H.addAngleBracketTokens(B.getBegin(), B.getEnd());
return true;
}
- bool VisitCallExpr(CallExpr *E) {
+ bool VisitCallExpr(const CallExpr *E) override {
// Highlighting parameters passed by non-const reference does not really
// make sense for literals...
if (isa<UserDefinedLiteral>(E))
@@ -880,7 +879,7 @@ class CollectExtraHighlightings
}
}
- bool VisitDecltypeTypeLoc(DecltypeTypeLoc L) {
+ bool VisitDecltypeTypeLoc(const DecltypeTypeLoc L) override {
if (auto K = kindForType(L.getTypePtr(), H.getResolver())) {
auto &Tok = H.addToken(L.getBeginLoc(), *K)
.addModifier(HighlightingModifier::Deduced);
@@ -892,7 +891,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitCXXDestructorDecl(CXXDestructorDecl *D) {
+ bool VisitCXXDestructorDecl(const CXXDestructorDecl *D) override {
if (auto *TI = D->getNameInfo().getNamedTypeInfo()) {
SourceLocation Loc = TI->getTypeLoc().getBeginLoc();
H.addExtraModifier(Loc, HighlightingModifier::ConstructorOrDestructor);
@@ -903,7 +902,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitCXXMemberCallExpr(CXXMemberCallExpr *CE) {
+ bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *CE) override {
// getMethodDecl can return nullptr with member pointers, e.g.
// `(foo.*pointer_to_member_fun)(arg);`
if (auto *D = CE->getMethodDecl()) {
@@ -925,7 +924,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitDeclaratorDecl(DeclaratorDecl *D) {
+ bool VisitDeclaratorDecl(const DeclaratorDecl *D) override {
for (unsigned i = 0; i < D->getNumTemplateParameterLists(); ++i) {
if (auto *TPL = D->getTemplateParameterList(i))
H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
@@ -979,7 +978,7 @@ class CollectExtraHighlightings
}
}
- bool VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
+ bool VisitObjCMethodDecl(const ObjCMethodDecl *OMD) override {
llvm::SmallVector<SourceLocation> Locs;
OMD->getSelectorLocs(Locs);
highlightObjCSelector(Locs, /*Decl=*/true,
@@ -988,11 +987,11 @@ class CollectExtraHighlightings
return true;
}
- bool VisitObjCMessageExpr(ObjCMessageExpr *OME) {
+ bool VisitObjCMessageExpr(const ObjCMessageExpr *OME) override {
llvm::SmallVector<SourceLocation> Locs;
OME->getSelectorLocs(Locs);
bool DefaultLibrary = false;
- if (ObjCMethodDecl *OMD = OME->getMethodDecl())
+ if (const ObjCMethodDecl *OMD = OME->getMethodDecl())
DefaultLibrary = isDefaultLibrary(OMD);
highlightObjCSelector(Locs, /*Decl=*/false, /*Def=*/false,
OME->isClassMessage(), DefaultLibrary);
@@ -1013,7 +1012,7 @@ class CollectExtraHighlightings
Tok.addModifier(HighlightingModifier::DefaultLibrary);
}
- bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *OPRE) {
+ bool VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) override {
// We need to handle implicit properties here since they will appear to
// reference `ObjCMethodDecl` via an implicit `ObjCMessageExpr`, so normal
// highlighting will not work.
@@ -1035,7 +1034,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitOverloadExpr(OverloadExpr *E) {
+ bool VisitOverloadExpr(const OverloadExpr *E) override {
H.addAngleBracketTokens(E->getLAngleLoc(), E->getRAngleLoc());
if (!E->decls().empty())
return true; // handled by findExplicitReferences.
@@ -1047,7 +1046,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+ bool VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) override {
H.addToken(E->getMemberNameInfo().getLoc(), HighlightingKind::Unknown)
.addModifier(HighlightingModifier::DependentName)
.addModifier(HighlightingModifier::ClassScope);
@@ -1055,7 +1054,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
+ bool VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) override {
H.addToken(E->getNameInfo().getLoc(), HighlightingKind::Unknown)
.addModifier(HighlightingModifier::DependentName)
.addModifier(HighlightingModifier::ClassScope);
@@ -1063,7 +1062,7 @@ class CollectExtraHighlightings
return true;
}
- bool VisitAttr(Attr *A) {
+ bool VisitAttr(const Attr *A) override {
switch (A->getKind()) {
case attr::Override:
case attr::Final:
@@ -1075,14 +1074,14 @@ class CollectExtraHighlightings
return true;
}
- bool VisitDependentNameTypeLoc(DependentNameTypeLoc L) {
+ bool VisitDependentNameTypeLoc(DependentNameTypeLoc L) override {
H.addToken(L.getNameLoc(), HighlightingKind::Type)
.addModifier(HighlightingModifier::DependentName)
.addModifier(HighlightingModifier::ClassScope);
return true;
}
- bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) {
+ bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) override {
if (!L.getTypePtr()->getTemplateName().getAsTemplateDecl(
/*IgnoreDeduced=*/true))
H.addToken(L.getTemplateNameLoc(), HighlightingKind::Type)
@@ -1092,12 +1091,12 @@ class CollectExtraHighlightings
return true;
}
- bool TraverseTemplateArgumentLoc(TemplateArgumentLoc L) {
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &L) override {
// Handle template template arguments only (other arguments are handled by
// their Expr, TypeLoc etc values).
if (L.getArgument().getKind() != TemplateArgument::Template &&
L.getArgument().getKind() != TemplateArgument::TemplateExpansion)
- return RecursiveASTVisitor::TraverseTemplateArgumentLoc(L);
+ return ConstDynamicRecursiveASTVisitor::TraverseTemplateArgumentLoc(L);
TemplateName N = L.getArgument().getAsTemplateOrTemplatePattern();
switch (N.getKind()) {
@@ -1120,7 +1119,7 @@ class CollectExtraHighlightings
// Names that could be resolved to a TemplateDecl are handled elsewhere.
break;
}
- return RecursiveASTVisitor::TraverseTemplateArgumentLoc(L);
+ return ConstDynamicRecursiveASTVisitor::TraverseTemplateArgumentLoc(L);
}
private:
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 05e04ac161e54..535c84efffe66 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -36,7 +36,7 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/ExprCXX.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtVisitor.h"
@@ -1043,7 +1043,7 @@ const Stmt *getLoopBody(DynTypedNode N) {
// AST traversal to highlight control flow statements under some root.
// Once we hit further control flow we prune the tree (or at least restrict
// what we highlight) so we capture e.g. breaks from the outer loop only.
-class FindControlFlow : public RecursiveASTVisitor<FindControlFlow> {
+class FindControlFlow : public ConstDynamicRecursiveASTVisitor {
// Types of control-flow statements we might highlight.
enum Target {
Break = 1,
@@ -1091,39 +1091,39 @@ class FindControlFlow : public RecursiveASTVisitor<FindControlFlow> {
// When traversing function or loops, limit targets to those that still
// refer to the original root.
- bool TraverseDecl(Decl *D) {
+ bool TraverseDecl(const Decl *D) override {
return !D || filterAndTraverse(DynTypedNode::create(*D), [&] {
- return RecursiveASTVisitor::TraverseDecl(D);
+ return ConstDynamicRecursiveASTVisitor::TraverseDecl(D);
});
}
- bool TraverseStmt(Stmt *S) {
+ bool TraverseStmt(const Stmt *S) override {
return !S || filterAndTraverse(DynTypedNode::create(*S), [&] {
- return RecursiveASTVisitor::TraverseStmt(S);
+ return ConstDynamicRecursiveASTVisitor::TraverseStmt(S);
});
}
// Add leaves that we found and want.
- bool VisitReturnStmt(ReturnStmt *R) {
+ bool VisitReturnStmt(const ReturnStmt *R) override {
found(Return, R->getReturnLoc());
return true;
}
- bool VisitBreakStmt(BreakStmt *B) {
+ bool VisitBreakStmt(const BreakStmt *B) override {
found(Break, B->getKwLoc());
return true;
}
- bool VisitContinueStmt(ContinueStmt *C) {
+ bool VisitContinueStmt(const ContinueStmt *C) override {
found(Continue, C->getKwLoc());
return true;
}
- bool VisitSwitchCase(SwitchCase *C) {
+ bool VisitSwitchCase(const SwitchCase *C) override {
found(Case, C->getKeywordLoc());
return true;
}
- bool VisitCXXThrowExpr(CXXThrowExpr *T) {
+ bool VisitCXXThrowExpr(const CXXThrowExpr *T) override {
found(Throw, T->getThrowLoc());
return true;
}
- bool VisitGotoStmt(GotoStmt *G) {
+ bool VisitGotoStmt(const GotoStmt *G) override {
// Goto is interesting if its target is outside the root.
if (const auto *LD = G->getLabel()) {
if (SM.isBeforeInTranslationUnit(LD->getLocation(), Bounds.getBegin()) ||
@@ -1243,7 +1243,7 @@ std::vector<SourceLocation> relatedControlFlow(const SelectionTree::Node &N) {
if (Root) {
if (!Bounds.isValid())
Bounds = Root->getSourceRange();
- FindControlFlow(Bounds, Result, SM).TraverseStmt(const_cast<Stmt *>(Root));
+ FindControlFlow(Bounds, Result, SM).TraverseStmt(Root);
}
return Result;
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
index f65c74fdbc9ee..b7a088679edda 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -14,7 +14,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
#include "clang/AST/NestedNameSpecifier.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/LLVM.h"
@@ -79,13 +79,13 @@ std::string AddUsing::title() const {
}
// Locates all "using" statements relevant to SelectionDeclContext.
-class UsingFinder : public RecursiveASTVisitor<UsingFinder> {
+class UsingFinder : public ConstDynamicRecursiveASTVisitor {
public:
UsingFinder(std::vector<const UsingDecl *> &Results,
const DeclContext *SelectionDeclContext, const SourceManager &SM)
: Results(Results), SelectionDeclContext(SelectionDeclContext), SM(SM) {}
- bool VisitUsingDecl(UsingDecl *D) {
+ bool VisitUsingDecl(const UsingDecl *D) override {
auto Loc = D->getUsingLoc();
if (SM.getFileID(Loc) != SM.getMainFileID()) {
return true;
@@ -96,7 +96,7 @@ class UsingFinder : public RecursiveASTVisitor<UsingFinder> {
return true;
}
- bool TraverseDecl(Decl *Node) {
+ bool TraverseDecl(const Decl *Node) override {
if (!Node)
return true;
// There is no need to go deeper into nodes that do not enclose selection,
@@ -104,7 +104,7 @@ class UsingFinder : public RecursiveASTVisitor<UsingFinder> {
// insertion point.
if (!Node->getDeclContext() ||
Node->getDeclContext()->Encloses(SelectionDeclContext)) {
- return RecursiveASTVisitor<UsingFinder>::TraverseDecl(Node);
+ return ConstDynamicRecursiveASTVisitor::TraverseDecl(Node);
}
return true;
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
index bc9a790232507..02b3b1fb88d88 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -58,7 +58,7 @@
#include "clang/AST/DeclBase.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
@@ -576,24 +576,23 @@ CapturedZoneInfo captureZoneInfo(const ExtractionZone &ExtZone) {
// We use the ASTVisitor instead of using the selection tree since we need to
// find references in the PostZone as well.
// FIXME: Check which statements we don't allow to extract.
- class ExtractionZoneVisitor
- : public clang::RecursiveASTVisitor<ExtractionZoneVisitor> {
+ class ExtractionZoneVisitor : public ConstDynamicRecursiveASTVisitor {
public:
ExtractionZoneVisitor(const ExtractionZone &ExtZone) : ExtZone(ExtZone) {
- TraverseDecl(const_cast<FunctionDecl *>(ExtZone.EnclosingFunction));
+ ExtractionZoneVisitor::TraverseDecl(ExtZone.EnclosingFunction);
}
- bool TraverseStmt(Stmt *S) {
+ bool TraverseStmt(const Stmt *S) override {
if (!S)
return true;
- bool IsRootStmt = ExtZone.isRootStmt(const_cast<const Stmt *>(S));
+ bool IsRootStmt = ExtZone.isRootStmt(S);
// If we are starting traversal of a RootStmt, we are somewhere inside
// ExtractionZone
if (IsRootStmt)
CurrentLocation = ZoneRelative::Inside;
addToLoopSwitchCounters(S, 1);
// Traverse using base class's TraverseStmt
- RecursiveASTVisitor::TraverseStmt(S);
+ ConstDynamicRecursiveASTVisitor::TraverseStmt(S);
addToLoopSwitchCounters(S, -1);
// We set the current location as after since next stmt will either be a
// RootStmt (handled at the beginning) or after extractionZone
@@ -604,7 +603,7 @@ CapturedZoneInfo captureZoneInfo(const ExtractionZone &ExtZone) {
// Add Increment to CurNumberOf{Loops,Switch} if statement is
// {Loop,Switch} and inside Extraction Zone.
- void addToLoopSwitchCounters(Stmt *S, int Increment) {
+ void addToLoopSwitchCounters(const Stmt *S, int Increment) {
if (CurrentLocation != ZoneRelative::Inside)
return;
if (isLoop(S))
@@ -613,12 +612,12 @@ CapturedZoneInfo captureZoneInfo(const ExtractionZone &ExtZone) {
CurNumberOfSwitch += Increment;
}
- bool VisitDecl(Decl *D) {
+ bool VisitDecl(const Decl *D) override {
Info.createDeclInfo(D, CurrentLocation);
return true;
}
- bool VisitDeclRefExpr(DeclRefExpr *DRE) {
+ bool VisitDeclRefExpr(const DeclRefExpr *DRE) override {
// Find the corresponding Decl and mark it's occurrence.
const Decl *D = DRE->getDecl();
auto *DeclInfo = Info.getDeclInfoFor(D);
@@ -630,13 +629,13 @@ CapturedZoneInfo captureZoneInfo(const ExtractionZone &ExtZone) {
return true;
}
- bool VisitReturnStmt(ReturnStmt *Return) {
+ bool VisitReturnStmt(const ReturnStmt *Return) override {
if (CurrentLocation == ZoneRelative::Inside)
Info.HasReturnStmt = true;
return true;
}
- bool VisitBreakStmt(BreakStmt *Break) {
+ bool VisitBreakStmt(const BreakStmt *Break) override {
// Control flow is broken if break statement is selected without any
// parent loop or switch statement.
if (CurrentLocation == ZoneRelative::Inside &&
@@ -645,7 +644,7 @@ CapturedZoneInfo captureZoneInfo(const ExtractionZone &ExtZone) {
return true;
}
- bool VisitContinueStmt(ContinueStmt *Continue) {
+ bool VisitContinueStmt(const ContinueStmt *Continue) override {
// Control flow is broken if Continue statement is selected without any
// parent loop
if (CurrentLocation == ZoneRelative::Inside && !CurNumberOfNestedLoops)
@@ -851,10 +850,9 @@ tooling::Replacement createForwardDeclaration(const NewFunction &ExtractedFunc,
// Returns true if ExtZone contains any ReturnStmts.
bool hasReturnStmt(const ExtractionZone &ExtZone) {
- class ReturnStmtVisitor
- : public clang::RecursiveASTVisitor<ReturnStmtVisitor> {
+ class ReturnStmtVisitor : public ConstDynamicRecursiveASTVisitor {
public:
- bool VisitReturnStmt(ReturnStmt *Return) {
+ bool VisitReturnStmt(const ReturnStmt *Return) override {
Found = true;
return false; // We found the answer, abort the scan.
}
@@ -863,7 +861,7 @@ bool hasReturnStmt(const ExtractionZone &ExtZone) {
ReturnStmtVisitor V;
for (const Stmt *RootStmt : ExtZone.RootStmts) {
- V.TraverseStmt(const_cast<Stmt *>(RootStmt));
+ V.TraverseStmt(RootStmt);
if (V.Found)
break;
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index c74250ccbe9ea..aa33b92d19f04 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -18,7 +18,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/LambdaCapture.h"
#include "clang/AST/OperationKinds.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/Basic/LangOptions.h"
@@ -62,7 +62,7 @@ class ExtractionContext {
const SourceManager &SM;
const ASTContext &Ctx;
// Decls referenced in the Expr
- std::vector<clang::Decl *> ReferencedDecls;
+ std::vector<const Decl *> ReferencedDecls;
// returns true if the Expr doesn't reference any variable declared in scope
bool exprIsValidOutside(const clang::Stmt *Scope) const;
// computes the Stmt before which we will extract out Expr
@@ -70,14 +70,12 @@ class ExtractionContext {
};
// Returns all the Decls referenced inside the given Expr
-static std::vector<clang::Decl *>
-computeReferencedDecls(const clang::Expr *Expr) {
+std::vector<const Decl *> computeReferencedDecls(const Expr *Expr) {
// RAV subclass to find all DeclRefs in a given Stmt
- class FindDeclRefsVisitor
- : public clang::RecursiveASTVisitor<FindDeclRefsVisitor> {
+ class FindDeclRefsVisitor : public ConstDynamicRecursiveASTVisitor {
public:
- std::vector<Decl *> ReferencedDecls;
- bool VisitDeclRefExpr(DeclRefExpr *DeclRef) { // NOLINT
+ std::vector<const Decl *> ReferencedDecls;
+ bool VisitDeclRefExpr(const DeclRefExpr *DeclRef) override { // NOLINT
// Stop the call operator of lambdas from being marked as a referenced
// DeclRefExpr in immediately invoked lambdas.
if (const auto *const Method =
@@ -94,7 +92,7 @@ computeReferencedDecls(const clang::Expr *Expr) {
// the DeclRefExprs inside the initializers of init-capture variables,
// variables mentioned in trailing return types, constraints and explicit
// defaulted template parameters.
- bool TraverseLambdaExpr(LambdaExpr *LExpr) {
+ bool TraverseLambdaExpr(const LambdaExpr *LExpr) override {
for (const auto &[Capture, Initializer] :
llvm::zip(LExpr->captures(), LExpr->capture_inits())) {
TraverseLambdaCapture(LExpr, &Capture, Initializer);
@@ -102,7 +100,7 @@ computeReferencedDecls(const clang::Expr *Expr) {
if (const clang::Expr *RequiresClause =
LExpr->getTrailingRequiresClause().ConstraintExpr) {
- TraverseStmt(const_cast<clang::Expr *>(RequiresClause));
+ TraverseStmt(RequiresClause);
}
for (auto *const TemplateParam : LExpr->getExplicitTemplateParameters())
@@ -125,7 +123,7 @@ computeReferencedDecls(const clang::Expr *Expr) {
};
FindDeclRefsVisitor Visitor;
- Visitor.TraverseStmt(const_cast<Stmt *>(cast<Stmt>(Expr)));
+ Visitor.TraverseStmt(cast<Stmt>(Expr));
return Visitor.ReferencedDecls;
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
index 5baa970bcb0c5..db258e0225410 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -13,7 +13,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Tooling/Core/Replacement.h"
#include <optional>
@@ -48,14 +48,14 @@ class RemoveUsingNamespace : public Tweak {
};
REGISTER_TWEAK(RemoveUsingNamespace)
-class FindSameUsings : public RecursiveASTVisitor<FindSameUsings> {
+class FindSameUsings : public ConstDynamicRecursiveASTVisitor {
public:
FindSameUsings(const UsingDirectiveDecl &Target,
std::vector<const UsingDirectiveDecl *> &Results)
: TargetNS(Target.getNominatedNamespace()),
TargetCtx(Target.getDeclContext()), Results(Results) {}
- bool VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+ bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) override {
if (D->getNominatedNamespace() != TargetNS ||
D->getDeclContext() != TargetCtx)
return true;
diff --git a/clang-tools-extra/clangd/unittests/ASTTests.cpp b/clang-tools-extra/clangd/unittests/ASTTests.cpp
index 91ae727d8c944..44f703605484c 100644
--- a/clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -305,11 +305,11 @@ TEST(ClangdAST, GetOnlyInstantiation) {
PrintingPolicy PP = AST.getASTContext().getPrintingPolicy();
PP.TerseOutput = true;
std::string Name;
- if (auto *Result = getOnlyInstantiation(
- const_cast<NamedDecl *>(&findDecl(AST, [&](const NamedDecl &D) {
+ if (const auto *Result = getOnlyInstantiation(
+ &findDecl(AST, [&](const NamedDecl &D) {
return D.getDescribedTemplate() != nullptr &&
D.getDeclKindName() == Case.NodeType;
- })))) {
+ }))) {
llvm::raw_string_ostream OS(Name);
Result->print(OS, PP);
}
diff --git a/clang-tools-extra/clangd/unittests/PrintASTTests.cpp b/clang-tools-extra/clangd/unittests/PrintASTTests.cpp
index 746966bbf171b..81e686d1cc876 100644
--- a/clang-tools-extra/clangd/unittests/PrintASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/PrintASTTests.cpp
@@ -11,7 +11,7 @@
#include "Protocol.h"
#include "SourceCode.h"
#include "TestTU.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -32,9 +32,9 @@ TEST_P(ASTUtils, PrintTemplateArgs) {
auto Pair = GetParam();
Annotations Test(Pair.AnnotatedCode);
auto AST = TestTU::withCode(Test.code()).build();
- struct Visitor : RecursiveASTVisitor<Visitor> {
+ struct Visitor : ConstDynamicRecursiveASTVisitor {
Visitor(std::vector<Position> Points) : Points(std::move(Points)) {}
- bool VisitNamedDecl(const NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
if (TemplateArgsAtPoints.size() == Points.size())
return true;
auto Pos = sourceLocToPosition(ND->getASTContext().getSourceManager(),
diff --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp
index a733fac932bf4..62a17d278d7cd 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -13,7 +13,7 @@
#include "TestFS.h"
#include "index/FileIndex.h"
#include "index/SymbolOrigin.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "llvm/ADT/ScopeExit.h"
@@ -240,10 +240,10 @@ const NamedDecl &findDecl(ParsedAST &AST, llvm::StringRef QName) {
const NamedDecl &findDecl(ParsedAST &AST,
std::function<bool(const NamedDecl &)> Filter) {
TraverseHeadersToo Too(AST);
- struct Visitor : RecursiveASTVisitor<Visitor> {
+ struct Visitor : ConstDynamicRecursiveASTVisitor {
decltype(Filter) F;
llvm::SmallVector<const NamedDecl *, 1> Decls;
- bool VisitNamedDecl(const NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
if (F(*ND))
Decls.push_back(ND);
return true;
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 0ac243937e6e4..355775b96c078 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -12,7 +12,7 @@
#include "clang-include-cleaner/Record.h"
#include "clang-include-cleaner/Types.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/FileEntry.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LLVM.h"
@@ -182,9 +182,9 @@ TEST_F(FindHeadersTest, NonSelfContainedTraverseExporter) {
}
TEST_F(FindHeadersTest, TargetIsExpandedFromMacroInHeader) {
- struct CustomVisitor : RecursiveASTVisitor<CustomVisitor> {
+ struct CustomVisitor : ConstDynamicRecursiveASTVisitor {
const Decl *Out = nullptr;
- bool VisitNamedDecl(const NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
if (ND->getName() == "FLAG_foo" || ND->getName() == "Foo") {
EXPECT_TRUE(Out == nullptr);
Out = ND;
@@ -285,11 +285,11 @@ TEST_F(FindHeadersTest, PreferredHeaderHint) {
class HeadersForSymbolTest : public FindHeadersTest {
protected:
llvm::SmallVector<Header> headersFor(llvm::StringRef Name) {
- struct Visitor : public RecursiveASTVisitor<Visitor> {
+ struct Visitor : ConstDynamicRecursiveASTVisitor {
const NamedDecl *Out = nullptr;
llvm::StringRef Name;
Visitor(llvm::StringRef Name) : Name(Name) {}
- bool VisitNamedDecl(const NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
if (auto *TD = ND->getDescribedTemplate())
ND = TD;
@@ -600,9 +600,9 @@ TEST_F(HeadersForSymbolTest, AmbiguousStdSymbolsUsingShadow) {
buildAST();
// Find the DeclRefExpr in the std::remove("abc") function call.
- struct Visitor : public RecursiveASTVisitor<Visitor> {
+ struct Visitor : ConstDynamicRecursiveASTVisitor {
const DeclRefExpr *Out = nullptr;
- bool VisitDeclRefExpr(const DeclRefExpr *DRE) {
+ bool VisitDeclRefExpr(const DeclRefExpr *DRE) override {
EXPECT_TRUE(Out == nullptr) << "Found multiple DeclRefExpr!";
Out = DRE;
return true;
diff --git a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
index 1e7baf142a75a..360a0e10b3d2d 100644
--- a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -10,7 +10,7 @@
#include "clang-include-cleaner/Types.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Preprocessor.h"
@@ -51,10 +51,10 @@ struct LocateExample {
}()) {}
const Decl &findDecl(llvm::StringRef SymbolName) {
- struct Visitor : RecursiveASTVisitor<Visitor> {
+ struct Visitor : ConstDynamicRecursiveASTVisitor {
llvm::StringRef NameToFind;
const NamedDecl *Out = nullptr;
- bool VisitNamedDecl(const NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
// Skip the templated decls, as they have the same name and matches in
// this file care about the outer template name.
if (auto *TD = ND->getDescribedTemplate())
diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp
index 376ad0c7875bf..b381b71ea03e5 100644
--- a/clang-tools-extra/modularize/Modularize.cpp
+++ b/clang-tools-extra/modularize/Modularize.cpp
@@ -229,7 +229,7 @@
#include "PreprocessorTracker.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
@@ -525,8 +525,7 @@ class EntityMap : public std::map<std::string, SmallVector<Entry, 2>> {
DenseMap<FileEntryRef, HeaderContents> AllHeaderContents;
};
-class CollectEntitiesVisitor
- : public RecursiveASTVisitor<CollectEntitiesVisitor> {
+class CollectEntitiesVisitor : public ConstDynamicRecursiveASTVisitor {
public:
CollectEntitiesVisitor(SourceManager &SM, EntityMap &Entities,
Preprocessor &PP, PreprocessorTracker &PPTracker,
@@ -534,30 +533,30 @@ class CollectEntitiesVisitor
: SM(SM), Entities(Entities), PP(PP), PPTracker(PPTracker),
HadErrors(HadErrors) {}
- bool TraverseStmt(Stmt *S) { return true; }
- bool TraverseType(QualType T) { return true; }
- bool TraverseTypeLoc(TypeLoc TL) { return true; }
- bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) { return true; }
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
+ bool TraverseStmt(const Stmt *S) override { return true; }
+ bool TraverseType(QualType T, bool TraverseQualifier) override { return true; }
+ bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier) override { return true; }
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier NNS) override { return true; }
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) override {
return true;
}
- bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo) {
+ bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo) override {
return true;
}
- bool TraverseTemplateName(TemplateName Template) { return true; }
- bool TraverseTemplateArgument(const TemplateArgument &Arg) { return true; }
- bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
+ bool TraverseTemplateName(TemplateName Template) override { return true; }
+ bool TraverseTemplateArgument(const TemplateArgument &Arg) override { return true; }
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) override {
return true;
}
- bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) { return true; }
- bool TraverseConstructorInitializer(CXXCtorInitializer *Init) { return true; }
- bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
- Expr *Init) {
+ bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) override { return true; }
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override { return true; }
+ bool TraverseLambdaCapture(const LambdaExpr *LE, const LambdaCapture *C,
+ const Expr *Init) override {
return true;
}
// Check 'extern "*" {}' block for #include directives.
- bool VisitLinkageSpecDecl(LinkageSpecDecl *D) {
+ bool VisitLinkageSpecDecl(const LinkageSpecDecl *D) override {
// Bail if not a block.
if (!D->hasBraces())
return true;
@@ -578,7 +577,7 @@ class CollectEntitiesVisitor
}
// Check 'namespace (name) {}' block for #include directives.
- bool VisitNamespaceDecl(const NamespaceDecl *D) {
+ bool VisitNamespaceDecl(const NamespaceDecl *D) override {
SourceRange BlockRange = D->getSourceRange();
std::string Label("namespace ");
Label += D->getName();
@@ -590,7 +589,7 @@ class CollectEntitiesVisitor
}
// Collect definition entities.
- bool VisitNamedDecl(NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
// We only care about file-context variables.
if (!ND->getDeclContext()->isFileContext())
return true;
@@ -714,45 +713,44 @@ class ModularizeFrontendActionFactory : public FrontendActionFactory {
int &HadErrors;
};
-class CompileCheckVisitor
- : public RecursiveASTVisitor<CompileCheckVisitor> {
+class CompileCheckVisitor : public ConstDynamicRecursiveASTVisitor {
public:
CompileCheckVisitor() {}
- bool TraverseStmt(Stmt *S) { return true; }
- bool TraverseType(QualType T) { return true; }
- bool TraverseTypeLoc(TypeLoc TL) { return true; }
- bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) { return true; }
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
+ bool TraverseStmt(const Stmt *S) override { return true; }
+ bool TraverseType(QualType T, bool TraverseQualifier) override { return true; }
+ bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier) override { return true; }
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier NNS) override { return true; }
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) override {
return true;
}
- bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo) {
+ bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo) override {
return true;
}
- bool TraverseTemplateName(TemplateName Template) { return true; }
- bool TraverseTemplateArgument(const TemplateArgument &Arg) { return true; }
- bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
+ bool TraverseTemplateName(TemplateName Template) override { return true; }
+ bool TraverseTemplateArgument(const TemplateArgument &Arg) override { return true; }
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) override {
return true;
}
- bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) { return true; }
- bool TraverseConstructorInitializer(CXXCtorInitializer *Init) { return true; }
- bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
- Expr *Init) {
+ bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) override { return true; }
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override { return true; }
+ bool TraverseLambdaCapture(const LambdaExpr *LE, const LambdaCapture *C,
+ const Expr *Init) override {
return true;
}
// Check 'extern "*" {}' block for #include directives.
- bool VisitLinkageSpecDecl(LinkageSpecDecl *D) {
+ bool VisitLinkageSpecDecl(const LinkageSpecDecl *D) override {
return true;
}
// Check 'namespace (name) {}' block for #include directives.
- bool VisitNamespaceDecl(const NamespaceDecl *D) {
+ bool VisitNamespaceDecl(const NamespaceDecl *D) override {
return true;
}
// Collect definition entities.
- bool VisitNamedDecl(NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
return true;
}
};
diff --git a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
index 6d5e7da689c5c..2e47333f3641d 100644
--- a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -10,14 +10,13 @@
#include "ClangDocTest.h"
#include "Representation.h"
#include "clang/AST/Comment.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "gtest/gtest.h"
namespace clang {
namespace doc {
-class ClangDocSerializeTestVisitor
- : public RecursiveASTVisitor<ClangDocSerializeTestVisitor> {
+class ClangDocSerializeTestVisitor : public ConstDynamicRecursiveASTVisitor {
EmittedInfoList &EmittedInfos;
bool Public;
@@ -45,24 +44,24 @@ class ClangDocSerializeTestVisitor
return true;
}
- bool VisitNamespaceDecl(const NamespaceDecl *D) { return mapDecl(D); }
+ bool VisitNamespaceDecl(const NamespaceDecl *D) override { return mapDecl(D); }
- bool VisitFunctionDecl(const FunctionDecl *D) {
+ bool VisitFunctionDecl(const FunctionDecl *D) override {
// Don't visit CXXMethodDecls twice
if (dyn_cast<CXXMethodDecl>(D))
return true;
return mapDecl(D);
}
- bool VisitCXXMethodDecl(const CXXMethodDecl *D) { return mapDecl(D); }
+ bool VisitCXXMethodDecl(const CXXMethodDecl *D) override { return mapDecl(D); }
- bool VisitRecordDecl(const RecordDecl *D) { return mapDecl(D); }
+ bool VisitRecordDecl(const RecordDecl *D) override { return mapDecl(D); }
- bool VisitEnumDecl(const EnumDecl *D) { return mapDecl(D); }
+ bool VisitEnumDecl(const EnumDecl *D) override { return mapDecl(D); }
- bool VisitTypedefDecl(const TypedefDecl *D) { return mapDecl(D); }
+ bool VisitTypedefDecl(const TypedefDecl *D) override { return mapDecl(D); }
- bool VisitTypeAliasDecl(const TypeAliasDecl *D) { return mapDecl(D); }
+ bool VisitTypeAliasDecl(const TypeAliasDecl *D) override { return mapDecl(D); }
};
void ExtractInfosFromCode(StringRef Code, size_t NumExpectedInfos, bool Public,
diff --git a/clang-tools-extra/unittests/clang-tidy/OverlappingReplacementsTest.cpp b/clang-tools-extra/unittests/clang-tidy/OverlappingReplacementsTest.cpp
index 3aaf5491d22c5..1d038b0f22021 100644
--- a/clang-tools-extra/unittests/clang-tidy/OverlappingReplacementsTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/OverlappingReplacementsTest.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "ClangTidyTest.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "gtest/gtest.h"
namespace clang {
@@ -83,19 +83,19 @@ class RefactorCheck : public ClangTidyCheck {
VD->getLocation()),
NewName);
- class UsageVisitor : public RecursiveASTVisitor<UsageVisitor> {
+ class UsageVisitor : public ConstDynamicRecursiveASTVisitor {
public:
UsageVisitor(const ValueDecl *VD, StringRef NewName,
DiagnosticBuilder &Diag)
: VD(VD), NewName(NewName), Diag(Diag) {}
- bool VisitDeclRefExpr(DeclRefExpr *E) {
+ bool VisitDeclRefExpr(const DeclRefExpr *E) override {
if (const ValueDecl *D = E->getDecl()) {
if (VD->getCanonicalDecl() == D->getCanonicalDecl()) {
Diag << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(E->getSourceRange()), NewName);
}
}
- return RecursiveASTVisitor<UsageVisitor>::VisitDeclRefExpr(E);
+ return ConstDynamicRecursiveASTVisitor::VisitDeclRefExpr(E);
}
private:
diff --git a/clang/include/clang/AST/DynamicRecursiveASTVisitor.h b/clang/include/clang/AST/DynamicRecursiveASTVisitor.h
index 7b5bdca318348..b752e05a75559 100644
--- a/clang/include/clang/AST/DynamicRecursiveASTVisitor.h
+++ b/clang/include/clang/AST/DynamicRecursiveASTVisitor.h
@@ -166,8 +166,7 @@ template <bool IsConst> class DynamicRecursiveASTVisitorBase {
///
/// \returns false if the visitation was terminated early, true otherwise.
// FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
- // Not virtual for now because no-one overrides it.
- bool TraverseTemplateArguments(ArrayRef<TemplateArgument> Args);
+ virtual bool TraverseTemplateArguments(ArrayRef<TemplateArgument> Args);
/// Recursively visit a template name and dispatch to the
/// appropriate method.
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index 1d1b7f183f75a..425e699c74843 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -91,6 +91,8 @@ isSameMethod([[maybe_unused]] FirstMethodPtrTy FirstMethodPtr,
/// A class that does preorder or postorder
/// depth-first traversal on the entire Clang AST and visits each node.
///
+/// Prefer to use (Const)DynamicRecursiveASTVisitor instead if possible.
+///
/// This class performs three distinct tasks:
/// 1. traverse the AST (i.e. go to each node);
/// 2. at a given node, walk up the class hierarchy, starting from
diff --git a/clang/include/clang/InstallAPI/Visitor.h b/clang/include/clang/InstallAPI/Visitor.h
index 3680ee566ca87..b86556d35309e 100644
--- a/clang/include/clang/InstallAPI/Visitor.h
+++ b/clang/include/clang/InstallAPI/Visitor.h
@@ -14,7 +14,7 @@
#define LLVM_CLANG_INSTALLAPI_VISITOR_H
#include "clang/AST/Mangle.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/InstallAPI/Context.h"
@@ -26,35 +26,37 @@ namespace installapi {
/// ASTVisitor for collecting declarations that represent global symbols.
class InstallAPIVisitor final : public ASTConsumer,
- public RecursiveASTVisitor<InstallAPIVisitor> {
+ public ConstDynamicRecursiveASTVisitor {
public:
InstallAPIVisitor(ASTContext &ASTCtx, InstallAPIContext &Ctx,
SourceManager &SrcMgr, Preprocessor &PP)
: Ctx(Ctx), SrcMgr(SrcMgr), PP(PP),
MC(ItaniumMangleContext::create(ASTCtx, ASTCtx.getDiagnostics())),
- Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {}
+ Layout(ASTCtx.getTargetInfo().getDataLayoutString()) {
+ ShouldVisitTemplateInstantiations = true;
+ }
+
void HandleTranslationUnit(ASTContext &ASTCtx) override;
- bool shouldVisitTemplateInstantiations() const { return true; }
/// Collect global variables.
- bool VisitVarDecl(const VarDecl *D);
+ bool VisitVarDecl(const VarDecl *D) override;
/// Collect global functions.
- bool VisitFunctionDecl(const FunctionDecl *D);
+ bool VisitFunctionDecl(const FunctionDecl *D) override;
/// Collect Objective-C Interface declarations.
/// Every Objective-C class has an interface declaration that lists all the
/// ivars, properties, and methods of the class.
- bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
+ bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) override;
/// Collect Objective-C Category/Extension declarations.
///
/// The class that is being extended might come from a different library and
/// is therefore itself not collected.
- bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
+ bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) override;
/// Collect global c++ declarations.
- bool VisitCXXRecordDecl(const CXXRecordDecl *D);
+ bool VisitCXXRecordDecl(const CXXRecordDecl *D) override;
private:
std::string getMangledName(const NamedDecl *D) const;
diff --git a/clang/lib/AST/ASTImporterLookupTable.cpp b/clang/lib/AST/ASTImporterLookupTable.cpp
index 29c3af1703b4f..0b10dc7793096 100644
--- a/clang/lib/AST/ASTImporterLookupTable.cpp
+++ b/clang/lib/AST/ASTImporterLookupTable.cpp
@@ -13,18 +13,23 @@
#include "clang/AST/ASTImporterLookupTable.h"
#include "clang/AST/Decl.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclFriend.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "llvm/Support/FormatVariadic.h"
namespace clang {
namespace {
-struct Builder : RecursiveASTVisitor<Builder> {
+struct Builder : DynamicRecursiveASTVisitor {
ASTImporterLookupTable <
- Builder(ASTImporterLookupTable <) : LT(LT) {}
+ Builder(ASTImporterLookupTable <) : LT(LT) {
+ ShouldVisitTemplateInstantiations = true;
+ ShouldVisitImplicitCode = true;
+ }
- bool VisitTypedefNameDecl(TypedefNameDecl *D) {
+ bool VisitTypedefNameDecl(TypedefNameDecl *D) override {
QualType Ty = D->getUnderlyingType();
Ty = Ty.getCanonicalType();
if (const auto *RTy = dyn_cast<RecordType>(Ty)) {
@@ -37,7 +42,7 @@ struct Builder : RecursiveASTVisitor<Builder> {
return true;
}
- bool VisitNamedDecl(NamedDecl *D) {
+ bool VisitNamedDecl(NamedDecl *D) override {
LT.add(D);
return true;
}
@@ -46,7 +51,7 @@ struct Builder : RecursiveASTVisitor<Builder> {
// visitation. However, there are cases when the befriended class is not a
// child, thus it must be fetched explicitly from the FriendDecl, and only
// then can we add it to the lookup table.
- bool VisitFriendDecl(FriendDecl *D) {
+ bool VisitFriendDecl(FriendDecl *D) override {
if (D->getFriendType()) {
QualType Ty = D->getFriendType()->getType();
// A FriendDecl with a dependent type (e.g. ClassTemplateSpecialization)
@@ -76,10 +81,6 @@ struct Builder : RecursiveASTVisitor<Builder> {
}
return true;
}
-
- // Override default settings of base.
- bool shouldVisitTemplateInstantiations() const { return true; }
- bool shouldVisitImplicitCode() const { return true; }
};
} // anonymous namespace
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 578d09f7971d6..5023da5abd2bb 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -27,7 +27,7 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/RecordLayout.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/VTableBuilder.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/SourceManager.h"
@@ -5697,10 +5697,9 @@ static bool ReferencesAnonymousEntity(ArrayRef<TemplateArgument> Args) {
case TemplateArgument::Pack:
return ReferencesAnonymousEntity(TA.getPackAsArray());
case TemplateArgument::Type: {
- struct ReferencesAnonymous
- : public RecursiveASTVisitor<ReferencesAnonymous> {
+ struct ReferencesAnonymous : DynamicRecursiveASTVisitor {
bool RefAnon = false;
- bool VisitRecordType(RecordType *RT) {
+ bool VisitRecordType(RecordType *RT) override {
if (ReferencesAnonymousEntity(RT)) {
RefAnon = true;
return false;
@@ -5721,17 +5720,17 @@ static bool ReferencesAnonymousEntity(ArrayRef<TemplateArgument> Args) {
});
}
namespace {
-struct ReconstitutableType : public RecursiveASTVisitor<ReconstitutableType> {
+struct ReconstitutableType : DynamicRecursiveASTVisitor {
bool Reconstitutable = true;
- bool VisitVectorType(VectorType *FT) {
+ bool VisitVectorType(VectorType *FT) override {
Reconstitutable = false;
return false;
}
- bool VisitAtomicType(AtomicType *FT) {
+ bool VisitAtomicType(AtomicType *FT) override {
Reconstitutable = false;
return false;
}
- bool VisitType(Type *T) {
+ bool VisitType(Type *T) override {
// _BitInt(N) isn't reconstitutable because the bit width isn't encoded in
// the DWARF, only the byte width.
if (T->isBitIntType()) {
@@ -5740,7 +5739,7 @@ struct ReconstitutableType : public RecursiveASTVisitor<ReconstitutableType> {
}
return true;
}
- bool TraverseEnumType(EnumType *ET, bool = false) {
+ bool TraverseEnumType(EnumType *ET, bool = false) override {
// Unnamed enums can't be reconstituted due to a lack of column info we
// produce in the DWARF, so we can't get Clang's full name back.
if (const auto *ED = dyn_cast<EnumDecl>(ET->getOriginalDecl())) {
@@ -5755,13 +5754,13 @@ struct ReconstitutableType : public RecursiveASTVisitor<ReconstitutableType> {
}
return true;
}
- bool VisitFunctionProtoType(FunctionProtoType *FT) {
+ bool VisitFunctionProtoType(FunctionProtoType *FT) override {
// noexcept is not encoded in DWARF, so the reversi
Reconstitutable &= !isNoexceptExceptionSpec(FT->getExceptionSpecType());
Reconstitutable &= !FT->getNoReturnAttr();
return Reconstitutable;
}
- bool VisitRecordType(RecordType *RT, bool = false) {
+ bool VisitRecordType(RecordType *RT) override {
if (ReferencesAnonymousEntity(RT)) {
Reconstitutable = false;
return false;
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index cf018c8c7de2a..a575b9524aa59 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -21,7 +21,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attrs.inc"
#include "clang/AST/Decl.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
@@ -874,13 +874,13 @@ llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) {
return nullptr;
}
-class OpaqueValueVisitor : public RecursiveASTVisitor<OpaqueValueVisitor> {
+class OpaqueValueVisitor : public DynamicRecursiveASTVisitor {
public:
llvm::SmallVector<OpaqueValueExpr *, 8> OVEs;
llvm::SmallPtrSet<OpaqueValueExpr *, 8> Visited;
OpaqueValueVisitor() {}
- bool VisitHLSLOutArgExpr(HLSLOutArgExpr *) {
+ bool VisitHLSLOutArgExpr(HLSLOutArgExpr *) override {
// These need to be bound in CodeGenFunction::EmitHLSLOutArgLValues
// or CodeGenFunction::EmitHLSLOutArgExpr. If they are part of this
// traversal, the temporary containing the copy out will not have
@@ -888,7 +888,7 @@ class OpaqueValueVisitor : public RecursiveASTVisitor<OpaqueValueVisitor> {
return false;
}
- bool VisitOpaqueValueExpr(OpaqueValueExpr *E) {
+ bool VisitOpaqueValueExpr(OpaqueValueExpr *E) override {
// Traverse the source expression first.
if (E->getSourceExpr())
TraverseStmt(E->getSourceExpr());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0eac7c351b164..dc7e2741c5611 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -35,7 +35,7 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Mangle.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CodeGenOptions.h"
@@ -4266,13 +4266,14 @@ namespace {
};
// Make sure we're not referencing non-imported vars or functions.
- struct DLLImportFunctionVisitor
- : public RecursiveASTVisitor<DLLImportFunctionVisitor> {
+ struct DLLImportFunctionVisitor : DynamicRecursiveASTVisitor {
bool SafeToInline = true;
- bool shouldVisitImplicitCode() const { return true; }
+ DLLImportFunctionVisitor() {
+ ShouldVisitImplicitCode = true;
+ }
- bool VisitVarDecl(VarDecl *VD) {
+ bool VisitVarDecl(VarDecl *VD) override {
if (VD->getTLSKind()) {
// A thread-local variable cannot be imported.
SafeToInline = false;
@@ -4286,13 +4287,13 @@ namespace {
return SafeToInline;
}
- bool VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+ bool VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) override {
if (const auto *D = E->getTemporary()->getDestructor())
SafeToInline = D->hasAttr<DLLImportAttr>();
return SafeToInline;
}
- bool VisitDeclRefExpr(DeclRefExpr *E) {
+ bool VisitDeclRefExpr(DeclRefExpr *E) override {
ValueDecl *VD = E->getDecl();
if (isa<FunctionDecl>(VD))
SafeToInline = VD->hasAttr<DLLImportAttr>();
@@ -4301,12 +4302,12 @@ namespace {
return SafeToInline;
}
- bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+ bool VisitCXXConstructExpr(CXXConstructExpr *E) override {
SafeToInline = E->getConstructor()->hasAttr<DLLImportAttr>();
return SafeToInline;
}
- bool VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
+ bool VisitCXXMemberCallExpr(CXXMemberCallExpr *E) override {
CXXMethodDecl *M = E->getMethodDecl();
if (!M) {
// Call through a pointer to member function. This is safe to inline.
@@ -4317,12 +4318,12 @@ namespace {
return SafeToInline;
}
- bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+ bool VisitCXXDeleteExpr(CXXDeleteExpr *E) override {
SafeToInline = E->getOperatorDelete()->hasAttr<DLLImportAttr>();
return SafeToInline;
}
- bool VisitCXXNewExpr(CXXNewExpr *E) {
+ bool VisitCXXNewExpr(CXXNewExpr *E) override {
SafeToInline = E->getOperatorNew()->hasAttr<DLLImportAttr>();
return SafeToInline;
}
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 98b30e084b18b..a90ecf91fbd0a 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -14,7 +14,7 @@
#include "CGDebugInfo.h"
#include "CodeGenFunction.h"
#include "CoverageMappingGen.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/MDBuilder.h"
@@ -156,8 +156,8 @@ static PGOHashVersion getPGOHashVersion(llvm::IndexedInstrProfReader *PGOReader,
}
/// A RecursiveASTVisitor that fills a map of statements to PGO counters.
-struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
- using Base = RecursiveASTVisitor<MapRegionCounters>;
+struct MapRegionCounters : ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
/// The next counter value to assign.
unsigned NextCounter;
@@ -184,16 +184,16 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
// Blocks and lambdas are handled as separate functions, so we need not
// traverse them in the parent context.
- bool TraverseBlockExpr(BlockExpr *BE) { return true; }
- bool TraverseLambdaExpr(LambdaExpr *LE) {
+ bool TraverseBlockExpr(const BlockExpr *BE) override { return true; }
+ bool TraverseLambdaExpr(const LambdaExpr *LE) override {
// Traverse the captures, but not the body.
for (auto C : zip(LE->captures(), LE->capture_inits()))
TraverseLambdaCapture(LE, &std::get<0>(C), std::get<1>(C));
return true;
}
- bool TraverseCapturedStmt(CapturedStmt *CS) { return true; }
+ bool TraverseCapturedStmt(const CapturedStmt *CS) override { return true; }
- bool VisitDecl(const Decl *D) {
+ bool VisitDecl(const Decl *D) override {
switch (D->getKind()) {
default:
break;
@@ -213,7 +213,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
/// If \p S gets a fresh counter, update the counter mappings. Return the
/// V1 hash of \p S.
- PGOHash::HashType updateCounterMappings(Stmt *S) {
+ PGOHash::HashType updateCounterMappings(const Stmt *S) {
auto Type = getHashType(PGO_HASH_V1, S);
if (Type != PGOHash::None)
CounterMap[S] = NextCounter++;
@@ -235,7 +235,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
SmallVector<const BinaryOperator *, 16> LogOpStack;
// Hook: dataTraverseStmtPre() is invoked prior to visiting an AST Stmt node.
- bool dataTraverseStmtPre(Stmt *S) {
+ bool dataTraverseStmtPre(const Stmt *S) override {
/// If MC/DC is not enabled, MCDCMaxCond will be set to 0. Do nothing.
if (MCDCMaxCond == 0)
return true;
@@ -275,7 +275,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
// Hook: dataTraverseStmtPost() is invoked by the AST visitor after visiting
// an AST Stmt node. MC/DC will use it to to signal when the top of a
// logical operation (boolean expression) nest is encountered.
- bool dataTraverseStmtPost(Stmt *S) {
+ bool dataTraverseStmtPost(const Stmt *S) override {
/// If MC/DC is not enabled, MCDCMaxCond will be set to 0. Do nothing.
if (MCDCMaxCond == 0)
return true;
@@ -328,7 +328,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
/// semantics of the operator. This is only valid for ">= v7" of the profile
/// version so that we facilitate backward compatibility. In addition, in
/// order to use MC/DC, count the number of total LHS and RHS conditions.
- bool VisitBinaryOperator(BinaryOperator *S) {
+ bool VisitBinaryOperator(const BinaryOperator *S) override {
if (S->isLogicalOp()) {
if (CodeGenFunction::isInstrumentedCondition(S->getLHS()))
NumCond++;
@@ -343,7 +343,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
return Base::VisitBinaryOperator(S);
}
- bool VisitConditionalOperator(ConditionalOperator *S) {
+ bool VisitConditionalOperator(const ConditionalOperator *S) override {
if (llvm::EnableSingleByteCoverage && S->getTrueExpr())
CounterMap[S->getTrueExpr()] = NextCounter++;
if (llvm::EnableSingleByteCoverage && S->getFalseExpr())
@@ -352,7 +352,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
}
/// Include \p S in the function hash.
- bool VisitStmt(Stmt *S) {
+ bool VisitStmt(const Stmt *S) override {
auto Type = updateCounterMappings(S);
if (Hash.getHashVersion() != PGO_HASH_V1)
Type = getHashType(Hash.getHashVersion(), S);
@@ -361,7 +361,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
return true;
}
- bool TraverseIfStmt(IfStmt *If) {
+ bool TraverseIfStmt(const IfStmt *If) override {
// If we used the V1 hash, use the default traversal.
if (Hash.getHashVersion() == PGO_HASH_V1)
return Base::TraverseIfStmt(If);
@@ -369,7 +369,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
// When single byte coverage mode is enabled, add a counter to then and
// else.
bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage;
- for (Stmt *CS : If->children()) {
+ for (const Stmt *CS : If->children()) {
if (!CS || NoSingleByteCoverage)
continue;
if (CS == If->getThen())
@@ -381,7 +381,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
// Otherwise, keep track of which branch we're in while traversing.
VisitStmt(If);
- for (Stmt *CS : If->children()) {
+ for (const Stmt *CS : If->children()) {
if (!CS)
continue;
if (CS == If->getThen())
@@ -394,11 +394,11 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
return true;
}
- bool TraverseWhileStmt(WhileStmt *While) {
+ bool TraverseWhileStmt(const WhileStmt *While) override {
// When single byte coverage mode is enabled, add a counter to condition and
// body.
bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage;
- for (Stmt *CS : While->children()) {
+ for (const Stmt *CS : While->children()) {
if (!CS || NoSingleByteCoverage)
continue;
if (CS == While->getCond())
@@ -413,11 +413,11 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
return true;
}
- bool TraverseDoStmt(DoStmt *Do) {
+ bool TraverseDoStmt(const DoStmt *Do) override {
// When single byte coverage mode is enabled, add a counter to condition and
// body.
bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage;
- for (Stmt *CS : Do->children()) {
+ for (const Stmt *CS : Do->children()) {
if (!CS || NoSingleByteCoverage)
continue;
if (CS == Do->getCond())
@@ -432,11 +432,11 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
return true;
}
- bool TraverseForStmt(ForStmt *For) {
+ bool TraverseForStmt(const ForStmt *For) override {
// When single byte coverage mode is enabled, add a counter to condition,
// increment and body.
bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage;
- for (Stmt *CS : For->children()) {
+ for (const Stmt *CS : For->children()) {
if (!CS || NoSingleByteCoverage)
continue;
if (CS == For->getCond())
@@ -453,10 +453,10 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
return true;
}
- bool TraverseCXXForRangeStmt(CXXForRangeStmt *ForRange) {
+ bool TraverseCXXForRangeStmt(const CXXForRangeStmt *ForRange) override {
// When single byte coverage mode is enabled, add a counter to body.
bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage;
- for (Stmt *CS : ForRange->children()) {
+ for (const Stmt *CS : ForRange->children()) {
if (!CS || NoSingleByteCoverage)
continue;
if (CS == ForRange->getBody())
@@ -473,7 +473,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
// stability, define a custom traversal which tracks the end of the statement
// in the hash (provided we're not using the V1 hash).
#define DEFINE_NESTABLE_TRAVERSAL(N) \
- bool Traverse##N(N *S) { \
+ bool Traverse##N(const N *S) override { \
Base::Traverse##N(S); \
if (Hash.getHashVersion() != PGO_HASH_V1) \
Hash.combine(PGOHash::EndOfScope); \
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index 074f2a520704d..aca58e3e74378 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
@@ -12,7 +12,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
@@ -56,7 +56,7 @@ class PCHContainerGenerator : public ASTConsumer {
std::shared_ptr<PCHBuffer> Buffer;
/// Visit every type and emit debug info for it.
- struct DebugTypeVisitor : public RecursiveASTVisitor<DebugTypeVisitor> {
+ struct DebugTypeVisitor : DynamicRecursiveASTVisitor{
clang::CodeGen::CGDebugInfo &DI;
ASTContext &Ctx;
DebugTypeVisitor(clang::CodeGen::CGDebugInfo &DI, ASTContext &Ctx)
@@ -67,13 +67,13 @@ class PCHContainerGenerator : public ASTConsumer {
return !Ty->isDependentType() && !Ty->isUndeducedType();
}
- bool VisitImportDecl(ImportDecl *D) {
+ bool VisitImportDecl(ImportDecl *D) override {
if (!D->getImportedOwningModule())
DI.EmitImportDecl(*D);
return true;
}
- bool VisitTypeDecl(TypeDecl *D) {
+ bool VisitTypeDecl(TypeDecl *D) override {
// TagDecls may be deferred until after all decls have been merged and we
// know the complete type. Pure forward declarations will be skipped, but
// they don't need to be emitted into the module anyway.
@@ -90,14 +90,14 @@ class PCHContainerGenerator : public ASTConsumer {
return true;
}
- bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
+ bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) override {
QualType QualTy(D->getTypeForDecl(), 0);
if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
DI.getOrCreateStandaloneType(QualTy, D->getLocation());
return true;
}
- bool VisitFunctionDecl(FunctionDecl *D) {
+ bool VisitFunctionDecl(FunctionDecl *D) override {
// Skip deduction guides.
if (isa<CXXDeductionGuideDecl>(D))
return true;
@@ -118,7 +118,7 @@ class PCHContainerGenerator : public ASTConsumer {
return true;
}
- bool VisitObjCMethodDecl(ObjCMethodDecl *D) {
+ bool VisitObjCMethodDecl(ObjCMethodDecl *D) override {
if (!D->getClassInterface())
return true;
diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp
index 67c8761511e0c..401b34bb9c3e1 100644
--- a/clang/lib/Frontend/ASTConsumers.cpp
+++ b/clang/lib/Frontend/ASTConsumers.cpp
@@ -13,9 +13,10 @@
#include "clang/Frontend/ASTConsumers.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclObjC.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/RecordLayout.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
@@ -26,8 +27,8 @@ using namespace clang;
namespace {
class ASTPrinter : public ASTConsumer,
- public RecursiveASTVisitor<ASTPrinter> {
- typedef RecursiveASTVisitor<ASTPrinter> base;
+ public DynamicRecursiveASTVisitor {
+ using base = DynamicRecursiveASTVisitor;
public:
enum Kind { DumpFull, Dump, Print, None };
@@ -36,14 +37,18 @@ namespace {
bool DumpLookups = false, bool DumpDeclTypes = false)
: Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)),
OutputKind(K), OutputFormat(Format), FilterString(FilterString),
- DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {}
+ DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
ASTPrinter(raw_ostream &Out, Kind K, ASTDumpOutputFormat Format,
StringRef FilterString, bool DumpLookups = false,
bool DumpDeclTypes = false)
: Out(Out), OwnedOut(nullptr), OutputKind(K), OutputFormat(Format),
FilterString(FilterString), DumpLookups(DumpLookups),
- DumpDeclTypes(DumpDeclTypes) {}
+ DumpDeclTypes(DumpDeclTypes) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
void HandleTranslationUnit(ASTContext &Context) override {
TranslationUnitDecl *D = Context.getTranslationUnitDecl();
@@ -54,9 +59,7 @@ namespace {
TraverseDecl(D);
}
- bool shouldWalkTypesOfTypeLocs() const { return false; }
-
- bool TraverseDecl(Decl *D) {
+ bool TraverseDecl(Decl *D) override {
if (D && filterMatches(D)) {
bool ShowColors = Out.has_colors();
if (ShowColors)
@@ -142,18 +145,18 @@ namespace {
};
class ASTDeclNodeLister : public ASTConsumer,
- public RecursiveASTVisitor<ASTDeclNodeLister> {
+ public DynamicRecursiveASTVisitor {
public:
ASTDeclNodeLister(raw_ostream *Out = nullptr)
- : Out(Out ? *Out : llvm::outs()) {}
+ : Out(Out ? *Out : llvm::outs()) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
void HandleTranslationUnit(ASTContext &Context) override {
TraverseDecl(Context.getTranslationUnitDecl());
}
- bool shouldWalkTypesOfTypeLocs() const { return false; }
-
- bool VisitNamedDecl(NamedDecl *D) {
+ bool VisitNamedDecl(NamedDecl *D) override {
D->printQualifiedName(Out);
Out << '\n';
return true;
diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index d7cfd23bb0a7a..83f880093e3ba 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/Mangle.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
@@ -242,8 +242,8 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
: Instance(Instance), InFile(InFile), Format(Format) {}
void HandleTranslationUnit(ASTContext &context) override {
- struct Visitor : public RecursiveASTVisitor<Visitor> {
- bool VisitNamedDecl(NamedDecl *ND) {
+ struct Visitor : ConstDynamicRecursiveASTVisitor {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
if (const auto *FD = dyn_cast<FunctionDecl>(ND))
if (FD->isLateTemplateParsed()) {
LateParsedDecls.insert(FD);
@@ -260,7 +260,7 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
}
std::set<const NamedDecl *> LateParsedDecls;
- std::set<NamedDecl *> NamedDecls;
+ std::set<const NamedDecl *> NamedDecls;
std::set<const ValueDecl *> ValueDecls;
} v;
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 1979117d4695c..2ec9222eb8e82 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -10,8 +10,11 @@
#include "clang/AST/ASTConcept.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprConcepts.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/ExprObjC.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/Sema/HeuristicResolver.h"
@@ -20,41 +23,39 @@ using namespace clang::index;
namespace {
-class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
+class BodyIndexer : public DynamicRecursiveASTVisitor {
IndexingContext &IndexCtx;
const NamedDecl *Parent;
const DeclContext *ParentDC;
SmallVector<Stmt*, 16> StmtStack;
- typedef RecursiveASTVisitor<BodyIndexer> base;
-
Stmt *getParentStmt() const {
return StmtStack.size() < 2 ? nullptr : StmtStack.end()[-2];
}
public:
BodyIndexer(IndexingContext &indexCtx,
const NamedDecl *Parent, const DeclContext *DC)
- : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { }
-
- bool shouldWalkTypesOfTypeLocs() const { return false; }
+ : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
- bool dataTraverseStmtPre(Stmt *S) {
+ bool dataTraverseStmtPre(Stmt *S) override {
StmtStack.push_back(S);
return true;
}
- bool dataTraverseStmtPost(Stmt *S) {
+ bool dataTraverseStmtPost(Stmt *S) override {
assert(StmtStack.back() == S);
StmtStack.pop_back();
return true;
}
- bool TraverseTypeLoc(TypeLoc TL) {
+ bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier) override {
IndexCtx.indexTypeLoc(TL, Parent, ParentDC);
return true;
}
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) override {
IndexCtx.indexNestedNameSpecifierLoc(NNS, Parent, ParentDC);
return true;
}
@@ -141,39 +142,39 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
Relations.emplace_back((unsigned)SymbolRole::RelationCalledBy, MD);
}
- bool VisitDeclRefExpr(DeclRefExpr *E) {
+ bool VisitDeclRefExpr(DeclRefExpr *E) override {
SmallVector<SymbolRelation, 4> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
return IndexCtx.handleReference(E->getDecl(), E->getLocation(),
Parent, ParentDC, Roles, Relations, E);
}
- bool VisitGotoStmt(GotoStmt *S) {
+ bool VisitGotoStmt(GotoStmt *S) override {
return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
ParentDC);
}
- bool VisitCXXNewExpr(CXXNewExpr *E) {
+ bool VisitCXXNewExpr(CXXNewExpr *E) override {
if (E->isGlobalNew() || !E->getOperatorNew())
return true;
return IndexCtx.handleReference(E->getOperatorNew(), E->getBeginLoc(),
Parent, ParentDC);
}
- bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+ bool VisitCXXDeleteExpr(CXXDeleteExpr *E) override {
if (E->isGlobalDelete() || !E->getOperatorDelete())
return true;
return IndexCtx.handleReference(E->getOperatorDelete(), E->getBeginLoc(),
Parent, ParentDC);
}
- bool VisitLabelStmt(LabelStmt *S) {
+ bool VisitLabelStmt(LabelStmt *S) override {
if (IndexCtx.shouldIndexFunctionLocalSymbols())
return IndexCtx.handleDecl(S->getDecl());
return true;
}
- bool VisitMemberExpr(MemberExpr *E) {
+ bool VisitMemberExpr(MemberExpr *E) override {
SourceLocation Loc = E->getMemberLoc();
if (Loc.isInvalid())
Loc = E->getBeginLoc();
@@ -196,21 +197,21 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
Roles, Relations, E);
}
- bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+ bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) override {
auto *Resolver = IndexCtx.getResolver();
assert(Resolver);
return indexDependentReference(E, E->getMemberNameInfo().getLoc(),
Resolver->resolveMemberExpr(E));
}
- bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
+ bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) override {
auto *Resolver = IndexCtx.getResolver();
assert(Resolver);
return indexDependentReference(E, E->getNameInfo().getLoc(),
Resolver->resolveDeclRefExpr(E));
}
- bool VisitDesignatedInitExpr(DesignatedInitExpr *E) {
+ bool VisitDesignatedInitExpr(DesignatedInitExpr *E) override {
for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) {
if (D.isFieldDesignator()) {
if (const FieldDecl *FD = D.getFieldDecl()) {
@@ -222,14 +223,14 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
return true;
}
- bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
+ bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) override {
SmallVector<SymbolRelation, 4> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
return IndexCtx.handleReference(E->getDecl(), E->getLocation(),
Parent, ParentDC, Roles, Relations, E);
}
- bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
+ bool VisitObjCMessageExpr(ObjCMessageExpr *E) override {
auto isDynamic = [](const ObjCMessageExpr *MsgE)->bool {
if (MsgE->getReceiverKind() != ObjCMessageExpr::Instance)
return false;
@@ -301,7 +302,7 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
return true;
}
- bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
+ bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) override {
if (E->isExplicitProperty()) {
SmallVector<SymbolRelation, 2> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
@@ -326,12 +327,12 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
return true;
}
- bool VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
+ bool VisitMSPropertyRefExpr(MSPropertyRefExpr *E) override {
return IndexCtx.handleReference(E->getPropertyDecl(), E->getMemberLoc(),
Parent, ParentDC, SymbolRoleSet(), {}, E);
}
- bool VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
+ bool VisitObjCProtocolExpr(ObjCProtocolExpr *E) override {
return IndexCtx.handleReference(E->getProtocol(), E->getProtocolIdLoc(),
Parent, ParentDC, SymbolRoleSet(), {}, E);
}
@@ -345,28 +346,28 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
Roles, Relations, E);
}
- bool VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
+ bool VisitObjCBoxedExpr(ObjCBoxedExpr *E) override {
if (ObjCMethodDecl *MD = E->getBoxingMethod()) {
return passObjCLiteralMethodCall(MD, E);
}
return true;
}
- bool VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
+ bool VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) override {
if (ObjCMethodDecl *MD = E->getDictWithObjectsMethod()) {
return passObjCLiteralMethodCall(MD, E);
}
return true;
}
- bool VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
+ bool VisitObjCArrayLiteral(ObjCArrayLiteral *E) override {
if (ObjCMethodDecl *MD = E->getArrayWithObjectsMethod()) {
return passObjCLiteralMethodCall(MD, E);
}
return true;
}
- bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+ bool VisitCXXConstructExpr(CXXConstructExpr *E) override {
SymbolRoleSet Roles{};
SmallVector<SymbolRelation, 2> Relations;
addCallRole(Roles, Relations);
@@ -374,14 +375,13 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
Parent, ParentDC, Roles, Relations, E);
}
- bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *E,
- DataRecursionQueue *Q = nullptr) {
+ bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *E) override {
if (E->getOperatorLoc().isInvalid())
return true; // implicit.
- return base::TraverseCXXOperatorCallExpr(E, Q);
+ return DynamicRecursiveASTVisitor::TraverseCXXOperatorCallExpr(E);
}
- bool VisitDeclStmt(DeclStmt *S) {
+ bool VisitDeclStmt(DeclStmt *S) override {
if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
IndexCtx.indexDeclGroupRef(S->getDeclGroup());
return true;
@@ -400,11 +400,11 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
}
bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
- Expr *Init) {
+ Expr *Init) override {
if (C->capturesThis() || C->capturesVLAType())
return true;
- if (!base::TraverseStmt(Init))
+ if (!DynamicRecursiveASTVisitor::TraverseStmt(Init))
return false;
if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols())
@@ -418,10 +418,10 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
// the things that we visit. Make sure to only visit the semantic form.
// Also visit things that are in the syntactic form but not the semantic one,
// for example the indices in DesignatedInitExprs.
- bool TraverseInitListExpr(InitListExpr *S, DataRecursionQueue *Q = nullptr) {
+ bool TraverseInitListExpr(InitListExpr *S) override {
auto visitForm = [&](InitListExpr *Form) {
for (Stmt *SubStmt : Form->children()) {
- if (!TraverseStmt(SubStmt, Q))
+ if (!TraverseStmt(SubStmt))
return false;
}
return true;
@@ -469,7 +469,7 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
return true;
}
- bool VisitOffsetOfExpr(OffsetOfExpr *S) {
+ bool VisitOffsetOfExpr(OffsetOfExpr *S) override {
for (unsigned I = 0, E = S->getNumComponents(); I != E; ++I) {
const OffsetOfNode &Component = S->getComponent(I);
if (Component.getKind() == OffsetOfNode::Field)
@@ -480,7 +480,7 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
return true;
}
- bool VisitParmVarDecl(ParmVarDecl* D) {
+ bool VisitParmVarDecl(ParmVarDecl* D) override {
// Index the parameters of lambda expression and requires expression.
if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
const auto *DC = D->getDeclContext();
@@ -490,7 +490,7 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
return true;
}
- bool VisitOverloadExpr(OverloadExpr *E) {
+ bool VisitOverloadExpr(OverloadExpr *E) override {
SmallVector<SymbolRelation, 4> Relations;
SymbolRoleSet Roles = getRolesForRef(E, Relations);
for (auto *D : E->decls())
@@ -499,16 +499,16 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
return true;
}
- bool VisitConceptSpecializationExpr(ConceptSpecializationExpr *R) {
+ bool VisitConceptSpecializationExpr(ConceptSpecializationExpr *R) override {
IndexCtx.handleReference(R->getNamedConcept(), R->getConceptNameLoc(),
Parent, ParentDC);
return true;
}
- bool TraverseTypeConstraint(const TypeConstraint *C) {
+ bool TraverseTypeConstraint(const TypeConstraint *C) override {
IndexCtx.handleReference(C->getNamedConcept(), C->getConceptNameLoc(),
Parent, ParentDC);
- return RecursiveASTVisitor::TraverseTypeConstraint(C);
+ return DynamicRecursiveASTVisitor::TraverseTypeConstraint(C);
}
};
diff --git a/clang/lib/Index/IndexTypeSourceInfo.cpp b/clang/lib/Index/IndexTypeSourceInfo.cpp
index 74c6c116b274e..b8270b108a91d 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -9,7 +9,8 @@
#include "IndexingContext.h"
#include "clang/AST/ASTConcept.h"
#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/DeclObjC.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Sema/HeuristicResolver.h"
#include "llvm/ADT/ScopeExit.h"
@@ -19,19 +20,19 @@ using namespace index;
namespace {
-class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
+class TypeIndexer : public DynamicRecursiveASTVisitor {
IndexingContext &IndexCtx;
const NamedDecl *Parent;
const DeclContext *ParentDC;
bool IsBase;
SmallVector<SymbolRelation, 3> Relations;
- typedef RecursiveASTVisitor<TypeIndexer> base;
-
public:
TypeIndexer(IndexingContext &indexCtx, const NamedDecl *parent,
const DeclContext *DC, bool isBase, bool isIBType)
: IndexCtx(indexCtx), Parent(parent), ParentDC(DC), IsBase(isBase) {
+ ShouldWalkTypesOfTypeLocs = false;
+
if (IsBase) {
assert(Parent);
Relations.emplace_back((unsigned)SymbolRole::RelationBaseOf, Parent);
@@ -42,22 +43,20 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
}
}
- bool shouldWalkTypesOfTypeLocs() const { return false; }
-
#define TRY_TO(CALL_EXPR) \
do { \
if (!CALL_EXPR) \
return false; \
} while (0)
- bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TTPL) {
+ bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TTPL) override {
SourceLocation Loc = TTPL.getNameLoc();
TemplateTypeParmDecl *TTPD = TTPL.getDecl();
return IndexCtx.handleReference(TTPD, Loc, Parent, ParentDC,
SymbolRoleSet());
}
- bool VisitTypedefTypeLoc(TypedefTypeLoc TL) {
+ bool VisitTypedefTypeLoc(TypedefTypeLoc TL) override {
SourceLocation Loc = TL.getNameLoc();
TypedefNameDecl *ND = TL.getDecl();
if (ND->isTransparentTag()) {
@@ -81,7 +80,7 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
return true;
}
- bool VisitAutoTypeLoc(AutoTypeLoc TL) {
+ bool VisitAutoTypeLoc(AutoTypeLoc TL) override {
if (auto *C = TL.getNamedConcept())
return IndexCtx.handleReference(C, TL.getConceptNameLoc(), Parent,
ParentDC);
@@ -95,7 +94,7 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
return true;
}
- bool TraverseParmVarDecl(ParmVarDecl *D) {
+ bool TraverseParmVarDecl(ParmVarDecl *D) override {
// Avoid visiting default arguments from the definition that were already
// visited in the declaration.
// FIXME: A free function definition can have default arguments.
@@ -108,15 +107,15 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
}
}
- return base::TraverseParmVarDecl(D);
+ return DynamicRecursiveASTVisitor::TraverseParmVarDecl(D);
}
- bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) override {
IndexCtx.indexNestedNameSpecifierLoc(NNS, Parent, ParentDC);
return true;
}
- bool VisitTagTypeLoc(TagTypeLoc TL) {
+ bool VisitTagTypeLoc(TagTypeLoc TL) override {
TagDecl *D = TL.getOriginalDecl();
if (!IndexCtx.shouldIndexFunctionLocalSymbols() &&
D->getParentFunctionOrMethod())
@@ -132,12 +131,12 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
Relations);
}
- bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
+ bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) override {
return IndexCtx.handleReference(TL.getIFaceDecl(), TL.getNameLoc(),
Parent, ParentDC, SymbolRoleSet(), Relations);
}
- bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
+ bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) override {
for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) {
IndexCtx.handleReference(TL.getProtocol(i), TL.getProtocolLoc(i),
Parent, ParentDC, SymbolRoleSet(), Relations);
@@ -162,7 +161,7 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
}
}
- bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
+ bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) override {
auto *T = TL.getTypePtr();
if (!T)
return true;
@@ -173,7 +172,7 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
}
bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL,
- bool TraverseQualifier) {
+ bool TraverseQualifier) override {
if (!WalkUpFromTemplateSpecializationTypeLoc(TL))
return false;
if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName()))
@@ -193,7 +192,7 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
return true;
}
- bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) {
+ bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) override {
auto *T = TL.getTypePtr();
if (!T)
return true;
@@ -203,7 +202,7 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
return true;
}
- bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
+ bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) override {
std::vector<const NamedDecl *> Symbols =
IndexCtx.getResolver()->resolveDependentNameType(TL.getTypePtr());
if (Symbols.size() != 1)
@@ -212,7 +211,7 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
ParentDC, SymbolRoleSet(), Relations);
}
- bool TraverseStmt(Stmt *S) {
+ bool TraverseStmt(Stmt *S) override {
IndexCtx.indexBody(S, Parent, ParentDC);
return true;
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
index d8539eaaac49f..91f7d215965a1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
@@ -11,7 +11,7 @@
#include "PtrTypesSemantics.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
@@ -44,54 +44,53 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
// The calls to checkAST* from AnalysisConsumer don't
// visit template instantiations or lambda classes. We
// want to visit those, so we make our own RecursiveASTVisitor.
- struct LocalVisitor : public RecursiveASTVisitor<LocalVisitor> {
- using Base = RecursiveASTVisitor<LocalVisitor>;
+ struct LocalVisitor : ConstDynamicRecursiveASTVisitor {
+ using Base = ConstDynamicRecursiveASTVisitor;
const ForwardDeclChecker *Checker;
- Decl *DeclWithIssue{nullptr};
+ const Decl *DeclWithIssue{nullptr};
explicit LocalVisitor(const ForwardDeclChecker *Checker)
: Checker(Checker) {
assert(Checker);
+ ShouldVisitTemplateInstantiations = true;
+ ShouldVisitImplicitCode = false;
}
- bool shouldVisitTemplateInstantiations() const { return true; }
- bool shouldVisitImplicitCode() const { return false; }
-
- bool VisitTypedefDecl(TypedefDecl *TD) {
+ bool VisitTypedefDecl(const TypedefDecl *TD) override {
Checker->visitTypedef(TD);
return true;
}
- bool VisitRecordDecl(const RecordDecl *RD) {
+ bool VisitRecordDecl(const RecordDecl *RD) override {
Checker->visitRecordDecl(RD, DeclWithIssue);
return true;
}
- bool TraverseDecl(Decl *D) {
+ bool TraverseDecl(const Decl *D) override {
llvm::SaveAndRestore SavedDecl(DeclWithIssue);
if (D && (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)))
DeclWithIssue = D;
return Base::TraverseDecl(D);
}
- bool VisitVarDecl(VarDecl *V) {
+ bool VisitVarDecl(const VarDecl *V) override {
if (V->isLocalVarDecl())
Checker->visitVarDecl(V, DeclWithIssue);
return true;
}
- bool VisitCallExpr(const CallExpr *CE) {
+ bool VisitCallExpr(const CallExpr *CE) override {
Checker->visitCallExpr(CE, DeclWithIssue);
return true;
}
- bool VisitCXXConstructExpr(const CXXConstructExpr *CE) {
+ bool VisitCXXConstructExpr(const CXXConstructExpr *CE) override {
Checker->visitConstructExpr(CE, DeclWithIssue);
return true;
}
- bool VisitObjCMessageExpr(const ObjCMessageExpr *ObjCMsgExpr) {
+ bool VisitObjCMessageExpr(const ObjCMessageExpr *ObjCMsgExpr) override {
Checker->visitObjCMessageExpr(ObjCMsgExpr, DeclWithIssue);
return true;
}
@@ -99,7 +98,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
LocalVisitor visitor(this);
RTC.visitTranslationUnitDecl(TUD);
- visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
+ visitor.TraverseDecl(TUD);
}
void visitTypedef(const TypedefDecl *TD) const {
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
index e1f9a77f5a5ca..a71f810516905 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
@@ -8,7 +8,7 @@
#include "ASTUtils.h"
#include "PtrTypesSemantics.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Analysis/RetainSummaryManager.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
@@ -45,64 +45,63 @@ class RetainPtrCtorAdoptChecker
// The calls to checkAST* from AnalysisConsumer don't
// visit template instantiations or lambda classes. We
// want to visit those, so we make our own RecursiveASTVisitor.
- struct LocalVisitor : public RecursiveASTVisitor<LocalVisitor> {
+ struct LocalVisitor : ConstDynamicRecursiveASTVisitor {
const RetainPtrCtorAdoptChecker *Checker;
- Decl *DeclWithIssue{nullptr};
+ const Decl *DeclWithIssue{nullptr};
- using Base = RecursiveASTVisitor<LocalVisitor>;
+ using Base = ConstDynamicRecursiveASTVisitor;
explicit LocalVisitor(const RetainPtrCtorAdoptChecker *Checker)
: Checker(Checker) {
assert(Checker);
+ ShouldVisitTemplateInstantiations = true;
+ ShouldVisitImplicitCode = false;
}
- bool shouldVisitTemplateInstantiations() const { return true; }
- bool shouldVisitImplicitCode() const { return false; }
-
- bool TraverseDecl(Decl *D) {
+ bool TraverseDecl(const Decl *D) override {
llvm::SaveAndRestore SavedDecl(DeclWithIssue);
if (D && (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)))
DeclWithIssue = D;
return Base::TraverseDecl(D);
}
- bool TraverseClassTemplateDecl(ClassTemplateDecl *CTD) {
+ bool TraverseClassTemplateDecl(const ClassTemplateDecl *CTD) override {
if (isRetainPtrOrOSPtr(safeGetName(CTD)))
return true; // Skip the contents of RetainPtr.
return Base::TraverseClassTemplateDecl(CTD);
}
- bool VisitTypedefDecl(TypedefDecl *TD) {
+ bool VisitTypedefDecl(const TypedefDecl *TD) override {
Checker->RTC.visitTypedef(TD);
return true;
}
- bool VisitCallExpr(const CallExpr *CE) {
+ bool VisitCallExpr(const CallExpr *CE) override {
Checker->visitCallExpr(CE, DeclWithIssue);
return true;
}
- bool VisitCXXConstructExpr(const CXXConstructExpr *CE) {
+ bool VisitCXXConstructExpr(const CXXConstructExpr *CE) override {
Checker->visitConstructExpr(CE, DeclWithIssue);
return true;
}
- bool VisitObjCMessageExpr(const ObjCMessageExpr *ObjCMsgExpr) {
+ bool VisitObjCMessageExpr(const ObjCMessageExpr *ObjCMsgExpr) override {
Checker->visitObjCMessageExpr(ObjCMsgExpr, DeclWithIssue);
return true;
}
- bool VisitReturnStmt(const ReturnStmt *RS) {
+ bool VisitReturnStmt(const ReturnStmt *RS) override {
Checker->visitReturnStmt(RS, DeclWithIssue);
return true;
}
- bool VisitVarDecl(const VarDecl *VD) {
+ bool VisitVarDecl(const VarDecl *VD) override {
Checker->visitVarDecl(VD);
return true;
}
- bool VisitBinaryOperator(const BinaryOperator *BO) {
+ bool VisitBinaryOperator(const BinaryOperator *BO) override {
Checker->visitBinaryOperator(BO);
return true;
}
@@ -113,7 +112,7 @@ class RetainPtrCtorAdoptChecker
TUD->getASTContext(), true /* trackObjCAndCFObjects */,
false /* trackOSObjects */);
RTC.visitTranslationUnitDecl(TUD);
- visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
+ visitor.TraverseDecl(TUD);
}
bool isAdoptFn(const Decl *FnDecl) const {
diff --git a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
index d70a679cc8dd0..6c9139acc982e 100644
--- a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -12,8 +12,9 @@
#include "clang/Tooling/ASTDiff/ASTDiff.h"
#include "clang/AST/ParentMapContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/AST/ExprCXX.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/PriorityQueue.h"
@@ -186,7 +187,7 @@ static bool isNodeExcluded(const SourceManager &SrcMgr, T *N) {
namespace {
// Sets Height, Parent and Children for each node.
-struct PreorderVisitor : public RecursiveASTVisitor<PreorderVisitor> {
+struct PreorderVisitor : DynamicRecursiveASTVisitor {
int Id = 0, Depth = 0;
NodeId Parent;
SyntaxTree::Impl &Tree;
@@ -228,30 +229,30 @@ struct PreorderVisitor : public RecursiveASTVisitor<PreorderVisitor> {
for (NodeId Child : N.Children)
N.Height = std::max(N.Height, 1 + Tree.getNode(Child).Height);
}
- bool TraverseDecl(Decl *D) {
+ bool TraverseDecl(Decl *D) override {
if (isNodeExcluded(Tree.AST.getSourceManager(), D))
return true;
auto SavedState = PreTraverse(D);
- RecursiveASTVisitor<PreorderVisitor>::TraverseDecl(D);
+ DynamicRecursiveASTVisitor::TraverseDecl(D);
PostTraverse(SavedState);
return true;
}
- bool TraverseStmt(Stmt *S) {
+ bool TraverseStmt(Stmt *S) override {
if (auto *E = dyn_cast_or_null<Expr>(S))
S = E->IgnoreImplicit();
if (isNodeExcluded(Tree.AST.getSourceManager(), S))
return true;
auto SavedState = PreTraverse(S);
- RecursiveASTVisitor<PreorderVisitor>::TraverseStmt(S);
+ DynamicRecursiveASTVisitor::TraverseStmt(S);
PostTraverse(SavedState);
return true;
}
- bool TraverseType(QualType T, bool TraverseQualifier = true) { return true; }
- bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
+ bool TraverseType(QualType T, bool TraverseQualifier = true) override { return true; }
+ bool TraverseConstructorInitializer(CXXCtorInitializer *Init) override {
if (isNodeExcluded(Tree.AST.getSourceManager(), Init))
return true;
auto SavedState = PreTraverse(Init);
- RecursiveASTVisitor<PreorderVisitor>::TraverseConstructorInitializer(Init);
+ DynamicRecursiveASTVisitor::TraverseConstructorInitializer(Init);
PostTraverse(SavedState);
return true;
}
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp
index 91d5cafda4f7a..68677f5c05857 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRFinder.cpp
@@ -13,7 +13,7 @@
#include "clang/Tooling/Refactoring/Rename/USRFinder.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Index/USRGeneration.h"
#include "clang/Lex/Lexer.h"
@@ -96,14 +96,12 @@ namespace {
/// Recursively visits each NamedDecl node to find the declaration with a
/// specific name.
-class NamedDeclFindingVisitor
- : public RecursiveASTVisitor<NamedDeclFindingVisitor> {
-public:
+struct NamedDeclFindingVisitor : ConstDynamicRecursiveASTVisitor {
explicit NamedDeclFindingVisitor(StringRef Name) : Name(Name) {}
// We don't have to traverse the uses to find some declaration with a
// specific name, so just visit the named declarations.
- bool VisitNamedDecl(const NamedDecl *ND) {
+ bool VisitNamedDecl(const NamedDecl *ND) override {
if (!ND)
return true;
// Fully qualified name is used to find the declaration.
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
index 07ef58079189e..55b4e34ecfe47 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -16,7 +16,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Lexer.h"
#include "clang/Tooling/Refactoring/Rename/USRFinder.h"
@@ -53,10 +53,11 @@ namespace {
// AdditionalUSRFinder. AdditionalUSRFinder adds USRs of ctor and dtor if given
// Decl refers to class and adds USRs of all overridden methods if Decl refers
// to virtual method.
-class AdditionalUSRFinder : public RecursiveASTVisitor<AdditionalUSRFinder> {
-public:
+struct AdditionalUSRFinder : ConstDynamicRecursiveASTVisitor {
AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context)
- : FoundDecl(FoundDecl), Context(Context) {}
+ : FoundDecl(FoundDecl), Context(Context) {
+ ShouldVisitTemplateInstantiations = true;
+ }
std::vector<std::string> Find() {
// Fill OverriddenMethods and PartialSpecs storages.
@@ -95,9 +96,7 @@ class AdditionalUSRFinder : public RecursiveASTVisitor<AdditionalUSRFinder> {
return std::vector<std::string>(USRSet.begin(), USRSet.end());
}
- bool shouldVisitTemplateInstantiations() const { return true; }
-
- bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) {
+ bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) override {
if (MethodDecl->isVirtual())
OverriddenMethods.push_back(MethodDecl);
if (MethodDecl->getInstantiatedFromMemberFunction())
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
index c9108fc299cc1..220691ca60a9d 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -16,7 +16,7 @@
#include "clang/Tooling/Refactoring/Rename/USRLocFinder.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ParentMapContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
@@ -184,8 +184,7 @@ NestedNameSpecifier GetNestedNameForType(TypeLoc TL) {
//
// This class will traverse the AST and find every AST node whose USR is in the
// given USRs' set.
-class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
-public:
+struct RenameLocFinder : ConstDynamicRecursiveASTVisitor {
RenameLocFinder(llvm::ArrayRef<std::string> USRs, ASTContext &Context)
: USRSet(USRs.begin(), USRs.end()), Context(Context) {}
@@ -210,7 +209,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
bool IgnorePrefixQualifiers;
};
- bool VisitNamedDecl(const NamedDecl *Decl) {
+ bool VisitNamedDecl(const NamedDecl *Decl) override {
// UsingDecl has been handled in other place.
if (llvm::isa<UsingDecl>(Decl))
return true;
@@ -243,7 +242,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
return true;
}
- bool VisitMemberExpr(const MemberExpr *Expr) {
+ bool VisitMemberExpr(const MemberExpr *Expr) override {
const NamedDecl *Decl = Expr->getFoundDecl();
auto StartLoc = Expr->getMemberLoc();
auto EndLoc = Expr->getMemberLoc();
@@ -257,7 +256,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
return true;
}
- bool VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
+ bool VisitDesignatedInitExpr(const DesignatedInitExpr *E) override {
for (const DesignatedInitExpr::Designator &D : E->designators()) {
if (D.isFieldDesignator()) {
if (const FieldDecl *Decl = D.getFieldDecl()) {
@@ -276,7 +275,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
return true;
}
- bool VisitCXXConstructorDecl(const CXXConstructorDecl *CD) {
+ bool VisitCXXConstructorDecl(const CXXConstructorDecl *CD) override {
// Fix the constructor initializer when renaming class members.
for (const auto *Initializer : CD->inits()) {
// Ignore implicit initializers.
@@ -297,7 +296,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
return true;
}
- bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
+ bool VisitDeclRefExpr(const DeclRefExpr *Expr) override {
const NamedDecl *Decl = Expr->getFoundDecl();
// Get the underlying declaration of the shadow declaration introduced by a
// using declaration.
@@ -371,7 +370,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
return true;
}
- bool VisitUsingDecl(const UsingDecl *Using) {
+ bool VisitUsingDecl(const UsingDecl *Using) override {
for (const auto *UsingShadow : Using->shadows()) {
if (isInUSRSet(UsingShadow->getTargetDecl())) {
UsingDecls.push_back(Using);
@@ -381,7 +380,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
return true;
}
- bool VisitNestedNameSpecifierLocations(NestedNameSpecifierLoc NestedLoc) {
+ bool visitNestedNameSpecifierLocations(NestedNameSpecifierLoc NestedLoc) {
TypeLoc TL = NestedLoc.getAsTypeLoc();
if (!TL)
return true;
@@ -400,7 +399,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
return true;
}
- bool VisitTypeLoc(TypeLoc Loc) {
+ bool VisitTypeLoc(TypeLoc Loc) override {
auto Parents = Context.getParents(Loc);
TypeLoc ParentTypeLoc;
if (!Parents.empty()) {
@@ -409,7 +408,7 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
// The VisitNestedNameSpecifierLoc interface is not impelmented in
// RecursiveASTVisitor, we have to handle it explicitly.
if (const auto *NSL = Parents[0].get<NestedNameSpecifierLoc>()) {
- VisitNestedNameSpecifierLocations(*NSL);
+ visitNestedNameSpecifierLocations(*NSL);
return true;
}
diff --git a/clang/unittests/AST/RecursiveASTVisitorTest.cpp b/clang/unittests/AST/RecursiveASTVisitorTest.cpp
index c5ad29a77d211..303aeffb2fc7b 100644
--- a/clang/unittests/AST/RecursiveASTVisitorTest.cpp
+++ b/clang/unittests/AST/RecursiveASTVisitorTest.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
@@ -68,61 +68,60 @@ enum class VisitEvent {
EndTraverseObjCProtocolLoc,
};
-class CollectInterestingEvents
- : public RecursiveASTVisitor<CollectInterestingEvents> {
+class CollectInterestingEvents : public DynamicRecursiveASTVisitor {
public:
- bool TraverseFunctionDecl(FunctionDecl *D) {
+ bool TraverseFunctionDecl(FunctionDecl *D) override {
Events.push_back(VisitEvent::StartTraverseFunction);
- bool Ret = RecursiveASTVisitor::TraverseFunctionDecl(D);
+ bool Ret = DynamicRecursiveASTVisitor::TraverseFunctionDecl(D);
Events.push_back(VisitEvent::EndTraverseFunction);
return Ret;
}
- bool TraverseAttr(Attr *A) {
+ bool TraverseAttr(Attr *A) override {
Events.push_back(VisitEvent::StartTraverseAttr);
- bool Ret = RecursiveASTVisitor::TraverseAttr(A);
+ bool Ret = DynamicRecursiveASTVisitor::TraverseAttr(A);
Events.push_back(VisitEvent::EndTraverseAttr);
return Ret;
}
- bool TraverseEnumDecl(EnumDecl *D) {
+ bool TraverseEnumDecl(EnumDecl *D) override {
Events.push_back(VisitEvent::StartTraverseEnum);
- bool Ret = RecursiveASTVisitor::TraverseEnumDecl(D);
+ bool Ret = DynamicRecursiveASTVisitor::TraverseEnumDecl(D);
Events.push_back(VisitEvent::EndTraverseEnum);
return Ret;
}
- bool TraverseTypedefTypeLoc(TypedefTypeLoc TL, bool TraverseQualifier) {
+ bool TraverseTypedefTypeLoc(TypedefTypeLoc TL, bool TraverseQualifier) override {
Events.push_back(VisitEvent::StartTraverseTypedefType);
bool Ret =
- RecursiveASTVisitor::TraverseTypedefTypeLoc(TL, TraverseQualifier);
+ DynamicRecursiveASTVisitor::TraverseTypedefTypeLoc(TL, TraverseQualifier);
Events.push_back(VisitEvent::EndTraverseTypedefType);
return Ret;
}
- bool TraverseObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
+ bool TraverseObjCInterfaceDecl(ObjCInterfaceDecl *ID) override {
Events.push_back(VisitEvent::StartTraverseObjCInterface);
- bool Ret = RecursiveASTVisitor::TraverseObjCInterfaceDecl(ID);
+ bool Ret = DynamicRecursiveASTVisitor::TraverseObjCInterfaceDecl(ID);
Events.push_back(VisitEvent::EndTraverseObjCInterface);
return Ret;
}
- bool TraverseObjCProtocolDecl(ObjCProtocolDecl *PD) {
+ bool TraverseObjCProtocolDecl(ObjCProtocolDecl *PD) override {
Events.push_back(VisitEvent::StartTraverseObjCProtocol);
- bool Ret = RecursiveASTVisitor::TraverseObjCProtocolDecl(PD);
+ bool Ret = DynamicRecursiveASTVisitor::TraverseObjCProtocolDecl(PD);
Events.push_back(VisitEvent::EndTraverseObjCProtocol);
return Ret;
}
- bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc) {
+ bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc) override {
Events.push_back(VisitEvent::StartTraverseObjCProtocolLoc);
- bool Ret = RecursiveASTVisitor::TraverseObjCProtocolLoc(ProtocolLoc);
+ bool Ret = DynamicRecursiveASTVisitor::TraverseObjCProtocolLoc(ProtocolLoc);
Events.push_back(VisitEvent::EndTraverseObjCProtocolLoc);
return Ret;
diff --git a/clang/unittests/Frontend/NoAlterCodeGenActionTest.cpp b/clang/unittests/Frontend/NoAlterCodeGenActionTest.cpp
index fed2d255a9fe8..97556e1eb1535 100644
--- a/clang/unittests/Frontend/NoAlterCodeGenActionTest.cpp
+++ b/clang/unittests/Frontend/NoAlterCodeGenActionTest.cpp
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/LangStandard.h"
#include "clang/CodeGen/BackendUtil.h"
#include "clang/CodeGen/CodeGenAction.h"
@@ -30,16 +30,16 @@ using namespace clang::tooling;
namespace {
-class ASTChecker : public RecursiveASTVisitor<ASTChecker> {
+class ASTChecker : public DynamicRecursiveASTVisitor {
public:
ASTContext &Ctx;
ASTChecker(ASTContext &Ctx) : Ctx(Ctx) {}
- bool VisitReturnStmt(ReturnStmt *RS) {
+ bool VisitReturnStmt(ReturnStmt *RS) override {
EXPECT_TRUE(RS->getRetValue());
return true;
}
- bool VisitCoroutineBodyStmt(CoroutineBodyStmt *CS) {
+ bool VisitCoroutineBodyStmt(CoroutineBodyStmt *CS) override {
return VisitReturnStmt(cast<ReturnStmt>(CS->getReturnStmt()));
}
};
>From a832fd0afe94c9ed3ac81544820919b49ee2f0ef Mon Sep 17 00:00:00 2001
From: Sirraide <aeternalmail at gmail.com>
Date: Tue, 23 Sep 2025 13:35:09 +0200
Subject: [PATCH 2/3] clang-format
---
.../bugprone/AssignmentInIfConditionCheck.cpp | 4 +-
.../modernize/DeprecatedHeadersCheck.cpp | 2 +-
.../clang-tidy/modernize/LoopConvertUtils.cpp | 3 +-
.../clang-tidy/modernize/LoopConvertUtils.h | 7 +-
.../modernize/UseTrailingReturnTypeCheck.cpp | 7 +-
.../ConvertMemberFunctionsToStatic.cpp | 4 +-
.../FunctionCognitiveComplexityCheck.cpp | 8 +-
.../MakeMemberFunctionConstCheck.cpp | 2 +-
.../readability/SimplifyBooleanExprCheck.cpp | 5 +-
.../utils/RenamerClangTidyCheck.cpp | 8 +-
clang-tools-extra/clangd/AST.cpp | 5 +-
clang-tools-extra/clangd/DumpAST.cpp | 17 +-
clang-tools-extra/clangd/FindTarget.cpp | 11 +-
clang-tools-extra/clangd/InlayHints.cpp | 2 +-
.../clangd/SemanticHighlighting.cpp | 23 +-
clang-tools-extra/clangd/XRefs.cpp | 4 +-
.../clangd/refactor/tweaks/AddUsing.cpp | 2 +-
.../refactor/tweaks/ExtractFunction.cpp | 2 +-
.../refactor/tweaks/ExtractVariable.cpp | 2 +-
.../clangd/unittests/ASTTests.cpp | 4 +-
.../unittests/FindHeadersTest.cpp | 2 +-
clang-tools-extra/modularize/Modularize.cpp | 60 +++--
.../unittests/clang-doc/SerializeTest.cpp | 12 +-
clang/include/clang/InstallAPI/Visitor.h | 2 +-
clang/lib/CodeGen/CGDebugInfo.cpp | 2 +-
clang/lib/CodeGen/CodeGenModule.cpp | 6 +-
.../CodeGen/ObjectFilePCHContainerWriter.cpp | 4 +-
clang/lib/Frontend/ASTConsumers.cpp | 237 +++++++++---------
.../InterfaceStubFunctionsConsumer.cpp | 2 +-
clang/lib/Index/IndexBody.cpp | 13 +-
clang/lib/Index/IndexTypeSourceInfo.cpp | 10 +-
clang/lib/Tooling/ASTDiff/ASTDiff.cpp | 8 +-
.../Refactoring/Rename/USRLocFinder.cpp | 2 +-
.../unittests/AST/RecursiveASTVisitorTest.cpp | 9 +-
34 files changed, 266 insertions(+), 225 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index d3b0b7c0f0a61..66e34418fb0ac 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -35,9 +35,7 @@ void AssignmentInIfConditionCheck::check(
: Check(Check) {}
// Dont traverse into any lambda expressions.
- bool TraverseLambdaExpr(const LambdaExpr *) override {
- return true;
- }
+ bool TraverseLambdaExpr(const LambdaExpr *) override { return true; }
// Dont traverse into any requires expressions.
bool TraverseRequiresExpr(const RequiresExpr *) override {
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index fa772b8da07d9..47b592842df5b 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -44,7 +44,7 @@ class IncludeModernizePPCallbacks : public PPCallbacks {
bool CheckHeaderFile;
};
-class ExternCRefutationVisitor : public ConstDynamicRecursiveASTVisitor{
+class ExternCRefutationVisitor : public ConstDynamicRecursiveASTVisitor {
std::vector<IncludeMarker> &IncludesToBeProcessed;
const SourceManager &SM;
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 8c23c7c6fa0a5..f9de75656a0d9 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -683,7 +683,8 @@ bool ForLoopIndexUseVisitor::TraverseCXXOperatorCallExpr(
/// \endcode
/// and further checking needs to be done later to ensure that exactly one array
/// is referenced.
-bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr(const ArraySubscriptExpr *E) {
+bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr(
+ const ArraySubscriptExpr *E) {
const Expr *Arr = E->getBase();
if (!isIndexInSubscriptExpr(E->getIdx(), IndexVar))
return VisitorBase::TraverseArraySubscriptExpr(E);
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
index 29bbd9cd6f6af..dc7ab847d9921 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
@@ -87,9 +87,7 @@ class ComponentFinderASTVisitor : public ConstDynamicRecursiveASTVisitor {
ComponentFinderASTVisitor() = default;
/// Find the components of an expression and place them in a ComponentVector.
- void findExprComponents(const Expr *SourceExpr) {
- TraverseStmt(SourceExpr);
- }
+ void findExprComponents(const Expr *SourceExpr) { TraverseStmt(SourceExpr); }
/// Accessor for Components.
const ComponentVector &getComponents() { return Components; }
@@ -332,7 +330,8 @@ class ForLoopIndexUseVisitor : public ConstDynamicRecursiveASTVisitor {
bool TraverseArraySubscriptExpr(const ArraySubscriptExpr *E) override;
bool TraverseCXXMemberCallExpr(const CXXMemberCallExpr *MemberCall) override;
bool TraverseCXXOperatorCallExpr(const CXXOperatorCallExpr *OpCall) override;
- bool TraverseLambdaCapture(const LambdaExpr *LE, const LambdaCapture *C, const Expr *Init) override;
+ bool TraverseLambdaCapture(const LambdaExpr *LE, const LambdaCapture *C,
+ const Expr *Init) override;
bool TraverseMemberExpr(const MemberExpr *Member) override;
bool TraverseUnaryOperator(const UnaryOperator *Uop) override;
bool VisitDeclRefExpr(const DeclRefExpr *E) override;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 9f9de5ab0131d..4616faa274509 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -114,13 +114,14 @@ struct UnqualNameVisitor : ConstDynamicRecursiveASTVisitor {
break;
}
- return ConstDynamicRecursiveASTVisitor::TraverseTypeLoc(
- TL, TraverseQualifier);
+ return ConstDynamicRecursiveASTVisitor::TraverseTypeLoc(TL,
+ TraverseQualifier);
}
// Replace the base method in order to call our own
// TraverseTypeLoc().
- bool TraverseQualifiedTypeLoc(QualifiedTypeLoc TL, bool TraverseQualifier) override {
+ bool TraverseQualifiedTypeLoc(QualifiedTypeLoc TL,
+ bool TraverseQualifier) override {
return TraverseTypeLoc(TL.getUnqualifiedLoc(), TraverseQualifier);
}
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
index dd5a3dcf08e79..9a9f66503713a 100644
--- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -66,7 +66,9 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
// If we enter a class declaration, don't traverse into it as any usages of
// `this` will correspond to the nested class.
- bool TraverseCXXRecordDecl(const CXXRecordDecl *RD) override { return true; }
+ bool TraverseCXXRecordDecl(const CXXRecordDecl *RD) override {
+ return true;
+ }
} UsageOfThis;
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 748246242b961..51a116071fcd9 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -10,8 +10,8 @@
#include "../ClangTidyDiagnosticConsumer.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
-#include "clang/AST/Expr.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/Expr.h"
#include "clang/AST/Stmt.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -241,7 +241,7 @@ class FunctionASTVisitor final : public ConstDynamicRecursiveASTVisitor {
}
bool TraverseIfStmt(const IfStmt *Node) override {
- return traverseIfStmt(Node);
+ return traverseIfStmt(Node);
}
bool traverseIfStmt(const IfStmt *Node, bool InElseIf = false) {
@@ -467,9 +467,7 @@ class FunctionASTVisitor final : public ConstDynamicRecursiveASTVisitor {
// function is the entry point, then the Nesting level should not be
// increased. Thus that parameter is there and is used to fall-through
// directly to traversing if this is the main function that is being analyzed.
- bool TraverseDecl(const Decl *Node) override {
- return traverseDecl(Node);
- }
+ bool TraverseDecl(const Decl *Node) override { return traverseDecl(Node); }
bool traverseDecl(const Decl *Node, bool MainAnalyzedFunction = false) {
if (!Node || MainAnalyzedFunction)
diff --git a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
index 2ffb2e2bb348a..c035693a0a5d5 100644
--- a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
@@ -8,8 +8,8 @@
#include "MakeMemberFunctionConstCheck.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/ParentMapContext.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/ParentMapContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 65a8365453e45..411d66e557e52 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "SimplifyBooleanExprCheck.h"
-#include "clang/AST/Expr.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/Expr.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Lex/Lexer.h"
#include "llvm/Support/SaveAndRestore.h"
@@ -258,7 +258,8 @@ static bool containsDiscardedTokens(const ASTContext &Context,
return false;
}
-class SimplifyBooleanExprCheck::Visitor : public ConstDynamicRecursiveASTVisitor {
+class SimplifyBooleanExprCheck::Visitor
+ : public ConstDynamicRecursiveASTVisitor {
using Base = ConstDynamicRecursiveASTVisitor;
public:
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 953818a186a52..93aa0fa586ea4 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -297,8 +297,8 @@ class RenamerClangTidyVisitor : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool
- VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *DepMemberRef) override {
+ bool VisitCXXDependentScopeMemberExpr(
+ const CXXDependentScopeMemberExpr *DepMemberRef) override {
QualType BaseType = DepMemberRef->isArrow()
? DepMemberRef->getBaseType()->getPointeeType()
: DepMemberRef->getBaseType();
@@ -342,8 +342,8 @@ class RenamerClangTidyVisitor : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool
- VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc Loc) override {
+ bool VisitTemplateSpecializationTypeLoc(
+ TemplateSpecializationTypeLoc Loc) override {
const TemplateDecl *Decl =
Loc.getTypePtr()->getTemplateName().getAsTemplateDecl(
/*IgnoreDeduced=*/true);
diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 8d7ba84ca774b..cf302124b3b61 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -17,10 +17,10 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclarationName.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/TypeLoc.h"
@@ -861,7 +861,8 @@ class ForwardingCallVisitor : public ConstDynamicRecursiveASTVisitor {
private:
// inspects the given callee with the given args to check whether it
// contains Parameters, and sets Info accordingly.
- void handleCall(const FunctionDecl *Callee, typename CallExpr::const_arg_range Args) {
+ void handleCall(const FunctionDecl *Callee,
+ typename CallExpr::const_arg_range Args) {
// Skip functions with less parameters, they can't be the target.
if (Callee->parameters().size() < Parameters.size())
return;
diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp
index d3f384f3351cf..87856501ce825 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -11,11 +11,11 @@
#include "SourceCode.h"
#include "support/Logger.h"
#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/TextNodeDumper.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
@@ -379,19 +379,26 @@ class DumpVisitor : public ConstDynamicRecursiveASTVisitor {
bool dataTraverseStmtPre(const Stmt *S) override {
return S && traverseNodePre(isa<Expr>(S) ? "expression" : "statement", S);
}
- bool dataTraverseStmtPost(const Stmt *X) override { return traverseNodePost(); }
+ bool dataTraverseStmtPost(const Stmt *X) override {
+ return traverseNodePost();
+ }
// QualifiedTypeLoc is handled strangely in RecursiveASTVisitor: the derived
// TraverseTypeLoc is not called for the inner UnqualTypeLoc.
// This means we'd never see 'int' in 'const int'! Work around that here.
// (The reason for the behavior is to avoid traversing the nested Type twice,
// but we ignore TraverseType anyway).
- bool TraverseQualifiedTypeLoc(QualifiedTypeLoc QTL, bool TraverseQualifier) override {
+ bool TraverseQualifiedTypeLoc(QualifiedTypeLoc QTL,
+ bool TraverseQualifier) override {
return TraverseTypeLoc(QTL.getUnqualifiedLoc());
}
// Uninteresting parts of the AST that don't have locations within them.
- bool TraverseNestedNameSpecifier(NestedNameSpecifier) override { return true; }
- bool TraverseType(QualType, bool TraverseQualifier = true) override { return true; }
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier) override {
+ return true;
+ }
+ bool TraverseType(QualType, bool TraverseQualifier = true) override {
+ return true;
+ }
// OpaqueValueExpr blocks traversal, we must explicitly traverse it.
bool TraverseOpaqueValueExpr(const OpaqueValueExpr *E) override {
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 1b9e84cc460ac..ba5d72ed4d7ca 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -17,13 +17,13 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/DeclarationName.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprConcepts.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/TemplateBase.h"
#include "clang/AST/Type.h"
@@ -954,7 +954,8 @@ class ExplicitReferenceCollector : public ConstDynamicRecursiveASTVisitor {
visitNode(DynTypedNode::create(*POE));
// Traverse only the syntactic form to find the *written* references.
// (The semantic form also contains lots of duplication)
- return ConstDynamicRecursiveASTVisitor::TraverseStmt(POE->getSyntacticForm());
+ return ConstDynamicRecursiveASTVisitor::TraverseStmt(
+ POE->getSyntacticForm());
}
// We re-define Traverse*, since there's no corresponding Visit*.
@@ -1010,7 +1011,8 @@ class ExplicitReferenceCollector : public ConstDynamicRecursiveASTVisitor {
bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override {
visitNode(DynTypedNode::create(*Init));
- return ConstDynamicRecursiveASTVisitor::TraverseConstructorInitializer(Init);
+ return ConstDynamicRecursiveASTVisitor::TraverseConstructorInitializer(
+ Init);
}
bool VisitConceptReference(const ConceptReference *CR) override {
@@ -1125,8 +1127,7 @@ void findExplicitReferences(const Decl *D,
void findExplicitReferences(const ASTContext &AST,
llvm::function_ref<void(ReferenceLoc)> Out,
const HeuristicResolver *Resolver) {
- ExplicitReferenceCollector(Out, Resolver)
- .TraverseAST(AST);
+ ExplicitReferenceCollector(Out, Resolver).TraverseAST(AST);
}
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, DeclRelation R) {
diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index 4a1395df7753d..1ec94fca55373 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -16,9 +16,9 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclarationName.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/Type.h"
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 01caf981f2b55..166d71dd27ed0 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -19,8 +19,8 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclarationName.h"
-#include "clang/AST/ExprCXX.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/ExprCXX.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/LangOptions.h"
@@ -671,7 +671,8 @@ class CollectExtraHighlightings : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E) override {
+ bool
+ VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E) override {
if (auto *Args = E->getTemplateArgsAsWritten())
H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
return true;
@@ -691,21 +692,22 @@ class CollectExtraHighlightings : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool
- VisitClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl *D) override {
+ bool VisitClassTemplateSpecializationDecl(
+ const ClassTemplateSpecializationDecl *D) override {
if (auto *Args = D->getTemplateArgsAsWritten())
H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
return true;
}
bool VisitClassTemplatePartialSpecializationDecl(
- const ClassTemplatePartialSpecializationDecl *D) override {
+ const ClassTemplatePartialSpecializationDecl *D) override {
if (auto *TPL = D->getTemplateParameters())
H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
return true;
}
- bool VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *D) override {
+ bool VisitVarTemplateSpecializationDecl(
+ const VarTemplateSpecializationDecl *D) override {
if (auto *Args = D->getTemplateArgsAsWritten())
H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
return true;
@@ -1046,7 +1048,8 @@ class CollectExtraHighlightings : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) override {
+ bool VisitCXXDependentScopeMemberExpr(
+ const CXXDependentScopeMemberExpr *E) override {
H.addToken(E->getMemberNameInfo().getLoc(), HighlightingKind::Unknown)
.addModifier(HighlightingModifier::DependentName)
.addModifier(HighlightingModifier::ClassScope);
@@ -1054,7 +1057,8 @@ class CollectExtraHighlightings : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) override {
+ bool
+ VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) override {
H.addToken(E->getNameInfo().getLoc(), HighlightingKind::Unknown)
.addModifier(HighlightingModifier::DependentName)
.addModifier(HighlightingModifier::ClassScope);
@@ -1081,7 +1085,8 @@ class CollectExtraHighlightings : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) override {
+ bool
+ VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) override {
if (!L.getTypePtr()->getTemplateName().getAsTemplateDecl(
/*IgnoreDeduced=*/true))
H.addToken(L.getTemplateNameLoc(), HighlightingKind::Type)
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 535c84efffe66..e2af24ad2398c 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -35,8 +35,8 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclVisitor.h"
-#include "clang/AST/ExprCXX.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/ExprCXX.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtVisitor.h"
@@ -1119,7 +1119,7 @@ class FindControlFlow : public ConstDynamicRecursiveASTVisitor {
found(Case, C->getKeywordLoc());
return true;
}
- bool VisitCXXThrowExpr(const CXXThrowExpr *T) override {
+ bool VisitCXXThrowExpr(const CXXThrowExpr *T) override {
found(Throw, T->getThrowLoc());
return true;
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
index b7a088679edda..6acbc481257a2 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -12,9 +12,9 @@
#include "refactor/Tweak.h"
#include "support/Logger.h"
#include "clang/AST/Decl.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/NestedNameSpecifier.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/LLVM.h"
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
index 02b3b1fb88d88..5678ff565e515 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -56,9 +56,9 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index aa33b92d19f04..1d722b1b142f0 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -14,11 +14,11 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/LambdaCapture.h"
#include "clang/AST/OperationKinds.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/Basic/LangOptions.h"
diff --git a/clang-tools-extra/clangd/unittests/ASTTests.cpp b/clang-tools-extra/clangd/unittests/ASTTests.cpp
index 44f703605484c..25151873c33c1 100644
--- a/clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -305,8 +305,8 @@ TEST(ClangdAST, GetOnlyInstantiation) {
PrintingPolicy PP = AST.getASTContext().getPrintingPolicy();
PP.TerseOutput = true;
std::string Name;
- if (const auto *Result = getOnlyInstantiation(
- &findDecl(AST, [&](const NamedDecl &D) {
+ if (const auto *Result =
+ getOnlyInstantiation(&findDecl(AST, [&](const NamedDecl &D) {
return D.getDescribedTemplate() != nullptr &&
D.getDeclKindName() == Case.NodeType;
}))) {
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 355775b96c078..b0a3b0d4d1549 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -11,8 +11,8 @@
#include "clang-include-cleaner/Analysis.h"
#include "clang-include-cleaner/Record.h"
#include "clang-include-cleaner/Types.h"
-#include "clang/AST/Expr.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/Expr.h"
#include "clang/Basic/FileEntry.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LLVM.h"
diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp
index b381b71ea03e5..52752242d6a13 100644
--- a/clang-tools-extra/modularize/Modularize.cpp
+++ b/clang-tools-extra/modularize/Modularize.cpp
@@ -534,9 +534,15 @@ class CollectEntitiesVisitor : public ConstDynamicRecursiveASTVisitor {
HadErrors(HadErrors) {}
bool TraverseStmt(const Stmt *S) override { return true; }
- bool TraverseType(QualType T, bool TraverseQualifier) override { return true; }
- bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier) override { return true; }
- bool TraverseNestedNameSpecifier(NestedNameSpecifier NNS) override { return true; }
+ bool TraverseType(QualType T, bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier NNS) override {
+ return true;
+ }
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) override {
return true;
}
@@ -544,12 +550,18 @@ class CollectEntitiesVisitor : public ConstDynamicRecursiveASTVisitor {
return true;
}
bool TraverseTemplateName(TemplateName Template) override { return true; }
- bool TraverseTemplateArgument(const TemplateArgument &Arg) override { return true; }
+ bool TraverseTemplateArgument(const TemplateArgument &Arg) override {
+ return true;
+ }
bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) override {
return true;
}
- bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) override { return true; }
- bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override { return true; }
+ bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) override {
+ return true;
+ }
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override {
+ return true;
+ }
bool TraverseLambdaCapture(const LambdaExpr *LE, const LambdaCapture *C,
const Expr *Init) override {
return true;
@@ -718,9 +730,15 @@ class CompileCheckVisitor : public ConstDynamicRecursiveASTVisitor {
CompileCheckVisitor() {}
bool TraverseStmt(const Stmt *S) override { return true; }
- bool TraverseType(QualType T, bool TraverseQualifier) override { return true; }
- bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier) override { return true; }
- bool TraverseNestedNameSpecifier(NestedNameSpecifier NNS) override { return true; }
+ bool TraverseType(QualType T, bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier NNS) override {
+ return true;
+ }
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) override {
return true;
}
@@ -728,31 +746,31 @@ class CompileCheckVisitor : public ConstDynamicRecursiveASTVisitor {
return true;
}
bool TraverseTemplateName(TemplateName Template) override { return true; }
- bool TraverseTemplateArgument(const TemplateArgument &Arg) override { return true; }
+ bool TraverseTemplateArgument(const TemplateArgument &Arg) override {
+ return true;
+ }
bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) override {
return true;
}
- bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) override { return true; }
- bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override { return true; }
+ bool TraverseTemplateArguments(ArrayRef<TemplateArgument>) override {
+ return true;
+ }
+ bool TraverseConstructorInitializer(const CXXCtorInitializer *Init) override {
+ return true;
+ }
bool TraverseLambdaCapture(const LambdaExpr *LE, const LambdaCapture *C,
const Expr *Init) override {
return true;
}
// Check 'extern "*" {}' block for #include directives.
- bool VisitLinkageSpecDecl(const LinkageSpecDecl *D) override {
- return true;
- }
+ bool VisitLinkageSpecDecl(const LinkageSpecDecl *D) override { return true; }
// Check 'namespace (name) {}' block for #include directives.
- bool VisitNamespaceDecl(const NamespaceDecl *D) override {
- return true;
- }
+ bool VisitNamespaceDecl(const NamespaceDecl *D) override { return true; }
// Collect definition entities.
- bool VisitNamedDecl(const NamedDecl *ND) override {
- return true;
- }
+ bool VisitNamedDecl(const NamedDecl *ND) override { return true; }
};
class CompileCheckConsumer : public ASTConsumer {
diff --git a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
index 2e47333f3641d..440de5178a840 100644
--- a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -44,7 +44,9 @@ class ClangDocSerializeTestVisitor : public ConstDynamicRecursiveASTVisitor {
return true;
}
- bool VisitNamespaceDecl(const NamespaceDecl *D) override { return mapDecl(D); }
+ bool VisitNamespaceDecl(const NamespaceDecl *D) override {
+ return mapDecl(D);
+ }
bool VisitFunctionDecl(const FunctionDecl *D) override {
// Don't visit CXXMethodDecls twice
@@ -53,7 +55,9 @@ class ClangDocSerializeTestVisitor : public ConstDynamicRecursiveASTVisitor {
return mapDecl(D);
}
- bool VisitCXXMethodDecl(const CXXMethodDecl *D) override { return mapDecl(D); }
+ bool VisitCXXMethodDecl(const CXXMethodDecl *D) override {
+ return mapDecl(D);
+ }
bool VisitRecordDecl(const RecordDecl *D) override { return mapDecl(D); }
@@ -61,7 +65,9 @@ class ClangDocSerializeTestVisitor : public ConstDynamicRecursiveASTVisitor {
bool VisitTypedefDecl(const TypedefDecl *D) override { return mapDecl(D); }
- bool VisitTypeAliasDecl(const TypeAliasDecl *D) override { return mapDecl(D); }
+ bool VisitTypeAliasDecl(const TypeAliasDecl *D) override {
+ return mapDecl(D);
+ }
};
void ExtractInfosFromCode(StringRef Code, size_t NumExpectedInfos, bool Public,
diff --git a/clang/include/clang/InstallAPI/Visitor.h b/clang/include/clang/InstallAPI/Visitor.h
index b86556d35309e..b425cc2ca74f9 100644
--- a/clang/include/clang/InstallAPI/Visitor.h
+++ b/clang/include/clang/InstallAPI/Visitor.h
@@ -13,8 +13,8 @@
#ifndef LLVM_CLANG_INSTALLAPI_VISITOR_H
#define LLVM_CLANG_INSTALLAPI_VISITOR_H
-#include "clang/AST/Mangle.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/Mangle.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/InstallAPI/Context.h"
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 5023da5abd2bb..4a77edf95f46e 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -25,9 +25,9 @@
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/RecordLayout.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/VTableBuilder.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/SourceManager.h"
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index dc7e2741c5611..5023b0a55da3e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -34,8 +34,8 @@
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
-#include "clang/AST/Mangle.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/Mangle.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CodeGenOptions.h"
@@ -4269,9 +4269,7 @@ namespace {
struct DLLImportFunctionVisitor : DynamicRecursiveASTVisitor {
bool SafeToInline = true;
- DLLImportFunctionVisitor() {
- ShouldVisitImplicitCode = true;
- }
+ DLLImportFunctionVisitor() { ShouldVisitImplicitCode = true; }
bool VisitVarDecl(VarDecl *VD) override {
if (VD->getTLSKind()) {
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index aca58e3e74378..2f26d64e73e97 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
@@ -11,8 +11,8 @@
#include "CodeGenModule.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
-#include "clang/AST/Expr.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/Expr.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
@@ -56,7 +56,7 @@ class PCHContainerGenerator : public ASTConsumer {
std::shared_ptr<PCHBuffer> Buffer;
/// Visit every type and emit debug info for it.
- struct DebugTypeVisitor : DynamicRecursiveASTVisitor{
+ struct DebugTypeVisitor : DynamicRecursiveASTVisitor {
clang::CodeGen::CGDebugInfo &DI;
ASTContext &Ctx;
DebugTypeVisitor(clang::CodeGen::CGDebugInfo &DI, ASTContext &Ctx)
diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp
index 401b34bb9c3e1..b1d99fd8657d5 100644
--- a/clang/lib/Frontend/ASTConsumers.cpp
+++ b/clang/lib/Frontend/ASTConsumers.cpp
@@ -14,9 +14,9 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/RecordLayout.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
@@ -26,145 +26,144 @@ using namespace clang;
/// ASTPrinter - Pretty-printer and dumper of ASTs
namespace {
- class ASTPrinter : public ASTConsumer,
- public DynamicRecursiveASTVisitor {
- using base = DynamicRecursiveASTVisitor;
-
- public:
- enum Kind { DumpFull, Dump, Print, None };
- ASTPrinter(std::unique_ptr<raw_ostream> Out, Kind K,
- ASTDumpOutputFormat Format, StringRef FilterString,
- bool DumpLookups = false, bool DumpDeclTypes = false)
- : Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)),
- OutputKind(K), OutputFormat(Format), FilterString(FilterString),
- DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {
- ShouldWalkTypesOfTypeLocs = false;
- }
+class ASTPrinter : public ASTConsumer, public DynamicRecursiveASTVisitor {
+ using base = DynamicRecursiveASTVisitor;
- ASTPrinter(raw_ostream &Out, Kind K, ASTDumpOutputFormat Format,
- StringRef FilterString, bool DumpLookups = false,
- bool DumpDeclTypes = false)
- : Out(Out), OwnedOut(nullptr), OutputKind(K), OutputFormat(Format),
- FilterString(FilterString), DumpLookups(DumpLookups),
- DumpDeclTypes(DumpDeclTypes) {
- ShouldWalkTypesOfTypeLocs = false;
- }
+public:
+ enum Kind { DumpFull, Dump, Print, None };
+ ASTPrinter(std::unique_ptr<raw_ostream> Out, Kind K,
+ ASTDumpOutputFormat Format, StringRef FilterString,
+ bool DumpLookups = false, bool DumpDeclTypes = false)
+ : Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)), OutputKind(K),
+ OutputFormat(Format), FilterString(FilterString),
+ DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
- void HandleTranslationUnit(ASTContext &Context) override {
- TranslationUnitDecl *D = Context.getTranslationUnitDecl();
+ ASTPrinter(raw_ostream &Out, Kind K, ASTDumpOutputFormat Format,
+ StringRef FilterString, bool DumpLookups = false,
+ bool DumpDeclTypes = false)
+ : Out(Out), OwnedOut(nullptr), OutputKind(K), OutputFormat(Format),
+ FilterString(FilterString), DumpLookups(DumpLookups),
+ DumpDeclTypes(DumpDeclTypes) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
- if (FilterString.empty())
- return print(D);
+ void HandleTranslationUnit(ASTContext &Context) override {
+ TranslationUnitDecl *D = Context.getTranslationUnitDecl();
- TraverseDecl(D);
- }
+ if (FilterString.empty())
+ return print(D);
- bool TraverseDecl(Decl *D) override {
- if (D && filterMatches(D)) {
- bool ShowColors = Out.has_colors();
- if (ShowColors)
- Out.changeColor(raw_ostream::BLUE);
-
- if (OutputFormat == ADOF_Default)
- Out << (OutputKind != Print ? "Dumping " : "Printing ") << getName(D)
- << ":\n";
-
- if (ShowColors)
- Out.resetColor();
- print(D);
- Out << "\n";
- // Don't traverse child nodes to avoid output duplication.
- return true;
- }
- return base::TraverseDecl(D);
- }
+ TraverseDecl(D);
+ }
- private:
- std::string getName(Decl *D) {
- if (isa<NamedDecl>(D))
- return cast<NamedDecl>(D)->getQualifiedNameAsString();
- return "";
+ bool TraverseDecl(Decl *D) override {
+ if (D && filterMatches(D)) {
+ bool ShowColors = Out.has_colors();
+ if (ShowColors)
+ Out.changeColor(raw_ostream::BLUE);
+
+ if (OutputFormat == ADOF_Default)
+ Out << (OutputKind != Print ? "Dumping " : "Printing ") << getName(D)
+ << ":\n";
+
+ if (ShowColors)
+ Out.resetColor();
+ print(D);
+ Out << "\n";
+ // Don't traverse child nodes to avoid output duplication.
+ return true;
}
- bool filterMatches(Decl *D) {
- return getName(D).find(FilterString) != std::string::npos;
+ return base::TraverseDecl(D);
+ }
+
+private:
+ std::string getName(Decl *D) {
+ if (isa<NamedDecl>(D))
+ return cast<NamedDecl>(D)->getQualifiedNameAsString();
+ return "";
+ }
+ bool filterMatches(Decl *D) {
+ return getName(D).find(FilterString) != std::string::npos;
+ }
+ void print(Decl *D) {
+ if (DumpLookups) {
+ if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
+ if (DC == DC->getPrimaryContext())
+ DC->dumpLookups(Out, OutputKind != None, OutputKind == DumpFull);
+ else
+ Out << "Lookup map is in primary DeclContext "
+ << DC->getPrimaryContext() << "\n";
+ } else
+ Out << "Not a DeclContext\n";
+ } else if (OutputKind == Print) {
+ PrintingPolicy Policy(D->getASTContext().getLangOpts());
+ Policy.IncludeTagDefinition = true;
+ D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
+ } else if (OutputKind != None) {
+ D->dump(Out, OutputKind == DumpFull, OutputFormat);
}
- void print(Decl *D) {
- if (DumpLookups) {
- if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
- if (DC == DC->getPrimaryContext())
- DC->dumpLookups(Out, OutputKind != None, OutputKind == DumpFull);
- else
- Out << "Lookup map is in primary DeclContext "
- << DC->getPrimaryContext() << "\n";
- } else
- Out << "Not a DeclContext\n";
- } else if (OutputKind == Print) {
- PrintingPolicy Policy(D->getASTContext().getLangOpts());
- Policy.IncludeTagDefinition = true;
- D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
- } else if (OutputKind != None) {
- D->dump(Out, OutputKind == DumpFull, OutputFormat);
- }
- if (DumpDeclTypes) {
- Decl *InnerD = D;
- if (auto *TD = dyn_cast<TemplateDecl>(D))
- if (Decl *TempD = TD->getTemplatedDecl())
- InnerD = TempD;
-
- // FIXME: Support OutputFormat in type dumping.
- // FIXME: Support combining -ast-dump-decl-types with -ast-dump-lookups.
- if (auto *VD = dyn_cast<ValueDecl>(InnerD))
- VD->getType().dump(Out, VD->getASTContext());
- if (auto *TD = dyn_cast<TypeDecl>(InnerD)) {
- const ASTContext &Ctx = TD->getASTContext();
- Ctx.getTypeDeclType(TD)->dump(Out, Ctx);
- }
+ if (DumpDeclTypes) {
+ Decl *InnerD = D;
+ if (auto *TD = dyn_cast<TemplateDecl>(D))
+ if (Decl *TempD = TD->getTemplatedDecl())
+ InnerD = TempD;
+
+ // FIXME: Support OutputFormat in type dumping.
+ // FIXME: Support combining -ast-dump-decl-types with -ast-dump-lookups.
+ if (auto *VD = dyn_cast<ValueDecl>(InnerD))
+ VD->getType().dump(Out, VD->getASTContext());
+ if (auto *TD = dyn_cast<TypeDecl>(InnerD)) {
+ const ASTContext &Ctx = TD->getASTContext();
+ Ctx.getTypeDeclType(TD)->dump(Out, Ctx);
}
}
+ }
- raw_ostream &Out;
- std::unique_ptr<raw_ostream> OwnedOut;
+ raw_ostream &Out;
+ std::unique_ptr<raw_ostream> OwnedOut;
- /// How to output individual declarations.
- Kind OutputKind;
+ /// How to output individual declarations.
+ Kind OutputKind;
- /// What format should the output take?
- ASTDumpOutputFormat OutputFormat;
+ /// What format should the output take?
+ ASTDumpOutputFormat OutputFormat;
- /// Which declarations or DeclContexts to display.
- std::string FilterString;
+ /// Which declarations or DeclContexts to display.
+ std::string FilterString;
- /// Whether the primary output is lookup results or declarations. Individual
- /// results will be output with a format determined by OutputKind. This is
- /// incompatible with OutputKind == Print.
- bool DumpLookups;
+ /// Whether the primary output is lookup results or declarations. Individual
+ /// results will be output with a format determined by OutputKind. This is
+ /// incompatible with OutputKind == Print.
+ bool DumpLookups;
- /// Whether to dump the type for each declaration dumped.
- bool DumpDeclTypes;
- };
+ /// Whether to dump the type for each declaration dumped.
+ bool DumpDeclTypes;
+};
- class ASTDeclNodeLister : public ASTConsumer,
- public DynamicRecursiveASTVisitor {
- public:
- ASTDeclNodeLister(raw_ostream *Out = nullptr)
- : Out(Out ? *Out : llvm::outs()) {
- ShouldWalkTypesOfTypeLocs = false;
- }
+class ASTDeclNodeLister : public ASTConsumer,
+ public DynamicRecursiveASTVisitor {
+public:
+ ASTDeclNodeLister(raw_ostream *Out = nullptr)
+ : Out(Out ? *Out : llvm::outs()) {
+ ShouldWalkTypesOfTypeLocs = false;
+ }
- void HandleTranslationUnit(ASTContext &Context) override {
- TraverseDecl(Context.getTranslationUnitDecl());
- }
+ void HandleTranslationUnit(ASTContext &Context) override {
+ TraverseDecl(Context.getTranslationUnitDecl());
+ }
- bool VisitNamedDecl(NamedDecl *D) override {
- D->printQualifiedName(Out);
- Out << '\n';
- return true;
- }
+ bool VisitNamedDecl(NamedDecl *D) override {
+ D->printQualifiedName(Out);
+ Out << '\n';
+ return true;
+ }
- private:
- raw_ostream &Out;
- };
+private:
+ raw_ostream &Out;
+};
} // end anonymous namespace
std::unique_ptr<ASTConsumer>
diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index 83f880093e3ba..2dbf24522fa9d 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/AST/Mangle.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/Mangle.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 2ec9222eb8e82..f117ee6a63def 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -11,10 +11,10 @@
#include "clang/AST/ASTLambda.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprConcepts.h"
#include "clang/AST/ExprObjC.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/Sema/HeuristicResolver.h"
@@ -33,9 +33,9 @@ class BodyIndexer : public DynamicRecursiveASTVisitor {
return StmtStack.size() < 2 ? nullptr : StmtStack.end()[-2];
}
public:
- BodyIndexer(IndexingContext &indexCtx,
- const NamedDecl *Parent, const DeclContext *DC)
- : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) {
+ BodyIndexer(IndexingContext &indexCtx, const NamedDecl *Parent,
+ const DeclContext *DC)
+ : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) {
ShouldWalkTypesOfTypeLocs = false;
}
@@ -197,7 +197,8 @@ class BodyIndexer : public DynamicRecursiveASTVisitor {
Roles, Relations, E);
}
- bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) override {
+ bool
+ VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) override {
auto *Resolver = IndexCtx.getResolver();
assert(Resolver);
return indexDependentReference(E, E->getMemberNameInfo().getLoc(),
@@ -480,7 +481,7 @@ class BodyIndexer : public DynamicRecursiveASTVisitor {
return true;
}
- bool VisitParmVarDecl(ParmVarDecl* D) override {
+ bool VisitParmVarDecl(ParmVarDecl *D) override {
// Index the parameters of lambda expression and requires expression.
if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
const auto *DC = D->getDeclContext();
diff --git a/clang/lib/Index/IndexTypeSourceInfo.cpp b/clang/lib/Index/IndexTypeSourceInfo.cpp
index b8270b108a91d..d8effcfd2b021 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -8,9 +8,9 @@
#include "IndexingContext.h"
#include "clang/AST/ASTConcept.h"
-#include "clang/AST/PrettyPrinter.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Sema/HeuristicResolver.h"
#include "llvm/ADT/ScopeExit.h"
@@ -161,7 +161,8 @@ class TypeIndexer : public DynamicRecursiveASTVisitor {
}
}
- bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) override {
+ bool VisitTemplateSpecializationTypeLoc(
+ TemplateSpecializationTypeLoc TL) override {
auto *T = TL.getTypePtr();
if (!T)
return true;
@@ -192,7 +193,8 @@ class TypeIndexer : public DynamicRecursiveASTVisitor {
return true;
}
- bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) override {
+ bool VisitDeducedTemplateSpecializationTypeLoc(
+ DeducedTemplateSpecializationTypeLoc TL) override {
auto *T = TL.getTypePtr();
if (!T)
return true;
diff --git a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
index 6c9139acc982e..5c2c7d79ec1da 100644
--- a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -11,10 +11,10 @@
//===----------------------------------------------------------------------===//
#include "clang/Tooling/ASTDiff/ASTDiff.h"
-#include "clang/AST/ParentMapContext.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
-#include "clang/Basic/SourceManager.h"
#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ParentMapContext.h"
+#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/PriorityQueue.h"
@@ -247,7 +247,9 @@ struct PreorderVisitor : DynamicRecursiveASTVisitor {
PostTraverse(SavedState);
return true;
}
- bool TraverseType(QualType T, bool TraverseQualifier = true) override { return true; }
+ bool TraverseType(QualType T, bool TraverseQualifier = true) override {
+ return true;
+ }
bool TraverseConstructorInitializer(CXXCtorInitializer *Init) override {
if (isNodeExcluded(Tree.AST.getSourceManager(), Init))
return true;
diff --git a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
index 220691ca60a9d..3f24807e7f7c9 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -15,8 +15,8 @@
#include "clang/Tooling/Refactoring/Rename/USRLocFinder.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/ParentMapContext.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
+#include "clang/AST/ParentMapContext.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
diff --git a/clang/unittests/AST/RecursiveASTVisitorTest.cpp b/clang/unittests/AST/RecursiveASTVisitorTest.cpp
index 303aeffb2fc7b..06021509a7a0b 100644
--- a/clang/unittests/AST/RecursiveASTVisitorTest.cpp
+++ b/clang/unittests/AST/RecursiveASTVisitorTest.cpp
@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
@@ -94,10 +94,11 @@ class CollectInterestingEvents : public DynamicRecursiveASTVisitor {
return Ret;
}
- bool TraverseTypedefTypeLoc(TypedefTypeLoc TL, bool TraverseQualifier) override {
+ bool TraverseTypedefTypeLoc(TypedefTypeLoc TL,
+ bool TraverseQualifier) override {
Events.push_back(VisitEvent::StartTraverseTypedefType);
- bool Ret =
- DynamicRecursiveASTVisitor::TraverseTypedefTypeLoc(TL, TraverseQualifier);
+ bool Ret = DynamicRecursiveASTVisitor::TraverseTypedefTypeLoc(
+ TL, TraverseQualifier);
Events.push_back(VisitEvent::EndTraverseTypedefType);
return Ret;
>From 1bace611d9acd954acbbe963f7a2f2489831ea09 Mon Sep 17 00:00:00 2001
From: Sirraide <aeternalmail at gmail.com>
Date: Tue, 23 Sep 2025 15:40:56 +0200
Subject: [PATCH 3/3] Revert some of the visitors in codegen to test the
performance impact
---
clang/lib/CodeGen/CGDebugInfo.cpp | 21 ++++++++++---------
clang/lib/CodeGen/CodeGenModule.cpp | 21 ++++++++++---------
.../CodeGen/ObjectFilePCHContainerWriter.cpp | 14 ++++++-------
3 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 4a77edf95f46e..578d09f7971d6 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -25,9 +25,9 @@
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/RecordLayout.h"
+#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/VTableBuilder.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/SourceManager.h"
@@ -5697,9 +5697,10 @@ static bool ReferencesAnonymousEntity(ArrayRef<TemplateArgument> Args) {
case TemplateArgument::Pack:
return ReferencesAnonymousEntity(TA.getPackAsArray());
case TemplateArgument::Type: {
- struct ReferencesAnonymous : DynamicRecursiveASTVisitor {
+ struct ReferencesAnonymous
+ : public RecursiveASTVisitor<ReferencesAnonymous> {
bool RefAnon = false;
- bool VisitRecordType(RecordType *RT) override {
+ bool VisitRecordType(RecordType *RT) {
if (ReferencesAnonymousEntity(RT)) {
RefAnon = true;
return false;
@@ -5720,17 +5721,17 @@ static bool ReferencesAnonymousEntity(ArrayRef<TemplateArgument> Args) {
});
}
namespace {
-struct ReconstitutableType : DynamicRecursiveASTVisitor {
+struct ReconstitutableType : public RecursiveASTVisitor<ReconstitutableType> {
bool Reconstitutable = true;
- bool VisitVectorType(VectorType *FT) override {
+ bool VisitVectorType(VectorType *FT) {
Reconstitutable = false;
return false;
}
- bool VisitAtomicType(AtomicType *FT) override {
+ bool VisitAtomicType(AtomicType *FT) {
Reconstitutable = false;
return false;
}
- bool VisitType(Type *T) override {
+ bool VisitType(Type *T) {
// _BitInt(N) isn't reconstitutable because the bit width isn't encoded in
// the DWARF, only the byte width.
if (T->isBitIntType()) {
@@ -5739,7 +5740,7 @@ struct ReconstitutableType : DynamicRecursiveASTVisitor {
}
return true;
}
- bool TraverseEnumType(EnumType *ET, bool = false) override {
+ bool TraverseEnumType(EnumType *ET, bool = false) {
// Unnamed enums can't be reconstituted due to a lack of column info we
// produce in the DWARF, so we can't get Clang's full name back.
if (const auto *ED = dyn_cast<EnumDecl>(ET->getOriginalDecl())) {
@@ -5754,13 +5755,13 @@ struct ReconstitutableType : DynamicRecursiveASTVisitor {
}
return true;
}
- bool VisitFunctionProtoType(FunctionProtoType *FT) override {
+ bool VisitFunctionProtoType(FunctionProtoType *FT) {
// noexcept is not encoded in DWARF, so the reversi
Reconstitutable &= !isNoexceptExceptionSpec(FT->getExceptionSpecType());
Reconstitutable &= !FT->getNoReturnAttr();
return Reconstitutable;
}
- bool VisitRecordType(RecordType *RT) override {
+ bool VisitRecordType(RecordType *RT, bool = false) {
if (ReferencesAnonymousEntity(RT)) {
Reconstitutable = false;
return false;
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 5023b0a55da3e..0eac7c351b164 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -34,8 +34,8 @@
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Mangle.h"
+#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CodeGenOptions.h"
@@ -4266,12 +4266,13 @@ namespace {
};
// Make sure we're not referencing non-imported vars or functions.
- struct DLLImportFunctionVisitor : DynamicRecursiveASTVisitor {
+ struct DLLImportFunctionVisitor
+ : public RecursiveASTVisitor<DLLImportFunctionVisitor> {
bool SafeToInline = true;
- DLLImportFunctionVisitor() { ShouldVisitImplicitCode = true; }
+ bool shouldVisitImplicitCode() const { return true; }
- bool VisitVarDecl(VarDecl *VD) override {
+ bool VisitVarDecl(VarDecl *VD) {
if (VD->getTLSKind()) {
// A thread-local variable cannot be imported.
SafeToInline = false;
@@ -4285,13 +4286,13 @@ namespace {
return SafeToInline;
}
- bool VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) override {
+ bool VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
if (const auto *D = E->getTemporary()->getDestructor())
SafeToInline = D->hasAttr<DLLImportAttr>();
return SafeToInline;
}
- bool VisitDeclRefExpr(DeclRefExpr *E) override {
+ bool VisitDeclRefExpr(DeclRefExpr *E) {
ValueDecl *VD = E->getDecl();
if (isa<FunctionDecl>(VD))
SafeToInline = VD->hasAttr<DLLImportAttr>();
@@ -4300,12 +4301,12 @@ namespace {
return SafeToInline;
}
- bool VisitCXXConstructExpr(CXXConstructExpr *E) override {
+ bool VisitCXXConstructExpr(CXXConstructExpr *E) {
SafeToInline = E->getConstructor()->hasAttr<DLLImportAttr>();
return SafeToInline;
}
- bool VisitCXXMemberCallExpr(CXXMemberCallExpr *E) override {
+ bool VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
CXXMethodDecl *M = E->getMethodDecl();
if (!M) {
// Call through a pointer to member function. This is safe to inline.
@@ -4316,12 +4317,12 @@ namespace {
return SafeToInline;
}
- bool VisitCXXDeleteExpr(CXXDeleteExpr *E) override {
+ bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
SafeToInline = E->getOperatorDelete()->hasAttr<DLLImportAttr>();
return SafeToInline;
}
- bool VisitCXXNewExpr(CXXNewExpr *E) override {
+ bool VisitCXXNewExpr(CXXNewExpr *E) {
SafeToInline = E->getOperatorNew()->hasAttr<DLLImportAttr>();
return SafeToInline;
}
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index 2f26d64e73e97..074f2a520704d 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
@@ -11,8 +11,8 @@
#include "CodeGenModule.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
-#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
+#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
@@ -56,7 +56,7 @@ class PCHContainerGenerator : public ASTConsumer {
std::shared_ptr<PCHBuffer> Buffer;
/// Visit every type and emit debug info for it.
- struct DebugTypeVisitor : DynamicRecursiveASTVisitor {
+ struct DebugTypeVisitor : public RecursiveASTVisitor<DebugTypeVisitor> {
clang::CodeGen::CGDebugInfo &DI;
ASTContext &Ctx;
DebugTypeVisitor(clang::CodeGen::CGDebugInfo &DI, ASTContext &Ctx)
@@ -67,13 +67,13 @@ class PCHContainerGenerator : public ASTConsumer {
return !Ty->isDependentType() && !Ty->isUndeducedType();
}
- bool VisitImportDecl(ImportDecl *D) override {
+ bool VisitImportDecl(ImportDecl *D) {
if (!D->getImportedOwningModule())
DI.EmitImportDecl(*D);
return true;
}
- bool VisitTypeDecl(TypeDecl *D) override {
+ bool VisitTypeDecl(TypeDecl *D) {
// TagDecls may be deferred until after all decls have been merged and we
// know the complete type. Pure forward declarations will be skipped, but
// they don't need to be emitted into the module anyway.
@@ -90,14 +90,14 @@ class PCHContainerGenerator : public ASTConsumer {
return true;
}
- bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) override {
+ bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
QualType QualTy(D->getTypeForDecl(), 0);
if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
DI.getOrCreateStandaloneType(QualTy, D->getLocation());
return true;
}
- bool VisitFunctionDecl(FunctionDecl *D) override {
+ bool VisitFunctionDecl(FunctionDecl *D) {
// Skip deduction guides.
if (isa<CXXDeductionGuideDecl>(D))
return true;
@@ -118,7 +118,7 @@ class PCHContainerGenerator : public ASTConsumer {
return true;
}
- bool VisitObjCMethodDecl(ObjCMethodDecl *D) override {
+ bool VisitObjCMethodDecl(ObjCMethodDecl *D) {
if (!D->getClassInterface())
return true;
More information about the cfe-commits
mailing list