clang API Documentation

Namespaces | Classes | Functions | Variables
clang::ast_matchers Namespace Reference

Namespaces

namespace  dynamic
namespace  internal

Classes

class  BoundNodes
 Maps string IDs to AST nodes matched by parts of a matcher. More...
class  MatchFinder
 A class to allow finding matches over the Clang AST. More...

Typedefs

typedef internal::Matcher< DeclDeclarationMatcher
 Types of matchers for the top-level classes in the AST class hierarchy.
typedef internal::Matcher< StmtStatementMatcher
typedef internal::Matcher
< QualType
TypeMatcher
typedef internal::Matcher
< TypeLoc
TypeLocMatcher
typedef internal::Matcher
< NestedNameSpecifier
NestedNameSpecifierMatcher
typedef internal::Matcher
< NestedNameSpecifierLoc
NestedNameSpecifierLocMatcher

Functions

template<typename T >
internal::Matcher< T > id (const std::string &ID, const internal::BindableMatcher< T > &InnerMatcher)
 If the provided matcher matches a node, binds the node to ID.
internal::TrueMatcher anything ()
 Matches any node.
 AST_MATCHER (Decl, isPublic)
 Matches public C++ declarations.
 AST_MATCHER (Decl, isProtected)
 Matches protected C++ declarations.
 AST_MATCHER (Decl, isPrivate)
 Matches private C++ declarations.
 AST_MATCHER (Decl, isImplicit)
 Matches a declaration that has been implicitly added by the compiler (eg. implicit default/copy constructors).
 AST_POLYMORPHIC_MATCHER_P (hasAnyTemplateArgument, AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl, TemplateSpecializationType), internal::Matcher< TemplateArgument >, InnerMatcher)
 Matches classTemplateSpecializations that have at least one TemplateArgument matching the given InnerMatcher.
 AST_MATCHER_P (Expr, ignoringImpCasts, internal::Matcher< Expr >, InnerMatcher)
 Matches expressions that match InnerMatcher after any implicit casts are stripped off.
 AST_MATCHER_P (Expr, ignoringParenCasts, internal::Matcher< Expr >, InnerMatcher)
 Matches expressions that match InnerMatcher after parentheses and casts are stripped off.
 AST_MATCHER_P (Expr, ignoringParenImpCasts, internal::Matcher< Expr >, InnerMatcher)
 Matches expressions that match InnerMatcher after implicit casts and parentheses are stripped off.
 AST_POLYMORPHIC_MATCHER_P2 (hasTemplateArgument, AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl, TemplateSpecializationType), unsigned, N, internal::Matcher< TemplateArgument >, InnerMatcher)
 Matches classTemplateSpecializations where the n'th TemplateArgument matches the given InnerMatcher.
 AST_POLYMORPHIC_MATCHER_P (templateArgumentCountIs, AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl, TemplateSpecializationType), unsigned, N)
 Matches if the number of template arguments equals N.
 AST_MATCHER_P (TemplateArgument, refersToType, internal::Matcher< QualType >, InnerMatcher)
 Matches a TemplateArgument that refers to a certain type.
 AST_MATCHER_P (TemplateArgument, refersToDeclaration, internal::Matcher< Decl >, InnerMatcher)
 Matches a canonical TemplateArgument that refers to a certain declaration.
 AST_MATCHER_P (TemplateArgument, isExpr, internal::Matcher< Expr >, InnerMatcher)
 Matches a sugar TemplateArgument that refers to a certain expression.
 AST_MATCHER (TemplateArgument, isIntegral)
 Matches a TemplateArgument that is an integral value.
 AST_MATCHER_P (TemplateArgument, refersToIntegralType, internal::Matcher< QualType >, InnerMatcher)
 Matches a TemplateArgument that referes to an integral type.
 AST_MATCHER_P (TemplateArgument, equalsIntegralValue, std::string, Value)
 Matches a TemplateArgument of integral type with a given value.
 AST_MATCHER_P (ForStmt, hasIncrement, internal::Matcher< Stmt >, InnerMatcher)
 Matches the increment statement of a for loop.
 AST_MATCHER_P (ForStmt, hasLoopInit, internal::Matcher< Stmt >, InnerMatcher)
 Matches the initialization statement of a for loop.
 AST_MATCHER_P (CXXForRangeStmt, hasLoopVariable, internal::Matcher< VarDecl >, InnerMatcher)
 Matches the initialization statement of a for loop.
 AST_MATCHER_P (CXXForRangeStmt, hasRangeInit, internal::Matcher< Expr >, InnerMatcher)
 Matches the range initialization statement of a for loop.
 AST_MATCHER_P (UnaryExprOrTypeTraitExpr, hasArgumentOfType, internal::Matcher< QualType >, InnerMatcher)
 Matches unary expressions that have a specific type of argument.
 AST_MATCHER_P (UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind)
 Matches unary expressions of a certain kind.
internal::Matcher< StmtalignOfExpr (const internal::Matcher< UnaryExprOrTypeTraitExpr > &InnerMatcher)
 Same as unaryExprOrTypeTraitExpr, but only matching alignof.
internal::Matcher< StmtsizeOfExpr (const internal::Matcher< UnaryExprOrTypeTraitExpr > &InnerMatcher)
 Same as unaryExprOrTypeTraitExpr, but only matching sizeof.
internal::Matcher< NamedDeclhasName (const std::string &Name)
 Matches NamedDecl nodes that have the specified name.
 AST_MATCHER_P (NamedDecl, matchesName, std::string, RegExp)
 Matches NamedDecl nodes whose fully qualified names contain a substring matched by the given RegExp.
internal::PolymorphicMatcherWithParam1
< internal::HasOverloadedOperatorNameMatcher,
StringRef,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(CXXOperatorCallExpr,
FunctionDecl)> 
hasOverloadedOperatorName (StringRef Name)
 Matches overloaded operator names.
 AST_MATCHER_P (CXXRecordDecl, isDerivedFrom, internal::Matcher< NamedDecl >, Base)
 Matches C++ classes that are directly or indirectly derived from a class matching Base.
 AST_MATCHER_P_OVERLOAD (CXXRecordDecl, isDerivedFrom, StringRef, BaseName, 1)
 Overloaded method as shortcut for isDerivedFrom(hasName(...)).
 AST_MATCHER_P_OVERLOAD (CXXRecordDecl, isSameOrDerivedFrom, internal::Matcher< NamedDecl >, Base, 0)
 Similar to isDerivedFrom(), but also matches classes that directly match Base.
 AST_MATCHER_P_OVERLOAD (CXXRecordDecl, isSameOrDerivedFrom, StringRef, BaseName, 1)
 Overloaded method as shortcut for isSameOrDerivedFrom(hasName(...)).
template<typename T >
internal::Matcher< T > findAll (const internal::Matcher< T > &Matcher)
 Matches if the node or any descendant matches.
internal::PolymorphicMatcherWithParam1
< internal::HasDeclarationMatcher,
internal::Matcher< Decl >
, void(internal::HasDeclarationSupportedTypes)> 
hasDeclaration (const internal::Matcher< Decl > &InnerMatcher)
 Matches a node if the declaration associated with that node matches the given matcher.
 AST_MATCHER_P (CXXMemberCallExpr, on, internal::Matcher< Expr >, InnerMatcher)
 Matches on the implicit object argument of a member call expression.
 AST_MATCHER_P (CallExpr, callee, internal::Matcher< Stmt >, InnerMatcher)
 Matches if the call expression's callee expression matches.
 AST_MATCHER_P_OVERLOAD (CallExpr, callee, internal::Matcher< Decl >, InnerMatcher, 1)
 Matches if the call expression's callee's declaration matches the given matcher.
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD (hasType, AST_POLYMORPHIC_SUPPORTED_TYPES_2(Expr, ValueDecl), internal::Matcher< QualType >, InnerMatcher, 0)
 Matches if the expression's or declaration's type matches a type matcher.
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD (hasType, AST_POLYMORPHIC_SUPPORTED_TYPES_2(Expr, ValueDecl), internal::Matcher< Decl >, InnerMatcher, 1)
 Overloaded to match the declaration of the expression's or value declaration's type.
 AST_MATCHER_P (DeclaratorDecl, hasTypeLoc, internal::Matcher< TypeLoc >, Inner)
 Matches if the type location of the declarator decl's type matches the inner matcher.
 AST_MATCHER_P (QualType, asString, std::string, Name)
 Matches if the matched type is represented by the given string.
 AST_MATCHER_P (QualType, pointsTo, internal::Matcher< QualType >, InnerMatcher)
 Matches if the matched type is a pointer type and the pointee type matches the specified matcher.
 AST_MATCHER_P_OVERLOAD (QualType, pointsTo, internal::Matcher< Decl >, InnerMatcher, 1)
 Overloaded to match the pointee type's declaration.
 AST_MATCHER_P (QualType, references, internal::Matcher< QualType >, InnerMatcher)
 Matches if the matched type is a reference type and the referenced type matches the specified matcher.
 AST_MATCHER_P (DeclRefExpr, to, internal::Matcher< Decl >, InnerMatcher)
 Matches QualTypes whose canonical type matches InnerMatcher.
 AST_MATCHER_P (DeclRefExpr, throughUsingDecl, internal::Matcher< UsingShadowDecl >, InnerMatcher)
 Matches a DeclRefExpr that refers to a declaration through a specific using shadow declaration.
 AST_MATCHER_P (DeclStmt, hasSingleDecl, internal::Matcher< Decl >, InnerMatcher)
 Matches the Decl of a DeclStmt which has a single declaration.
 AST_MATCHER_P (VarDecl, hasInitializer, internal::Matcher< Expr >, InnerMatcher)
 Matches a variable declaration that has an initializer expression that matches the given matcher.
 AST_MATCHER (VarDecl, hasLocalStorage)
 Matches a variable declaration that has function scope and is a non-static local variable.
 AST_MATCHER (VarDecl, hasGlobalStorage)
 Matches a variable declaration that does not have local storage.
 AST_POLYMORPHIC_MATCHER_P (argumentCountIs, AST_POLYMORPHIC_SUPPORTED_TYPES_2(CallExpr, CXXConstructExpr), unsigned, N)
 Checks that a call expression or a constructor call expression has a specific number of arguments (including absent default arguments).
 AST_POLYMORPHIC_MATCHER_P2 (hasArgument, AST_POLYMORPHIC_SUPPORTED_TYPES_2(CallExpr, CXXConstructExpr), unsigned, N, internal::Matcher< Expr >, InnerMatcher)
 Matches the n'th argument of a call expression or a constructor call expression.
 AST_MATCHER_P (DeclStmt, declCountIs, unsigned, N)
 Matches declaration statements that contain a specific number of declarations.
 AST_MATCHER_P2 (DeclStmt, containsDeclaration, unsigned, N, internal::Matcher< Decl >, InnerMatcher)
 Matches the n'th declaration of a declaration statement.
 AST_MATCHER_P (CXXConstructorDecl, hasAnyConstructorInitializer, internal::Matcher< CXXCtorInitializer >, InnerMatcher)
 Matches a constructor initializer.
 AST_MATCHER_P (CXXCtorInitializer, forField, internal::Matcher< FieldDecl >, InnerMatcher)
 Matches the field declaration of a constructor initializer.
 AST_MATCHER_P (CXXCtorInitializer, withInitializer, internal::Matcher< Expr >, InnerMatcher)
 Matches the initializer expression of a constructor initializer.
 AST_MATCHER (CXXCtorInitializer, isWritten)
 Matches a constructor initializer if it is explicitly written in code (as opposed to implicitly added by the compiler).
 AST_POLYMORPHIC_MATCHER_P (hasAnyArgument, AST_POLYMORPHIC_SUPPORTED_TYPES_2(CallExpr, CXXConstructExpr), internal::Matcher< Expr >, InnerMatcher)
 Matches any argument of a call expression or a constructor call expression.
 AST_MATCHER (CXXConstructExpr, isListInitialization)
 Matches a constructor call expression which uses list initialization.
 AST_MATCHER_P2 (FunctionDecl, hasParameter, unsigned, N, internal::Matcher< ParmVarDecl >, InnerMatcher)
 Matches the n'th parameter of a function declaration.
 AST_MATCHER_P (FunctionDecl, hasAnyParameter, internal::Matcher< ParmVarDecl >, InnerMatcher)
 Matches any parameter of a function declaration.
 AST_MATCHER_P (FunctionDecl, parameterCountIs, unsigned, N)
 Matches FunctionDecls that have a specific parameter count.
 AST_MATCHER_P (FunctionDecl, returns, internal::Matcher< QualType >, InnerMatcher)
 Matches the return type of a function declaration.
 AST_MATCHER (FunctionDecl, isExternC)
 Matches extern "C" function declarations.
 AST_MATCHER (FunctionDecl, isDeleted)
 Matches deleted function declarations.
 AST_POLYMORPHIC_MATCHER_P (hasCondition, AST_POLYMORPHIC_SUPPORTED_TYPES_5(IfStmt, ForStmt, WhileStmt, DoStmt, ConditionalOperator), internal::Matcher< Expr >, InnerMatcher)
 Matches the condition expression of an if statement, for loop, or conditional operator.
 AST_MATCHER_P (IfStmt, hasThen, internal::Matcher< Stmt >, InnerMatcher)
 Matches the then-statement of an if statement.
 AST_MATCHER_P (IfStmt, hasElse, internal::Matcher< Stmt >, InnerMatcher)
 Matches the else-statement of an if statement.
 AST_POLYMORPHIC_MATCHER_P (equalsBoundNode, AST_POLYMORPHIC_SUPPORTED_TYPES_4(Stmt, Decl, Type, QualType), std::string, ID)
 Matches if a node equals a previously bound node.
 AST_MATCHER_P (IfStmt, hasConditionVariableStatement, internal::Matcher< DeclStmt >, InnerMatcher)
 Matches the condition variable statement in an if statement.
 AST_MATCHER_P (ArraySubscriptExpr, hasIndex, internal::Matcher< Expr >, InnerMatcher)
 Matches the index expression of an array subscript expression.
 AST_MATCHER_P (ArraySubscriptExpr, hasBase, internal::Matcher< Expr >, InnerMatcher)
 Matches the base expression of an array subscript expression.
 AST_POLYMORPHIC_MATCHER_P (hasBody, AST_POLYMORPHIC_SUPPORTED_TYPES_4(DoStmt, ForStmt, WhileStmt, CXXForRangeStmt), internal::Matcher< Stmt >, InnerMatcher)
 Matches a 'for', 'while', or 'do while' statement that has a given body.
 AST_MATCHER_P (CompoundStmt, hasAnySubstatement, internal::Matcher< Stmt >, InnerMatcher)
 Matches compound statements where at least one substatement matches a given matcher.
 AST_MATCHER_P (CompoundStmt, statementCountIs, unsigned, N)
 Checks that a compound statement contains a specific number of child statements.
template<typename ValueT >
internal::PolymorphicMatcherWithParam1
< internal::ValueEqualsMatcher,
ValueT > 
equals (const ValueT &Value)
 Matches literals that are equal to the given value.
 AST_POLYMORPHIC_MATCHER_P (hasOperatorName, AST_POLYMORPHIC_SUPPORTED_TYPES_2(BinaryOperator, UnaryOperator), std::string, Name)
 Matches the operator Name of operator expressions (binary or unary).
 AST_MATCHER_P (BinaryOperator, hasLHS, internal::Matcher< Expr >, InnerMatcher)
 Matches the left hand side of binary operator expressions.
 AST_MATCHER_P (BinaryOperator, hasRHS, internal::Matcher< Expr >, InnerMatcher)
 Matches the right hand side of binary operator expressions.
