|
clang 23.0.0git
|
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. | |
Public Member Functions | |
| Derived & | getDerived () |
| Return a reference to the derived class. | |
| bool | shouldVisitTemplateInstantiations () const |
| Return whether this visitor should recurse into template instantiations. | |
| bool | shouldWalkTypesOfTypeLocs () const |
| Return whether this visitor should recurse into the types of TypeLocs. | |
| bool | shouldVisitImplicitCode () const |
| Return whether this visitor should recurse into implicit code, e.g., implicit constructors and destructors. | |
| bool | shouldVisitLambdaBody () const |
| Return whether this visitor should recurse into lambda body. | |
| bool | shouldTraversePostOrder () const |
| Return whether this visitor should traverse post-order. | |
| bool | TraverseAST (ASTContext &AST) |
| Recursively visits an entire AST, starting from the TranslationUnitDecl. | |
| bool | TraverseStmt (Stmt *S, DataRecursionQueue *Queue=nullptr) |
| Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dynamic type. | |
| bool | dataTraverseStmtPre (Stmt *S) |
| Invoked before visiting a statement or expression via data recursion. | |
| bool | dataTraverseStmtPost (Stmt *S) |
| Invoked after visiting a statement or expression via data recursion. | |
| bool | TraverseType (QualType T, bool TraverseQualifier=true) |
| Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property. | |
| bool | TraverseTypeLoc (TypeLoc TL, bool TraverseQualifier=true) |
| Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument type's getTypeClass() property. | |
| bool | TraverseAttr (Attr *At) |
| Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic type. | |
| bool | TraverseDecl (Decl *D) |
| Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic type. | |
| bool | TraverseNestedNameSpecifier (NestedNameSpecifier NNS) |
| Recursively visit a C++ nested-name-specifier. | |
| bool | TraverseNestedNameSpecifierLoc (NestedNameSpecifierLoc NNS) |
| Recursively visit a C++ nested-name-specifier with location information. | |
| bool | TraverseDeclarationNameInfo (DeclarationNameInfo NameInfo) |
| Recursively visit a name with its location information. | |
| bool | TraverseTemplateName (TemplateName Template) |
| Recursively visit a template name and dispatch to the appropriate method. | |
| bool | TraverseTemplateArgument (const TemplateArgument &Arg) |
| Recursively visit a template argument and dispatch to the appropriate method for the argument type. | |
| bool | TraverseTemplateArgumentLoc (const TemplateArgumentLoc &ArgLoc) |
| Recursively visit a template argument location and dispatch to the appropriate method for the argument type. | |
| bool | TraverseTemplateArguments (ArrayRef< TemplateArgument > Args) |
| Recursively visit a set of template arguments. | |
| bool | TraverseCXXBaseSpecifier (const CXXBaseSpecifier &Base) |
| Recursively visit a base specifier. | |
| bool | TraverseConstructorInitializer (CXXCtorInitializer *Init) |
| Recursively visit a constructor initializer. | |
| bool | TraverseLambdaCapture (LambdaExpr *LE, const LambdaCapture *C, Expr *Init) |
| Recursively visit a lambda capture. | |
| bool | TraverseSynOrSemInitListExpr (InitListExpr *S, DataRecursionQueue *Queue=nullptr) |
| Recursively visit the syntactic or semantic form of an initialization list. | |
| bool | TraverseObjCProtocolLoc (ObjCProtocolLoc ProtocolLoc) |
| Recursively visit an Objective-C protocol reference with location information. | |
| bool | TraverseConceptReference (ConceptReference *CR) |
| Recursively visit concept reference with location information. | |
| bool | VisitConceptReference (ConceptReference *CR) |
| bool | TraverseOffsetOfNode (const OffsetOfNode *Node) |
| Recursively visit a single component of an __builtin_offsetof designator (a field, identifier, base-class, or array-index node). | |
| bool | VisitOffsetOfNode (const OffsetOfNode *Node) |
| Visit a single component of an __builtin_offsetof designator. | |
| 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) |
| bool | TraverseTypeConstraint (const TypeConstraint *C) |
| bool | TraverseConceptRequirement (concepts::Requirement *R) |
| bool | TraverseConceptTypeRequirement (concepts::TypeRequirement *R) |
| bool | TraverseConceptExprRequirement (concepts::ExprRequirement *R) |
| bool | TraverseConceptNestedRequirement (concepts::NestedRequirement *R) |
| bool | dataTraverseNode (Stmt *S, DataRecursionQueue *Queue) |
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 156 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 164 of file RecursiveASTVisitor.h.
| bool clang::RecursiveASTVisitor< Derived >::canIgnoreChildDeclWhileTraversingDeclContext | ( | const Decl * | Child | ) |
| bool clang::RecursiveASTVisitor< Derived >::dataTraverseNode | ( | Stmt * | S, |
| DataRecursionQueue * | Queue ) |
Definition at line 573 of file RecursiveASTVisitor.h.
References clang::Stmt::getStmtClass(), and clang::Stmt::NoStmtClass.
Referenced by TraverseStmt().
|
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 212 of file RecursiveASTVisitor.h.
Referenced by TraverseStmt().
|
inline |
Invoked before visiting a statement or expression via data recursion.
Definition at line 205 of file RecursiveASTVisitor.h.
Referenced by TraverseStmt().
|
inline |
Return a reference to the derived class.
Definition at line 167 of file RecursiveASTVisitor.h.
Referenced by clang::RecursiveASTVisitor< RecursiveSymbolVisitor< T > >::TraverseAST(), TraverseConceptExprRequirement(), TraverseConceptNestedRequirement(), TraverseConceptRequirement(), TraverseConceptTypeRequirement(), TraverseConstructorInitializer(), TraverseDecl(), clang::LexicallyOrderedRecursiveASTVisitor< Derived >::TraverseDeclContextHelper(), TraverseStmt(), TraverseTemplateArgument(), TraverseTemplateArgumentLoc(), TraverseTypeConstraint(), clang::RecursiveASTVisitor< RecursiveSymbolVisitor< T > >::WalkUpFromDecl(), clang::RecursiveASTVisitor< RecursiveSymbolVisitor< T > >::WalkUpFromQualifiedTypeLoc(), clang::RecursiveASTVisitor< RecursiveSymbolVisitor< T > >::WalkUpFromStmt(), clang::RecursiveASTVisitor< RecursiveSymbolVisitor< T > >::WalkUpFromType(), clang::RecursiveASTVisitor< RecursiveSymbolVisitor< T > >::WalkUpFromTypeLoc(), and clang::RecursiveASTVisitor< RecursiveSymbolVisitor< T > >::WalkUpFromUnqualTypeLoc().
|
inline |
Definition at line 348 of file RecursiveASTVisitor.h.
|
inline |
Return whether this visitor should traverse post-order.
Definition at line 185 of file RecursiveASTVisitor.h.
Referenced by TraverseStmt().
|
inline |
Return whether this visitor should recurse into implicit code, e.g., implicit constructors and destructors.
Definition at line 179 of file RecursiveASTVisitor.h.
Referenced by TraverseConceptExprRequirement(), TraverseConstructorInitializer(), TraverseDecl(), and TraverseTypeConstraint().
|
inline |
Return whether this visitor should recurse into lambda body.
Definition at line 182 of file RecursiveASTVisitor.h.
|
inline |
Return whether this visitor should recurse into template instantiations.
Definition at line 171 of file RecursiveASTVisitor.h.
|
inline |
Return whether this visitor should recurse into the types of TypeLocs.
Definition at line 175 of file RecursiveASTVisitor.h.
|
inline |
Recursively visits an entire AST, starting from the TranslationUnitDecl.
Definition at line 189 of file RecursiveASTVisitor.h.
Referenced by clang::ParentMapContext::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.
| bool clang::RecursiveASTVisitor< Derived >::TraverseConceptExprRequirement | ( | concepts::ExprRequirement * | R | ) |
Definition at line 600 of file RecursiveASTVisitor.h.
References getDerived(), shouldVisitImplicitCode(), TraverseStmt(), TraverseTypeConstraint(), and TRY_TO.
| bool clang::RecursiveASTVisitor< Derived >::TraverseConceptNestedRequirement | ( | concepts::NestedRequirement * | R | ) |
Definition at line 618 of file RecursiveASTVisitor.h.
References getDerived().
| bool clang::RecursiveASTVisitor< Derived >::TraverseConceptReference | ( | ConceptReference * | CR | ) |
Recursively visit concept reference with location information.
Referenced by TraverseTypeConstraint().
| bool clang::RecursiveASTVisitor< Derived >::TraverseConceptRequirement | ( | concepts::Requirement * | R | ) |
Definition at line 555 of file RecursiveASTVisitor.h.
References clang::cast(), getDerived(), clang::concepts::Requirement::RK_Compound, clang::concepts::Requirement::RK_Nested, clang::concepts::Requirement::RK_Simple, and clang::concepts::Requirement::RK_Type.
| bool clang::RecursiveASTVisitor< Derived >::TraverseConceptTypeRequirement | ( | concepts::TypeRequirement * | R | ) |
Definition at line 592 of file RecursiveASTVisitor.h.
References getDerived().
| 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 967 of file RecursiveASTVisitor.h.
References getDerived(), clang::Init, shouldVisitImplicitCode(), TraverseStmt(), TraverseTypeLoc(), and TRY_TO.
| bool clang::RecursiveASTVisitor< Derived >::TraverseCXXBaseSpecifier | ( | const CXXBaseSpecifier & | Base | ) |
Recursively visit a base specifier.
This can be overridden by a subclass.
| 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 759 of file RecursiveASTVisitor.h.
References getDerived(), clang::Decl::getKind(), clang::Decl::isImplicit(), and shouldVisitImplicitCode().
Referenced by clang::LexicallyOrderedRecursiveASTVisitor< Derived >::TraverseDeclContextHelper(), and TraverseLambdaCapture().
| bool clang::RecursiveASTVisitor< Derived >::TraverseDeclarationNameInfo | ( | DeclarationNameInfo | NameInfo | ) |
Recursively visit a name with its location information.
Definition at line 845 of file RecursiveASTVisitor.h.
References clang::DeclarationName::CXXConstructorName, clang::DeclarationName::CXXConversionFunctionName, clang::DeclarationName::CXXDeductionGuideName, clang::DeclarationName::CXXDestructorName, clang::DeclarationName::CXXLiteralOperatorName, clang::DeclarationName::CXXOperatorName, clang::DeclarationName::CXXUsingDirective, clang::DeclarationName::getCXXDeductionGuideTemplate(), clang::DeclarationNameInfo::getName(), clang::DeclarationNameInfo::getNamedTypeInfo(), clang::DeclarationName::getNameKind(), clang::DeclarationName::Identifier, clang::DeclarationName::ObjCMultiArgSelector, clang::DeclarationName::ObjCOneArgSelector, clang::DeclarationName::ObjCZeroArgSelector, clang::TemplateName, TraverseTemplateName(), TraverseTypeLoc(), and TRY_TO.
| 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 980 of file RecursiveASTVisitor.h.
References clang::C, clang::Init, TraverseDecl(), TraverseStmt(), and TRY_TO.
| bool clang::RecursiveASTVisitor< Derived >::TraverseNestedNameSpecifier | ( | NestedNameSpecifier | NNS | ) |
Recursively visit a C++ nested-name-specifier.
Definition at line 801 of file RecursiveASTVisitor.h.
References clang::NestedNameSpecifier::getAsNamespaceAndPrefix(), clang::NestedNameSpecifier::getAsType(), clang::NestedNameSpecifier::getKind(), clang::NestedNameSpecifier::Global, clang::NestedNameSpecifier::MicrosoftSuper, clang::NestedNameSpecifier::Namespace, clang::NestedNameSpecifier::Null, clang::NamespaceAndPrefix::Prefix, TraverseNestedNameSpecifier(), TraverseType(), TRY_TO, and clang::NestedNameSpecifier::Type.
Referenced by TraverseNestedNameSpecifier(), and TraverseTemplateName().
| bool clang::RecursiveASTVisitor< Derived >::TraverseNestedNameSpecifierLoc | ( | NestedNameSpecifierLoc | NNS | ) |
Recursively visit a C++ nested-name-specifier with location information.
Definition at line 822 of file RecursiveASTVisitor.h.
References clang::NestedNameSpecifierLoc::castAsNamespaceAndPrefix(), clang::NestedNameSpecifierLoc::castAsTypeLoc(), clang::NestedNameSpecifier::getKind(), clang::NestedNameSpecifierLoc::getNestedNameSpecifier(), clang::TypeLoc::getPrefix(), clang::NestedNameSpecifier::Global, clang::NestedNameSpecifier::MicrosoftSuper, clang::NestedNameSpecifier::Namespace, clang::NestedNameSpecifier::Null, clang::NamespaceAndPrefixLoc::Prefix, TraverseNestedNameSpecifierLoc(), TraverseTypeLoc(), TRY_TO, and clang::NestedNameSpecifier::Type.
| bool clang::RecursiveASTVisitor< Derived >::TraverseObjCProtocolLoc | ( | ObjCProtocolLoc | ProtocolLoc | ) |
Recursively visit an Objective-C protocol reference with location information.
| bool clang::RecursiveASTVisitor< Derived >::TraverseOffsetOfNode | ( | const OffsetOfNode * | Node | ) |
Recursively visit a single component of an __builtin_offsetof designator (a field, identifier, base-class, or array-index node).
| LLVM_ATTRIBUTE_NOINLINE 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 677 of file RecursiveASTVisitor.h.
References dataTraverseNode(), dataTraverseStmtPost(), dataTraverseStmtPre(), getDerived(), shouldTraversePostOrder(), and TRY_TO.
Referenced by clang::CodeGen::CGHLSLRuntime::emitInitListOpaqueValues(), TraverseConceptExprRequirement(), TraverseConstructorInitializer(), TraverseCXXOperatorCallExpr(), TraverseLambdaCapture(), and TraverseTypeConstraint().
| bool clang::RecursiveASTVisitor< Derived >::TraverseSynOrSemInitListExpr | ( | InitListExpr * | S, |
| DataRecursionQueue * | Queue = nullptr ) |
Recursively visit the syntactic or semantic form of an initialization list.
| 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 888 of file RecursiveASTVisitor.h.
References clang::TemplateArgument::Declaration, clang::TemplateArgument::Expression, clang::TemplateArgument::getAsExpr(), clang::TemplateArgument::getAsTemplateOrTemplatePattern(), clang::TemplateArgument::getAsType(), getDerived(), clang::TemplateArgument::getKind(), clang::TemplateArgument::Integral, clang::TemplateArgument::Null, clang::TemplateArgument::NullPtr, clang::TemplateArgument::Pack, clang::TemplateArgument::pack_elements(), clang::TemplateArgument::StructuralValue, clang::TemplateArgument::Template, clang::TemplateArgument::TemplateExpansion, and clang::TemplateArgument::Type.
Referenced by 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 919 of file RecursiveASTVisitor.h.
References clang::TemplateArgument::Declaration, clang::TemplateArgument::Expression, clang::TemplateArgumentLoc::getArgument(), clang::TemplateArgument::getAsTemplateOrTemplatePattern(), clang::TemplateArgument::getAsType(), getDerived(), clang::TemplateArgument::getKind(), clang::TemplateArgumentLoc::getSourceExpression(), clang::TemplateArgumentLoc::getTemplateQualifierLoc(), clang::TemplateArgumentLoc::getTypeSourceInfo(), clang::TemplateArgument::Integral, clang::TemplateArgument::Null, clang::TemplateArgument::NullPtr, clang::TemplateArgument::Pack, clang::TemplateArgument::pack_elements(), clang::TemplateArgument::StructuralValue, clang::TemplateArgument::Template, clang::TemplateArgument::TemplateExpansion, TraverseNestedNameSpecifierLoc(), TRY_TO, and clang::TemplateArgument::Type.
| bool clang::RecursiveASTVisitor< Derived >::TraverseTemplateArguments | ( | ArrayRef< TemplateArgument > | Args | ) |
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 958 of file RecursiveASTVisitor.h.
References TraverseTemplateArgument(), and TRY_TO.
| bool clang::RecursiveASTVisitor< Derived >::TraverseTemplateName | ( | TemplateName | Template | ) |
Recursively visit a template name and dispatch to the appropriate method.
Definition at line 874 of file RecursiveASTVisitor.h.
References clang::Template, TraverseNestedNameSpecifier(), and TRY_TO.
Referenced by TraverseDeclarationNameInfo().
| bool clang::RecursiveASTVisitor< Derived >::TraverseType | ( | QualType | T, |
| bool | TraverseQualifier = true ) |
Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property.
Definition at line 717 of file RecursiveASTVisitor.h.
Referenced by TraverseNestedNameSpecifier().
| bool clang::RecursiveASTVisitor< Derived >::TraverseTypeConstraint | ( | const TypeConstraint * | C | ) |
Definition at line 536 of file RecursiveASTVisitor.h.
References clang::C, getDerived(), shouldVisitImplicitCode(), TraverseConceptReference(), TraverseStmt(), and TRY_TO.
Referenced by TraverseConceptExprRequirement().
| bool clang::RecursiveASTVisitor< Derived >::TraverseTypeLoc | ( | TypeLoc | TL, |
| bool | TraverseQualifier = true ) |
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument type's getTypeClass() property.
Definition at line 736 of file RecursiveASTVisitor.h.
References clang::TypeLoc::getTypeLocClass(), and clang::TypeLoc::isNull().
Referenced by TraverseConstructorInitializer(), TraverseDeclarationNameInfo(), TraverseMemberPointerTypeLoc(), TraverseNestedNameSpecifierLoc(), and TraverseParenTypeLoc().
|
inline |
Definition at line 339 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 325 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 464 of file RecursiveASTVisitor.h.
|
inline |
Visit a single component of an __builtin_offsetof designator.
Definition at line 334 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 438 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 387 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 409 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 431 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 442 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 463 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 435 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 386 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 408 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 430 of file RecursiveASTVisitor.h.
|
inline |
Definition at line 439 of file RecursiveASTVisitor.h.