17 #ifndef LLVM_CLANG_ASTMATCHERS_DYNAMIC_VARIANTVALUE_H
18 #define LLVM_CLANG_ASTMATCHERS_DYNAMIC_VARIANTVALUE_H
22 #include "llvm/ADT/IntrusiveRefCntPtr.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/Twine.h"
29 namespace ast_matchers {
65 return MatcherKind < Other.MatcherKind;
77 using ast_matchers::internal::DynTypedMatcher;
98 bool canConstructFrom(
const DynTypedMatcher &
Matcher,
99 bool &IsExactMatch)
const;
103 virtual DynTypedMatcher
104 convertMatcher(
const DynTypedMatcher &Matcher)
const = 0;
110 constructVariadicOperator(DynTypedMatcher::VariadicOperator Op,
114 ~MatcherOps() =
default;
123 class Payload :
public RefCountedBaseVPTR {
131 unsigned *Specificity)
const = 0;
152 std::vector<VariantMatcher> Args);
177 if (!
Value)
return false;
178 return Value->getTypedMatcher(TypedMatcherOps<T>()).hasValue();
188 unsigned *Specificity)
const {
190 return Value->isConvertibleTo(Kind, Specificity);
200 assert(hasTypedMatcher<T>() &&
"hasTypedMatcher<T>() == false");
201 return Value->getTypedMatcher(TypedMatcherOps<T>())
202 ->template convertTo<T>();
214 template <
typename T>
struct TypedMatcherOps;
217 class PolymorphicPayload;
218 class VariadicOpPayload;
223 template <
typename T>
224 struct VariantMatcher::TypedMatcherOps final : VariantMatcher::MatcherOps {
226 : MatcherOps(ast_type_traits::ASTNodeKind::getFromNodeKind<T>()) {}
227 typedef ast_matchers::internal::Matcher<T> MatcherT;
230 convertMatcher(
const DynTypedMatcher &
Matcher)
const override {
231 return DynTypedMatcher(Matcher.convertTo<T>());
326 #endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_VARIANT_VALUE_H
const MatchFinder::MatchersByType * Matchers
bool isMatcher() const
Matcher value functions.
void setString(StringRef String)
std::string getTypeAsString() const
String representation of the type of the value.
The base class of the type hierarchy.
const DynTypedMatcher *const Matcher
VariantValue & operator=(const VariantValue &Other)
static VariantMatcher SingleMatcher(const DynTypedMatcher &Matcher)
Clones the provided matcher.
static VariantMatcher VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op, std::vector< VariantMatcher > Args)
Creates a 'variadic' operator matcher.
bool isUnsigned() const
Unsigned value functions.
bool isConvertibleTo(ast_type_traits::ASTNodeKind Kind, unsigned *Specificity) const
Determines if the contained matcher can be converted to Kind.
std::vector< DynTypedMatcher > InnerMatchers
ast_type_traits::ASTNodeKind getMatcherKind() const
bool isNull() const
Whether the matcher is null.
ArgKind(Kind K)
Constructor for non-matcher types.
std::string asString() const
String representation of the type.
bool isConvertibleTo(ArgKind To, unsigned *Specificity) const
Determines if this type can be converted to To.
VariantMatcher()
A null matcher.
std::string getTypeAsString() const
String representation of the type of the value.
ast_matchers::internal::Matcher< T > getTypedMatcher() const
Return this matcher as a Matcher<T>.
ArgKind(ast_type_traits::ASTNodeKind MatcherKind)
Constructor for matcher types.
static VariantMatcher PolymorphicMatcher(std::vector< DynTypedMatcher > Matchers)
Clones the provided matchers.
void reset()
Makes the matcher the "null" matcher.
void setMatcher(const VariantMatcher &Matcher)
bool operator<(const ArgKind &Other) const
bool isString() const
String value functions.
A variant matcher object.
bool isConvertibleTo(ArgKind Kind, unsigned *Specificity) const
Determines if the contained value can be converted to Kind.
const std::string & getString() const
void setUnsigned(unsigned Unsigned)
const VariantMatcher & getMatcher() const
bool hasTypedMatcher() const
Determines if the contained matcher can be converted to Matcher<T>.
unsigned getUnsigned() const
llvm::Optional< DynTypedMatcher > getSingleMatcher() const
Return a single matcher, if there is no ambiguity.