15 #ifndef LLVM_CLANG_AST_ASTNODETRAVERSER_H 16 #define LLVM_CLANG_AST_ASTNODETRAVERSER_H 54 template <
typename Derived,
typename NodeDelegateType>
59 const comments::FullComment *>,
66 bool Deserialize =
false;
71 NodeDelegateType &getNodeDelegate() {
72 return getDerived().doGetNodeDelegate();
74 Derived &getDerived() {
return *
static_cast<Derived *
>(
this); }
83 getNodeDelegate().AddChild([=] {
84 getNodeDelegate().Visit(D);
90 for (
const auto &A : D->
attrs())
95 Visit(Comment, Comment);
98 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D)) {
99 if (
const auto *DC = dyn_cast<DeclContext>(D))
106 getNodeDelegate().AddChild(
Label, [=] {
109 if (
auto *E = dyn_cast_or_null<Expr>(S)) {
114 S = E->IgnoreParenImpCasts();
117 S = E->IgnoreUnlessSpelledInSource();
122 getNodeDelegate().Visit(S);
131 if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S))
134 if (isa<LambdaExpr>(S) &&
148 getNodeDelegate().AddChild([=] {
149 getNodeDelegate().Visit(T);
155 getNodeDelegate().AddChild([=] {
156 getNodeDelegate().Visit(T);
163 if (SingleStepDesugar !=
QualType(T, 0))
164 Visit(SingleStepDesugar);
169 getNodeDelegate().AddChild([=] {
170 getNodeDelegate().Visit(A);
176 getNodeDelegate().AddChild([=] {
177 getNodeDelegate().Visit(Init);
183 const Decl *From =
nullptr,
const char *
Label =
nullptr) {
184 getNodeDelegate().AddChild([=] {
185 getNodeDelegate().Visit(A, R, From, Label);
191 getNodeDelegate().AddChild([=] {
192 getNodeDelegate().Visit(C);
199 getNodeDelegate().AddChild([=] {
200 getNodeDelegate().Visit(C);
207 getNodeDelegate().AddChild([=] {
208 getNodeDelegate().Visit(A);
210 Visit(TSI->getType());
211 Visit(A.getAssociationExpr());
216 getNodeDelegate().AddChild([=] {
217 getNodeDelegate().Visit(C, FC);
233 if (
const auto *D = N.
get<
Decl>())
235 else if (
const auto *S = N.
get<
Stmt>())
239 else if (
const auto *T = N.
get<
Type>())
261 for (
const auto &TP : *TPL)
264 if (
const Expr *RC = TPL->getRequiresClause())
278 const Decl *From =
nullptr,
279 const char *Label =
nullptr) {
284 for (
unsigned i = 0, e = TAL.
size(); i < e; ++i)
292 for (
const auto &typeParam : *typeParams) {
354 for (
const auto &Arg : *T)
356 if (T->isTypeAlias())
357 Visit(T->getAliasedType());
390 if (
const auto *
C = dyn_cast<CXXConstructorDecl>(D))
391 for (
const auto *I :
C->inits())
454 template <
typename SpecializationDecl>
456 for (
const auto *RedeclWithBadType : D->redecls()) {
460 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
465 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
466 "expected an injected-class-name");
473 template <
typename TemplateDecl>
479 for (
const auto *Child : D->specializations())
541 if (TC->hasExplicitTemplateArgs())
542 for (
const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
574 Visit(TD->getTypeForDecl());
602 for (
const auto &I : D->
inits())
616 for (
const auto &D : Node->
decls())
621 for (
const auto *A : Node->
getAttrs())
634 for (
const auto *
C : Node->
clauses())
640 Visit(Filler,
"array_filler");
662 for (
unsigned I = 0, N = Node->
capture_size(); I != N; ++I) {
664 if (!
C->isExplicit())
667 Visit(
C->getCapturedVar());
700 #include "clang/AST/AttrNodeTraverse.inc" 705 #endif // LLVM_CLANG_AST_ASTNODETRAVERSER_H clauselist_range clauselists()
void dumpTemplateDeclSpecialization(const SpecializationDecl *D)
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
const BlockDecl * getBlockDecl() const
const Type * Ty
The locally-unqualified type.
Represents a function declaration or definition.
Expr * getInit() const
Get the initializer.
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D)
Expr * getCopyExpr() const
bool getDeserialize() const
A class which contains all the information about a particular captured value.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getElementType() const
QualType getPointeeType() const
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D)
void VisitAttributedStmt(const AttributedStmt *Node)
A (possibly-)qualified type.
void dumpTemplateParameters(const TemplateParameterList *TPL)
ArrayRef< OMPClause * > clauses()
void VisitBlockPointerType(const BlockPointerType *T)
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
void VisitAdjustedType(const AdjustedType *T)
void VisitPackTemplateArgument(const TemplateArgument &TA)
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
RetTy Visit(REF(TemplateArgument) TA, ParamTys... P)
void dumpTemplateArgumentList(const TemplateArgumentList &TAL)
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Expr * getUnderlyingExpr() const
void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node)
void VisitOMPDeclareMapperDecl(const OMPDeclareMapperDecl *D)
Stmt - This represents one statement.
Expr * getBitWidth() const
This represents '#pragma omp allocate ...' directive.
FunctionType - C99 6.7.5.3 - Function Declarators.
An instance of this object exists for each enum constant that is defined.
void VisitAttributedType(const AttributedType *T)
Represents the declaration of a typedef-name via the 'typedef' type specifier.
void VisitFunctionDecl(const FunctionDecl *D)
unsigned size() const
Retrieve the number of template arguments in this template argument list.
const T * get() const
Retrieve the stored node as type T.
Decl - This represents one declaration (or definition), e.g.
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
void VisitExpressionTemplateArgument(const TemplateArgument &TA)
Represents an attribute applied to a statement.
The base class of the type hierarchy.
const DefArgStorage & getDefaultArgStorage() const
Declaration of a variable template.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
RetTy Visit(const Type *T)
Performs the operation associated with this visitor object.
A container of type source information.
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
void Visit(const comments::Comment *C, const comments::FullComment *FC)
void dumpASTTemplateArgumentListInfo(const ASTTemplateArgumentListInfo *TALI)
QualType getElementType() const
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
void VisitBlockExpr(const BlockExpr *Node)
Represents a variable declaration or definition.
void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D)
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
void VisitCXXCatchStmt(const CXXCatchStmt *Node)
Represents a variable template specialization, which refers to a variable template with a given set o...
ObjCMethodDecl - Represents an instance or class method declaration.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
void VisitVarTemplatePartialSpecializationDecl(const VarTemplatePartialSpecializationDecl *D)
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Stores a list of template parameters for a TemplateDecl and its derived classes.
void Visit(const Decl *D)
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Represents a parameter to a function.
Represents the result of substituting a type for a template type parameter.
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
void VisitObjCMethodDecl(const ObjCMethodDecl *D)
QualType getOriginalType() const
Represents a class template specialization, which refers to a class template with a given set of temp...
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
StringLiteral * getMessage()
QualType getPointeeType() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
void VisitVariableArrayType(const VariableArrayType *T)
ArrayRef< QualType > getParamTypes() const
Will traverse all child nodes.
void VisitGenericSelectionExpr(const GenericSelectionExpr *E)
const DefArgStorage & getDefaultArgStorage() const
Represents a member of a struct/union/class.
A simple visitor class that helps create attribute visitors.
void VisitSizeOfPackExpr(const SizeOfPackExpr *Node)
CompoundStmt * getBody() const
Retrieve the body of the lambda.
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class. ...
Represents the result of substituting a set of types for a template type parameter pack...
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
void Visit(const OMPClause *C)
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
void VisitOMPAllocateDecl(const OMPAllocateDecl *D)
Declaration of a function specialization at template class scope.
SourceRange getSourceRange() const LLVM_READONLY
void VisitFunctionProtoType(const FunctionProtoType *T)
ArrayRef< ParmVarDecl * > parameters() const
Represents Objective-C's @catch statement.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Describes an C or C++ initializer list.
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
ArrayRef< BindingDecl * > bindings() const
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
AssociationTy< true > ConstAssociation
bool isBitField() const
Determines whether this field is a bitfield.
void VisitTypeOfExprType(const TypeOfExprType *T)
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
void VisitPackExpansionType(const PackExpansionType *T)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
void VisitTemplateSpecializationType(const TemplateSpecializationType *T)
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
A simple visitor class that helps create template argument visitors.
Represents a typeof (or typeof) expression (a GCC extension).
void VisitUsingShadowDecl(const UsingShadowDecl *D)
const Type * getClass() const
void VisitOMPExecutableDirective(const OMPExecutableDirective *Node)
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Expr * getSizeExpr() const
void Visit(const Type *T)
void VisitCapturedDecl(const CapturedDecl *D)
const Expr * getInitExpr() const
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D)
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
void VisitBlockDecl(const BlockDecl *D)
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Represents the body of a CapturedStmt, and serves as its DeclContext.
Represents an ObjC class declaration.
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
void VisitCapturedStmt(const CapturedStmt *Node)
A binding in a decomposition declaration.
Expr * getSizeExpr() const
void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams)
void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, const Decl *From=nullptr, const char *Label=nullptr)
QualType getElementType() const
Represents an extended vector type where either the type or size is dependent.
param_iterator param_begin()
void VisitInitListExpr(const InitListExpr *ILE)
void Visit(const Stmt *Node, StringRef Label={})
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Represents a prototype with parameter type info, e.g.
void Visit(const GenericSelectionExpr::ConstAssociation &A)
Holds a QualType and a TypeSourceInfo* that came out of a declarator parsing.
void VisitFriendDecl(const FriendDecl *D)
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D)
void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D)
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
void VisitObjCObjectPointerType(const ObjCObjectPointerType *T)
void VisitFieldDecl(const FieldDecl *D)
Represents an array type in C++ whose size is a value-dependent expression.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
QualType getElementType() const
Represents a block literal declaration, which is like an unnamed FunctionDecl.
This represents one expression.
QualType getPointeeType() const
Expr * getPlaceholderTypeConstraint() const
Return the constraint introduced by the placeholder type of this non-type template parameter (if any)...
Declaration of a template type parameter.
Will not traverse implicit casts and parentheses.
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
void dumpTemplateDecl(const TemplateDecl *D)
VarDecl * getExceptionDecl() const
Ignore AST nodes not written in the source.
Represents an expression that computes the length of a parameter pack.
void Visit(const CXXCtorInitializer *Init)
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents the type decltype(expr) (C++11).
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
void VisitVarTemplateDecl(const VarTemplateDecl *D)
Qualifiers Quals
The local qualifiers.
Declaration of an alias template.
void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D)
clauselist_range clauselists()
void VisitEnumConstantDecl(const EnumConstantDecl *D)
Represents a GCC generic vector type.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
void VisitBindingDecl(const BindingDecl *D)
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
Expr * getUnderlyingExpr() const
void SetTraversalKind(ast_type_traits::TraversalKind TK)
void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D)
void VisitDecltypeType(const DecltypeType *T)
bool hasQualifiers() const
Return true if the set contains any qualifiers.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
void VisitReferenceType(const ReferenceType *T)
void VisitClassScopeFunctionSpecializationDecl(const ClassScopeFunctionSpecializationDecl *D)
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
This captures a statement into a function.
void VisitPipeType(const PipeType *T)
void VisitVarDecl(const VarDecl *D)
void VisitArrayType(const ArrayType *T)
void Visit(const ast_type_traits::DynTypedNode &N)
QualType getReturnType() const
void VisitObjCCategoryDecl(const ObjCCategoryDecl *D)
This represents '#pragma omp declare reduction ...' directive.
Pseudo declaration for capturing expressions.
This is a basic class for representing single OpenMP executable directive.
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
void VisitDecompositionDecl(const DecompositionDecl *D)
void VisitOpaqueValueExpr(const OpaqueValueExpr *Node)
TemplateArgument getArgumentPack() const
ASTContext & getASTContext() const LLVM_READONLY
QualType getElementType() const
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
void Visit(const TemplateArgument &A, SourceRange R={}, const Decl *From=nullptr, const char *Label=nullptr)
void VisitDeclStmt(const DeclStmt *Node)
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
void VisitLocInfoType(const LocInfoType *T)
void VisitFunctionType(const FunctionType *T)
void VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T)
QualType getLocallyUnqualifiedSingleStepDesugaredType() const
Pull a single level of sugar off of this locally-unqualified type.
ObjCCategoryDecl - Represents a category declaration.
This is a basic class for representing single OpenMP clause.
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
unsigned capture_size() const
Determine the number of captures in this lambda.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
ASTNodeTraverser traverses the Clang AST for dumping purposes.
void VisitClassTemplateDecl(const ClassTemplateDecl *D)
const ParmDecl * getInheritedFrom() const
Get the parameter from which we inherit the default argument, if any.
Represents a C++11 static_assert declaration.
void VisitComplexType(const ComplexType *T)
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
void setDeserialize(bool D)
Represents a pack expansion of types.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Represents a C11 generic selection.
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
ast_type_traits::DynTypedNode Node
Represents a template argument.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Dataflow Directional Tag Classes.
void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D)
TypeSourceInfo * getTypeSourceInfo() const
const TemplateArgument & getArgument() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
ArrayRef< Capture > captures() const
void Visit(const Attr *A)
The base class of all kinds of template declarations (e.g., class, function, etc.).
void VisitAtomicType(const AtomicType *T)
void VisitStaticAssertDecl(const StaticAssertDecl *D)
ArrayRef< const Attr * > getAttrs() const
void VisitConceptDecl(const ConceptDecl *D)
QualType getUnderlyingType() const
const Expr * getInit() const
A decomposition declaration.
void VisitPointerType(const PointerType *T)
A pointer to member type per C++ 8.3.3 - Pointers to members.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
void VisitTypeAliasDecl(const TypeAliasDecl *D)
TemplateParameterList * getTemplateParameterList() const
If this is a generic lambda expression, retrieve the template parameter list associated with it...
void VisitMemberPointerType(const MemberPointerType *T)
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
const DefArgStorage & getDefaultArgStorage() const
A dynamically typed AST node container.
QualType getModifiedType() const
Represents a pointer to an Objective C object.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D)
Complex values, per C99 6.2.5p11.
Location wrapper for a TemplateArgument.
comments::FullComment * getLocalCommentForDeclUncached(const Decl *D) const
Return parsed documentation comment attached to a given declaration.
Represents a C++ base or member initializer.
void VisitClassTemplatePartialSpecializationDecl(const ClassTemplatePartialSpecializationDecl *D)
bool hasBody() const override
Determine whether this method has a body.
TraversalKind
Defines how we descend a level in the AST when we pass through expressions.
Base for LValueReferenceType and RValueReferenceType.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
void VisitClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl *D)
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof...
void Visit(const BlockDecl::Capture &C)
void VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *D)
A template argument list.
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
An attributed type is a type to which a type attribute has been applied.
void dumpDeclContext(const DeclContext *DC)
CXXCatchStmt - This represents a C++ catch block.
The parameter type of a method or function.
Declaration of a class template.
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
CXXMethodDecl * getSpecialization() const
This represents '#pragma omp declare mapper ...' directive.
void VisitVectorType(const VectorType *T)
void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T)
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T)
RetTy Visit(PTR(Stmt) S, ParamTys... P)
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Represents a type template specialization; the template must be a class template, a type alias templa...
ArrayRef< ParmVarDecl * > parameters() const
Expr * getBinding() const
Get the expression to which this declaration is bound.
const VarDecl * getCatchParamDecl() const
void VisitLambdaExpr(const LambdaExpr *Node)
QualType getDefaultArgument() const
Retrieve the default argument, if any.
A trivial tuple used to represent a source range.
void VisitDependentSizedArrayType(const DependentSizedArrayType *T)
Represents a C array with a specified size that is not an integer-constant-expression.
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D)
Expr * getConstraintExpr() const
A simple visitor class that helps create declaration visitors.
This represents '#pragma omp threadprivate ...' directive.
void VisitUnaryTransformType(const UnaryTransformType *T)
Declaration of a template function.
Attr - This represents one attribute.
const StringLiteral * getAsmString() const
QualType getPointeeType() const
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
void VisitTypedefDecl(const TypedefDecl *D)
QualType getType() const
Return the type wrapped by this type source info.
association_range associations()
ArrayRef< ParmVarDecl * > parameters() const
Expr * getSizeExpr() const
void VisitObjCImplementationDecl(const ObjCImplementationDecl *D)
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.