Coverage Report

Created: 2022-07-16 07:03

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