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"
28 namespace ast_matchers {
66 return MatcherKind < Other.MatcherKind;
78 using ast_matchers::internal::DynTypedMatcher;
99 bool canConstructFrom(
const DynTypedMatcher &
Matcher,
100 bool &IsExactMatch)
const;
104 virtual DynTypedMatcher
105 convertMatcher(
const DynTypedMatcher &Matcher)
const = 0;
111 constructVariadicOperator(DynTypedMatcher::VariadicOperator Op,
115 ~MatcherOps() =
default;
132 unsigned *Specificity)
const = 0;
153 std::vector<VariantMatcher> Args);
178 if (!
Value)
return false;
179 return Value->getTypedMatcher(TypedMatcherOps<T>()).hasValue();
189 unsigned *Specificity)
const {
191 return Value->isConvertibleTo(Kind, Specificity);
201 assert(hasTypedMatcher<T>() &&
"hasTypedMatcher<T>() == false");
202 return Value->getTypedMatcher(TypedMatcherOps<T>())
203 ->template convertTo<T>();
214 : Value(std::move(Value)) {}
216 template <
typename T>
struct TypedMatcherOps;
219 class PolymorphicPayload;
220 class VariadicOpPayload;
222 std::shared_ptr<const Payload>
Value;
225 template <
typename T>
226 struct VariantMatcher::TypedMatcherOps final : VariantMatcher::MatcherOps {
228 : MatcherOps(ast_type_traits::ASTNodeKind::getFromNodeKind<T>()) {}
229 typedef ast_matchers::internal::Matcher<T> MatcherT;
232 convertMatcher(
const DynTypedMatcher &
Matcher)
const override {
233 return DynTypedMatcher(Matcher.convertTo<T>());
349 #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
VariantValue(int Signed)
Constructs an unsigned value (disambiguation from bool).
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.
void setDouble(double Double)
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>.
bool isBoolean() const
Boolean value functions.
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.
bool isDouble() const
Double value functions.
const std::string & getString() const
void setUnsigned(unsigned Unsigned)
void setBoolean(bool Boolean)
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.