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/BuiltinTraits.inc"
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;
591 : BaseKind(BaseKind), DerivedKind(DerivedKind) {}
600 std::vector<ArgKind> &Kinds)
const override {
604 bool isConvertibleTo(
ASTNodeKind Kind,
unsigned *Specificity,
615#define CHECK_ARG_COUNT(count) \
616 if (Args.size() != count) { \
617 Error->addError(NameRange, Error->ET_RegistryWrongArgCount) \
618 << count << Args.size(); \
619 return VariantMatcher(); \
622#define CHECK_ARG_TYPE(index, type) \
623 if (!ArgTypeTraits<type>::hasCorrectType(Args[index].Value)) { \
624 Error->addError(Args[index].Range, Error->ET_RegistryWrongArgType) \
625 << (index + 1) << ArgTypeTraits<type>::getKind().asString() \
626 << Args[index].Value.getTypeAsString(); \
627 return VariantMatcher(); \
629 if (!ArgTypeTraits<type>::hasCorrectValue(Args[index].Value)) { \
630 if (std::optional<std::string> BestGuess = \
631 ArgTypeTraits<type>::getBestGuess(Args[index].Value)) { \
632 Error->addError(Args[index].Range, \
633 Error->ET_RegistryUnknownEnumWithReplace) \
634 << index + 1 << Args[index].Value.getString() << *BestGuess; \
635 } else if (Args[index].Value.isString()) { \
636 Error->addError(Args[index].Range, Error->ET_RegistryValueNotFound) \
637 << Args[index].Value.getString(); \
639 return VariantMatcher(); \
643template <
typename ReturnType>
647 using FuncType = ReturnType (*)();
653template <
typename ReturnType,
typename ArgType1>
657 using FuncType = ReturnType (*)(ArgType1);
665template <
typename ReturnType,
typename ArgType1,
typename ArgType2>
669 using FuncType = ReturnType (*)(ArgType1, ArgType2);
678#undef CHECK_ARG_COUNT
683template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
684 typename FromTypes,
typename ToTypes>
688 StringRef Name, std::vector<std::unique_ptr<MatcherDescriptor>> &Out)
689 : Name(Name), Out(Out) {
690 collect(FromTypes());
694 using AdaptativeFunc = ast_matchers::internal::ArgumentAdaptingMatcherFunc<
695 ArgumentAdapterT, FromTypes, ToTypes>;
698 static void collect(ast_matchers::internal::EmptyTypeList) {}
702 template <
typename FromTypeList>
703 inline void collect(FromTypeList);
706 std::vector<std::unique_ptr<MatcherDescriptor>> &Out;
718 : Overloads(
std::make_move_iterator(Callbacks.begin()),
719 std::make_move_iterator(Callbacks.end())) {}
726 std::vector<VariantMatcher> Constructed;
728 for (
const auto &O : Overloads) {
730 if (!SubMatcher.
isNull()) {
731 Constructed.push_back(SubMatcher);
738 if (Constructed.size() > 1) {
740 Error->addError(NameRange,
Error->ET_RegistryAmbiguousOverload);
743 return Constructed[0];
747 bool Overload0Variadic = Overloads[0]->isVariadic();
749 for (
const auto &O : Overloads) {
750 assert(Overload0Variadic == O->isVariadic());
753 return Overload0Variadic;
757 unsigned Overload0NumArgs = Overloads[0]->getNumArgs();
759 for (
const auto &O : Overloads) {
760 assert(Overload0NumArgs == O->getNumArgs());
763 return Overload0NumArgs;
767 std::vector<ArgKind> &Kinds)
const override {
768 for (
const auto &O : Overloads) {
769 if (O->isConvertibleTo(ThisKind))
770 O->getArgKinds(ThisKind, ArgNo, Kinds);
776 for (
const auto &O : Overloads) {
777 if (O->isConvertibleTo(Kind, Specificity, LeastDerivedKind))
784 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
787template <
typename ReturnType>
791 llvm::Regex::RegexFlags),
792 ReturnType (*NoFlags)(StringRef),
794 : WithFlags(WithFlags), NoFlags(NoFlags),
795 RetKinds(RetKinds.begin(), RetKinds.end()) {}
800 std::vector<ArgKind> &Kinds)
const override {
813 if (Args.size() < 1 || Args.size() > 2) {
815 <<
"1 or 2" << Args.size();
819 Error->addError(Args[0].Range,
Error->ET_RegistryWrongArgType)
821 << Args[0].Value.getTypeAsString();
824 if (Args.size() == 1) {
830 Error->addError(Args[1].Range,
Error->ET_RegistryWrongArgType)
832 << Args[1].Value.getTypeAsString();
837 if (std::optional<std::string> BestGuess =
840 Error->addError(Args[1].Range,
Error->ET_RegistryUnknownEnumWithReplace)
841 << 2 << Args[1].Value.getString() << *BestGuess;
843 Error->addError(Args[1].Range,
Error->ET_RegistryValueNotFound)
844 << Args[1].Value.getString();
854 ReturnType (*
const WithFlags)(StringRef, llvm::Regex::RegexFlags);
855 ReturnType (*
const NoFlags)(StringRef);
856 const std::vector<ASTNodeKind> RetKinds;
862 using VarOp = DynTypedMatcher::VariadicOperator;
865 VarOp Op, StringRef MatcherName)
866 : MinCount(MinCount), MaxCount(MaxCount), Op(Op),
867 MatcherName(MatcherName) {}
872 if (Args.size() < MinCount || MaxCount < Args.size()) {
873 const std::string MaxStr =
874 (MaxCount == std::numeric_limits<unsigned>::max() ?
""
877 Error->addError(NameRange,
Error->ET_RegistryWrongArgCount)
878 << (
"(" + Twine(MinCount) +
", " + MaxStr +
")") << Args.size();
882 std::vector<VariantMatcher> InnerArgs;
883 for (
size_t i = 0, e = Args.size(); i != e; ++i) {
886 if (!
Value.isMatcher()) {
888 << (i + 1) <<
"Matcher<>" <<
Value.getTypeAsString();
891 InnerArgs.push_back(
Value.getMatcher());
900 std::vector<ArgKind> &Kinds)
const override {
908 if (LeastDerivedKind)
909 *LeastDerivedKind = Kind;
916 const unsigned MinCount;
917 const unsigned MaxCount;
919 const StringRef MatcherName;
924 std::vector<ASTNodeKind> NodeKinds;
928 std::vector<ASTNodeKind> NodeKinds)
929 : CladeNodeKind(CladeNodeKind), NodeKinds(
std::move(NodeKinds)) {}
934 std::vector<DynTypedMatcher> NodeArgs;
936 for (
auto NK : NodeKinds) {
937 std::vector<DynTypedMatcher> InnerArgs;
939 for (
const auto &Arg : Args) {
940 if (!Arg.Value.isMatcher())
945 InnerArgs.push_back(DM);
949 if (InnerArgs.empty()) {
951 DynTypedMatcher::trueMatcher(NK).dynCastTo(CladeNodeKind));
954 DynTypedMatcher::constructVariadic(
955 ast_matchers::internal::DynTypedMatcher::VO_AllOf, NK,
957 .dynCastTo(CladeNodeKind));
961 auto Result = DynTypedMatcher::constructVariadic(
962 ast_matchers::internal::DynTypedMatcher::VO_AnyOf, CladeNodeKind,
964 Result.setAllowBind(
true);
972 std::vector<ArgKind> &Kinds)
const override {
980 if (LeastDerivedKind)
981 *LeastDerivedKind = CladeNodeKind;
995 std::unique_ptr<MatcherDescriptor>
999 std::vector<ASTNodeKind> NodeKinds;
1000 for (
const auto &Arg : Args) {
1001 if (!Arg.Value.isNodeKind())
1003 NodeKinds.push_back(Arg.Value.getNodeKind());
1006 if (NodeKinds.empty())
1011 for (
auto NK : NodeKinds)
1013 if (!NK.getCladeKind().isSame(CladeNodeKind))
1017 return std::make_unique<MapAnyOfMatcherDescriptor>(CladeNodeKind,
1018 std::move(NodeKinds));
1026 std::vector<ArgKind> &ArgKinds)
const override {
1030 ASTNodeKind *LeastDerivedKind =
nullptr)
const override {
1033 if (LeastDerivedKind)
1034 *LeastDerivedKind = Kind;
1045template <
typename ReturnType>
1046std::unique_ptr<MatcherDescriptor>
1048 std::vector<ASTNodeKind> RetTypes;
1050 return std::make_unique<FixedArgCountMatcherDescriptor>(
1056template <
typename ReturnType,
typename ArgType1>
1057std::unique_ptr<MatcherDescriptor>
1059 std::vector<ASTNodeKind> RetTypes;
1062 return std::make_unique<FixedArgCountMatcherDescriptor>(
1064 reinterpret_cast<void (*)()
>(
Func), MatcherName, RetTypes, AK);
1068template <
typename ReturnType,
typename ArgType1,
typename ArgType2>
1069std::unique_ptr<MatcherDescriptor>
1071 StringRef MatcherName) {
1072 std::vector<ASTNodeKind> RetTypes;
1076 return std::make_unique<FixedArgCountMatcherDescriptor>(
1078 reinterpret_cast<void (*)()
>(
Func), MatcherName, RetTypes, AKs);
1081template <
typename ReturnType>
1083 ReturnType (*FuncFlags)(llvm::StringRef, llvm::Regex::RegexFlags),
1084 ReturnType (*
Func)(llvm::StringRef)) {
1085 std::vector<ASTNodeKind> RetTypes;
1087 return std::make_unique<RegexMatcherDescriptor<ReturnType>>(FuncFlags,
Func,
1092template <
typename ResultT,
typename ArgT,
1095 ast_matchers::internal::VariadicFunction<ResultT, ArgT, Func> VarFunc,
1096 StringRef MatcherName) {
1097 return std::make_unique<VariadicFuncMatcherDescriptor>(VarFunc, MatcherName);
1104template <
typename BaseT,
typename DerivedT>
1106 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT>,
1108 return std::make_unique<DynCastAllOfMatcherDescriptor>(
1114template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
1115 typename FromTypes,
typename ToTypes>
1117 ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
1118 FromTypes, ToTypes>,
1119 StringRef MatcherName) {
1120 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
1123 return std::make_unique<OverloadedMatcherDescriptor>(Overloads);
1126template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
1127 typename FromTypes,
typename ToTypes>
1128template <
typename FromTypeList>
1129inline void AdaptativeOverloadCollector<ArgumentAdapterT, FromTypes,
1130 ToTypes>::collect(FromTypeList) {
1132 &AdaptativeFunc::template create<typename FromTypeList::head>, Name));
1133 collect(
typename FromTypeList::tail());
1137template <
unsigned MinCount,
unsigned MaxCount>
1139 ast_matchers::internal::VariadicOperatorMatcherFunc<MinCount, MaxCount>
1141 StringRef MatcherName) {
1142 return std::make_unique<VariadicOperatorMatcherDescriptor>(
1143 MinCount, MaxCount,
Func.Op, MatcherName);
1146template <
typename CladeType,
typename... MatcherT>
1148 ast_matchers::internal::MapAnyOfMatcherImpl<CladeType, MatcherT...>,
1149 StringRef MatcherName) {
1150 return std::make_unique<MapAnyOfMatcherDescriptor>(
#define GEN_CLANG_CLAUSE_CLASS
#define CLAUSE_CLASS(Enum, Str, Class)
Defines the clang::attr::Kind enum.
Defines enumerations for traits support.
Diagnostics class to manage error messages.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key)
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)
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(ASTNodeKind BaseKind, ASTNodeKind DerivedKind)
bool isVariadic() const override
Returns whether the matcher is variadic.
ASTNodeKind nodeMatcherType() const override
void getArgKinds(ASTNodeKind, unsigned, std::vector< ArgKind > &Kinds) const override
Given that the matcher is being converted to type ThisKind, append the set of argument types accepted...
unsigned getNumArgs() const override
Returns the number of arguments accepted by the matcher if not variadic.
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
Top level wrappers for InstallAPI frontend operations.
@ Result
The result type of a method or function.
const FunctionProtoType * T
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)