xref: /llvm-project/clang/lib/ASTMatchers/Dynamic/Registry.cpp (revision 1ca258e6a89203d8b74db740f98b32b5925b6bbb)
1 //===--- Registry.cpp - Matcher registry -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Registry map populated at static initialization time.
12 ///
13 //===------------------------------------------------------------===//
14 
15 #include "clang/ASTMatchers/Dynamic/Registry.h"
16 #include "Marshallers.h"
17 #include "clang/ASTMatchers/ASTMatchers.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/ManagedStatic.h"
21 #include <set>
22 #include <utility>
23 
24 using namespace clang::ast_type_traits;
25 
26 namespace clang {
27 namespace ast_matchers {
28 namespace dynamic {
29 namespace {
30 
31 using internal::MatcherDescriptor;
32 
33 typedef llvm::StringMap<const MatcherDescriptor *> ConstructorMap;
34 class RegistryMaps {
35 public:
36   RegistryMaps();
37   ~RegistryMaps();
38 
39   const ConstructorMap &constructors() const { return Constructors; }
40 
41 private:
42   void registerMatcher(StringRef MatcherName, MatcherDescriptor *Callback);
43   ConstructorMap Constructors;
44 };
45 
46 void RegistryMaps::registerMatcher(StringRef MatcherName,
47                                    MatcherDescriptor *Callback) {
48   assert(Constructors.find(MatcherName) == Constructors.end());
49   Constructors[MatcherName] = Callback;
50 }
51 
52 #define REGISTER_MATCHER(name)                                                 \
53   registerMatcher(#name, internal::makeMatcherAutoMarshall(                    \
54                              ::clang::ast_matchers::name, #name));
55 
56 #define SPECIFIC_MATCHER_OVERLOAD(name, Id)                                    \
57   static_cast< ::clang::ast_matchers::name##_Type##Id>(                        \
58       ::clang::ast_matchers::name)
59 
60 #define REGISTER_OVERLOADED_2(name)                                            \
61   do {                                                                         \
62     MatcherDescriptor *Callbacks[] = {                                         \
63       internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 0),    \
64                                         #name),                                \
65       internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 1),    \
66                                         #name)                                 \
67     };                                                                         \
68     registerMatcher(#name,                                                     \
69                     new internal::OverloadedMatcherDescriptor(Callbacks));     \
70   } while (0)
71 
72 /// \brief Generate a registry map with all the known matchers.
73 RegistryMaps::RegistryMaps() {
74   // TODO: Here is the list of the missing matchers, grouped by reason.
75   //
76   // Need Variant/Parser fixes:
77   // ofKind
78   //
79   // Polymorphic + argument overload:
80   // findAll
81   //
82   // Other:
83   // equals
84   // equalsNode
85 
86   REGISTER_OVERLOADED_2(callee);
87   REGISTER_OVERLOADED_2(hasPrefix);
88   REGISTER_OVERLOADED_2(hasType);
89   REGISTER_OVERLOADED_2(isDerivedFrom);
90   REGISTER_OVERLOADED_2(isSameOrDerivedFrom);
91   REGISTER_OVERLOADED_2(loc);
92   REGISTER_OVERLOADED_2(pointsTo);
93   REGISTER_OVERLOADED_2(references);
94   REGISTER_OVERLOADED_2(thisPointerType);
95 
96   REGISTER_MATCHER(accessSpecDecl);
97   REGISTER_MATCHER(alignOfExpr);
98   REGISTER_MATCHER(allOf);
99   REGISTER_MATCHER(anyOf);
100   REGISTER_MATCHER(anything);
101   REGISTER_MATCHER(argumentCountIs);
102   REGISTER_MATCHER(arraySubscriptExpr);
103   REGISTER_MATCHER(arrayType);
104   REGISTER_MATCHER(asmStmt);
105   REGISTER_MATCHER(asString);
106   REGISTER_MATCHER(atomicType);
107   REGISTER_MATCHER(autoType);
108   REGISTER_MATCHER(binaryOperator);
109   REGISTER_MATCHER(bindTemporaryExpr);
110   REGISTER_MATCHER(blockPointerType);
111   REGISTER_MATCHER(boolLiteral);
112   REGISTER_MATCHER(breakStmt);
113   REGISTER_MATCHER(builtinType);
114   REGISTER_MATCHER(callExpr);
115   REGISTER_MATCHER(caseStmt);
116   REGISTER_MATCHER(castExpr);
117   REGISTER_MATCHER(catchStmt);
118   REGISTER_MATCHER(characterLiteral);
119   REGISTER_MATCHER(classTemplateDecl);
120   REGISTER_MATCHER(classTemplateSpecializationDecl);
121   REGISTER_MATCHER(complexType);
122   REGISTER_MATCHER(compoundLiteralExpr);
123   REGISTER_MATCHER(compoundStmt);
124   REGISTER_MATCHER(conditionalOperator);
125   REGISTER_MATCHER(constantArrayType);
126   REGISTER_MATCHER(constCastExpr);
127   REGISTER_MATCHER(constructExpr);
128   REGISTER_MATCHER(constructorDecl);
129   REGISTER_MATCHER(containsDeclaration);
130   REGISTER_MATCHER(continueStmt);
131   REGISTER_MATCHER(conversionDecl);
132   REGISTER_MATCHER(cStyleCastExpr);
133   REGISTER_MATCHER(ctorInitializer);
134   REGISTER_MATCHER(CUDAKernelCallExpr);
135   REGISTER_MATCHER(decl);
136   REGISTER_MATCHER(declaratorDecl);
137   REGISTER_MATCHER(declCountIs);
138   REGISTER_MATCHER(declRefExpr);
139   REGISTER_MATCHER(declStmt);
140   REGISTER_MATCHER(defaultArgExpr);
141   REGISTER_MATCHER(defaultStmt);
142   REGISTER_MATCHER(deleteExpr);
143   REGISTER_MATCHER(dependentSizedArrayType);
144   REGISTER_MATCHER(destructorDecl);
145   REGISTER_MATCHER(doStmt);
146   REGISTER_MATCHER(dynamicCastExpr);
147   REGISTER_MATCHER(eachOf);
148   REGISTER_MATCHER(elaboratedType);
149   REGISTER_MATCHER(enumConstantDecl);
150   REGISTER_MATCHER(enumDecl);
151   REGISTER_MATCHER(equalsBoundNode);
152   REGISTER_MATCHER(equalsIntegralValue);
153   REGISTER_MATCHER(explicitCastExpr);
154   REGISTER_MATCHER(expr);
155   REGISTER_MATCHER(exprWithCleanups);
156   REGISTER_MATCHER(fieldDecl);
157   REGISTER_MATCHER(floatLiteral);
158   REGISTER_MATCHER(forEach);
159   REGISTER_MATCHER(forEachConstructorInitializer);
160   REGISTER_MATCHER(forEachDescendant);
161   REGISTER_MATCHER(forEachSwitchCase);
162   REGISTER_MATCHER(forField);
163   REGISTER_MATCHER(forRangeStmt);
164   REGISTER_MATCHER(forStmt);
165   REGISTER_MATCHER(friendDecl);
166   REGISTER_MATCHER(functionalCastExpr);
167   REGISTER_MATCHER(functionDecl);
168   REGISTER_MATCHER(functionTemplateDecl);
169   REGISTER_MATCHER(functionType);
170   REGISTER_MATCHER(gotoStmt);
171   REGISTER_MATCHER(has);
172   REGISTER_MATCHER(hasAncestor);
173   REGISTER_MATCHER(hasAnyArgument);
174   REGISTER_MATCHER(hasAnyConstructorInitializer);
175   REGISTER_MATCHER(hasAnyParameter);
176   REGISTER_MATCHER(hasAnySubstatement);
177   REGISTER_MATCHER(hasAnyTemplateArgument);
178   REGISTER_MATCHER(hasAnyUsingShadowDecl);
179   REGISTER_MATCHER(hasArgument);
180   REGISTER_MATCHER(hasArgumentOfType);
181   REGISTER_MATCHER(hasAttr);
182   REGISTER_MATCHER(hasBase);
183   REGISTER_MATCHER(hasBody);
184   REGISTER_MATCHER(hasCanonicalType);
185   REGISTER_MATCHER(hasCaseConstant);
186   REGISTER_MATCHER(hasCondition);
187   REGISTER_MATCHER(hasConditionVariableStatement);
188   REGISTER_MATCHER(hasDeclaration);
189   REGISTER_MATCHER(hasDeclContext);
190   REGISTER_MATCHER(hasDeducedType);
191   REGISTER_MATCHER(hasDescendant);
192   REGISTER_MATCHER(hasDestinationType);
193   REGISTER_MATCHER(hasEitherOperand);
194   REGISTER_MATCHER(hasElementType);
195   REGISTER_MATCHER(hasElse);
196   REGISTER_MATCHER(hasFalseExpression);
197   REGISTER_MATCHER(hasGlobalStorage);
198   REGISTER_MATCHER(hasImplicitDestinationType);
199   REGISTER_MATCHER(hasIncrement);
200   REGISTER_MATCHER(hasIndex);
201   REGISTER_MATCHER(hasInitializer);
202   REGISTER_MATCHER(hasKeywordSelector);
203   REGISTER_MATCHER(hasLHS);
204   REGISTER_MATCHER(hasLocalQualifiers);
205   REGISTER_MATCHER(hasLocalStorage);
206   REGISTER_MATCHER(hasLoopInit);
207   REGISTER_MATCHER(hasLoopVariable);
208   REGISTER_MATCHER(hasMethod);
209   REGISTER_MATCHER(hasName);
210   REGISTER_MATCHER(hasNullSelector);
211   REGISTER_MATCHER(hasObjectExpression);
212   REGISTER_MATCHER(hasOperatorName);
213   REGISTER_MATCHER(hasOverloadedOperatorName);
214   REGISTER_MATCHER(hasParameter);
215   REGISTER_MATCHER(hasParent);
216   REGISTER_MATCHER(hasQualifier);
217   REGISTER_MATCHER(hasRangeInit);
218   REGISTER_MATCHER(hasReceiverType);
219   REGISTER_MATCHER(hasRHS);
220   REGISTER_MATCHER(hasSelector);
221   REGISTER_MATCHER(hasSingleDecl);
222   REGISTER_MATCHER(hasSize);
223   REGISTER_MATCHER(hasSizeExpr);
224   REGISTER_MATCHER(hasSourceExpression);
225   REGISTER_MATCHER(hasTargetDecl);
226   REGISTER_MATCHER(hasTemplateArgument);
227   REGISTER_MATCHER(hasThen);
228   REGISTER_MATCHER(hasTrueExpression);
229   REGISTER_MATCHER(hasTypeLoc);
230   REGISTER_MATCHER(hasUnaryOperand);
231   REGISTER_MATCHER(hasUnarySelector);
232   REGISTER_MATCHER(hasValueType);
233   REGISTER_MATCHER(ifStmt);
234   REGISTER_MATCHER(ignoringImpCasts);
235   REGISTER_MATCHER(ignoringParenCasts);
236   REGISTER_MATCHER(ignoringParenImpCasts);
237   REGISTER_MATCHER(implicitCastExpr);
238   REGISTER_MATCHER(incompleteArrayType);
239   REGISTER_MATCHER(initListExpr);
240   REGISTER_MATCHER(innerType);
241   REGISTER_MATCHER(integerLiteral);
242   REGISTER_MATCHER(isArrow);
243   REGISTER_MATCHER(isBaseInitializer);
244   REGISTER_MATCHER(isCatchAll);
245   REGISTER_MATCHER(isConst);
246   REGISTER_MATCHER(isConstQualified);
247   REGISTER_MATCHER(isCopyConstructor);
248   REGISTER_MATCHER(isDefaultConstructor);
249   REGISTER_MATCHER(isDefinition);
250   REGISTER_MATCHER(isDeleted);
251   REGISTER_MATCHER(isExceptionVariable);
252   REGISTER_MATCHER(isExplicitTemplateSpecialization);
253   REGISTER_MATCHER(isExpr);
254   REGISTER_MATCHER(isExternC);
255   REGISTER_MATCHER(isFinal);
256   REGISTER_MATCHER(isImplicit);
257   REGISTER_MATCHER(isExpansionInFileMatching);
258   REGISTER_MATCHER(isExpansionInMainFile);
259   REGISTER_MATCHER(isInstantiated);
260   REGISTER_MATCHER(isExpansionInSystemHeader);
261   REGISTER_MATCHER(isInteger);
262   REGISTER_MATCHER(isIntegral);
263   REGISTER_MATCHER(isInTemplateInstantiation);
264   REGISTER_MATCHER(isListInitialization);
265   REGISTER_MATCHER(isMoveConstructor);
266   REGISTER_MATCHER(isOverride);
267   REGISTER_MATCHER(isPrivate);
268   REGISTER_MATCHER(isProtected);
269   REGISTER_MATCHER(isPublic);
270   REGISTER_MATCHER(isPure);
271   REGISTER_MATCHER(isTemplateInstantiation);
272   REGISTER_MATCHER(isVirtual);
273   REGISTER_MATCHER(isWritten);
274   REGISTER_MATCHER(labelStmt);
275   REGISTER_MATCHER(lambdaExpr);
276   REGISTER_MATCHER(lValueReferenceType);
277   REGISTER_MATCHER(matchesName);
278   REGISTER_MATCHER(matchesSelector);
279   REGISTER_MATCHER(materializeTemporaryExpr);
280   REGISTER_MATCHER(member);
281   REGISTER_MATCHER(memberCallExpr);
282   REGISTER_MATCHER(memberExpr);
283   REGISTER_MATCHER(memberPointerType);
284   REGISTER_MATCHER(methodDecl);
285   REGISTER_MATCHER(namedDecl);
286   REGISTER_MATCHER(namespaceDecl);
287   REGISTER_MATCHER(namesType);
288   REGISTER_MATCHER(nestedNameSpecifier);
289   REGISTER_MATCHER(nestedNameSpecifierLoc);
290   REGISTER_MATCHER(newExpr);
291   REGISTER_MATCHER(nullPtrLiteralExpr);
292   REGISTER_MATCHER(nullStmt);
293   REGISTER_MATCHER(numSelectorArgs);
294   REGISTER_MATCHER(ofClass);
295   REGISTER_MATCHER(objcMessageExpr);
296   REGISTER_MATCHER(on);
297   REGISTER_MATCHER(onImplicitObjectArgument);
298   REGISTER_MATCHER(operatorCallExpr);
299   REGISTER_MATCHER(parameterCountIs);
300   REGISTER_MATCHER(parenType);
301   REGISTER_MATCHER(parmVarDecl);
302   REGISTER_MATCHER(pointee);
303   REGISTER_MATCHER(pointerType);
304   REGISTER_MATCHER(qualType);
305   REGISTER_MATCHER(recordDecl);
306   REGISTER_MATCHER(recordType);
307   REGISTER_MATCHER(referenceType);
308   REGISTER_MATCHER(refersToDeclaration);
309   REGISTER_MATCHER(refersToIntegralType);
310   REGISTER_MATCHER(refersToType);
311   REGISTER_MATCHER(reinterpretCastExpr);
312   REGISTER_MATCHER(returns);
313   REGISTER_MATCHER(returnStmt);
314   REGISTER_MATCHER(rValueReferenceType);
315   REGISTER_MATCHER(sizeOfExpr);
316   REGISTER_MATCHER(specifiesNamespace);
317   REGISTER_MATCHER(specifiesType);
318   REGISTER_MATCHER(specifiesTypeLoc);
319   REGISTER_MATCHER(statementCountIs);
320   REGISTER_MATCHER(staticCastExpr);
321   REGISTER_MATCHER(staticAssertDecl);
322   REGISTER_MATCHER(stmt);
323   REGISTER_MATCHER(stringLiteral);
324   REGISTER_MATCHER(substNonTypeTemplateParmExpr);
325   REGISTER_MATCHER(switchCase);
326   REGISTER_MATCHER(switchStmt);
327   REGISTER_MATCHER(templateArgument);
328   REGISTER_MATCHER(templateArgumentCountIs);
329   REGISTER_MATCHER(templateSpecializationType);
330   REGISTER_MATCHER(temporaryObjectExpr);
331   REGISTER_MATCHER(thisExpr);
332   REGISTER_MATCHER(throughUsingDecl);
333   REGISTER_MATCHER(throwExpr);
334   REGISTER_MATCHER(to);
335   REGISTER_MATCHER(translationUnitDecl);
336   REGISTER_MATCHER(tryStmt);
337   REGISTER_MATCHER(type);
338   REGISTER_MATCHER(typedefDecl);
339   REGISTER_MATCHER(typedefType);
340   REGISTER_MATCHER(typeLoc);
341   REGISTER_MATCHER(unaryExprOrTypeTraitExpr);
342   REGISTER_MATCHER(unaryOperator);
343   REGISTER_MATCHER(unaryTransformType);
344   REGISTER_MATCHER(unless);
345   REGISTER_MATCHER(unresolvedConstructExpr);
346   REGISTER_MATCHER(unresolvedUsingValueDecl);
347   REGISTER_MATCHER(userDefinedLiteral);
348   REGISTER_MATCHER(usingDecl);
349   REGISTER_MATCHER(usingDirectiveDecl);
350   REGISTER_MATCHER(valueDecl);
351   REGISTER_MATCHER(varDecl);
352   REGISTER_MATCHER(variableArrayType);
353   REGISTER_MATCHER(voidType);
354   REGISTER_MATCHER(whileStmt);
355   REGISTER_MATCHER(withInitializer);
356 }
357 
358 RegistryMaps::~RegistryMaps() {
359   for (ConstructorMap::iterator it = Constructors.begin(),
360                                 end = Constructors.end();
361        it != end; ++it) {
362     delete it->second;
363   }
364 }
365 
366 static llvm::ManagedStatic<RegistryMaps> RegistryData;
367 
368 } // anonymous namespace
369 
370 // static
371 llvm::Optional<MatcherCtor> Registry::lookupMatcherCtor(StringRef MatcherName) {
372   ConstructorMap::const_iterator it =
373       RegistryData->constructors().find(MatcherName);
374   return it == RegistryData->constructors().end()
375              ? llvm::Optional<MatcherCtor>()
376              : it->second;
377 }
378 
379 namespace {
380 
381 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
382                               const std::set<ASTNodeKind> &KS) {
383   unsigned Count = 0;
384   for (std::set<ASTNodeKind>::const_iterator I = KS.begin(), E = KS.end();
385        I != E; ++I) {
386     if (I != KS.begin())
387       OS << "|";
388     if (Count++ == 3) {
389       OS << "...";
390       break;
391     }
392     OS << *I;
393   }
394   return OS;
395 }
396 
397 }  // namespace
398 
399 std::vector<ArgKind> Registry::getAcceptedCompletionTypes(
400     ArrayRef<std::pair<MatcherCtor, unsigned>> Context) {
401   ASTNodeKind InitialTypes[] = {
402       ASTNodeKind::getFromNodeKind<Decl>(),
403       ASTNodeKind::getFromNodeKind<QualType>(),
404       ASTNodeKind::getFromNodeKind<Type>(),
405       ASTNodeKind::getFromNodeKind<Stmt>(),
406       ASTNodeKind::getFromNodeKind<NestedNameSpecifier>(),
407       ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>(),
408       ASTNodeKind::getFromNodeKind<TypeLoc>()};
409 
410   // Starting with the above seed of acceptable top-level matcher types, compute
411   // the acceptable type set for the argument indicated by each context element.
412   std::set<ArgKind> TypeSet(std::begin(InitialTypes), std::end(InitialTypes));
413   for (const auto &CtxEntry : Context) {
414     MatcherCtor Ctor = CtxEntry.first;
415     unsigned ArgNumber = CtxEntry.second;
416     std::vector<ArgKind> NextTypeSet;
417     for (const ArgKind &Kind : TypeSet) {
418       if (Kind.getArgKind() == Kind.AK_Matcher &&
419           Ctor->isConvertibleTo(Kind.getMatcherKind()) &&
420           (Ctor->isVariadic() || ArgNumber < Ctor->getNumArgs()))
421         Ctor->getArgKinds(Kind.getMatcherKind(), ArgNumber, NextTypeSet);
422     }
423     TypeSet.clear();
424     TypeSet.insert(NextTypeSet.begin(), NextTypeSet.end());
425   }
426   return std::vector<ArgKind>(TypeSet.begin(), TypeSet.end());
427 }
428 
429 std::vector<MatcherCompletion>
430 Registry::getMatcherCompletions(ArrayRef<ArgKind> AcceptedTypes) {
431   std::vector<MatcherCompletion> Completions;
432 
433   // Search the registry for acceptable matchers.
434   for (ConstructorMap::const_iterator I = RegistryData->constructors().begin(),
435                                       E = RegistryData->constructors().end();
436        I != E; ++I) {
437     std::set<ASTNodeKind> RetKinds;
438     unsigned NumArgs = I->second->isVariadic() ? 1 : I->second->getNumArgs();
439     bool IsPolymorphic = I->second->isPolymorphic();
440     std::vector<std::vector<ArgKind>> ArgsKinds(NumArgs);
441     unsigned MaxSpecificity = 0;
442     for (const ArgKind& Kind : AcceptedTypes) {
443       if (Kind.getArgKind() != Kind.AK_Matcher)
444         continue;
445       unsigned Specificity;
446       ASTNodeKind LeastDerivedKind;
447       if (I->second->isConvertibleTo(Kind.getMatcherKind(), &Specificity,
448                                      &LeastDerivedKind)) {
449         if (MaxSpecificity < Specificity)
450           MaxSpecificity = Specificity;
451         RetKinds.insert(LeastDerivedKind);
452         for (unsigned Arg = 0; Arg != NumArgs; ++Arg)
453           I->second->getArgKinds(Kind.getMatcherKind(), Arg, ArgsKinds[Arg]);
454         if (IsPolymorphic)
455           break;
456       }
457     }
458 
459     if (!RetKinds.empty() && MaxSpecificity > 0) {
460       std::string Decl;
461       llvm::raw_string_ostream OS(Decl);
462 
463       if (IsPolymorphic) {
464         OS << "Matcher<T> " << I->first() << "(Matcher<T>";
465       } else {
466         OS << "Matcher<" << RetKinds << "> " << I->first() << "(";
467         for (const std::vector<ArgKind> &Arg : ArgsKinds) {
468           if (&Arg != &ArgsKinds[0])
469             OS << ", ";
470 
471           bool FirstArgKind = true;
472           std::set<ASTNodeKind> MatcherKinds;
473           // Two steps. First all non-matchers, then matchers only.
474           for (const ArgKind &AK : Arg) {
475             if (AK.getArgKind() == ArgKind::AK_Matcher) {
476               MatcherKinds.insert(AK.getMatcherKind());
477             } else {
478               if (!FirstArgKind) OS << "|";
479               FirstArgKind = false;
480               OS << AK.asString();
481             }
482           }
483           if (!MatcherKinds.empty()) {
484             if (!FirstArgKind) OS << "|";
485             OS << "Matcher<" << MatcherKinds << ">";
486           }
487         }
488       }
489       if (I->second->isVariadic())
490         OS << "...";
491       OS << ")";
492 
493       std::string TypedText = I->first();
494       TypedText += "(";
495       if (ArgsKinds.empty())
496         TypedText += ")";
497       else if (ArgsKinds[0][0].getArgKind() == ArgKind::AK_String)
498         TypedText += "\"";
499 
500       Completions.emplace_back(TypedText, OS.str(), MaxSpecificity);
501     }
502   }
503 
504   return Completions;
505 }
506 
507 // static
508 VariantMatcher Registry::constructMatcher(MatcherCtor Ctor,
509                                           const SourceRange &NameRange,
510                                           ArrayRef<ParserValue> Args,
511                                           Diagnostics *Error) {
512   return Ctor->create(NameRange, Args, Error);
513 }
514 
515 // static
516 VariantMatcher Registry::constructBoundMatcher(MatcherCtor Ctor,
517                                                const SourceRange &NameRange,
518                                                StringRef BindID,
519                                                ArrayRef<ParserValue> Args,
520                                                Diagnostics *Error) {
521   VariantMatcher Out = constructMatcher(Ctor, NameRange, Args, Error);
522   if (Out.isNull()) return Out;
523 
524   llvm::Optional<DynTypedMatcher> Result = Out.getSingleMatcher();
525   if (Result.hasValue()) {
526     llvm::Optional<DynTypedMatcher> Bound = Result->tryBind(BindID);
527     if (Bound.hasValue()) {
528       return VariantMatcher::SingleMatcher(*Bound);
529     }
530   }
531   Error->addError(NameRange, Error->ET_RegistryNotBindable);
532   return VariantMatcher();
533 }
534 
535 }  // namespace dynamic
536 }  // namespace ast_matchers
537 }  // namespace clang
538