Coverage Report

Created: 2020-09-19 12:23

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