Changeset View
Changeset View
Standalone View
Standalone View
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
Show First 20 Lines • Show All 673 Lines • ▼ Show 20 Lines | public: | ||||
/// A class is not considered to be derived from itself. | /// A class is not considered to be derived from itself. | ||||
virtual bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration, | virtual bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration, | ||||
const Matcher<NamedDecl> &Base, | const Matcher<NamedDecl> &Base, | ||||
BoundNodesTreeBuilder *Builder, | BoundNodesTreeBuilder *Builder, | ||||
bool Directly) = 0; | bool Directly) = 0; | ||||
template <typename T> | template <typename T> | ||||
bool matchesChildOf(const T &Node, const DynTypedMatcher &Matcher, | bool matchesChildOf(const T &Node, const DynTypedMatcher &Matcher, | ||||
BoundNodesTreeBuilder *Builder, TraversalKind Traverse, | BoundNodesTreeBuilder *Builder, BindKind Bind) { | ||||
BindKind Bind) { | |||||
static_assert(std::is_base_of<Decl, T>::value || | static_assert(std::is_base_of<Decl, T>::value || | ||||
std::is_base_of<Stmt, T>::value || | std::is_base_of<Stmt, T>::value || | ||||
std::is_base_of<NestedNameSpecifier, T>::value || | std::is_base_of<NestedNameSpecifier, T>::value || | ||||
std::is_base_of<NestedNameSpecifierLoc, T>::value || | std::is_base_of<NestedNameSpecifierLoc, T>::value || | ||||
std::is_base_of<TypeLoc, T>::value || | std::is_base_of<TypeLoc, T>::value || | ||||
std::is_base_of<QualType, T>::value, | std::is_base_of<QualType, T>::value, | ||||
"unsupported type for recursive matching"); | "unsupported type for recursive matching"); | ||||
return matchesChildOf(DynTypedNode::create(Node), getASTContext(), Matcher, | return matchesChildOf(DynTypedNode::create(Node), getASTContext(), Matcher, | ||||
Builder, Traverse, Bind); | Builder, Bind); | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
bool matchesDescendantOf(const T &Node, const DynTypedMatcher &Matcher, | bool matchesDescendantOf(const T &Node, const DynTypedMatcher &Matcher, | ||||
BoundNodesTreeBuilder *Builder, BindKind Bind) { | BoundNodesTreeBuilder *Builder, BindKind Bind) { | ||||
static_assert(std::is_base_of<Decl, T>::value || | static_assert(std::is_base_of<Decl, T>::value || | ||||
std::is_base_of<Stmt, T>::value || | std::is_base_of<Stmt, T>::value || | ||||
std::is_base_of<NestedNameSpecifier, T>::value || | std::is_base_of<NestedNameSpecifier, T>::value || | ||||
Show All 24 Lines | public: | ||||
virtual bool IsMatchingInASTNodeNotSpelledInSource() const = 0; | virtual bool IsMatchingInASTNodeNotSpelledInSource() const = 0; | ||||
bool isTraversalIgnoringImplicitNodes() const; | bool isTraversalIgnoringImplicitNodes() const; | ||||
protected: | protected: | ||||
virtual bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx, | virtual bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx, | ||||
const DynTypedMatcher &Matcher, | const DynTypedMatcher &Matcher, | ||||
BoundNodesTreeBuilder *Builder, | BoundNodesTreeBuilder *Builder, | ||||
TraversalKind Traverse, BindKind Bind) = 0; | BindKind Bind) = 0; | ||||
virtual bool matchesDescendantOf(const DynTypedNode &Node, ASTContext &Ctx, | virtual bool matchesDescendantOf(const DynTypedNode &Node, ASTContext &Ctx, | ||||
const DynTypedMatcher &Matcher, | const DynTypedMatcher &Matcher, | ||||
BoundNodesTreeBuilder *Builder, | BoundNodesTreeBuilder *Builder, | ||||
BindKind Bind) = 0; | BindKind Bind) = 0; | ||||
virtual bool matchesAncestorOf(const DynTypedNode &Node, ASTContext &Ctx, | virtual bool matchesAncestorOf(const DynTypedNode &Node, ASTContext &Ctx, | ||||
const DynTypedMatcher &Matcher, | const DynTypedMatcher &Matcher, | ||||
▲ Show 20 Lines • Show All 620 Lines • ▼ Show 20 Lines | |||||
public: | public: | ||||
explicit HasMatcher(const Matcher<ChildT> &InnerMatcher) | explicit HasMatcher(const Matcher<ChildT> &InnerMatcher) | ||||
: InnerMatcher(InnerMatcher) {} | : InnerMatcher(InnerMatcher) {} | ||||
bool matches(const T &Node, ASTMatchFinder *Finder, | bool matches(const T &Node, ASTMatchFinder *Finder, | ||||
BoundNodesTreeBuilder *Builder) const override { | BoundNodesTreeBuilder *Builder) const override { | ||||
return Finder->matchesChildOf(Node, this->InnerMatcher, Builder, | return Finder->matchesChildOf(Node, this->InnerMatcher, Builder, | ||||
TraversalKind::TK_AsIs, | |||||
ASTMatchFinder::BK_First); | ASTMatchFinder::BK_First); | ||||
} | } | ||||
}; | }; | ||||
/// Matches nodes of type T that have child nodes of type ChildT for | /// Matches nodes of type T that have child nodes of type ChildT for | ||||
/// which a specified child matcher matches. ChildT must be an AST base | /// which a specified child matcher matches. ChildT must be an AST base | ||||
/// type. | /// type. | ||||
/// As opposed to the HasMatcher, the ForEachMatcher will produce a match | /// As opposed to the HasMatcher, the ForEachMatcher will produce a match | ||||
/// for each child that matches. | /// for each child that matches. | ||||
template <typename T, typename ChildT> | template <typename T, typename ChildT> | ||||
class ForEachMatcher : public MatcherInterface<T> { | class ForEachMatcher : public MatcherInterface<T> { | ||||
static_assert(IsBaseType<ChildT>::value, | static_assert(IsBaseType<ChildT>::value, | ||||
"for each only accepts base type matcher"); | "for each only accepts base type matcher"); | ||||
const DynTypedMatcher InnerMatcher; | const DynTypedMatcher InnerMatcher; | ||||
public: | public: | ||||
explicit ForEachMatcher(const Matcher<ChildT> &InnerMatcher) | explicit ForEachMatcher(const Matcher<ChildT> &InnerMatcher) | ||||
: InnerMatcher(InnerMatcher) {} | : InnerMatcher(InnerMatcher) {} | ||||
bool matches(const T &Node, ASTMatchFinder *Finder, | bool matches(const T &Node, ASTMatchFinder *Finder, | ||||
BoundNodesTreeBuilder *Builder) const override { | BoundNodesTreeBuilder *Builder) const override { | ||||
return Finder->matchesChildOf( | return Finder->matchesChildOf( | ||||
Node, this->InnerMatcher, Builder, | Node, this->InnerMatcher, Builder, | ||||
TraversalKind::TK_IgnoreImplicitCastsAndParentheses, | |||||
ASTMatchFinder::BK_All); | ASTMatchFinder::BK_All); | ||||
} | } | ||||
}; | }; | ||||
/// VariadicOperatorMatcher related types. | /// VariadicOperatorMatcher related types. | ||||
/// @{ | /// @{ | ||||
/// Polymorphic matcher object that uses a \c | /// Polymorphic matcher object that uses a \c | ||||
▲ Show 20 Lines • Show All 575 Lines • Show Last 20 Lines |