Coverage Report

Created: 2020-02-25 14:32

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