Skip to content

Commit 7873d3b

Browse files
authored
Revert "[Clang] [NFC] Introduce ConstDynamicRecursiveASTVisitor" (#124667)
Reverts #122991 One of the bots is breaking; I’ll have to investigate what the issue is; this might be because I haven’t updated the branch in a while.
1 parent 8900c09 commit 7873d3b

File tree

3 files changed

+210
-161
lines changed

3 files changed

+210
-161
lines changed

clang/include/clang/AST/DynamicRecursiveASTVisitor.h

Lines changed: 43 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ class ASTContext;
5252
/// WalkUpFromX or post-order traversal).
5353
///
5454
/// \see RecursiveASTVisitor.
55-
template <bool IsConst> class DynamicRecursiveASTVisitorBase {
56-
protected:
57-
template <typename ASTNode>
58-
using MaybeConst = std::conditional_t<IsConst, const ASTNode, ASTNode>;
59-
55+
class DynamicRecursiveASTVisitor {
6056
public:
6157
/// Whether this visitor should recurse into template instantiations.
6258
bool ShouldVisitTemplateInstantiations = false;
@@ -72,38 +68,36 @@ template <bool IsConst> class DynamicRecursiveASTVisitorBase {
7268
bool ShouldVisitLambdaBody = true;
7369

7470
protected:
75-
DynamicRecursiveASTVisitorBase() = default;
76-
DynamicRecursiveASTVisitorBase(DynamicRecursiveASTVisitorBase &&) = default;
77-
DynamicRecursiveASTVisitorBase(const DynamicRecursiveASTVisitorBase &) =
78-
default;
79-
DynamicRecursiveASTVisitorBase &
80-
operator=(DynamicRecursiveASTVisitorBase &&) = default;
81-
DynamicRecursiveASTVisitorBase &
82-
operator=(const DynamicRecursiveASTVisitorBase &) = default;
71+
DynamicRecursiveASTVisitor() = default;
72+
DynamicRecursiveASTVisitor(DynamicRecursiveASTVisitor &&) = default;
73+
DynamicRecursiveASTVisitor(const DynamicRecursiveASTVisitor &) = default;
74+
DynamicRecursiveASTVisitor &
75+
operator=(DynamicRecursiveASTVisitor &&) = default;
76+
DynamicRecursiveASTVisitor &
77+
operator=(const DynamicRecursiveASTVisitor &) = default;
8378

8479
public:
8580
virtual void anchor();
86-
virtual ~DynamicRecursiveASTVisitorBase() = default;
81+
virtual ~DynamicRecursiveASTVisitor() = default;
8782

8883
/// Recursively visits an entire AST, starting from the TranslationUnitDecl.
8984
/// \returns false if visitation was terminated early.
90-
virtual bool TraverseAST(MaybeConst<ASTContext> &AST);
85+
virtual bool TraverseAST(ASTContext &AST);
9186

9287
/// Recursively visit an attribute, by dispatching to
9388
/// Traverse*Attr() based on the argument's dynamic type.
9489
///
9590
/// \returns false if the visitation was terminated early, true
9691
/// otherwise (including when the argument is a Null type location).
97-
virtual bool TraverseAttr(MaybeConst<Attr> *At);
92+
virtual bool TraverseAttr(Attr *At);
9893

9994
/// Recursively visit a constructor initializer. This
10095
/// automatically dispatches to another visitor for the initializer
10196
/// expression, but not for the name of the initializer, so may
10297
/// be overridden for clients that need access to the name.
10398
///
10499
/// \returns false if the visitation was terminated early, true otherwise.
105-
virtual bool
106-
TraverseConstructorInitializer(MaybeConst<CXXCtorInitializer> *Init);
100+
virtual bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
107101

108102
/// Recursively visit a base specifier. This can be overridden by a
109103
/// subclass.
@@ -116,7 +110,7 @@ template <bool IsConst> class DynamicRecursiveASTVisitorBase {
116110
///
117111
/// \returns false if the visitation was terminated early, true
118112
/// otherwise (including when the argument is NULL).
119-
virtual bool TraverseDecl(MaybeConst<Decl> *D);
113+
virtual bool TraverseDecl(Decl *D);
120114

121115
/// Recursively visit a name with its location information.
122116
///
@@ -127,15 +121,13 @@ template <bool IsConst> class DynamicRecursiveASTVisitorBase {
127121
/// will be used to initialize the capture.
128122
///
129123
/// \returns false if the visitation was terminated early, true otherwise.
130-
virtual bool TraverseLambdaCapture(MaybeConst<LambdaExpr> *LE,
131-
const LambdaCapture *C,
132-
MaybeConst<Expr> *Init);
124+
virtual bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
125+
Expr *Init);
133126

134127
/// Recursively visit a C++ nested-name-specifier.
135128
///
136129
/// \returns false if the visitation was terminated early, true otherwise.
137-
virtual bool
138-
TraverseNestedNameSpecifier(MaybeConst<NestedNameSpecifier> *NNS);
130+
virtual bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
139131

140132
/// Recursively visit a C++ nested-name-specifier with location
141133
/// information.
@@ -148,7 +140,7 @@ template <bool IsConst> class DynamicRecursiveASTVisitorBase {
148140
///
149141
/// \returns false if the visitation was terminated early, true
150142
/// otherwise (including when the argument is nullptr).
151-
virtual bool TraverseStmt(MaybeConst<Stmt> *S);
143+
virtual bool TraverseStmt(Stmt *S);
152144

153145
/// Recursively visit a template argument and dispatch to the
154146
/// appropriate method for the argument type.
@@ -198,86 +190,74 @@ template <bool IsConst> class DynamicRecursiveASTVisitorBase {
198190

199191
/// Traverse a concept (requirement).
200192
virtual bool TraverseTypeConstraint(const TypeConstraint *C);
201-
virtual bool TraverseConceptRequirement(MaybeConst<concepts::Requirement> *R);
202-
203-
virtual bool
204-
TraverseConceptTypeRequirement(MaybeConst<concepts::TypeRequirement> *R);
205-
206-
virtual bool
207-
TraverseConceptExprRequirement(MaybeConst<concepts::ExprRequirement> *R);
208-
209-
virtual bool
210-
TraverseConceptNestedRequirement(MaybeConst<concepts::NestedRequirement> *R);
211-
212-
virtual bool TraverseConceptReference(MaybeConst<ConceptReference> *CR);
213-
virtual bool VisitConceptReference(MaybeConst<ConceptReference> *CR) {
214-
return true;
215-
}
193+
virtual bool TraverseConceptRequirement(concepts::Requirement *R);
194+
virtual bool TraverseConceptTypeRequirement(concepts::TypeRequirement *R);
195+
virtual bool TraverseConceptExprRequirement(concepts::ExprRequirement *R);
196+
virtual bool TraverseConceptNestedRequirement(concepts::NestedRequirement *R);
197+
virtual bool TraverseConceptReference(ConceptReference *CR);
198+
virtual bool VisitConceptReference(ConceptReference *CR) { return true; }
216199

217200
/// Visit a node.
218-
virtual bool VisitAttr(MaybeConst<Attr> *A) { return true; }
219-
virtual bool VisitDecl(MaybeConst<Decl> *D) { return true; }
220-
virtual bool VisitStmt(MaybeConst<Stmt> *S) { return true; }
221-
virtual bool VisitType(MaybeConst<Type> *T) { return true; }
201+
virtual bool VisitAttr(Attr *A) { return true; }
202+
virtual bool VisitDecl(Decl *D) { return true; }
203+
virtual bool VisitStmt(Stmt *S) { return true; }
204+
virtual bool VisitType(Type *T) { return true; }
222205
virtual bool VisitTypeLoc(TypeLoc TL) { return true; }
223206

224207
/// Walk up from a node.
225-
bool WalkUpFromDecl(MaybeConst<Decl> *D) { return VisitDecl(D); }
226-
bool WalkUpFromStmt(MaybeConst<Stmt> *S) { return VisitStmt(S); }
227-
bool WalkUpFromType(MaybeConst<Type> *T) { return VisitType(T); }
208+
bool WalkUpFromDecl(Decl *D) { return VisitDecl(D); }
209+
bool WalkUpFromStmt(Stmt *S) { return VisitStmt(S); }
210+
bool WalkUpFromType(Type *T) { return VisitType(T); }
228211
bool WalkUpFromTypeLoc(TypeLoc TL) { return VisitTypeLoc(TL); }
229212

230213
/// Invoked before visiting a statement or expression via data recursion.
231214
///
232215
/// \returns false to skip visiting the node, true otherwise.
233-
virtual bool dataTraverseStmtPre(MaybeConst<Stmt> *S) { return true; }
216+
virtual bool dataTraverseStmtPre(Stmt *S) { return true; }
234217

235218
/// Invoked after visiting a statement or expression via data recursion.
236219
/// This is not invoked if the previously invoked \c dataTraverseStmtPre
237220
/// returned false.
238221
///
239222
/// \returns false if the visitation was terminated early, true otherwise.
240-
virtual bool dataTraverseStmtPost(MaybeConst<Stmt> *S) { return true; }
241-
virtual bool dataTraverseNode(MaybeConst<Stmt> *S);
223+
virtual bool dataTraverseStmtPost(Stmt *S) { return true; }
224+
virtual bool dataTraverseNode(Stmt *S);
242225

243226
#define DEF_TRAVERSE_TMPL_INST(kind) \
244-
virtual bool TraverseTemplateInstantiations( \
245-
MaybeConst<kind##TemplateDecl> *D);
227+
virtual bool TraverseTemplateInstantiations(kind##TemplateDecl *D);
246228
DEF_TRAVERSE_TMPL_INST(Class)
247229
DEF_TRAVERSE_TMPL_INST(Var)
248230
DEF_TRAVERSE_TMPL_INST(Function)
249231
#undef DEF_TRAVERSE_TMPL_INST
250232

251233
// Decls.
252234
#define ABSTRACT_DECL(DECL)
253-
#define DECL(CLASS, BASE) \
254-
virtual bool Traverse##CLASS##Decl(MaybeConst<CLASS##Decl> *D);
235+
#define DECL(CLASS, BASE) virtual bool Traverse##CLASS##Decl(CLASS##Decl *D);
255236
#include "clang/AST/DeclNodes.inc"
256237

257238
#define DECL(CLASS, BASE) \
258-
bool WalkUpFrom##CLASS##Decl(MaybeConst<CLASS##Decl> *D); \
259-
virtual bool Visit##CLASS##Decl(MaybeConst<CLASS##Decl> *D) { return true; }
239+
bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D); \
240+
virtual bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
260241
#include "clang/AST/DeclNodes.inc"
261242

262243
// Stmts.
263244
#define ABSTRACT_STMT(STMT)
264-
#define STMT(CLASS, PARENT) virtual bool Traverse##CLASS(MaybeConst<CLASS> *S);
245+
#define STMT(CLASS, PARENT) virtual bool Traverse##CLASS(CLASS *S);
265246
#include "clang/AST/StmtNodes.inc"
266247

267248
#define STMT(CLASS, PARENT) \
268-
bool WalkUpFrom##CLASS(MaybeConst<CLASS> *S); \
269-
virtual bool Visit##CLASS(MaybeConst<CLASS> *S) { return true; }
249+
bool WalkUpFrom##CLASS(CLASS *S); \
250+
virtual bool Visit##CLASS(CLASS *S) { return true; }
270251
#include "clang/AST/StmtNodes.inc"
271252

272253
// Types.
273254
#define ABSTRACT_TYPE(CLASS, BASE)
274-
#define TYPE(CLASS, BASE) \
275-
virtual bool Traverse##CLASS##Type(MaybeConst<CLASS##Type> *T);
255+
#define TYPE(CLASS, BASE) virtual bool Traverse##CLASS##Type(CLASS##Type *T);
276256
#include "clang/AST/TypeNodes.inc"
277257

278258
#define TYPE(CLASS, BASE) \
279-
bool WalkUpFrom##CLASS##Type(MaybeConst<CLASS##Type> *T); \
280-
virtual bool Visit##CLASS##Type(MaybeConst<CLASS##Type> *T) { return true; }
259+
bool WalkUpFrom##CLASS##Type(CLASS##Type *T); \
260+
virtual bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
281261
#include "clang/AST/TypeNodes.inc"
282262

283263
// TypeLocs.
@@ -291,14 +271,6 @@ template <bool IsConst> class DynamicRecursiveASTVisitorBase {
291271
virtual bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
292272
#include "clang/AST/TypeLocNodes.def"
293273
};
294-
295-
extern template class DynamicRecursiveASTVisitorBase<false>;
296-
extern template class DynamicRecursiveASTVisitorBase<true>;
297-
298-
using DynamicRecursiveASTVisitor =
299-
DynamicRecursiveASTVisitorBase</*Const=*/false>;
300-
using ConstDynamicRecursiveASTVisitor =
301-
DynamicRecursiveASTVisitorBase</*Const=*/true>;
302274
} // namespace clang
303275

304276
#endif // LLVM_CLANG_AST_DYNAMIC_RECURSIVE_AST_VISITOR_H

0 commit comments

Comments
 (0)