internal::Matcher< BinaryOperatorhasEitherOperand (const internal::Matcher< Expr > &InnerMatcher)
 Matches if either the left hand side or the right hand side of a binary operator matches.
 AST_MATCHER_P (UnaryOperator, hasUnaryOperand, internal::Matcher< Expr >, InnerMatcher)
 Matches if the operand of a unary operator matches.
 AST_MATCHER_P (ConditionalOperator, hasTrueExpression, internal::Matcher< Expr >, InnerMatcher)
 Matches if the cast's source expression matches the given matcher.
 AST_MATCHER_P (ConditionalOperator, hasFalseExpression, internal::Matcher< Expr >, InnerMatcher)
 Matches the false branch expression of a conditional operator.
 AST_POLYMORPHIC_MATCHER (isDefinition, AST_POLYMORPHIC_SUPPORTED_TYPES_3(TagDecl, VarDecl, FunctionDecl))
 Matches if a declaration has a body attached.
 AST_MATCHER_P (CXXMethodDecl, ofClass, internal::Matcher< CXXRecordDecl >, InnerMatcher)
 Matches the class declaration that the given method declaration belongs to.
 AST_MATCHER (CXXMethodDecl, isVirtual)
 Matches if the given method declaration is virtual.
 AST_MATCHER (CXXMethodDecl, isPure)
 Matches if the given method declaration is pure.
 AST_MATCHER (CXXMethodDecl, isConst)
 Matches if the given method declaration is const.
 AST_MATCHER (CXXMethodDecl, isOverride)
 Matches if the given method declaration overrides another method.
 AST_MATCHER (MemberExpr, isArrow)
 Matches member expressions that are called with '->' as opposed to '.'.
 AST_MATCHER (QualType, isInteger)
 Matches QualType nodes that are of integer type.
 AST_MATCHER (QualType, isConstQualified)
 Matches QualType nodes that are const-qualified, i.e., that include "top-level" const.
 AST_MATCHER (QualType, hasLocalQualifiers)
 Matches QualType nodes that have local CV-qualifiers attached to the node, not hidden within a typedef.
 AST_MATCHER_P (MemberExpr, member, internal::Matcher< ValueDecl >, InnerMatcher)
 Matches a member expression where the member is matched by a given matcher.
 AST_MATCHER_P (MemberExpr, hasObjectExpression, internal::Matcher< Expr >, InnerMatcher)
 Matches a member expression where the object expression is matched by a given matcher.
 AST_MATCHER_P (UsingDecl, hasAnyUsingShadowDecl, internal::Matcher< UsingShadowDecl >, InnerMatcher)
 Matches any using shadow declaration.
 AST_MATCHER_P (UsingShadowDecl, hasTargetDecl, internal::Matcher< NamedDecl >, InnerMatcher)
 Matches a using shadow declaration where the target declaration is matched by the given matcher.
 AST_POLYMORPHIC_MATCHER (isTemplateInstantiation, AST_POLYMORPHIC_SUPPORTED_TYPES_3(FunctionDecl, VarDecl, CXXRecordDecl))
 Matches template instantiations of function, class, or static member variable template instantiations.
 AST_MATCHER (Decl, isInstantiated)
 Matches declarations that are template instantiations or are inside template instantiations.
 AST_MATCHER (Stmt, isInTemplateInstantiation)
 Matches statements inside of a template instantiation.
 AST_POLYMORPHIC_MATCHER (isExplicitTemplateSpecialization, AST_POLYMORPHIC_SUPPORTED_TYPES_3(FunctionDecl, VarDecl, CXXRecordDecl))
 Matches explicit template specializations of function, class, or static member variable template instantiations.
 AST_MATCHER_FUNCTION_P_OVERLOAD (internal::BindableMatcher< TypeLoc >, loc, internal::Matcher< QualType >, InnerMatcher, 0)
 Matches TypeLocs for which the given inner QualType-matcher matches.
 AST_TYPE_MATCHER (BuiltinType, builtinType)
 Matches builtin Types.
 AST_TYPE_MATCHER (ArrayType, arrayType)
 Matches all kinds of arrays.
 AST_TYPE_MATCHER (ComplexType, complexType)
 Matches C99 complex types.
 AST_TYPELOC_TRAVERSE_MATCHER (hasElementType, getElement, AST_POLYMORPHIC_SUPPORTED_TYPES_2(ArrayType, ComplexType))
 Matches arrays and C99 complex types that have a specific element type.
 AST_TYPE_MATCHER (ConstantArrayType, constantArrayType)
 Matches C arrays with a specified constant size.
 AST_MATCHER_P (ConstantArrayType, hasSize, unsigned, N)
 Matches ConstantArrayType nodes that have the specified size.
 AST_TYPE_MATCHER (DependentSizedArrayType, dependentSizedArrayType)
 Matches C++ arrays whose size is a value-dependent expression.
 AST_TYPE_MATCHER (IncompleteArrayType, incompleteArrayType)
 Matches C arrays with unspecified size.
 AST_TYPE_MATCHER (VariableArrayType, variableArrayType)
 Matches C arrays with a specified size that is not an integer-constant-expression.
 AST_MATCHER_P (VariableArrayType, hasSizeExpr, internal::Matcher< Expr >, InnerMatcher)
 Matches VariableArrayType nodes that have a specific size expression.
 AST_TYPE_MATCHER (AtomicType, atomicType)
 Matches atomic types.
 AST_TYPELOC_TRAVERSE_MATCHER (hasValueType, getValue, AST_POLYMORPHIC_SUPPORTED_TYPES_1(AtomicType))
 Matches atomic types with a specific value type.
 AST_TYPE_MATCHER (AutoType, autoType)
 Matches types nodes representing C++11 auto types.
 AST_TYPE_TRAVERSE_MATCHER (hasDeducedType, getDeducedType, AST_POLYMORPHIC_SUPPORTED_TYPES_1(AutoType))
 Matches AutoType nodes where the deduced type is a specific type.
 AST_TYPE_MATCHER (FunctionType, functionType)
 Matches FunctionType nodes.
 AST_TYPE_MATCHER (ParenType, parenType)
 Matches ParenType nodes.
 AST_TYPE_TRAVERSE_MATCHER (innerType, getInnerType, AST_POLYMORPHIC_SUPPORTED_TYPES_1(ParenType))
 Matches ParenType nodes where the inner type is a specific type.
 AST_TYPE_MATCHER (BlockPointerType, blockPointerType)
 Matches block pointer types, i.e. types syntactically represented as "void (^)(int)".
 AST_TYPE_MATCHER (MemberPointerType, memberPointerType)
 Matches member pointer types. Given.
 AST_TYPE_MATCHER (PointerType, pointerType)
 Matches pointer types.
 AST_TYPE_MATCHER (ReferenceType, referenceType)
 Matches both lvalue and rvalue reference types.
 AST_TYPE_MATCHER (LValueReferenceType, lValueReferenceType)
 Matches lvalue reference types.
 AST_TYPE_MATCHER (RValueReferenceType, rValueReferenceType)
 Matches rvalue reference types.
 AST_TYPELOC_TRAVERSE_MATCHER (pointee, getPointee, AST_POLYMORPHIC_SUPPORTED_TYPES_4(BlockPointerType, MemberPointerType, PointerType, ReferenceType))
 Narrows PointerType (and similar) matchers to those where the pointee matches a given matcher.
 AST_TYPE_MATCHER (TypedefType, typedefType)
 Matches typedef types.
 AST_TYPE_MATCHER (UnaryTransformType, unaryTransformType)
 Matches template specialization types.
 AST_MATCHER_FUNCTION_P_OVERLOAD (internal::BindableMatcher< NestedNameSpecifierLoc >, loc, internal::Matcher< NestedNameSpecifier >, InnerMatcher, 1)
 Matches NestedNameSpecifierLocs for which the given inner NestedNameSpecifier-matcher matches.
 AST_MATCHER_P (NestedNameSpecifier, specifiesType, internal::Matcher< QualType >, InnerMatcher)
 Matches nested name specifiers that specify a type matching the given QualType matcher without qualifiers.
 AST_MATCHER_P (NestedNameSpecifierLoc, specifiesTypeLoc, internal::Matcher< TypeLoc >, InnerMatcher)
 Matches nested name specifier locs that specify a type matching the given TypeLoc.
 AST_MATCHER_P_OVERLOAD (NestedNameSpecifier, hasPrefix, internal::Matcher< NestedNameSpecifier >, InnerMatcher, 0)
 Matches on the prefix of a NestedNameSpecifier.
 AST_MATCHER_P_OVERLOAD (NestedNameSpecifierLoc, hasPrefix, internal::Matcher< NestedNameSpecifierLoc >, InnerMatcher, 1)
 Matches on the prefix of a NestedNameSpecifierLoc.
 AST_MATCHER_P (NestedNameSpecifier, specifiesNamespace, internal::Matcher< NamespaceDecl >, InnerMatcher)
 Matches nested name specifiers that specify a namespace matching the given namespace matcher.
 AST_MATCHER_P (SwitchStmt, forEachSwitchCase, internal::Matcher< SwitchCase >, InnerMatcher)
 Matches each case or default statement belonging to the given switch statement. This matcher may produce multiple matches.
 AST_MATCHER_P (CXXConstructorDecl, forEachConstructorInitializer, internal::Matcher< CXXCtorInitializer >, InnerMatcher)
 Matches each constructor initializer in a constructor definition.
 AST_MATCHER_P (CaseStmt, hasCaseConstant, internal::Matcher< Expr >, InnerMatcher)
 If the given case statement does not use the GNU case range extension, matches the constant given in the statement.
 AST_MATCHER_P (Decl, hasAttr, attr::Kind, AttrKind)
 Matches declaration that has a given attribute.
template<typename NodeT >
const NodeT * selectFirst (StringRef BoundTo, const SmallVectorImpl< BoundNodes > &Results)
 Returns the first result of type NodeT bound to BoundTo.
 AST_MATCHER_P_OVERLOAD (Decl, equalsNode, const Decl *, Other, 0)
 Overloads for the equalsNode matcher. FIXME: Implement for other node types.
 AST_MATCHER_P_OVERLOAD (Stmt, equalsNode, const Stmt *, Other, 1)
 Matches if a node equals another node.
template<typename MatcherT , typename NodeT >
SmallVector< BoundNodes, 1 > match (MatcherT Matcher, const NodeT &Node, ASTContext &Context)
 Returns the results of matching Matcher on Node.
template<typename MatcherT >
SmallVector< BoundNodes, 1 > match (MatcherT Matcher, const ast_type_traits::DynTypedNode &Node, ASTContext &Context)

Variables

const
internal::VariadicAllOfMatcher
< Decl
decl
 Matches declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, LinkageSpecDecl
linkageSpecDecl
 Matches a declaration of a linkage specification.
const
internal::VariadicDynCastAllOfMatcher
< Decl, NamedDecl
namedDecl
 Matches a declaration of anything that could have a name.
const
internal::VariadicDynCastAllOfMatcher
< Decl, NamespaceDecl
namespaceDecl
 Matches a declaration of a namespace.
const
internal::VariadicDynCastAllOfMatcher
< Decl, CXXRecordDecl
recordDecl
 Matches C++ class declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, ClassTemplateDecl
classTemplateDecl
 Matches C++ class template declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl,
ClassTemplateSpecializationDecl
classTemplateSpecializationDecl
 Matches C++ class template specializations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, DeclaratorDecl
declaratorDecl
 Matches declarator declarations (field, variable, function and non-type template parameter declarations).
const
internal::VariadicDynCastAllOfMatcher
< Decl, ParmVarDecl
parmVarDecl
 Matches parameter variable declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, AccessSpecDecl
accessSpecDecl
 Matches C++ access specifier declarations.
const
internal::VariadicAllOfMatcher
< CXXCtorInitializer
ctorInitializer
 Matches constructor initializers.
const
internal::VariadicAllOfMatcher
< TemplateArgument
templateArgument
 Matches template arguments.
const
internal::VariadicDynCastAllOfMatcher
< Decl, ValueDecl
valueDecl
 Matches any value declaration.
const
internal::VariadicDynCastAllOfMatcher
< Decl, CXXConstructorDecl
constructorDecl
 Matches C++ constructor declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, CXXDestructorDecl
destructorDecl
 Matches explicit C++ destructor declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, EnumDecl
enumDecl
 Matches enum declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, EnumConstantDecl
enumConstantDecl
 Matches enum constants.
const
internal::VariadicDynCastAllOfMatcher
< Decl, CXXMethodDecl
methodDecl
 Matches method declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, VarDecl
varDecl
 Matches variable declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, FieldDecl
fieldDecl
 Matches field declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, FunctionDecl
functionDecl
 Matches function declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, FunctionTemplateDecl
functionTemplateDecl
 Matches C++ function template declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, FriendDecl
friendDecl
 Matches friend declarations.
const
internal::VariadicAllOfMatcher
< Stmt
stmt
 Matches statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, DeclStmt
declStmt
 Matches declaration statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, MemberExpr
memberExpr
 Matches member expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CallExpr
callExpr
 Matches call expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, LambdaExpr
lambdaExpr
 Matches lambda expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXMemberCallExpr
memberCallExpr
 Matches member call expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ExprWithCleanups
exprWithCleanups
 Matches expressions that introduce cleanups to be run at the end of the sub-expression's evaluation.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, InitListExpr
initListExpr
 Matches init list expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt,
SubstNonTypeTemplateParmExpr
substNonTypeTemplateParmExpr
 Matches substitutions of non-type template parameters.
const
internal::VariadicDynCastAllOfMatcher
< Decl, UsingDecl
usingDecl
 Matches using declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl, UsingDirectiveDecl
usingDirectiveDecl
 Matches using namespace declarations.
const
internal::VariadicDynCastAllOfMatcher
< Decl,
UnresolvedUsingValueDecl
unresolvedUsingValueDecl
 Matches unresolved using value declarations.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXConstructExpr
constructExpr
 Matches constructor call expressions (including implicit ones).
const
internal::VariadicDynCastAllOfMatcher
< Stmt,
CXXUnresolvedConstructExpr
unresolvedConstructExpr
 Matches unresolved constructor call expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXThisExpr
thisExpr
 Matches implicit and explicit this expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXBindTemporaryExpr
bindTemporaryExpr
 Matches nodes where temporaries are created.
const
internal::VariadicDynCastAllOfMatcher
< Stmt,
MaterializeTemporaryExpr
materializeTemporaryExpr
 Matches nodes where temporaries are materialized.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXNewExpr
newExpr
 Matches new expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXDeleteExpr
deleteExpr
 Matches delete expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ArraySubscriptExpr
arraySubscriptExpr
 Matches array subscript expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXDefaultArgExpr
defaultArgExpr
 Matches the value of a default argument at the call site.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXOperatorCallExpr
operatorCallExpr
 Matches overloaded operator calls.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, Expr
expr
 Matches expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, DeclRefExpr
declRefExpr
 Matches expressions that refer to declarations.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, IfStmt
ifStmt
 Matches if statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ForStmt
forStmt
 Matches for statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXForRangeStmt
forRangeStmt
 Matches range-based for statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, WhileStmt
whileStmt
 Matches while statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, DoStmt
doStmt
 Matches do statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, BreakStmt
breakStmt
 Matches break statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ContinueStmt
continueStmt
 Matches continue statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ReturnStmt
returnStmt
 Matches return statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, GotoStmt
gotoStmt
 Matches goto statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, LabelStmt
labelStmt
 Matches label statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, SwitchStmt
switchStmt
 Matches switch statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, SwitchCase
switchCase
 Matches case and default statements inside switch statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CaseStmt
caseStmt
 Matches case statements inside switch statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, DefaultStmt
defaultStmt
 Matches default statements inside switch statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CompoundStmt
compoundStmt
 Matches compound statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXCatchStmt
catchStmt
 Matches catch statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXTryStmt
tryStmt
 Matches try statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXThrowExpr
throwExpr
 Matches throw expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, NullStmt
nullStmt
 Matches null statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, AsmStmt
