Coverage Report

Created: 2022-01-18 06:27

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