Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions clang-tools-extra/clang-doc/Mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,37 +21,34 @@ 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:
explicit ConditionVisitor(AssignmentInIfConditionCheck &Check)
: Check(Check) {}

// Dont traverse into any lambda expressions.
bool TraverseLambdaExpr(LambdaExpr *, DataRecursionQueue * = nullptr) {
return true;
}
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -1612,21 +1612,21 @@ 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 {
return lazyMapOfSetsIntersectionExists(ParentExprsForParamRefs, Param1,
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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
51 changes: 26 additions & 25 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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));
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -683,8 +683,9 @@ 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);

Expand Down Expand Up @@ -737,7 +738,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) ||
Expand Down Expand Up @@ -770,9 +771,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)) {
Expand All @@ -785,7 +786,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);
}
Expand All @@ -794,7 +795,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;
Expand All @@ -815,7 +816,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;
Expand All @@ -826,7 +827,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
Expand All @@ -838,7 +839,7 @@ bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
return true;
}
}
return TraverseStmtImpl(S);
return traverseStmtImpl(S);
}

std::string VariableNamer::createIndexName() {
Expand Down
Loading
Loading