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" 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;
128 virtual std::string getTypeAsString()
const = 0;
130 getTypedMatcher(
const MatcherOps &Ops)
const = 0;
132 unsigned *Specificity)
const = 0;
140 static VariantMatcher SingleMatcher(
const DynTypedMatcher &Matcher);
146 PolymorphicMatcher(std::vector<DynTypedMatcher> Matchers);
152 VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op,
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>();
210 std::string getTypeAsString()
const;
214 :
Value(std::move(Value)) {}
216 template <
typename T>
struct TypedMatcherOps;
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>());
270 explicit operator bool()
const {
return hasValue(); }
274 bool isBoolean()
const;
275 bool getBoolean()
const;
276 void setBoolean(
bool Boolean);
279 bool isDouble()
const;
280 double getDouble()
const;
281 void setDouble(
double Double);
284 bool isUnsigned()
const;
285 unsigned getUnsigned()
const;
286 void setUnsigned(
unsigned Unsigned);
289 bool isString()
const;
290 const std::string &getString()
const;
291 void setString(StringRef String);
294 bool isMatcher()
const;
317 std::string getTypeAsString()
const;
349 #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.
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