clang 23.0.0git
Marshallers.h
Go to the documentation of this file.
1//===- Marshallers.h - Generic matcher function marshallers -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Functions templates and classes to wrap matcher construct functions.
11///
12/// A collection of template function and classes that provide a generic
13/// marshalling layer on top of matcher construct functions.
14/// These are used by the registry to export all marshaller constructors with
15/// the same generic interface.
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_CLANG_LIB_ASTMATCHERS_DYNAMIC_MARSHALLERS_H
20#define LLVM_CLANG_LIB_ASTMATCHERS_DYNAMIC_MARSHALLERS_H
21
28#include "clang/Basic/LLVM.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"
37#include <cassert>
38#include <cstddef>
39#include <iterator>
40#include <limits>
41#include <memory>
42#include <optional>
43#include <string>
44#include <utility>
45#include <vector>
46
47namespace clang {
48namespace ast_matchers {
49namespace dynamic {
50namespace internal {
51
52/// Helper template class to just from argument type to the right is/get
53/// functions in VariantValue.
54/// Used to verify and extract the matcher arguments below.
55template <class T> struct ArgTypeTraits;
56template <class T> struct ArgTypeTraits<const T &> : public ArgTypeTraits<T> {
57};
58
59template <> struct ArgTypeTraits<std::string> {
60 static bool hasCorrectType(const VariantValue &Value) {
61 return Value.isString();
62 }
63 static bool hasCorrectValue(const VariantValue &Value) { return true; }
64
65 static const std::string &get(const VariantValue &Value) {
66 return Value.getString();
67 }
68
69 static ArgKind getKind() {
71 }
72
73 static std::optional<std::string> getBestGuess(const VariantValue &) {
74 return std::nullopt;
75 }
76};
77
78template <>
79struct ArgTypeTraits<StringRef> : public ArgTypeTraits<std::string> {
80};
81
82template <class T> struct ArgTypeTraits<ast_matchers::internal::Matcher<T>> {
83 static bool hasCorrectType(const VariantValue& Value) {
84 return Value.isMatcher();
85 }
86 static bool hasCorrectValue(const VariantValue &Value) {
87 return Value.getMatcher().hasTypedMatcher<T>();
88 }
89
90 static ast_matchers::internal::Matcher<T> get(const VariantValue &Value) {
91 return Value.getMatcher().getTypedMatcher<T>();
92 }
93
97
98 static std::optional<std::string> getBestGuess(const VariantValue &) {
99 return std::nullopt;
100 }
101};
102
103template <> struct ArgTypeTraits<bool> {
104 static bool hasCorrectType(const VariantValue &Value) {
105 return Value.isBoolean();
106 }
107 static bool hasCorrectValue(const VariantValue &Value) { return true; }
108
109 static bool get(const VariantValue &Value) {
110 return Value.getBoolean();
111 }
112
113 static ArgKind getKind() {
115 }
116
117 static std::optional<std::string> getBestGuess(const VariantValue &) {
118 return std::nullopt;
119 }
120};
121
122template <> struct ArgTypeTraits<double> {
123 static bool hasCorrectType(const VariantValue &Value) {
124 return Value.isDouble();
125 }
126 static bool hasCorrectValue(const VariantValue &Value) { return true; }
127
128 static double get(const VariantValue &Value) {
129 return Value.getDouble();
130 }
131
132 static ArgKind getKind() {
134 }
135
136 static std::optional<std::string> getBestGuess(const VariantValue &) {
137 return std::nullopt;
138 }
139};
140
141template <> struct ArgTypeTraits<unsigned> {
142 static bool hasCorrectType(const VariantValue &Value) {
143 return Value.isUnsigned();
144 }
145 static bool hasCorrectValue(const VariantValue &Value) { return true; }
146
147 static unsigned get(const VariantValue &Value) {
148 return Value.getUnsigned();
149 }
150
151 static ArgKind getKind() {
153 }
154
155 static std::optional<std::string> getBestGuess(const VariantValue &) {
156 return std::nullopt;
157 }
158};
159
160template <> struct ArgTypeTraits<attr::Kind> {
161private:
162 static std::optional<attr::Kind> getAttrKind(llvm::StringRef AttrKind) {
163 if (!AttrKind.consume_front("attr::"))
164 return std::nullopt;
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);
169 }
170
171public:
172 static bool hasCorrectType(const VariantValue &Value) {
173 return Value.isString();
174 }
175 static bool hasCorrectValue(const VariantValue& Value) {
176 return getAttrKind(Value.getString()).has_value();
177 }
178
180 return *getAttrKind(Value.getString());
181 }
182
183 static ArgKind getKind() {
185 }
186
187 static std::optional<std::string> getBestGuess(const VariantValue &Value);
188};
189
190template <> struct ArgTypeTraits<CastKind> {
191private:
192 static std::optional<CastKind> getCastKind(llvm::StringRef AttrKind) {
193 if (!AttrKind.consume_front("CK_"))
194 return std::nullopt;
195 return llvm::StringSwitch<std::optional<CastKind>>(AttrKind)
196#define CAST_OPERATION(Name) .Case(#Name, CK_##Name)
197#include "clang/AST/OperationKinds.def"
198 .Default(std::nullopt);
199 }
200
201public:
202 static bool hasCorrectType(const VariantValue &Value) {
203 return Value.isString();
204 }
205 static bool hasCorrectValue(const VariantValue& Value) {
206 return getCastKind(Value.getString()).has_value();
207 }
208
210 return *getCastKind(Value.getString());
211 }
212
213 static ArgKind getKind() {
215 }
216
217 static std::optional<std::string> getBestGuess(const VariantValue &Value);
218};
219
220template <> struct ArgTypeTraits<llvm::Regex::RegexFlags> {
221private:
222 static std::optional<llvm::Regex::RegexFlags> getFlags(llvm::StringRef Flags);
223
224public:
225 static bool hasCorrectType(const VariantValue &Value) {
226 return Value.isString();
227 }
228 static bool hasCorrectValue(const VariantValue& Value) {
229 return getFlags(Value.getString()).has_value();
230 }
231
232 static llvm::Regex::RegexFlags get(const VariantValue &Value) {
233 return *getFlags(Value.getString());
234 }
235
237
238 static std::optional<std::string> getBestGuess(const VariantValue &Value);
239};
240
241template <> struct ArgTypeTraits<OpenMPClauseKind> {
242private:
243 static std::optional<OpenMPClauseKind>
244 getClauseKind(llvm::StringRef ClauseKind) {
245 return llvm::StringSwitch<std::optional<OpenMPClauseKind>>(ClauseKind)
247#define CLAUSE_CLASS(Enum, Str, Class) .Case(#Enum, llvm::omp::Clause::Enum)
248#include "llvm/Frontend/OpenMP/OMP.inc"
249 .Default(std::nullopt);
250 }
251
252public:
253 static bool hasCorrectType(const VariantValue &Value) {
254 return Value.isString();
255 }
256 static bool hasCorrectValue(const VariantValue& Value) {
257 return getClauseKind(Value.getString()).has_value();
258 }
259
261 return *getClauseKind(Value.getString());
262 }
263
265
266 static std::optional<std::string> getBestGuess(const VariantValue &Value);
267};
268
270private:
271 static std::optional<UnaryExprOrTypeTrait>
272 getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
273 if (!ClauseKind.consume_front("UETT_"))
274 return std::nullopt;
275 return llvm::StringSwitch<std::optional<UnaryExprOrTypeTrait>>(ClauseKind)
276#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) .Case(#Name, UETT_##Name)
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);
281 }
282
283public:
284 static bool hasCorrectType(const VariantValue &Value) {
285 return Value.isString();
286 }
287 static bool hasCorrectValue(const VariantValue& Value) {
288 return getUnaryOrTypeTraitKind(Value.getString()).has_value();
289 }
290
292 return *getUnaryOrTypeTraitKind(Value.getString());
293 }
294
296
297 static std::optional<std::string> getBestGuess(const VariantValue &Value);
298};
299
300/// Matcher descriptor interface.
301///
302/// Provides a \c create() method that constructs the matcher from the provided
303/// arguments, and various other methods for type introspection.
305public:
306 virtual ~MatcherDescriptor() = default;
307
310 Diagnostics *Error) const = 0;
311
312 virtual ASTNodeKind nodeMatcherType() const { return ASTNodeKind(); }
313
314 virtual bool isBuilderMatcher() const { return false; }
315
316 virtual std::unique_ptr<MatcherDescriptor>
318 Diagnostics *Error) const {
319 return {};
320 }
321
322 /// Returns whether the matcher is variadic. Variadic matchers can take any
323 /// number of arguments, but they must be of the same type.
324 virtual bool isVariadic() const = 0;
325
326 /// Returns the number of arguments accepted by the matcher if not variadic.
327 virtual unsigned getNumArgs() const = 0;
328
329 /// Given that the matcher is being converted to type \p ThisKind, append the
330 /// set of argument types accepted for argument \p ArgNo to \p ArgKinds.
331 // FIXME: We should provide the ability to constrain the output of this
332 // function based on the types of other matcher arguments.
333 virtual void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
334 std::vector<ArgKind> &ArgKinds) const = 0;
335
336 /// Returns whether this matcher is convertible to the given type. If it is
337 /// so convertible, store in *Specificity a value corresponding to the
338 /// "specificity" of the converted matcher to the given context, and in
339 /// *LeastDerivedKind the least derived matcher kind which would result in the
340 /// same matcher overload. Zero specificity indicates that this conversion
341 /// would produce a trivial matcher that will either always or never match.
342 /// Such matchers are excluded from code completion results.
343 virtual bool
344 isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity = nullptr,
345 ASTNodeKind *LeastDerivedKind = nullptr) const = 0;
346
347 /// Returns whether the matcher will, given a matcher of any type T, yield a
348 /// matcher of type T.
349 virtual bool isPolymorphic() const { return false; }
350};
351
353 ASTNodeKind Kind, unsigned *Specificity,
354 ASTNodeKind *LeastDerivedKind) {
355 for (const ASTNodeKind &NodeKind : RetKinds) {
356 if (ArgKind::MakeMatcherArg(NodeKind).isConvertibleTo(
357 ArgKind::MakeMatcherArg(Kind), Specificity)) {
358 if (LeastDerivedKind)
359 *LeastDerivedKind = NodeKind;
360 return true;
361 }
362 }
363 return false;
364}
365
366/// Simple callback implementation. Marshaller and function are provided.
367///
368/// This class wraps a function of arbitrary signature and a marshaller
369/// function into a MatcherDescriptor.
370/// The marshaller is in charge of taking the VariantValue arguments, checking
371/// their types, unpacking them and calling the underlying function.
373public:
374 using MarshallerType = VariantMatcher (*)(void (*Func)(),
375 StringRef MatcherName,
376 SourceRange NameRange,
379
380 /// \param Marshaller Function to unpack the arguments and call \c Func
381 /// \param Func Matcher construct function. This is the function that
382 /// compile-time matcher expressions would use to create the matcher.
383 /// \param RetKinds The list of matcher types to which the matcher is
384 /// convertible.
385 /// \param ArgKinds The types of the arguments this matcher takes.
387 StringRef MatcherName,
388 ArrayRef<ASTNodeKind> RetKinds,
389 ArrayRef<ArgKind> ArgKinds)
390 : Marshaller(Marshaller), Func(Func), MatcherName(MatcherName),
391 RetKinds(RetKinds.begin(), RetKinds.end()),
392 ArgKinds(ArgKinds.begin(), ArgKinds.end()) {}
393
396 Diagnostics *Error) const override {
397 return Marshaller(Func, MatcherName, NameRange, Args, Error);
398 }
399
400 bool isVariadic() const override { return false; }
401 unsigned getNumArgs() const override { return ArgKinds.size(); }
402
403 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
404 std::vector<ArgKind> &Kinds) const override {
405 Kinds.push_back(ArgKinds[ArgNo]);
406 }
407
408 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
409 ASTNodeKind *LeastDerivedKind) const override {
410 return isRetKindConvertibleTo(RetKinds, Kind, Specificity,
411 LeastDerivedKind);
412 }
413
414private:
415 const MarshallerType Marshaller;
416 void (* const Func)();
417 const std::string MatcherName;
418 const std::vector<ASTNodeKind> RetKinds;
419 const std::vector<ArgKind> ArgKinds;
420};
421
422/// Helper methods to extract and merge all possible typed matchers
423/// out of the polymorphic object.
424template <class PolyMatcher>
425void mergePolyMatchers(const PolyMatcher &Poly,
426 std::vector<DynTypedMatcher> &Out,
427 ast_matchers::internal::EmptyTypeList) {}
428
429template <class PolyMatcher, class TypeList>
430void mergePolyMatchers(const PolyMatcher &Poly,
431 std::vector<DynTypedMatcher> &Out, TypeList) {
432 Out.push_back(ast_matchers::internal::Matcher<typename TypeList::head>(Poly));
433 mergePolyMatchers(Poly, Out, typename TypeList::tail());
434}
435
436/// Convert the return values of the functions into a VariantMatcher.
437///
438/// There are 2 cases right now: The return value is a Matcher<T> or is a
439/// polymorphic matcher. For the former, we just construct the VariantMatcher.
440/// For the latter, we instantiate all the possible Matcher<T> of the poly
441/// matcher.
442inline VariantMatcher outvalueToVariantMatcher(const DynTypedMatcher &Matcher) {
443 return VariantMatcher::SingleMatcher(Matcher);
444}
445
446template <typename T>
448 typename T::ReturnTypes * = nullptr) {
449 std::vector<DynTypedMatcher> Matchers;
450 mergePolyMatchers(PolyMatcher, Matchers, typename T::ReturnTypes());
451 VariantMatcher Out = VariantMatcher::PolymorphicMatcher(std::move(Matchers));
452 return Out;
453}
454
455template <typename T>
456inline void
461
462template <>
463inline void
465 std::vector<ASTNodeKind> &RetTypes) {}
466
467template <typename T>
469 static void build(std::vector<ASTNodeKind> &RetTypes) {
471 }
472};
473
474template <typename T>
475struct BuildReturnTypeVector<ast_matchers::internal::Matcher<T>> {
476 static void build(std::vector<ASTNodeKind> &RetTypes) {
477 RetTypes.push_back(ASTNodeKind::getFromNodeKind<T>());
478 }
479};
480
481template <typename T>
482struct BuildReturnTypeVector<ast_matchers::internal::BindableMatcher<T>> {
483 static void build(std::vector<ASTNodeKind> &RetTypes) {
484 RetTypes.push_back(ASTNodeKind::getFromNodeKind<T>());
485 }
486};
487
488/// Variadic marshaller function.
489template <typename ResultT, typename ArgT,
490 ResultT (*Func)(ArrayRef<const ArgT *>)>
492variadicMatcherDescriptor(StringRef MatcherName, SourceRange NameRange,
494 SmallVector<ArgT *, 8> InnerArgsPtr;
495 InnerArgsPtr.resize_for_overwrite(Args.size());
496 SmallVector<ArgT, 8> InnerArgs;
497 InnerArgs.reserve(Args.size());
498
499 for (size_t i = 0, e = Args.size(); i != e; ++i) {
500 using ArgTraits = ArgTypeTraits<ArgT>;
501
502 const ParserValue &Arg = Args[i];
503 const VariantValue &Value = Arg.Value;
504 if (!ArgTraits::hasCorrectType(Value)) {
505 Error->addError(Arg.Range, Error->ET_RegistryWrongArgType)
506 << (i + 1) << ArgTraits::getKind().asString() << Value.getTypeAsString();
507 return {};
508 }
509 if (!ArgTraits::hasCorrectValue(Value)) {
510 if (std::optional<std::string> BestGuess =
511 ArgTraits::getBestGuess(Value)) {
512 Error->addError(Arg.Range, Error->ET_RegistryUnknownEnumWithReplace)
513 << i + 1 << Value.getString() << *BestGuess;
514 } else if (Value.isString()) {
515 Error->addError(Arg.Range, Error->ET_RegistryValueNotFound)
516 << Value.getString();
517 } else {
518 // This isn't ideal, but it's better than reporting an empty string as
519 // the error in this case.
520 Error->addError(Arg.Range, Error->ET_RegistryWrongArgType)
521 << (i + 1) << ArgTraits::getKind().asString()
522 << Value.getTypeAsString();
523 }
524 return {};
525 }
526 assert(InnerArgs.size() < InnerArgs.capacity());
527 InnerArgs.emplace_back(ArgTraits::get(Value));
528 InnerArgsPtr[i] = &InnerArgs[i];
529 }
530 return outvalueToVariantMatcher(Func(InnerArgsPtr));
531}
532
533/// Matcher descriptor for variadic functions.
534///
535/// This class simply wraps a VariadicFunction with the right signature to export
536/// it as a MatcherDescriptor.
537/// This allows us to have one implementation of the interface for as many free
538/// functions as we want, reducing the number of symbols and size of the
539/// object file.
541public:
542 using RunFunc = VariantMatcher (*)(StringRef MatcherName,
543 SourceRange NameRange,
546
547 template <typename ResultT, typename ArgT,
548 ResultT (*F)(ArrayRef<const ArgT *>)>
550 ast_matchers::internal::VariadicFunction<ResultT, ArgT, F> Func,
551 StringRef MatcherName)
553 MatcherName(MatcherName.str()),
554 ArgsKind(ArgTypeTraits<ArgT>::getKind()) {
556 }
557
560 Diagnostics *Error) const override {
561 return Func(MatcherName, NameRange, Args, Error);
562 }
563
564 bool isVariadic() const override { return true; }
565 unsigned getNumArgs() const override { return 0; }
566
567 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
568 std::vector<ArgKind> &Kinds) const override {
569 Kinds.push_back(ArgsKind);
570 }
571
572 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
573 ASTNodeKind *LeastDerivedKind) const override {
574 return isRetKindConvertibleTo(RetKinds, Kind, Specificity,
575 LeastDerivedKind);
576 }
577
578 ASTNodeKind nodeMatcherType() const override { return RetKinds[0]; }
579
580private:
581 const RunFunc Func;
582 const std::string MatcherName;
583 std::vector<ASTNodeKind> RetKinds;
584 const ArgKind ArgsKind;
585};
586
587/// Return CK_Trivial when appropriate for VariadicDynCastAllOfMatchers.
589public:
590 template <typename BaseT, typename DerivedT>
592 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT> Func,
593 StringRef MatcherName)
594 : VariadicFuncMatcherDescriptor(Func, MatcherName),
595 DerivedKind(ASTNodeKind::getFromNodeKind<DerivedT>()) {}
596
597 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
598 ASTNodeKind *LeastDerivedKind) const override {
599 // If Kind is not a base of DerivedKind, either DerivedKind is a base of
600 // Kind (in which case the match will always succeed) or Kind and
601 // DerivedKind are unrelated (in which case it will always fail), so set
602 // Specificity to 0.
604 LeastDerivedKind)) {
605 if (Kind.isSame(DerivedKind) || !Kind.isBaseOf(DerivedKind)) {
606 if (Specificity)
607 *Specificity = 0;
608 }
609 return true;
610 } else {
611 return false;
612 }
613 }
614
615 ASTNodeKind nodeMatcherType() const override { return DerivedKind; }
616
617private:
618 const ASTNodeKind DerivedKind;
619};
620
621/// Helper macros to check the arguments on all marshaller functions.
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(); \
627 }
628
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(); \
635 } \
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(); \
645 } \
646 return VariantMatcher(); \
647 }
648
649/// 0-arg marshaller function.
650template <typename ReturnType>
651VariantMatcher
652matcherMarshall0(void (*Func)(), StringRef MatcherName, SourceRange NameRange,
654 using FuncType = ReturnType (*)();
656 return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)());
657}
658
659/// 1-arg marshaller function.
660template <typename ReturnType, typename ArgType1>
662matcherMarshall1(void (*Func)(), StringRef MatcherName, SourceRange NameRange,
664 using FuncType = ReturnType (*)(ArgType1);
666 CHECK_ARG_TYPE(0, ArgType1);
667 return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)(
669}
670
671/// 2-arg marshaller function.
672template <typename ReturnType, typename ArgType1, typename ArgType2>
674matcherMarshall2(void (*Func)(), StringRef MatcherName, SourceRange NameRange,
676 using FuncType = ReturnType (*)(ArgType1, ArgType2);
678 CHECK_ARG_TYPE(0, ArgType1);
679 CHECK_ARG_TYPE(1, ArgType2);
680 return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)(
683}
684
685#undef CHECK_ARG_COUNT
686#undef CHECK_ARG_TYPE
687
688/// Helper class used to collect all the possible overloads of an
689/// argument adaptative matcher function.
690template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
691 typename FromTypes, typename ToTypes>
693public:
695 StringRef Name, std::vector<std::unique_ptr<MatcherDescriptor>> &Out)
696 : Name(Name), Out(Out) {
697 collect(FromTypes());
698 }
699
700private:
701 using AdaptativeFunc = ast_matchers::internal::ArgumentAdaptingMatcherFunc<
702 ArgumentAdapterT, FromTypes, ToTypes>;
703
704 /// End case for the recursion
705 static void collect(ast_matchers::internal::EmptyTypeList) {}
706
707 /// Recursive case. Get the overload for the head of the list, and
708 /// recurse to the tail.
709 template <typename FromTypeList>
710 inline void collect(FromTypeList);
711
712 StringRef Name;
713 std::vector<std::unique_ptr<MatcherDescriptor>> &Out;
714};
715
716/// MatcherDescriptor that wraps multiple "overloads" of the same
717/// matcher.
718///
719/// It will try every overload and generate appropriate errors for when none or
720/// more than one overloads match the arguments.
722public:
724 MutableArrayRef<std::unique_ptr<MatcherDescriptor>> Callbacks)
725 : Overloads(std::make_move_iterator(Callbacks.begin()),
726 std::make_move_iterator(Callbacks.end())) {}
727
728 ~OverloadedMatcherDescriptor() override = default;
729
732 Diagnostics *Error) const override {
733 std::vector<VariantMatcher> Constructed;
735 for (const auto &O : Overloads) {
736 VariantMatcher SubMatcher = O->create(NameRange, Args, Error);
737 if (!SubMatcher.isNull()) {
738 Constructed.push_back(SubMatcher);
739 }
740 }
741
742 if (Constructed.empty()) return VariantMatcher(); // No overload matched.
743 // We ignore the errors if any matcher succeeded.
744 Ctx.revertErrors();
745 if (Constructed.size() > 1) {
746 // More than one constructed. It is ambiguous.
747 Error->addError(NameRange, Error->ET_RegistryAmbiguousOverload);
748 return VariantMatcher();
749 }
750 return Constructed[0];
751 }
752
753 bool isVariadic() const override {
754 bool Overload0Variadic = Overloads[0]->isVariadic();
755#ifndef NDEBUG
756 for (const auto &O : Overloads) {
757 assert(Overload0Variadic == O->isVariadic());
758 }
759#endif
760 return Overload0Variadic;
761 }
762
763 unsigned getNumArgs() const override {
764 unsigned Overload0NumArgs = Overloads[0]->getNumArgs();
765#ifndef NDEBUG
766 for (const auto &O : Overloads) {
767 assert(Overload0NumArgs == O->getNumArgs());
768 }
769#endif
770 return Overload0NumArgs;
771 }
772
773 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
774 std::vector<ArgKind> &Kinds) const override {
775 for (const auto &O : Overloads) {
776 if (O->isConvertibleTo(ThisKind))
777 O->getArgKinds(ThisKind, ArgNo, Kinds);
778 }
779 }
780
781 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
782 ASTNodeKind *LeastDerivedKind) const override {
783 for (const auto &O : Overloads) {
784 if (O->isConvertibleTo(Kind, Specificity, LeastDerivedKind))
785 return true;
786 }
787 return false;
788 }
789
790private:
791 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
792};
793
794template <typename ReturnType>
796public:
797 RegexMatcherDescriptor(ReturnType (*WithFlags)(StringRef,
798 llvm::Regex::RegexFlags),
799 ReturnType (*NoFlags)(StringRef),
800 ArrayRef<ASTNodeKind> RetKinds)
801 : WithFlags(WithFlags), NoFlags(NoFlags),
802 RetKinds(RetKinds.begin(), RetKinds.end()) {}
803 bool isVariadic() const override { return true; }
804 unsigned getNumArgs() const override { return 0; }
805
806 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
807 std::vector<ArgKind> &Kinds) const override {
808 assert(ArgNo < 2);
809 Kinds.push_back(ArgKind::AK_String);
810 }
811
812 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
813 ASTNodeKind *LeastDerivedKind) const override {
814 return isRetKindConvertibleTo(RetKinds, Kind, Specificity,
815 LeastDerivedKind);
816 }
817
819 Diagnostics *Error) const override {
820 if (Args.size() < 1 || Args.size() > 2) {
821 Error->addError(NameRange, Diagnostics::ET_RegistryWrongArgCount)
822 << "1 or 2" << Args.size();
823 return VariantMatcher();
824 }
826 Error->addError(Args[0].Range, Error->ET_RegistryWrongArgType)
827 << 1 << ArgTypeTraits<StringRef>::getKind().asString()
828 << Args[0].Value.getTypeAsString();
829 return VariantMatcher();
830 }
831 if (Args.size() == 1) {
833 NoFlags(ArgTypeTraits<StringRef>::get(Args[0].Value)));
834 }
836 Args[1].Value)) {
837 Error->addError(Args[1].Range, Error->ET_RegistryWrongArgType)
839 << Args[1].Value.getTypeAsString();
840 return VariantMatcher();
841 }
843 Args[1].Value)) {
844 if (std::optional<std::string> BestGuess =
846 Args[1].Value)) {
847 Error->addError(Args[1].Range, Error->ET_RegistryUnknownEnumWithReplace)
848 << 2 << Args[1].Value.getString() << *BestGuess;
849 } else {
850 Error->addError(Args[1].Range, Error->ET_RegistryValueNotFound)
851 << Args[1].Value.getString();
852 }
853 return VariantMatcher();
854 }
856 WithFlags(ArgTypeTraits<StringRef>::get(Args[0].Value),
858 }
859
860private:
861 ReturnType (*const WithFlags)(StringRef, llvm::Regex::RegexFlags);
862 ReturnType (*const NoFlags)(StringRef);
863 const std::vector<ASTNodeKind> RetKinds;
864};
865
866/// Variadic operator marshaller function.
868public:
869 using VarOp = DynTypedMatcher::VariadicOperator;
870
871 VariadicOperatorMatcherDescriptor(unsigned MinCount, unsigned MaxCount,
872 VarOp Op, StringRef MatcherName)
873 : MinCount(MinCount), MaxCount(MaxCount), Op(Op),
874 MatcherName(MatcherName) {}
875
878 Diagnostics *Error) const override {
879 if (Args.size() < MinCount || MaxCount < Args.size()) {
880 const std::string MaxStr =
881 (MaxCount == std::numeric_limits<unsigned>::max() ? ""
882 : Twine(MaxCount))
883 .str();
884 Error->addError(NameRange, Error->ET_RegistryWrongArgCount)
885 << ("(" + Twine(MinCount) + ", " + MaxStr + ")") << Args.size();
886 return VariantMatcher();
887 }
888
889 std::vector<VariantMatcher> InnerArgs;
890 for (size_t i = 0, e = Args.size(); i != e; ++i) {
891 const ParserValue &Arg = Args[i];
892 const VariantValue &Value = Arg.Value;
893 if (!Value.isMatcher()) {
894 Error->addError(Arg.Range, Error->ET_RegistryWrongArgType)
895 << (i + 1) << "Matcher<>" << Value.getTypeAsString();
896 return VariantMatcher();
897 }
898 InnerArgs.push_back(Value.getMatcher());
899 }
900 return VariantMatcher::VariadicOperatorMatcher(Op, std::move(InnerArgs));
901 }
902
903 bool isVariadic() const override { return true; }
904 unsigned getNumArgs() const override { return 0; }
905
906 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
907 std::vector<ArgKind> &Kinds) const override {
908 Kinds.push_back(ArgKind::MakeMatcherArg(ThisKind));
909 }
910
911 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
912 ASTNodeKind *LeastDerivedKind) const override {
913 if (Specificity)
914 *Specificity = 1;
915 if (LeastDerivedKind)
916 *LeastDerivedKind = Kind;
917 return true;
918 }
919
920 bool isPolymorphic() const override { return true; }
921
922private:
923 const unsigned MinCount;
924 const unsigned MaxCount;
925 const VarOp Op;
926 const StringRef MatcherName;
927};
928
930 ASTNodeKind CladeNodeKind;
931 std::vector<ASTNodeKind> NodeKinds;
932
933public:
935 std::vector<ASTNodeKind> NodeKinds)
936 : CladeNodeKind(CladeNodeKind), NodeKinds(std::move(NodeKinds)) {}
937
939 Diagnostics *Error) const override {
940
941 std::vector<DynTypedMatcher> NodeArgs;
942
943 for (auto NK : NodeKinds) {
944 std::vector<DynTypedMatcher> InnerArgs;
945
946 for (const auto &Arg : Args) {
947 if (!Arg.Value.isMatcher())
948 return {};
949 const VariantMatcher &VM = Arg.Value.getMatcher();
950 if (VM.hasTypedMatcher(NK)) {
951 auto DM = VM.getTypedMatcher(NK);
952 InnerArgs.push_back(DM);
953 }
954 }
955
956 if (InnerArgs.empty()) {
957 NodeArgs.push_back(
958 DynTypedMatcher::trueMatcher(NK).dynCastTo(CladeNodeKind));
959 } else {
960 NodeArgs.push_back(
961 DynTypedMatcher::constructVariadic(
962 ast_matchers::internal::DynTypedMatcher::VO_AllOf, NK,
963 InnerArgs)
964 .dynCastTo(CladeNodeKind));
965 }
966 }
967
968 auto Result = DynTypedMatcher::constructVariadic(
969 ast_matchers::internal::DynTypedMatcher::VO_AnyOf, CladeNodeKind,
970 NodeArgs);
971 Result.setAllowBind(true);
973 }
974
975 bool isVariadic() const override { return true; }
976 unsigned getNumArgs() const override { return 0; }
977
978 void getArgKinds(ASTNodeKind ThisKind, unsigned,
979 std::vector<ArgKind> &Kinds) const override {
980 Kinds.push_back(ArgKind::MakeMatcherArg(ThisKind));
981 }
982
983 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
984 ASTNodeKind *LeastDerivedKind) const override {
985 if (Specificity)
986 *Specificity = 1;
987 if (LeastDerivedKind)
988 *LeastDerivedKind = CladeNodeKind;
989 return true;
990 }
991};
992
994public:
996 Diagnostics *) const override {
997 return {};
998 }
999
1000 bool isBuilderMatcher() const override { return true; }
1001
1002 std::unique_ptr<MatcherDescriptor>
1004 Diagnostics *) const override {
1005
1006 std::vector<ASTNodeKind> NodeKinds;
1007 for (const auto &Arg : Args) {
1008 if (!Arg.Value.isNodeKind())
1009 return {};
1010 NodeKinds.push_back(Arg.Value.getNodeKind());
1011 }
1012
1013 if (NodeKinds.empty())
1014 return {};
1015
1016 ASTNodeKind CladeNodeKind = NodeKinds.front().getCladeKind();
1017
1018 for (auto NK : NodeKinds)
1019 {
1020 if (!NK.getCladeKind().isSame(CladeNodeKind))
1021 return {};
1022 }
1023
1024 return std::make_unique<MapAnyOfMatcherDescriptor>(CladeNodeKind,
1025 std::move(NodeKinds));
1026 }
1027
1028 bool isVariadic() const override { return true; }
1029
1030 unsigned getNumArgs() const override { return 0; }
1031
1032 void getArgKinds(ASTNodeKind ThisKind, unsigned,
1033 std::vector<ArgKind> &ArgKinds) const override {
1034 ArgKinds.push_back(ArgKind::MakeNodeArg(ThisKind));
1035 }
1036 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity = nullptr,
1037 ASTNodeKind *LeastDerivedKind = nullptr) const override {
1038 if (Specificity)
1039 *Specificity = 1;
1040 if (LeastDerivedKind)
1041 *LeastDerivedKind = Kind;
1042 return true;
1043 }
1044
1045 bool isPolymorphic() const override { return false; }
1046};
1047
1048/// Helper functions to select the appropriate marshaller functions.
1049/// They detect the number of arguments, arguments types and return type.
1050
1051/// 0-arg overload
1052template <typename ReturnType>
1053std::unique_ptr<MatcherDescriptor>
1054makeMatcherAutoMarshall(ReturnType (*Func)(), StringRef MatcherName) {
1055 std::vector<ASTNodeKind> RetTypes;
1057 return std::make_unique<FixedArgCountMatcherDescriptor>(
1058 matcherMarshall0<ReturnType>, reinterpret_cast<void (*)()>(Func),
1059 MatcherName, RetTypes, ArrayRef<ArgKind>());
1060}
1061
1062/// 1-arg overload
1063template <typename ReturnType, typename ArgType1>
1064std::unique_ptr<MatcherDescriptor>
1065makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1), StringRef MatcherName) {
1066 std::vector<ASTNodeKind> RetTypes;
1069 return std::make_unique<FixedArgCountMatcherDescriptor>(
1071 reinterpret_cast<void (*)()>(Func), MatcherName, RetTypes, AK);
1072}
1073
1074/// 2-arg overload
1075template <typename ReturnType, typename ArgType1, typename ArgType2>
1076std::unique_ptr<MatcherDescriptor>
1077makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1, ArgType2),
1078 StringRef MatcherName) {
1079 std::vector<ASTNodeKind> RetTypes;
1083 return std::make_unique<FixedArgCountMatcherDescriptor>(
1085 reinterpret_cast<void (*)()>(Func), MatcherName, RetTypes, AKs);
1086}
1087
1088template <typename ReturnType>
1089std::unique_ptr<MatcherDescriptor> makeMatcherRegexMarshall(
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,
1095 RetTypes);
1096}
1097
1098/// Variadic overload.
1099template <typename ResultT, typename ArgT,
1100 ResultT (*Func)(ArrayRef<const ArgT *>)>
1101std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall(
1102 ast_matchers::internal::VariadicFunction<ResultT, ArgT, Func> VarFunc,
1103 StringRef MatcherName) {
1104 return std::make_unique<VariadicFuncMatcherDescriptor>(VarFunc, MatcherName);
1105}
1106
1107/// Overload for VariadicDynCastAllOfMatchers.
1108///
1109/// Not strictly necessary, but DynCastAllOfMatcherDescriptor gives us better
1110/// completion results for that type of matcher.
1111template <typename BaseT, typename DerivedT>
1112std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall(
1113 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT>
1114 VarFunc,
1115 StringRef MatcherName) {
1116 return std::make_unique<DynCastAllOfMatcherDescriptor>(VarFunc, MatcherName);
1117}
1118
1119/// Argument adaptative overload.
1120template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
1121 typename FromTypes, typename ToTypes>
1122std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall(
1123 ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
1124 FromTypes, ToTypes>,
1125 StringRef MatcherName) {
1126 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads;
1128 Overloads);
1129 return std::make_unique<OverloadedMatcherDescriptor>(Overloads);
1130}
1131
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) {
1137 Out.push_back(makeMatcherAutoMarshall(
1138 &AdaptativeFunc::template create<typename FromTypeList::head>, Name));
1139 collect(typename FromTypeList::tail());
1140}
1141
1142/// Variadic operator overload.
1143template <unsigned MinCount, unsigned MaxCount>
1144std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall(
1145 ast_matchers::internal::VariadicOperatorMatcherFunc<MinCount, MaxCount>
1146 Func,
1147 StringRef MatcherName) {
1148 return std::make_unique<VariadicOperatorMatcherDescriptor>(
1149 MinCount, MaxCount, Func.Op, MatcherName);
1150}
1151
1152template <typename CladeType, typename... MatcherT>
1153std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall(
1154 ast_matchers::internal::MapAnyOfMatcherImpl<CladeType, MatcherT...>,
1155 StringRef MatcherName) {
1156 return std::make_unique<MapAnyOfMatcherDescriptor>(
1158 std::vector<ASTNodeKind>{ASTNodeKind::getFromNodeKind<MatcherT>()...});
1159}
1160
1161} // namespace internal
1162} // namespace dynamic
1163} // namespace ast_matchers
1164} // namespace clang
1165
1166#endif // LLVM_CLANG_LIB_ASTMATCHERS_DYNAMIC_MARSHALLERS_H
#define GEN_CLANG_CLAUSE_CLASS
Definition ASTFwd.h:30
#define CLAUSE_CLASS(Enum, Str, Class)
Definition ASTFwd.h:31
#define ATTR(A)
Definition ASTFwd.h:34
Defines the clang::attr::Kind enum.
Diagnostics class to manage error messages.
#define X(type, name)
Definition Value.h:97
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)
Definition TypeTraits.h:52
Polymorphic value type.
__device__ double
Kind identifier.
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.
Definition Diagnostics.h:50
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)
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.
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
virtual bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity=nullptr, ASTNodeKind *LeastDerivedKind=nullptr) const =0
Returns whether this matcher is convertible to the given type.
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 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
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)
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...
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)
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.
Definition TypeTraits.h:51
@ Result
The result type of a method or function.
Definition TypeBase.h:905
CastKind
CastKind - The kind of operation required for a conversion.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5981
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5984
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
Definition OpenMPKinds.h:28
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
Context for overloaded matcher construction.
void revertErrors()
Revert all errors that happened within this context.
A VariantValue instance annotated with its parser context.
Definition Diagnostics.h:42
static std::optional< std::string > getBestGuess(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &Value)
static OpenMPClauseKind get(const VariantValue &Value)
static UnaryExprOrTypeTrait get(const VariantValue &Value)
static std::optional< std::string > getBestGuess(const VariantValue &Value)
static ast_matchers::internal::Matcher< T > get(const VariantValue &Value)
Definition Marshallers.h:90
static std::optional< std::string > getBestGuess(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 bool hasCorrectValue(const VariantValue &Value)
static bool hasCorrectType(const VariantValue &Value)
static llvm::Regex::RegexFlags get(const VariantValue &Value)
static const std::string & get(const VariantValue &Value)
Definition Marshallers.h:65
static std::optional< std::string > getBestGuess(const VariantValue &)
Definition Marshallers.h:73
static std::optional< std::string > getBestGuess(const VariantValue &)
Helper template class to just from argument type to the right is/get functions in VariantValue.
Definition Marshallers.h:55
static void build(std::vector< ASTNodeKind > &RetTypes)