summaryrefslogtreecommitdiff
path: root/lib/ASTMatchers/Dynamic/Marshallers.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ASTMatchers/Dynamic/Marshallers.h')
-rw-r--r--lib/ASTMatchers/Dynamic/Marshallers.h49
1 files changed, 35 insertions, 14 deletions
diff --git a/lib/ASTMatchers/Dynamic/Marshallers.h b/lib/ASTMatchers/Dynamic/Marshallers.h
index 64d6b7814aeb6..7b1a307026334 100644
--- a/lib/ASTMatchers/Dynamic/Marshallers.h
+++ b/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -1,4 +1,4 @@
-//===--- Marshallers.h - Generic matcher function marshallers -*- C++ -*-===//
+//===--- Marshallers.h - Generic matcher function marshallers ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -32,7 +32,6 @@ namespace ast_matchers {
namespace dynamic {
namespace internal {
-
/// \brief Helper template class to just from argument type to the right is/get
/// functions in VariantValue.
/// Used to verify and extract the matcher arguments below.
@@ -97,6 +96,28 @@ public:
}
};
+template <> struct ArgTypeTraits<clang::CastKind> {
+private:
+ static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+ return llvm::StringSwitch<clang::CastKind>(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+ .Default(CK_Invalid);
+ }
+
+public:
+ static bool is(const VariantValue &Value) {
+ return Value.isString() &&
+ getCastKind(Value.getString()) != CK_Invalid;
+ }
+ static clang::CastKind get(const VariantValue &Value) {
+ return getCastKind(Value.getString());
+ }
+ static ArgKind getKind() {
+ return ArgKind(ArgKind::AK_String);
+ }
+};
+
/// \brief Matcher descriptor interface.
///
/// Provides a \c create() method that constructs the matcher from the provided
@@ -234,7 +255,7 @@ static VariantMatcher outvalueToVariantMatcher(const DynTypedMatcher &Matcher) {
template <typename T>
static VariantMatcher outvalueToVariantMatcher(const T &PolyMatcher,
typename T::ReturnTypes * =
- NULL) {
+ nullptr) {
std::vector<DynTypedMatcher> Matchers;
mergePolyMatchers(PolyMatcher, Matchers, typename T::ReturnTypes());
VariantMatcher Out = VariantMatcher::PolymorphicMatcher(std::move(Matchers));
@@ -326,8 +347,9 @@ public:
template <typename ResultT, typename ArgT,
ResultT (*F)(ArrayRef<const ArgT *>)>
- VariadicFuncMatcherDescriptor(llvm::VariadicFunction<ResultT, ArgT, F> Func,
- StringRef MatcherName)
+ VariadicFuncMatcherDescriptor(
+ ast_matchers::internal::VariadicFunction<ResultT, ArgT, F> Func,
+ StringRef MatcherName)
: Func(&variadicMatcherDescriptor<ResultT, ArgT, F>),
MatcherName(MatcherName.str()),
ArgsKind(ArgTypeTraits<ArgT>::getKind()) {
@@ -410,7 +432,6 @@ private:
return VariantMatcher(); \
}
-
/// \brief 0-arg marshaller function.
template <typename ReturnType>
static VariantMatcher matcherMarshall0(void (*Func)(), StringRef MatcherName,
@@ -657,9 +678,9 @@ MatcherDescriptor *makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1, ArgType2
/// \brief Variadic overload.
template <typename ResultT, typename ArgT,
ResultT (*Func)(ArrayRef<const ArgT *>)>
-MatcherDescriptor *
-makeMatcherAutoMarshall(llvm::VariadicFunction<ResultT, ArgT, Func> VarFunc,
- StringRef MatcherName) {
+MatcherDescriptor *makeMatcherAutoMarshall(
+ ast_matchers::internal::VariadicFunction<ResultT, ArgT, Func> VarFunc,
+ StringRef MatcherName) {
return new VariadicFuncMatcherDescriptor(VarFunc, MatcherName);
}
@@ -708,9 +729,9 @@ makeMatcherAutoMarshall(ast_matchers::internal::VariadicOperatorMatcherFunc<
MatcherName);
}
-} // namespace internal
-} // namespace dynamic
-} // namespace ast_matchers
-} // namespace clang
+} // namespace internal
+} // namespace dynamic
+} // namespace ast_matchers
+} // namespace clang
-#endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_MARSHALLERS_H
+#endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_MARSHALLERS_H