@@ -34,10 +34,10 @@ namespace clang::tidy::modernize {
34
34
// / RecursiveASTVisitor::TraverseStmt() and pop_back() afterwards. The Stmt atop
35
35
// / the stack is the parent of the current statement (NULL for the topmost
36
36
// / statement).
37
- bool StmtAncestorASTVisitor::TraverseStmt (Stmt *Statement) {
37
+ bool StmtAncestorASTVisitor::TraverseStmt (const Stmt *Statement) {
38
38
StmtAncestors.insert (std::make_pair (Statement, StmtStack.back ()));
39
39
StmtStack.push_back (Statement);
40
- RecursiveASTVisitor<StmtAncestorASTVisitor> ::TraverseStmt (Statement);
40
+ ConstDynamicRecursiveASTVisitor ::TraverseStmt (Statement);
41
41
StmtStack.pop_back ();
42
42
return true ;
43
43
}
@@ -47,7 +47,7 @@ bool StmtAncestorASTVisitor::TraverseStmt(Stmt *Statement) {
47
47
// / Combined with StmtAncestors, this provides roughly the same information as
48
48
// / Scope, as we can map a VarDecl to its DeclStmt, then walk up the parent tree
49
49
// / using StmtAncestors.
50
- bool StmtAncestorASTVisitor::VisitDeclStmt (DeclStmt *Statement) {
50
+ bool StmtAncestorASTVisitor::VisitDeclStmt (const DeclStmt *Statement) {
51
51
for (const auto *Decl : Statement->decls ()) {
52
52
if (const auto *V = dyn_cast<VarDecl>(Decl))
53
53
DeclParents.insert (std::make_pair (V, Statement));
@@ -56,27 +56,27 @@ bool StmtAncestorASTVisitor::VisitDeclStmt(DeclStmt *Statement) {
56
56
}
57
57
58
58
// / record the DeclRefExpr as part of the parent expression.
59
- bool ComponentFinderASTVisitor::VisitDeclRefExpr (DeclRefExpr *E) {
59
+ bool ComponentFinderASTVisitor::VisitDeclRefExpr (const DeclRefExpr *E) {
60
60
Components.push_back (E);
61
61
return true ;
62
62
}
63
63
64
64
// / record the MemberExpr as part of the parent expression.
65
- bool ComponentFinderASTVisitor::VisitMemberExpr (MemberExpr *Member) {
65
+ bool ComponentFinderASTVisitor::VisitMemberExpr (const MemberExpr *Member) {
66
66
Components.push_back (Member);
67
67
return true ;
68
68
}
69
69
70
70
// / Forward any DeclRefExprs to a check on the referenced variable
71
71
// / declaration.
72
- bool DependencyFinderASTVisitor::VisitDeclRefExpr (DeclRefExpr *DeclRef) {
72
+ bool DependencyFinderASTVisitor::VisitDeclRefExpr (const DeclRefExpr *DeclRef) {
73
73
if (auto *V = dyn_cast_or_null<VarDecl>(DeclRef->getDecl ()))
74
74
return VisitVarDecl (V);
75
75
return true ;
76
76
}
77
77
78
78
// / Determine if any this variable is declared inside the ContainingStmt.
79
- bool DependencyFinderASTVisitor::VisitVarDecl (VarDecl *V) {
79
+ bool DependencyFinderASTVisitor::VisitVarDecl (const VarDecl *V) {
80
80
const Stmt *Curr = DeclParents->lookup (V);
81
81
// First, see if the variable was declared within an inner scope of the loop.
82
82
while (Curr != nullptr ) {
@@ -100,7 +100,7 @@ bool DependencyFinderASTVisitor::VisitVarDecl(VarDecl *V) {
100
100
101
101
// / If we already created a variable for TheLoop, check to make sure
102
102
// / that the name was not already taken.
103
- bool DeclFinderASTVisitor::VisitForStmt (ForStmt *TheLoop) {
103
+ bool DeclFinderASTVisitor::VisitForStmt (const ForStmt *TheLoop) {
104
104
StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find (TheLoop);
105
105
if (I != GeneratedDecls->end () && I->second == Name) {
106
106
Found = true ;
@@ -111,7 +111,7 @@ bool DeclFinderASTVisitor::VisitForStmt(ForStmt *TheLoop) {
111
111
112
112
// / If any named declaration within the AST subtree has the same name,
113
113
// / then consider Name already taken.
114
- bool DeclFinderASTVisitor::VisitNamedDecl (NamedDecl *D) {
114
+ bool DeclFinderASTVisitor::VisitNamedDecl (const NamedDecl *D) {
115
115
const IdentifierInfo *Ident = D->getIdentifier ();
116
116
if (Ident && Ident->getName () == Name) {
117
117
Found = true ;
@@ -122,7 +122,7 @@ bool DeclFinderASTVisitor::VisitNamedDecl(NamedDecl *D) {
122
122
123
123
// / Forward any declaration references to the actual check on the
124
124
// / referenced declaration.
125
- bool DeclFinderASTVisitor::VisitDeclRefExpr (DeclRefExpr *DeclRef) {
125
+ bool DeclFinderASTVisitor::VisitDeclRefExpr (const DeclRefExpr *DeclRef) {
126
126
if (auto *D = dyn_cast<NamedDecl>(DeclRef->getDecl ()))
127
127
return VisitNamedDecl (D);
128
128
return true ;
@@ -497,7 +497,7 @@ void ForLoopIndexUseVisitor::addUsage(const Usage &U) {
497
497
// / int k = *i + 2;
498
498
// / }
499
499
// / \endcode
500
- bool ForLoopIndexUseVisitor::TraverseUnaryOperator (UnaryOperator *Uop) {
500
+ bool ForLoopIndexUseVisitor::TraverseUnaryOperator (const UnaryOperator *Uop) {
501
501
// If we dereference an iterator that's actually a pointer, count the
502
502
// occurrence.
503
503
if (isDereferenceOfUop (Uop, IndexVar)) {
@@ -533,7 +533,7 @@ bool ForLoopIndexUseVisitor::TraverseUnaryOperator(UnaryOperator *Uop) {
533
533
// / }
534
534
// / \endcode
535
535
// / will not.
536
- bool ForLoopIndexUseVisitor::TraverseMemberExpr (MemberExpr *Member) {
536
+ bool ForLoopIndexUseVisitor::TraverseMemberExpr (const MemberExpr *Member) {
537
537
const Expr *Base = Member->getBase ();
538
538
const DeclRefExpr *Obj = getDeclRef (Base);
539
539
const Expr *ResultExpr = Member;
@@ -593,8 +593,8 @@ bool ForLoopIndexUseVisitor::TraverseMemberExpr(MemberExpr *Member) {
593
593
// / Calls on the iterator object are not permitted, unless done through
594
594
// / operator->(). The one exception is allowing vector::at() for pseudoarrays.
595
595
bool ForLoopIndexUseVisitor::TraverseCXXMemberCallExpr (
596
- CXXMemberCallExpr *MemberCall) {
597
- auto *Member =
596
+ const CXXMemberCallExpr *MemberCall) {
597
+ const auto *Member =
598
598
dyn_cast<MemberExpr>(MemberCall->getCallee ()->IgnoreParenImpCasts ());
599
599
if (!Member)
600
600
return VisitorBase::TraverseCXXMemberCallExpr (MemberCall);
@@ -638,7 +638,7 @@ bool ForLoopIndexUseVisitor::TraverseCXXMemberCallExpr(
638
638
// / }
639
639
// / \endcode
640
640
bool ForLoopIndexUseVisitor::TraverseCXXOperatorCallExpr (
641
- CXXOperatorCallExpr *OpCall) {
641
+ const CXXOperatorCallExpr *OpCall) {
642
642
switch (OpCall->getOperator ()) {
643
643
case OO_Star:
644
644
if (isDereferenceOfOpCall (OpCall, IndexVar)) {
@@ -683,8 +683,8 @@ bool ForLoopIndexUseVisitor::TraverseCXXOperatorCallExpr(
683
683
// / \endcode
684
684
// / and further checking needs to be done later to ensure that exactly one array
685
685
// / is referenced.
686
- bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr (ArraySubscriptExpr *E) {
687
- Expr *Arr = E->getBase ();
686
+ bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr (const ArraySubscriptExpr *E) {
687
+ const Expr *Arr = E->getBase ();
688
688
if (!isIndexInSubscriptExpr (E->getIdx (), IndexVar))
689
689
return VisitorBase::TraverseArraySubscriptExpr (E);
690
690
@@ -737,7 +737,7 @@ bool ForLoopIndexUseVisitor::TraverseArraySubscriptExpr(ArraySubscriptExpr *E) {
737
737
// / for (int i = 0; i < obj.getVector().size(); ++i)
738
738
// / obj.foo(10); // using `obj` is considered risky
739
739
// / \endcode
740
- bool ForLoopIndexUseVisitor::VisitDeclRefExpr (DeclRefExpr *E) {
740
+ bool ForLoopIndexUseVisitor::VisitDeclRefExpr (const DeclRefExpr *E) {
741
741
const ValueDecl *TheDecl = E->getDecl ();
742
742
if (areSameVariable (IndexVar, TheDecl) ||
743
743
exprReferencesVariable (IndexVar, E) || areSameVariable (EndVar, TheDecl) ||
@@ -770,9 +770,9 @@ bool ForLoopIndexUseVisitor::VisitDeclRefExpr(DeclRefExpr *E) {
770
770
// / f(elem);
771
771
// / }
772
772
// / \endcode
773
- bool ForLoopIndexUseVisitor::TraverseLambdaCapture (LambdaExpr *LE,
773
+ bool ForLoopIndexUseVisitor::TraverseLambdaCapture (const LambdaExpr *LE,
774
774
const LambdaCapture *C,
775
- Expr *Init) {
775
+ const Expr *Init) {
776
776
if (C->capturesVariable ()) {
777
777
ValueDecl *VDecl = C->getCapturedVar ();
778
778
if (areSameVariable (IndexVar, VDecl)) {
@@ -785,7 +785,7 @@ bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
785
785
C->getLocation ()));
786
786
}
787
787
if (VDecl->isInitCapture ())
788
- TraverseStmtImpl (cast<VarDecl>(VDecl)->getInit ());
788
+ traverseStmtImpl (cast<VarDecl>(VDecl)->getInit ());
789
789
}
790
790
return VisitorBase::TraverseLambdaCapture (LE, C, Init);
791
791
}
@@ -794,7 +794,7 @@ bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
794
794
// / element, note it for reuse as the loop variable.
795
795
// /
796
796
// / See the comments for isAliasDecl.
797
- bool ForLoopIndexUseVisitor::VisitDeclStmt (DeclStmt *S) {
797
+ bool ForLoopIndexUseVisitor::VisitDeclStmt (const DeclStmt *S) {
798
798
if (!AliasDecl && S->isSingleDecl () &&
799
799
isAliasDecl (Context, S->getSingleDecl (), IndexVar)) {
800
800
AliasDecl = S;
@@ -815,7 +815,7 @@ bool ForLoopIndexUseVisitor::VisitDeclStmt(DeclStmt *S) {
815
815
return true ;
816
816
}
817
817
818
- bool ForLoopIndexUseVisitor::TraverseStmtImpl ( Stmt *S) {
818
+ bool ForLoopIndexUseVisitor::traverseStmtImpl ( const Stmt *S) {
819
819
// All this pointer swapping is a mechanism for tracking immediate parentage
820
820
// of Stmts.
821
821
const Stmt *OldNextParent = NextStmtParent;
@@ -826,7 +826,7 @@ bool ForLoopIndexUseVisitor::TraverseStmtImpl(Stmt *S) {
826
826
return Result;
827
827
}
828
828
829
- bool ForLoopIndexUseVisitor::TraverseStmt (Stmt *S) {
829
+ bool ForLoopIndexUseVisitor::TraverseStmt (const Stmt *S) {
830
830
// If this is an initialization expression for a lambda capture, prune the
831
831
// traversal so that we don't end up diagnosing the contained DeclRefExpr as
832
832
// inconsistent usage. No need to record the usage here -- this is done in
@@ -838,7 +838,7 @@ bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
838
838
return true ;
839
839
}
840
840
}
841
- return TraverseStmtImpl (S);
841
+ return traverseStmtImpl (S);
842
842
}
843
843
844
844
std::string VariableNamer::createIndexName () {
0 commit comments