Coverage Report

Created: 2023-05-31 04:38

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