16 #ifndef LLVM_CLANG_ASTMATCHERS_DYNAMIC_VARIANTVALUE_H 17 #define LLVM_CLANG_ASTMATCHERS_DYNAMIC_VARIANTVALUE_H 21 #include "llvm/ADT/IntrusiveRefCntPtr.h" 22 #include "llvm/ADT/Optional.h" 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;
127 virtual std::string getTypeAsString()
const = 0;
129 getTypedMatcher(
const MatcherOps &Ops)
const = 0;
131 unsigned *Specificity)
const = 0;
139 static VariantMatcher SingleMatcher(
const DynTypedMatcher &Matcher);
145 PolymorphicMatcher(std::vector<DynTypedMatcher> Matchers);
151 VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op,
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>();
209 std::string getTypeAsString()
const;
213 :
Value(std::move(Value)) {}
215 template <
typename T>
struct TypedMatcherOps;
221 std::shared_ptr<const Payload>
Value;
224 template <
typename T>
225 struct VariantMatcher::TypedMatcherOps final : VariantMatcher::MatcherOps {
227 : MatcherOps(ast_type_traits::ASTNodeKind::getFromNodeKind<T>()) {}
228 typedef ast_matchers::internal::Matcher<T> MatcherT;
231 convertMatcher(
const DynTypedMatcher &Matcher)
const override {
232 return DynTypedMatcher(Matcher.convertTo<T>());
269 explicit operator bool()
const {
return hasValue(); }
273 bool isBoolean()
const;
274 bool getBoolean()
const;
275 void setBoolean(
bool Boolean);
278 bool isDouble()
const;
279 double getDouble()
const;
280 void setDouble(
double Double);
283 bool isUnsigned()
const;
284 unsigned getUnsigned()
const;
285 void setUnsigned(
unsigned Unsigned);
288 bool isString()
const;
289 const std::string &getString()
const;
290 void setString(StringRef String);
293 bool isMatcher()
const;
316 std::string getTypeAsString()
const;
348 #endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_VARIANT_VALUE_H bool hasTypedMatcher() const
Determines if the contained matcher can be converted to Matcher<T>.
std::string asString() const
String representation of the type.
The base class of the type hierarchy.
bool operator<(const ArgKind &Other) const
ast_matchers::internal::Matcher< T > getTypedMatcher() const
Return this matcher as a Matcher<T>.
bool isConvertibleTo(ArgKind To, unsigned *Specificity) const
Determines if this type can be converted to To.
VariantValue(int Signed)
Constructs an unsigned value (disambiguation from bool).
ArgKind(Kind K)
Constructor for non-matcher types.
NodeKind
A kind of a syntax node, used for implementing casts.
Dataflow Directional Tag Classes.
ArgKind(ast_type_traits::ASTNodeKind MatcherKind)
Constructor for matcher types.
bool isNull() const
Whether the matcher is null.
A variant matcher object.
bool isConvertibleTo(ast_type_traits::ASTNodeKind Kind, unsigned *Specificity) const
Determines if the contained matcher can be converted to Kind.
ast_type_traits::ASTNodeKind getMatcherKind() const