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"
61 return Value.isString();
66 return Value.getString();
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 * =
nullptr) {
449 std::vector<DynTypedMatcher> Matchers;
465 std::vector<ASTNodeKind> &RetTypes) {}
469 static void build(std::vector<ASTNodeKind> &RetTypes) {
476 static void build(std::vector<ASTNodeKind> &RetTypes) {
483 static void build(std::vector<ASTNodeKind> &RetTypes) {
489template <
typename ResultT,
typename ArgT,
495 InnerArgsPtr.resize_for_overwrite(Args.size());
497 InnerArgs.reserve(Args.size());
499 for (
size_t i = 0, e = Args.size(); i != e; ++i) {
504 if (!ArgTraits::hasCorrectType(
Value)) {
506 << (i + 1) << ArgTraits::getKind().asString() <<
Value.getTypeAsString();
509 if (!ArgTraits::hasCorrectValue(
Value)) {
510 if (std::optional<std::string> BestGuess =
511 ArgTraits::getBestGuess(
Value)) {
513 << i + 1 <<
Value.getString() << *BestGuess;
514 }
else if (
Value.isString()) {
516 <<
Value.getString();
521 << (i + 1) << ArgTraits::getKind().asString()
522 <<
Value.getTypeAsString();
526 assert(InnerArgs.size() < InnerArgs.capacity());
527 InnerArgs.emplace_back(ArgTraits::get(
Value));
528 InnerArgsPtr[i] = &InnerArgs[i];
547 template <
typename ResultT,
typename ArgT,
550 ast_matchers::internal::VariadicFunction<ResultT, ArgT, F> Func,
551 StringRef MatcherName)
553 MatcherName(MatcherName.str()),
561 return Func(MatcherName, NameRange, Args,
Error);
568 std::vector<ArgKind> &Kinds)
const override {
569 Kinds.push_back(ArgsKind);
582 const std::string MatcherName;
583 std::vector<ASTNodeKind> RetKinds;
590 template <
typename BaseT,
typename DerivedT>
592 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT> Func,
593 StringRef MatcherName)
595 DerivedKind(
ASTNodeKind::getFromNodeKind<DerivedT>()) {}
605 if (Kind.isSame(DerivedKind) || !Kind.isBaseOf(DerivedKind)) {
622#define CHECK_ARG_COUNT(count) \
623 if (Args.size() != count) { \
624 Error->addError(NameRange, Error->ET_RegistryWrongArgCount) \
625 << count << Args.size(); \
626 return VariantMatcher(); \
629#define CHECK_ARG_TYPE(index, type) \
630 if (!ArgTypeTraits<type>::hasCorrectType(Args[index].Value)) { \
631 Error->addError(Args[index].Range, Error->ET_RegistryWrongArgType) \
632 << (index + 1) << ArgTypeTraits<type>::getKind().asString() \
633 << Args[index].Value.getTypeAsString(); \
634 return VariantMatcher(); \
636 if (!ArgTypeTraits<type>::hasCorrectValue(Args[index].Value)) { \
637 if (std::optional<std::string> BestGuess = \
638 ArgTypeTraits<type>::getBestGuess(Args[index].Value)) { \
639 Error->addError(Args[index].Range, \
640 Error->ET_RegistryUnknownEnumWithReplace) \
641 << index + 1 << Args[index].Value.getString() << *BestGuess; \
642 } else if (Args[index].Value.isString()) { \
643 Error->addError(Args[index].Range, Error->ET_RegistryValueNotFound) \
644 << Args[index].Value.getString(); \
646 return VariantMatcher(); \
650template <
typename ReturnType>
654 using FuncType = ReturnType (*)();
660template <
typename ReturnType,
typename ArgType1>
664 using FuncType = ReturnType (*)(ArgType1);
672template <
typename ReturnType,
typename ArgType1,
typename ArgType2>
676 using FuncType = ReturnType (*)(ArgType1, ArgType2);
685#undef CHECK_ARG_COUNT
690template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
691 typename FromTypes,
typename ToTypes>
695 StringRef Name, std::vector<std::unique_ptr<MatcherDescriptor>> &Out)
696 : Name(Name), Out(Out) {
697 collect(FromTypes());
701 using AdaptativeFunc = ast_matchers::internal::ArgumentAdaptingMatcherFunc<
702 ArgumentAdapterT, FromTypes, ToTypes>;
705 static void collect(ast_matchers::internal::EmptyTypeList) {}
709 template <
typename FromTypeList>
710 inline void collect(FromTypeList);
713 std::vector<std::unique_ptr<MatcherDescriptor>> &Out;
725 : Overloads(
std::make_move_iterator(Callbacks.begin()),
726 std::make_move_iterator(Callbacks.end())) {}
733 std::vector<VariantMatcher> Constructed;
735 for (
const auto &O : Overloads) {
737 if (!SubMatcher.
isNull()) {
738 Constructed.push_back(SubMatcher);
745 if (Constructed.size() > 1) {
747 Error->addError(NameRange,
Error->ET_RegistryAmbiguousOverload);
750 return Constructed[0];
754 bool Overload0Variadic = Overloads[0]->isVariadic();
756 for (
const auto &O : Overloads) {
757 assert(Overload0Variadic == O->isVariadic());
760 return Overload0Variadic;
764 unsigned Overload0NumArgs = Overloads[0]->getNumArgs();
766 for (
const auto &O : Overloads) {
767 assert(Overload0NumArgs == O->getNumArgs());
770 return Overload0NumArgs;
774 std::vector<ArgKind> &Kinds)
const override {
775 for (
const auto &O : Overloads) {
776 if (O->isConvertibleTo(ThisKind))
777 O->getArgKinds(ThisKind, ArgNo, Kinds);
783 for (
const auto &O : Overloads) {
784 if (O->isConvertibleTo(Kind, Specificity, LeastDerivedKind))
791 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
794template <
typename ReturnType>
798 llvm::Regex::RegexFlags),
799 ReturnType (*NoFlags)(StringRef),
801 : WithFlags(WithFlags), NoFlags(NoFlags),
802 RetKinds(RetKinds.begin(), RetKinds.end()) {}
807 std::vector<ArgKind> &Kinds)
const override {
820 if (Args.size() < 1 || Args.size() > 2) {
822 <<
"1 or 2" << Args.size();
826 Error->addError(Args[0].Range,
Error->ET_RegistryWrongArgType)
828 << Args[0].Value.getTypeAsString();
831 if (Args.size() == 1) {
837 Error->addError(Args[1].Range,
Error->ET_RegistryWrongArgType)
839 << Args[1].Value.getTypeAsString();
844 if (std::optional<std::string> BestGuess =
847 Error->addError(Args[1].Range,
Error->ET_RegistryUnknownEnumWithReplace)
848 << 2 << Args[1].Value.getString() << *BestGuess;
850 Error->addError(Args[1].Range,
Error->ET_RegistryValueNotFound)
851 << Args[1].Value.getString();
861 ReturnType (*
const WithFlags)(StringRef, llvm::Regex::RegexFlags);
862 ReturnType (*
const NoFlags)(StringRef);
863 const std::vector<ASTNodeKind> RetKinds;
869 using VarOp = DynTypedMatcher::VariadicOperator;
872 VarOp Op, StringRef MatcherName)
873 : MinCount(MinCount), MaxCount(MaxCount), Op(Op),
874 MatcherName(MatcherName) {}
879 if (Args.size() < MinCount || MaxCount < Args.size()) {
880 const std::string MaxStr =
881 (MaxCount == std::numeric_limits<unsigned>::max() ?
""
884 Error->addError(NameRange,
Error->ET_RegistryWrongArgCount)
885 << (
"(" + Twine(MinCount) +
", " + MaxStr +
")") << Args.size();
889 std::vector<VariantMatcher> InnerArgs;
890 for (
size_t i = 0, e = Args.size(); i != e; ++i) {
893 if (!
Value.isMatcher()) {
895 << (i + 1) <<
"Matcher<>" <<
Value.getTypeAsString();
898 InnerArgs.push_back(
Value.getMatcher());
907 std::vector<ArgKind> &Kinds)
const override {
915 if (LeastDerivedKind)
916 *LeastDerivedKind = Kind;
923 const unsigned MinCount;
924 const unsigned MaxCount;
926 const StringRef MatcherName;
931 std::vector<ASTNodeKind> NodeKinds;
935 std::vector<ASTNodeKind> NodeKinds)
936 : CladeNodeKind(CladeNodeKind), NodeKinds(
std::move(NodeKinds)) {}
941 std::vector<DynTypedMatcher> NodeArgs;
943 for (
auto NK : NodeKinds) {
944 std::vector<DynTypedMatcher> InnerArgs;
946 for (
const auto &Arg : Args) {
947 if (!Arg.Value.isMatcher())
952 InnerArgs.push_back(DM);
956 if (InnerArgs.empty()) {
958 DynTypedMatcher::trueMatcher(NK).dynCastTo(CladeNodeKind));
961 DynTypedMatcher::constructVariadic(
962 ast_matchers::internal::DynTypedMatcher::VO_AllOf, NK,
964 .dynCastTo(CladeNodeKind));
968 auto Result = DynTypedMatcher::constructVariadic(
969 ast_matchers::internal::DynTypedMatcher::VO_AnyOf, CladeNodeKind,
971 Result.setAllowBind(
true);
979 std::vector<ArgKind> &Kinds)
const override {
987 if (LeastDerivedKind)
988 *LeastDerivedKind = CladeNodeKind;
1002 std::unique_ptr<MatcherDescriptor>
1006 std::vector<ASTNodeKind> NodeKinds;
1007 for (
const auto &Arg : Args) {
1008 if (!Arg.Value.isNodeKind())
1010 NodeKinds.push_back(Arg.Value.getNodeKind());
1013 if (NodeKinds.empty())
1018 for (
auto NK : NodeKinds)
1020 if (!NK.getCladeKind().isSame(CladeNodeKind))
1024 return std::make_unique<MapAnyOfMatcherDescriptor>(CladeNodeKind,
1025 std::move(NodeKinds));
1033 std::vector<ArgKind> &ArgKinds)
const override {
1037 ASTNodeKind *LeastDerivedKind =
nullptr)
const override {
1040 if (LeastDerivedKind)
1041 *LeastDerivedKind = Kind;
1052template <
typename ReturnType>
1053std::unique_ptr<MatcherDescriptor>
1055 std::vector<ASTNodeKind> RetTypes;
1057 return std::make_unique<FixedArgCountMatcherDescriptor>(
1063template <
typename ReturnType,
typename ArgType1>
1064std::unique_ptr<MatcherDescriptor>
1066 std::vector<ASTNodeKind> RetTypes;
1069 return std::make_unique<FixedArgCountMatcherDescriptor>(
1071 reinterpret_cast<void (*)()
>(
Func), MatcherName, RetTypes, AK);
1075template <
typename ReturnType,
typename ArgType1,
typename ArgType2>
1076std::unique_ptr<MatcherDescriptor>
1078 StringRef MatcherName) {
1079 std::vector<ASTNodeKind> RetTypes;
1083 return std::make_unique<FixedArgCountMatcherDescriptor>(
1085 reinterpret_cast<void (*)()
>(
Func), MatcherName, RetTypes, AKs);
1088template <
typename ReturnType>
1090 ReturnType (*FuncFlags)(llvm::StringRef, llvm::Regex::RegexFlags),
1091 ReturnType (*
Func)(llvm::StringRef)) {
1092 std::vector<ASTNodeKind> RetTypes;
1094 return std::make_unique<RegexMatcherDescriptor<ReturnType>>(FuncFlags,
Func,
1099template <
typename ResultT,
typename ArgT,
1102 ast_matchers::internal::VariadicFunction<ResultT, ArgT, Func> VarFunc,
1103 StringRef MatcherName) {
1104 return std::make_unique<VariadicFuncMatcherDescriptor>(VarFunc, MatcherName);
1111template <
typename BaseT,
typename DerivedT>
1113 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT>
1115 StringRef MatcherName) {
1116 return std::make_unique<DynCastAllOfMatcherDescriptor>(VarFunc, MatcherName);
1120template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
1121 typename FromTypes,
typename ToTypes>
1123 ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
1124 FromTypes, ToTypes>,
1125 StringRef MatcherName) {
1126 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
1129 return std::make_unique<OverloadedMatcherDescriptor>(Overloads);
1132template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
1133 typename FromTypes,
typename ToTypes>
1134template <
typename FromTypeList>
1135inline void AdaptativeOverloadCollector<ArgumentAdapterT, FromTypes,
1136 ToTypes>::collect(FromTypeList) {
1138 &AdaptativeFunc::template create<typename FromTypeList::head>, Name));
1139 collect(
typename FromTypeList::tail());
1143template <
unsigned MinCount,
unsigned MaxCount>
1145 ast_matchers::internal::VariadicOperatorMatcherFunc<MinCount, MaxCount>
1147 StringRef MatcherName) {
1148 return std::make_unique<VariadicOperatorMatcherDescriptor>(
1149 MinCount, MaxCount,
Func.Op, MatcherName);
1152template <
typename CladeType,
typename... MatcherT>
1154 ast_matchers::internal::MapAnyOfMatcherImpl<CladeType, MatcherT...>,
1155 StringRef MatcherName) {
1156 return std::make_unique<MapAnyOfMatcherDescriptor>(
#define GEN_CLANG_CLAUSE_CLASS
#define CLAUSE_CLASS(Enum, Str, Class)
Defines the clang::attr::Kind enum.
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 constexpr ASTNodeKind getFromNodeKind()
Construct an identifier for T.
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)
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.
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
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...
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
bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, ASTNodeKind *LeastDerivedKind) const override
Returns whether this matcher is convertible to the given type.
VariantMatcher(*)(StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) RunFunc
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)
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.
VariantMatcher matcherMarshall0(void(*Func)(), StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error)
0-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.
std::unique_ptr< MatcherDescriptor > makeMatcherRegexMarshall(ReturnType(*FuncFlags)(llvm::StringRef, llvm::Regex::RegexFlags), ReturnType(*Func)(llvm::StringRef))
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.
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.
void buildReturnTypeVectorFromTypeList< ast_matchers::internal::EmptyTypeList >(std::vector< ASTNodeKind > &RetTypes)
void buildReturnTypeVectorFromTypeList(std::vector< ASTNodeKind > &RetTypes)
VariantMatcher matcherMarshall1(void(*Func)(), StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error)
1-arg marshaller function.
VariantMatcher matcherMarshall2(void(*Func)(), StringRef MatcherName, SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error)
2-arg marshaller function.
const internal::VariadicAllOfMatcher< Attr > attr
The JSON file list parser is used to communicate input to InstallAPI.
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.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
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)