asmStmt
 Matches asm statements.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXBoolLiteralExpr
boolLiteral
 Matches bool literals.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, StringLiteral
stringLiteral
 Matches string literals (also matches wide string literals).
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CharacterLiteral
characterLiteral
 Matches character literals (also matches wchar_t).
const
internal::VariadicDynCastAllOfMatcher
< Stmt, IntegerLiteral
integerLiteral
 Matches integer literals of all sizes / encodings, e.g. 1, 1L, 0x1 and 1U.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, FloatingLiteral
floatLiteral
 Matches float literals of all sizes / encodings, e.g. 1.0, 1.0f, 1.0L and 1e10.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, UserDefinedLiteral
userDefinedLiteral
 Matches user defined literal operator call.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CompoundLiteralExpr
compoundLiteralExpr
 Matches compound (i.e. non-scalar) literals.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXNullPtrLiteralExpr
nullPtrLiteralExpr
 Matches nullptr literal.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, BinaryOperator
binaryOperator
 Matches binary operator expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, UnaryOperator
unaryOperator
 Matches unary operator expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ConditionalOperator
conditionalOperator
 Matches conditional operator expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXReinterpretCastExpr
reinterpretCastExpr
 Matches a reinterpret_cast expression.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXStaticCastExpr
staticCastExpr
 Matches a C++ static_cast expression.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXDynamicCastExpr
dynamicCastExpr
 Matches a dynamic_cast expression.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXConstCastExpr
constCastExpr
 Matches a const_cast expression.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CStyleCastExpr
cStyleCastExpr
 Matches a C-style cast expression.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ExplicitCastExpr
explicitCastExpr
 Matches explicit cast expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, ImplicitCastExpr
implicitCastExpr
 Matches the implicit cast nodes of Clang's AST.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CastExpr
castExpr
 Matches any cast nodes of Clang's AST.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXFunctionalCastExpr
functionalCastExpr
 Matches functional cast expressions.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CXXTemporaryObjectExpr
temporaryObjectExpr
 Matches functional cast expressions having N != 1 arguments.
const
internal::VariadicAllOfMatcher
< QualType
qualType
 Matches QualTypes in the clang AST.
const
internal::VariadicAllOfMatcher
< Type
type
 Matches Types in the clang AST.
const
internal::VariadicAllOfMatcher
< TypeLoc
typeLoc
 Matches TypeLocs in the clang AST.
const
internal::VariadicOperatorMatcherFunc
< 2, UINT_MAX
eachOf
 Matches if any of the given matchers matches.
const
internal::VariadicOperatorMatcherFunc
< 2, UINT_MAX
anyOf
 Matches if any of the given matchers matches.
const
internal::VariadicOperatorMatcherFunc
< 2, UINT_MAX
allOf
 Matches if all given matchers match.
const
internal::VariadicDynCastAllOfMatcher
< Stmt,
UnaryExprOrTypeTraitExpr
unaryExprOrTypeTraitExpr
 Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
const
internal::ArgumentAdaptingMatcherFunc
< internal::HasMatcher >
LLVM_ATTRIBUTE_UNUSED 
has = {}
 Matches the first method of a class or struct that satisfies InnerMatcher.
const
internal::ArgumentAdaptingMatcherFunc
< internal::HasDescendantMatcher >
LLVM_ATTRIBUTE_UNUSED 
hasDescendant = {}
 Matches AST nodes that have descendant AST nodes that match the provided matcher.
const
internal::ArgumentAdaptingMatcherFunc
< internal::ForEachMatcher >
LLVM_ATTRIBUTE_UNUSED 
forEach = {}
 Matches AST nodes that have child AST nodes that match the provided matcher.
const
internal::ArgumentAdaptingMatcherFunc
< internal::ForEachDescendantMatcher >
LLVM_ATTRIBUTE_UNUSED 
forEachDescendant = {}
 Matches AST nodes that have descendant AST nodes that match the provided matcher.
const
internal::ArgumentAdaptingMatcherFunc
< internal::HasParentMatcher,
internal::TypeList< Decl, Stmt >
, internal::TypeList< Decl,
Stmt > > LLVM_ATTRIBUTE_UNUSED 
hasParent = {}
 Matches AST nodes that have a parent that matches the provided matcher.
const
internal::ArgumentAdaptingMatcherFunc
< internal::HasAncestorMatcher,
internal::TypeList< Decl, Stmt >
, internal::TypeList< Decl,
Stmt > > LLVM_ATTRIBUTE_UNUSED 
hasAncestor = {}
 Matches AST nodes that have an ancestor that matches the provided matcher.
const
internal::VariadicOperatorMatcherFunc< 1, 1 > 
unless
 Matches if the provided matcher does not match.
const
internal::VariadicAllOfMatcher
< NestedNameSpecifier
nestedNameSpecifier
 Matches record types (e.g. structs, classes).
const
internal::VariadicAllOfMatcher
< NestedNameSpecifierLoc
nestedNameSpecifierLoc
 Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.
const
internal::VariadicDynCastAllOfMatcher
< Stmt, CUDAKernelCallExpr
CUDAKernelCallExpr
 Matches CUDA kernel call expression.

Typedef Documentation

Types of matchers for the top-level classes in the AST class hierarchy.

Definition at line 121 of file ASTMatchers.h.

Definition at line 126 of file ASTMatchers.h.

Definition at line 125 of file ASTMatchers.h.

Definition at line 122 of file ASTMatchers.h.

Definition at line 124 of file ASTMatchers.h.

Definition at line 123 of file ASTMatchers.h.


Function Documentation

internal::Matcher<Stmt> clang::ast_matchers::alignOfExpr ( const internal::Matcher< UnaryExprOrTypeTraitExpr > &  InnerMatcher) [inline]

Same as unaryExprOrTypeTraitExpr, but only matching alignof.

Definition at line 1574 of file ASTMatchers.h.

References allOf, stmt, clang::UETT_AlignOf, and unaryExprOrTypeTraitExpr.

internal::TrueMatcher clang::ast_matchers::anything ( ) [inline]

Matches any node.

Useful when another matcher requires a child matcher, but there's no additional constraint. This will often be used with an explicit conversion to an internal::Matcher<> type such as TypeMatcher.

Example: DeclarationMatcher(anything()) matches all declarations, e.g.,

 "int* p" and "void f()" in
   int* p;
   void f();

Usable as: Any Matcher

Definition at line 143 of file ASTMatchers.h.

clang::ast_matchers::AST_MATCHER ( Decl  ,
isPublic   
)

Matches public C++ declarations.

Given

   class C {
   public:    int a;
   protected: int b;
   private:   int c;
   };

fieldDecl(isPublic()) matches 'int a;'

Definition at line 297 of file ASTMatchers.h.

References clang::AS_public, and Node.

clang::ast_matchers::AST_MATCHER ( Decl  ,
isProtected   
)

Matches protected C++ declarations.

Given

   class C {
   public:    int a;
   protected: int b;
   private:   int c;
   };

fieldDecl(isProtected()) matches 'int b;'

Definition at line 313 of file ASTMatchers.h.

References clang::AS_protected, and Node.

clang::ast_matchers::AST_MATCHER ( Decl  ,
isPrivate   
)

Matches private C++ declarations.

Given

   class C {
   public:    int a;
   protected: int b;
   private:   int c;
   };

fieldDecl(isPrivate()) matches 'int c;'

Definition at line 329 of file ASTMatchers.h.

References clang::AS_private, and Node.

clang::ast_matchers::AST_MATCHER ( Decl  ,
isImplicit   
)

Matches a declaration that has been implicitly added by the compiler (eg. implicit default/copy constructors).

Definition at line 335 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( TemplateArgument  ,
isIntegral   
)

Matches a TemplateArgument that is an integral value.

Given

   template<int T> struct A {};
   C<42> c;

classTemplateSpecializationDecl( hasAnyTemplateArgument(isIntegral())) matches the implicit instantiation of C in C<42> with isIntegral() matching 42.

Definition at line 547 of file ASTMatchers.h.

References clang::TemplateArgument::Integral, and Node.

clang::ast_matchers::AST_MATCHER ( VarDecl  ,
hasLocalStorage   
)

Matches a variable declaration that has function scope and is a non-static local variable.

Example matches x (matcher = varDecl(hasLocalStorage())

 void f() {
   int x;
   static int y;
 }
 int z;

Definition at line 2188 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( VarDecl  ,
hasGlobalStorage   
)

Matches a variable declaration that does not have local storage.

Example matches y and z (matcher = varDecl(hasGlobalStorage())

 void f() {
   int x;
   static int y;
 }
 int z;

Definition at line 2202 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( CXXCtorInitializer  ,
isWritten   
)

Matches a constructor initializer if it is explicitly written in code (as opposed to implicitly added by the compiler).

Given

   struct Foo {
     Foo() { }
     Foo(int) : foo_("A") { }
     string foo_;
   };

constructorDecl(hasAnyConstructorInitializer(isWritten())) will match Foo(int), but not Foo()

Definition at line 2351 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( CXXConstructExpr  ,
isListInitialization   
)

Matches a constructor call expression which uses list initialization.

Definition at line 2385 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( FunctionDecl  ,
isExternC   
)

Matches extern "C" function declarations.

Given:

   extern "C" void f() {}
   extern "C" { void g() {} }
   void h() {}

functionDecl(isExternC()) matches the declaration of f and g, but not the declaration h

Definition at line 2461 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( FunctionDecl  ,
isDeleted   
)

Matches deleted function declarations.

Given:

   void Func();
   void DeletedFunc() = delete;

functionDecl(isDeleted()) matches the declaration of DeletedFunc, but not Func.

Definition at line 2474 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( CXXMethodDecl  ,
isVirtual   
)

Matches if the given method declaration is virtual.

Given

   class A {
    public:
     virtual void x();
   };

matches A::x

Definition at line 2842 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( CXXMethodDecl  ,
isPure   
)

Matches if the given method declaration is pure.

Given

   class A {
    public:
     virtual void x() = 0;
   };

matches A::x

Definition at line 2856 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( CXXMethodDecl  ,
isConst   
)

Matches if the given method declaration is const.

Given

 struct A {
   void foo() const;
   void bar();
 };

methodDecl(isConst()) matches A::foo() but not A::bar()

Definition at line 2871 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( CXXMethodDecl  ,
isOverride   
)

Matches if the given method declaration overrides another method.

Given

   class A {
    public:
     virtual void x();
   };
   class B : public A {
    public:
     virtual void x();
   };

matches B::x

Definition at line 2889 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( MemberExpr  ,
isArrow   
)

Matches member expressions that are called with '->' as opposed to '.'.

Member calls on the implicit this pointer match as called with '->'.

Given

   class Y {
     void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
     int a;
     static int b;
   };

memberExpr(isArrow()) matches this->x, x, y.x, a, this->b

Definition at line 2908 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( QualType  ,
isInteger   
)

Matches QualType nodes that are of integer type.

Given

   void a(int);
   void b(long);
   void c(double);

functionDecl(hasAnyParameter(hasType(isInteger()))) matches "a(int)", "b(long)", but not "c(double)".

Definition at line 2922 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( QualType  ,
isConstQualified   
)

Matches QualType nodes that are const-qualified, i.e., that include "top-level" const.

Given

   void a(int);
   void b(int const);
   void c(const int);
   void d(const int*);
   void e(int const) {};

functionDecl(hasAnyParameter(hasType(isConstQualified()))) matches "void b(int const)", "void c(const int)" and "void e(int const) {}". It does not match d as there is no top-level const on the parameter type "const int *".

Definition at line 2941 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( QualType  ,
hasLocalQualifiers   
)

Matches QualType nodes that have local CV-qualifiers attached to the node, not hidden within a typedef.

Given

   typedef const int const_int;
   const_int i;
   int *const j;
   int *volatile k;
   int m;

varDecl(hasType(hasLocalQualifiers())) matches only j and k. i is const-qualified but the qualifier is not local.

Definition at line 2958 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER ( Decl  ,
isInstantiated   
)

Matches declarations that are template instantiations or are inside template instantiations.

Given

   template<typename T> void A(T t) { T i; }
   A(0);
   A(0U);

functionDecl(isInstantiated()) matches 'A(int) {...};' and 'A(unsigned) {...}'.

Definition at line 3070 of file ASTMatchers.h.

References anyOf, Builder, decl, Finder, functionDecl, hasAncestor, InnerMatcher, clang::isTemplateInstantiation(), Node, and recordDecl.

clang::ast_matchers::AST_MATCHER ( Stmt  ,
isInTemplateInstantiation   
)

Matches statements inside of a template instantiation.

Given

   int j;
   template<typename T> void A(T t) { T i; j += 42;}
   A(0);
   A(0U);

declStmt(isInTemplateInstantiation()) matches 'int i;' and 'unsigned i'. unless(stmt(isInTemplateInstantiation())) will NOT match j += 42; as it's shared between the template definition and instantiation.

Definition at line 3092 of file ASTMatchers.h.

References anyOf, Builder, decl, Finder, functionDecl, hasAncestor, InnerMatcher, clang::isTemplateInstantiation(), Node, recordDecl, and stmt.

clang::ast_matchers::AST_MATCHER_FUNCTION_P_OVERLOAD ( internal::BindableMatcher< TypeLoc >  ,
loc  ,
internal::Matcher< QualType >  ,
InnerMatcher  ,
 
)

Matches TypeLocs for which the given inner QualType-matcher matches.

Definition at line 3119 of file ASTMatchers.h.

References InnerMatcher.

clang::ast_matchers::AST_MATCHER_FUNCTION_P_OVERLOAD ( internal::BindableMatcher< NestedNameSpecifierLoc >  ,
loc  ,
internal::Matcher< NestedNameSpecifier >  ,
InnerMatcher  ,
 
)

Matches NestedNameSpecifierLocs for which the given inner NestedNameSpecifier-matcher matches.

Definition at line 3605 of file ASTMatchers.h.

References InnerMatcher.

clang::ast_matchers::AST_MATCHER_P ( Expr  ,
ignoringImpCasts  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches expressions that match InnerMatcher after any implicit casts are stripped off.

Parentheses and explicit casts are not discarded. Given

   int arr[5];
   int a = 0;
   char b = 0;
   const int c = a;
   int *d = arr;
   long e = (long) 0l;

The matchers

    varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
    varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))

would match the declarations for a, b, c, and d, but not e. While

    varDecl(hasInitializer(integerLiteral()))
    varDecl(hasInitializer(declRefExpr()))

only match the declarations for b, c, and d.

Definition at line 387 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( Expr  ,
ignoringParenCasts  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches expressions that match InnerMatcher after parentheses and casts are stripped off.

Implicit and non-C Style casts are also discarded. Given

   int a = 0;
   char b = (0);
   void* c = reinterpret_cast<char*>(0);
   char d = char(0);

The matcher varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) would match the declarations for a, b, c, and d. while varDecl(hasInitializer(integerLiteral())) only match the declaration for a.

Definition at line 409 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( Expr  ,
ignoringParenImpCasts  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches expressions that match InnerMatcher after implicit casts and parentheses are stripped off.

Explicit casts are not discarded. Given

   int arr[5];
   int a = 0;
   char b = (0);
   const int c = a;
   int *d = (arr);
   long e = ((long) 0l);

The matchers varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) would match the declarations for a, b, c, and d, but not e. while varDecl(hasInitializer(integerLiteral())) varDecl(hasInitializer(declRefExpr())) would only match the declaration for a.

Definition at line 434 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( TemplateArgument  ,
refersToType  ,
internal::Matcher< QualType >  ,
InnerMatcher   
)

Matches a TemplateArgument that refers to a certain type.

Given

   struct X {};
   template<typename T> struct A {};
   A<X> a;

classTemplateSpecializationDecl(hasAnyTemplateArgument( refersToType(class(hasName("X"))))) matches the specialization A<X>

Definition at line 491 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, Node, and clang::TemplateArgument::Type.

clang::ast_matchers::AST_MATCHER_P ( TemplateArgument  ,
refersToDeclaration  ,
internal::Matcher< Decl >  ,
InnerMatcher   
)

Matches a canonical TemplateArgument that refers to a certain declaration.

Given

   template<typename T> struct A {};
   struct B { B* next; };
   A<&B::next> a;

classTemplateSpecializationDecl(hasAnyTemplateArgument( refersToDeclaration(fieldDecl(hasName("next")))) matches the specialization A<&B::next> with fieldDecl(...) matching B::next

Definition at line 511 of file ASTMatchers.h.

References Builder, clang::TemplateArgument::Declaration, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( TemplateArgument  ,
isExpr  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches a sugar TemplateArgument that refers to a certain expression.

Given

   template<typename T> struct A {};
   struct B { B* next; };
   A<&B::next> a;

templateSpecializationType(hasAnyTemplateArgument( isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) matches the specialization A<&B::next> with fieldDecl(...) matching B::next

Definition at line 530 of file ASTMatchers.h.

References Builder, clang::TemplateArgument::Expression, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( TemplateArgument  ,
refersToIntegralType  ,
internal::Matcher< QualType >  ,
InnerMatcher   
)

Matches a TemplateArgument that referes to an integral type.

Given

   template<int T> struct A {};
   C<42> c;

classTemplateSpecializationDecl( hasAnyTemplateArgument(refersToIntegralType(asString("int")))) matches the implicit instantiation of C in C<42>.

Definition at line 561 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, clang::TemplateArgument::Integral, and Node.

clang::ast_matchers::AST_MATCHER_P ( TemplateArgument  ,
equalsIntegralValue  ,
std::string  ,
Value   
)

Matches a TemplateArgument of integral type with a given value.

Note that 'Value' is a string as the template argument's value is an arbitrary precision integer. 'Value' must be euqal to the canonical representation of that integral value in base 10.

Given

   template<int T> struct A {};
   C<42> c;

classTemplateSpecializationDecl( hasAnyTemplateArgument(equalsIntegralValue("42"))) matches the implicit instantiation of C in C<42>.

Definition at line 582 of file ASTMatchers.h.

References clang::TemplateArgument::Integral, and Node.

clang::ast_matchers::AST_MATCHER_P ( ForStmt  ,
hasIncrement  ,
internal::Matcher< Stmt >  ,
InnerMatcher   
)

Matches the increment statement of a for loop.

Example: forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) matches '++x' in

     for (x; x < N; ++x) { }

Definition at line 1019 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( ForStmt  ,
hasLoopInit  ,
internal::Matcher< Stmt >  ,
InnerMatcher   
)

Matches the initialization statement of a for loop.

Example: forStmt(hasLoopInit(declStmt())) matches 'int x = 0' in

     for (int x = 0; x < N; ++x) { }

Definition at line 1034 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CXXForRangeStmt  ,
hasLoopVariable  ,
internal::Matcher< VarDecl >  ,
InnerMatcher   
)

Matches the initialization statement of a for loop.

Example: forStmt(hasLoopVariable(anything())) matches 'int x' in

     for (int x : a) { }

Definition at line 1057 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CXXForRangeStmt  ,
hasRangeInit  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the range initialization statement of a for loop.

Example: forStmt(hasRangeInit(anything())) matches 'a' in

     for (int x : a) { }

Definition at line 1071 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( UnaryExprOrTypeTraitExpr  ,
hasArgumentOfType  ,
internal::Matcher< QualType >  ,
InnerMatcher   
)

Matches unary expressions that have a specific type of argument.

Given

   int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);

unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) matches sizeof(a) and alignof(c)

