Coverage Report

Created: 2021-01-23 06:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/ASTMatchers/Dynamic/Registry.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Registry.cpp - Matcher registry ------------------------------------===//
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
/// Registry map populated at static initialization time.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/ASTMatchers/Dynamic/Registry.h"
15
#include "Marshallers.h"
16
#include "clang/AST/ASTTypeTraits.h"
17
#include "clang/ASTMatchers/ASTMatchers.h"
18
#include "clang/ASTMatchers/Dynamic/Diagnostics.h"
19
#include "clang/ASTMatchers/Dynamic/VariantValue.h"
20
#include "llvm/ADT/Optional.h"
21
#include "llvm/ADT/STLExtras.h"
22
#include "llvm/ADT/StringMap.h"
23
#include "llvm/ADT/StringRef.h"
24
#include "llvm/Support/ManagedStatic.h"
25
#include "llvm/Support/raw_ostream.h"
26
#include <cassert>
27
#include <iterator>
28
#include <memory>
29
#include <set>
30
#include <string>
31
#include <utility>
32
#include <vector>
33
34
namespace clang {
35
namespace ast_matchers {
36
namespace dynamic {
37
38
namespace {
39
40
using internal::MatcherDescriptor;
41
42
using ConstructorMap =
43
    llvm::StringMap<std::unique_ptr<const MatcherDescriptor>>;
44
45
class RegistryMaps {
46
public:
47
  RegistryMaps();
48
  ~RegistryMaps();
49
50
384
  const ConstructorMap &constructors() const { return Constructors; }
51
52
private:
53
  void registerMatcher(StringRef MatcherName,
54
                       std::unique_ptr<MatcherDescriptor> Callback);
55
56
  ConstructorMap Constructors;
57
};
58
59
} // namespace
60
61
void RegistryMaps::registerMatcher(
62
10.1k
    StringRef MatcherName, std::unique_ptr<MatcherDescriptor> Callback) {
63
10.1k
  assert(Constructors.find(MatcherName) == Constructors.end());
64
10.1k
  Constructors[MatcherName] = std::move(Callback);
65
10.1k
}
66
67
#define REGISTER_MATCHER(name)                                                 \
68
9.77k
  registerMatcher(#name, internal::makeMatcherAutoMarshall(                    \
69
9.77k
                             ::clang::ast_matchers::name, #name));
70
71
#define REGISTER_MATCHER_OVERLOAD(name)                                        \
72
299
  registerMatcher(#name,                                                       \
73
299
      std::make_unique<internal::OverloadedMatcherDescriptor>(name##Callbacks))
74
75
#define SPECIFIC_MATCHER_OVERLOAD(name, Id)                                    \
76
621
  static_cast<::clang::ast_matchers::name##_Type##Id>(                         \
77
621
      ::clang::ast_matchers::name)
78
79
#define MATCHER_OVERLOAD_ENTRY(name, Id)                                       \
80
621
        internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, Id), \
81
621
                                          #name)
82
83
#define REGISTER_OVERLOADED_2(name)                                            \
84
276
  do {                                                                         \
85
276
    std::unique_ptr<MatcherDescriptor> name##Callbacks[] = {                   \
86
276
        MATCHER_OVERLOAD_ENTRY(name, 0),                                       \
87
276
        MATCHER_OVERLOAD_ENTRY(name, 1)};                                      \
88
276
    REGISTER_MATCHER_OVERLOAD(name);                                           \
89
276
  } while (false)
90
91
#define REGISTER_REGEX_MATCHER(name)                                           \
92
69
  registerMatcher(#name, internal::makeMatcherRegexMarshall(name, name))
93
94
/// Generate a registry map with all the known matchers.
95
/// Please keep sorted alphabetically!
96
23
RegistryMaps::RegistryMaps() {
97
  // TODO: Here is the list of the missing matchers, grouped by reason.
98
  //
99
  // Polymorphic + argument overload:
100
  // findAll
101
  //
102
  // Other:
103
  // equalsNode
104
105
23
  REGISTER_OVERLOADED_2(callee);
106
23
  REGISTER_OVERLOADED_2(hasAnyCapture);
107
23
  REGISTER_OVERLOADED_2(hasPrefix);
108
23
  REGISTER_OVERLOADED_2(hasType);
109
23
  REGISTER_OVERLOADED_2(ignoringParens);
110
23
  REGISTER_OVERLOADED_2(isDerivedFrom);
111
23
  REGISTER_OVERLOADED_2(isDirectlyDerivedFrom);
112
23
  REGISTER_OVERLOADED_2(isSameOrDerivedFrom);
113
23
  REGISTER_OVERLOADED_2(loc);
114
23
  REGISTER_OVERLOADED_2(pointsTo);
115
23
  REGISTER_OVERLOADED_2(references);
116
23
  REGISTER_OVERLOADED_2(thisPointerType);
117
118
23
  std::unique_ptr<MatcherDescriptor> equalsCallbacks[] = {
119
23
      MATCHER_OVERLOAD_ENTRY(equals, 0),
120
23
      MATCHER_OVERLOAD_ENTRY(equals, 1),
121
23
      MATCHER_OVERLOAD_ENTRY(equals, 2),
122
23
  };
123
23
  REGISTER_MATCHER_OVERLOAD(equals);
124
125
23
  REGISTER_REGEX_MATCHER(isExpansionInFileMatching);
126
23
  REGISTER_REGEX_MATCHER(matchesName);
127
23
  REGISTER_REGEX_MATCHER(matchesSelector);
128
129
23
  REGISTER_MATCHER(accessSpecDecl);
130
23
  REGISTER_MATCHER(addrLabelExpr);
131
23
  REGISTER_MATCHER(alignOfExpr);
132
23
  REGISTER_MATCHER(allOf);
133
23
  REGISTER_MATCHER(anyOf);
134
23
  REGISTER_MATCHER(anything);
135
23
  REGISTER_MATCHER(argumentCountIs);
136
23
  REGISTER_MATCHER(arraySubscriptExpr);
137
23
  REGISTER_MATCHER(arrayType);
138
23
  REGISTER_MATCHER(asString);
139
23
  REGISTER_MATCHER(asmStmt);
140
23
  REGISTER_MATCHER(atomicExpr);
141
23
  REGISTER_MATCHER(atomicType);
142
23
  REGISTER_MATCHER(autoType);
143
23
  REGISTER_MATCHER(autoreleasePoolStmt)
144
23
  REGISTER_MATCHER(binaryConditionalOperator);
145
23
  REGISTER_MATCHER(binaryOperator);
146
23
  REGISTER_MATCHER(binaryOperation);
147
23
  REGISTER_MATCHER(blockDecl);
148
23
  REGISTER_MATCHER(blockExpr);
149
23
  REGISTER_MATCHER(blockPointerType);
150
23
  REGISTER_MATCHER(booleanType);
151
23
  REGISTER_MATCHER(breakStmt);
152
23
  REGISTER_MATCHER(builtinType);
153
23
  REGISTER_MATCHER(cStyleCastExpr);
154
23
  REGISTER_MATCHER(callExpr);
155
23
  REGISTER_MATCHER(caseStmt);
156
23
  REGISTER_MATCHER(castExpr);
157
23
  REGISTER_MATCHER(characterLiteral);
158
23
  REGISTER_MATCHER(chooseExpr);
159
23
  REGISTER_MATCHER(classTemplateDecl);
160
23
  REGISTER_MATCHER(classTemplatePartialSpecializationDecl);
161
23
  REGISTER_MATCHER(classTemplateSpecializationDecl);
162
23
  REGISTER_MATCHER(complexType);
163
23
  REGISTER_MATCHER(compoundLiteralExpr);
164
23
  REGISTER_MATCHER(compoundStmt);
165
23
  REGISTER_MATCHER(conditionalOperator);
166
23
  REGISTER_MATCHER(constantArrayType);
167
23
  REGISTER_MATCHER(constantExpr);
168
23
  REGISTER_MATCHER(containsDeclaration);
169
23
  REGISTER_MATCHER(continueStmt);
170
23
  REGISTER_MATCHER(cudaKernelCallExpr);
171
23
  REGISTER_MATCHER(cxxBindTemporaryExpr);
172
23
  REGISTER_MATCHER(cxxBoolLiteral);
173
23
  REGISTER_MATCHER(cxxCatchStmt);
174
23
  REGISTER_MATCHER(cxxConstCastExpr);
175
23
  REGISTER_MATCHER(cxxConstructExpr);
176
23
  REGISTER_MATCHER(cxxConstructorDecl);
177
23
  REGISTER_MATCHER(cxxConversionDecl);
178
23
  REGISTER_MATCHER(cxxCtorInitializer);
179
23
  REGISTER_MATCHER(cxxDeductionGuideDecl);
180
23
  REGISTER_MATCHER(cxxDefaultArgExpr);
181
23
  REGISTER_MATCHER(cxxDeleteExpr);
182
23
  REGISTER_MATCHER(cxxDependentScopeMemberExpr);
183
23
  REGISTER_MATCHER(cxxDestructorDecl);
184
23
  REGISTER_MATCHER(cxxDynamicCastExpr);
185
23
  REGISTER_MATCHER(cxxForRangeStmt);
186
23
  REGISTER_MATCHER(cxxFunctionalCastExpr);
187
23
  REGISTER_MATCHER(cxxMemberCallExpr);
188
23
  REGISTER_MATCHER(cxxMethodDecl);
189
23
  REGISTER_MATCHER(cxxNewExpr);
190
23
  REGISTER_MATCHER(cxxNoexceptExpr);
191
23
  REGISTER_MATCHER(cxxNullPtrLiteralExpr);
192
23
  REGISTER_MATCHER(cxxOperatorCallExpr);
193
23
  REGISTER_MATCHER(cxxRecordDecl);
194
23
  REGISTER_MATCHER(cxxReinterpretCastExpr);
195
23
  REGISTER_MATCHER(cxxRewrittenBinaryOperator);
196
23
  REGISTER_MATCHER(cxxStaticCastExpr);
197
23
  REGISTER_MATCHER(cxxStdInitializerListExpr);
198
23
  REGISTER_MATCHER(cxxTemporaryObjectExpr);
199
23
  REGISTER_MATCHER(cxxThisExpr);
200
23
  REGISTER_MATCHER(cxxThrowExpr);
201
23
  REGISTER_MATCHER(cxxTryStmt);
202
23
  REGISTER_MATCHER(cxxUnresolvedConstructExpr);
203
23
  REGISTER_MATCHER(decayedType);
204
23
  REGISTER_MATCHER(decl);
205
23
  REGISTER_MATCHER(decompositionDecl);
206
23
  REGISTER_MATCHER(declCountIs);
207
23
  REGISTER_MATCHER(declRefExpr);
208
23
  REGISTER_MATCHER(declStmt);
209
23
  REGISTER_MATCHER(declaratorDecl);
210
23
  REGISTER_MATCHER(decltypeType);
211
23
  REGISTER_MATCHER(deducedTemplateSpecializationType);
212
23
  REGISTER_MATCHER(defaultStmt);
213
23
  REGISTER_MATCHER(dependentSizedArrayType);
214
23
  REGISTER_MATCHER(designatedInitExpr);
215
23
  REGISTER_MATCHER(designatorCountIs);
216
23
  REGISTER_MATCHER(doStmt);
217
23
  REGISTER_MATCHER(eachOf);
218
23
  REGISTER_MATCHER(elaboratedType);
219
23
  REGISTER_MATCHER(enumConstantDecl);
220
23
  REGISTER_MATCHER(enumDecl);
221
23
  REGISTER_MATCHER(enumType);
222
23
  REGISTER_MATCHER(equalsBoundNode);
223
23
  REGISTER_MATCHER(equalsIntegralValue);
224
23
  REGISTER_MATCHER(explicitCastExpr);
225
23
  REGISTER_MATCHER(expr);
226
23
  REGISTER_MATCHER(exprWithCleanups);
227
23
  REGISTER_MATCHER(fieldDecl);
228
23
  REGISTER_MATCHER(floatLiteral);
229
23
  REGISTER_MATCHER(forEach);
230
23
  REGISTER_MATCHER(forEachArgumentWithParam);
231
23
  REGISTER_MATCHER(forEachArgumentWithParamType);
232
23
  REGISTER_MATCHER(forEachConstructorInitializer);
233
23
  REGISTER_MATCHER(forEachDescendant);
234
23
  REGISTER_MATCHER(forEachOverridden);
235
23
  REGISTER_MATCHER(forEachSwitchCase);
236
23
  REGISTER_MATCHER(forField);
237
23
  REGISTER_MATCHER(forFunction);
238
23
  REGISTER_MATCHER(forStmt);
239
23
  REGISTER_MATCHER(friendDecl);
240
23
  REGISTER_MATCHER(functionDecl);
241
23
  REGISTER_MATCHER(functionProtoType);
242
23
  REGISTER_MATCHER(functionTemplateDecl);
243
23
  REGISTER_MATCHER(functionType);
244
23
  REGISTER_MATCHER(genericSelectionExpr);
245
23
  REGISTER_MATCHER(gnuNullExpr);
246
23
  REGISTER_MATCHER(gotoStmt);
247
23
  REGISTER_MATCHER(has);
248
23
  REGISTER_MATCHER(hasAncestor);
249
23
  REGISTER_MATCHER(hasAnyArgument);
250
23
  REGISTER_MATCHER(hasAnyBase);
251
23
  REGISTER_MATCHER(hasAnyClause);
252
23
  REGISTER_MATCHER(hasAnyConstructorInitializer);
253
23
  REGISTER_MATCHER(hasAnyDeclaration);
254
23
  REGISTER_MATCHER(hasAnyName);
255
23
  REGISTER_MATCHER(hasAnyOperatorName);
256
23
  REGISTER_MATCHER(hasAnyOverloadedOperatorName);
257
23
  REGISTER_MATCHER(hasAnyParameter);
258
23
  REGISTER_MATCHER(hasAnyPlacementArg);
259
23
  REGISTER_MATCHER(hasAnySelector);
260
23
  REGISTER_MATCHER(hasAnySubstatement);
261
23
  REGISTER_MATCHER(hasAnyTemplateArgument);
262
23
  REGISTER_MATCHER(hasAnyUsingShadowDecl);
263
23
  REGISTER_MATCHER(hasArgument);
264
23
  REGISTER_MATCHER(hasArgumentOfType);
265
23
  REGISTER_MATCHER(hasArraySize);
266
23
  REGISTER_MATCHER(hasAttr);
267
23
  REGISTER_MATCHER(hasAutomaticStorageDuration);
268
23
  REGISTER_MATCHER(hasBase);
269
23
  REGISTER_MATCHER(hasBitWidth);
270
23
  REGISTER_MATCHER(hasBody);
271
23
  REGISTER_MATCHER(hasCanonicalType);
272
23
  REGISTER_MATCHER(hasCaseConstant);
273
23
  REGISTER_MATCHER(hasCastKind);
274
23
  REGISTER_MATCHER(hasCondition);
275
23
  REGISTER_MATCHER(hasConditionVariableStatement);
276
23
  REGISTER_MATCHER(hasDecayedType);
277
23
  REGISTER_MATCHER(hasDeclContext);
278
23
  REGISTER_MATCHER(hasDeclaration);
279
23
  REGISTER_MATCHER(hasDeducedType);
280
23
  REGISTER_MATCHER(hasDefaultArgument);
281
23
  REGISTER_MATCHER(hasDefinition);
282
23
  REGISTER_MATCHER(hasDescendant);
283
23
  REGISTER_MATCHER(hasDestinationType);
284
23
  REGISTER_MATCHER(hasDirectBase);
285
23
  REGISTER_MATCHER(hasDynamicExceptionSpec);
286
23
  REGISTER_MATCHER(hasEitherOperand);
287
23
  REGISTER_MATCHER(hasElementType);
288
23
  REGISTER_MATCHER(hasElse);
289
23
  REGISTER_MATCHER(hasExplicitSpecifier);
290
23
  REGISTER_MATCHER(hasExternalFormalLinkage);
291
23
  REGISTER_MATCHER(hasFalseExpression);
292
23
  REGISTER_MATCHER(hasGlobalStorage);
293
23
  REGISTER_MATCHER(hasImplicitDestinationType);
294
23
  REGISTER_MATCHER(hasInClassInitializer);
295
23
  REGISTER_MATCHER(hasIncrement);
296
23
  REGISTER_MATCHER(hasIndex);
297
23
  REGISTER_MATCHER(hasInit);
298
23
  REGISTER_MATCHER(hasInitializer);
299
23
  REGISTER_MATCHER(hasInitStatement);
300
23
  REGISTER_MATCHER(hasKeywordSelector);
301
23
  REGISTER_MATCHER(hasLHS);
302
23
  REGISTER_MATCHER(hasLocalQualifiers);
303
23
  REGISTER_MATCHER(hasLocalStorage);
304
23
  REGISTER_MATCHER(hasLoopInit);
305
23
  REGISTER_MATCHER(hasLoopVariable);
306
23
  REGISTER_MATCHER(hasMemberName);
307
23
  REGISTER_MATCHER(hasMethod);
308
23
  REGISTER_MATCHER(hasName);
309
23
  REGISTER_MATCHER(hasNullSelector);
310
23
  REGISTER_MATCHER(hasObjectExpression);
311
23
  REGISTER_MATCHER(hasOperands);
312
23
  REGISTER_MATCHER(hasOperatorName);
313
23
  REGISTER_MATCHER(hasOverloadedOperatorName);
314
23
  REGISTER_MATCHER(hasParameter);
315
23
  REGISTER_MATCHER(hasParent);
316
23
  REGISTER_MATCHER(hasQualifier);
317
23
  REGISTER_MATCHER(hasRHS);
318
23
  REGISTER_MATCHER(hasRangeInit);
319
23
  REGISTER_MATCHER(hasReceiver);
320
23
  REGISTER_MATCHER(hasReceiverType);
321
23
  REGISTER_MATCHER(hasReplacementType);
322
23
  REGISTER_MATCHER(hasReturnValue);
323
23
  REGISTER_MATCHER(hasPlacementArg);
324
23
  REGISTER_MATCHER(hasSelector);
325
23
  REGISTER_MATCHER(hasSingleDecl);
326
23
  REGISTER_MATCHER(hasSize);
327
23
  REGISTER_MATCHER(hasSizeExpr);
328
23
  REGISTER_MATCHER(hasSourceExpression);
329
23
  REGISTER_MATCHER(hasSpecializedTemplate);
330
23
  REGISTER_MATCHER(hasStaticStorageDuration);
331
23
  REGISTER_MATCHER(hasStructuredBlock);
332
23
  REGISTER_MATCHER(hasSyntacticForm);
333
23
  REGISTER_MATCHER(hasTargetDecl);
334
23
  REGISTER_MATCHER(hasTemplateArgument);
335
23
  REGISTER_MATCHER(hasThen);
336
23
  REGISTER_MATCHER(hasThreadStorageDuration);
337
23
  REGISTER_MATCHER(hasTrailingReturn);
338
23
  REGISTER_MATCHER(hasTrueExpression);
339
23
  REGISTER_MATCHER(hasTypeLoc);
340
23
  REGISTER_MATCHER(hasUnaryOperand);
341
23
  REGISTER_MATCHER(hasUnarySelector);
342
23
  REGISTER_MATCHER(hasUnderlyingDecl);
343
23
  REGISTER_MATCHER(hasUnderlyingType);
344
23
  REGISTER_MATCHER(hasUnqualifiedDesugaredType);
345
23
  REGISTER_MATCHER(hasValueType);
346
23
  REGISTER_MATCHER(ifStmt);
347
23
  REGISTER_MATCHER(ignoringElidableConstructorCall);
348
23
  REGISTER_MATCHER(ignoringImpCasts);
349
23
  REGISTER_MATCHER(ignoringImplicit);
350
23
  REGISTER_MATCHER(ignoringParenCasts);
351
23
  REGISTER_MATCHER(ignoringParenImpCasts);
352
23
  REGISTER_MATCHER(imaginaryLiteral);
353
23
  REGISTER_MATCHER(implicitCastExpr);
354
23
  REGISTER_MATCHER(implicitValueInitExpr);
355
23
  REGISTER_MATCHER(incompleteArrayType);
356
23
  REGISTER_MATCHER(indirectFieldDecl);
357
23
  REGISTER_MATCHER(initListExpr);
358
23
  REGISTER_MATCHER(injectedClassNameType);
359
23
  REGISTER_MATCHER(innerType);
360
23
  REGISTER_MATCHER(integerLiteral);
361
23
  REGISTER_MATCHER(isAllowedToContainClauseKind);
362
23
  REGISTER_MATCHER(isAnonymous);
363
23
  REGISTER_MATCHER(isAnyCharacter);
364
23
  REGISTER_MATCHER(isAnyPointer);
365
23
  REGISTER_MATCHER(isArray);
366
23
  REGISTER_MATCHER(isArrow);
367
23
  REGISTER_MATCHER(isAssignmentOperator);
368
23
  REGISTER_MATCHER(isAtPosition);
369
23
  REGISTER_MATCHER(isBaseInitializer);
370
23
  REGISTER_MATCHER(isBitField);
371
23
  REGISTER_MATCHER(isCatchAll);
372
23
  REGISTER_MATCHER(isClass);
373
23
  REGISTER_MATCHER(isClassMessage);
374
23
  REGISTER_MATCHER(isClassMethod);
375
23
  REGISTER_MATCHER(isComparisonOperator);
376
23
  REGISTER_MATCHER(isConst);
377
23
  REGISTER_MATCHER(isConstQualified);
378
23
  REGISTER_MATCHER(isConstexpr);
379
23
  REGISTER_MATCHER(isCopyAssignmentOperator);
380
23
  REGISTER_MATCHER(isCopyConstructor);
381
23
  REGISTER_MATCHER(isDefaultConstructor);
382
23
  REGISTER_MATCHER(isDefaulted);
383
23
  REGISTER_MATCHER(isDefinition);
384
23
  REGISTER_MATCHER(isDelegatingConstructor);
385
23
  REGISTER_MATCHER(isDeleted);
386
23
  REGISTER_MATCHER(isEnum);
387
23
  REGISTER_MATCHER(isExceptionVariable);
388
23
  REGISTER_MATCHER(isExpandedFromMacro);
389
23
  REGISTER_MATCHER(isExpansionInMainFile);
390
23
  REGISTER_MATCHER(isExpansionInSystemHeader);
391
23
  REGISTER_MATCHER(isExplicit);
392
23
  REGISTER_MATCHER(isExplicitTemplateSpecialization);
393
23
  REGISTER_MATCHER(isExpr);
394
23
  REGISTER_MATCHER(isExternC);
395
23
  REGISTER_MATCHER(isFinal);
396
23
  REGISTER_MATCHER(isFirstPrivateKind);
397
23
  REGISTER_MATCHER(isImplicit);
398
23
  REGISTER_MATCHER(isInStdNamespace);
399
23
  REGISTER_MATCHER(isInTemplateInstantiation);
400
23
  REGISTER_MATCHER(isInline);
401
23
  REGISTER_MATCHER(isInstanceMessage);
402
23
  REGISTER_MATCHER(isInstanceMethod);
403
23
  REGISTER_MATCHER(isInstantiated);
404
23
  REGISTER_MATCHER(isInstantiationDependent);
405
23
  REGISTER_MATCHER(isInteger);
406
23
  REGISTER_MATCHER(isIntegral);
407
23
  REGISTER_MATCHER(isLambda);
408
23
  REGISTER_MATCHER(isListInitialization);
409
23
  REGISTER_MATCHER(isMain);
410
23
  REGISTER_MATCHER(isMemberInitializer);
411
23
  REGISTER_MATCHER(isMoveAssignmentOperator);
412
23
  REGISTER_MATCHER(isMoveConstructor);
413
23
  REGISTER_MATCHER(isNoReturn);
414
23
  REGISTER_MATCHER(isNoThrow);
415
23
  REGISTER_MATCHER(isNoneKind);
416
23
  REGISTER_MATCHER(isOverride);
417
23
  REGISTER_MATCHER(isPrivate);
418
23
  REGISTER_MATCHER(isProtected);
419
23
  REGISTER_MATCHER(isPublic);
420
23
  REGISTER_MATCHER(isPure);
421
23
  REGISTER_MATCHER(isScoped);
422
23
  REGISTER_MATCHER(isSharedKind);
423
23
  REGISTER_MATCHER(isSignedInteger);
424
23
  REGISTER_MATCHER(isStandaloneDirective);
425
23
  REGISTER_MATCHER(isStaticLocal);
426
23
  REGISTER_MATCHER(isStaticStorageClass);
427
23
  REGISTER_MATCHER(isStruct);
428
23
  REGISTER_MATCHER(isTemplateInstantiation);
429
23
  REGISTER_MATCHER(isTypeDependent);
430
23
  REGISTER_MATCHER(isUnion);
431
23
  REGISTER_MATCHER(isUnsignedInteger);
432
23
  REGISTER_MATCHER(isUserProvided);
433
23
  REGISTER_MATCHER(isValueDependent);
434
23
  REGISTER_MATCHER(isVariadic);
435
23
  REGISTER_MATCHER(isVirtual);
436
23
  REGISTER_MATCHER(isVirtualAsWritten);
437
23
  REGISTER_MATCHER(isVolatileQualified);
438
23
  REGISTER_MATCHER(isWeak);
439
23
  REGISTER_MATCHER(isWritten);
440
23
  REGISTER_MATCHER(lValueReferenceType);
441
23
  REGISTER_MATCHER(labelDecl);
442
23
  REGISTER_MATCHER(labelStmt);
443
23
  REGISTER_MATCHER(lambdaExpr);
444
23
  REGISTER_MATCHER(linkageSpecDecl);
445
23
  REGISTER_MATCHER(materializeTemporaryExpr);
446
23
  REGISTER_MATCHER(member);
447
23
  REGISTER_MATCHER(memberExpr);
448
23
  REGISTER_MATCHER(memberHasSameNameAsBoundNode);
449
23
  REGISTER_MATCHER(memberPointerType);
450
23
  REGISTER_MATCHER(namedDecl);
451
23
  REGISTER_MATCHER(namesType);
452
23
  REGISTER_MATCHER(namespaceAliasDecl);
453
23
  REGISTER_MATCHER(namespaceDecl);
454
23
  REGISTER_MATCHER(nestedNameSpecifier);
455
23
  REGISTER_MATCHER(nestedNameSpecifierLoc);
456
23
  REGISTER_MATCHER(nonTypeTemplateParmDecl);
457
23
  REGISTER_MATCHER(nullPointerConstant);
458
23
  REGISTER_MATCHER(nullStmt);
459
23
  REGISTER_MATCHER(numSelectorArgs);
460
23
  REGISTER_MATCHER(objcCatchStmt);
461
23
  REGISTER_MATCHER(objcCategoryDecl);
462
23
  REGISTER_MATCHER(objcCategoryImplDecl);
463
23
  REGISTER_MATCHER(objcFinallyStmt);
464
23
  REGISTER_MATCHER(objcImplementationDecl);
465
23
  REGISTER_MATCHER(objcInterfaceDecl);
466
23
  REGISTER_MATCHER(objcIvarDecl);
467
23
  REGISTER_MATCHER(objcIvarRefExpr);
468
23
  REGISTER_MATCHER(objcMessageExpr);
469
23
  REGISTER_MATCHER(objcMethodDecl);
470
23
  REGISTER_MATCHER(objcObjectPointerType);
471
23
  REGISTER_MATCHER(objcPropertyDecl);
472
23
  REGISTER_MATCHER(objcProtocolDecl);
473
23
  REGISTER_MATCHER(objcThrowStmt);
474
23
  REGISTER_MATCHER(objcTryStmt);
475
23
  REGISTER_MATCHER(ofClass);
476
23
  REGISTER_MATCHER(ofKind);
477
23
  REGISTER_MATCHER(ompDefaultClause);
478
23
  REGISTER_MATCHER(ompExecutableDirective);
479
23
  REGISTER_MATCHER(on);
480
23
  REGISTER_MATCHER(onImplicitObjectArgument);
481
23
  REGISTER_MATCHER(opaqueValueExpr);
482
23
  REGISTER_MATCHER(optionally);
483
23
  REGISTER_MATCHER(parameterCountIs);
484
23
  REGISTER_MATCHER(parenExpr);
485
23
  REGISTER_MATCHER(parenListExpr);
486
23
  REGISTER_MATCHER(parenType);
487
23
  REGISTER_MATCHER(parmVarDecl);
488
23
  REGISTER_MATCHER(pointee);
489
23
  REGISTER_MATCHER(pointerType);
490
23
  REGISTER_MATCHER(predefinedExpr);
491
23
  REGISTER_MATCHER(qualType);
492
23
  REGISTER_MATCHER(rValueReferenceType);
493
23
  REGISTER_MATCHER(realFloatingPointType);
494
23
  REGISTER_MATCHER(recordDecl);
495
23
  REGISTER_MATCHER(recordType);
496
23
  REGISTER_MATCHER(referenceType);
497
23
  REGISTER_MATCHER(refersToDeclaration);
498
23
  REGISTER_MATCHER(refersToIntegralType);
499
23
  REGISTER_MATCHER(refersToTemplate);
500
23
  REGISTER_MATCHER(refersToType);
501
23
  REGISTER_MATCHER(requiresZeroInitialization);
502
23
  REGISTER_MATCHER(returnStmt);
503
23
  REGISTER_MATCHER(returns);
504
23
  REGISTER_MATCHER(sizeOfExpr);
505
23
  REGISTER_MATCHER(specifiesNamespace);
506
23
  REGISTER_MATCHER(specifiesType);
507
23
  REGISTER_MATCHER(specifiesTypeLoc);
508
23
  REGISTER_MATCHER(statementCountIs);
509
23
  REGISTER_MATCHER(staticAssertDecl);
510
23
  REGISTER_MATCHER(stmt);
511
23
  REGISTER_MATCHER(stmtExpr);
512
23
  REGISTER_MATCHER(stringLiteral);
513
23
  REGISTER_MATCHER(substNonTypeTemplateParmExpr);
514
23
  REGISTER_MATCHER(substTemplateTypeParmType);
515
23
  REGISTER_MATCHER(switchCase);
516
23
  REGISTER_MATCHER(switchStmt);
517
23
  REGISTER_MATCHER(tagDecl);
518
23
  REGISTER_MATCHER(tagType);
519
23
  REGISTER_MATCHER(templateArgument);
520
23
  REGISTER_MATCHER(templateArgumentCountIs);
521
23
  REGISTER_MATCHER(templateName);
522
23
  REGISTER_MATCHER(templateSpecializationType);
523
23
  REGISTER_MATCHER(templateTemplateParmDecl);
524
23
  REGISTER_MATCHER(templateTypeParmDecl);
525
23
  REGISTER_MATCHER(templateTypeParmType);
526
23
  REGISTER_MATCHER(throughUsingDecl);
527
23
  REGISTER_MATCHER(to);
528
23
  REGISTER_MATCHER(translationUnitDecl);
529
23
  REGISTER_MATCHER(type);
530
23
  REGISTER_MATCHER(typeAliasDecl);
531
23
  REGISTER_MATCHER(typeAliasTemplateDecl);
532
23
  REGISTER_MATCHER(typeLoc);
533
23
  REGISTER_MATCHER(typedefDecl);
534
23
  REGISTER_MATCHER(typedefNameDecl);
535
23
  REGISTER_MATCHER(typedefType);
536
23
  REGISTER_MATCHER(unaryExprOrTypeTraitExpr);
537
23
  REGISTER_MATCHER(unaryOperator);
538
23
  REGISTER_MATCHER(unaryTransformType);
539
23
  REGISTER_MATCHER(unless);
540
23
  REGISTER_MATCHER(unresolvedLookupExpr);
541
23
  REGISTER_MATCHER(unresolvedMemberExpr);
542
23
  REGISTER_MATCHER(unresolvedUsingTypenameDecl);
543
23
  REGISTER_MATCHER(unresolvedUsingValueDecl);
544
23
  REGISTER_MATCHER(userDefinedLiteral);
545
23
  REGISTER_MATCHER(usesADL);
546
23
  REGISTER_MATCHER(usingDecl);
547
23
  REGISTER_MATCHER(usingDirectiveDecl);
548
23
  REGISTER_MATCHER(valueDecl);
549
23
  REGISTER_MATCHER(varDecl);
550
23
  REGISTER_MATCHER(variableArrayType);
551
23
  REGISTER_MATCHER(voidType);
552
23
  REGISTER_MATCHER(whileStmt);
553
23
  REGISTER_MATCHER(withInitializer);
554
23
}
555
556
0
RegistryMaps::~RegistryMaps() = default;
557
558
static llvm::ManagedStatic<RegistryMaps> RegistryData;
559
560
// static
561
187
llvm::Optional<MatcherCtor> Registry::lookupMatcherCtor(StringRef MatcherName) {
562
187
  auto it = RegistryData->constructors().find(MatcherName);
563
187
  return it == RegistryData->constructors().end()
564
5
             ? llvm::Optional<MatcherCtor>()
565
182
             : it->second.get();
566
187
}
567
568
static llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
569
1.30k
                                     const std::set<ASTNodeKind> &KS) {
570
1.30k
  unsigned Count = 0;
571
1.30k
  for (std::set<ASTNodeKind>::const_iterator I = KS.begin(), E = KS.end();
572
2.76k
       I != E; 
++I1.46k
) {
573
1.53k
    if (I != KS.begin())
574
228
      OS << "|";
575
1.53k
    if (Count++ == 3) {
576
66
      OS << "...";
577
66
      break;
578
66
    }
579
1.46k
    OS << *I;
580
1.46k
  }
581
1.30k
  return OS;
582
1.30k
}
583
584
std::vector<ArgKind> Registry::getAcceptedCompletionTypes(
585
10
    ArrayRef<std::pair<MatcherCtor, unsigned>> Context) {
586
10
  ASTNodeKind InitialTypes[] = {
587
10
      ASTNodeKind::getFromNodeKind<Decl>(),
588
10
      ASTNodeKind::getFromNodeKind<QualType>(),
589
10
      ASTNodeKind::getFromNodeKind<Type>(),
590
10
      ASTNodeKind::getFromNodeKind<Stmt>(),
591
10
      ASTNodeKind::getFromNodeKind<NestedNameSpecifier>(),
592
10
      ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>(),
593
10
      ASTNodeKind::getFromNodeKind<TypeLoc>()};
594
595
  // Starting with the above seed of acceptable top-level matcher types, compute
596
  // the acceptable type set for the argument indicated by each context element.
597
10
  std::set<ArgKind> TypeSet(std::begin(InitialTypes), std::end(InitialTypes));
598
11
  for (const auto &CtxEntry : Context) {
599
11
    MatcherCtor Ctor = CtxEntry.first;
600
11
    unsigned ArgNumber = CtxEntry.second;
601
11
    std::vector<ArgKind> NextTypeSet;
602
65
    for (const ArgKind &Kind : TypeSet) {
603
65
      if (Kind.getArgKind() == Kind.AK_Matcher &&
604
65
          Ctor->isConvertibleTo(Kind.getMatcherKind()) &&
605
16
          (Ctor->isVariadic() || 
ArgNumber < Ctor->getNumArgs()1
))
606
16
        Ctor->getArgKinds(Kind.getMatcherKind(), ArgNumber, NextTypeSet);
607
65
    }
608
11
    TypeSet.clear();
609
11
    TypeSet.insert(NextTypeSet.begin(), NextTypeSet.end());
610
11
  }
611
10
  return std::vector<ArgKind>(TypeSet.begin(), TypeSet.end());
612
10
}
613
614
std::vector<MatcherCompletion>
615
10
Registry::getMatcherCompletions(ArrayRef<ArgKind> AcceptedTypes) {
616
10
  std::vector<MatcherCompletion> Completions;
617
618
  // Search the registry for acceptable matchers.
619
4.41k
  for (const auto &M : RegistryData->constructors()) {
620
4.41k
    const MatcherDescriptor& Matcher = *M.getValue();
621
4.41k
    StringRef Name = M.getKey();
622
623
4.41k
    std::set<ASTNodeKind> RetKinds;
624
2.34k
    unsigned NumArgs = Matcher.isVariadic() ? 
12.07k
: Matcher.getNumArgs();
625
4.41k
    bool IsPolymorphic = Matcher.isPolymorphic();
626
4.41k
    std::vector<std::vector<ArgKind>> ArgsKinds(NumArgs);
627
4.41k
    unsigned MaxSpecificity = 0;
628
9.20k
    for (const ArgKind& Kind : AcceptedTypes) {
629
9.20k
      if (Kind.getArgKind() != Kind.AK_Matcher)
630
441
        continue;
631
8.76k
      unsigned Specificity;
632
8.76k
      ASTNodeKind LeastDerivedKind;
633
8.76k
      if (Matcher.isConvertibleTo(Kind.getMatcherKind(), &Specificity,
634
1.22k
                                  &LeastDerivedKind)) {
635
1.22k
        if (MaxSpecificity < Specificity)
636
787
          MaxSpecificity = Specificity;
637
1.22k
        RetKinds.insert(LeastDerivedKind);
638
2.29k
        for (unsigned Arg = 0; Arg != NumArgs; 
++Arg1.06k
)
639
1.06k
          Matcher.getArgKinds(Kind.getMatcherKind(), Arg, ArgsKinds[Arg]);
640
1.22k
        if (IsPolymorphic)
641
40
          break;
642
1.22k
      }
643
8.76k
    }
644
645
4.41k
    if (!RetKinds.empty() && 
MaxSpecificity > 01.12k
) {
646
787
      std::string Decl;
647
787
      llvm::raw_string_ostream OS(Decl);
648
649
787
      if (IsPolymorphic) {
650
40
        OS << "Matcher<T> " << Name << "(Matcher<T>";
651
747
      } else {
652
747
        OS << "Matcher<" << RetKinds << "> " << Name << "(";
653
611
        for (const std::vector<ArgKind> &Arg : ArgsKinds) {
654
611
          if (&Arg != &ArgsKinds[0])
655
5
            OS << ", ";
656
657
611
          bool FirstArgKind = true;
658
611
          std::set<ASTNodeKind> MatcherKinds;
659
          // Two steps. First all non-matchers, then matchers only.
660
1.29k
          for (const ArgKind &AK : Arg) {
661
1.29k
            if (AK.getArgKind() == ArgKind::AK_Matcher) {
662
1.21k
              MatcherKinds.insert(AK.getMatcherKind());
663
73
            } else {
664
73
              if (!FirstArgKind) 
OS << "|"14
;
665
73
              FirstArgKind = false;
666
73
              OS << AK.asString();
667
73
            }
668
1.29k
          }
669
611
          if (!MatcherKinds.empty()) {
670
555
            if (!FirstArgKind) 
OS << "|"3
;
671
555
            OS << "Matcher<" << MatcherKinds << ">";
672
555
          }
673
611
        }
674
747
      }
675
787
      if (Matcher.isVariadic())
676
488
        OS << "...";
677
787
      OS << ")";
678
679
787
      std::string TypedText = std::string(Name);
680
787
      TypedText += "(";
681
787
      if (ArgsKinds.empty())
682
141
        TypedText += ")";
683
646
      else if (ArgsKinds[0][0].getArgKind() == ArgKind::AK_String)
684
48
        TypedText += "\"";
685
686
787
      Completions.emplace_back(TypedText, OS.str(), MaxSpecificity);
687
787
    }
688
4.41k
  }
689
690
10
  return Completions;
691
10
}
692
693
VariantMatcher Registry::constructMatcher(MatcherCtor Ctor,
694
                                          SourceRange NameRange,
695
                                          ArrayRef<ParserValue> Args,
696
156
                                          Diagnostics *Error) {
697
156
  return Ctor->create(NameRange, Args, Error);
698
156
}
699
700
VariantMatcher Registry::constructBoundMatcher(MatcherCtor Ctor,
701
                                               SourceRange NameRange,
702
                                               StringRef BindID,
703
                                               ArrayRef<ParserValue> Args,
704
3
                                               Diagnostics *Error) {
705
3
  VariantMatcher Out = constructMatcher(Ctor, NameRange, Args, Error);
706
3
  if (Out.isNull()) 
return Out0
;
707
708
3
  llvm::Optional<DynTypedMatcher> Result = Out.getSingleMatcher();
709
3
  if (Result.hasValue()) {
710
2
    llvm::Optional<DynTypedMatcher> Bound = Result->tryBind(BindID);
711
2
    if (Bound.hasValue()) {
712
2
      return VariantMatcher::SingleMatcher(*Bound);
713
2
    }
714
1
  }
715
1
  Error->addError(NameRange, Error->ET_RegistryNotBindable);
716
1
  return VariantMatcher();
717
1
}
718
719
} // namespace dynamic
720
} // namespace ast_matchers
721
} // namespace clang