clang
8.0.0
|
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each node. More...
#include "clang/AST/RecursiveASTVisitor.h"
Public Types | |
typedef SmallVectorImpl< llvm::PointerIntPair< Stmt *, 1, bool > > | DataRecursionQueue |
A queue used for performing data recursion over statements. More... | |
Public Member Functions | |
Derived & | getDerived () |
Return a reference to the derived class. More... | |
bool | shouldVisitTemplateInstantiations () const |
Return whether this visitor should recurse into template instantiations. More... | |
bool | shouldWalkTypesOfTypeLocs () const |
Return whether this visitor should recurse into the types of TypeLocs. More... | |
bool | shouldVisitImplicitCode () const |
Return whether this visitor should recurse into implicit code, e.g., implicit constructors and destructors. More... | |
bool | shouldTraversePostOrder () const |
Return whether this visitor should traverse post-order. More... | |
bool | TraverseAST (ASTContext &AST) |
Recursively visits an entire AST, starting from the top-level Decls in the AST traversal scope (by default, the TranslationUnitDecl). More... | |
bool | TraverseStmt (Stmt *S, DataRecursionQueue *Queue=nullptr) |
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dynamic type. More... | |
bool | dataTraverseStmtPre (Stmt *S) |
Invoked before visiting a statement or expression via data recursion. More... | |
bool | dataTraverseStmtPost (Stmt *S) |
Invoked after visiting a statement or expression via data recursion. More... | |
bool | TraverseType (QualType T) |
Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property. More... | |
bool | TraverseTypeLoc (TypeLoc TL) |
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument type's getTypeClass() property. More... | |
bool | TraverseAttr (Attr *At) |
Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic type. More... | |
bool | TraverseDecl (Decl *D) |
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic type. More... | |
bool | TraverseNestedNameSpecifier (NestedNameSpecifier *NNS) |
Recursively visit a C++ nested-name-specifier. More... | |
bool | TraverseNestedNameSpecifierLoc (NestedNameSpecifierLoc NNS) |
Recursively visit a C++ nested-name-specifier with location information. More... | |
bool | TraverseDeclarationNameInfo (DeclarationNameInfo NameInfo) |
Recursively visit a name with its location information. More... | |
bool | TraverseTemplateName (TemplateName Template) |
Recursively visit a template name and dispatch to the appropriate method. More... | |
bool | TraverseTemplateArgument (const TemplateArgument &Arg) |
Recursively visit a template argument and dispatch to the appropriate method for the argument type. More... | |
bool | TraverseTemplateArgumentLoc (const TemplateArgumentLoc &ArgLoc) |
Recursively visit a template argument location and dispatch to the appropriate method for the argument type. More... | |
bool | TraverseTemplateArguments (const TemplateArgument *Args, unsigned NumArgs) |
Recursively visit a set of template arguments. More... | |
bool | TraverseCXXBaseSpecifier (const CXXBaseSpecifier &Base) |
Recursively visit a base specifier. More... | |
bool | TraverseConstructorInitializer (CXXCtorInitializer *Init) |
Recursively visit a constructor initializer. More... | |
bool | TraverseLambdaCapture (LambdaExpr *LE, const LambdaCapture *C, Expr *Init) |
Recursively visit a lambda capture. More... | |
bool | TraverseSynOrSemInitListExpr (InitListExpr *S, DataRecursionQueue *Queue=nullptr) |
Recursively visit the syntactic or semantic form of an initialization list. More... | |
bool | VisitAttr (Attr *A) |
Stmt::child_range | getStmtChildren (Stmt *S) |
bool | WalkUpFromStmt (Stmt *S) |
bool | VisitStmt (Stmt *S) |
bool | WalkUpFromType (Type *T) |
bool | VisitType (Type *T) |
bool | WalkUpFromTypeLoc (TypeLoc TL) |
bool | VisitTypeLoc (TypeLoc TL) |
bool | WalkUpFromQualifiedTypeLoc (QualifiedTypeLoc TL) |
bool | VisitQualifiedTypeLoc (QualifiedTypeLoc TL) |
bool | WalkUpFromUnqualTypeLoc (UnqualTypeLoc TL) |
bool | VisitUnqualTypeLoc (UnqualTypeLoc TL) |
bool | WalkUpFromDecl (Decl *D) |
bool | VisitDecl (Decl *D) |
bool | canIgnoreChildDeclWhileTraversingDeclContext (const Decl *Child) { TRY_TO(TraverseTypeLoc(TL.getValueLoc())) |
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each node.
This class performs three distinct tasks:
These tasks are done by three groups of methods, respectively:
These three method groups are tiered (Traverse* > WalkUpFrom* > Visit*). A method (e.g. Traverse*) may call methods from the same tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*). It may not call methods from a higher tier.
Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar is Foo's super class) before calling VisitFoo(), the result is that the Visit*() methods for a given node are called in the top-down order (e.g. for a node of type NamespaceDecl, the order will be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
This scheme guarantees that all Visit*() calls for the same AST node are grouped together. In other words, Visit*() methods for different nodes are never interleaved.
Clients of this visitor should subclass the visitor (providing themselves as the template argument, using the curiously recurring template pattern) and override any of the Traverse*, WalkUpFrom*, and Visit* methods for declarations, types, statements, expressions, or other AST nodes where the visitor should customize behavior. Most users only need to override Visit*. Advanced users may override Traverse* and WalkUpFrom* to implement custom traversal strategies. Returning false from one of these overridden functions will abort the entire traversal.
By default, this visitor tries to visit every part of the explicit source code exactly once. The default policy towards templates is to descend into the 'pattern' class or function body, not any explicit or implicit instantiations. Explicit specializations are still visited, and the patterns of partial specializations are visited separately. This behavior can be changed by overriding shouldVisitTemplateInstantiations() in the derived class to return true, in which case all known implicit and explicit instantiations will be visited at the same time as the pattern from which they were produced.
By default, this visitor preorder traverses the AST. If postorder traversal is needed, the shouldTraversePostOrder
method needs to be overridden to return true
.
Definition at line 151 of file RecursiveASTVisitor.h.
typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool> > clang::RecursiveASTVisitor< Derived >::DataRecursionQueue |
A queue used for performing data recursion over statements.
Parameters involving this type are used to implement data recursion over Stmts and Exprs within this class, and should typically not be explicitly specified by derived classes. The bool bit indicates whether the statement has been traversed or not.
Definition at line 159 of file RecursiveASTVisitor.h.
bool clang::RecursiveASTVisitor< Derived >::canIgnoreChildDeclWhileTraversingDeclContext | ( | const Decl * | Child | ) | { TRY_TO(TraverseTypeLoc(TL.getValueLoc())) |
Definition at line 1369 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::canIgnoreChildDeclWhileTraversingDeclContext(), and clang::LexicallyOrderedRecursiveASTVisitor< Derived >::TraverseDeclContextHelper().
|
inline |
Invoked after visiting a statement or expression via data recursion.
This is not invoked if the previously invoked dataTraverseStmtPre
returned false.
Definition at line 206 of file RecursiveASTVisitor.h.
|
inline |
Invoked before visiting a statement or expression via data recursion.
Definition at line 199 of file RecursiveASTVisitor.h.
|
inline |
Return a reference to the derived class.
Definition at line 162 of file RecursiveASTVisitor.h.
Referenced by clang::LexicallyOrderedRecursiveASTVisitor< Derived >::getStmtChildren(), clang::if(), clang::RecursiveASTVisitor< CallGraph >::TraverseAST(), clang::RecursiveASTVisitor< CallGraph >::TraverseConstructorInitializer(), clang::RecursiveASTVisitor< CallGraph >::TraverseDecl(), clang::LexicallyOrderedRecursiveASTVisitor< Derived >::TraverseDeclContextHelper(), clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateArgument(), clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateArgumentLoc(), clang::RecursiveASTVisitor< CallGraph >::WalkUpFromDecl(), clang::RecursiveASTVisitor< CallGraph >::WalkUpFromQualifiedTypeLoc(), clang::RecursiveASTVisitor< CallGraph >::WalkUpFromStmt(), clang::RecursiveASTVisitor< CallGraph >::WalkUpFromType(), clang::RecursiveASTVisitor< CallGraph >::WalkUpFromTypeLoc(), and clang::RecursiveASTVisitor< CallGraph >::WalkUpFromUnqualTypeLoc().
|
inline |
Definition at line 320 of file RecursiveASTVisitor.h.
Referenced by clang::if().
|
inline |
Return whether this visitor should traverse post-order.
Definition at line 177 of file RecursiveASTVisitor.h.
Referenced by clang::LexicallyOrderedRecursiveASTVisitor< Derived >::getStmtChildren(), and clang::if().
|
inline |
Return whether this visitor should recurse into implicit code, e.g., implicit constructors and destructors.
Definition at line 174 of file RecursiveASTVisitor.h.
Referenced by clang::if(), and clang::RecursiveASTVisitor< CallGraph >::TraverseDecl().
|
inline |
Return whether this visitor should recurse into template instantiations.
Definition at line 166 of file RecursiveASTVisitor.h.
Referenced by clang::if().
|
inline |
Return whether this visitor should recurse into the types of TypeLocs.
Definition at line 170 of file RecursiveASTVisitor.h.
|
inline |
Recursively visits an entire AST, starting from the top-level Decls in the AST traversal scope (by default, the TranslationUnitDecl).
Definition at line 182 of file RecursiveASTVisitor.h.
Referenced by clang::ASTContext::ParentMap::ParentMap().
bool clang::RecursiveASTVisitor< Derived >::TraverseAttr | ( | Attr * | At | ) |
Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic type.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost().
bool clang::RecursiveASTVisitor< Derived >::TraverseConstructorInitializer | ( | CXXCtorInitializer * | Init | ) |
Recursively visit a constructor initializer.
This automatically dispatches to another visitor for the initializer expression, but not for the name of the initializer, so may be overridden for clients that need access to the name.
Definition at line 908 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), and clang::if().
bool clang::RecursiveASTVisitor< Derived >::TraverseCXXBaseSpecifier | ( | const CXXBaseSpecifier & | Base | ) |
Recursively visit a base specifier.
This can be overridden by a subclass.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), and clang::if().
bool clang::RecursiveASTVisitor< Derived >::TraverseDecl | ( | Decl * | D | ) |
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic type.
Definition at line 708 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::canIgnoreChildDeclWhileTraversingDeclContext(), clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), clang::LexicallyOrderedRecursiveASTVisitor< Derived >::getStmtChildren(), clang::if(), clang::LexicallyOrderedRecursiveASTVisitor< Derived >::TraverseDeclContextHelper(), and clang::RecursiveASTVisitor< CallGraph >::TraverseLambdaCapture().
bool clang::RecursiveASTVisitor< Derived >::TraverseDeclarationNameInfo | ( | DeclarationNameInfo | NameInfo | ) |
Recursively visit a name with its location information.
Definition at line 789 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), and clang::if().
bool clang::RecursiveASTVisitor< Derived >::TraverseLambdaCapture | ( | LambdaExpr * | LE, |
const LambdaCapture * | C, | ||
Expr * | Init | ||
) |
Recursively visit a lambda capture.
Init
is the expression that will be used to initialize the capture.
Definition at line 921 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost().
bool clang::RecursiveASTVisitor< Derived >::TraverseNestedNameSpecifier | ( | NestedNameSpecifier * | NNS | ) |
Recursively visit a C++ nested-name-specifier.
Definition at line 738 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), clang::RecursiveASTVisitor< CallGraph >::TraverseNestedNameSpecifier(), and clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateName().
bool clang::RecursiveASTVisitor< Derived >::TraverseNestedNameSpecifierLoc | ( | NestedNameSpecifierLoc | NNS | ) |
Recursively visit a C++ nested-name-specifier with location information.
Definition at line 763 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), clang::for(), clang::if(), and clang::RecursiveASTVisitor< CallGraph >::TraverseNestedNameSpecifierLoc().
bool clang::RecursiveASTVisitor< Derived >::TraverseStmt | ( | Stmt * | S, |
DataRecursionQueue * | Queue = nullptr |
||
) |
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dynamic type.
Definition at line 627 of file RecursiveASTVisitor.h.
Referenced by clang::if(), clang::RecursiveASTVisitor< CallGraph >::TraverseAST(), clang::RecursiveASTVisitor< CallGraph >::TraverseConstructorInitializer(), and clang::RecursiveASTVisitor< CallGraph >::TraverseLambdaCapture().
bool clang::RecursiveASTVisitor< Derived >::TraverseSynOrSemInitListExpr | ( | InitListExpr * | S, |
DataRecursionQueue * | Queue = nullptr |
||
) |
Recursively visit the syntactic or semantic form of an initialization list.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), and clang::if().
bool clang::RecursiveASTVisitor< Derived >::TraverseTemplateArgument | ( | const TemplateArgument & | Arg | ) |
Recursively visit a template argument and dispatch to the appropriate method for the argument type.
Definition at line 828 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), and clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateArguments().
bool clang::RecursiveASTVisitor< Derived >::TraverseTemplateArgumentLoc | ( | const TemplateArgumentLoc & | ArgLoc | ) |
Recursively visit a template argument location and dispatch to the appropriate method for the argument type.
Definition at line 859 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), clang::for(), and clang::if().
bool clang::RecursiveASTVisitor< Derived >::TraverseTemplateArguments | ( | const TemplateArgument * | Args, |
unsigned | NumArgs | ||
) |
Recursively visit a set of template arguments.
This can be overridden by a subclass, but it's not expected that will be needed – this visitor always dispatches to another.
Definition at line 898 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost().
bool clang::RecursiveASTVisitor< Derived >::TraverseTemplateName | ( | TemplateName | Template | ) |
Recursively visit a template name and dispatch to the appropriate method.
Definition at line 818 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), and clang::RecursiveASTVisitor< CallGraph >::TraverseDeclarationNameInfo().
bool clang::RecursiveASTVisitor< Derived >::TraverseType | ( | QualType | T | ) |
Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property.
Definition at line 671 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), clang::if(), and clang::RecursiveASTVisitor< CallGraph >::TraverseNestedNameSpecifier().
bool clang::RecursiveASTVisitor< Derived >::TraverseTypeLoc | ( | TypeLoc | TL | ) |
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument type's getTypeClass() property.
Definition at line 687 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< CallGraph >::dataTraverseStmtPost(), clang::for(), clang::if(), clang::RecursiveASTVisitor< CallGraph >::TraverseConstructorInitializer(), clang::RecursiveASTVisitor< CallGraph >::TraverseDeclarationNameInfo(), and clang::RecursiveASTVisitor< CallGraph >::TraverseNestedNameSpecifierLoc().
|
inline |
Definition at line 311 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 494 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 468 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 365 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 440 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 461 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 472 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 493 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 465 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 364 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 439 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 460 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 469 of file RecursiveASTVisitor.h.