From: Alp Toker Date: Sun, 18 May 2014 18:38:08 +0000 (+0000) Subject: Begin RAV reunification: s/DataRecursiveASTVisitor/RecursiveASTVisitor/ X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4db4ffda2372348e2021a097870ff51d42068621;p=clang Begin RAV reunification: s/DataRecursiveASTVisitor/RecursiveASTVisitor/ Define a macro to reduce the delta between RecursiveASTVisitor and DataRecursiveASTVisitor. Some years ago, someone thought it was a good idea to copy the entire RAV to support cursor visitation in libclang. Since then the two have diverged needlessly and the rest is history. This series of commits aims to reduce delta between the two so that we can reason about their differences, apply bugfixes that were only made to one but not the other, and ultimately find a way to unify two two chunks of code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209091 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 57d1e2acd0..2e59e2898f 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -69,9 +69,13 @@ namespace clang { +// Reduce the diff between RecursiveASTVisitor / DataRecursiveASTVisitor to +// make it easier to track changes and keep the two in sync. +#define RecursiveASTVisitor DataRecursiveASTVisitor + // A helper macro to implement short-circuiting when recursing. It // invokes CALL_EXPR, which must be a method call, on the derived -// object (s.t. a user of DataRecursiveASTVisitor can override the method +// object (s.t. a user of RecursiveASTVisitor can override the method // in CALL_EXPR). #define TRY_TO(CALL_EXPR) \ do { if (!getDerived().CALL_EXPR) return false; } while (0) @@ -141,7 +145,7 @@ namespace clang { /// instantiations will be visited at the same time as the pattern /// from which they were produced. template -class DataRecursiveASTVisitor { +class RecursiveASTVisitor { public: /// \brief Return a reference to the derived class. Derived &getDerived() { return *static_cast(this); } @@ -438,9 +442,9 @@ private: QueuesTy Queues; class NewQueueRAII { - DataRecursiveASTVisitor &RAV; + RecursiveASTVisitor &RAV; public: - NewQueueRAII(StmtsTy &queue, DataRecursiveASTVisitor &RAV) : RAV(RAV) { + NewQueueRAII(StmtsTy &queue, RecursiveASTVisitor &RAV) : RAV(RAV) { RAV.Queues.push_back(&queue); } ~NewQueueRAII() { @@ -457,7 +461,7 @@ public: class StmtQueueAction { StmtsTy &CurrQueue; public: - explicit StmtQueueAction(DataRecursiveASTVisitor &RAV) + explicit StmtQueueAction(RecursiveASTVisitor &RAV) : CurrQueue(RAV.getCurrentQueue()) { } void queue(Stmt *S) { @@ -470,7 +474,7 @@ public: return getDerived().Traverse##NAME(static_cast(VAR)) template -bool DataRecursiveASTVisitor::TraverseStmt(Stmt *S) { +bool RecursiveASTVisitor::TraverseStmt(Stmt *S) { if (!S) return true; @@ -539,7 +543,7 @@ bool DataRecursiveASTVisitor::TraverseStmt(Stmt *S) { } template -bool DataRecursiveASTVisitor::TraverseType(QualType T) { +bool RecursiveASTVisitor::TraverseType(QualType T) { if (T.isNull()) return true; @@ -555,7 +559,7 @@ bool DataRecursiveASTVisitor::TraverseType(QualType T) { } template -bool DataRecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { +bool RecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { if (TL.isNull()) return true; @@ -572,12 +576,12 @@ bool DataRecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { // Define the Traverse*Attr(Attr* A) methods -#define VISITORCLASS DataRecursiveASTVisitor +#define VISITORCLASS RecursiveASTVisitor #include "clang/AST/AttrVisitor.inc" #undef VISITORCLASS template -bool DataRecursiveASTVisitor::TraverseDecl(Decl *D) { +bool RecursiveASTVisitor::TraverseDecl(Decl *D) { if (!D) return true; @@ -608,7 +612,7 @@ bool DataRecursiveASTVisitor::TraverseDecl(Decl *D) { #undef DISPATCH template -bool DataRecursiveASTVisitor::TraverseNestedNameSpecifier( +bool RecursiveASTVisitor::TraverseNestedNameSpecifier( NestedNameSpecifier *NNS) { if (!NNS) return true; @@ -632,7 +636,7 @@ bool DataRecursiveASTVisitor::TraverseNestedNameSpecifier( } template -bool DataRecursiveASTVisitor::TraverseNestedNameSpecifierLoc( +bool RecursiveASTVisitor::TraverseNestedNameSpecifierLoc( NestedNameSpecifierLoc NNS) { if (!NNS) return true; @@ -657,7 +661,7 @@ bool DataRecursiveASTVisitor::TraverseNestedNameSpecifierLoc( } template -bool DataRecursiveASTVisitor::TraverseDeclarationNameInfo( +bool RecursiveASTVisitor::TraverseDeclarationNameInfo( DeclarationNameInfo NameInfo) { switch (NameInfo.getName().getNameKind()) { case DeclarationName::CXXConstructorName: @@ -682,7 +686,7 @@ bool DataRecursiveASTVisitor::TraverseDeclarationNameInfo( } template -bool DataRecursiveASTVisitor::TraverseTemplateName(TemplateName Template) { +bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) { if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier())); else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) @@ -692,7 +696,7 @@ bool DataRecursiveASTVisitor::TraverseTemplateName(TemplateName Templat } template -bool DataRecursiveASTVisitor::TraverseTemplateArgument( +bool RecursiveASTVisitor::TraverseTemplateArgument( const TemplateArgument &Arg) { switch (Arg.getKind()) { case TemplateArgument::Null: @@ -723,7 +727,7 @@ bool DataRecursiveASTVisitor::TraverseTemplateArgument( // FIXME: no template name location? // FIXME: no source locations for a template argument pack? template -bool DataRecursiveASTVisitor::TraverseTemplateArgumentLoc( +bool RecursiveASTVisitor::TraverseTemplateArgumentLoc( const TemplateArgumentLoc &ArgLoc) { const TemplateArgument &Arg = ArgLoc.getArgument(); @@ -762,7 +766,7 @@ bool DataRecursiveASTVisitor::TraverseTemplateArgumentLoc( } template -bool DataRecursiveASTVisitor::TraverseTemplateArguments( +bool RecursiveASTVisitor::TraverseTemplateArguments( const TemplateArgument *Args, unsigned NumArgs) { for (unsigned I = 0; I != NumArgs; ++I) { @@ -773,7 +777,7 @@ bool DataRecursiveASTVisitor::TraverseTemplateArguments( } template -bool DataRecursiveASTVisitor::TraverseConstructorInitializer( +bool RecursiveASTVisitor::TraverseConstructorInitializer( CXXCtorInitializer *Init) { if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); @@ -784,7 +788,7 @@ bool DataRecursiveASTVisitor::TraverseConstructorInitializer( } template -bool DataRecursiveASTVisitor::TraverseLambdaCapture(LambdaCapture C) { +bool RecursiveASTVisitor::TraverseLambdaCapture(LambdaCapture C) { return true; } @@ -793,7 +797,7 @@ bool DataRecursiveASTVisitor::TraverseLambdaCapture(LambdaCapture C) { // This macro makes available a variable T, the passed-in type. #define DEF_TRAVERSE_TYPE(TYPE, CODE) \ template \ - bool DataRecursiveASTVisitor::Traverse##TYPE (TYPE *T) { \ + bool RecursiveASTVisitor::Traverse##TYPE (TYPE *T) { \ TRY_TO(WalkUpFrom##TYPE (T)); \ { CODE; } \ return true; \ @@ -975,7 +979,7 @@ DEF_TRAVERSE_TYPE(AtomicType, { // continue to work. #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \ template \ - bool DataRecursiveASTVisitor::Traverse##TYPE##Loc(TYPE##Loc TL) { \ + bool RecursiveASTVisitor::Traverse##TYPE##Loc(TYPE##Loc TL) { \ if (getDerived().shouldWalkTypesOfTypeLocs()) \ TRY_TO(WalkUpFrom##TYPE(const_cast(TL.getTypePtr()))); \ TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \ @@ -984,7 +988,7 @@ DEF_TRAVERSE_TYPE(AtomicType, { } template -bool DataRecursiveASTVisitor::TraverseQualifiedTypeLoc( +bool RecursiveASTVisitor::TraverseQualifiedTypeLoc( QualifiedTypeLoc TL) { // Move this over to the 'main' typeloc tree. Note that this is a // move -- we pretend that we were really looking at the unqualified @@ -1044,7 +1048,7 @@ DEF_TRAVERSE_TYPELOC(AdjustedType, { }) template -bool DataRecursiveASTVisitor::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { +bool RecursiveASTVisitor::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { // This isn't available for ArrayType, but is for the ArrayTypeLoc. TRY_TO(TraverseStmt(TL.getSizeExpr())); return true; @@ -1212,7 +1216,7 @@ DEF_TRAVERSE_TYPELOC(AtomicType, { // than those. template -bool DataRecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC) { +bool RecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC) { if (!DC) return true; @@ -1229,7 +1233,7 @@ bool DataRecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC // This macro makes available a variable D, the passed-in decl. #define DEF_TRAVERSE_DECL(DECL, CODE) \ template \ -bool DataRecursiveASTVisitor::Traverse##DECL (DECL *D) { \ +bool RecursiveASTVisitor::Traverse##DECL (DECL *D) { \ TRY_TO(WalkUpFrom##DECL (D)); \ { CODE; } \ TRY_TO(TraverseDeclContextHelper(dyn_cast(D))); \ @@ -1390,7 +1394,7 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, { // A helper method for TemplateDecl's children. template -bool DataRecursiveASTVisitor::TraverseTemplateParameterListHelper( +bool RecursiveASTVisitor::TraverseTemplateParameterListHelper( TemplateParameterList *TPL) { if (TPL) { for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); @@ -1404,7 +1408,7 @@ bool DataRecursiveASTVisitor::TraverseTemplateParameterListHelper( // A helper method for traversing the implicit instantiations of a // class template. template -bool DataRecursiveASTVisitor::TraverseClassInstantiations( +bool RecursiveASTVisitor::TraverseClassInstantiations( ClassTemplateDecl *D) { for (auto *SD : D->specializations()) { for (auto *RD : SD->redecls()) { @@ -1457,7 +1461,7 @@ DEF_TRAVERSE_DECL(ClassTemplateDecl, { // A helper method for traversing the implicit instantiations of a // class template. template -bool DataRecursiveASTVisitor::TraverseVariableInstantiations( +bool RecursiveASTVisitor::TraverseVariableInstantiations( VarTemplateDecl *D) { for (auto *SD : D->specializations()) { for (auto *RD : SD->redecls()) { @@ -1508,7 +1512,7 @@ DEF_TRAVERSE_DECL( // A helper method for traversing the instantiations of a // function while skipping its specializations. template -bool DataRecursiveASTVisitor::TraverseFunctionInstantiations( +bool RecursiveASTVisitor::TraverseFunctionInstantiations( FunctionTemplateDecl *D) { for (auto *FD : D->specializations()) { for (auto *RD : FD->redecls()) { @@ -1609,7 +1613,7 @@ DEF_TRAVERSE_DECL(EnumDecl, { // Helper methods for RecordDecl and its children. template -bool DataRecursiveASTVisitor::TraverseRecordHelper( +bool RecursiveASTVisitor::TraverseRecordHelper( RecordDecl *D) { // We shouldn't traverse D->getTypeForDecl(); it's a result of // declaring the type, not something that was written in the source. @@ -1619,7 +1623,7 @@ bool DataRecursiveASTVisitor::TraverseRecordHelper( } template -bool DataRecursiveASTVisitor::TraverseCXXRecordHelper( +bool RecursiveASTVisitor::TraverseCXXRecordHelper( CXXRecordDecl *D) { if (!TraverseRecordHelper(D)) return false; @@ -1663,7 +1667,7 @@ DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, { }) template -bool DataRecursiveASTVisitor::TraverseTemplateArgumentLocsHelper( +bool RecursiveASTVisitor::TraverseTemplateArgumentLocsHelper( const TemplateArgumentLoc *TAL, unsigned Count) { for (unsigned I = 0; I < Count; ++I) { TRY_TO(TraverseTemplateArgumentLoc(TAL[I])); @@ -1706,7 +1710,7 @@ DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, { DEF_TRAVERSE_DECL(IndirectFieldDecl, {}) template -bool DataRecursiveASTVisitor::TraverseDeclaratorHelper(DeclaratorDecl *D) { +bool RecursiveASTVisitor::TraverseDeclaratorHelper(DeclaratorDecl *D) { TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); if (D->getTypeSourceInfo()) TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); @@ -1742,7 +1746,7 @@ DEF_TRAVERSE_DECL(ObjCIvarDecl, { }) template -bool DataRecursiveASTVisitor::TraverseFunctionHelper(FunctionDecl *D) { +bool RecursiveASTVisitor::TraverseFunctionHelper(FunctionDecl *D) { TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); @@ -1817,7 +1821,7 @@ DEF_TRAVERSE_DECL(CXXDestructorDecl, { }) template -bool DataRecursiveASTVisitor::TraverseVarHelper(VarDecl *D) { +bool RecursiveASTVisitor::TraverseVarHelper(VarDecl *D) { TRY_TO(TraverseDeclaratorHelper(D)); // Default params are taken care of when we traverse the ParmVarDecl. if (!isa(D)) @@ -1905,7 +1909,7 @@ DEF_TRAVERSE_DECL(ParmVarDecl, { // This macro makes available a variable S, the passed-in stmt. #define DEF_TRAVERSE_STMT(STMT, CODE) \ template \ -bool DataRecursiveASTVisitor::Traverse##STMT (STMT *S) { \ +bool RecursiveASTVisitor::Traverse##STMT (STMT *S) { \ TRY_TO(WalkUpFrom##STMT(S)); \ StmtQueueAction StmtQueue(*this); \ { CODE; } \ @@ -2052,7 +2056,7 @@ DEF_TRAVERSE_STMT(CXXStaticCastExpr, { // calls WalkUp*() on the semantic form, before our code can convert // to the syntactic form. template -bool DataRecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { +bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { if (InitListExpr *Syn = S->getSyntacticForm()) S = Syn; TRY_TO(WalkUpFromInitListExpr(S)); @@ -2068,7 +2072,7 @@ bool DataRecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { // are interleaved. We also need to watch out for null types (default // generic associations). template -bool DataRecursiveASTVisitor:: +bool RecursiveASTVisitor:: TraverseGenericSelectionExpr(GenericSelectionExpr *S) { TRY_TO(WalkUpFromGenericSelectionExpr(S)); StmtQueueAction StmtQueue(*this); @@ -2084,7 +2088,7 @@ TraverseGenericSelectionExpr(GenericSelectionExpr *S) { // PseudoObjectExpr is a special case because of the wierdness with // syntactic expressions and opaque values. template -bool DataRecursiveASTVisitor:: +bool RecursiveASTVisitor:: TraversePseudoObjectExpr(PseudoObjectExpr *S) { TRY_TO(WalkUpFromPseudoObjectExpr(S)); StmtQueueAction StmtQueue(*this); @@ -2164,7 +2168,7 @@ DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, { // Walk only the visible parts of lambda expressions. template -bool DataRecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { +bool RecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { TRY_TO(WalkUpFromLambdaExpr(S)); for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), @@ -2323,7 +2327,7 @@ DEF_TRAVERSE_STMT(AsTypeExpr, { }) // OpenMP directives. template -bool DataRecursiveASTVisitor::TraverseOMPExecutableDirective( +bool RecursiveASTVisitor::TraverseOMPExecutableDirective( OMPExecutableDirective *S) { ArrayRef Clauses = S->clauses(); for (ArrayRef::iterator I = Clauses.begin(), E = Clauses.end(); @@ -2342,7 +2346,7 @@ DEF_TRAVERSE_STMT(OMPSimdDirective, { // OpenMP clauses. template -bool DataRecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { +bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { if (!C) return true; switch (C->getClauseKind()) { #define OPENMP_CLAUSE(Name, Class) \ @@ -2355,72 +2359,72 @@ bool DataRecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { } template -bool DataRecursiveASTVisitor::VisitOMPIfClause(OMPIfClause *C) { +bool RecursiveASTVisitor::VisitOMPIfClause(OMPIfClause *C) { TraverseStmt(C->getCondition()); return true; } template -bool DataRecursiveASTVisitor::VisitOMPNumThreadsClause( +bool RecursiveASTVisitor::VisitOMPNumThreadsClause( OMPNumThreadsClause *C) { TraverseStmt(C->getNumThreads()); return true; } template -bool DataRecursiveASTVisitor::VisitOMPSafelenClause( +bool RecursiveASTVisitor::VisitOMPSafelenClause( OMPSafelenClause *C) { TraverseStmt(C->getSafelen()); return true; } template -bool DataRecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { +bool RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { return true; } template bool -DataRecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *C) { +RecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *C) { return true; } template template -void DataRecursiveASTVisitor::VisitOMPClauseList(T *Node) { +void RecursiveASTVisitor::VisitOMPClauseList(T *Node) { for (auto *I : Node->varlists()) TraverseStmt(I); } template -bool DataRecursiveASTVisitor::VisitOMPPrivateClause(OMPPrivateClause *C) { +bool RecursiveASTVisitor::VisitOMPPrivateClause(OMPPrivateClause *C) { VisitOMPClauseList(C); return true; } template -bool DataRecursiveASTVisitor::VisitOMPFirstprivateClause( +bool RecursiveASTVisitor::VisitOMPFirstprivateClause( OMPFirstprivateClause *C) { VisitOMPClauseList(C); return true; } template -bool DataRecursiveASTVisitor::VisitOMPSharedClause(OMPSharedClause *C) { +bool RecursiveASTVisitor::VisitOMPSharedClause(OMPSharedClause *C) { VisitOMPClauseList(C); return true; } template bool -DataRecursiveASTVisitor::VisitOMPLinearClause(OMPLinearClause *C) { +RecursiveASTVisitor::VisitOMPLinearClause(OMPLinearClause *C) { VisitOMPClauseList(C); TraverseStmt(C->getStep()); return true; } template -bool DataRecursiveASTVisitor::VisitOMPCopyinClause(OMPCopyinClause *C) { +bool RecursiveASTVisitor::VisitOMPCopyinClause(OMPCopyinClause *C) { VisitOMPClauseList(C); return true; } @@ -2446,6 +2450,8 @@ bool DataRecursiveASTVisitor::VisitOMPCopyinClause(OMPCopyinClause *C) #undef TRY_TO +#undef RecursiveASTVisitor + } // end namespace clang #endif // LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H