Coverage Report

Created: 2021-08-24 07:12

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