Definition at line 1553 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( UnaryExprOrTypeTraitExpr  ,
ofKind  ,
UnaryExprOrTypeTrait  ,
Kind   
)

Matches unary expressions of a certain kind.

Given

   int x;
   int s = sizeof(x) + alignof(x)

unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) matches sizeof(x)

Definition at line 1568 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P ( NamedDecl  ,
matchesName  ,
std::string  ,
RegExp   
)

Matches NamedDecl nodes whose fully qualified names contain a substring matched by the given RegExp.

Supports specifying enclosing namespaces or classes by prefixing the name with '<enclosing>::'. Does not match typedefs of an underlying type with the given name.

Example matches X (regexp == "::X")

   class X;

Example matches X (regexp is one of "::X", "^foo::.*X", among others)

   namespace foo { namespace bar { class X; } }

Definition at line 1623 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P ( CXXRecordDecl  ,
isDerivedFrom  ,
internal::Matcher< NamedDecl >  ,
Base   
)

Matches C++ classes that are directly or indirectly derived from a class matching Base.

Note that a class is not considered to be derived from itself.

Example matches Y, Z, C (Base == hasName("X"))

   class X;
   class Y : public X {};  // directly derived
   class Z : public Y {};  // indirectly derived
   typedef X A;
   typedef A B;
   class C : public B {};  // derived from a typedef of X

In the following example, Bar matches isDerivedFrom(hasName("X")):

   class Foo;
   typedef Foo X;
   class Bar : public Foo {};  // derived from a type that X is a typedef of

Definition at line 1679 of file ASTMatchers.h.

References Builder, Finder, and Node.

clang::ast_matchers::AST_MATCHER_P ( CXXMemberCallExpr  ,
on  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches on the implicit object argument of a member call expression.

Example matches y.x() (matcher = callExpr(on(hasType(recordDecl(hasName("Y"))))))

   class Y { public: void x(); };
   void z() { Y y; y.x(); }",

FIXME: Overload to allow directly matching types?

Definition at line 1900 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CallExpr  ,
callee  ,
internal::Matcher< Stmt >  ,
InnerMatcher   
)

Matches if the call expression's callee expression matches.

Given

   class Y { void x() { this->x(); x(); Y y; y.x(); } };
   void f() { f(); }

callExpr(callee(expr())) matches this->x(), x(), y.x(), f() with callee(...) matching this->x, x, y.x, f respectively

Note: Callee cannot take the more general internal::Matcher<Expr> because this introduces ambiguous overloads with calls to Callee taking a internal::Matcher<Decl>, as the matcher hierarchy is purely implemented in terms of implicit casts.

Definition at line 1924 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( DeclaratorDecl  ,
hasTypeLoc  ,
internal::Matcher< TypeLoc >  ,
Inner   
)

Matches if the type location of the declarator decl's type matches the inner matcher.

Given

   int x;

declaratorDecl(hasTypeLoc(loc(asString("int")))) matches int x

Definition at line 1992 of file ASTMatchers.h.

References Builder, Finder, and Node.

clang::ast_matchers::AST_MATCHER_P ( QualType  ,
asString  ,
std::string  ,
Name   
)

Matches if the matched type is represented by the given string.

Given

   class Y { public: void x(); };
   void z() { Y* y; y->x(); }

callExpr(on(hasType(asString("class Y *")))) matches y->x()

Definition at line 2008 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P ( QualType  ,
pointsTo  ,
internal::Matcher< QualType >  ,
InnerMatcher   
)

Matches if the matched type is a pointer type and the pointee type matches the specified matcher.

Example matches y->x() (matcher = callExpr(on(hasType(pointsTo(recordDecl(hasName("Y")))))))

   class Y { public: void x(); };
   void z() { Y *y; y->x(); }

Definition at line 2021 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( QualType  ,
references  ,
internal::Matcher< QualType >  ,
InnerMatcher   
)

Matches if the matched type is a reference type and the referenced type matches the specified matcher.

Example matches X &x and const X &y (matcher = varDecl(hasType(references(recordDecl(hasName("X"))))))

   class X {
     void a(X b) {
       X &x = b;
       const X &y = b;
     }
   };

Definition at line 2048 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( DeclRefExpr  ,
to  ,
internal::Matcher< Decl >  ,
InnerMatcher   
)

Matches QualTypes whose canonical type matches InnerMatcher.

Given:

   typedef int &int_ref;
   int a;
   int_ref b = a;
 \code

 \c varDecl(hasType(qualType(referenceType()))))) will not match the
 declaration of b but \c
 varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does.
AST_MATCHER_P(QualType, hasCanonicalType, internal::Matcher<QualType>,
              InnerMatcher) {
  if (Node.isNull())
    return false;
  return InnerMatcher.matches(Node.getCanonicalType(), Finder, Builder);
}

 \brief Overloaded to match the referenced type's declaration.
AST_MATCHER_P_OVERLOAD(QualType, references, internal::Matcher<Decl>,
                       InnerMatcher, 1) {
  return references(qualType(hasDeclaration(InnerMatcher)))
      .matches(Node, Finder, Builder);
}

AST_MATCHER_P(CXXMemberCallExpr, onImplicitObjectArgument,
              internal::Matcher<Expr>, InnerMatcher) {
  const Expr *ExprNode = Node.getImplicitObjectArgument();
  return (ExprNode != nullptr &&
          InnerMatcher.matches(*ExprNode, Finder, Builder));
}

 \brief Matches if the expression's type either matches the specified
 matcher, or is a pointer to a type that matches the InnerMatcher.
AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType,
                       internal::Matcher<QualType>, InnerMatcher, 0) {
  return onImplicitObjectArgument(
      anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher))))
      .matches(Node, Finder, Builder);
}

 \brief Overloaded to match the type's declaration.
AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType,
                       internal::Matcher<Decl>, InnerMatcher, 1) {
  return onImplicitObjectArgument(
      anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher))))
      .matches(Node, Finder, Builder);
}

 \brief Matches a DeclRefExpr that refers to a declaration that matches the
 specified matcher.

 Example matches x in if(x)
     (matcher = declRefExpr(to(varDecl(hasName("x")))))
 \code
   bool x;
   if (x) {}

Definition at line 2113 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( DeclRefExpr  ,
throughUsingDecl  ,
internal::Matcher< UsingShadowDecl >  ,
InnerMatcher   
)

Matches a DeclRefExpr that refers to a declaration through a specific using shadow declaration.

FIXME: This currently only works for functions. Fix.

Given

   namespace a { void f() {} }
   using a::f;
   void g() {
     f();     // Matches this ..
     a::f();  // .. but not this.
   }

declRefExpr(throughUsingDeclaration(anything())) matches f()

Definition at line 2136 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( DeclStmt  ,
hasSingleDecl  ,
internal::Matcher< Decl >  ,
InnerMatcher   
)

Matches the Decl of a DeclStmt which has a single declaration.

Given

   int a, b;
   int c;

declStmt(hasSingleDecl(anything())) matches 'int c;' but not 'int a, b;'.

Definition at line 2153 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( VarDecl  ,
hasInitializer  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches a variable declaration that has an initializer expression that matches the given matcher.

Example matches x (matcher = varDecl(hasInitializer(callExpr())))

   bool y() { return true; }
   bool x = y();

Definition at line 2169 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( DeclStmt  ,
declCountIs  ,
unsigned  ,
 
)

Matches declaration statements that contain a specific number of declarations.

Example: Given

   int a, b;
   int c;
   int d = 2, e;

declCountIs(2) matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.

Definition at line 2248 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P ( CXXConstructorDecl  ,
hasAnyConstructorInitializer  ,
internal::Matcher< CXXCtorInitializer >  ,
InnerMatcher   
)

Matches a constructor initializer.

Given

   struct Foo {
     Foo() : foo_(1) { }
     int foo_;
   };

recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything())))) record matches Foo, hasAnyConstructorInitializer matches foo_(1)

Definition at line 2292 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CXXCtorInitializer  ,
forField  ,
internal::Matcher< FieldDecl >  ,
InnerMatcher   
)

Matches the field declaration of a constructor initializer.

Given

   struct Foo {
     Foo() : foo_(1) { }
     int foo_;
   };

recordDecl(has(constructorDecl(hasAnyConstructorInitializer( forField(hasName("foo_")))))) matches Foo with forField matching foo_

Definition at line 2311 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CXXCtorInitializer  ,
withInitializer  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the initializer expression of a constructor initializer.

Given

   struct Foo {
     Foo() : foo_(1) { }
     int foo_;
   };

recordDecl(has(constructorDecl(hasAnyConstructorInitializer( withInitializer(integerLiteral(equals(1))))))) matches Foo with withInitializer matching (1)

Definition at line 2331 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( FunctionDecl  ,
hasAnyParameter  ,
internal::Matcher< ParmVarDecl >  ,
InnerMatcher   
)

Matches any parameter of a function declaration.

Does not match the 'this' parameter of a method.

Given

   class X { void f(int x, int y, int z) {} };

methodDecl(hasAnyParameter(hasName("y"))) matches f(int x, int y, int z) {} with hasAnyParameter(...) matching int y

Definition at line 2419 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( FunctionDecl  ,
parameterCountIs  ,
unsigned  ,
 
)

Matches FunctionDecls that have a specific parameter count.

Given

   void f(int i) {}
   void g(int i, int j) {}

functionDecl(parameterCountIs(2)) matches g(int i, int j) {}

Definition at line 2434 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P ( FunctionDecl  ,
returns  ,
internal::Matcher< QualType >  ,
InnerMatcher   
)

Matches the return type of a function declaration.

Given:

   class X { int f() { return 1; } };

methodDecl(returns(asString("int"))) matches int f() { return 1; }

Definition at line 2446 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( IfStmt  ,
hasThen  ,
internal::Matcher< Stmt >  ,
InnerMatcher   
)

Matches the then-statement of an if statement.

Examples matches the if statement (matcher = ifStmt(hasThen(boolLiteral(equals(true)))))

   if (false) true; else false;

Definition at line 2501 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( IfStmt  ,
hasElse  ,
internal::Matcher< Stmt >  ,
InnerMatcher   
)

Matches the else-statement of an if statement.

Examples matches the if statement (matcher = ifStmt(hasElse(boolLiteral(equals(true)))))

   if (false) false; else true;

Definition at line 2513 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( IfStmt  ,
hasConditionVariableStatement  ,
internal::Matcher< DeclStmt >  ,
InnerMatcher   
)

Matches the condition variable statement in an if statement.

Given

   if (A* a = GetAPointer()) {}

hasConditionVariableStatement(...) matches 'A* a = GetAPointer()'.

Definition at line 2562 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( ArraySubscriptExpr  ,
hasIndex  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the index expression of an array subscript expression.

Given

   int i[5];
   void f() { i[1] = 42; }

arraySubscriptExpression(hasIndex(integerLiteral())) matches i[1] with the integerLiteral() matching 1

Definition at line 2579 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( ArraySubscriptExpr  ,
hasBase  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the base expression of an array subscript expression.

Given

   int i[5];
   void f() { i[1] = 42; }

arraySubscriptExpression(hasBase(implicitCastExpr( hasSourceExpression(declRefExpr())))) matches i[1] with the declRefExpr() matching i

Definition at line 2596 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CompoundStmt  ,
hasAnySubstatement  ,
internal::Matcher< Stmt >  ,
InnerMatcher   
)

Matches compound statements where at least one substatement matches a given matcher.

Given

   { {}; 1+2; }

hasAnySubstatement(compoundStmt()) matches '{ {}; 1+2; }' with compoundStmt() matching '{}'

Definition at line 2635 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CompoundStmt  ,
statementCountIs  ,
unsigned  ,
 
)

Checks that a compound statement contains a specific number of child statements.

Example: Given

   { for (;;) {} }

compoundStmt(statementCountIs(0))) matches '{}' but does not match the outer compound statement.

Definition at line 2651 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P ( BinaryOperator  ,
hasLHS  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the left hand side of binary operator expressions.

Example matches a (matcher = binaryOperator(hasLHS()))

   a || b

Definition at line 2691 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( BinaryOperator  ,
hasRHS  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the right hand side of binary operator expressions.

Example matches b (matcher = binaryOperator(hasRHS()))

   a || b

Definition at line 2704 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( UnaryOperator  ,
hasUnaryOperand  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches if the operand of a unary operator matches.

Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true))))

   !true

Definition at line 2724 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( ConditionalOperator  ,
hasTrueExpression  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches if the cast's source expression matches the given matcher.

Example: matches "a string" (matcher = hasSourceExpression(constructExpr()))

 class URL { URL(string); };
 URL url = "a string";
AST_MATCHER_P(CastExpr, hasSourceExpression,
              internal::Matcher<Expr>, InnerMatcher) {
  const Expr* const SubExpression = Node.getSubExpr();
  return (SubExpression != nullptr &&
          InnerMatcher.matches(*SubExpression, Finder, Builder));
}

 \brief Matches casts whose destination type matches a given matcher.

 (Note: Clang's AST refers to other conversions as "casts" too, and calls
 actual casts "explicit" casts.)
AST_MATCHER_P(ExplicitCastExpr, hasDestinationType,
              internal::Matcher<QualType>, InnerMatcher) {
  const QualType NodeType = Node.getTypeAsWritten();
  return InnerMatcher.matches(NodeType, Finder, Builder);
}

 \brief Matches implicit casts whose destination type matches a given
 matcher.

 FIXME: Unit test this matcher
AST_MATCHER_P(ImplicitCastExpr, hasImplicitDestinationType,
              internal::Matcher<QualType>, InnerMatcher) {
  return InnerMatcher.matches(Node.getType(), Finder, Builder);
}

 \brief Matches the true branch expression of a conditional operator.

 Example matches a
 \code
   condition ? a : b

Definition at line 2770 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( ConditionalOperator  ,
hasFalseExpression  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the false branch expression of a conditional operator.

Example matches b

   condition ? a : b

Definition at line 2783 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CXXMethodDecl  ,
ofClass  ,
internal::Matcher< CXXRecordDecl >  ,
InnerMatcher   
)

Matches the class declaration that the given method declaration belongs to.

FIXME: Generalize this for other kinds of declarations. FIXME: What other kind of declarations would we need to generalize this to?

Example matches A() in the last line (matcher = constructExpr(hasDeclaration(methodDecl( ofClass(hasName("A"))))))

   class A {
    public:
     A();
   };
   A a = A();

Definition at line 2825 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( MemberExpr  ,
member  ,
internal::Matcher< ValueDecl >  ,
InnerMatcher   
)

Matches a member expression where the member is matched by a given matcher.

Given

   struct { int first, second; } first, second;
   int i(second.first);
   int j(first.second);

memberExpr(member(hasName("first"))) matches second.first but not first.second (because the member name there is "second").

Definition at line 2974 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( MemberExpr  ,
hasObjectExpression  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches a member expression where the object expression is matched by a given matcher.

Given

   struct X { int m; };
   void f(X x) { x.m; m; }

memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X"))))))) matches "x.m" and "m" with hasObjectExpression(...) matching "x" and the implicit object expression of "m" which has type X*.

Definition at line 2991 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( UsingDecl  ,
hasAnyUsingShadowDecl  ,
internal::Matcher< UsingShadowDecl >  ,
InnerMatcher   
)

Matches any using shadow declaration.

Given

   namespace X { void b(); }
   using X::b;

usingDecl(hasAnyUsingShadowDecl(hasName("b")))) matches

 using X::b 

Definition at line 3005 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( UsingShadowDecl  ,
hasTargetDecl  ,
internal::Matcher< NamedDecl >  ,
InnerMatcher   
)

Matches a using shadow declaration where the target declaration is matched by the given matcher.

Given

   namespace X { int a; void b(); }
   using X::a;
   using X::b;

usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) matches

 using X::b 

but not

 using X::a 

Definition at line 3023 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( ConstantArrayType  ,
hasSize  ,
unsigned  ,
 
)

Matches ConstantArrayType nodes that have the specified size.

Given

   int a[42];
   int b[2 * 21];
   int c[41], d[43];

constantArrayType(hasSize(42)) matches "int a[42]" and "int b[2 * 21]"

Definition at line 3202 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P ( VariableArrayType  ,
hasSizeExpr  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches VariableArrayType nodes that have a specific size expression.

Given

   void f(int b) {
     int a[b];
   }

variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( varDecl(hasName("b"))))))) matches "int a[b]"

Definition at line 3258 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( NestedNameSpecifier  ,
specifiesType  ,
internal::Matcher< QualType >  ,
InnerMatcher   
)

Matches nested name specifiers that specify a type matching the given QualType matcher without qualifiers.

Given

   struct A { struct B { struct C {}; }; };
   A::B::C c;

nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A"))))) matches "A::"

Definition at line 3623 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( NestedNameSpecifierLoc  ,
specifiesTypeLoc  ,
internal::Matcher< TypeLoc >  ,
InnerMatcher   
)

Matches nested name specifier locs that specify a type matching the given TypeLoc.

Given

   struct A { struct B { struct C {}; }; };
   A::B::C c;

nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( hasDeclaration(recordDecl(hasName("A"))))))) matches "A::"

Definition at line 3641 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( NestedNameSpecifier  ,
specifiesNamespace  ,
internal::Matcher< NamespaceDecl >  ,
InnerMatcher   
)

Matches nested name specifiers that specify a namespace matching the given namespace matcher.

Given

   namespace ns { struct A {}; }
   ns::A a;

nestedNameSpecifier(specifiesNamespace(hasName("ns"))) matches "ns::"

Definition at line 3692 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( SwitchStmt  ,
forEachSwitchCase  ,
internal::Matcher< SwitchCase >  ,
InnerMatcher   
)

Matches each case or default statement belonging to the given switch statement. This matcher may produce multiple matches.

Given

   switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } }

switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s") matches four times, with "c" binding each of "case 1:", "case 2:", "case 3:" and "case 4:", and "s" respectively binding "switch (1)", "switch (1)", "switch (2)" and "switch (2)".

Definition at line 3730 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CXXConstructorDecl  ,
forEachConstructorInitializer  ,
internal::Matcher< CXXCtorInitializer >  ,
InnerMatcher   
)

Matches each constructor initializer in a constructor definition.

Given

   class A { A() : i(42), j(42) {} int i; int j; };

constructorDecl(forEachConstructorInitializer(forField(decl().bind("x")))) will trigger two matches, binding for 'i' and 'j' respectively.

Definition at line 3759 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( CaseStmt  ,
hasCaseConstant  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

If the given case statement does not use the GNU case range extension, matches the constant given in the statement.

Given

   switch (1) { case 1: case 1+1: case 3 ... 4: ; }

caseStmt(hasCaseConstant(integerLiteral())) matches "case 1:"

Definition at line 3783 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P ( Decl  ,
hasAttr  ,
attr::Kind  ,
AttrKind   
)

Matches declaration that has a given attribute.

Given

   __attribute__((device)) void f() { ... }

decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of f.

Definition at line 3799 of file ASTMatchers.h.

References clang::Attr::getKind(), and Node.

clang::ast_matchers::AST_MATCHER_P2 ( DeclStmt  ,
containsDeclaration  ,
unsigned  ,
,
internal::Matcher< Decl >  ,
InnerMatcher   
)

Matches the n'th declaration of a declaration statement.

Note that this does not work for global declarations because the AST breaks up multiple-declaration DeclStmt's into multiple single-declaration DeclStmt's. Example: Given non-global declarations

   int a, b = 0;
   int c;
   int d = 2, e;

declStmt(containsDeclaration( 0, varDecl(hasInitializer(anything())))) matches only 'int d = 2, e;', and declStmt(containsDeclaration(1, varDecl()))

   matches 'int a, b = 0' as well as 'int d = 2, e;'
   but 'int c;' is not matched.

Definition at line 2271 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P2 ( FunctionDecl  ,
hasParameter  ,
unsigned  ,
,
internal::Matcher< ParmVarDecl >  ,
InnerMatcher   
)

Matches the n'th parameter of a function declaration.

Given

   class X { void f(int x) {} };

methodDecl(hasParameter(0, hasType(varDecl()))) matches f(int x) {} with hasParameter(...) matching int x

Definition at line 2399 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( CXXRecordDecl  ,
isDerivedFrom  ,
StringRef  ,
BaseName  ,
 
)

Overloaded method as shortcut for isDerivedFrom(hasName(...)).

Definition at line 1685 of file ASTMatchers.h.

References Builder, Finder, hasName(), and Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( CXXRecordDecl  ,
isSameOrDerivedFrom  ,
internal::Matcher< NamedDecl >  ,
Base  ,
 
)

Similar to isDerivedFrom(), but also matches classes that directly match Base.

Definition at line 1692 of file ASTMatchers.h.

References anyOf, Builder, Finder, clang::threadSafety::sx::matches(), and Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( CXXRecordDecl  ,
isSameOrDerivedFrom  ,
StringRef  ,
BaseName  ,
 
)

Overloaded method as shortcut for isSameOrDerivedFrom(hasName(...)).

Definition at line 1700 of file ASTMatchers.h.

References Builder, Finder, hasName(), and Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( CallExpr  ,
callee  ,
internal::Matcher< Decl >  ,
InnerMatcher  ,
 
)

Matches if the call expression's callee's declaration matches the given matcher.

Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x")))))

   class Y { public: void x(); };
   void z() { Y y; y.x(); }

Definition at line 1939 of file ASTMatchers.h.

References Builder, callExpr, Finder, hasDeclaration(), InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( QualType  ,
pointsTo  ,
internal::Matcher< Decl >  ,
InnerMatcher  ,
 
)

Overloaded to match the pointee type's declaration.

Definition at line 2029 of file ASTMatchers.h.

References Builder, Finder, hasDeclaration(), InnerMatcher, Node, and qualType.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( NestedNameSpecifier  ,
hasPrefix  ,
internal::Matcher< NestedNameSpecifier >  ,
InnerMatcher  ,
 
)

Matches on the prefix of a NestedNameSpecifier.

Given

   struct A { struct B { struct C {}; }; };
   A::B::C c;

nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and matches "A::"

Definition at line 3655 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( NestedNameSpecifierLoc  ,
hasPrefix  ,
internal::Matcher< NestedNameSpecifierLoc >  ,
InnerMatcher  ,
 
)

Matches on the prefix of a NestedNameSpecifierLoc.

Given

   struct A { struct B { struct C {}; }; };
   A::B::C c;

nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A"))))) matches "A::"

Definition at line 3673 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( Decl  ,
equalsNode  ,
const Decl *  ,
Other  ,
 
)

Overloads for the equalsNode matcher. FIXME: Implement for other node types.

Matches if a node equals another node.

Decl has pointer identity in the AST.

Definition at line 3706 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_MATCHER_P_OVERLOAD ( Stmt  ,
equalsNode  ,
const Stmt *  ,
Other  ,
 
)

Matches if a node equals another node.

Stmt has pointer identity in the AST.

Definition at line 3713 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER ( isDefinition  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_3(TagDecl, VarDecl, FunctionDecl)   
)

Matches if a declaration has a body attached.

Example matches A, va, fa

   class A {};
   class B;  // Doesn't match, as it has no body.
   int va;
   extern int vb;  // Doesn't match, as it doesn't define the variable.
   void fa() {}
   void fb();  // Doesn't match, as it has no body.

Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>

Definition at line 2803 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER ( isTemplateInstantiation  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_3(FunctionDecl, VarDecl, CXXRecordDecl)   
)

Matches template instantiations of function, class, or static member variable template instantiations.

Given

   template <typename T> class X {}; class A {}; X<A> x;

or

   template <typename T> class X {}; class A {}; template class X<A>;

recordDecl(hasName("::X"), isTemplateInstantiation()) matches the template instantiation of X.

But given

   template <typename T>  class X {}; class A {};
   template <> class X<A> {}; X<A> x;

recordDecl(hasName("::X"), isTemplateInstantiation()) does not match, as X is an explicit template specialization.

Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>

Definition at line 3051 of file ASTMatchers.h.

References Node, clang::TSK_ExplicitInstantiationDefinition, and clang::TSK_ImplicitInstantiation.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER ( isExplicitTemplateSpecialization  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_3(FunctionDecl, VarDecl, CXXRecordDecl)   
)

Matches explicit template specializations of function, class, or static member variable template instantiations.

Given

   template<typename T> void A(T t) { }
   template<> void A(int N) { }

functionDecl(isExplicitTemplateSpecialization()) matches the specialization A<int>().

Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>

Definition at line 3111 of file ASTMatchers.h.

References Node, and clang::TSK_ExplicitSpecialization.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( hasAnyTemplateArgument  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl,TemplateSpecializationType)  ,
internal::Matcher< TemplateArgument >  ,
InnerMatcher   
)

Matches classTemplateSpecializations that have at least one TemplateArgument matching the given InnerMatcher.

Given

   template<typename T> class A {};
   template<> class A<double> {};
   A<int> a;

classTemplateSpecializationDecl(hasAnyTemplateArgument( refersToType(asString("int")))) matches the specialization A<int>

Definition at line 351 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( templateArgumentCountIs  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl,TemplateSpecializationType)  ,
unsigned  ,
 
)

Matches if the number of template arguments equals N.

Given

   template<typename T> struct C {};
   C<int> c;

classTemplateSpecializationDecl(templateArgumentCountIs(1)) matches C<int>.

Definition at line 472 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( argumentCountIs  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(CallExpr, CXXConstructExpr)  ,
unsigned  ,
 
)

Checks that a call expression or a constructor call expression has a specific number of arguments (including absent default arguments).

Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))

   void f(int x, int y);
   f(0, 0);

Definition at line 2214 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( hasAnyArgument  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(CallExpr, CXXConstructExpr)  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches any argument of a call expression or a constructor call expression.

Given

   void x(int, int, int) { int y; x(1, y, 42); }

callExpr(hasAnyArgument(declRefExpr())) matches x(1, y, 42) with hasAnyArgument(...) matching y

FIXME: Currently this will ignore parentheses and implicit casts on the argument before applying the inner matcher. We'll want to remove this to allow for greater control by the user once ignoreImplicit() has been implemented.

Definition at line 2371 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( hasCondition  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_5(IfStmt, ForStmt, WhileStmt, DoStmt, ConditionalOperator)  ,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the condition expression of an if statement, for loop, or conditional operator.

Example matches true (matcher = hasCondition(boolLiteral(equals(true))))

   if (true) {}

Definition at line 2485 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( equalsBoundNode  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_4(Stmt, Decl, Type, QualType)  ,
std::string  ,
ID   
)

Matches if a node equals a previously bound node.

Matches a node if it equals the node previously bound to ID.

Given

   class X { int a; int b; };

recordDecl( has(fieldDecl(hasName("a"), hasType(type().bind("t")))), has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) matches the class X, as a and b have the same type.

Note that when multiple matches are involved via forEach* matchers, equalsBoundNodes acts as a filter. For example: compoundStmt( forEachDescendant(varDecl().bind("d")), forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) will trigger a match for each combination of variable declaration and reference to that variable declaration within a compound statement.

Definition at line 2539 of file ASTMatchers.h.

References Builder, clang::serialized_diags::create(), and Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( hasBody  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_4(DoStmt, ForStmt,WhileStmt,CXXForRangeStmt)  ,
internal::Matcher< Stmt >  ,
InnerMatcher   
)

Matches a 'for', 'while', or 'do while' statement that has a given body.

Given

   for (;;) {}

hasBody(compoundStmt()) matches 'for (;;) {}' with compoundStmt() matching '{}'

Definition at line 2614 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P ( hasOperatorName  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(BinaryOperator, UnaryOperator)  ,
std::string  ,
Name   
)

Matches the operator Name of operator expressions (binary or unary).

Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))

   !(a || b)

Definition at line 2679 of file ASTMatchers.h.

References Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P2 ( hasTemplateArgument  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl,TemplateSpecializationType)  ,
unsigned  ,
,
internal::Matcher< TemplateArgument >  ,
InnerMatcher   
)

Matches classTemplateSpecializations where the n'th TemplateArgument matches the given InnerMatcher.

Given

   template<typename T, typename U> class A {};
   A<bool, int> b;
   A<int, bool> c;

classTemplateSpecializationDecl(hasTemplateArgument( 1, refersToType(asString("int")))) matches the specialization A<bool, int>

Definition at line 451 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P2 ( hasArgument  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(CallExpr, CXXConstructExpr)  ,
unsigned  ,
,
internal::Matcher< Expr >  ,
InnerMatcher   
)

Matches the n'th argument of a call expression or a constructor call expression.

Example matches y in x(y) (matcher = callExpr(hasArgument(0, declRefExpr())))

   void x(int) { int y; x(y); }

Definition at line 2228 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

Matches if the expression's or declaration's type matches a type matcher.

Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))

  class X {};
  void y(X &x) { x; X z; }

Definition at line 1953 of file ASTMatchers.h.

References Builder, Finder, InnerMatcher, and Node.

Overloaded to match the declaration of the expression's or value declaration's type.

In case of a value declaration (for example a variable declaration), this resolves one layer of indirection. For example, in the value declaration "X x;", recordDecl(hasName("X")) matches the declaration of X, while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration of x."

Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))

  class X {};
  void y(X &x) { x; X z; }

Usable as: Matcher<Expr>, Matcher<ValueDecl>

Definition at line 1976 of file ASTMatchers.h.

References Builder, Finder, hasDeclaration(), InnerMatcher, Node, and qualType.

clang::ast_matchers::AST_TYPE_MATCHER ( BuiltinType  ,
builtinType   
)

Matches builtin Types.

Given

   struct A {};
   A a;
   int b;
   float c;
   bool d;

builtinType() matches "int b", "float c" and "bool d"

clang::ast_matchers::AST_TYPE_MATCHER ( ArrayType  ,
arrayType   
)

Matches all kinds of arrays.

Given

   int a[] = { 2, 3 };
   int b[4];
   void f() { int c[a[0]]; }

arrayType() matches "int a[]", "int b[4]" and "int c[a[0]]";

clang::ast_matchers::AST_TYPE_MATCHER ( ComplexType  ,
complexType   
)

Matches C99 complex types.

Given

   _Complex float f;

complexType() matches "_Complex float f"

clang::ast_matchers::AST_TYPE_MATCHER ( ConstantArrayType  ,
constantArrayType   
)

Matches C arrays with a specified constant size.

Given

   void() {
     int a[2];
     int b[] = { 2, 3 };
     int c[b[0]];
   }

constantArrayType() matches "int a[2]"

clang::ast_matchers::AST_TYPE_MATCHER ( DependentSizedArrayType  ,
dependentSizedArrayType   
)

Matches C++ arrays whose size is a value-dependent expression.

Given

   template<typename T, int Size>
   class array {
     T data[Size];
   };

dependentSizedArrayType matches "T data[Size]"

clang::ast_matchers::AST_TYPE_MATCHER ( IncompleteArrayType  ,
incompleteArrayType   
)

Matches C arrays with unspecified size.

Given

   int a[] = { 2, 3 };
   int b[42];
   void f(int c[]) { int d[a[0]]; };

incompleteArrayType() matches "int a[]" and "int c[]"

clang::ast_matchers::AST_TYPE_MATCHER ( VariableArrayType  ,
variableArrayType   
)

Matches C arrays with a specified size that is not an integer-constant-expression.

Given

   void f() {
     int a[] = { 2, 3 }
     int b[42];
     int c[a[0]];
   }

variableArrayType() matches "int c[a[0]]"

clang::ast_matchers::AST_TYPE_MATCHER ( AtomicType  ,
atomicType   
)

Matches atomic types.

Given

   _Atomic(int) i;

atomicType() matches "_Atomic(int) i"

clang::ast_matchers::AST_TYPE_MATCHER ( AutoType  ,
autoType   
)

Matches types nodes representing C++11 auto types.

Given:

   auto n = 4;
   int v[] = { 2, 3 }
   for (auto i : v) { }

autoType() matches "auto n" and "auto i"

clang::ast_matchers::AST_TYPE_MATCHER ( FunctionType  ,
functionType   
)

Matches FunctionType nodes.

Given

   int (*f)(int);
   void g();

functionType() matches "int (*f)(int)" and the type of "g".

clang::ast_matchers::AST_TYPE_MATCHER ( ParenType  ,
parenType   
)

Matches ParenType nodes.

Given

   int (*ptr_to_array)[4];
   int *array_of_ptrs[4];

varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not array_of_ptrs.

clang::ast_matchers::AST_TYPE_MATCHER ( BlockPointerType  ,
blockPointerType   
)

Matches block pointer types, i.e. types syntactically represented as "void (^)(int)".

The pointee is always required to be a FunctionType.

clang::ast_matchers::AST_TYPE_MATCHER ( MemberPointerType  ,
memberPointerType   
)

Matches member pointer types. Given.

   struct A { int i; }
   A::* ptr = A::i;

memberPointerType() matches "A::* ptr"

clang::ast_matchers::AST_TYPE_MATCHER ( PointerType  ,
pointerType   
)

Matches pointer types.

Given

   int *a;
   int &b = *a;
   int c = 5;

pointerType() matches "int *a"

clang::ast_matchers::AST_TYPE_MATCHER ( ReferenceType  ,
referenceType   
)

Matches both lvalue and rvalue reference types.

Given

   int *a;
   int &b = *a;
   int &&c = 1;
   auto &d = b;
   auto &&e = c;
   auto &&f = 2;
   int g = 5;

referenceType() matches the types of b, c, d, e, and f.

clang::ast_matchers::AST_TYPE_MATCHER ( LValueReferenceType  ,
lValueReferenceType   
)

Matches lvalue reference types.

Given:

   int *a;
   int &b = *a;
   int &&c = 1;
   auto &d = b;
   auto &&e = c;
   auto &&f = 2;
   int g = 5;

lValueReferenceType() matches the types of b, d, and e. e is matched since the type is deduced as int& by reference collapsing rules.

clang::ast_matchers::AST_TYPE_MATCHER ( RValueReferenceType  ,
rValueReferenceType   
)

Matches rvalue reference types.

Given:

   int *a;
   int &b = *a;
   int &&c = 1;
   auto &d = b;
   auto &&e = c;
   auto &&f = 2;
   int g = 5;

rValueReferenceType() matches the types of c and f. e is not matched as it is deduced to int& by reference collapsing rules.

clang::ast_matchers::AST_TYPE_MATCHER ( TypedefType  ,
typedefType   
)

Matches typedef types.

Given

   typedef int X;

typedefType() matches "typedef int X"

clang::ast_matchers::AST_TYPE_MATCHER ( UnaryTransformType  ,
unaryTransformType   
)

Matches template specialization types.

Given

   template <typename T>
   class C { };

   template class C<int>;  // A
   C<char> var;            // B
 \code

 \c templateSpecializationType() matches the type of the explicit
 instantiation in \c A and the type of the variable declaration in \c B.
AST_TYPE_MATCHER(TemplateSpecializationType, templateSpecializationType);

 \brief Matches types nodes representing unary type transformations.

 Given:
 \code
   typedef __underlying_type(T) type;

unaryTransformType() matches "__underlying_type(T)"

clang::ast_matchers::AST_TYPE_TRAVERSE_MATCHER ( hasDeducedType  ,
getDeducedType  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_1(AutoType)   
)

Matches AutoType nodes where the deduced type is a specific type.

Note: There is no TypeLoc for the deduced type and thus no getDeducedLoc() matcher.

Given

   auto a = 1;
   auto b = 2.0;

autoType(hasDeducedType(isInteger())) matches "auto a"

Usable as: Matcher<AutoType>

clang::ast_matchers::AST_TYPE_TRAVERSE_MATCHER ( innerType  ,
getInnerType  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_1(ParenType)   
)

Matches ParenType nodes where the inner type is a specific type.

Given

   int (*ptr_to_array)[4];
   int (*ptr_to_func)(int);

varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches ptr_to_func but not ptr_to_array.

Usable as: Matcher<ParenType>

clang::ast_matchers::AST_TYPELOC_TRAVERSE_MATCHER ( hasElementType  ,
getElement  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_2(ArrayType, ComplexType)   
)

Matches arrays and C99 complex types that have a specific element type.

Given

   struct A {};
   A a[7];
   int b[7];

arrayType(hasElementType(builtinType())) matches "int b[7]"

Usable as: Matcher<ArrayType>, Matcher<ComplexType>

Matches atomic types with a specific value type.

Given

   _Atomic(int) i;
   _Atomic(float) f;

atomicType(hasValueType(isInteger())) matches "_Atomic(int) i"

Usable as: Matcher<AtomicType>

clang::ast_matchers::AST_TYPELOC_TRAVERSE_MATCHER ( pointee  ,
getPointee  ,
AST_POLYMORPHIC_SUPPORTED_TYPES_4(BlockPointerType, MemberPointerType, PointerType, ReferenceType)   
)

Narrows PointerType (and similar) matchers to those where the pointee matches a given matcher.

Given

   int *a;
   int const *b;
   float const *f;

pointerType(pointee(isConstQualified(), isInteger())) matches "int const *b"

Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, Matcher<PointerType>, Matcher<ReferenceType>

template<typename ValueT >
internal::PolymorphicMatcherWithParam1<internal::ValueEqualsMatcher, ValueT> clang::ast_matchers::equals ( const ValueT &  Value)

Matches literals that are equal to the given value.

Example matches true (matcher = boolLiteral(equals(true)))

   true

Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>, Matcher<FloatingLiteral>, Matcher<IntegerLiteral>

Definition at line 2666 of file ASTMatchers.h.

template<typename T >
internal::Matcher<T> clang::ast_matchers::findAll ( const internal::Matcher< T > &  Matcher)

Matches if the node or any descendant matches.

Generates results for each match.

For example, in:

   class A { class B {}; class C {}; };

The matcher:

   recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("m")))

will generate results for A, B and C.

Usable as: Any Matcher

Definition at line 1818 of file ASTMatchers.h.

References eachOf, and forEachDescendant.

internal::PolymorphicMatcherWithParam1< internal::HasDeclarationMatcher, internal::Matcher<Decl>, void(internal::HasDeclarationSupportedTypes)> clang::ast_matchers::hasDeclaration ( const internal::Matcher< Decl > &  InnerMatcher) [inline]

Matches a node if the declaration associated with that node matches the given matcher.

The associated declaration is:

  • for type nodes, the declaration of the underlying type
  • for CallExpr, the declaration of the callee
  • for MemberExpr, the declaration of the referenced member
  • for CXXConstructExpr, the declaration of the constructor

Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions.

Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, Matcher<TypedefType>, Matcher<UnresolvedUsingType>

Definition at line 1885 of file ASTMatchers.h.

References InnerMatcher.

Referenced by AST_MATCHER_P_OVERLOAD(), and AST_POLYMORPHIC_MATCHER_P_OVERLOAD().

Matches if either the left hand side or the right hand side of a binary operator matches.

Definition at line 2713 of file ASTMatchers.h.

References anyOf.

internal::Matcher<NamedDecl> clang::ast_matchers::hasName ( const std::string &  Name) [inline]

Matches NamedDecl nodes that have the specified name.

Supports specifying enclosing namespaces or classes by prefixing the name with '<enclosing>::'. Does not match typedefs of an underlying type with the given name.

Example matches X (Name == "X")

   class X;

Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")

   namespace a { namespace b { class X; } }

Definition at line 1603 of file ASTMatchers.h.

Referenced by AST_MATCHER_P_OVERLOAD().

internal::PolymorphicMatcherWithParam1< internal::HasOverloadedOperatorNameMatcher, StringRef, AST_POLYMORPHIC_SUPPORTED_TYPES_2(CXXOperatorCallExpr, FunctionDecl)> clang::ast_matchers::hasOverloadedOperatorName ( StringRef  Name) [inline]

Matches overloaded operator names.

Matches overloaded operator names specified in strings without the "operator" prefix: e.g. "<<".

Given:

   class A { int operator*(); };
   const A &operator<<(const A &a, const A &b);
   A a;
   a << a;   // <-- This matches

operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified line and recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches the declaration of A.

Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>

Definition at line 1651 of file ASTMatchers.h.

References AST_POLYMORPHIC_SUPPORTED_TYPES_2.

template<typename T >
internal::Matcher<T> clang::ast_matchers::id ( const std::string &  ID,
const internal::BindableMatcher< T > &  InnerMatcher 
)

If the provided matcher matches a node, binds the node to ID.

FIXME: Do we want to support this now that we have bind()?

Definition at line 113 of file ASTMatchers.h.

Referenced by buildByrefHelpers(), clang::Sema::CodeCompleteObjCSuperMessage(), clang::ASTContext::getAttributedType(), clang::MicrosoftVTableContext::getVFTableLayout(), and HandleExtVectorTypeAttr().

template<typename MatcherT , typename NodeT >
SmallVector< BoundNodes, 1 > clang::ast_matchers::match ( MatcherT  Matcher,
const NodeT &  Node,
ASTContext &  Context 
)

Returns the results of matching Matcher on Node.

Collects the BoundNodes of all callback invocations when matching Matcher on Node and returns the collected results.

Multiple results occur when using matchers like forEachDescendant, which generate a result for each sub-match.

See also:
selectFirst

Definition at line 286 of file ASTMatchFinder.h.

References clang::ast_type_traits::DynTypedNode::create().

Referenced by clang::Sema::ActOnAtEnd(), clang::Sema::ActOnCXXDelete(), AttributesMatch(), ClassImplementsAllMethodsAndProperties(), MatchTwoAttributeLists(), clang::ASTContext::ObjCQualifiedClassTypesAreCompatible(), clang::ASTContext::ObjCQualifiedIdTypesAreCompatible(), and clang::Sema::WarnExactTypedMethods().

template<typename MatcherT >
SmallVector< BoundNodes, 1 > clang::ast_matchers::match ( MatcherT  Matcher,
const ast_type_traits::DynTypedNode &  Node,
ASTContext &  Context 
)
template<typename NodeT >
const NodeT* clang::ast_matchers::selectFirst ( StringRef  BoundTo,
const SmallVectorImpl< BoundNodes > &  Results 
)

Returns the first result of type NodeT bound to BoundTo.

Returns NULL if there is no match, or if the matching node cannot be casted to NodeT.

This is useful in combanation with match():

   const Decl *D = selectFirst<Decl>("id", match(Matcher.bind("id"),
                                                 Node, Context));

Definition at line 255 of file ASTMatchFinder.h.

References Node.

internal::Matcher<Stmt> clang::ast_matchers::sizeOfExpr ( const internal::Matcher< UnaryExprOrTypeTraitExpr > &  InnerMatcher) [inline]

Same as unaryExprOrTypeTraitExpr, but only matching sizeof.

Definition at line 1582 of file ASTMatchers.h.

References allOf, stmt, clang::UETT_SizeOf, and unaryExprOrTypeTraitExpr.


Variable Documentation

const internal::VariadicDynCastAllOfMatcher< Decl, AccessSpecDecl> clang::ast_matchers::accessSpecDecl

Matches C++ access specifier declarations.

Given

   class C {
   public:
     int a;
   };

accessSpecDecl() matches 'public:'

Definition at line 261 of file ASTMatchers.h.

const internal::VariadicOperatorMatcherFunc<2, UINT_MAX> clang::ast_matchers::allOf
Initial value:

Matches if all given matchers match.

Usable as: Any Matcher

Definition at line 1528 of file ASTMatchers.h.

Referenced by alignOfExpr(), and sizeOfExpr().

const internal::VariadicOperatorMatcherFunc<2, UINT_MAX> clang::ast_matchers::anyOf
Initial value:

Matches if any of the given matchers matches.

Usable as: Any Matcher

Definition at line 1521 of file ASTMatchers.h.

Referenced by AST_MATCHER(), AST_MATCHER_P_OVERLOAD(), and hasEitherOperand().

const internal::VariadicDynCastAllOfMatcher< Stmt, ArraySubscriptExpr> clang::ast_matchers::arraySubscriptExpr

Matches array subscript expressions.

Given

   int i = a[1];

arraySubscriptExpr() matches "a[1]"

Definition at line 944 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> clang::ast_matchers::asmStmt

Matches asm statements.

  int i = 100;
   __asm("mov al, 2");

asmStmt() matches '__asm("mov al, 2")'

Definition at line 1241 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, BinaryOperator> clang::ast_matchers::binaryOperator

Matches binary operator expressions.

Example matches a || b

   !(a || b)

Definition at line 1325 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXBindTemporaryExpr> clang::ast_matchers::bindTemporaryExpr

Matches nodes where temporaries are created.

Example matches FunctionTakesString(GetStringByValue()) (matcher = bindTemporaryExpr())

   FunctionTakesString(GetStringByValue());
   FunctionTakesStringByPointer(GetStringPointer());

Definition at line 890 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXBoolLiteralExpr> clang::ast_matchers::boolLiteral

Matches bool literals.

Example matches true

   true

Definition at line 1251 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> clang::ast_matchers::breakStmt

Matches break statements.

Given

   while (true) { break; }

breakStmt() matches 'break'

Definition at line 1105 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> clang::ast_matchers::callExpr

Matches call expressions.

Example matches x.y() and y()

   X x;
   x.y();
   y();

Definition at line 748 of file ASTMatchers.h.

Referenced by clang::Sema::ActOnPropertyImplDecl(), and AST_MATCHER_P_OVERLOAD().

const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> clang::ast_matchers::caseStmt

Matches case statements inside switch statements.

Given

   switch(a) { case 42: break; default: break; }

caseStmt() matches 'case 42: break;'.

Definition at line 1177 of file ASTMatchers.h.

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

const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> clang::ast_matchers::castExpr

Matches any cast nodes of Clang's AST.

Example: castExpr() matches each of the following:

   (int) 3;
   const_cast<Expr *>(SubExpr);
   char c = 0;

but does not match

   int i = (0);
   int k = 0;

Definition at line 1462 of file ASTMatchers.h.

Referenced by addFixitForObjCARCConversion(), clang::Sema::CheckObjCARCConversion(), clang::Sema::CheckObjCBridgeRelatedCast(), clang::Sema::CheckTollFreeBridgeCast(), and clang::Sema::diagnoseARCUnbridgedCast().

const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> clang::ast_matchers::catchStmt

Matches catch statements.

   try {} catch(int i) {}

catchStmt() matches 'catch(int i)'

Definition at line 1204 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CharacterLiteral> clang::ast_matchers::characterLiteral

Matches character literals (also matches wchar_t).

Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), though.

Example matches 'a', L'a'

   char ch = 'a'; wchar_t chw = L'a';

Definition at line 1274 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplateDecl> clang::ast_matchers::classTemplateDecl

Matches C++ class template declarations.

Example matches Z

   template<class T> class Z {};

Definition at line 210 of file ASTMatchers.h.

Matches C++ class template specializations.

Given

   template<typename T> class A {};
   template<> class A<double> {};
   A<int> a;

classTemplateSpecializationDecl() matches the specializations A<int> and A<double>

Definition at line 224 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CompoundLiteralExpr> clang::ast_matchers::compoundLiteralExpr

Matches compound (i.e. non-scalar) literals.

Example match: {1}, (1, 2)

   int array[4] = {1}; vector int myvec = (vector int)(1, 2);

Definition at line 1310 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> clang::ast_matchers::compoundStmt

Matches compound statements.

Example matches '{}' and '{{}}'in 'for (;;) {{}}'

   for (;;) {{}}

Definition at line 1195 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, ConditionalOperator> clang::ast_matchers::conditionalOperator

Matches conditional operator expressions.

Example matches a ? b : c

   (a ? b : c) + 42

Definition at line 1345 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstCastExpr> clang::ast_matchers::constCastExpr

Matches a const_cast expression.

Example: Matches const_cast<int*>(&r) in

   int n = 42;
   const int &r(n);
   int* p = const_cast<int*>(&r);

Definition at line 1404 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstructExpr> clang::ast_matchers::constructExpr

Matches constructor call expressions (including implicit ones).

Example matches string(ptr, n) and ptr within arguments of f (matcher = constructExpr())

   void f(const string &a, const string &b);
   char *ptr;
   int n;
   f(string(ptr, n), ptr);

Definition at line 854 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Decl, CXXConstructorDecl> clang::ast_matchers::constructorDecl

Matches C++ constructor declarations.

Example matches Foo::Foo() and Foo::Foo(int)

   class Foo {
    public:
     Foo();
     Foo(int);
     int DoSomething();
   };

Definition at line 611 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> clang::ast_matchers::continueStmt

Matches continue statements.

Given

   while (true) { continue; }

continueStmt() matches 'continue'

Definition at line 1115 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CStyleCastExpr> clang::ast_matchers::cStyleCastExpr

Matches a C-style cast expression.

Example: Matches (int*) 2.2f in

   int i = (int) 2.2f;

Definition at line 1414 of file ASTMatchers.h.

const internal::VariadicAllOfMatcher<CXXCtorInitializer> clang::ast_matchers::ctorInitializer

Matches constructor initializers.

Examples matches i(42).

   class C {
     C() : i(42) {}
     int i;
   };

Definition at line 272 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr> clang::ast_matchers::CUDAKernelCallExpr

Matches CUDA kernel call expression.

Example matches,

   kernel<<<i,j>>>();

Definition at line 3814 of file ASTMatchers.h.

Referenced by clang::Sema::ActOnCallExpr(), and clang::Sema::BuildResolvedCallExpr().

const internal::VariadicAllOfMatcher<Decl> clang::ast_matchers::decl
const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl> clang::ast_matchers::declaratorDecl

Matches declarator declarations (field, variable, function and non-type template parameter declarations).

Given

   class X { int y; };

declaratorDecl() matches int y.

Definition at line 236 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> clang::ast_matchers::declRefExpr

Matches expressions that refer to declarations.

Example matches x in if (x)

   bool x;
   if (x) {}

Definition at line 992 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, DeclStmt> clang::ast_matchers::declStmt

Matches declaration statements.

Given

   int a;

declStmt() matches 'int a'.

Definition at line 725 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDefaultArgExpr> clang::ast_matchers::defaultArgExpr

Matches the value of a default argument at the call site.

Example matches the CXXDefaultArgExpr placeholder inserted for the default value of the second parameter in the call expression f(42) (matcher = defaultArgExpr())

   void f(int x, int y = 0);
   f(42);

Definition at line 957 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> clang::ast_matchers::defaultStmt

Matches default statements inside switch statements.

Given

   switch(a) { case 42: break; default: break; }

defaultStmt() matches 'default: break;'.

Definition at line 1187 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> clang::ast_matchers::deleteExpr

Matches delete expressions.

Given

   delete X;

deleteExpr() matches 'delete X'.

Definition at line 932 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Decl, CXXDestructorDecl> clang::ast_matchers::destructorDecl

Matches explicit C++ destructor declarations.

Example matches Foo::~Foo()

   class Foo {
    public:
     virtual ~Foo();
   };

Definition at line 624 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> clang::ast_matchers::doStmt

Matches do statements.

Given

   do {} while (true);

doStmt() matches 'do {} while(true)'

Definition at line 1095 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDynamicCastExpr> clang::ast_matchers::dynamicCastExpr

Matches a dynamic_cast expression.

Example: dynamicCastExpr() matches dynamic_cast<D*>(&b); in

   struct B { virtual ~B() {} }; struct D : B {};
   B b;
   D* p = dynamic_cast<D*>(&b);

Definition at line 1392 of file ASTMatchers.h.

const internal::VariadicOperatorMatcherFunc<2, UINT_MAX> clang::ast_matchers::eachOf
Initial value:

Matches if any of the given matchers matches.

Unlike anyOf, eachOf will generate a match result for each matching submatcher.

For example, in:

   class A { int a; int b; };

The matcher:

   recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
                     has(fieldDecl(hasName("b")).bind("v"))))

will generate two results binding "v", the first of which binds the field declaration of a, the second the field declaration of b.

Usable as: Any Matcher

Definition at line 1514 of file ASTMatchers.h.

Referenced by findAll().

const internal::VariadicDynCastAllOfMatcher< Decl, EnumConstantDecl> clang::ast_matchers::enumConstantDecl

Matches enum constants.

Example matches A, B, C

   enum X {
     A, B, C
   };

Definition at line 646 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> clang::ast_matchers::enumDecl

Matches enum declarations.

Example matches X

   enum X {
     A, B, C
   };

Definition at line 634 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, ExplicitCastExpr> clang::ast_matchers::explicitCastExpr

Matches explicit cast expressions.

Matches any cast expression written in user code, whether it be a C-style cast, a functional-style cast, or a keyword cast.

Does not match implicit conversions.

Note: the name "explicitCast" is chosen to match Clang's terminology, as Clang uses the term "cast" to apply to implicit conversions as well as to actual cast expressions.

See also:
hasDestinationType.

Example: matches all five of the casts in

   int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42)))))

but does not match the implicit conversion in

   long ell = 42;

Definition at line 1439 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> clang::ast_matchers::expr
const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups> clang::ast_matchers::exprWithCleanups

Matches expressions that introduce cleanups to be run at the end of the sub-expression's evaluation.

Example matches std::string()

   const std::string str = std::string();

Definition at line 777 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> clang::ast_matchers::fieldDecl

Matches field declarations.

Given

   class X { int m; };

fieldDecl() matches 'm'.

Definition at line 675 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, FloatingLiteral> clang::ast_matchers::floatLiteral

Matches float literals of all sizes / encodings, e.g. 1.0, 1.0f, 1.0L and 1e10.

Does not match implicit conversions such as

   float a = 10;

Definition at line 1293 of file ASTMatchers.h.

const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> LLVM_ATTRIBUTE_UNUSED clang::ast_matchers::forEach = {}

Matches AST nodes that have child AST nodes that match the provided matcher.

Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X")))

   class X {};  // Matches X, because X::X is a class of name X inside X.
   class Y { class X {}; };
   class Z { class Y { class X {}; }; };  // Does not match Z.

ChildT must be an AST base type.

As opposed to 'has', 'forEach' will cause a match for each result that matches instead of only on the first one.

Usable as: Any Matcher

Definition at line 1773 of file ASTMatchers.h.

const internal::ArgumentAdaptingMatcherFunc<internal::ForEachDescendantMatcher> LLVM_ATTRIBUTE_UNUSED clang::ast_matchers::forEachDescendant = {}

Matches AST nodes that have descendant AST nodes that match the provided matcher.

Example matches X, A, B, C (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X")))))

   class X {};  // Matches X, because X::X is a class of name X inside X.
   class A { class X {}; };
   class B { class C { class X {}; }; };

DescendantT must be an AST base type.

As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for each result that matches instead of only on the first one.

Note: Recursively combined ForEachDescendant can cause many matches: recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl())))) will match 10 times (plus injected class name matches) on:

   class A { class B { class C { class D { class E {}; }; }; }; };

Usable as: Any Matcher

Definition at line 1800 of file ASTMatchers.h.

Referenced by findAll().

const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt> clang::ast_matchers::forRangeStmt

Matches range-based for statements.

forRangeStmt() matches 'for (auto a : i)'

   int i[] =  {1, 2, 3}; for (auto a : i);
   for(int j = 0; j < 5; ++j);

Definition at line 1047 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> clang::ast_matchers::forStmt

Matches for statements.

Example matches 'for (;;) {}'

   for (;;) {}
   int i[] =  {1, 2, 3}; for (auto a : i);

Definition at line 1009 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> clang::ast_matchers::friendDecl

Matches friend declarations.

Given

   class X { friend void foo(); };

friendDecl() matches 'friend void foo()'.

Definition at line 703 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXFunctionalCastExpr> clang::ast_matchers::functionalCastExpr

Matches functional cast expressions.

Example: Matches Foo(bar);

   Foo f = bar;
   Foo g = (Foo) bar;
   Foo h = Foo(bar);

Definition at line 1474 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> clang::ast_matchers::functionDecl

Matches function declarations.

Example matches f

   void f();

Definition at line 683 of file ASTMatchers.h.

Referenced by AST_MATCHER().

const internal::VariadicDynCastAllOfMatcher< Decl, FunctionTemplateDecl> clang::ast_matchers::functionTemplateDecl

Matches C++ function template declarations.

Example matches f

   template<class T> void f(T t) {}

Definition at line 693 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> clang::ast_matchers::gotoStmt

Matches goto statements.

Given

   goto FOO;
   FOO: bar();

gotoStmt() matches 'goto FOO'

Definition at line 1136 of file ASTMatchers.h.

const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> LLVM_ATTRIBUTE_UNUSED clang::ast_matchers::has = {}

Matches the first method of a class or struct that satisfies InnerMatcher.

Given:

   class A { void func(); };
   class B { void member(); };
 \code

 \c recordDecl(hasMethod(hasName("func"))) matches the declaration of \c A
 but not \c B.
AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>,
              InnerMatcher) {
  return matchesFirstInPointerRange(InnerMatcher, Node.method_begin(),
                                    Node.method_end(), Finder, Builder);
}

 \brief Matches AST nodes that have child AST nodes that match the
 provided matcher.

 Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X")))
 \code
   class X {};  // Matches X, because X::X is a class of name X inside X.
   class Y { class X {}; };
   class Z { class Y { class X {}; }; };  // Does not match Z.

ChildT must be an AST base type.

Usable as: Any Matcher

Definition at line 1737 of file ASTMatchers.h.

Referenced by getLiteralInfo().

const internal::ArgumentAdaptingMatcherFunc< internal::HasAncestorMatcher, internal::TypeList<Decl, Stmt>, internal::TypeList<Decl, Stmt> > LLVM_ATTRIBUTE_UNUSED clang::ast_matchers::hasAncestor = {}

Matches AST nodes that have an ancestor that matches the provided matcher.

Given

 void f() { if (true) { int x = 42; } }
 void g() { for (;;) { int x = 43; } }

expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43.

Usable as: Any Matcher

Definition at line 1849 of file ASTMatchers.h.

Referenced by AST_MATCHER().

const internal::ArgumentAdaptingMatcherFunc<internal::HasDescendantMatcher> LLVM_ATTRIBUTE_UNUSED clang::ast_matchers::hasDescendant = {}

Matches AST nodes that have descendant AST nodes that match the provided matcher.

Example matches X, Y, Z (matcher = recordDecl(hasDescendant(recordDecl(hasName("X")))))

   class X {};  // Matches X, because X::X is a class of name X inside X.
   class Y { class X {}; };
   class Z { class Y { class X {}; }; };

DescendantT must be an AST base type.

Usable as: Any Matcher

Definition at line 1754 of file ASTMatchers.h.

const internal::ArgumentAdaptingMatcherFunc< internal::HasParentMatcher, internal::TypeList<Decl, Stmt>, internal::TypeList<Decl, Stmt> > LLVM_ATTRIBUTE_UNUSED clang::ast_matchers::hasParent = {}

Matches AST nodes that have a parent that matches the provided matcher.

Given

 void f() { for (;;) { int x = 42; if (true) { int x = 43; } } }

compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".

Usable as: Any Matcher

Definition at line 1834 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> clang::ast_matchers::ifStmt

Matches if statements.

Example matches 'if (x) {}'

   if (x) {}

Definition at line 1000 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, ImplicitCastExpr> clang::ast_matchers::implicitCastExpr

Matches the implicit cast nodes of Clang's AST.

This matches many different places, including function call return value eliding, as well as any type conversions.

Definition at line 1447 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> clang::ast_matchers::initListExpr

Matches init list expressions.

Given

   int a[] = { 1, 2 };
   struct B { int x, y; };
   B b = { 5, 6 };

initListExpr() matches "{ 1, 2 }" and "{ 5, 6 }"

Definition at line 789 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, IntegerLiteral> clang::ast_matchers::integerLiteral

Matches integer literals of all sizes / encodings, e.g. 1, 1L, 0x1 and 1U.

Does not match character-encoded integers such as L'a'.

Definition at line 1282 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> clang::ast_matchers::labelStmt

Matches label statements.

Given

   goto FOO;
   FOO: bar();

labelStmt() matches 'FOO:'

Definition at line 1147 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> clang::ast_matchers::lambdaExpr

Matches lambda expressions.

Example matches [&](){return 5;}

   [&](){return 5;}

Definition at line 756 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl> clang::ast_matchers::linkageSpecDecl

Matches a declaration of a linkage specification.

Given

   extern "C" {}

linkageSpecDecl() matches "extern "C" {}"

Definition at line 165 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, MaterializeTemporaryExpr> clang::ast_matchers::materializeTemporaryExpr

Matches nodes where temporaries are materialized.

Example: Given

   struct T {void func()};
   T f();
   void g(T);

materializeTemporaryExpr() matches 'f()' in these statements

   T u(f());
   g(f());

but does not match

   f();
   f().func();

Definition at line 912 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXMemberCallExpr> clang::ast_matchers::memberCallExpr

Matches member call expressions.

Example matches x.y()

   X x;
   x.y();

Definition at line 767 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> clang::ast_matchers::memberExpr

Matches member expressions.

Given

   class Y {
     void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
     int a; static int b;
   };

memberExpr() matches this->x, x, y.x, a, this->b

Definition at line 738 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> clang::ast_matchers::methodDecl

Matches method declarations.

Example matches y

   class X { void y(); };

Definition at line 654 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> clang::ast_matchers::namedDecl

Matches a declaration of anything that could have a name.

Example matches X, S, the anonymous union type, i, and U;

   typedef int X;
   struct S {
     union {
       int i;
     } U;
   };

Definition at line 178 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> clang::ast_matchers::namespaceDecl

Matches a declaration of a namespace.

Given

   namespace {}
   namespace test {}

namespaceDecl() matches "namespace {}" and "namespace test {}"

Definition at line 189 of file ASTMatchers.h.

const internal::VariadicAllOfMatcher<NestedNameSpecifier> clang::ast_matchers::nestedNameSpecifier

Matches record types (e.g. structs, classes).

Given

   class C {};
   struct S {};

   C c;
   S s;
 \code

 \c recordType() matches the type of the variable declarations of both \c c
 and \c s.
AST_TYPE_MATCHER(RecordType, recordType);

 \brief Matches types specified with an elaborated type keyword or with a
 qualified name.

 Given
 \code
   namespace N {
     namespace M {
       class D {};
     }
   }
   class C {};

   class C c;
   N::M::D d;
 \code

 \c elaboratedType() matches the type of the variable declarations of both
 \c c and \c d.
AST_TYPE_MATCHER(ElaboratedType, elaboratedType);

 \brief Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
 matches \c InnerMatcher if the qualifier exists.

 Given
 \code
   namespace N {
     namespace M {
       class D {};
     }
   }
   N::M::D d;
 \code

 \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
 matches the type of the variable declaration of \c d.
AST_MATCHER_P(ElaboratedType, hasQualifier,
              internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
  if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
    return InnerMatcher.matches(*Qualifier, Finder, Builder);

  return false;
}

 \brief Matches ElaboratedTypes whose named type matches \c InnerMatcher.

 Given
 \code
   namespace N {
     namespace M {
       class D {};
     }
   }
   N::M::D d;
 \code

 \c elaboratedType(namesType(recordType(
 hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
 declaration of \c d.
AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
              InnerMatcher) {
  return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
}

 \brief Matches declarations whose declaration context, interpreted as a
 Decl, matches \c InnerMatcher.

 Given
 \code
   namespace N {
     namespace M {
       class D {};
     }
   }
 \code

 \c recordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the
 declaration of \c class \c D.
AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher<Decl>, InnerMatcher) {
  const DeclContext *DC = Node.getDeclContext();
  if (!DC) return false;
  return InnerMatcher.matches(*Decl::castFromDeclContext(DC), Finder, Builder);
}

 \brief Matches nested name specifiers.

 Given
 \code
   namespace ns {
     struct A { static void f(); };
     void A::f() {}
     void g() { A::f(); }
   }
   ns::A a;

nestedNameSpecifier() matches "ns::" and both "A::"

Definition at line 3597 of file ASTMatchers.h.

Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.

Definition at line 3601 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> clang::ast_matchers::newExpr

Matches new expressions.

Given

   new X;

newExpr() matches 'new X'.

Definition at line 922 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXNullPtrLiteralExpr> clang::ast_matchers::nullPtrLiteralExpr

Matches nullptr literal.

Definition at line 1315 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> clang::ast_matchers::nullStmt

Matches null statements.

   foo();;

nullStmt() matches the second ';'

Definition at line 1231 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXOperatorCallExpr> clang::ast_matchers::operatorCallExpr

Matches overloaded operator calls.

Note that if an operator isn't overloaded, it won't match. Instead, use binaryOperator matcher. Currently it does not match operators such as new delete. FIXME: figure out why these do not match?

Example matches both operator<<((o << b), c) and operator<<(o, b) (matcher = operatorCallExpr())

   ostream &operator<< (ostream &out, int i) { };
   ostream &o; int b = 1, c = 1;
   o << b << c;

Definition at line 975 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> clang::ast_matchers::parmVarDecl

Matches parameter variable declarations.

Given

   void f(int x);

parmVarDecl() matches int x.

Definition at line 246 of file ASTMatchers.h.

const internal::VariadicAllOfMatcher<QualType> clang::ast_matchers::qualType

Matches QualTypes in the clang AST.

Definition at line 1487 of file ASTMatchers.h.

Referenced by AST_MATCHER_P_OVERLOAD(), and AST_POLYMORPHIC_MATCHER_P_OVERLOAD().

const internal::VariadicDynCastAllOfMatcher< Decl, CXXRecordDecl> clang::ast_matchers::recordDecl

Matches C++ class declarations.

Example matches X, Z

   class X;
   template<class T> class Z {};

Definition at line 200 of file ASTMatchers.h.

Referenced by AST_MATCHER().

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXReinterpretCastExpr> clang::ast_matchers::reinterpretCastExpr

Matches a reinterpret_cast expression.

Either the source expression or the destination type can be matched using has(), but hasDestinationType() is more specific and can be more readable.

Example matches reinterpret_cast<char*>(&p) in

   void* p = reinterpret_cast<char*>(&p);

Definition at line 1359 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> clang::ast_matchers::returnStmt

Matches return statements.

Given

   return 1;

returnStmt() matches 'return 1'

Definition at line 1125 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXStaticCastExpr> clang::ast_matchers::staticCastExpr

Matches a C++ static_cast expression.

See also:
hasDestinationType
reinterpretCast

Example: staticCastExpr() matches static_cast<long>(8) in

   long eight(static_cast<long>(8));

Definition at line 1376 of file ASTMatchers.h.

const internal::VariadicAllOfMatcher<Stmt> clang::ast_matchers::stmt

Matches statements.

Given

   { ++a; }

stmt() matches both the compound statement '{ ++a; }' and '++a'.

Definition at line 713 of file ASTMatchers.h.

Referenced by alignOfExpr(), AST_MATCHER(), GenerateExtensivePathDiagnostic(), clang::AnalysisDeclContext::registerForcedBlockExpression(), sizeOfExpr(), and clang::CFG::VisitBlockStmts().

const internal::VariadicDynCastAllOfMatcher< Stmt, StringLiteral> clang::ast_matchers::stringLiteral

Matches string literals (also matches wide string literals).

Example matches "abcd", L"abcd"

   char *s = "abcd"; wchar_t *ws = L"abcd"

Definition at line 1261 of file ASTMatchers.h.

Matches substitutions of non-type template parameters.

Given

   template <int N>
   struct A { static const int n = N; };
   struct B : public A<42> {};

substNonTypeTemplateParmExpr() matches "N" in the right-hand side of "static const int n = N;"

Definition at line 802 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> clang::ast_matchers::switchCase

Matches case and default statements inside switch statements.

Given

   switch(a) { case 42: break; default: break; }

switchCase() matches 'case 42: break;' and 'default: break;'.

Definition at line 1167 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> clang::ast_matchers::switchStmt

Matches switch statements.

Given

   switch(a) { case 42: break; default: break; }

switchStmt() matches 'switch(a)'.

Definition at line 1157 of file ASTMatchers.h.

const internal::VariadicAllOfMatcher<TemplateArgument> clang::ast_matchers::templateArgument

Matches template arguments.

Given

   template <typename T> struct C {};
   C<int> c;

templateArgument() matches 'int' in C<int>.

Definition at line 283 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXTemporaryObjectExpr> clang::ast_matchers::temporaryObjectExpr

Matches functional cast expressions having N != 1 arguments.

Example: Matches Foo(bar, bar)

   Foo h = Foo(bar, bar);

Definition at line 1484 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> clang::ast_matchers::thisExpr

Matches implicit and explicit this expressions.

Example matches the implicit this expression in "return i". (matcher = thisExpr())

 struct foo {
   int i;
   int f() { return i; }
 };

Definition at line 878 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> clang::ast_matchers::throwExpr

Matches throw expressions.

   try { throw 5; } catch(int i) {}

throwExpr() matches 'throw 5'

Definition at line 1222 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> clang::ast_matchers::tryStmt

Matches try statements.

   try {} catch(int i) {}

tryStmt() matches 'try {}'

Definition at line 1213 of file ASTMatchers.h.

const internal::VariadicAllOfMatcher<Type> clang::ast_matchers::type

Matches Types in the clang AST.

Definition at line 1490 of file ASTMatchers.h.

Referenced by clang::Sema::ActOnForEachDeclStmt(), clang::Sema::ActOnObjCAtSynchronizedOperand(), clang::InitializationSequence::AddPassByIndirectCopyRestoreStep(), clang::Sema::AddPushedVisibilityAttribute(), breakDownVectorType(), clang::Sema::BuildDeclarationNameExpr(), clang::Sema::BuildMemberReferenceExpr(), clang::arcmt::trans::canApplyWeak(), clang::Sema::CheckCompleteVariableDeclaration(), clang::Sema::CodeCompleteCase(), clang::PseudoObjectExpr::Create(), diagnoseBadTypeAttribute(), clang::Sema::DiagnoseSentinelCalls(), distributeFunctionTypeAttr(), distributeObjCPointerTypeAttr(), clang::CodeGen::CodeGenFunction::EmitARCRetainAutoreleasedReturnValue(), clang::CodeGen::CodeGenFunction::EmitARCStoreStrong(), clang::CodeGen::CodeGenFunction::EmitAutoVarInit(), clang::CodeGen::CodeGenFunction::emitAutoVarTypeCleanup(), clang::CodeGen::CodeGenFunction::EmitBlockLiteral(), clang::CodeGen::CodeGenFunction::EmitCallArg(), clang::CodeGen::CodeGenFunction::EmitCXXAggrConstructorCall(), emitCXXDestructMethod(), EmitCXXNewAllocSize(), clang::CodeGen::CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(), EmitDeclDestroy(), EmitDeclInit(), clang::CodeGen::CodeGenFunction::EmitDelegateCallArg(), clang::CodeGen::CodeGenFunction::EmitExprAsInit(), clang::CodeGen::CodeGenFunction::EmitExtVectorElementExpr(), clang::CodeGen::CodeGenFunction::EmitLValueForField(), clang::CodeGen::CodeGenFunction::EnterDtorCleanups(), clang::Expr::findBoundMemberType(), clang::Sema::FixOverloadedFunctionReference(), clang::CodeGen::CodeGenFunction::GenerateCopyHelperFunction(), clang::CodeGen::CodeGenFunction::GenerateDestroyHelperFunction(), clang::ASTContext::getAttributedType(), clang::Type::getBaseElementTypeUnsafe(), getComplexType(), clang::CodeGen::CodeGenFunction::getEvaluationKind(), getLVForTemplateParameterList(), clang::CodeGen::CodeGenModule::getMemberPointerConstant(), getNullForVariable(), clang::ASTContext::getVariableArrayDecayedType(), handleBlocksAttr(), handleObjCGCTypeAttr(), handleObjCOwnershipTypeAttr(), handleObjCPreciseLifetimeAttr(), handleVisibilityAttr(), inferARCLifetimeForPointee(), clang::Sema::inferObjCARCLifetime(), isPlaceholderToRemoveAsArg(), clang::Sema::PrepareCastToObjCObjectPointer(), clang::CodeGen::CodeGenFunction::pushDestroy(), clang::CodeGen::CodeGenFunction::pushLifetimeExtendedDestroy(), clang::Sema::RequireCompleteDeclContext(), tryCaptureAsConstant(), and tryEmitARCRetainLoadOfScalar().

const internal::VariadicAllOfMatcher<TypeLoc> clang::ast_matchers::typeLoc

Matches TypeLocs in the clang AST.

Definition at line 1493 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, UnaryExprOrTypeTraitExpr> clang::ast_matchers::unaryExprOrTypeTraitExpr

Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)

Given

   Foo x = bar;
   int y = sizeof(x) + alignof(x);

unaryExprOrTypeTraitExpr() matches sizeof(x) and alignof(x)

Definition at line 1543 of file ASTMatchers.h.

Referenced by alignOfExpr(), and sizeOfExpr().

const internal::VariadicDynCastAllOfMatcher< Stmt, UnaryOperator> clang::ast_matchers::unaryOperator

Matches unary operator expressions.

Example matches !a

   !a || b

Definition at line 1335 of file ASTMatchers.h.

const internal::VariadicOperatorMatcherFunc<1, 1> clang::ast_matchers::unless
Initial value:

Matches if the provided matcher does not match.

Example matches Y (matcher = recordDecl(unless(hasName("X"))))

   class X {};
   class Y {};

Usable as: Any Matcher

Definition at line 1860 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, CXXUnresolvedConstructExpr> clang::ast_matchers::unresolvedConstructExpr

Matches unresolved constructor call expressions.

Example matches T(t) in return statement of f (matcher = unresolvedConstructExpr())

   template <typename T>
   void f(const T& t) { return T(t); }

Definition at line 866 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Decl, UnresolvedUsingValueDecl> clang::ast_matchers::unresolvedUsingValueDecl

Matches unresolved using value declarations.

Given

   template<typename X>
   class C : private X {
     using X::x;
   };

unresolvedUsingValueDecl() matches

 using X::x 

Definition at line 840 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher< Stmt, UserDefinedLiteral> clang::ast_matchers::userDefinedLiteral

Matches user defined literal operator call.

Example match: "foo"_suffix

Definition at line 1300 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> clang::ast_matchers::usingDecl

Matches using declarations.

Given

   namespace X { int x; }
   using X::x;

usingDecl() matches

 using X::x 

Definition at line 813 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl> clang::ast_matchers::usingDirectiveDecl

Matches using namespace declarations.

Given

   namespace X { int x; }
   using namespace X;

usingDirectiveDecl() matches

 using namespace X 

Definition at line 825 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> clang::ast_matchers::valueDecl

Matches any value declaration.

Example matches A, B, C and F

   enum X { A, B, C };
   void F();

Definition at line 596 of file ASTMatchers.h.

const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> clang::ast_matchers::varDecl

Matches variable declarations.

Note: this does not match declarations of member variables, which are "field" declarations in Clang parlance.

Example matches a

   int a;

Definition at line 665 of file ASTMatchers.h.

Referenced by clang::ento::ExprEngine::ProcessAutomaticObjDtor().

const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> clang::ast_matchers::whileStmt

Matches while statements.

Given

   while (true) {}

whileStmt() matches 'while (true) {}'.

Definition at line 1085 of file ASTMatchers.h.