clang 20.0.0git
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
clang::DynamicRecursiveASTVisitor Class Reference

Recursive AST visitor that supports extension via dynamic dispatch. More...

#include "clang/AST/DynamicRecursiveASTVisitor.h"

Inheritance diagram for clang::DynamicRecursiveASTVisitor:
Inheritance graph
[legend]

Public Member Functions

virtual void anchor ()
 
virtual ~DynamicRecursiveASTVisitor ()=default
 
virtual bool TraverseAST (ASTContext &AST)
 Recursively visits an entire AST, starting from the TranslationUnitDecl.
 
virtual bool TraverseAttr (Attr *At)
 Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic type.
 
virtual bool TraverseConstructorInitializer (CXXCtorInitializer *Init)
 Recursively visit a constructor initializer.
 
virtual bool TraverseCXXBaseSpecifier (const CXXBaseSpecifier &Base)
 Recursively visit a base specifier.
 
virtual bool TraverseDecl (Decl *D)
 Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic type.
 
virtual bool TraverseDeclarationNameInfo (DeclarationNameInfo NameInfo)
 Recursively visit a name with its location information.
 
virtual bool TraverseLambdaCapture (LambdaExpr *LE, const LambdaCapture *C, Expr *Init)
 Recursively visit a lambda capture.
 
virtual bool TraverseNestedNameSpecifier (NestedNameSpecifier *NNS)
 Recursively visit a C++ nested-name-specifier.
 
virtual bool TraverseNestedNameSpecifierLoc (NestedNameSpecifierLoc NNS)
 Recursively visit a C++ nested-name-specifier with location information.
 
virtual bool TraverseStmt (Stmt *S)
 Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dynamic type.
 
virtual bool TraverseTemplateArgument (const TemplateArgument &Arg)
 Recursively visit a template argument and dispatch to the appropriate method for the argument type.
 
virtual 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.
 
virtual bool TraverseTemplateName (TemplateName Template)
 Recursively visit a template name and dispatch to the appropriate method.
 
virtual bool TraverseType (QualType T)
 Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property.
 
virtual bool TraverseTypeLoc (TypeLoc TL)
 Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument type's getTypeClass() property.
 
virtual bool TraverseObjCProtocolLoc (ObjCProtocolLoc ProtocolLoc)
 Recursively visit an Objective-C protocol reference with location information.
 
virtual bool TraverseTypeConstraint (const TypeConstraint *C)
 Traverse a concept (requirement).
 
virtual bool TraverseConceptRequirement (concepts::Requirement *R)
 
virtual bool TraverseConceptTypeRequirement (concepts::TypeRequirement *R)
 
virtual bool TraverseConceptExprRequirement (concepts::ExprRequirement *R)
 
virtual bool TraverseConceptNestedRequirement (concepts::NestedRequirement *R)
 
virtual bool TraverseConceptReference (ConceptReference *CR)
 
virtual bool VisitConceptReference (ConceptReference *CR)
 
virtual bool VisitAttr (Attr *A)
 Visit a node.
 
virtual bool VisitDecl (Decl *D)
 
virtual bool VisitStmt (Stmt *S)
 
virtual bool VisitType (Type *T)
 
virtual bool VisitTypeLoc (TypeLoc TL)
 
bool WalkUpFromDecl (Decl *D)
 Walk up from a node.
 
bool WalkUpFromStmt (Stmt *S)
 
bool WalkUpFromType (Type *T)
 
bool WalkUpFromTypeLoc (TypeLoc TL)
 
virtual bool dataTraverseStmtPre (Stmt *S)
 Invoked before visiting a statement or expression via data recursion.
 
virtual bool dataTraverseStmtPost (Stmt *S)
 Invoked after visiting a statement or expression via data recursion.
 
virtual bool dataTraverseNode (Stmt *S)
 

Public Attributes

bool ShouldVisitTemplateInstantiations = false
 Whether this visitor should recurse into template instantiations.
 
bool ShouldWalkTypesOfTypeLocs = true
 Whether this visitor should recurse into the types of TypeLocs.
 
bool ShouldVisitImplicitCode = false
 Whether this visitor should recurse into implicit code, e.g.
 
bool ShouldVisitLambdaBody = true
 Whether this visitor should recurse into lambda body.
 

Protected Member Functions

 DynamicRecursiveASTVisitor ()=default
 
 DynamicRecursiveASTVisitor (DynamicRecursiveASTVisitor &&)=default
 
 DynamicRecursiveASTVisitor (const DynamicRecursiveASTVisitor &)=default
 
DynamicRecursiveASTVisitoroperator= (DynamicRecursiveASTVisitor &&)=default
 
DynamicRecursiveASTVisitoroperator= (const DynamicRecursiveASTVisitor &)=default
 

