clang  3.9.0
Registry.cpp
Go to the documentation of this file.
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 
16 #include "Marshallers.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/ManagedStatic.h"
22 #include <set>
23 #include <utility>
24 
25 using namespace clang::ast_type_traits;
26 
27 namespace clang {
28 namespace ast_matchers {
29 namespace dynamic {
30 namespace {
31 
32 using internal::MatcherDescriptor;
33 
34 typedef llvm::StringMap<const MatcherDescriptor *> ConstructorMap;
35 class RegistryMaps {
36 public:
37  RegistryMaps();
38  ~RegistryMaps();
39 
40  const ConstructorMap &constructors() const { return Constructors; }
41 
42 private:
43  void registerMatcher(StringRef MatcherName, MatcherDescriptor *Callback);
44  ConstructorMap Constructors;
45 };
46 
47 void RegistryMaps::registerMatcher(StringRef MatcherName,
48  MatcherDescriptor *Callback) {
49  assert(Constructors.find(MatcherName) == Constructors.end());
50  Constructors[MatcherName] = Callback;
51 }
52 
53 #define REGISTER_MATCHER(name) \
54  registerMatcher(#name, internal::makeMatcherAutoMarshall( \
55  ::clang::ast_matchers::name, #name));
56 
57 #define SPECIFIC_MATCHER_OVERLOAD(name, Id) \
58  static_cast< ::clang::ast_matchers::name##_Type##Id>( \
59  ::clang::ast_matchers::name)
60 
61 #define REGISTER_OVERLOADED_2(name) \
62  do { \
63  MatcherDescriptor *Callbacks[] = { \
64  internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 0), \
65  #name), \
66  internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 1), \
67  #name) \
68  }; \
69  registerMatcher(#name, \
70  new internal::OverloadedMatcherDescriptor(Callbacks)); \
71  } while (0)
72 
73 /// \brief Generate a registry map with all the known matchers.
74 RegistryMaps::RegistryMaps() {
75  // TODO: Here is the list of the missing matchers, grouped by reason.
76  //
77  // Need Variant/Parser fixes:
78  // ofKind
79  //
80  // Polymorphic + argument overload:
81  // findAll
82  //
83  // Other:
84  // equals
85  // equalsNode
86 
87  REGISTER_OVERLOADED_2(callee);
88  REGISTER_OVERLOADED_2(hasPrefix);
89  REGISTER_OVERLOADED_2(hasType);
90  REGISTER_OVERLOADED_2(isDerivedFrom);
91  REGISTER_OVERLOADED_2(isSameOrDerivedFrom);
93  REGISTER_OVERLOADED_2(pointsTo);
94  REGISTER_OVERLOADED_2(references);
95  REGISTER_OVERLOADED_2(thisPointerType);
96 
103  REGISTER_MATCHER(argumentCountIs);
105  REGISTER_MATCHER(arrayType);
107  REGISTER_MATCHER(asString);
109  REGISTER_MATCHER(atomicType);
110  REGISTER_MATCHER(autoType);
113  REGISTER_MATCHER(blockPointerType);
114  REGISTER_MATCHER(booleanType);
116  REGISTER_MATCHER(builtinType);
123  REGISTER_MATCHER(complexType);
127  REGISTER_MATCHER(constantArrayType);
128  REGISTER_MATCHER(containsDeclaration);
159  REGISTER_MATCHER(decayedType);
162  REGISTER_MATCHER(declCountIs);
166  REGISTER_MATCHER(dependentSizedArrayType);
168  REGISTER_MATCHER(designatorCountIs);
171  REGISTER_MATCHER(elaboratedType);
174  REGISTER_MATCHER(enumType);
175  REGISTER_MATCHER(equalsBoundNode);
176  REGISTER_MATCHER(equalsIntegralValue);
183  REGISTER_MATCHER(forEachArgumentWithParam);
184  REGISTER_MATCHER(forEachConstructorInitializer);
186  REGISTER_MATCHER(forEachSwitchCase);
187  REGISTER_MATCHER(forField);
188  REGISTER_MATCHER(forFunction);
192  REGISTER_MATCHER(functionProtoType);
194  REGISTER_MATCHER(functionType);
199  REGISTER_MATCHER(hasAnyArgument);
200  REGISTER_MATCHER(hasAnyConstructorInitializer);
202  REGISTER_MATCHER(hasAnyParameter);
203  REGISTER_MATCHER(hasAnySubstatement);
204  REGISTER_MATCHER(hasAnyTemplateArgument);
205  REGISTER_MATCHER(hasAnyUsingShadowDecl);
206  REGISTER_MATCHER(hasArgument);
207  REGISTER_MATCHER(hasArgumentOfType);
208  REGISTER_MATCHER(hasAttr);
209  REGISTER_MATCHER(hasAutomaticStorageDuration);
210  REGISTER_MATCHER(hasBase);
211  REGISTER_MATCHER(hasBitWidth);
212  REGISTER_MATCHER(hasBody);
213  REGISTER_MATCHER(hasCanonicalType);
214  REGISTER_MATCHER(hasCaseConstant);
215  REGISTER_MATCHER(hasCastKind);
216  REGISTER_MATCHER(hasCondition);
217  REGISTER_MATCHER(hasConditionVariableStatement);
218  REGISTER_MATCHER(hasDecayedType);
220  REGISTER_MATCHER(hasDeclContext);
221  REGISTER_MATCHER(hasDeducedType);
223  REGISTER_MATCHER(hasDestinationType);
224  REGISTER_MATCHER(hasDynamicExceptionSpec);
226  REGISTER_MATCHER(hasElementType);
227  REGISTER_MATCHER(hasElse);
228  REGISTER_MATCHER(hasFalseExpression);
229  REGISTER_MATCHER(hasGlobalStorage);
230  REGISTER_MATCHER(hasImplicitDestinationType);
231  REGISTER_MATCHER(hasIncrement);
232  REGISTER_MATCHER(hasIndex);
233  REGISTER_MATCHER(hasInitializer);
234  REGISTER_MATCHER(hasKeywordSelector);
235  REGISTER_MATCHER(hasLHS);
236  REGISTER_MATCHER(hasLocalQualifiers);
237  REGISTER_MATCHER(hasLocalStorage);
238  REGISTER_MATCHER(hasLoopInit);
239  REGISTER_MATCHER(hasLoopVariable);
240  REGISTER_MATCHER(hasMethod);
242  REGISTER_MATCHER(hasNullSelector);
243  REGISTER_MATCHER(hasObjectExpression);
244  REGISTER_MATCHER(hasOperatorName);
246  REGISTER_MATCHER(hasParameter);
248  REGISTER_MATCHER(hasQualifier);
249  REGISTER_MATCHER(hasRangeInit);
250  REGISTER_MATCHER(hasReceiverType);
251  REGISTER_MATCHER(hasReturnValue);
252  REGISTER_MATCHER(hasRHS);
253  REGISTER_MATCHER(hasSelector);
254  REGISTER_MATCHER(hasSingleDecl);
255  REGISTER_MATCHER(hasSize);
256  REGISTER_MATCHER(hasSizeExpr);
257  REGISTER_MATCHER(hasSourceExpression);
258  REGISTER_MATCHER(hasStaticStorageDuration);
259  REGISTER_MATCHER(hasSyntacticForm);
260  REGISTER_MATCHER(hasTargetDecl);
261  REGISTER_MATCHER(hasTemplateArgument);
262  REGISTER_MATCHER(hasThen);
263  REGISTER_MATCHER(hasThreadStorageDuration);
264  REGISTER_MATCHER(hasTrueExpression);
265  REGISTER_MATCHER(hasTypeLoc);
266  REGISTER_MATCHER(hasUnaryOperand);
267  REGISTER_MATCHER(hasUnarySelector);
268  REGISTER_MATCHER(hasValueType);
270  REGISTER_MATCHER(ignoringImplicit);
271  REGISTER_MATCHER(ignoringImpCasts);
272  REGISTER_MATCHER(ignoringParenCasts);
273  REGISTER_MATCHER(ignoringParenImpCasts);
274  REGISTER_MATCHER(ignoringParens);
277  REGISTER_MATCHER(incompleteArrayType);
279  REGISTER_MATCHER(injectedClassNameType);
280  REGISTER_MATCHER(innerType);
282  REGISTER_MATCHER(isAnonymous);
283  REGISTER_MATCHER(isAnyCharacter);
284  REGISTER_MATCHER(isAnyPointer);
285  REGISTER_MATCHER(isArrow);
286  REGISTER_MATCHER(isBaseInitializer);
287  REGISTER_MATCHER(isBitField);
288  REGISTER_MATCHER(isCatchAll);
289  REGISTER_MATCHER(isClass);
290  REGISTER_MATCHER(isConst);
291  REGISTER_MATCHER(isConstQualified);
292  REGISTER_MATCHER(isCopyAssignmentOperator);
293  REGISTER_MATCHER(isCopyConstructor);
294  REGISTER_MATCHER(isDefaultConstructor);
295  REGISTER_MATCHER(isDefaulted);
296  REGISTER_MATCHER(isDefinition);
297  REGISTER_MATCHER(isDeleted);
298  REGISTER_MATCHER(isExceptionVariable);
299  REGISTER_MATCHER(isExplicit);
300  REGISTER_MATCHER(isExplicitTemplateSpecialization);
301  REGISTER_MATCHER(isExpr);
303  REGISTER_MATCHER(isFinal);
304  REGISTER_MATCHER(isInline);
305  REGISTER_MATCHER(isImplicit);
306  REGISTER_MATCHER(isExpansionInFileMatching);
307  REGISTER_MATCHER(isExpansionInMainFile);
308  REGISTER_MATCHER(isInstantiated);
309  REGISTER_MATCHER(isExpansionInSystemHeader);
310  REGISTER_MATCHER(isInteger);
311  REGISTER_MATCHER(isIntegral);
312  REGISTER_MATCHER(isInTemplateInstantiation);
313  REGISTER_MATCHER(isLambda);
314  REGISTER_MATCHER(isListInitialization);
315  REGISTER_MATCHER(isMemberInitializer);
316  REGISTER_MATCHER(isMoveAssignmentOperator);
317  REGISTER_MATCHER(isMoveConstructor);
318  REGISTER_MATCHER(isNoThrow);
319  REGISTER_MATCHER(isOverride);
320  REGISTER_MATCHER(isPrivate);
321  REGISTER_MATCHER(isProtected);
322  REGISTER_MATCHER(isPublic);
323  REGISTER_MATCHER(isPure);
324  REGISTER_MATCHER(isSignedInteger);
325  REGISTER_MATCHER(isStruct);
327  REGISTER_MATCHER(isUnion);
328  REGISTER_MATCHER(isUnsignedInteger);
329  REGISTER_MATCHER(isVariadic);
330  REGISTER_MATCHER(isVirtual);
331  REGISTER_MATCHER(isVirtualAsWritten);
332  REGISTER_MATCHER(isVolatileQualified);
333  REGISTER_MATCHER(isWritten);
337  REGISTER_MATCHER(lValueReferenceType);
338  REGISTER_MATCHER(matchesName);
339  REGISTER_MATCHER(matchesSelector);
341  REGISTER_MATCHER(member);
343  REGISTER_MATCHER(memberPointerType);
347  REGISTER_MATCHER(namesType);
350  REGISTER_MATCHER(nullPointerConstant);
352  REGISTER_MATCHER(numSelectorArgs);
353  REGISTER_MATCHER(ofClass);
356  REGISTER_MATCHER(objcObjectPointerType);
357  REGISTER_MATCHER(on);
358  REGISTER_MATCHER(onImplicitObjectArgument);
360  REGISTER_MATCHER(parameterCountIs);
363  REGISTER_MATCHER(parenType);
365  REGISTER_MATCHER(pointee);
366  REGISTER_MATCHER(pointerType);
369  REGISTER_MATCHER(realFloatingPointType);
371  REGISTER_MATCHER(recordType);
372  REGISTER_MATCHER(referenceType);
373  REGISTER_MATCHER(refersToDeclaration);
374  REGISTER_MATCHER(refersToIntegralType);
375  REGISTER_MATCHER(refersToType);
376  REGISTER_MATCHER(requiresZeroInitialization);
377  REGISTER_MATCHER(returns);
379  REGISTER_MATCHER(rValueReferenceType);
381  REGISTER_MATCHER(specifiesNamespace);
382  REGISTER_MATCHER(specifiesType);
383  REGISTER_MATCHER(specifiesTypeLoc);
384  REGISTER_MATCHER(statementCountIs);
390  REGISTER_MATCHER(substTemplateTypeParmType);
394  REGISTER_MATCHER(templateArgumentCountIs);
395  REGISTER_MATCHER(templateSpecializationType);
396  REGISTER_MATCHER(templateTypeParmType);
397  REGISTER_MATCHER(throughUsingDecl);
398  REGISTER_MATCHER(to);
403  REGISTER_MATCHER(typedefType);
408  REGISTER_MATCHER(unaryTransformType);
418  REGISTER_MATCHER(variableArrayType);
419  REGISTER_MATCHER(voidType);
421  REGISTER_MATCHER(withInitializer);
422 }
423 
424 RegistryMaps::~RegistryMaps() {
425  llvm::DeleteContainerSeconds(Constructors);
426 }
427 
428 static llvm::ManagedStatic<RegistryMaps> RegistryData;
429 
430 } // anonymous namespace
431 
432 // static
433 llvm::Optional<MatcherCtor> Registry::lookupMatcherCtor(StringRef MatcherName) {
434  ConstructorMap::const_iterator it =
435  RegistryData->constructors().find(MatcherName);
436  return it == RegistryData->constructors().end()
438  : it->second;
439 }
440 
441 namespace {
442 
443 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
444  const std::set<ASTNodeKind> &KS) {
445  unsigned Count = 0;
446  for (std::set<ASTNodeKind>::const_iterator I = KS.begin(), E = KS.end();
447  I != E; ++I) {
448  if (I != KS.begin())
449  OS << "|";
450  if (Count++ == 3) {
451  OS << "...";
452  break;
453  }
454  OS << *I;
455  }
456  return OS;
457 }
458 
459 } // namespace
460 
461 std::vector<ArgKind> Registry::getAcceptedCompletionTypes(
462  ArrayRef<std::pair<MatcherCtor, unsigned>> Context) {
463  ASTNodeKind InitialTypes[] = {
464  ASTNodeKind::getFromNodeKind<Decl>(),
465  ASTNodeKind::getFromNodeKind<QualType>(),
466  ASTNodeKind::getFromNodeKind<Type>(),
467  ASTNodeKind::getFromNodeKind<Stmt>(),
468  ASTNodeKind::getFromNodeKind<NestedNameSpecifier>(),
469  ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>(),
470  ASTNodeKind::getFromNodeKind<TypeLoc>()};
471 
472  // Starting with the above seed of acceptable top-level matcher types, compute
473  // the acceptable type set for the argument indicated by each context element.
474  std::set<ArgKind> TypeSet(std::begin(InitialTypes), std::end(InitialTypes));
475  for (const auto &CtxEntry : Context) {
476  MatcherCtor Ctor = CtxEntry.first;
477  unsigned ArgNumber = CtxEntry.second;
478  std::vector<ArgKind> NextTypeSet;
479  for (const ArgKind &Kind : TypeSet) {
480  if (Kind.getArgKind() == Kind.AK_Matcher &&
481  Ctor->isConvertibleTo(Kind.getMatcherKind()) &&
482  (Ctor->isVariadic() || ArgNumber < Ctor->getNumArgs()))
483  Ctor->getArgKinds(Kind.getMatcherKind(), ArgNumber, NextTypeSet);
484  }
485  TypeSet.clear();
486  TypeSet.insert(NextTypeSet.begin(), NextTypeSet.end());
487  }
488  return std::vector<ArgKind>(TypeSet.begin(), TypeSet.end());
489 }
490 
491 std::vector<MatcherCompletion>
492 Registry::getMatcherCompletions(ArrayRef<ArgKind> AcceptedTypes) {
493  std::vector<MatcherCompletion> Completions;
494 
495  // Search the registry for acceptable matchers.
496  for (const auto &M : RegistryData->constructors()) {
497  const auto *Matcher = M.getValue();
498  StringRef Name = M.getKey();
499 
500  std::set<ASTNodeKind> RetKinds;
501  unsigned NumArgs = Matcher->isVariadic() ? 1 : Matcher->getNumArgs();
502  bool IsPolymorphic = Matcher->isPolymorphic();
503  std::vector<std::vector<ArgKind>> ArgsKinds(NumArgs);
504  unsigned MaxSpecificity = 0;
505  for (const ArgKind& Kind : AcceptedTypes) {
506  if (Kind.getArgKind() != Kind.AK_Matcher)
507  continue;
508  unsigned Specificity;
509  ASTNodeKind LeastDerivedKind;
510  if (Matcher->isConvertibleTo(Kind.getMatcherKind(), &Specificity,
511  &LeastDerivedKind)) {
512  if (MaxSpecificity < Specificity)
513  MaxSpecificity = Specificity;
514  RetKinds.insert(LeastDerivedKind);
515  for (unsigned Arg = 0; Arg != NumArgs; ++Arg)
516  Matcher->getArgKinds(Kind.getMatcherKind(), Arg, ArgsKinds[Arg]);
517  if (IsPolymorphic)
518  break;
519  }
520  }
521 
522  if (!RetKinds.empty() && MaxSpecificity > 0) {
523  std::string Decl;
524  llvm::raw_string_ostream OS(Decl);
525 
526  if (IsPolymorphic) {
527  OS << "Matcher<T> " << Name << "(Matcher<T>";
528  } else {
529  OS << "Matcher<" << RetKinds << "> " << Name << "(";
530  for (const std::vector<ArgKind> &Arg : ArgsKinds) {
531  if (&Arg != &ArgsKinds[0])
532  OS << ", ";
533 
534  bool FirstArgKind = true;
535  std::set<ASTNodeKind> MatcherKinds;
536  // Two steps. First all non-matchers, then matchers only.
537  for (const ArgKind &AK : Arg) {
538  if (AK.getArgKind() == ArgKind::AK_Matcher) {
539  MatcherKinds.insert(AK.getMatcherKind());
540  } else {
541  if (!FirstArgKind) OS << "|";
542  FirstArgKind = false;
543  OS << AK.asString();
544  }
545  }
546  if (!MatcherKinds.empty()) {
547  if (!FirstArgKind) OS << "|";
548  OS << "Matcher<" << MatcherKinds << ">";
549  }
550  }
551  }
552  if (Matcher->isVariadic())
553  OS << "...";
554  OS << ")";
555 
556  std::string TypedText = Name;
557  TypedText += "(";
558  if (ArgsKinds.empty())
559  TypedText += ")";
560  else if (ArgsKinds[0][0].getArgKind() == ArgKind::AK_String)
561  TypedText += "\"";
562 
563  Completions.emplace_back(TypedText, OS.str(), MaxSpecificity);
564  }
565  }
566 
567  return Completions;
568 }
569 
570 // static
571 VariantMatcher Registry::constructMatcher(MatcherCtor Ctor,
572  SourceRange NameRange,
574  Diagnostics *Error) {
575  return Ctor->create(NameRange, Args, Error);
576 }
577 
578 // static
579 VariantMatcher Registry::constructBoundMatcher(MatcherCtor Ctor,
580  SourceRange NameRange,
581  StringRef BindID,
583  Diagnostics *Error) {
584  VariantMatcher Out = constructMatcher(Ctor, NameRange, Args, Error);
585  if (Out.isNull()) return Out;
586 
588  if (Result.hasValue()) {
589  llvm::Optional<DynTypedMatcher> Bound = Result->tryBind(BindID);
590  if (Bound.hasValue()) {
591  return VariantMatcher::SingleMatcher(*Bound);
592  }
593  }
594  Error->addError(NameRange, Error->ET_RegistryNotBindable);
595  return VariantMatcher();
596 }
597 
598 } // namespace dynamic
599 } // namespace ast_matchers
600 } // namespace clang
internal::TrueMatcher anything()
Matches any node.
Definition: ASTMatchers.h:145
const internal::ArgumentAdaptingMatcherFunc< internal::HasParentMatcher, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc >, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc > > LLVM_ATTRIBUTE_UNUSED hasParent
Matches AST nodes that have a parent that matches the provided matcher.
Definition: ASTMatchers.h:2367
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
Definition: ASTMatchers.h:1367
const internal::ArgumentAdaptingMatcherFunc< internal::HasAncestorMatcher, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc >, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc > > LLVM_ATTRIBUTE_UNUSED hasAncestor
Matches AST nodes that have an ancestor that matches the provided matcher.
Definition: ASTMatchers.h:2384
const internal::VariadicDynCastAllOfMatcher< Stmt, BreakStmt > breakStmt
Matches break statements.
Definition: ASTMatchers.h:1491
const internal::VariadicDynCastAllOfMatcher< Stmt, DoStmt > doStmt
Matches do statements.
Definition: ASTMatchers.h:1481
const internal::VariadicDynCastAllOfMatcher< Stmt, AddrLabelExpr > addrLabelExpr
Matches address of label statements (GNU extension).
Definition: ASTMatchers.h:1545
const internal::VariadicDynCastAllOfMatcher< Stmt, BinaryConditionalOperator > binaryConditionalOperator
Matches binary conditional operator expressions (GNU extension).
Definition: ASTMatchers.h:1774
const internal::VariadicDynCastAllOfMatcher< Stmt, StmtExpr > stmtExpr
Matches statement expression (GNU extension).
Definition: ASTMatchers.h:1734
const internal::ArgumentAdaptingMatcherFunc< internal::HasDescendantMatcher > LLVM_ATTRIBUTE_UNUSED hasDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher. ...
Definition: ASTMatchers.h:2281
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Definition: ASTMatchers.h:985
Registry of all known matchers.
const internal::VariadicDynCastAllOfMatcher< Stmt, OpaqueValueExpr > opaqueValueExpr
Matches opaque value expressions.
Definition: ASTMatchers.h:1786
internal::PolymorphicMatcherWithParam1< internal::HasDeclarationMatcher, internal::Matcher< Decl >, void(internal::HasDeclarationSupportedTypes)> hasDeclaration(const internal::Matcher< Decl > &InnerMatcher)
Matches a node if the declaration associated with that node matches the given matcher.
Definition: ASTMatchers.h:2420
const internal::VariadicDynCastAllOfMatcher< Decl, CXXMethodDecl > cxxMethodDecl
Matches method declarations.
Definition: ASTMatchers.h:917
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXNullPtrLiteralExpr > cxxNullPtrLiteralExpr
Matches nullptr literal.
Definition: ASTMatchers.h:1716
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDynamicCastExpr > cxxDynamicCastExpr
Matches a dynamic_cast expression.
Definition: ASTMatchers.h:1850
const internal::ArgumentAdaptingMatcherFunc< internal::ForEachMatcher > LLVM_ATTRIBUTE_UNUSED forEach
Matches AST nodes that have child AST nodes that match the provided matcher.
Definition: ASTMatchers.h:2301
const internal::VariadicDynCastAllOfMatcher< Stmt, LabelStmt > labelStmt
Matches label statements.
Definition: ASTMatchers.h:1533
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXThisExpr > cxxThisExpr
Matches implicit and explicit this expressions.
Definition: ASTMatchers.h:1262
const internal::VariadicDynCastAllOfMatcher< Decl, UsingDecl > usingDecl
Matches using declarations.
Definition: ASTMatchers.h:1148
const internal::VariadicDynCastAllOfMatcher< Decl, ValueDecl > valueDecl
Matches any value declaration.
Definition: ASTMatchers.h:859
const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplateDecl > classTemplateDecl
Matches C++ class template declarations.
Definition: ASTMatchers.h:375
const internal::VariadicDynCastAllOfMatcher< Decl, EnumConstantDecl > enumConstantDecl
Matches enum constants.
Definition: ASTMatchers.h:909
const DynTypedMatcher *const Matcher
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
Definition: ASTMatchers.h:937
const internal::VariadicDynCastAllOfMatcher< Decl, TypeAliasDecl > typeAliasDecl
Matches type alias declarations.
Definition: ASTMatchers.h:193
iterator begin() const
Definition: Type.h:4235
const internal::VariadicDynCastAllOfMatcher< Stmt, AsmStmt > asmStmt
Matches asm statements.
Definition: ASTMatchers.h:1639
const internal::VariadicDynCastAllOfMatcher< Stmt, DesignatedInitExpr > designatedInitExpr
Matches C99 designated initializer expressions [C99 6.7.8].
Definition: ASTMatchers.h:1962
const internal::VariadicDynCastAllOfMatcher< Stmt, ConditionalOperator > conditionalOperator
Matches conditional operator expressions.
Definition: ASTMatchers.h:1764
const internal::VariadicDynCastAllOfMatcher< Stmt, UnaryExprOrTypeTraitExpr > unaryExprOrTypeTraitExpr
Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
Definition: ASTMatchers.h:2036
const internal::VariadicAllOfMatcher< QualType > qualType
Matches QualTypes in the clang AST.
Definition: ASTMatchers.h:1980
const internal::VariadicDynCastAllOfMatcher< Stmt, CaseStmt > caseStmt
Matches case statements inside switch statements.
Definition: ASTMatchers.h:1575
#define REGISTER_OVERLOADED_2(name)
Definition: Registry.cpp:61
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchers.h:283
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCMessageExpr > objcMessageExpr
Matches ObjectiveC Message invocation expressions.
Definition: ASTMatchers.h:1052
const internal::VariadicDynCastAllOfMatcher< Decl, CXXDestructorDecl > cxxDestructorDecl
Matches explicit C++ destructor declarations.
Definition: ASTMatchers.h:887
const internal::VariadicDynCastAllOfMatcher< Stmt, WhileStmt > whileStmt
Matches while statements.
Definition: ASTMatchers.h:1471
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXTryStmt > cxxTryStmt
Matches try statements.
Definition: ASTMatchers.h:1611
const internal::VariadicDynCastAllOfMatcher< Stmt, CompoundLiteralExpr > compoundLiteralExpr
Matches compound (i.e.
Definition: ASTMatchers.h:1711
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXReinterpretCastExpr > cxxReinterpretCastExpr
Matches a reinterpret_cast expression.
Definition: ASTMatchers.h:1817
const internal::VariadicDynCastAllOfMatcher< Stmt, NullStmt > nullStmt
Matches null statements.
Definition: ASTMatchers.h:1629
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXNewExpr > cxxNewExpr
Matches new expressions.
Definition: ASTMatchers.h:1306
const internal::VariadicDynCastAllOfMatcher< Decl, NamedDecl > namedDecl
Matches a declaration of anything that could have a name.
Definition: ASTMatchers.h:307
const internal::VariadicDynCastAllOfMatcher< Decl, TypedefDecl > typedefDecl
Matches typedef declarations.
Definition: ASTMatchers.h:170
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXMemberCallExpr > cxxMemberCallExpr
Matches member call expressions.
Definition: ASTMatchers.h:1039
const internal::VariadicOperatorMatcherFunc< 2, UINT_MAX > eachOf
Matches if any of the given matchers matches.
Definition: ASTMatchers.h:2007
const internal::VariadicDynCastAllOfMatcher< Stmt, DefaultStmt > defaultStmt
Matches default statements inside switch statements.
Definition: ASTMatchers.h:1585
const internal::VariadicDynCastAllOfMatcher< Stmt, ExprWithCleanups > exprWithCleanups
Matches expressions that introduce cleanups to be run at the end of the sub-expression's evaluation...
Definition: ASTMatchers.h:1074
const internal::VariadicDynCastAllOfMatcher< Stmt, CompoundStmt > compoundStmt
Matches compound statements.
Definition: ASTMatchers.h:1593
const internal::VariadicDynCastAllOfMatcher< Decl, ParmVarDecl > parmVarDecl
Matches parameter variable declarations.
Definition: ASTMatchers.h:411
const internal::VariadicDynCastAllOfMatcher< Stmt, ReturnStmt > returnStmt
Matches return statements.
Definition: ASTMatchers.h:1511
const internal::VariadicDynCastAllOfMatcher< Decl, TranslationUnitDecl > translationUnitDecl
Matches the top declaration context.
Definition: ASTMatchers.h:159
const internal::VariadicDynCastAllOfMatcher< Decl, FriendDecl > friendDecl
Matches friend declarations.
Definition: ASTMatchers.h:975
internal::Matcher< Stmt > sizeOfExpr(const internal::Matcher< UnaryExprOrTypeTraitExpr > &InnerMatcher)
Same as unaryExprOrTypeTraitExpr, but only matching sizeof.
Definition: ASTMatchers.h:2075
Functions templates and classes to wrap matcher construct functions.
const internal::VariadicDynCastAllOfMatcher< Decl, StaticAssertDecl > staticAssertDecl
Matches a C++ static_assert declaration.
Definition: ASTMatchers.h:1803
const internal::VariadicDynCastAllOfMatcher< Decl, LabelDecl > labelDecl
Matches a declaration of label.
Definition: ASTMatchers.h:318
iterator end() const
const internal::VariadicDynCastAllOfMatcher< Stmt, DeclStmt > declStmt
Matches declaration statements.
Definition: ASTMatchers.h:997
internal::PolymorphicMatcherWithParam1< internal::HasOverloadedOperatorNameMatcher, StringRef, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)> hasOverloadedOperatorName(StringRef Name)
Matches overloaded operator names.
Definition: ASTMatchers.h:2161
detail::InMemoryDirectory::const_iterator I
const internal::VariadicDynCastAllOfMatcher< Stmt, UnaryOperator > unaryOperator
Matches unary operator expressions.
Definition: ASTMatchers.h:1754
const internal::VariadicDynCastAllOfMatcher< Stmt, MemberExpr > memberExpr
Matches member expressions.
Definition: ASTMatchers.h:1010
bool isNull() const
Whether the matcher is null.
Definition: VariantValue.h:158
const internal::VariadicDynCastAllOfMatcher< Stmt, InitListExpr > initListExpr
Matches init list expressions.
Definition: ASTMatchers.h:1086
const internal::VariadicOperatorMatcherFunc< 2, UINT_MAX > allOf
Matches if all given matchers match.
Definition: ASTMatchers.h:2021
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXFunctionalCastExpr > cxxFunctionalCastExpr
Matches functional cast expressions.
Definition: ASTMatchers.h:1932
const internal::VariadicDynCastAllOfMatcher< Stmt, ArraySubscriptExpr > arraySubscriptExpr
Matches array subscript expressions.
Definition: ASTMatchers.h:1328
ASTContext * Context
const internal::VariadicDynCastAllOfMatcher< Stmt, LambdaExpr > lambdaExpr
Matches lambda expressions.
Definition: ASTMatchers.h:1028
const internal::VariadicDynCastAllOfMatcher< Stmt, BinaryOperator > binaryOperator
Matches binary operator expressions.
Definition: ASTMatchers.h:1744
const internal::VariadicAllOfMatcher< NestedNameSpecifier > nestedNameSpecifier
Matches nested name specifiers.
Definition: ASTMatchers.h:4965
const internal::ArgumentAdaptingMatcherFunc< internal::ForEachDescendantMatcher > LLVM_ATTRIBUTE_UNUSED forEachDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher. ...
Definition: ASTMatchers.h:2330
const internal::VariadicDynCastAllOfMatcher< Stmt, IntegerLiteral > integerLiteral
Matches integer literals of all sizes / encodings, e.g.
Definition: ASTMatchers.h:1682
const internal::VariadicDynCastAllOfMatcher< Stmt, ForStmt > forStmt
Matches for statements.
Definition: ASTMatchers.h:1393
MatchFinder::MatchCallback * Callback
const internal::VariadicOperatorMatcherFunc< 1, 1 > unless
Matches if the provided matcher does not match.
Definition: ASTMatchers.h:2395
const internal::VariadicAllOfMatcher< NestedNameSpecifierLoc > nestedNameSpecifierLoc
Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.
Definition: ASTMatchers.h:4969
const internal::VariadicDynCastAllOfMatcher< Stmt, GotoStmt > gotoStmt
Matches goto statements.
Definition: ASTMatchers.h:1522
#define REGISTER_MATCHER(name)
Definition: Registry.cpp:53
const internal::VariadicDynCastAllOfMatcher< Decl, RecordDecl > recordDecl
Matches class, struct, and union declarations.
Definition: ASTMatchers.h:354
virtual VariantMatcher create(SourceRange NameRange, ArrayRef< ParserValue > Args, Diagnostics *Error) const =0
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXTemporaryObjectExpr > cxxTemporaryObjectExpr
Matches functional cast expressions having N != 1 arguments.
Definition: ASTMatchers.h:1942
const internal::VariadicDynCastAllOfMatcher< Stmt, PredefinedExpr > predefinedExpr
Matches predefined identifier expressions [C99 6.4.2.2].
Definition: ASTMatchers.h:1952
const internal::VariadicDynCastAllOfMatcher< Stmt, MaterializeTemporaryExpr > materializeTemporaryExpr
Matches nodes where temporaries are materialized.
Definition: ASTMatchers.h:1296
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXForRangeStmt > cxxForRangeStmt
Matches range-based for statements.
Definition: ASTMatchers.h:1433
const internal::VariadicFunction< internal::Matcher< NamedDecl >, StringRef, internal::hasAnyNameFunc > hasAnyName
Matches NamedDecl nodes that have any of the specified names.
Definition: ASTMatchers.h:2114
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4154
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXStaticCastExpr > cxxStaticCastExpr
Matches a C++ static_cast expression.
Definition: ASTMatchers.h:1834
const internal::VariadicDynCastAllOfMatcher< Stmt, AtomicExpr > atomicExpr
Matches atomic builtins.
Definition: ASTMatchers.h:1726
The result type of a method or function.
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:165
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDeleteExpr > cxxDeleteExpr
Matches delete expressions.
Definition: ASTMatchers.h:1316
const internal::VariadicDynCastAllOfMatcher< Stmt, SwitchCase > switchCase
Matches case and default statements inside switch statements.
Definition: ASTMatchers.h:1565
Helper class to manage error messages.
Definition: Diagnostics.h:51
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCInterfaceDecl > objcInterfaceDecl
Matches Objective-C interface declarations.
Definition: ASTMatchers.h:1063
const internal::VariadicAllOfMatcher< TypeLoc > typeLoc
Matches TypeLocs in the clang AST.
Definition: ASTMatchers.h:1986
ArgStream addError(SourceRange Range, ErrorType Error)
Add an error to the diagnostics.
Definition: Diagnostics.cpp:66
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXBindTemporaryExpr > cxxBindTemporaryExpr
Matches nodes where temporaries are created.
Definition: ASTMatchers.h:1274
const internal::VariadicDynCastAllOfMatcher< Decl, UnresolvedUsingValueDecl > unresolvedUsingValueDecl
Matches unresolved using value declarations.
Definition: ASTMatchers.h:1194
Kind
const internal::VariadicDynCastAllOfMatcher< Stmt, CharacterLiteral > characterLiteral
Matches character literals (also matches wchar_t).
Definition: ASTMatchers.h:1674
const internal::VariadicDynCastAllOfMatcher< Stmt, DeclRefExpr > declRefExpr
Matches expressions that refer to declarations.
Definition: ASTMatchers.h:1376
const internal::VariadicAllOfMatcher< CXXCtorInitializer > cxxCtorInitializer
Matches constructor initializers.
Definition: ASTMatchers.h:437
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXThrowExpr > cxxThrowExpr
Matches throw expressions.
Definition: ASTMatchers.h:1620
const internal::VariadicDynCastAllOfMatcher< Stmt, ImplicitCastExpr > implicitCastExpr
Matches the implicit cast nodes of Clang's AST.
Definition: ASTMatchers.h:1905
const internal::ArgumentAdaptingMatcherFunc< internal::HasMatcher > LLVM_ATTRIBUTE_UNUSED has
Matches AST nodes that have child AST nodes that match the provided matcher.
Definition: ASTMatchers.h:2264
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXOperatorCallExpr > cxxOperatorCallExpr
Matches overloaded operator calls.
Definition: ASTMatchers.h:1359
const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplateSpecializationDecl > classTemplateSpecializationDecl
Matches C++ class template specializations.
Definition: ASTMatchers.h:389
internal::Matcher< Stmt > alignOfExpr(const internal::Matcher< UnaryExprOrTypeTraitExpr > &InnerMatcher)
Same as unaryExprOrTypeTraitExpr, but only matching alignof.
Definition: ASTMatchers.h:2067
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
Definition: ASTMatchers.h:955
const internal::VariadicDynCastAllOfMatcher< Decl, CXXConstructorDecl > cxxConstructorDecl
Matches C++ constructor declarations.
Definition: ASTMatchers.h:874
const internal::VariadicDynCastAllOfMatcher< Decl, AccessSpecDecl > accessSpecDecl
Matches C++ access specifier declarations.
Definition: ASTMatchers.h:426
virtual bool isVariadic() const =0
Returns whether the matcher is variadic.
const internal::VariadicDynCastAllOfMatcher< Stmt, ExplicitCastExpr > explicitCastExpr
Matches explicit cast expressions.
Definition: ASTMatchers.h:1897
const internal::VariadicDynCastAllOfMatcher< Stmt, SubstNonTypeTemplateParmExpr > substNonTypeTemplateParmExpr
Matches substitutions of non-type template parameters.
Definition: ASTMatchers.h:1137
virtual unsigned getNumArgs() const =0
Returns the number of arguments accepted by the matcher if not variadic.
const internal::VariadicDynCastAllOfMatcher< Stmt, StringLiteral > stringLiteral
Matches string literals (also matches wide string literals).
Definition: ASTMatchers.h:1660
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDefaultArgExpr > cxxDefaultArgExpr
Matches the value of a default argument at the call site.
Definition: ASTMatchers.h:1341
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstCastExpr > cxxConstCastExpr
Matches a const_cast expression.
Definition: ASTMatchers.h:1862
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionTemplateDecl > functionTemplateDecl
Matches C++ function template declarations.
Definition: ASTMatchers.h:965
const internal::VariadicDynCastAllOfMatcher< Decl, EnumDecl > enumDecl
Matches enum declarations.
Definition: ASTMatchers.h:897
const internal::VariadicDynCastAllOfMatcher< Stmt, ParenExpr > parenExpr
Matches parentheses used in expressions.
Definition: ASTMatchers.h:1224
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1983
detail::InMemoryDirectory::const_iterator E
const internal::VariadicDynCastAllOfMatcher< Stmt, CUDAKernelCallExpr > cudaKernelCallExpr
Matches CUDA kernel call expression.
Definition: ASTMatchers.h:5331
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXUnresolvedConstructExpr > cxxUnresolvedConstructExpr
Matches unresolved constructor call expressions.
Definition: ASTMatchers.h:1250
const internal::VariadicDynCastAllOfMatcher< Decl, UsingDirectiveDecl > usingDirectiveDecl
Matches using namespace declarations.
Definition: ASTMatchers.h:1161
const internal::VariadicDynCastAllOfMatcher< Stmt, CStyleCastExpr > cStyleCastExpr
Matches a C-style cast expression.
Definition: ASTMatchers.h:1872
const internal::VariadicDynCastAllOfMatcher< Decl, UnresolvedUsingTypenameDecl > unresolvedUsingTypenameDecl
Matches unresolved using value declarations that involve the typename.
Definition: ASTMatchers.h:1213
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstructExpr > cxxConstructExpr
Matches constructor call expressions (including implicit ones).
Definition: ASTMatchers.h:1238
const internal::VariadicDynCastAllOfMatcher< Stmt, FloatingLiteral > floatLiteral
Matches float literals of all sizes / encodings, e.g.
Definition: ASTMatchers.h:1693
const internal::VariadicDynCastAllOfMatcher< Stmt, IfStmt > ifStmt
Matches if statements.
Definition: ASTMatchers.h:1384
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
Definition: ASTMatchers.h:1020
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXCatchStmt > cxxCatchStmt
Matches catch statements.
Definition: ASTMatchers.h:1602
internal::Matcher< BinaryOperator > hasEitherOperand(const internal::Matcher< Expr > &InnerMatcher)
Matches if either the left hand side or the right hand side of a binary operator matches.
Definition: ASTMatchers.h:3646
const internal::VariadicOperatorMatcherFunc< 2, UINT_MAX > anyOf
Matches if any of the given matchers matches.
Definition: ASTMatchers.h:2014
const internal::VariadicDynCastAllOfMatcher< Stmt, ContinueStmt > continueStmt
Matches continue statements.
Definition: ASTMatchers.h:1501
const internal::VariadicAllOfMatcher< TemplateArgument > templateArgument
Matches template arguments.
Definition: ASTMatchers.h:448
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
Definition: ASTMatchers.h:1920
internal::Matcher< NamedDecl > hasName(const std::string &Name)
Matches NamedDecl nodes that have the specified name.
Definition: ASTMatchers.h:2096
const internal::VariadicDynCastAllOfMatcher< Decl, TypedefNameDecl > typedefNameDecl
Matches typedef name declarations.
Definition: ASTMatchers.h:182
const internal::VariadicDynCastAllOfMatcher< Stmt, ParenListExpr > parenListExpr
Matches paren list expressions.
Definition: ASTMatchers.h:1123
const internal::VariadicDynCastAllOfMatcher< Stmt, ImplicitValueInitExpr > implicitValueInitExpr
Matches implicit initializers of init list expressions.
Definition: ASTMatchers.h:1106
raw_ostream & operator<<(raw_ostream &OS, ASTNodeKind K)
const internal::VariadicDynCastAllOfMatcher< Decl, CXXConversionDecl > cxxConversionDecl
Matches conversion operator declarations.
Definition: ASTMatchers.h:926
const internal::VariadicDynCastAllOfMatcher< Decl, NamespaceDecl > namespaceDecl
Matches a declaration of a namespace.
Definition: ASTMatchers.h:329
const internal::VariadicDynCastAllOfMatcher< Stmt, UserDefinedLiteral > userDefinedLiteral
Matches user defined literal operator call.
Definition: ASTMatchers.h:1700
const internal::VariadicDynCastAllOfMatcher< Stmt, SwitchStmt > switchStmt
Matches switch statements.
Definition: ASTMatchers.h:1555
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXBoolLiteralExpr > cxxBoolLiteral
Matches bool literals.
Definition: ASTMatchers.h:1649
const internal::VariadicDynCastAllOfMatcher< Decl, FieldDecl > fieldDecl
Matches field declarations.
Definition: ASTMatchers.h:947
const internal::VariadicDynCastAllOfMatcher< Stmt, UnresolvedLookupExpr > unresolvedLookupExpr
Matches reference to a name that can be looked up during parsing but could not be resolved to a speci...
Definition: ASTMatchers.h:1179
ConstructorMap Constructors
Definition: Registry.cpp:44
virtual void getArgKinds(ast_type_traits::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...
const internal::VariadicDynCastAllOfMatcher< Decl, NamespaceAliasDecl > namespaceAliasDecl
Matches a declaration of a namespace alias.
Definition: ASTMatchers.h:341
virtual bool isConvertibleTo(ast_type_traits::ASTNodeKind Kind, unsigned *Specificity=nullptr, ast_type_traits::ASTNodeKind *LeastDerivedKind=nullptr) const =0
Returns whether this matcher is convertible to the given type.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXRecordDecl > cxxRecordDecl
Matches C++ class declarations.
Definition: ASTMatchers.h:365
const internal::VariadicDynCastAllOfMatcher< Decl, DeclaratorDecl > declaratorDecl
Matches declarator declarations (field, variable, function and non-type template parameter declaratio...
Definition: ASTMatchers.h:401
llvm::Optional< DynTypedMatcher > getSingleMatcher() const
Return a single matcher, if there is no ambiguity.
static bool isExternC(const NamedDecl *ND)
Definition: Mangle.cpp:59
const internal::VariadicDynCastAllOfMatcher< Stmt, GNUNullExpr > gnuNullExpr
Matches GNU __null expression.
Definition: ASTMatchers.h:1719