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 22 #include "clang/AST/ASTTypeTraits.h" 23 #include "clang/AST/OperationKinds.h" 24 #include "clang/ASTMatchers/ASTMatchersInternal.h" 25 #include "clang/ASTMatchers/Dynamic/Diagnostics.h" 26 #include "clang/ASTMatchers/Dynamic/VariantValue.h" 27 #include "clang/Basic/AttrKinds.h" 28 #include "clang/Basic/LLVM.h" 29 #include "clang/Basic/OpenMPKinds.h" 30 #include "clang/Basic/TypeTraits.h" 31 #include "llvm/ADT/ArrayRef.h" 32 #include "llvm/ADT/None.h" 33 #include "llvm/ADT/Optional.h" 34 #include "llvm/ADT/STLExtras.h" 35 #include "llvm/ADT/StringRef.h" 36 #include "llvm/ADT/StringSwitch.h" 37 #include "llvm/ADT/Twine.h" 38 #include "llvm/Support/Regex.h" 39 #include <cassert> 40 #include <cstddef> 41 #include <iterator> 42 #include <limits> 43 #include <memory> 44 #include <string> 45 #include <utility> 46 #include <vector> 47 48 namespace clang { 49 namespace ast_matchers { 50 namespace dynamic { 51 namespace internal { 52 53 /// Helper template class to just from argument type to the right is/get 54 /// functions in VariantValue. 55 /// Used to verify and extract the matcher arguments below. 56 template <class T> struct ArgTypeTraits; 57 template <class T> struct ArgTypeTraits<const T &> : public ArgTypeTraits<T> { 58 }; 59 60 template <> struct ArgTypeTraits<std::string> { 61 static bool hasCorrectType(const VariantValue &Value) { 62 return Value.isString(); 63 } 64 static bool hasCorrectValue(const VariantValue &Value) { return true; } 65 66 static const std::string &get(const VariantValue &Value) { 67 return Value.getString(); 68 } 69 70 static ArgKind getKind() { 71 return ArgKind(ArgKind::AK_String); 72 } 73 74 static llvm::Optional<std::string> getBestGuess(const VariantValue &) { 75 return llvm::None; 76 } 77 }; 78 79 template <> 80 struct ArgTypeTraits<StringRef> : public ArgTypeTraits<std::string> { 81 }; 82 83 template <class T> struct ArgTypeTraits<ast_matchers::internal::Matcher<T>> { 84 static bool hasCorrectType(const VariantValue& Value) { 85 return Value.isMatcher(); 86 } 87 static bool hasCorrectValue(const VariantValue &Value) { 88 return Value.getMatcher().hasTypedMatcher<T>(); 89 } 90 91 static ast_matchers::internal::Matcher<T> get(const VariantValue &Value) { 92 return Value.getMatcher().getTypedMatcher<T>(); 93 } 94 95 static ArgKind getKind() { 96 return ArgKind::MakeMatcherArg(ASTNodeKind::getFromNodeKind<T>()); 97 } 98 99 static llvm::Optional<std::string> getBestGuess(const VariantValue &) { 100 return llvm::None; 101 } 102 }; 103 104 template <> struct ArgTypeTraits<bool> { 105 static bool hasCorrectType(const VariantValue &Value) { 106 return Value.isBoolean(); 107 } 108 static bool hasCorrectValue(const VariantValue &Value) { return true; } 109 110 static bool get(const VariantValue &Value) { 111 return Value.getBoolean(); 112 } 113 114 static ArgKind getKind() { 115 return ArgKind(ArgKind::AK_Boolean); 116 } 117 118 static llvm::Optional<std::string> getBestGuess(const VariantValue &) { 119 return llvm::None; 120 } 121 }; 122 123 template <> struct ArgTypeTraits<double> { 124 static bool hasCorrectType(const VariantValue &Value) { 125 return Value.isDouble(); 126 } 127 static bool hasCorrectValue(const VariantValue &Value) { return true; } 128 129 static double get(const VariantValue &Value) { 130 return Value.getDouble(); 131 } 132 133 static ArgKind getKind() { 134 return ArgKind(ArgKind::AK_Double); 135 } 136 137 static llvm::Optional<std::string> getBestGuess(const VariantValue &) { 138 return llvm::None; 139 } 140 }; 141 142 template <> struct ArgTypeTraits<unsigned> { 143 static bool hasCorrectType(const VariantValue &Value) { 144 return Value.isUnsigned(); 145 } 146 static bool hasCorrectValue(const VariantValue &Value) { return true; } 147 148 static unsigned get(const VariantValue &Value) { 149 return Value.getUnsigned(); 150 } 151 152 static ArgKind getKind() { 153 return ArgKind(ArgKind::AK_Unsigned); 154 } 155 156 static llvm::Optional<std::string> getBestGuess(const VariantValue &) { 157 return llvm::None; 158 } 159 }; 160 161 template <> struct ArgTypeTraits<attr::Kind> { 162 private: 163 static Optional<attr::Kind> getAttrKind(llvm::StringRef AttrKind) { 164 if (!AttrKind.consume_front("attr::")) 165 return llvm::None; 166 return llvm::StringSwitch<Optional<attr::Kind>>(AttrKind) 167 #define ATTR(X) .Case(#X, attr::X) 168 #include "clang/Basic/AttrList.inc" 169 .Default(llvm::None); 170 } 171 172 public: 173 static bool hasCorrectType(const VariantValue &Value) { 174 return Value.isString(); 175 } 176 static bool hasCorrectValue(const VariantValue& Value) { 177 return getAttrKind(Value.getString()).hasValue(); 178 } 179 180 static attr::Kind get(const VariantValue &Value) { 181 return *getAttrKind(Value.getString()); 182 } 183 184 static ArgKind getKind() { 185 return ArgKind(ArgKind::AK_String); 186 } 187 188 static llvm::Optional<std::string> getBestGuess(const VariantValue &Value); 189 }; 190 191 template <> struct ArgTypeTraits<CastKind> { 192 private: 193 static Optional<CastKind> getCastKind(llvm::StringRef AttrKind) { 194 if (!AttrKind.consume_front("CK_")) 195 return llvm::None; 196 return llvm::StringSwitch<Optional<CastKind>>(AttrKind) 197 #define CAST_OPERATION(Name) .Case(#Name, CK_##Name) 198 #include "clang/AST/OperationKinds.def" 199 .Default(llvm::None); 200 } 201 202 public: 203 static bool hasCorrectType(const VariantValue &Value) { 204 return Value.isString(); 205 } 206 static bool hasCorrectValue(const VariantValue& Value) { 207 return getCastKind(Value.getString()).hasValue(); 208 } 209 210 static CastKind get(const VariantValue &Value) { 211 return *getCastKind(Value.getString()); 212 } 213 214 static ArgKind getKind() { 215 return ArgKind(ArgKind::AK_String); 216 } 217 218 static llvm::Optional<std::string> getBestGuess(const VariantValue &Value); 219 }; 220 221 template <> struct ArgTypeTraits<llvm::Regex::RegexFlags> { 222 private: 223 static Optional<llvm::Regex::RegexFlags> getFlags(llvm::StringRef Flags); 224 225 public: 226 static bool hasCorrectType(const VariantValue &Value) { 227 return Value.isString(); 228 } 229 static bool hasCorrectValue(const VariantValue& Value) { 230 return getFlags(Value.getString()).hasValue(); 231 } 232 233 static llvm::Regex::RegexFlags get(const VariantValue &Value) { 234 return *getFlags(Value.getString()); 235 } 236 237 static ArgKind getKind() { return ArgKind(ArgKind::AK_String); } 238 239 static llvm::Optional<std::string> getBestGuess(const VariantValue &Value); 240 }; 241 242 template <> struct ArgTypeTraits<OpenMPClauseKind> { 243 private: 244 static Optional<OpenMPClauseKind> getClauseKind(llvm::StringRef ClauseKind) { 245 return llvm::StringSwitch<Optional<OpenMPClauseKind>>(ClauseKind) 246 #define GEN_CLANG_CLAUSE_CLASS 247 #define CLAUSE_CLASS(Enum, Str, Class) .Case(#Enum, llvm::omp::Clause::Enum) 248 #include "llvm/Frontend/OpenMP/OMP.inc" 249 .Default(llvm::None); 250 } 251 252 public: 253 static bool hasCorrectType(const VariantValue &Value) { 254 return Value.isString(); 255 } 256 static bool hasCorrectValue(const VariantValue& Value) { 257 return getClauseKind(Value.getString()).hasValue(); 258 } 259 260 static OpenMPClauseKind get(const VariantValue &Value) { 261 return *getClauseKind(Value.getString()); 262 } 263 264 static ArgKind getKind() { return ArgKind(ArgKind::AK_String); } 265 266 static llvm::Optional<std::string> getBestGuess(const VariantValue &Value); 267 }; 268 269 template <> struct ArgTypeTraits<UnaryExprOrTypeTrait> { 270 private: 271 static Optional<UnaryExprOrTypeTrait> 272 getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) { 273 if (!ClauseKind.consume_front("UETT_")) 274 return llvm::None; 275 return llvm::StringSwitch<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(llvm::None); 281 } 282 283 public: 284 static bool hasCorrectType(const VariantValue &Value) { 285 return Value.isString(); 286 } 287 static bool hasCorrectValue(const VariantValue& Value) { 288 return getUnaryOrTypeTraitKind(Value.getString()).hasValue(); 289 } 290 291 static UnaryExprOrTypeTrait get(const VariantValue &Value) { 292 return *getUnaryOrTypeTraitKind(Value.getString()); 293 } 294 295 static ArgKind getKind() { return ArgKind(ArgKind::AK_String); } 296 297 static llvm::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. 304 class MatcherDescriptor { 305 public: 306 virtual ~MatcherDescriptor() = default; 307 308 virtual VariantMatcher create(SourceRange NameRange, 309 ArrayRef<ParserValue> Args, 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> 317 buildMatcherCtor(SourceRange NameRange, ArrayRef<ParserValue> Args, 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 352 inline bool isRetKindConvertibleTo(ArrayRef<ASTNodeKind> RetKinds, 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. 372 class FixedArgCountMatcherDescriptor : public MatcherDescriptor { 373 public: 374 using MarshallerType = VariantMatcher (*)(void (*Func)(), 375 StringRef MatcherName, 376 SourceRange NameRange, 377 ArrayRef<ParserValue> Args, 378 Diagnostics *Error); 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. 386 FixedArgCountMatcherDescriptor(MarshallerType Marshaller, void (*Func)(), 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 394 VariantMatcher create(SourceRange NameRange, 395 ArrayRef<ParserValue> Args, 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 414 private: 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. 424 template <class PolyMatcher> 425 static void mergePolyMatchers(const PolyMatcher &Poly, 426 std::vector<DynTypedMatcher> &Out, 427 ast_matchers::internal::EmptyTypeList) {} 428 429 template <class PolyMatcher, class TypeList> 430 static void 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. 442 inline VariantMatcher outvalueToVariantMatcher(const DynTypedMatcher &Matcher) { 443 return VariantMatcher::SingleMatcher(Matcher); 444 } 445 446 template <typename T> 447 static VariantMatcher outvalueToVariantMatcher(const T &PolyMatcher, 448 typename T::ReturnTypes * = 449 nullptr) { 450 std::vector<DynTypedMatcher> Matchers; 451 mergePolyMatchers(PolyMatcher, Matchers, typename T::ReturnTypes()); 452 VariantMatcher Out = VariantMatcher::PolymorphicMatcher(std::move(Matchers)); 453 return Out; 454 } 455 456 template <typename T> 457 inline void 458 buildReturnTypeVectorFromTypeList(std::vector<ASTNodeKind> &RetTypes) { 459 RetTypes.push_back(ASTNodeKind::getFromNodeKind<typename T::head>()); 460 buildReturnTypeVectorFromTypeList<typename T::tail>(RetTypes); 461 } 462 463 template <> 464 inline void 465 buildReturnTypeVectorFromTypeList<ast_matchers::internal::EmptyTypeList>( 466 std::vector<ASTNodeKind> &RetTypes) {} 467 468 template <typename T> 469 struct BuildReturnTypeVector { 470 static void build(std::vector<ASTNodeKind> &RetTypes) { 471 buildReturnTypeVectorFromTypeList<typename T::ReturnTypes>(RetTypes); 472 } 473 }; 474 475 template <typename T> 476 struct BuildReturnTypeVector<ast_matchers::internal::Matcher<T>> { 477 static void build(std::vector<ASTNodeKind> &RetTypes) { 478 RetTypes.push_back(ASTNodeKind::getFromNodeKind<T>()); 479 } 480 }; 481 482 template <typename T> 483 struct BuildReturnTypeVector<ast_matchers::internal::BindableMatcher<T>> { 484 static void build(std::vector<ASTNodeKind> &RetTypes) { 485 RetTypes.push_back(ASTNodeKind::getFromNodeKind<T>()); 486 } 487 }; 488 489 /// Variadic marshaller function. 490 template <typename ResultT, typename ArgT, 491 ResultT (*Func)(ArrayRef<const ArgT *>)> 492 VariantMatcher 493 variadicMatcherDescriptor(StringRef MatcherName, SourceRange NameRange, 494 ArrayRef<ParserValue> Args, Diagnostics *Error) { 495 SmallVector<ArgT *, 8> InnerArgsPtr; 496 InnerArgsPtr.resize_for_overwrite(Args.size()); 497 SmallVector<ArgT, 8> InnerArgs; 498 InnerArgs.reserve(Args.size()); 499 500 for (size_t i = 0, e = Args.size(); i != e; ++i) { 501 using ArgTraits = ArgTypeTraits<ArgT>; 502 503 const ParserValue &Arg = Args[i]; 504 const VariantValue &Value = Arg.Value; 505 if (!ArgTraits::hasCorrectType(Value)) { 506 Error->addError(Arg.Range, Error->ET_RegistryWrongArgType) 507 << (i + 1) << ArgTraits::getKind().asString() << Value.getTypeAsString(); 508 return {}; 509 } 510 if (!ArgTraits::hasCorrectValue(Value)) { 511 if (llvm::Optional<std::string> BestGuess = 512 ArgTraits::getBestGuess(Value)) { 513 Error->addError(Arg.Range, Error->ET_RegistryUnknownEnumWithReplace) 514 << i + 1 << Value.getString() << *BestGuess; 515 } else if (Value.isString()) { 516 Error->addError(Arg.Range, Error->ET_RegistryValueNotFound) 517 << Value.getString(); 518 } else { 519 // This isn't ideal, but it's better than reporting an empty string as 520 // the error in this case. 521 Error->addError(Arg.Range, Error->ET_RegistryWrongArgType) 522 << (i + 1) << ArgTraits::getKind().asString() 523 << Value.getTypeAsString(); 524 } 525 return {}; 526 } 527 InnerArgs.set_size(i + 1); 528 InnerArgsPtr[i] = new (&InnerArgs[i]) ArgT(ArgTraits::get(Value)); 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. 540 class VariadicFuncMatcherDescriptor : public MatcherDescriptor { 541 public: 542 using RunFunc = VariantMatcher (*)(StringRef MatcherName, 543 SourceRange NameRange, 544 ArrayRef<ParserValue> Args, 545 Diagnostics *Error); 546 547 template <typename ResultT, typename ArgT, 548 ResultT (*F)(ArrayRef<const ArgT *>)> 549 VariadicFuncMatcherDescriptor( 550 ast_matchers::internal::VariadicFunction<ResultT, ArgT, F> Func, 551 StringRef MatcherName) 552 : Func(&variadicMatcherDescriptor<ResultT, ArgT, F>), 553 MatcherName(MatcherName.str()), 554 ArgsKind(ArgTypeTraits<ArgT>::getKind()) { 555 BuildReturnTypeVector<ResultT>::build(RetKinds); 556 } 557 558 VariantMatcher create(SourceRange NameRange, 559 ArrayRef<ParserValue> Args, 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 580 private: 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. 588 class DynCastAllOfMatcherDescriptor : public VariadicFuncMatcherDescriptor { 589 public: 590 template <typename BaseT, typename DerivedT> 591 DynCastAllOfMatcherDescriptor( 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. 603 if (VariadicFuncMatcherDescriptor::isConvertibleTo(Kind, Specificity, 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 617 private: 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 (llvm::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. 650 template <typename ReturnType> 651 static VariantMatcher matcherMarshall0(void (*Func)(), StringRef MatcherName, 652 SourceRange NameRange, 653 ArrayRef<ParserValue> Args, 654 Diagnostics *Error) { 655 using FuncType = ReturnType (*)(); 656 CHECK_ARG_COUNT(0); 657 return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)()); 658 } 659 660 /// 1-arg marshaller function. 661 template <typename ReturnType, typename ArgType1> 662 static VariantMatcher matcherMarshall1(void (*Func)(), StringRef MatcherName, 663 SourceRange NameRange, 664 ArrayRef<ParserValue> Args, 665 Diagnostics *Error) { 666 using FuncType = ReturnType (*)(ArgType1); 667 CHECK_ARG_COUNT(1); 668 CHECK_ARG_TYPE(0, ArgType1); 669 return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)( 670 ArgTypeTraits<ArgType1>::get(Args[0].Value))); 671 } 672 673 /// 2-arg marshaller function. 674 template <typename ReturnType, typename ArgType1, typename ArgType2> 675 static VariantMatcher matcherMarshall2(void (*Func)(), StringRef MatcherName, 676 SourceRange NameRange, 677 ArrayRef<ParserValue> Args, 678 Diagnostics *Error) { 679 using FuncType = ReturnType (*)(ArgType1, ArgType2); 680 CHECK_ARG_COUNT(2); 681 CHECK_ARG_TYPE(0, ArgType1); 682 CHECK_ARG_TYPE(1, ArgType2); 683 return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)( 684 ArgTypeTraits<ArgType1>::get(Args[0].Value), 685 ArgTypeTraits<ArgType2>::get(Args[1].Value))); 686 } 687 688 #undef CHECK_ARG_COUNT 689 #undef CHECK_ARG_TYPE 690 691 /// Helper class used to collect all the possible overloads of an 692 /// argument adaptative matcher function. 693 template <template <typename ToArg, typename FromArg> class ArgumentAdapterT, 694 typename FromTypes, typename ToTypes> 695 class AdaptativeOverloadCollector { 696 public: 697 AdaptativeOverloadCollector( 698 StringRef Name, std::vector<std::unique_ptr<MatcherDescriptor>> &Out) 699 : Name(Name), Out(Out) { 700 collect(FromTypes()); 701 } 702 703 private: 704 using AdaptativeFunc = ast_matchers::internal::ArgumentAdaptingMatcherFunc< 705 ArgumentAdapterT, FromTypes, ToTypes>; 706 707 /// End case for the recursion 708 static void collect(ast_matchers::internal::EmptyTypeList) {} 709 710 /// Recursive case. Get the overload for the head of the list, and 711 /// recurse to the tail. 712 template <typename FromTypeList> 713 inline void collect(FromTypeList); 714 715 StringRef Name; 716 std::vector<std::unique_ptr<MatcherDescriptor>> &Out; 717 }; 718 719 /// MatcherDescriptor that wraps multiple "overloads" of the same 720 /// matcher. 721 /// 722 /// It will try every overload and generate appropriate errors for when none or 723 /// more than one overloads match the arguments. 724 class OverloadedMatcherDescriptor : public MatcherDescriptor { 725 public: 726 OverloadedMatcherDescriptor( 727 MutableArrayRef<std::unique_ptr<MatcherDescriptor>> Callbacks) 728 : Overloads(std::make_move_iterator(Callbacks.begin()), 729 std::make_move_iterator(Callbacks.end())) {} 730 731 ~OverloadedMatcherDescriptor() override = default; 732 733 VariantMatcher create(SourceRange NameRange, 734 ArrayRef<ParserValue> Args, 735 Diagnostics *Error) const override { 736 std::vector<VariantMatcher> Constructed; 737 Diagnostics::OverloadContext Ctx(Error); 738 for (const auto &O : Overloads) { 739 VariantMatcher SubMatcher = O->create(NameRange, Args, Error); 740 if (!SubMatcher.isNull()) { 741 Constructed.push_back(SubMatcher); 742 } 743 } 744 745 if (Constructed.empty()) return VariantMatcher(); // No overload matched. 746 // We ignore the errors if any matcher succeeded. 747 Ctx.revertErrors(); 748 if (Constructed.size() > 1) { 749 // More than one constructed. It is ambiguous. 750 Error->addError(NameRange, Error->ET_RegistryAmbiguousOverload); 751 return VariantMatcher(); 752 } 753 return Constructed[0]; 754 } 755 756 bool isVariadic() const override { 757 bool Overload0Variadic = Overloads[0]->isVariadic(); 758 #ifndef NDEBUG 759 for (const auto &O : Overloads) { 760 assert(Overload0Variadic == O->isVariadic()); 761 } 762 #endif 763 return Overload0Variadic; 764 } 765 766 unsigned getNumArgs() const override { 767 unsigned Overload0NumArgs = Overloads[0]->getNumArgs(); 768 #ifndef NDEBUG 769 for (const auto &O : Overloads) { 770 assert(Overload0NumArgs == O->getNumArgs()); 771 } 772 #endif 773 return Overload0NumArgs; 774 } 775 776 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, 777 std::vector<ArgKind> &Kinds) const override { 778 for (const auto &O : Overloads) { 779 if (O->isConvertibleTo(ThisKind)) 780 O->getArgKinds(ThisKind, ArgNo, Kinds); 781 } 782 } 783 784 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, 785 ASTNodeKind *LeastDerivedKind) const override { 786 for (const auto &O : Overloads) { 787 if (O->isConvertibleTo(Kind, Specificity, LeastDerivedKind)) 788 return true; 789 } 790 return false; 791 } 792 793 private: 794 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads; 795 }; 796 797 template <typename ReturnType> 798 class RegexMatcherDescriptor : public MatcherDescriptor { 799 public: 800 RegexMatcherDescriptor(ReturnType (*WithFlags)(StringRef, 801 llvm::Regex::RegexFlags), 802 ReturnType (*NoFlags)(StringRef), 803 ArrayRef<ASTNodeKind> RetKinds) 804 : WithFlags(WithFlags), NoFlags(NoFlags), 805 RetKinds(RetKinds.begin(), RetKinds.end()) {} 806 bool isVariadic() const override { return true; } 807 unsigned getNumArgs() const override { return 0; } 808 809 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, 810 std::vector<ArgKind> &Kinds) const override { 811 assert(ArgNo < 2); 812 Kinds.push_back(ArgKind::AK_String); 813 } 814 815 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, 816 ASTNodeKind *LeastDerivedKind) const override { 817 return isRetKindConvertibleTo(RetKinds, Kind, Specificity, 818 LeastDerivedKind); 819 } 820 821 VariantMatcher create(SourceRange NameRange, ArrayRef<ParserValue> Args, 822 Diagnostics *Error) const override { 823 if (Args.size() < 1 || Args.size() > 2) { 824 Error->addError(NameRange, Diagnostics::ET_RegistryWrongArgCount) 825 << "1 or 2" << Args.size(); 826 return VariantMatcher(); 827 } 828 if (!ArgTypeTraits<StringRef>::hasCorrectType(Args[0].Value)) { 829 Error->addError(Args[0].Range, Error->ET_RegistryWrongArgType) 830 << 1 << ArgTypeTraits<StringRef>::getKind().asString() 831 << Args[0].Value.getTypeAsString(); 832 return VariantMatcher(); 833 } 834 if (Args.size() == 1) { 835 return outvalueToVariantMatcher( 836 NoFlags(ArgTypeTraits<StringRef>::get(Args[0].Value))); 837 } 838 if (!ArgTypeTraits<llvm::Regex::RegexFlags>::hasCorrectType( 839 Args[1].Value)) { 840 Error->addError(Args[1].Range, Error->ET_RegistryWrongArgType) 841 << 2 << ArgTypeTraits<llvm::Regex::RegexFlags>::getKind().asString() 842 << Args[1].Value.getTypeAsString(); 843 return VariantMatcher(); 844 } 845 if (!ArgTypeTraits<llvm::Regex::RegexFlags>::hasCorrectValue( 846 Args[1].Value)) { 847 if (llvm::Optional<std::string> BestGuess = 848 ArgTypeTraits<llvm::Regex::RegexFlags>::getBestGuess( 849 Args[1].Value)) { 850 Error->addError(Args[1].Range, Error->ET_RegistryUnknownEnumWithReplace) 851 << 2 << Args[1].Value.getString() << *BestGuess; 852 } else { 853 Error->addError(Args[1].Range, Error->ET_RegistryValueNotFound) 854 << Args[1].Value.getString(); 855 } 856 return VariantMatcher(); 857 } 858 return outvalueToVariantMatcher( 859 WithFlags(ArgTypeTraits<StringRef>::get(Args[0].Value), 860 ArgTypeTraits<llvm::Regex::RegexFlags>::get(Args[1].Value))); 861 } 862 863 private: 864 ReturnType (*const WithFlags)(StringRef, llvm::Regex::RegexFlags); 865 ReturnType (*const NoFlags)(StringRef); 866 const std::vector<ASTNodeKind> RetKinds; 867 }; 868 869 /// Variadic operator marshaller function. 870 class VariadicOperatorMatcherDescriptor : public MatcherDescriptor { 871 public: 872 using VarOp = DynTypedMatcher::VariadicOperator; 873 874 VariadicOperatorMatcherDescriptor(unsigned MinCount, unsigned MaxCount, 875 VarOp Op, StringRef MatcherName) 876 : MinCount(MinCount), MaxCount(MaxCount), Op(Op), 877 MatcherName(MatcherName) {} 878 879 VariantMatcher create(SourceRange NameRange, 880 ArrayRef<ParserValue> Args, 881 Diagnostics *Error) const override { 882 if (Args.size() < MinCount || MaxCount < Args.size()) { 883 const std::string MaxStr = 884 (MaxCount == std::numeric_limits<unsigned>::max() ? "" 885 : Twine(MaxCount)) 886 .str(); 887 Error->addError(NameRange, Error->ET_RegistryWrongArgCount) 888 << ("(" + Twine(MinCount) + ", " + MaxStr + ")") << Args.size(); 889 return VariantMatcher(); 890 } 891 892 std::vector<VariantMatcher> InnerArgs; 893 for (size_t i = 0, e = Args.size(); i != e; ++i) { 894 const ParserValue &Arg = Args[i]; 895 const VariantValue &Value = Arg.Value; 896 if (!Value.isMatcher()) { 897 Error->addError(Arg.Range, Error->ET_RegistryWrongArgType) 898 << (i + 1) << "Matcher<>" << Value.getTypeAsString(); 899 return VariantMatcher(); 900 } 901 InnerArgs.push_back(Value.getMatcher()); 902 } 903 return VariantMatcher::VariadicOperatorMatcher(Op, std::move(InnerArgs)); 904 } 905 906 bool isVariadic() const override { return true; } 907 unsigned getNumArgs() const override { return 0; } 908 909 void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo, 910 std::vector<ArgKind> &Kinds) const override { 911 Kinds.push_back(ArgKind::MakeMatcherArg(ThisKind)); 912 } 913 914 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, 915 ASTNodeKind *LeastDerivedKind) const override { 916 if (Specificity) 917 *Specificity = 1; 918 if (LeastDerivedKind) 919 *LeastDerivedKind = Kind; 920 return true; 921 } 922 923 bool isPolymorphic() const override { return true; } 924 925 private: 926 const unsigned MinCount; 927 const unsigned MaxCount; 928 const VarOp Op; 929 const StringRef MatcherName; 930 }; 931 932 class MapAnyOfMatcherDescriptor : public MatcherDescriptor { 933 ASTNodeKind CladeNodeKind; 934 std::vector<ASTNodeKind> NodeKinds; 935 936 public: 937 MapAnyOfMatcherDescriptor(ASTNodeKind CladeNodeKind, 938 std::vector<ASTNodeKind> NodeKinds) 939 : CladeNodeKind(CladeNodeKind), NodeKinds(NodeKinds) {} 940 941 VariantMatcher create(SourceRange NameRange, ArrayRef<ParserValue> Args, 942 Diagnostics *Error) const override { 943 944 std::vector<DynTypedMatcher> NodeArgs; 945 946 for (auto NK : NodeKinds) { 947 std::vector<DynTypedMatcher> InnerArgs; 948 949 for (const auto &Arg : Args) { 950 if (!Arg.Value.isMatcher()) 951 return {}; 952 const VariantMatcher &VM = Arg.Value.getMatcher(); 953 if (VM.hasTypedMatcher(NK)) { 954 auto DM = VM.getTypedMatcher(NK); 955 InnerArgs.push_back(DM); 956 } 957 } 958 959 if (InnerArgs.empty()) { 960 NodeArgs.push_back( 961 DynTypedMatcher::trueMatcher(NK).dynCastTo(CladeNodeKind)); 962 } else { 963 NodeArgs.push_back( 964 DynTypedMatcher::constructVariadic( 965 ast_matchers::internal::DynTypedMatcher::VO_AllOf, NK, 966 InnerArgs) 967 .dynCastTo(CladeNodeKind)); 968 } 969 } 970 971 auto Result = DynTypedMatcher::constructVariadic( 972 ast_matchers::internal::DynTypedMatcher::VO_AnyOf, CladeNodeKind, 973 NodeArgs); 974 Result.setAllowBind(true); 975 return VariantMatcher::SingleMatcher(Result); 976 } 977 978 bool isVariadic() const override { return true; } 979 unsigned getNumArgs() const override { return 0; } 980 981 void getArgKinds(ASTNodeKind ThisKind, unsigned, 982 std::vector<ArgKind> &Kinds) const override { 983 Kinds.push_back(ArgKind::MakeMatcherArg(ThisKind)); 984 } 985 986 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity, 987 ASTNodeKind *LeastDerivedKind) const override { 988 if (Specificity) 989 *Specificity = 1; 990 if (LeastDerivedKind) 991 *LeastDerivedKind = CladeNodeKind; 992 return true; 993 } 994 }; 995 996 class MapAnyOfBuilderDescriptor : public MatcherDescriptor { 997 public: 998 VariantMatcher create(SourceRange, ArrayRef<ParserValue>, 999 Diagnostics *) const override { 1000 return {}; 1001 } 1002 1003 bool isBuilderMatcher() const override { return true; } 1004 1005 std::unique_ptr<MatcherDescriptor> 1006 buildMatcherCtor(SourceRange, ArrayRef<ParserValue> Args, 1007 Diagnostics *) const override { 1008 1009 std::vector<ASTNodeKind> NodeKinds; 1010 for (auto Arg : Args) { 1011 if (!Arg.Value.isNodeKind()) 1012 return {}; 1013 NodeKinds.push_back(Arg.Value.getNodeKind()); 1014 } 1015 1016 if (NodeKinds.empty()) 1017 return {}; 1018 1019 ASTNodeKind CladeNodeKind = NodeKinds.front().getCladeKind(); 1020 1021 for (auto NK : NodeKinds) 1022 { 1023 if (!NK.getCladeKind().isSame(CladeNodeKind)) 1024 return {}; 1025 } 1026 1027 return std::make_unique<MapAnyOfMatcherDescriptor>(CladeNodeKind, 1028 NodeKinds); 1029 } 1030 1031 bool isVariadic() const override { return true; } 1032 1033 unsigned getNumArgs() const override { return 0; } 1034 1035 void getArgKinds(ASTNodeKind ThisKind, unsigned, 1036 std::vector<ArgKind> &ArgKinds) const override { 1037 ArgKinds.push_back(ArgKind::MakeNodeArg(ThisKind)); 1038 return; 1039 } 1040 bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity = nullptr, 1041 ASTNodeKind *LeastDerivedKind = nullptr) const override { 1042 if (Specificity) 1043 *Specificity = 1; 1044 if (LeastDerivedKind) 1045 *LeastDerivedKind = Kind; 1046 return true; 1047 } 1048 1049 bool isPolymorphic() const override { return false; } 1050 }; 1051 1052 /// Helper functions to select the appropriate marshaller functions. 1053 /// They detect the number of arguments, arguments types and return type. 1054 1055 /// 0-arg overload 1056 template <typename ReturnType> 1057 std::unique_ptr<MatcherDescriptor> 1058 makeMatcherAutoMarshall(ReturnType (*Func)(), StringRef MatcherName) { 1059 std::vector<ASTNodeKind> RetTypes; 1060 BuildReturnTypeVector<ReturnType>::build(RetTypes); 1061 return std::make_unique<FixedArgCountMatcherDescriptor>( 1062 matcherMarshall0<ReturnType>, reinterpret_cast<void (*)()>(Func), 1063 MatcherName, RetTypes, None); 1064 } 1065 1066 /// 1-arg overload 1067 template <typename ReturnType, typename ArgType1> 1068 std::unique_ptr<MatcherDescriptor> 1069 makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1), StringRef MatcherName) { 1070 std::vector<ASTNodeKind> RetTypes; 1071 BuildReturnTypeVector<ReturnType>::build(RetTypes); 1072 ArgKind AK = ArgTypeTraits<ArgType1>::getKind(); 1073 return std::make_unique<FixedArgCountMatcherDescriptor>( 1074 matcherMarshall1<ReturnType, ArgType1>, 1075 reinterpret_cast<void (*)()>(Func), MatcherName, RetTypes, AK); 1076 } 1077 1078 /// 2-arg overload 1079 template <typename ReturnType, typename ArgType1, typename ArgType2> 1080 std::unique_ptr<MatcherDescriptor> 1081 makeMatcherAutoMarshall(ReturnType (*Func)(ArgType1, ArgType2), 1082 StringRef MatcherName) { 1083 std::vector<ASTNodeKind> RetTypes; 1084 BuildReturnTypeVector<ReturnType>::build(RetTypes); 1085 ArgKind AKs[] = { ArgTypeTraits<ArgType1>::getKind(), 1086 ArgTypeTraits<ArgType2>::getKind() }; 1087 return std::make_unique<FixedArgCountMatcherDescriptor>( 1088 matcherMarshall2<ReturnType, ArgType1, ArgType2>, 1089 reinterpret_cast<void (*)()>(Func), MatcherName, RetTypes, AKs); 1090 } 1091 1092 template <typename ReturnType> 1093 std::unique_ptr<MatcherDescriptor> makeMatcherRegexMarshall( 1094 ReturnType (*FuncFlags)(llvm::StringRef, llvm::Regex::RegexFlags), 1095 ReturnType (*Func)(llvm::StringRef)) { 1096 std::vector<ASTNodeKind> RetTypes; 1097 BuildReturnTypeVector<ReturnType>::build(RetTypes); 1098 return std::make_unique<RegexMatcherDescriptor<ReturnType>>(FuncFlags, Func, 1099 RetTypes); 1100 } 1101 1102 /// Variadic overload. 1103 template <typename ResultT, typename ArgT, 1104 ResultT (*Func)(ArrayRef<const ArgT *>)> 1105 std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall( 1106 ast_matchers::internal::VariadicFunction<ResultT, ArgT, Func> VarFunc, 1107 StringRef MatcherName) { 1108 return std::make_unique<VariadicFuncMatcherDescriptor>(VarFunc, MatcherName); 1109 } 1110 1111 /// Overload for VariadicDynCastAllOfMatchers. 1112 /// 1113 /// Not strictly necessary, but DynCastAllOfMatcherDescriptor gives us better 1114 /// completion results for that type of matcher. 1115 template <typename BaseT, typename DerivedT> 1116 std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall( 1117 ast_matchers::internal::VariadicDynCastAllOfMatcher<BaseT, DerivedT> 1118 VarFunc, 1119 StringRef MatcherName) { 1120 return std::make_unique<DynCastAllOfMatcherDescriptor>(VarFunc, MatcherName); 1121 } 1122 1123 /// Argument adaptative overload. 1124 template <template <typename ToArg, typename FromArg> class ArgumentAdapterT, 1125 typename FromTypes, typename ToTypes> 1126 std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall( 1127 ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT, 1128 FromTypes, ToTypes>, 1129 StringRef MatcherName) { 1130 std::vector<std::unique_ptr<MatcherDescriptor>> Overloads; 1131 AdaptativeOverloadCollector<ArgumentAdapterT, FromTypes, ToTypes>(MatcherName, 1132 Overloads); 1133 return std::make_unique<OverloadedMatcherDescriptor>(Overloads); 1134 } 1135 1136 template <template <typename ToArg, typename FromArg> class ArgumentAdapterT, 1137 typename FromTypes, typename ToTypes> 1138 template <typename FromTypeList> 1139 inline void AdaptativeOverloadCollector<ArgumentAdapterT, FromTypes, 1140 ToTypes>::collect(FromTypeList) { 1141 Out.push_back(makeMatcherAutoMarshall( 1142 &AdaptativeFunc::template create<typename FromTypeList::head>, Name)); 1143 collect(typename FromTypeList::tail()); 1144 } 1145 1146 /// Variadic operator overload. 1147 template <unsigned MinCount, unsigned MaxCount> 1148 std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall( 1149 ast_matchers::internal::VariadicOperatorMatcherFunc<MinCount, MaxCount> 1150 Func, 1151 StringRef MatcherName) { 1152 return std::make_unique<VariadicOperatorMatcherDescriptor>( 1153 MinCount, MaxCount, Func.Op, MatcherName); 1154 } 1155 1156 template <typename CladeType, typename... MatcherT> 1157 std::unique_ptr<MatcherDescriptor> makeMatcherAutoMarshall( 1158 ast_matchers::internal::MapAnyOfMatcherImpl<CladeType, MatcherT...>, 1159 StringRef MatcherName) { 1160 return std::make_unique<MapAnyOfMatcherDescriptor>( 1161 ASTNodeKind::getFromNodeKind<CladeType>(), 1162 std::vector<ASTNodeKind>{ASTNodeKind::getFromNodeKind<MatcherT>()...}); 1163 } 1164 1165 } // namespace internal 1166 } // namespace dynamic 1167 } // namespace ast_matchers 1168 } // namespace clang 1169 1170 #endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_MARSHALLERS_H 1171