clang 22.0.0git
clang::DynamicRecursiveASTVisitorBase< IsConst > Class Template Reference

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

#include "clang/AST/DynamicRecursiveASTVisitor.h"

Inheritance diagram for clang::DynamicRecursiveASTVisitorBase< IsConst >:
[legend]

Public Member Functions

virtual void anchor ()
virtual ~DynamicRecursiveASTVisitorBase ()=default
virtual bool TraverseAST (MaybeConst< ASTContext > &AST)
 Recursively visits an entire AST, starting from the TranslationUnitDecl.
virtual bool TraverseAttr (MaybeConst< Attr > *At)
 Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic type.
virtual bool TraverseConstructorInitializer (MaybeConst< CXXCtorInitializer > *Init)
 Recursively visit a constructor initializer.
virtual bool TraverseCXXBaseSpecifier (const CXXBaseSpecifier &Base)
 Recursively visit a base specifier.
virtual bool TraverseDecl (MaybeConst< 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 (MaybeConst< LambdaExpr > *LE, const LambdaCapture *C, MaybeConst< 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 (MaybeConst< 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, bool TraverseQualifier=true)
 Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property.
virtual 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.
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 (MaybeConst< concepts::Requirement > *R)
virtual bool TraverseConceptTypeRequirement (MaybeConst< concepts::TypeRequirement > *R)
virtual bool TraverseConceptExprRequirement (MaybeConst< concepts::ExprRequirement > *R)
virtual bool TraverseConceptNestedRequirement (MaybeConst< concepts::NestedRequirement > *R)
virtual bool TraverseConceptReference (MaybeConst< ConceptReference > *CR)
virtual bool VisitConceptReference (MaybeConst< ConceptReference > *CR)
virtual bool VisitAttr (MaybeConst< Attr > *A)
 Visit a node.
virtual bool VisitDecl (MaybeConst< Decl > *D)
virtual bool VisitStmt (MaybeConst< Stmt > *S)
virtual bool VisitType (MaybeConst< Type > *T)
virtual bool VisitTypeLoc (TypeLoc TL)
bool WalkUpFromDecl (MaybeConst< Decl > *D)
 Walk up from a node.
bool WalkUpFromStmt (MaybeConst< Stmt > *S)
bool WalkUpFromType (MaybeConst< Type > *T)
bool WalkUpFromTypeLoc (TypeLoc TL)
virtual bool dataTraverseStmtPre (MaybeConst< Stmt > *S)
 Invoked before visiting a statement or expression via data recursion.
virtual bool dataTraverseStmtPost (MaybeConst< Stmt > *S)
 Invoked after visiting a statement or expression via data recursion.
virtual bool dataTraverseNode (MaybeConst< 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 Types

template<typename ASTNode>
using MaybeConst = std::conditional_t<IsConst, const ASTNode, ASTNode>

Protected Member Functions

 DynamicRecursiveASTVisitorBase ()=default
 DynamicRecursiveASTVisitorBase (DynamicRecursiveASTVisitorBase &&)=default
 DynamicRecursiveASTVisitorBase (const DynamicRecursiveASTVisitorBase &)=default
DynamicRecursiveASTVisitorBaseoperator= (DynamicRecursiveASTVisitorBase &&)=default
DynamicRecursiveASTVisitorBaseoperator= (const DynamicRecursiveASTVisitorBase &)=default

Detailed Description

template<bool IsConst>
class clang::DynamicRecursiveASTVisitorBase< IsConst >

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:

  • Visiting attributes,
  • Overriding WalkUpFromX,
  • Overriding getStmtChildren().

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.

Member Typedef Documentation

◆ MaybeConst

template<bool IsConst>
template<typename ASTNode>
using clang::DynamicRecursiveASTVisitorBase< IsConst >::MaybeConst = std::conditional_t<IsConst, const ASTNode, ASTNode>
protected

Definition at line 58 of file DynamicRecursiveASTVisitor.h.

Constructor & Destructor Documentation

◆ DynamicRecursiveASTVisitorBase() [1/3]

template<bool IsConst>
clang::DynamicRecursiveASTVisitorBase< IsConst >::DynamicRecursiveASTVisitorBase ( )
protecteddefault

◆ DynamicRecursiveASTVisitorBase() [2/3]

template<bool IsConst>
clang::DynamicRecursiveASTVisitorBase< IsConst >::DynamicRecursiveASTVisitorBase ( DynamicRecursiveASTVisitorBase< IsConst > && )
protecteddefault

◆ DynamicRecursiveASTVisitorBase() [3/3]

template<bool IsConst>
clang::DynamicRecursiveASTVisitorBase< IsConst >::DynamicRecursiveASTVisitorBase ( const DynamicRecursiveASTVisitorBase< IsConst > & )
protecteddefault

◆ ~DynamicRecursiveASTVisitorBase()

template<bool IsConst>
virtual clang::DynamicRecursiveASTVisitorBase< IsConst >::~DynamicRecursiveASTVisitorBase ( )
virtualdefault

Member Function Documentation

◆ anchor()

template<bool Const>
void DynamicRecursiveASTVisitorBase::anchor ( )
virtual

Definition at line 275 of file DynamicRecursiveASTVisitor.cpp.

◆ dataTraverseNode()

template<bool Const>
bool DynamicRecursiveASTVisitorBase::dataTraverseNode ( MaybeConst< Stmt > * S)
virtual

Definition at line 350 of file DynamicRecursiveASTVisitor.cpp.

References dataTraverseNode().

Referenced by dataTraverseNode().

◆ dataTraverseStmtPost()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::dataTraverseStmtPost ( MaybeConst< 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 239 of file DynamicRecursiveASTVisitor.h.

◆ dataTraverseStmtPre()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::dataTraverseStmtPre ( MaybeConst< 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 232 of file DynamicRecursiveASTVisitor.h.

◆ operator=() [1/2]

template<bool IsConst>
DynamicRecursiveASTVisitorBase & clang::DynamicRecursiveASTVisitorBase< IsConst >::operator= ( const DynamicRecursiveASTVisitorBase< IsConst > & )
protecteddefault

◆ operator=() [2/2]

template<bool IsConst>
DynamicRecursiveASTVisitorBase & clang::DynamicRecursiveASTVisitorBase< IsConst >::operator= ( DynamicRecursiveASTVisitorBase< IsConst > && )
protecteddefault

◆ TraverseAST()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseAST ( MaybeConst< ASTContext > & AST)
virtual

Recursively visits an entire AST, starting from the TranslationUnitDecl.

Returns
false if visitation was terminated early.

◆ TraverseAttr()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseAttr ( MaybeConst< 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).

◆ TraverseConceptExprRequirement()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseConceptExprRequirement ( MaybeConst< concepts::ExprRequirement > * R)
virtual

◆ TraverseConceptNestedRequirement()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseConceptNestedRequirement ( MaybeConst< concepts::NestedRequirement > * R)
virtual

◆ TraverseConceptReference()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseConceptReference ( MaybeConst< ConceptReference > * CR)
virtual

◆ TraverseConceptRequirement()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseConceptRequirement ( MaybeConst< concepts::Requirement > * R)
virtual

◆ TraverseConceptTypeRequirement()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseConceptTypeRequirement ( MaybeConst< concepts::TypeRequirement > * R)
virtual

◆ TraverseConstructorInitializer()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseConstructorInitializer ( MaybeConst< 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.

◆ TraverseCXXBaseSpecifier()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::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.

◆ TraverseDecl()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseDecl ( MaybeConst< 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).

◆ TraverseDeclarationNameInfo()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseDeclarationNameInfo ( DeclarationNameInfo NameInfo)
virtual

Recursively visit a name with its location information.

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

◆ TraverseLambdaCapture()

template<bool Const>
bool DynamicRecursiveASTVisitorBase::TraverseLambdaCapture ( MaybeConst< LambdaExpr > * LE,
const LambdaCapture * C,
MaybeConst< 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 341 of file DynamicRecursiveASTVisitor.cpp.

References clang::C, clang::Init, and TraverseLambdaCapture().

Referenced by TraverseLambdaCapture().

◆ TraverseNestedNameSpecifier()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseNestedNameSpecifier ( NestedNameSpecifier NNS)
virtual

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

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

◆ TraverseNestedNameSpecifierLoc()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseNestedNameSpecifierLoc ( NestedNameSpecifierLoc NNS)
virtual

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

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

◆ TraverseObjCProtocolLoc()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseObjCProtocolLoc ( ObjCProtocolLoc ProtocolLoc)
virtual

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

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

◆ TraverseStmt()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseStmt ( MaybeConst< 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).

Referenced by checkOpenMPLoop(), clang::dataflow::getReferencedDecls(), and clang::dataflow::getReferencedDecls().

◆ TraverseTemplateArgument()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::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.

◆ TraverseTemplateArgumentLoc()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::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.

◆ TraverseTemplateArguments()

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseTemplateArguments ( ArrayRef< TemplateArgument > Args)

Recursively visit a set of template arguments.

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

◆ TraverseTemplateName()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::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.

◆ TraverseType()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseType ( QualType T,
bool TraverseQualifier = true )
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).

◆ TraverseTypeConstraint()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::TraverseTypeConstraint ( const TypeConstraint * C)
virtual

Traverse a concept (requirement).

◆ TraverseTypeLoc()

template<bool Const>
bool DynamicRecursiveASTVisitorBase::TraverseTypeLoc ( TypeLoc TL,
bool TraverseQualifier = true )
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 330 of file DynamicRecursiveASTVisitor.cpp.

References TraverseTypeLoc().

Referenced by TraverseTypeLoc().

◆ VisitAttr()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::VisitAttr ( MaybeConst< Attr > * A)
inlinevirtual

Visit a node.

Definition at line 217 of file DynamicRecursiveASTVisitor.h.

◆ VisitConceptReference()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::VisitConceptReference ( MaybeConst< ConceptReference > * CR)
inlinevirtual

Definition at line 212 of file DynamicRecursiveASTVisitor.h.

◆ VisitDecl()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::VisitDecl ( MaybeConst< Decl > * D)
inlinevirtual

◆ VisitStmt()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::VisitStmt ( MaybeConst< Stmt > * S)
inlinevirtual

◆ VisitType()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::VisitType ( MaybeConst< Type > * T)
inlinevirtual

◆ VisitTypeLoc()

template<bool IsConst>
virtual bool clang::DynamicRecursiveASTVisitorBase< IsConst >::VisitTypeLoc ( TypeLoc TL)
inlinevirtual

◆ WalkUpFromDecl()

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::WalkUpFromDecl ( MaybeConst< Decl > * D)
inline

Walk up from a node.

Definition at line 224 of file DynamicRecursiveASTVisitor.h.

◆ WalkUpFromStmt()

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::WalkUpFromStmt ( MaybeConst< Stmt > * S)
inline

Definition at line 225 of file DynamicRecursiveASTVisitor.h.

◆ WalkUpFromType()

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::WalkUpFromType ( MaybeConst< Type > * T)
inline

Definition at line 226 of file DynamicRecursiveASTVisitor.h.

◆ WalkUpFromTypeLoc()

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::WalkUpFromTypeLoc ( TypeLoc TL)
inline

Definition at line 227 of file DynamicRecursiveASTVisitor.h.

Member Data Documentation

◆ ShouldVisitImplicitCode

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::ShouldVisitImplicitCode = false

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

implicit constructors and destructors.

Definition at line 69 of file DynamicRecursiveASTVisitor.h.

◆ ShouldVisitLambdaBody

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::ShouldVisitLambdaBody = true

Whether this visitor should recurse into lambda body.

Definition at line 72 of file DynamicRecursiveASTVisitor.h.

◆ ShouldVisitTemplateInstantiations

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::ShouldVisitTemplateInstantiations = false

Whether this visitor should recurse into template instantiations.

Definition at line 62 of file DynamicRecursiveASTVisitor.h.

◆ ShouldWalkTypesOfTypeLocs

template<bool IsConst>
bool clang::DynamicRecursiveASTVisitorBase< IsConst >::ShouldWalkTypesOfTypeLocs = true

Whether this visitor should recurse into the types of TypeLocs.

Definition at line 65 of file DynamicRecursiveASTVisitor.h.


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