Detailed Description

Recursive AST visitor that supports extension via dynamic dispatch.

Like RecursiveASTVisitor, this class allows for traversal of arbitrarily complex ASTs. The main difference is that this uses virtual functions instead of CRTP, which greatly improves compile times of Clang itself, as well as binary size.

Instead of functions (e.g. shouldVisitImplicitCode()), this class uses member variables (e.g. ShouldVisitImplicitCode) to control visitation behaviour.

However, there is no support for overriding some of the less commonly used features of the RAV, such as WalkUpFromX or attribute traversal (attributes can still be traversed, but you can't change what happens when we traverse one).

The following is a list of RAV features that are NOT customisable:

Furthermore, post-order traversal is not supported at all.

Prefer to use this over RecursiveASTVisitor unless you absolutely need to use one of the features listed above (e.g. overriding WalkUpFromX or post-order traversal).

See also
RecursiveASTVisitor.

Definition at line 55 of file DynamicRecursiveASTVisitor.h.

Constructor & Destructor Documentation

◆ DynamicRecursiveASTVisitor() [1/3]

clang::DynamicRecursiveASTVisitor::DynamicRecursiveASTVisitor ( )
protecteddefault

◆ DynamicRecursiveASTVisitor() [2/3]

clang::DynamicRecursiveASTVisitor::DynamicRecursiveASTVisitor ( DynamicRecursiveASTVisitor &&  )
protecteddefault

◆ DynamicRecursiveASTVisitor() [3/3]

clang::DynamicRecursiveASTVisitor::DynamicRecursiveASTVisitor ( const DynamicRecursiveASTVisitor )
protecteddefault

◆ ~DynamicRecursiveASTVisitor()

virtual clang::DynamicRecursiveASTVisitor::~DynamicRecursiveASTVisitor ( )
virtualdefault

Member Function Documentation

◆ anchor()

void DynamicRecursiveASTVisitor::anchor ( )
virtual

Definition at line 269 of file DynamicRecursiveASTVisitor.cpp.

◆ dataTraverseNode()

bool DynamicRecursiveASTVisitor::dataTraverseNode ( Stmt S)
virtual

Definition at line 386 of file DynamicRecursiveASTVisitor.cpp.

◆ dataTraverseStmtPost()

virtual bool clang::DynamicRecursiveASTVisitor::dataTraverseStmtPost ( Stmt S)
inlinevirtual

Invoked after visiting a statement or expression via data recursion.

This is not invoked if the previously invoked dataTraverseStmtPre returned false.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 223 of file DynamicRecursiveASTVisitor.h.

◆ dataTraverseStmtPre()

virtual bool clang::DynamicRecursiveASTVisitor::dataTraverseStmtPre ( Stmt S)
inlinevirtual

Invoked before visiting a statement or expression via data recursion.

Returns
false to skip visiting the node, true otherwise.

Definition at line 216 of file DynamicRecursiveASTVisitor.h.

◆ operator=() [1/2]

DynamicRecursiveASTVisitor & clang::DynamicRecursiveASTVisitor::operator= ( const DynamicRecursiveASTVisitor )
protecteddefault

◆ operator=() [2/2]

DynamicRecursiveASTVisitor & clang::DynamicRecursiveASTVisitor::operator= ( DynamicRecursiveASTVisitor &&  )
protecteddefault

◆ TraverseAST()

bool DynamicRecursiveASTVisitor::TraverseAST ( ASTContext AST)
virtual

Recursively visits an entire AST, starting from the TranslationUnitDecl.

Returns
false if visitation was terminated early.

Definition at line 271 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseAttr()

bool DynamicRecursiveASTVisitor::TraverseAttr ( Attr At)
virtual

Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic type.

Returns
false if the visitation was terminated early, true otherwise (including when the argument is a Null type location).

Definition at line 275 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseConceptExprRequirement()

bool DynamicRecursiveASTVisitor::TraverseConceptExprRequirement ( concepts::ExprRequirement R)
virtual

Definition at line 347 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseConceptNestedRequirement()

bool DynamicRecursiveASTVisitor::TraverseConceptNestedRequirement ( concepts::NestedRequirement R)
virtual

Definition at line 352 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseConceptReference()

bool DynamicRecursiveASTVisitor::TraverseConceptReference ( ConceptReference CR)
virtual

Definition at line 358 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseConceptRequirement()

bool DynamicRecursiveASTVisitor::TraverseConceptRequirement ( concepts::Requirement R)
virtual

Definition at line 338 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseConceptTypeRequirement()

bool DynamicRecursiveASTVisitor::TraverseConceptTypeRequirement ( concepts::TypeRequirement R)
virtual

Definition at line 342 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseConstructorInitializer()

bool DynamicRecursiveASTVisitor::TraverseConstructorInitializer ( CXXCtorInitializer Init)
virtual

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.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 279 of file DynamicRecursiveASTVisitor.cpp.

References clang::Init.

Referenced by clang::Sema::DiagnoseImmediateEscalatingReason().

◆ TraverseCXXBaseSpecifier()

bool DynamicRecursiveASTVisitor::TraverseCXXBaseSpecifier ( const CXXBaseSpecifier Base)
virtual

Recursively visit a base specifier.

This can be overridden by a subclass.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 363 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseDecl()

bool DynamicRecursiveASTVisitor::TraverseDecl ( Decl D)
virtual

Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic type.

Returns
false if the visitation was terminated early, true otherwise (including when the argument is NULL).

Reimplemented in clang::dataflow::AnalysisASTVisitor, and clang::ast_matchers::MatchDescendantVisitor.

Definition at line 285 of file DynamicRecursiveASTVisitor.cpp.

References D.

Referenced by clang::CallGraph::addToCallGraph(), clang::dataflow::AnalysisASTVisitor::TraverseDecl(), and clang::ast_matchers::MatchDescendantVisitor::TraverseDecl().

◆ TraverseDeclarationNameInfo()

bool DynamicRecursiveASTVisitor::TraverseDeclarationNameInfo ( DeclarationNameInfo  NameInfo)
virtual

Recursively visit a name with its location information.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 368 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseLambdaCapture()

bool DynamicRecursiveASTVisitor::TraverseLambdaCapture ( LambdaExpr LE,
const LambdaCapture C,
Expr Init 
)
virtual

Recursively visit a lambda capture.

Init is the expression that will be used to initialize the capture.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 289 of file DynamicRecursiveASTVisitor.cpp.

References clang::C, and clang::Init.

◆ TraverseNestedNameSpecifier()

bool DynamicRecursiveASTVisitor::TraverseNestedNameSpecifier ( NestedNameSpecifier NNS)
virtual

Recursively visit a C++ nested-name-specifier.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 374 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseNestedNameSpecifierLoc()

bool DynamicRecursiveASTVisitor::TraverseNestedNameSpecifierLoc ( NestedNameSpecifierLoc  NNS)
virtual

Recursively visit a C++ nested-name-specifier with location information.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 380 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseObjCProtocolLoc()

bool DynamicRecursiveASTVisitor::TraverseObjCProtocolLoc ( ObjCProtocolLoc  ProtocolLoc)
virtual

Recursively visit an Objective-C protocol reference with location information.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 332 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseStmt()

bool DynamicRecursiveASTVisitor::TraverseStmt ( Stmt S)
virtual

Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dynamic type.

Returns
false if the visitation was terminated early, true otherwise (including when the argument is nullptr).

Reimplemented in clang::ast_matchers::MatchDescendantVisitor, and clang::CallGraph.

Definition at line 296 of file DynamicRecursiveASTVisitor.cpp.

Referenced by clang::dataflow::getReferencedDecls(), clang::dataflow::ReferencedDeclsVisitor::traverseConstructorInits(), and clang::ast_matchers::MatchDescendantVisitor::TraverseStmt().

◆ TraverseTemplateArgument()

bool DynamicRecursiveASTVisitor::TraverseTemplateArgument ( const TemplateArgument Arg)
virtual

Recursively visit a template argument and dispatch to the appropriate method for the argument type.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 300 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseTemplateArgumentLoc()

bool DynamicRecursiveASTVisitor::TraverseTemplateArgumentLoc ( const TemplateArgumentLoc ArgLoc)
virtual

Recursively visit a template argument location and dispatch to the appropriate method for the argument type.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 310 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseTemplateArguments()

bool DynamicRecursiveASTVisitor::TraverseTemplateArguments ( ArrayRef< TemplateArgument Args)

Recursively visit a set of template arguments.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 305 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseTemplateName()

bool DynamicRecursiveASTVisitor::TraverseTemplateName ( TemplateName  Template)
virtual

Recursively visit a template name and dispatch to the appropriate method.

Returns
false if the visitation was terminated early, true otherwise.

Definition at line 316 of file DynamicRecursiveASTVisitor.cpp.

◆ TraverseType()

bool DynamicRecursiveASTVisitor::TraverseType ( QualType  T)
virtual

Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property.

Returns
false if the visitation was terminated early, true otherwise (including when the argument is a Null type).

Definition at line 320 of file DynamicRecursiveASTVisitor.cpp.

References clang::T.

◆ TraverseTypeConstraint()

bool DynamicRecursiveASTVisitor::TraverseTypeConstraint ( const TypeConstraint C)
virtual

Traverse a concept (requirement).

Definition at line 328 of file DynamicRecursiveASTVisitor.cpp.

References clang::C.

◆ TraverseTypeLoc()

bool DynamicRecursiveASTVisitor::TraverseTypeLoc ( TypeLoc  TL)
virtual

Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument type's getTypeClass() property.

Returns
false if the visitation was terminated early, true otherwise (including when the argument is a Null type location).

Definition at line 324 of file DynamicRecursiveASTVisitor.cpp.

◆ VisitAttr()

virtual bool clang::DynamicRecursiveASTVisitor::VisitAttr ( Attr A)
inlinevirtual

Visit a node.

Definition at line 201 of file DynamicRecursiveASTVisitor.h.

◆ VisitConceptReference()

virtual bool clang::DynamicRecursiveASTVisitor::VisitConceptReference ( ConceptReference CR)
inlinevirtual

Definition at line 198 of file DynamicRecursiveASTVisitor.h.

◆ VisitDecl()

virtual bool clang::DynamicRecursiveASTVisitor::VisitDecl ( Decl D)
inlinevirtual

Reimplemented in clang::dataflow::ReferencedDeclsVisitor.

Definition at line 202 of file DynamicRecursiveASTVisitor.h.

Referenced by WalkUpFromDecl().

◆ VisitStmt()

virtual bool clang::DynamicRecursiveASTVisitor::VisitStmt ( Stmt S)
inlinevirtual

◆ VisitType()

virtual bool clang::DynamicRecursiveASTVisitor::VisitType ( Type T)
inlinevirtual

Definition at line 204 of file DynamicRecursiveASTVisitor.h.

Referenced by WalkUpFromType().

◆ VisitTypeLoc()

virtual bool clang::DynamicRecursiveASTVisitor::VisitTypeLoc ( TypeLoc  TL)
inlinevirtual

Definition at line 205 of file DynamicRecursiveASTVisitor.h.

Referenced by WalkUpFromTypeLoc().

◆ WalkUpFromDecl()

bool clang::DynamicRecursiveASTVisitor::WalkUpFromDecl ( Decl D)
inline

Walk up from a node.

Definition at line 208 of file DynamicRecursiveASTVisitor.h.

References D, and VisitDecl().

◆ WalkUpFromStmt()

bool clang::DynamicRecursiveASTVisitor::WalkUpFromStmt ( Stmt S)
inline

Definition at line 209 of file DynamicRecursiveASTVisitor.h.

References VisitStmt().

◆ WalkUpFromType()

bool clang::DynamicRecursiveASTVisitor::WalkUpFromType ( Type T)
inline

Definition at line 210 of file DynamicRecursiveASTVisitor.h.

References clang::T, and VisitType().

◆ WalkUpFromTypeLoc()

bool clang::DynamicRecursiveASTVisitor::WalkUpFromTypeLoc ( TypeLoc  TL)
inline

Definition at line 211 of file DynamicRecursiveASTVisitor.h.

References VisitTypeLoc().

Member Data Documentation

◆ ShouldVisitImplicitCode

bool clang::DynamicRecursiveASTVisitor::ShouldVisitImplicitCode = false

Whether this visitor should recurse into implicit code, e.g.

implicit constructors and destructors.

Definition at line 65 of file DynamicRecursiveASTVisitor.h.

Referenced by clang::dataflow::AnalysisASTVisitor::AnalysisASTVisitor(), clang::CallGraph::CallGraph(), and clang::ast_matchers::MatchDescendantVisitor::MatchDescendantVisitor().

◆ ShouldVisitLambdaBody

bool clang::DynamicRecursiveASTVisitor::ShouldVisitLambdaBody = true

Whether this visitor should recurse into lambda body.

Definition at line 68 of file DynamicRecursiveASTVisitor.h.

Referenced by clang::dataflow::AnalysisASTVisitor::AnalysisASTVisitor().

◆ ShouldVisitTemplateInstantiations

bool clang::DynamicRecursiveASTVisitor::ShouldVisitTemplateInstantiations = false

Whether this visitor should recurse into template instantiations.

Definition at line 58 of file DynamicRecursiveASTVisitor.h.

Referenced by clang::CallGraph::CallGraph(), and clang::ast_matchers::MatchDescendantVisitor::MatchDescendantVisitor().

◆ ShouldWalkTypesOfTypeLocs

bool clang::DynamicRecursiveASTVisitor::ShouldWalkTypesOfTypeLocs = true

Whether this visitor should recurse into the types of TypeLocs.

Definition at line 61 of file DynamicRecursiveASTVisitor.h.

Referenced by clang::CallGraph::CallGraph().


The documentation for this class was generated from the following files: