#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERSINTERNAL_H
#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERSINTERNAL_H
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/OperatorKinds.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Regex.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
namespace clang {
class ASTContext;
namespace ast_matchers {
class BoundNodes;
namespace internal {
template <typename... Ts> struct TypeList { … };
TypeList<T1, Ts...>;
EmptyTypeList;
template <typename AnyTypeList, typename T> struct TypeListContainsSuperOf { … };
TypeListContainsSuperOf<EmptyTypeList, T>;
template <typename ResultT, typename ArgT,
ResultT (*Func)(ArrayRef<const ArgT *>)>
struct VariadicFunction { … };
inline QualType getUnderlyingType(const Expr &Node) { … }
inline QualType getUnderlyingType(const ValueDecl &Node) { … }
inline QualType getUnderlyingType(const TypedefNameDecl &Node) { … }
inline QualType getUnderlyingType(const FriendDecl &Node) { … }
inline QualType getUnderlyingType(const CXXBaseSpecifier &Node) { … }
template <typename T,
std::enable_if_t<TypeListContainsSuperOf<
TypeList<CXXBaseSpecifier, CXXCtorInitializer,
CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr,
CompoundLiteralExpr, DeclaratorDecl, ObjCPropertyDecl,
TemplateArgumentLoc, TypedefNameDecl>,
T>::value> * = nullptr>
inline TypeSourceInfo *GetTypeSourceInfo(const T &Node) { … }
template <typename T,
std::enable_if_t<TypeListContainsSuperOf<
TypeList<CXXFunctionalCastExpr, ExplicitCastExpr>, T>::value> * =
nullptr>
inline TypeSourceInfo *GetTypeSourceInfo(const T &Node) { … }
inline TypeSourceInfo *GetTypeSourceInfo(const BlockDecl &Node) { … }
inline TypeSourceInfo *GetTypeSourceInfo(const CXXNewExpr &Node) { … }
inline const FunctionProtoType *
getFunctionProtoType(const FunctionProtoType &Node) { … }
inline const FunctionProtoType *getFunctionProtoType(const FunctionDecl &Node) { … }
inline clang::AccessSpecifier getAccessSpecifier(const Decl &Node) { … }
inline clang::AccessSpecifier getAccessSpecifier(const CXXBaseSpecifier &Node) { … }
class BoundNodesMap { … };
class BoundNodesTreeBuilder { … };
class ASTMatchFinder;
class DynMatcherInterface
: public llvm::ThreadSafeRefCountedBase<DynMatcherInterface> { … };
template <typename T>
class MatcherInterface : public DynMatcherInterface { … };
template <typename T>
class SingleNodeMatcherInterface : public MatcherInterface<T> { … };
template <typename> class Matcher;
class DynTypedMatcher { … };
template <typename T>
class Matcher { … };
template <typename T>
inline Matcher<T> makeMatcher(MatcherInterface<T> *Implementation) { … }
class ASTMatchFinder { … };
struct ASTChildrenNotSpelledInSourceScope { … };
template <>
inline Matcher<QualType> DynTypedMatcher::convertTo<QualType>() const { … }
template <typename MatcherT, typename IteratorT>
IteratorT matchesFirstInRange(const MatcherT &Matcher, IteratorT Start,
IteratorT End, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) { … }
template <typename MatcherT, typename IteratorT>
IteratorT matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start,
IteratorT End, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) { … }
template <typename T, std::enable_if_t<!std::is_base_of<FunctionDecl, T>::value>
* = nullptr>
inline bool isDefaultedHelper(const T *) { … }
inline bool isDefaultedHelper(const FunctionDecl *FD) { … }
template <typename Ty>
class has_getDecl { … };
template <typename T, typename ArgT>
class HasOverloadedOperatorNameMatcher : public SingleNodeMatcherInterface<T> { … };
class HasNameMatcher : public SingleNodeMatcherInterface<NamedDecl> { … };
Matcher<NamedDecl> hasAnyNameFunc(ArrayRef<const StringRef *> NameRefs);
Matcher<ObjCMessageExpr> hasAnySelectorFunc(
ArrayRef<const StringRef *> NameRefs);
template <typename T, typename DeclMatcherT>
class HasDeclarationMatcher : public MatcherInterface<T> { … };
template <typename T>
struct IsBaseType { … };
template <typename T>
const bool IsBaseType<T>::value;
AllNodeBaseTypes;
template <class T> struct ExtractFunctionArgMeta;
ExtractFunctionArgMeta<void (T)>;
template <class T, class Tuple, std::size_t... I>
constexpr T *new_from_tuple_impl(Tuple &&t, std::index_sequence<I...>) { … }
template <class T, class Tuple> constexpr T *new_from_tuple(Tuple &&t) { … }
AdaptativeDefaultFromTypes;
AdaptativeDefaultToTypes;
HasDeclarationSupportedTypes;
template <typename T> class BindableMatcher : public Matcher<T> { … };
class TrueMatcher { … };
template <typename T>
BindableMatcher<T>
makeAllOfComposite(ArrayRef<const Matcher<T> *> InnerMatchers) { … }
template <typename T, typename InnerT>
BindableMatcher<T>
makeDynCastAllOfComposite(ArrayRef<const Matcher<InnerT> *> InnerMatchers) { … }
template <typename SourceT, typename TargetT>
class VariadicDynCastAllOfMatcher
: public VariadicFunction<BindableMatcher<SourceT>, Matcher<TargetT>,
makeDynCastAllOfComposite<SourceT, TargetT>> { … };
template <typename T>
class VariadicAllOfMatcher
: public VariadicFunction<BindableMatcher<T>, Matcher<T>,
makeAllOfComposite<T>> { … };
template <typename... Ps> class VariadicOperatorMatcher { … };
template <unsigned MinCount, unsigned MaxCount>
struct VariadicOperatorMatcherFunc { … };
template <typename T, bool IsBaseOf, typename Head, typename Tail>
struct GetCladeImpl { … };
GetCladeImpl<T, false, Head, Tail>;
template <typename T, typename... U>
struct GetClade : GetCladeImpl<T, false, T, AllNodeBaseTypes> { … };
template <typename CladeType, typename... MatcherTypes>
struct MapAnyOfMatcherImpl { … };
MapAnyOfMatcher;
template <typename... MatcherTypes> struct MapAnyOfHelper { … };
template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
typename T, typename ToTypes>
class ArgumentAdaptingMatcherFuncAdaptor { … };
template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
typename FromTypes = AdaptativeDefaultFromTypes,
typename ToTypes = AdaptativeDefaultToTypes>
struct ArgumentAdaptingMatcherFunc { … };
template <typename T> class TraversalMatcher : public MatcherInterface<T> { … };
template <typename MatcherType> class TraversalWrapper { … };
template <template <typename T, typename... Params> class MatcherT,
typename ReturnTypesF, typename... ParamTypes>
class PolymorphicMatcher { … };
template <typename T, typename ChildT>
class HasMatcher : public MatcherInterface<T> { … };
template <typename T, typename ChildT>
class ForEachMatcher : public MatcherInterface<T> { … };
template <typename T>
inline Matcher<T> DynTypedMatcher::unconditionalConvertTo() const { … }
template <typename T, typename DescendantT>
class HasDescendantMatcher : public MatcherInterface<T> { … };
template <typename T, typename ParentT>
class HasParentMatcher : public MatcherInterface<T> { … };
template <typename T, typename AncestorT>
class HasAncestorMatcher : public MatcherInterface<T> { … };
template <typename T, typename DescendantT>
class ForEachDescendantMatcher : public MatcherInterface<T> { … };
template <typename T, typename ValueT>
class ValueEqualsMatcher : public SingleNodeMatcherInterface<T> { … };
template <>
inline bool ValueEqualsMatcher<FloatingLiteral, double>::matchesNode(
const FloatingLiteral &Node) const { … }
template <>
inline bool ValueEqualsMatcher<FloatingLiteral, float>::matchesNode(
const FloatingLiteral &Node) const { … }
template <>
inline bool ValueEqualsMatcher<FloatingLiteral, llvm::APFloat>::matchesNode(
const FloatingLiteral &Node) const { … }
template <typename TLoc, typename T>
class LocMatcher : public MatcherInterface<TLoc> { … };
class TypeLocTypeMatcher : public MatcherInterface<TypeLoc> { … };
template <typename T> class TypeTraverseMatcher : public MatcherInterface<T> { … };
template <typename T>
class TypeLocTraverseMatcher : public MatcherInterface<T> { … };
template <typename InnerTBase,
template <typename OuterT> class Getter,
template <typename OuterT> class MatcherImpl,
typename ReturnTypesF>
class TypeTraversePolymorphicMatcher { … };
template <typename Matcher, Matcher (*Func)()> class MemoizedMatcher { … };
template <typename InnerTBase, template <typename OuterT> class Getter,
template <typename OuterT> class MatcherImpl, typename ReturnTypesF>
TypeTraversePolymorphicMatcher<InnerTBase, Getter, MatcherImpl, ReturnTypesF>
TypeTraversePolymorphicMatcher<
InnerTBase, Getter, MatcherImpl,
ReturnTypesF>::create(ArrayRef<const Matcher<InnerTBase> *> InnerMatchers) { … }
inline ArrayRef<TemplateArgument>
getTemplateSpecializationArgs(const ClassTemplateSpecializationDecl &D) { … }
inline ArrayRef<TemplateArgument>
getTemplateSpecializationArgs(const VarTemplateSpecializationDecl &D) { … }
inline ArrayRef<TemplateArgument>
getTemplateSpecializationArgs(const TemplateSpecializationType &T) { … }
inline ArrayRef<TemplateArgument>
getTemplateSpecializationArgs(const FunctionDecl &FD) { … }
inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const ClassTemplateSpecializationDecl &D) { … }
inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const VarTemplateSpecializationDecl &D) { … }
inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const FunctionDecl &FD) { … }
inline ArrayRef<TemplateArgumentLoc>
getTemplateArgsWritten(const DeclRefExpr &DRE) { … }
inline SmallVector<TemplateArgumentLoc>
getTemplateArgsWritten(const TemplateSpecializationTypeLoc &T) { … }
struct NotEqualsBoundNodePredicate { … };
template <typename Ty, typename Enable = void> struct GetBodyMatcher { … };
GetBodyMatcher<Ty, std::enable_if_t<std::is_base_of<FunctionDecl, Ty>::value>>;
template <typename NodeType>
inline std::optional<BinaryOperatorKind>
equivalentBinaryOperator(const NodeType &Node) { … }
template <>
inline std::optional<BinaryOperatorKind>
equivalentBinaryOperator<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) { … }
template <typename NodeType>
inline std::optional<UnaryOperatorKind>
equivalentUnaryOperator(const NodeType &Node) { … }
template <>
inline std::optional<UnaryOperatorKind>
equivalentUnaryOperator<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) { … }
template <typename NodeType> inline const Expr *getLHS(const NodeType &Node) { … }
template <>
inline const Expr *
getLHS<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) { … }
template <typename NodeType> inline const Expr *getRHS(const NodeType &Node) { … }
template <>
inline const Expr *
getRHS<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) { … }
template <typename NodeType>
inline const Expr *getSubExpr(const NodeType &Node) { … }
template <>
inline const Expr *
getSubExpr<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) { … }
template <typename Ty>
struct HasSizeMatcher { … };
template <>
inline bool HasSizeMatcher<StringLiteral>::hasSize(
const StringLiteral &Node, unsigned int N) { … }
template <typename Ty>
struct GetSourceExpressionMatcher { … };
template <>
inline const Expr *GetSourceExpressionMatcher<OpaqueValueExpr>::get(
const OpaqueValueExpr &Node) { … }
template <typename Ty>
struct CompoundStmtMatcher { … };
template <>
inline const CompoundStmt *
CompoundStmtMatcher<StmtExpr>::get(const StmtExpr &Node) { … }
std::optional<SourceLocation> getExpansionLocOfMacro(StringRef MacroName,
SourceLocation Loc,
const ASTContext &Context);
inline std::optional<StringRef> getOpName(const UnaryOperator &Node) { … }
inline std::optional<StringRef> getOpName(const BinaryOperator &Node) { … }
inline StringRef getOpName(const CXXRewrittenBinaryOperator &Node) { … }
inline std::optional<StringRef> getOpName(const CXXOperatorCallExpr &Node) { … }
inline StringRef getOpName(const CXXFoldExpr &Node) { … }
template <typename T, typename ArgT = std::vector<std::string>>
class HasAnyOperatorNameMatcher : public SingleNodeMatcherInterface<T> {
static_assert(std::is_same<T, BinaryOperator>::value ||
std::is_same<T, CXXOperatorCallExpr>::value ||
std::is_same<T, CXXRewrittenBinaryOperator>::value ||
std::is_same<T, UnaryOperator>::value,
"Matcher only supports `BinaryOperator`, `UnaryOperator`, "
"`CXXOperatorCallExpr` and `CXXRewrittenBinaryOperator`");
static_assert(std::is_same<ArgT, std::vector<std::string>>::value,
"Matcher ArgT must be std::vector<std::string>");
public:
explicit HasAnyOperatorNameMatcher(std::vector<std::string> Names)
: … { … }
bool matchesNode(const T &Node) const override { … }
private:
static std::optional<StringRef> getOpName(const UnaryOperator &Node) { … }
static std::optional<StringRef> getOpName(const BinaryOperator &Node) { … }
static StringRef getOpName(const CXXRewrittenBinaryOperator &Node) { … }
static std::optional<StringRef> getOpName(const CXXOperatorCallExpr &Node) { … }
std::vector<std::string> Names;
};
HasOpNameMatcher;
HasOpNameMatcher hasAnyOperatorNameFunc(ArrayRef<const StringRef *> NameRefs);
HasOverloadOpNameMatcher;
HasOverloadOpNameMatcher
hasAnyOverloadedOperatorNameFunc(ArrayRef<const StringRef *> NameRefs);
bool matchesAnyBase(const CXXRecordDecl &Node,
const Matcher<CXXBaseSpecifier> &BaseSpecMatcher,
ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder);
std::shared_ptr<llvm::Regex> createAndVerifyRegex(StringRef Regex,
llvm::Regex::RegexFlags Flags,
StringRef MatcherID);
inline bool
MatchTemplateArgLocAt(const DeclRefExpr &Node, unsigned int Index,
internal::Matcher<TemplateArgumentLoc> InnerMatcher,
internal::ASTMatchFinder *Finder,
internal::BoundNodesTreeBuilder *Builder) { … }
inline bool
MatchTemplateArgLocAt(const TemplateSpecializationTypeLoc &Node,
unsigned int Index,
internal::Matcher<TemplateArgumentLoc> InnerMatcher,
internal::ASTMatchFinder *Finder,
internal::BoundNodesTreeBuilder *Builder) { … }
}
}
}
#endif