From: Argyrios Kyrtzidis Date: Fri, 20 Dec 2013 02:02:54 +0000 (+0000) Subject: Move tools/libclang/RecursiveASTVisitor.h -> include/clang/AST/DataRecursiveASTVisitor.h X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ed99f0faa4958a20323050ecc13e75693d43faf;p=clang Move tools/libclang/RecursiveASTVisitor.h -> include/clang/AST/DataRecursiveASTVisitor.h This is to make it available so the static analyzer can use it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197766 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/libclang/RecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h similarity index 95% rename from tools/libclang/RecursiveASTVisitor.h rename to include/clang/AST/DataRecursiveASTVisitor.h index fa574f66a1..3f4df50c54 100644 --- a/tools/libclang/RecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -1,4 +1,4 @@ -//===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===// +//===--- DataRecursiveASTVisitor.h - Data-Recursive AST Visitor -*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// // -// This file defines the RecursiveASTVisitor interface, which recursively -// traverses the entire AST. +// This file defines the DataRecursiveASTVisitor interface, which recursively +// traverses the entire AST, using data recursion for Stmts/Exprs. // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H -#define LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H +#ifndef LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H +#define LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" @@ -67,11 +67,10 @@ OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor) namespace clang { -namespace cxindex { // 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 RecursiveASTVisitor can override the method +// object (s.t. a user of DataRecursiveASTVisitor can override the method // in CALL_EXPR). #define TRY_TO(CALL_EXPR) \ do { if (!getDerived().CALL_EXPR) return false; } while (0) @@ -141,7 +140,7 @@ namespace cxindex { /// instantiations will be visited at the same time as the pattern /// from which they were produced. template -class RecursiveASTVisitor { +class DataRecursiveASTVisitor { public: /// \brief Return a reference to the derived class. Derived &getDerived() { return *static_cast(this); } @@ -420,9 +419,9 @@ private: QueuesTy Queues; class NewQueueRAII { - RecursiveASTVisitor &RAV; + DataRecursiveASTVisitor &RAV; public: - NewQueueRAII(StmtsTy &queue, RecursiveASTVisitor &RAV) : RAV(RAV) { + NewQueueRAII(StmtsTy &queue, DataRecursiveASTVisitor &RAV) : RAV(RAV) { RAV.Queues.push_back(&queue); } ~NewQueueRAII() { @@ -439,7 +438,7 @@ public: class StmtQueueAction { StmtsTy &CurrQueue; public: - explicit StmtQueueAction(RecursiveASTVisitor &RAV) + explicit StmtQueueAction(DataRecursiveASTVisitor &RAV) : CurrQueue(RAV.getCurrentQueue()) { } void queue(Stmt *S) { @@ -452,7 +451,7 @@ public: return getDerived().Traverse##NAME(static_cast(VAR)) template -bool RecursiveASTVisitor::TraverseStmt(Stmt *S) { +bool DataRecursiveASTVisitor::TraverseStmt(Stmt *S) { if (!S) return true; @@ -521,7 +520,7 @@ bool RecursiveASTVisitor::TraverseStmt(Stmt *S) { } template -bool RecursiveASTVisitor::TraverseType(QualType T) { +bool DataRecursiveASTVisitor::TraverseType(QualType T) { if (T.isNull()) return true; @@ -537,7 +536,7 @@ bool RecursiveASTVisitor::TraverseType(QualType T) { } template -bool RecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { +bool DataRecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { if (TL.isNull()) return true; @@ -554,7 +553,7 @@ bool RecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { template -bool RecursiveASTVisitor::TraverseDecl(Decl *D) { +bool DataRecursiveASTVisitor::TraverseDecl(Decl *D) { if (!D) return true; @@ -577,7 +576,7 @@ bool RecursiveASTVisitor::TraverseDecl(Decl *D) { #undef DISPATCH template -bool RecursiveASTVisitor::TraverseNestedNameSpecifier( +bool DataRecursiveASTVisitor::TraverseNestedNameSpecifier( NestedNameSpecifier *NNS) { if (!NNS) return true; @@ -601,7 +600,7 @@ bool RecursiveASTVisitor::TraverseNestedNameSpecifier( } template -bool RecursiveASTVisitor::TraverseNestedNameSpecifierLoc( +bool DataRecursiveASTVisitor::TraverseNestedNameSpecifierLoc( NestedNameSpecifierLoc NNS) { if (!NNS) return true; @@ -626,7 +625,7 @@ bool RecursiveASTVisitor::TraverseNestedNameSpecifierLoc( } template -bool RecursiveASTVisitor::TraverseDeclarationNameInfo( +bool DataRecursiveASTVisitor::TraverseDeclarationNameInfo( DeclarationNameInfo NameInfo) { switch (NameInfo.getName().getNameKind()) { case DeclarationName::CXXConstructorName: @@ -651,7 +650,7 @@ bool RecursiveASTVisitor::TraverseDeclarationNameInfo( } template -bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) { +bool DataRecursiveASTVisitor::TraverseTemplateName(TemplateName Template) { if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier())); else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) @@ -661,7 +660,7 @@ bool RecursiveASTVisitor::TraverseTemplateName(TemplateName Template) { } template -bool RecursiveASTVisitor::TraverseTemplateArgument( +bool DataRecursiveASTVisitor::TraverseTemplateArgument( const TemplateArgument &Arg) { switch (Arg.getKind()) { case TemplateArgument::Null: @@ -692,7 +691,7 @@ bool RecursiveASTVisitor::TraverseTemplateArgument( // FIXME: no template name location? // FIXME: no source locations for a template argument pack? template -bool RecursiveASTVisitor::TraverseTemplateArgumentLoc( +bool DataRecursiveASTVisitor::TraverseTemplateArgumentLoc( const TemplateArgumentLoc &ArgLoc) { const TemplateArgument &Arg = ArgLoc.getArgument(); @@ -731,7 +730,7 @@ bool RecursiveASTVisitor::TraverseTemplateArgumentLoc( } template -bool RecursiveASTVisitor::TraverseTemplateArguments( +bool DataRecursiveASTVisitor::TraverseTemplateArguments( const TemplateArgument *Args, unsigned NumArgs) { for (unsigned I = 0; I != NumArgs; ++I) { @@ -742,7 +741,7 @@ bool RecursiveASTVisitor::TraverseTemplateArguments( } template -bool RecursiveASTVisitor::TraverseConstructorInitializer( +bool DataRecursiveASTVisitor::TraverseConstructorInitializer( CXXCtorInitializer *Init) { if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); @@ -753,7 +752,7 @@ bool RecursiveASTVisitor::TraverseConstructorInitializer( } template -bool RecursiveASTVisitor::TraverseLambdaCapture(LambdaExpr::Capture C){ +bool DataRecursiveASTVisitor::TraverseLambdaCapture(LambdaExpr::Capture C){ return true; } @@ -762,7 +761,7 @@ bool RecursiveASTVisitor::TraverseLambdaCapture(LambdaExpr::Capture C){ // This macro makes available a variable T, the passed-in type. #define DEF_TRAVERSE_TYPE(TYPE, CODE) \ template \ - bool RecursiveASTVisitor::Traverse##TYPE (TYPE *T) { \ + bool DataRecursiveASTVisitor::Traverse##TYPE (TYPE *T) { \ TRY_TO(WalkUpFrom##TYPE (T)); \ { CODE; } \ return true; \ @@ -949,7 +948,7 @@ DEF_TRAVERSE_TYPE(AtomicType, { // continue to work. #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \ template \ - bool RecursiveASTVisitor::Traverse##TYPE##Loc(TYPE##Loc TL) { \ + bool DataRecursiveASTVisitor::Traverse##TYPE##Loc(TYPE##Loc TL) { \ if (getDerived().shouldWalkTypesOfTypeLocs()) \ TRY_TO(WalkUpFrom##TYPE(const_cast(TL.getTypePtr()))); \ TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \ @@ -958,7 +957,7 @@ DEF_TRAVERSE_TYPE(AtomicType, { } template -bool RecursiveASTVisitor::TraverseQualifiedTypeLoc( +bool DataRecursiveASTVisitor::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 @@ -1018,7 +1017,7 @@ DEF_TRAVERSE_TYPELOC(AdjustedType, { }) template -bool RecursiveASTVisitor::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { +bool DataRecursiveASTVisitor::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { // This isn't available for ArrayType, but is for the ArrayTypeLoc. TRY_TO(TraverseStmt(TL.getSizeExpr())); return true; @@ -1188,7 +1187,7 @@ DEF_TRAVERSE_TYPELOC(AtomicType, { // than those. template -bool RecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC) { +bool DataRecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC) { if (!DC) return true; @@ -1207,7 +1206,7 @@ bool RecursiveASTVisitor::TraverseDeclContextHelper(DeclContext *DC) { // This macro makes available a variable D, the passed-in decl. #define DEF_TRAVERSE_DECL(DECL, CODE) \ template \ -bool RecursiveASTVisitor::Traverse##DECL (DECL *D) { \ +bool DataRecursiveASTVisitor::Traverse##DECL (DECL *D) { \ TRY_TO(WalkUpFrom##DECL (D)); \ { CODE; } \ TRY_TO(TraverseDeclContextHelper(dyn_cast(D))); \ @@ -1370,7 +1369,7 @@ DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, { // A helper method for TemplateDecl's children. template -bool RecursiveASTVisitor::TraverseTemplateParameterListHelper( +bool DataRecursiveASTVisitor::TraverseTemplateParameterListHelper( TemplateParameterList *TPL) { if (TPL) { for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); @@ -1384,7 +1383,7 @@ bool RecursiveASTVisitor::TraverseTemplateParameterListHelper( // A helper method for traversing the implicit instantiations of a // class template. template -bool RecursiveASTVisitor::TraverseClassInstantiations( +bool DataRecursiveASTVisitor::TraverseClassInstantiations( ClassTemplateDecl *D) { ClassTemplateDecl::spec_iterator end = D->spec_end(); for (ClassTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) { @@ -1433,7 +1432,7 @@ DEF_TRAVERSE_DECL(ClassTemplateDecl, { // A helper method for traversing the implicit instantiations of a // class template. template -bool RecursiveASTVisitor::TraverseVariableInstantiations( +bool DataRecursiveASTVisitor::TraverseVariableInstantiations( VarTemplateDecl *D) { VarTemplateDecl::spec_iterator end = D->spec_end(); for (VarTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) { @@ -1484,7 +1483,7 @@ DEF_TRAVERSE_DECL( // A helper method for traversing the instantiations of a // function while skipping its specializations. template -bool RecursiveASTVisitor::TraverseFunctionInstantiations( +bool DataRecursiveASTVisitor::TraverseFunctionInstantiations( FunctionTemplateDecl *D) { FunctionTemplateDecl::spec_iterator end = D->spec_end(); for (FunctionTemplateDecl::spec_iterator it = D->spec_begin(); it != end; @@ -1584,7 +1583,7 @@ DEF_TRAVERSE_DECL(EnumDecl, { // Helper methods for RecordDecl and its children. template -bool RecursiveASTVisitor::TraverseRecordHelper( +bool DataRecursiveASTVisitor::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. @@ -1594,7 +1593,7 @@ bool RecursiveASTVisitor::TraverseRecordHelper( } template -bool RecursiveASTVisitor::TraverseCXXRecordHelper( +bool DataRecursiveASTVisitor::TraverseCXXRecordHelper( CXXRecordDecl *D) { if (!TraverseRecordHelper(D)) return false; @@ -1640,7 +1639,7 @@ DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, { }) template -bool RecursiveASTVisitor::TraverseTemplateArgumentLocsHelper( +bool DataRecursiveASTVisitor::TraverseTemplateArgumentLocsHelper( const TemplateArgumentLoc *TAL, unsigned Count) { for (unsigned I = 0; I < Count; ++I) { TRY_TO(TraverseTemplateArgumentLoc(TAL[I])); @@ -1683,7 +1682,7 @@ DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, { DEF_TRAVERSE_DECL(IndirectFieldDecl, {}) template -bool RecursiveASTVisitor::TraverseDeclaratorHelper(DeclaratorDecl *D) { +bool DataRecursiveASTVisitor::TraverseDeclaratorHelper(DeclaratorDecl *D) { TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); if (D->getTypeSourceInfo()) TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); @@ -1719,7 +1718,7 @@ DEF_TRAVERSE_DECL(ObjCIvarDecl, { }) template -bool RecursiveASTVisitor::TraverseFunctionHelper(FunctionDecl *D) { +bool DataRecursiveASTVisitor::TraverseFunctionHelper(FunctionDecl *D) { TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); @@ -1796,7 +1795,7 @@ DEF_TRAVERSE_DECL(CXXDestructorDecl, { }) template -bool RecursiveASTVisitor::TraverseVarHelper(VarDecl *D) { +bool DataRecursiveASTVisitor::TraverseVarHelper(VarDecl *D) { TRY_TO(TraverseDeclaratorHelper(D)); // Default params are taken care of when we traverse the ParmVarDecl. if (!isa(D)) @@ -1884,7 +1883,7 @@ DEF_TRAVERSE_DECL(ParmVarDecl, { // This macro makes available a variable S, the passed-in stmt. #define DEF_TRAVERSE_STMT(STMT, CODE) \ template \ -bool RecursiveASTVisitor::Traverse##STMT (STMT *S) { \ +bool DataRecursiveASTVisitor::Traverse##STMT (STMT *S) { \ TRY_TO(WalkUpFrom##STMT(S)); \ StmtQueueAction StmtQueue(*this); \ { CODE; } \ @@ -2032,7 +2031,7 @@ DEF_TRAVERSE_STMT(CXXStaticCastExpr, { // calls WalkUp*() on the semantic form, before our code can convert // to the syntactic form. template -bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { +bool DataRecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { if (InitListExpr *Syn = S->getSyntacticForm()) S = Syn; TRY_TO(WalkUpFromInitListExpr(S)); @@ -2048,7 +2047,7 @@ bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { // are interleaved. We also need to watch out for null types (default // generic associations). template -bool RecursiveASTVisitor:: +bool DataRecursiveASTVisitor:: TraverseGenericSelectionExpr(GenericSelectionExpr *S) { TRY_TO(WalkUpFromGenericSelectionExpr(S)); StmtQueueAction StmtQueue(*this); @@ -2064,7 +2063,7 @@ TraverseGenericSelectionExpr(GenericSelectionExpr *S) { // PseudoObjectExpr is a special case because of the wierdness with // syntactic expressions and opaque values. template -bool RecursiveASTVisitor:: +bool DataRecursiveASTVisitor:: TraversePseudoObjectExpr(PseudoObjectExpr *S) { TRY_TO(WalkUpFromPseudoObjectExpr(S)); StmtQueueAction StmtQueue(*this); @@ -2148,7 +2147,7 @@ DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, { // Walk only the visible parts of lambda expressions. template -bool RecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { +bool DataRecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { TRY_TO(WalkUpFromLambdaExpr(S)); for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), @@ -2315,7 +2314,7 @@ DEF_TRAVERSE_STMT(OMPParallelDirective, { // OpenMP clauses. template -bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { +bool DataRecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { if (!C) return true; switch (C->getClauseKind()) { #define OPENMP_CLAUSE(Name, Class) \ @@ -2328,13 +2327,13 @@ bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { } template -bool RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { +bool DataRecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { return true; } template template -void RecursiveASTVisitor::VisitOMPClauseList(T *Node) { +void DataRecursiveASTVisitor::VisitOMPClauseList(T *Node) { for (typename T::varlist_iterator I = Node->varlist_begin(), E = Node->varlist_end(); I != E; ++I) @@ -2342,20 +2341,20 @@ void RecursiveASTVisitor::VisitOMPClauseList(T *Node) { } template -bool RecursiveASTVisitor::VisitOMPPrivateClause(OMPPrivateClause *C) { +bool DataRecursiveASTVisitor::VisitOMPPrivateClause(OMPPrivateClause *C) { VisitOMPClauseList(C); return true; } template -bool RecursiveASTVisitor::VisitOMPFirstprivateClause( +bool DataRecursiveASTVisitor::VisitOMPFirstprivateClause( OMPFirstprivateClause *C) { VisitOMPClauseList(C); return true; } template -bool RecursiveASTVisitor::VisitOMPSharedClause(OMPSharedClause *C) { +bool DataRecursiveASTVisitor::VisitOMPSharedClause(OMPSharedClause *C) { VisitOMPClauseList(C); return true; } @@ -2381,7 +2380,6 @@ bool RecursiveASTVisitor::VisitOMPSharedClause(OMPSharedClause *C) { #undef TRY_TO -} // end namespace cxindex } // end namespace clang #endif // LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H diff --git a/tools/libclang/IndexBody.cpp b/tools/libclang/IndexBody.cpp index e08a3461e8..6cc8062382 100644 --- a/tools/libclang/IndexBody.cpp +++ b/tools/libclang/IndexBody.cpp @@ -8,19 +8,19 @@ //===----------------------------------------------------------------------===// #include "IndexingContext.h" -#include "RecursiveASTVisitor.h" +#include "clang/AST/DataRecursiveASTVisitor.h" using namespace clang; using namespace cxindex; namespace { -class BodyIndexer : public cxindex::RecursiveASTVisitor { +class BodyIndexer : public DataRecursiveASTVisitor { IndexingContext &IndexCtx; const NamedDecl *Parent; const DeclContext *ParentDC; - typedef RecursiveASTVisitor base; + typedef DataRecursiveASTVisitor base; public: BodyIndexer(IndexingContext &indexCtx, const NamedDecl *Parent, const DeclContext *DC) diff --git a/tools/libclang/IndexTypeSourceInfo.cpp b/tools/libclang/IndexTypeSourceInfo.cpp index 2c771c854c..4f8d4e5925 100644 --- a/tools/libclang/IndexTypeSourceInfo.cpp +++ b/tools/libclang/IndexTypeSourceInfo.cpp @@ -8,14 +8,14 @@ //===----------------------------------------------------------------------===// #include "IndexingContext.h" -#include "RecursiveASTVisitor.h" +#include "clang/AST/DataRecursiveASTVisitor.h" using namespace clang; using namespace cxindex; namespace { -class TypeIndexer : public cxindex::RecursiveASTVisitor { +class TypeIndexer : public DataRecursiveASTVisitor { IndexingContext &IndexCtx; const NamedDecl *Parent; const DeclContext *ParentDC;