19#ifndef LLVM_CLANG_LIB_ASTMATCHERS_DYNAMIC_MARSHALLERS_H
20#define LLVM_CLANG_LIB_ASTMATCHERS_DYNAMIC_MARSHALLERS_H
31#include "llvm/ADT/ArrayRef.h"
32#include "llvm/ADT/STLExtras.h"
33#include "llvm/ADT/StringRef.h"
34#include "llvm/ADT/StringSwitch.h"
35#include "llvm/ADT/Twine.h"
36#include "llvm/Support/Regex.h"
48namespace ast_matchers {
61 return Value.isString();
66 return Value.getString();
82template <
class T>
struct ArgTypeTraits<ast_matchers::internal::Matcher<T>> {
84 return Value.isMatcher();
87 return Value.getMatcher().hasTypedMatcher<
T>();
91 return Value.getMatcher().getTypedMatcher<
T>();
105 return Value.isBoolean();
110 return Value.getBoolean();
124 return Value.isDouble();
129 return Value.getDouble();
143 return Value.isUnsigned();
148 return Value.getUnsigned();
162 static std::optional<attr::Kind> getAttrKind(llvm::StringRef AttrKind) {
163 if (!AttrKind.consume_front(
"attr::"))
165 return llvm::StringSwitch<std::optional<attr::Kind>>(AttrKind)
166#define
ATTR(
X) .Case(#
X, attr::X)
167#include "clang/Basic/AttrList.inc"
168 .Default(std::nullopt);
173 return Value.isString();
176 return getAttrKind(
Value.getString()).has_value();
180 return *getAttrKind(
Value.getString());
192 static std::optional<CastKind> getCastKind(llvm::StringRef AttrKind) {
193 if (!AttrKind.consume_front(
"CK_"))
195 return llvm::StringSwitch<std::optional<CastKind>>(AttrKind)
197#include "clang/AST/OperationKinds.def"
198 .Default(std::nullopt);
203 return Value.isString();
206 return getCastKind(
Value.getString()).has_value();
210 return *getCastKind(
Value.getString());
222 static std::optional<llvm::Regex::RegexFlags> getFlags(llvm::StringRef Flags);
226 return Value.isString();
229 return getFlags(
Value.getString()).has_value();
233 return *getFlags(
Value.getString());
243 static std::optional<OpenMPClauseKind>
244 getClauseKind(llvm::StringRef ClauseKind) {
245 return llvm::StringSwitch<std::optional<OpenMPClauseKind>>(ClauseKind)
248#include "llvm/Frontend/OpenMP/OMP.inc"
249 .Default(std::nullopt);
254 return Value.isString();
257 return getClauseKind(
Value.getString()).has_value();
261 return *getClauseKind(
Value.getString());
271 static std::optional<UnaryExprOrTypeTrait>
272 getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
273 if (!ClauseKind.consume_front(
"UETT_"))
275 return llvm::StringSwitch<std::optional<UnaryExprOrTypeTrait>>(ClauseKind)
277#define CXX11_UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) \
278 .Case(#Name, UETT_##Name)
279#include "clang/Basic/TokenKinds.def"
280 .Default(std::nullopt);
285 return Value.isString();
288 return getUnaryOrTypeTraitKind(
Value.getString()).has_value();
292 return *getUnaryOrTypeTraitKind(
Value.getString());
316 virtual std::unique_ptr<MatcherDescriptor>
334 std::vector<ArgKind> &ArgKinds)
const = 0;
345 ASTNodeKind *LeastDerivedKind =
nullptr)
const = 0;
358 if (LeastDerivedKind)
359 *LeastDerivedKind = NodeKind;
375 StringRef MatcherName,
387 StringRef MatcherName,
390 : Marshaller(Marshaller), Func(Func), MatcherName(MatcherName),
391 RetKinds(RetKinds.begin(), RetKinds.end()),
392 ArgKinds(ArgKinds.begin(), ArgKinds.end()) {}
397 return Marshaller(Func, MatcherName, NameRange, Args, Error);
401 unsigned getNumArgs()
const override {
return ArgKinds.size(); }
404 std::vector<ArgKind> &Kinds)
const override {
405 Kinds.push_back(ArgKinds[ArgNo]);
416 void (*
const Func)();
417 const std::string MatcherName;
418 const std::vector<ASTNodeKind> RetKinds;
419 const std::vector<ArgKind> ArgKinds;
424template <
class PolyMatcher>
426 std::vector<DynTypedMatcher> &Out,
427 ast_matchers::internal::EmptyTypeList) {}
429template <
class PolyMatcher,
class TypeList>
431 std::vector<DynTypedMatcher> &Out, TypeList) {
432 Out.push_back(ast_matchers::internal::Matcher<typename TypeList::head>(Poly));
448 typename T::ReturnTypes * =
450 std::vector<DynTypedMatcher> Matchers;
459 RetTypes.push_back(ASTNodeKind::getFromNodeKind<typename T::head>());
460 buildReturnTypeVectorFromTypeList<typename T::tail>(RetTypes);
466 std::vector<ASTNodeKind> &RetTypes) {}
470 static void build(std::vector<ASTNodeKind> &RetTypes) {
471 buildReturnTypeVectorFromTypeList<typename T::ReturnTypes>(RetTypes);
477 static void build(std::vector<ASTNodeKind> &RetTypes) {
478 RetTypes.push_back(ASTNodeKind::getFromNodeKind<T>());
484 static void build(std::vector<ASTNodeKind> &RetTypes) {
485 RetTypes.push_back(ASTNodeKind::getFromNodeKind<T>());
490template <
typename ResultT,
typename ArgT,
496 InnerArgsPtr.resize_for_overwrite(Args.size());
498 InnerArgs.reserve(Args.size());
500 for (
size_t i = 0, e = Args.size(); i != e; ++i) {
505 if (!ArgTraits::hasCorrectType(
Value)) {
506 Error->addError(Arg.
Range, Error->ET_RegistryWrongArgType)
507 << (i + 1) << ArgTraits::getKind().asString() <<
Value.getTypeAsString();
510 if (!ArgTraits::hasCorrectValue(
Value)) {
511 if (std::optional<std::string> BestGuess =
512 ArgTraits::getBestGuess(
Value)) {
513 Error->addError(Arg.
Range, Error->ET_RegistryUnknownEnumWithReplace)
514 << i + 1 <<
Value.getString() << *BestGuess;
515 }
else if (
Value.isString()) {
516 Error->addError(Arg.
Range, Error->ET_RegistryValueNotFound)
517 <<
Value.getString();
521 Error->addError(Arg.
Range, Error->ET_RegistryWrongArgType)
522 << (i + 1) << ArgTraits::getKind().asString()
523 <<
Value.getTypeAsString();
527 assert(InnerArgs.size() < InnerArgs.capacity());
528 InnerArgs.emplace_back(ArgTraits::get(
Value));
529 InnerArgsPtr[i] = &InnerArgs[i];
548 template <
typename ResultT,
typename ArgT,
551 ast_matchers::internal::VariadicFunction<ResultT, ArgT, F>
Func,
552 StringRef MatcherName)
553 :
Func(&variadicMatcherDescriptor<ResultT, ArgT, F>),
554 MatcherName(MatcherName.str()),
562 return Func(MatcherName, NameRange, Args, Error);
569 std::vector<ArgKind> &Kinds)
const override {
570 Kinds.push_back(ArgsKind);
583 const std::string MatcherName;
584 std::vector<ASTNodeKind> RetKinds;
591 template <
typename BaseT,
typename DerivedT>
593 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT>
Func,
594 StringRef MatcherName)
596 DerivedKind(
ASTNodeKind::getFromNodeKind<DerivedT>()) {}
606 if (
Kind.isSame(DerivedKind) || !
Kind.isBaseOf(DerivedKind)) {
623#define CHECK_ARG_COUNT(count) \
624 if (Args.size() != count) { \
625 Error->addError(NameRange, Error->ET_RegistryWrongArgCount) \
626 << count << Args.size(); \
627 return VariantMatcher(); \
630#define CHECK_ARG_TYPE(index, type) \
631 if (!ArgTypeTraits<type>::hasCorrectType(Args[index].Value)) { \
632 Error->addError(Args[index].Range, Error->ET_RegistryWrongArgType) \
633 << (index + 1) << ArgTypeTraits<type>::getKind().asString() \
634 << Args[index].Value.getTypeAsString(); \
635 return VariantMatcher(); \
637 if (!ArgTypeTraits<type>::hasCorrectValue(Args[index].Value)) { \
638 if (std::optional<std::string> BestGuess = \
639 ArgTypeTraits<type>::getBestGuess(Args[index].Value)) { \
640 Error->addError(Args[index].Range, \
641 Error->ET_RegistryUnknownEnumWithReplace) \
642 << index + 1 << Args[index].Value.getString() << *BestGuess; \
643 } else if (Args[index].Value.isString()) { \
644 Error->addError(Args[index].Range, Error->ET_RegistryValueNotFound) \
645 << Args[index].Value.getString(); \
647 return VariantMatcher(); \
651template <
typename ReturnType>
656 using FuncType = ReturnType (*)();
662template <
typename ReturnType,
typename ArgType1>
667 using FuncType = ReturnType (*)(ArgType1);
675template <
typename ReturnType,
typename ArgType1,
typename ArgType2>
680 using FuncType = ReturnType (*)(ArgType1, ArgType2);
689#undef CHECK_ARG_COUNT
694template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
695 typename FromTypes,
typename ToTypes>
699 StringRef Name, std::vector<std::unique_ptr<MatcherDescriptor>> &Out)
700 : Name(Name), Out(Out) {
701 collect(FromTypes());
705 using AdaptativeFunc = ast_matchers::internal::ArgumentAdaptingMatcherFunc<
706 ArgumentAdapterT, FromTypes, ToTypes>;
709 static void collect(ast_matchers::internal::EmptyTypeList) {}
713 template <
typename FromTypeList>
714 inline void collect(FromTypeList);
717 std::vector<std::unique_ptr<MatcherDescriptor>> &Out;
729 : Overloads(
std::make_move_iterator(Callbacks.begin()),
730 std::make_move_iterator(Callbacks.end())) {}
737 std::vector<VariantMatcher> Constructed;
739 for (
const auto &O : Overloads) {
741 if (!SubMatcher.
isNull()) {
742 Constructed.push_back(SubMatcher);
749 if (Constructed.size() > 1) {
751 Error->addError(NameRange, Error->ET_RegistryAmbiguousOverload);
754 return Constructed[0];
758 bool Overload0Variadic = Overloads[0]->isVariadic();
760 for (
const auto &O : Overloads) {
761 assert(Overload0Variadic == O->isVariadic());
764 return Overload0Variadic;
768 unsigned Overload0NumArgs = Overloads[0]->getNumArgs();
770 for (
const auto &O : Overloads) {
771 assert(Overload0NumArgs == O->getNumArgs());
774 return Overload0NumArgs;
778 std::vector<ArgKind> &Kinds)
const override {
779 for (
const auto &O : Overloads) {
780 if (O->isConvertibleTo(ThisKind))
781 O->getArgKinds(ThisKind, ArgNo, Kinds);
787 for (
const auto &O : Overloads) {
788 if (O->isConvertibleTo(
Kind, Specificity, LeastDerivedKind))
795 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
798template <
typename ReturnType>
802 llvm::Regex::RegexFlags),
803 ReturnType (*NoFlags)(StringRef),
805 : WithFlags(WithFlags), NoFlags(NoFlags),
806 RetKinds(RetKinds.begin(), RetKinds.end()) {}
811 std::vector<ArgKind> &Kinds)
const override {
824 if (Args.size() < 1 || Args.size() > 2) {
826 <<
"1 or 2" << Args.size();
830 Error->addError(Args[0].
Range, Error->ET_RegistryWrongArgType)
832 << Args[0].Value.getTypeAsString();
835 if (Args.size() == 1) {
841 Error->addError(Args[1].
Range, Error->ET_RegistryWrongArgType)
843 << Args[1].Value.getTypeAsString();
848 if (std::optional<std::string> BestGuess =
851 Error->addError(Args[1].
Range, Error->ET_RegistryUnknownEnumWithReplace)
852 << 2 << Args[1].Value.getString() << *BestGuess;
854 Error->addError(Args[1].
Range, Error->ET_RegistryValueNotFound)
855 << Args[1].Value.getString();
865 ReturnType (*
const WithFlags)(StringRef, llvm::Regex::RegexFlags);
866 ReturnType (*
const NoFlags)(StringRef);
867 const std::vector<ASTNodeKind> RetKinds;
873 using VarOp = DynTypedMatcher::VariadicOperator;
876 VarOp Op, StringRef MatcherName)
877 : MinCount(MinCount), MaxCount(MaxCount), Op(Op),
878 MatcherName(MatcherName) {}
883 if (Args.size() < MinCount || MaxCount < Args.size()) {
884 const std::string MaxStr =
885 (MaxCount == std::numeric_limits<unsigned>::max() ?
""
888 Error->addError(NameRange, Error->ET_RegistryWrongArgCount)
889 << (
"(" + Twine(MinCount) +
", " + MaxStr +
")") << Args.size();
893 std::vector<VariantMatcher> InnerArgs;
894 for (
size_t i = 0, e = Args.size(); i != e; ++i) {
897 if (!
Value.isMatcher()) {
898 Error->addError(Arg.
Range, Error->ET_RegistryWrongArgType)
899 << (i + 1) <<
"Matcher<>" <<
Value.getTypeAsString();
902 InnerArgs.push_back(
Value.getMatcher());
911 std::vector<ArgKind> &Kinds)
const override {
919 if (LeastDerivedKind)
920 *LeastDerivedKind =
Kind;
927 const unsigned MinCount;
928 const unsigned MaxCount;
930 const StringRef MatcherName;
935 std::vector<ASTNodeKind> NodeKinds;
939 std::vector<ASTNodeKind> NodeKinds)
940 : CladeNodeKind(CladeNodeKind), NodeKinds(
std::move(NodeKinds)) {}
945 std::vector<DynTypedMatcher> NodeArgs;
947 for (
auto NK : NodeKinds) {
948 std::vector<DynTypedMatcher> InnerArgs;
950 for (
const auto &Arg : Args) {
951 if (!Arg.Value.isMatcher())
956 InnerArgs.push_back(DM);
960 if (InnerArgs.empty()) {
962 DynTypedMatcher::trueMatcher(NK).dynCastTo(CladeNodeKind));
965 DynTypedMatcher::constructVariadic(
966 ast_matchers::internal::DynTypedMatcher::VO_AllOf, NK,
968 .dynCastTo(CladeNodeKind));
972 auto Result = DynTypedMatcher::constructVariadic(
973 ast_matchers::internal::DynTypedMatcher::VO_AnyOf, CladeNodeKind,
975 Result.setAllowBind(
true);
983 std::vector<ArgKind> &Kinds)
const override {
991 if (LeastDerivedKind)
992 *LeastDerivedKind = CladeNodeKind;
1006 std::unique_ptr<MatcherDescriptor>
1010 std::vector<ASTNodeKind> NodeKinds;
1011 for (
const auto &Arg : Args) {
1012 if (!Arg.Value.isNodeKind())
1014 NodeKinds.push_back(Arg.Value.getNodeKind());
1017 if (NodeKinds.empty())
1022 for (
auto NK : NodeKinds)
1024 if (!NK.getCladeKind().isSame(CladeNodeKind))
1028 return std::make_unique<MapAnyOfMatcherDescriptor>(CladeNodeKind,
1029 std::move(NodeKinds));
1037 std::vector<ArgKind> &ArgKinds)
const override {
1041 ASTNodeKind *LeastDerivedKind =
nullptr)
const override {
1044 if (LeastDerivedKind)
1045 *LeastDerivedKind =
Kind;
1056template <
typename ReturnType>
1057std::unique_ptr<MatcherDescriptor>
1059 std::vector<ASTNodeKind> RetTypes;
1061 return std::make_unique<FixedArgCountMatcherDescriptor>(
1062 matcherMarshall0<ReturnType>,
reinterpret_cast<void (*)()
>(
Func),
1063 MatcherName, RetTypes, std::nullopt);
1067template <
typename ReturnType,
typename ArgType1>
1068std::unique_ptr<MatcherDescriptor>
1070 std::vector<ASTNodeKind> RetTypes;
1073 return std::make_unique<FixedArgCountMatcherDescriptor>(
1074 matcherMarshall1<ReturnType, ArgType1>,
1075 reinterpret_cast<void (*)()
>(
Func), MatcherName, RetTypes, AK);
1079template <
typename ReturnType,
typename ArgType1,
typename ArgType2>
1080std::unique_ptr<MatcherDescriptor>
1082 StringRef MatcherName) {
1083 std::vector<ASTNodeKind> RetTypes;
1087 return std::make_unique<FixedArgCountMatcherDescriptor>(
1088 matcherMarshall2<ReturnType, ArgType1, ArgType2>,
1089 reinterpret_cast<void (*)()
>(
Func), MatcherName, RetTypes, AKs);
1092template <
typename ReturnType>
1094 ReturnType (*FuncFlags)(llvm::StringRef, llvm::Regex::RegexFlags),
1095 ReturnType (*
Func)(llvm::StringRef)) {
1096 std::vector<ASTNodeKind> RetTypes;
1098 return std::make_unique<RegexMatcherDescriptor<ReturnType>>(FuncFlags,
Func,
1103template <
typename ResultT,
typename ArgT,
1106 ast_matchers::internal::VariadicFunction<ResultT, ArgT, Func> VarFunc,
1107 StringRef MatcherName) {
1108 return std::make_unique<VariadicFuncMatcherDescriptor>(VarFunc, MatcherName);
1115template <
typename BaseT,
typename DerivedT>
1117 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT>
1119 StringRef MatcherName) {
1120 return std::make_unique<DynCastAllOfMatcherDescriptor>(VarFunc, MatcherName);
1124template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
1125 typename FromTypes,
typename ToTypes>
1127 ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
1128 FromTypes, ToTypes>,
1129 StringRef MatcherName) {
1130 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
1133 return std::make_unique<OverloadedMatcherDescriptor>(Overloads);
1136template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
1137 typename FromTypes,
typename ToTypes>
1138template <
typename FromTypeList>
1139inline void AdaptativeOverloadCollector<ArgumentAdapterT, FromTypes,
1140 ToTypes>::collect(FromTypeList) {
1142 &AdaptativeFunc::template create<typename FromTypeList::head>, Name));
1143 collect(
typename FromTypeList::tail());
1147template <
unsigned MinCount,
unsigned MaxCount>
1149 ast_matchers::internal::VariadicOperatorMatcherFunc<MinCount, MaxCount>
1151 StringRef MatcherName) {
1152 return std::make_unique<VariadicOperatorMatcherDescriptor>(
1153 MinCount, MaxCount,
Func.Op, MatcherName);
1156template <
typename CladeType,
typename... MatcherT>
1158 ast_matchers::internal::MapAnyOfMatcherImpl<CladeType, MatcherT...>,
1159 StringRef MatcherName) {
1160 return std::make_unique<MapAnyOfMatcherDescriptor>(
1161 ASTNodeKind::getFromNodeKind<CladeType>(),
1162 std::vector<ASTNodeKind>{ASTNodeKind::getFromNodeKind<MatcherT>()...});
#define GEN_CLANG_CLAUSE_CLASS
#define CLAUSE_CLASS(Enum, Str, Class)
Defines the clang::attr::Kind enum.
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
Diagnostics class to manage error messages.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static std::optional< std::string > getBestGuess(llvm::StringRef Search, llvm::ArrayRef< llvm::StringRef > Allowed, llvm::StringRef DropPrefix="", unsigned MaxEditDistance=3)
#define CHECK_ARG_COUNT(count)
Helper macros to check the arguments on all marshaller functions.
#define CHECK_ARG_TYPE(index, type)
Defines some OpenMP-specific enums and functions.
#define CAST_OPERATION(Name)
Defines enumerations for the type traits support.
#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key)
ASTNodeKind getCladeKind() const
static ArgKind MakeMatcherArg(ASTNodeKind MatcherKind)
Constructor for matcher types.
static ArgKind MakeNodeArg(ASTNodeKind MatcherKind)
Helper class to manage error messages.
@ ET_RegistryWrongArgCount
A variant matcher object.
ast_matchers::internal::Matcher< T > getTypedMatcher() const
Return this matcher as a Matcher<T>.
static VariantMatcher PolymorphicMatcher(std::vector< DynTypedMatcher > Matchers)
Clones the provided matchers.
bool hasTypedMatcher() const
Determines if the contained matcher can be converted to Matcher<T>.
bool isNull() const
Whether the matcher is null.
static VariantMatcher VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op, std::vector< VariantMatcher > Args)
Creates a 'variadic' operator matcher.
static VariantMatcher SingleMatcher(const DynTypedMatcher &Matcher)
Clones the provided matcher.
Helper class used to collect all the possible overloads of an argument adaptative matcher function.
AdaptativeOverloadCollector(StringRef Name, std::vector< std::unique_ptr< MatcherDescriptor > > &Out)
Return CK_Trivial when appropriate for VariadicDynCastAllOfMatchers.
DynCastAllOfMatcherDescriptor(ast_matchers::internal::VariadicDynCastAllOfMatcher< BaseT, DerivedT > Func, StringRef MatcherName)
ASTNodeKind nodeMatcherType() const override
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
Simple callback implementation.
VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const override
void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, std::vector< ArgKind > &Kinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
VariantMatcher(*)(void(*Func)(), StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) MarshallerType
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
bool isVariadic() const override
Returns whether the matcher is variadic.
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
FixedArgCountMatcherDescriptor(MarshallerType Marshaller, void(*Func)(), StringRef MatcherName, ArrayRef< ASTNodeKind > RetKinds, ArrayRef< ArgKind > ArgKinds)
bool isVariadic() const override
Returns whether the matcher is variadic.
VariantMatcher create(SourceRange, ArrayRef< ParserValue >, Diagnostics *) const override
std::unique_ptr< MatcherDescriptor > buildMatcherCtor(SourceRange, ArrayRef< ParserValue > Args, Diagnostics *) const override
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
bool isPolymorphic() const override
Returns whether the matcher will, given a matcher of any type T, yield a matcher of type T.
bool isBuilderMatcher() const override
void getArgKinds(ASTNodeKind ThisKind, unsigned, std::vector< ArgKind > &ArgKinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity=nullptr, ASTNodeKind *LeastDerivedKind=nullptr) const override
Returns whether this matcher is convertible to the given type.
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
bool isVariadic() const override
Returns whether the matcher is variadic.
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
MapAnyOfMatcherDescriptor(ASTNodeKind CladeNodeKind, std::vector< ASTNodeKind > NodeKinds)
void getArgKinds(ASTNodeKind ThisKind, unsigned, std::vector< ArgKind > &Kinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const override
Matcher descriptor interface.
virtual bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity=nullptr, ASTNodeKind *LeastDerivedKind=nullptr) const =0
Returns whether this matcher is convertible to the given type.
virtual bool isBuilderMatcher() const
virtual void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, std::vector< ArgKind > &ArgKinds) const =0
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
virtual bool isPolymorphic() const
Returns whether the matcher will, given a matcher of any type T, yield a matcher of type T.
virtual std::unique_ptr< MatcherDescriptor > buildMatcherCtor(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const
virtual bool isVariadic() const =0
Returns whether the matcher is variadic.
virtual ASTNodeKind nodeMatcherType() const
virtual unsigned getNumArgs() const =0
Returns the number of arguments accepted by the matcher if not variadic.
virtual VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const =0
virtual ~MatcherDescriptor()=default
MatcherDescriptor that wraps multiple "overloads" of the same matcher.
VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const override
void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, std::vector< ArgKind > &Kinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
bool isVariadic() const override
Returns whether the matcher is variadic.
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
OverloadedMatcherDescriptor(MutableArrayRef< std::unique_ptr< MatcherDescriptor > > Callbacks)
~OverloadedMatcherDescriptor() override=default
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
RegexMatcherDescriptor(ReturnType(*WithFlags)(StringRef, llvm::Regex::RegexFlags), ReturnType(*NoFlags)(StringRef), ArrayRef< ASTNodeKind > RetKinds)
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const override
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
bool isVariadic() const override
Returns whether the matcher is variadic.
void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, std::vector< ArgKind > &Kinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
Matcher descriptor for variadic functions.
void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, std::vector< ArgKind > &Kinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
ASTNodeKind nodeMatcherType() const override
VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const override
VariantMatcher(*)(StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) RunFunc
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
bool isVariadic() const override
Returns whether the matcher is variadic.
VariadicFuncMatcherDescriptor(ast_matchers::internal::VariadicFunction< ResultT, ArgT, F > Func, StringRef MatcherName)
Variadic operator marshaller function.
DynTypedMatcher::VariadicOperator VarOp
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
bool isVariadic() const override
Returns whether the matcher is variadic.
VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const override
bool isPolymorphic() const override
Returns whether the matcher will, given a matcher of any type T, yield a matcher of type T.
void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, std::vector< ArgKind > &Kinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
VariadicOperatorMatcherDescriptor(unsigned MinCount, unsigned MaxCount, VarOp Op, StringRef MatcherName)
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
static VariantMatcher matcherMarshall2(void(*Func)(), StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error)
2-arg marshaller function.
VariantMatcher outvalueToVariantMatcher(const DynTypedMatcher &Matcher)
Convert the return values of the functions into a VariantMatcher.
VariantMatcher variadicMatcherDescriptor(StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error)
Variadic marshaller function.
static void mergePolyMatchers(const PolyMatcher &Poly, std::vector< DynTypedMatcher > &Out, ast_matchers::internal::EmptyTypeList)
Helper methods to extract and merge all possible typed matchers out of the polymorphic object.
std::unique_ptr< MatcherDescriptor > makeMatcherRegexMarshall(ReturnType(*FuncFlags)(llvm::StringRef, llvm::Regex::RegexFlags), ReturnType(*Func)(llvm::StringRef))
static VariantMatcher matcherMarshall0(void(*Func)(), StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error)
0-arg marshaller function.
bool isRetKindConvertibleTo(ArrayRef< ASTNodeKind > RetKinds, ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind)
std::unique_ptr< MatcherDescriptor > makeMatcherAutoMarshall(ReturnType(*Func)(), StringRef MatcherName)
Helper functions to select the appropriate marshaller functions.
static VariantMatcher matcherMarshall1(void(*Func)(), StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error)
1-arg marshaller function.
void buildReturnTypeVectorFromTypeList< ast_matchers::internal::EmptyTypeList >(std::vector< ASTNodeKind > &RetTypes)
void buildReturnTypeVectorFromTypeList(std::vector< ASTNodeKind > &RetTypes)
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
The JSON file list parser is used to communicate input to InstallAPI.
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ Result
The result type of a method or function.
CastKind
CastKind - The kind of operation required for a conversion.
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Diagnostic wrappers for TextAPI types for error reporting.
Context for overloaded matcher construction.
void revertErrors()
Revert all errors that happened within this context.
A VariantValue instance annotated with its parser context.
static bool hasCorrectValue(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &Value)
static CastKind get(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static OpenMPClauseKind get(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static UnaryExprOrTypeTrait get(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static ast_matchers::internal::Matcher< T > get(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &)
static bool hasCorrectType(const VariantValue &Value)
static attr::Kind get(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static bool get(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &)
static bool hasCorrectType(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &)
static double get(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static llvm::Regex::RegexFlags get(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static const std::string & get(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &)
static std::optional< std::string > getBestGuess(const VariantValue &)
static bool hasCorrectType(const VariantValue &Value)
static unsigned get(const VariantValue &Value)
static bool hasCorrectValue(const VariantValue &Value)
Helper template class to just from argument type to the right is/get functions in VariantValue.
static void build(std::vector< ASTNodeKind > &RetTypes)
static void build(std::vector< ASTNodeKind > &RetTypes)
static void build(std::vector< ASTNodeKind > &RetTypes)