2013-05-16 03:49:05 +08:00
|
|
|
//===--- Registry.cpp - Matcher registry -------------------------===//
|
2013-05-14 17:13:00 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
2013-05-16 03:49:05 +08:00
|
|
|
//===------------------------------------------------------------===//
|
2013-05-14 17:13:00 +08:00
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief Registry map populated at static initialization time.
|
|
|
|
///
|
2013-05-16 03:49:05 +08:00
|
|
|
//===------------------------------------------------------------===//
|
2013-05-14 17:13:00 +08:00
|
|
|
|
|
|
|
#include "clang/ASTMatchers/Dynamic/Registry.h"
|
|
|
|
#include "Marshallers.h"
|
|
|
|
#include "clang/ASTMatchers/ASTMatchers.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2014-01-24 06:48:38 +08:00
|
|
|
#include <set>
|
2014-01-07 19:51:46 +08:00
|
|
|
#include <utility>
|
2013-05-14 17:13:00 +08:00
|
|
|
|
2014-01-24 06:48:38 +08:00
|
|
|
using namespace clang::ast_type_traits;
|
|
|
|
|
2013-05-14 17:13:00 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace ast_matchers {
|
|
|
|
namespace dynamic {
|
|
|
|
namespace {
|
|
|
|
|
2013-11-23 09:34:36 +08:00
|
|
|
using internal::MatcherDescriptor;
|
2013-05-14 17:13:00 +08:00
|
|
|
|
2013-11-23 09:34:36 +08:00
|
|
|
typedef llvm::StringMap<const MatcherDescriptor *> ConstructorMap;
|
2013-05-14 17:13:00 +08:00
|
|
|
class RegistryMaps {
|
|
|
|
public:
|
|
|
|
RegistryMaps();
|
|
|
|
~RegistryMaps();
|
|
|
|
|
|
|
|
const ConstructorMap &constructors() const { return Constructors; }
|
|
|
|
|
|
|
|
private:
|
2013-11-23 09:34:36 +08:00
|
|
|
void registerMatcher(StringRef MatcherName, MatcherDescriptor *Callback);
|
2013-05-14 17:13:00 +08:00
|
|
|
ConstructorMap Constructors;
|
|
|
|
};
|
|
|
|
|
|
|
|
void RegistryMaps::registerMatcher(StringRef MatcherName,
|
2013-11-23 09:34:36 +08:00
|
|
|
MatcherDescriptor *Callback) {
|
2013-06-04 23:46:22 +08:00
|
|
|
assert(Constructors.find(MatcherName) == Constructors.end());
|
2013-05-14 17:13:00 +08:00
|
|
|
Constructors[MatcherName] = Callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define REGISTER_MATCHER(name) \
|
|
|
|
registerMatcher(#name, internal::makeMatcherAutoMarshall( \
|
|
|
|
::clang::ast_matchers::name, #name));
|
|
|
|
|
2013-07-23 00:13:57 +08:00
|
|
|
#define SPECIFIC_MATCHER_OVERLOAD(name, Id) \
|
|
|
|
static_cast< ::clang::ast_matchers::name##_Type##Id>( \
|
|
|
|
::clang::ast_matchers::name)
|
|
|
|
|
|
|
|
#define REGISTER_OVERLOADED_2(name) \
|
|
|
|
do { \
|
2013-11-23 09:34:36 +08:00
|
|
|
MatcherDescriptor *Callbacks[] = { \
|
2013-07-23 00:13:57 +08:00
|
|
|
internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 0), \
|
|
|
|
#name), \
|
|
|
|
internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 1), \
|
|
|
|
#name) \
|
|
|
|
}; \
|
2013-08-17 00:19:42 +08:00
|
|
|
registerMatcher(#name, \
|
2013-11-23 09:34:36 +08:00
|
|
|
new internal::OverloadedMatcherDescriptor(Callbacks)); \
|
2013-07-24 22:48:01 +08:00
|
|
|
} while (0)
|
|
|
|
|
2013-05-14 17:13:00 +08:00
|
|
|
/// \brief Generate a registry map with all the known matchers.
|
|
|
|
RegistryMaps::RegistryMaps() {
|
2013-06-04 23:46:22 +08:00
|
|
|
// TODO: Here is the list of the missing matchers, grouped by reason.
|
|
|
|
//
|
|
|
|
// Need Variant/Parser fixes:
|
|
|
|
// ofKind
|
|
|
|
//
|
|
|
|
// Polymorphic + argument overload:
|
|
|
|
// findAll
|
|
|
|
//
|
|
|
|
// Other:
|
|
|
|
// equals
|
|
|
|
// equalsNode
|
2013-05-14 17:13:00 +08:00
|
|
|
|
2013-07-23 00:13:57 +08:00
|
|
|
REGISTER_OVERLOADED_2(callee);
|
|
|
|
REGISTER_OVERLOADED_2(hasPrefix);
|
|
|
|
REGISTER_OVERLOADED_2(hasType);
|
|
|
|
REGISTER_OVERLOADED_2(isDerivedFrom);
|
|
|
|
REGISTER_OVERLOADED_2(isSameOrDerivedFrom);
|
2014-03-10 23:40:23 +08:00
|
|
|
REGISTER_OVERLOADED_2(loc);
|
2013-07-23 00:13:57 +08:00
|
|
|
REGISTER_OVERLOADED_2(pointsTo);
|
|
|
|
REGISTER_OVERLOADED_2(references);
|
|
|
|
REGISTER_OVERLOADED_2(thisPointerType);
|
|
|
|
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(accessSpecDecl);
|
|
|
|
REGISTER_MATCHER(alignOfExpr);
|
2013-08-29 02:42:04 +08:00
|
|
|
REGISTER_MATCHER(allOf);
|
|
|
|
REGISTER_MATCHER(anyOf);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(anything);
|
|
|
|
REGISTER_MATCHER(argumentCountIs);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(arraySubscriptExpr);
|
|
|
|
REGISTER_MATCHER(arrayType);
|
|
|
|
REGISTER_MATCHER(asmStmt);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(asString);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(atomicType);
|
|
|
|
REGISTER_MATCHER(autoType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(binaryOperator);
|
|
|
|
REGISTER_MATCHER(bindTemporaryExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(blockPointerType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(boolLiteral);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(breakStmt);
|
|
|
|
REGISTER_MATCHER(builtinType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(callExpr);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(caseStmt);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(castExpr);
|
|
|
|
REGISTER_MATCHER(catchStmt);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(characterLiteral);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(classTemplateDecl);
|
|
|
|
REGISTER_MATCHER(classTemplateSpecializationDecl);
|
|
|
|
REGISTER_MATCHER(complexType);
|
|
|
|
REGISTER_MATCHER(compoundLiteralExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(compoundStmt);
|
|
|
|
REGISTER_MATCHER(conditionalOperator);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(constantArrayType);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(constCastExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(constructExpr);
|
|
|
|
REGISTER_MATCHER(constructorDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(containsDeclaration);
|
|
|
|
REGISTER_MATCHER(continueStmt);
|
2015-04-21 04:58:50 +08:00
|
|
|
REGISTER_MATCHER(conversionDecl);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(cStyleCastExpr);
|
2013-08-15 08:33:08 +08:00
|
|
|
REGISTER_MATCHER(ctorInitializer);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(CUDAKernelCallExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(decl);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(declaratorDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(declCountIs);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(declRefExpr);
|
|
|
|
REGISTER_MATCHER(declStmt);
|
|
|
|
REGISTER_MATCHER(defaultArgExpr);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(defaultStmt);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(deleteExpr);
|
|
|
|
REGISTER_MATCHER(dependentSizedArrayType);
|
|
|
|
REGISTER_MATCHER(destructorDecl);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(doStmt);
|
|
|
|
REGISTER_MATCHER(dynamicCastExpr);
|
2013-08-29 02:42:04 +08:00
|
|
|
REGISTER_MATCHER(eachOf);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(elaboratedType);
|
|
|
|
REGISTER_MATCHER(enumConstantDecl);
|
|
|
|
REGISTER_MATCHER(enumDecl);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(equalsBoundNode);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(equalsIntegralValue);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(explicitCastExpr);
|
|
|
|
REGISTER_MATCHER(expr);
|
2014-04-02 21:12:14 +08:00
|
|
|
REGISTER_MATCHER(exprWithCleanups);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(fieldDecl);
|
2013-07-27 02:52:58 +08:00
|
|
|
REGISTER_MATCHER(floatLiteral);
|
2013-08-17 00:19:42 +08:00
|
|
|
REGISTER_MATCHER(forEach);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(forEachConstructorInitializer);
|
2013-08-17 00:19:42 +08:00
|
|
|
REGISTER_MATCHER(forEachDescendant);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(forEachSwitchCase);
|
2013-07-17 22:28:00 +08:00
|
|
|
REGISTER_MATCHER(forField);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(forRangeStmt);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(forStmt);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(friendDecl);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(functionalCastExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(functionDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(functionTemplateDecl);
|
|
|
|
REGISTER_MATCHER(functionType);
|
|
|
|
REGISTER_MATCHER(gotoStmt);
|
2013-08-17 00:19:42 +08:00
|
|
|
REGISTER_MATCHER(has);
|
|
|
|
REGISTER_MATCHER(hasAncestor);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(hasAnyArgument);
|
2013-07-17 22:28:00 +08:00
|
|
|
REGISTER_MATCHER(hasAnyConstructorInitializer);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasAnyParameter);
|
|
|
|
REGISTER_MATCHER(hasAnySubstatement);
|
2013-07-17 23:11:30 +08:00
|
|
|
REGISTER_MATCHER(hasAnyTemplateArgument);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasAnyUsingShadowDecl);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(hasArgument);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasArgumentOfType);
|
2014-08-25 19:23:50 +08:00
|
|
|
REGISTER_MATCHER(hasAttr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasBase);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(hasBody);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasCanonicalType);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(hasCaseConstant);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(hasCondition);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasConditionVariableStatement);
|
2013-11-18 22:53:42 +08:00
|
|
|
REGISTER_MATCHER(hasDeclaration);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(hasDeclContext);
|
2013-07-16 03:25:06 +08:00
|
|
|
REGISTER_MATCHER(hasDeducedType);
|
2013-08-17 00:19:42 +08:00
|
|
|
REGISTER_MATCHER(hasDescendant);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasDestinationType);
|
|
|
|
REGISTER_MATCHER(hasEitherOperand);
|
2013-07-16 03:25:06 +08:00
|
|
|
REGISTER_MATCHER(hasElementType);
|
2014-08-16 03:13:27 +08:00
|
|
|
REGISTER_MATCHER(hasElse);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasFalseExpression);
|
2014-06-06 02:22:14 +08:00
|
|
|
REGISTER_MATCHER(hasGlobalStorage);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasImplicitDestinationType);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasIncrement);
|
|
|
|
REGISTER_MATCHER(hasIndex);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasInitializer);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(hasKeywordSelector);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasLHS);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasLocalQualifiers);
|
2014-06-06 02:22:14 +08:00
|
|
|
REGISTER_MATCHER(hasLocalStorage);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasLoopInit);
|
2014-08-16 03:13:27 +08:00
|
|
|
REGISTER_MATCHER(hasLoopVariable);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasMethod);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasName);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(hasNullSelector);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasObjectExpression);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(hasOperatorName);
|
|
|
|
REGISTER_MATCHER(hasOverloadedOperatorName);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasParameter);
|
2013-08-17 00:19:42 +08:00
|
|
|
REGISTER_MATCHER(hasParent);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasQualifier);
|
2014-08-16 03:13:27 +08:00
|
|
|
REGISTER_MATCHER(hasRangeInit);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(hasReceiverType);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(hasRHS);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(hasSelector);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasSingleDecl);
|
|
|
|
REGISTER_MATCHER(hasSize);
|
|
|
|
REGISTER_MATCHER(hasSizeExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasSourceExpression);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasTargetDecl);
|
2013-07-17 23:11:30 +08:00
|
|
|
REGISTER_MATCHER(hasTemplateArgument);
|
2014-08-16 03:13:27 +08:00
|
|
|
REGISTER_MATCHER(hasThen);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasTrueExpression);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(hasTypeLoc);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasUnaryOperand);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(hasUnarySelector);
|
2013-07-16 03:25:06 +08:00
|
|
|
REGISTER_MATCHER(hasValueType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(ifStmt);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(ignoringImpCasts);
|
|
|
|
REGISTER_MATCHER(ignoringParenCasts);
|
|
|
|
REGISTER_MATCHER(ignoringParenImpCasts);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(implicitCastExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(incompleteArrayType);
|
|
|
|
REGISTER_MATCHER(initListExpr);
|
2013-07-16 03:25:06 +08:00
|
|
|
REGISTER_MATCHER(innerType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(integerLiteral);
|
|
|
|
REGISTER_MATCHER(isArrow);
|
2015-08-05 20:11:30 +08:00
|
|
|
REGISTER_MATCHER(isBaseInitializer);
|
2015-07-02 20:53:22 +08:00
|
|
|
REGISTER_MATCHER(isCatchAll);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(isConst);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(isConstQualified);
|
2015-08-05 20:11:30 +08:00
|
|
|
REGISTER_MATCHER(isCopyConstructor);
|
|
|
|
REGISTER_MATCHER(isDefaultConstructor);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(isDefinition);
|
2014-08-15 22:20:59 +08:00
|
|
|
REGISTER_MATCHER(isDeleted);
|
2015-07-16 01:11:21 +08:00
|
|
|
REGISTER_MATCHER(isExceptionVariable);
|
2015-08-12 05:09:52 +08:00
|
|
|
REGISTER_MATCHER(isExplicit);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(isExplicitTemplateSpecialization);
|
2014-02-21 03:18:03 +08:00
|
|
|
REGISTER_MATCHER(isExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(isExternC);
|
2015-07-24 20:35:41 +08:00
|
|
|
REGISTER_MATCHER(isFinal);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(isImplicit);
|
2014-11-26 01:01:06 +08:00
|
|
|
REGISTER_MATCHER(isExpansionInFileMatching);
|
|
|
|
REGISTER_MATCHER(isExpansionInMainFile);
|
2014-09-03 20:08:14 +08:00
|
|
|
REGISTER_MATCHER(isInstantiated);
|
2014-11-26 01:01:06 +08:00
|
|
|
REGISTER_MATCHER(isExpansionInSystemHeader);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(isInteger);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(isIntegral);
|
2014-09-03 20:08:14 +08:00
|
|
|
REGISTER_MATCHER(isInTemplateInstantiation);
|
2014-02-07 05:52:24 +08:00
|
|
|
REGISTER_MATCHER(isListInitialization);
|
2015-08-12 04:42:00 +08:00
|
|
|
REGISTER_MATCHER(isMemberInitializer);
|
2015-08-05 20:11:30 +08:00
|
|
|
REGISTER_MATCHER(isMoveConstructor);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(isOverride);
|
|
|
|
REGISTER_MATCHER(isPrivate);
|
|
|
|
REGISTER_MATCHER(isProtected);
|
|
|
|
REGISTER_MATCHER(isPublic);
|
2014-08-16 03:13:27 +08:00
|
|
|
REGISTER_MATCHER(isPure);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(isTemplateInstantiation);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(isVirtual);
|
2013-07-17 22:28:00 +08:00
|
|
|
REGISTER_MATCHER(isWritten);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(labelStmt);
|
|
|
|
REGISTER_MATCHER(lambdaExpr);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(lValueReferenceType);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(matchesName);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(matchesSelector);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(materializeTemporaryExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(member);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(memberCallExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(memberExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(memberPointerType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(methodDecl);
|
|
|
|
REGISTER_MATCHER(namedDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(namespaceDecl);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(namesType);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(nestedNameSpecifier);
|
|
|
|
REGISTER_MATCHER(nestedNameSpecifierLoc);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(newExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(nullPtrLiteralExpr);
|
|
|
|
REGISTER_MATCHER(nullStmt);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(numSelectorArgs);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(ofClass);
|
2015-03-12 23:48:15 +08:00
|
|
|
REGISTER_MATCHER(objcMessageExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(on);
|
|
|
|
REGISTER_MATCHER(onImplicitObjectArgument);
|
|
|
|
REGISTER_MATCHER(operatorCallExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(parameterCountIs);
|
|
|
|
REGISTER_MATCHER(parenType);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(parmVarDecl);
|
2013-07-16 03:25:06 +08:00
|
|
|
REGISTER_MATCHER(pointee);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(pointerType);
|
|
|
|
REGISTER_MATCHER(qualType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(recordDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(recordType);
|
|
|
|
REGISTER_MATCHER(referenceType);
|
|
|
|
REGISTER_MATCHER(refersToDeclaration);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(refersToIntegralType);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(refersToType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(reinterpretCastExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(returns);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(returnStmt);
|
|
|
|
REGISTER_MATCHER(rValueReferenceType);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(sizeOfExpr);
|
|
|
|
REGISTER_MATCHER(specifiesNamespace);
|
|
|
|
REGISTER_MATCHER(specifiesType);
|
|
|
|
REGISTER_MATCHER(specifiesTypeLoc);
|
|
|
|
REGISTER_MATCHER(statementCountIs);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(staticCastExpr);
|
2015-06-06 06:40:53 +08:00
|
|
|
REGISTER_MATCHER(staticAssertDecl);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(stmt);
|
|
|
|
REGISTER_MATCHER(stringLiteral);
|
2014-08-16 03:13:27 +08:00
|
|
|
REGISTER_MATCHER(substNonTypeTemplateParmExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(switchCase);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(switchStmt);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(templateArgument);
|
|
|
|
REGISTER_MATCHER(templateArgumentCountIs);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(templateSpecializationType);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(temporaryObjectExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(thisExpr);
|
|
|
|
REGISTER_MATCHER(throughUsingDecl);
|
|
|
|
REGISTER_MATCHER(throwExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(to);
|
2015-02-10 22:46:45 +08:00
|
|
|
REGISTER_MATCHER(translationUnitDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(tryStmt);
|
|
|
|
REGISTER_MATCHER(type);
|
2014-11-26 01:01:06 +08:00
|
|
|
REGISTER_MATCHER(typedefDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(typedefType);
|
2014-10-09 21:06:22 +08:00
|
|
|
REGISTER_MATCHER(typeLoc);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(unaryExprOrTypeTraitExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(unaryOperator);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(unaryTransformType);
|
2013-11-22 22:41:48 +08:00
|
|
|
REGISTER_MATCHER(unless);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(unresolvedConstructExpr);
|
|
|
|
REGISTER_MATCHER(unresolvedUsingValueDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(userDefinedLiteral);
|
|
|
|
REGISTER_MATCHER(usingDecl);
|
2014-08-16 03:13:27 +08:00
|
|
|
REGISTER_MATCHER(usingDirectiveDecl);
|
2014-10-28 21:33:58 +08:00
|
|
|
REGISTER_MATCHER(valueDecl);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(varDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(variableArrayType);
|
2014-12-15 23:09:22 +08:00
|
|
|
REGISTER_MATCHER(voidType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(whileStmt);
|
2013-07-17 22:28:00 +08:00
|
|
|
REGISTER_MATCHER(withInitializer);
|
2013-05-14 17:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RegistryMaps::~RegistryMaps() {
|
2015-08-13 03:00:39 +08:00
|
|
|
for (auto &E : Constructors)
|
|
|
|
delete E.getValue();
|
2013-05-14 17:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static llvm::ManagedStatic<RegistryMaps> RegistryData;
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// static
|
2014-04-14 21:51:21 +08:00
|
|
|
llvm::Optional<MatcherCtor> Registry::lookupMatcherCtor(StringRef MatcherName) {
|
2013-05-14 17:13:00 +08:00
|
|
|
ConstructorMap::const_iterator it =
|
|
|
|
RegistryData->constructors().find(MatcherName);
|
2014-04-14 21:51:21 +08:00
|
|
|
return it == RegistryData->constructors().end()
|
|
|
|
? llvm::Optional<MatcherCtor>()
|
|
|
|
: it->second;
|
2013-11-23 09:13:16 +08:00
|
|
|
}
|
|
|
|
|
2014-01-24 06:48:38 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
|
|
|
const std::set<ASTNodeKind> &KS) {
|
|
|
|
unsigned Count = 0;
|
|
|
|
for (std::set<ASTNodeKind>::const_iterator I = KS.begin(), E = KS.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I != KS.begin())
|
|
|
|
OS << "|";
|
|
|
|
if (Count++ == 3) {
|
|
|
|
OS << "...";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
OS << *I;
|
|
|
|
}
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2014-08-13 05:11:37 +08:00
|
|
|
} // namespace
|
2014-01-24 06:48:38 +08:00
|
|
|
|
2014-08-13 05:11:37 +08:00
|
|
|
std::vector<ArgKind> Registry::getAcceptedCompletionTypes(
|
|
|
|
ArrayRef<std::pair<MatcherCtor, unsigned>> Context) {
|
2014-01-24 06:48:38 +08:00
|
|
|
ASTNodeKind InitialTypes[] = {
|
2014-08-13 05:11:37 +08:00
|
|
|
ASTNodeKind::getFromNodeKind<Decl>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<QualType>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<Type>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<Stmt>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<NestedNameSpecifier>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<TypeLoc>()};
|
2014-01-24 06:48:38 +08:00
|
|
|
|
|
|
|
// Starting with the above seed of acceptable top-level matcher types, compute
|
|
|
|
// the acceptable type set for the argument indicated by each context element.
|
2014-08-13 05:11:37 +08:00
|
|
|
std::set<ArgKind> TypeSet(std::begin(InitialTypes), std::end(InitialTypes));
|
|
|
|
for (const auto &CtxEntry : Context) {
|
|
|
|
MatcherCtor Ctor = CtxEntry.first;
|
|
|
|
unsigned ArgNumber = CtxEntry.second;
|
|
|
|
std::vector<ArgKind> NextTypeSet;
|
|
|
|
for (const ArgKind &Kind : TypeSet) {
|
|
|
|
if (Kind.getArgKind() == Kind.AK_Matcher &&
|
|
|
|
Ctor->isConvertibleTo(Kind.getMatcherKind()) &&
|
|
|
|
(Ctor->isVariadic() || ArgNumber < Ctor->getNumArgs()))
|
|
|
|
Ctor->getArgKinds(Kind.getMatcherKind(), ArgNumber, NextTypeSet);
|
2014-01-24 06:48:38 +08:00
|
|
|
}
|
|
|
|
TypeSet.clear();
|
2014-08-13 05:11:37 +08:00
|
|
|
TypeSet.insert(NextTypeSet.begin(), NextTypeSet.end());
|
2014-01-24 06:48:38 +08:00
|
|
|
}
|
2014-08-13 05:11:37 +08:00
|
|
|
return std::vector<ArgKind>(TypeSet.begin(), TypeSet.end());
|
|
|
|
}
|
2014-01-24 06:48:38 +08:00
|
|
|
|
2014-08-13 05:11:37 +08:00
|
|
|
std::vector<MatcherCompletion>
|
|
|
|
Registry::getMatcherCompletions(ArrayRef<ArgKind> AcceptedTypes) {
|
|
|
|
std::vector<MatcherCompletion> Completions;
|
2014-01-24 06:48:38 +08:00
|
|
|
|
2014-08-13 05:11:37 +08:00
|
|
|
// Search the registry for acceptable matchers.
|
2015-08-13 03:00:39 +08:00
|
|
|
for (const auto &M : RegistryData->constructors()) {
|
|
|
|
const auto *Matcher = M.getValue();
|
|
|
|
StringRef Name = M.getKey();
|
|
|
|
|
2014-01-24 06:48:38 +08:00
|
|
|
std::set<ASTNodeKind> RetKinds;
|
2015-08-13 03:00:39 +08:00
|
|
|
unsigned NumArgs = Matcher->isVariadic() ? 1 : Matcher->getNumArgs();
|
|
|
|
bool IsPolymorphic = Matcher->isPolymorphic();
|
2014-08-13 05:11:37 +08:00
|
|
|
std::vector<std::vector<ArgKind>> ArgsKinds(NumArgs);
|
2014-01-24 06:48:38 +08:00
|
|
|
unsigned MaxSpecificity = 0;
|
2014-08-13 05:11:37 +08:00
|
|
|
for (const ArgKind& Kind : AcceptedTypes) {
|
|
|
|
if (Kind.getArgKind() != Kind.AK_Matcher)
|
|
|
|
continue;
|
2014-01-24 06:48:38 +08:00
|
|
|
unsigned Specificity;
|
|
|
|
ASTNodeKind LeastDerivedKind;
|
2015-08-13 03:00:39 +08:00
|
|
|
if (Matcher->isConvertibleTo(Kind.getMatcherKind(), &Specificity,
|
|
|
|
&LeastDerivedKind)) {
|
2014-01-24 06:48:38 +08:00
|
|
|
if (MaxSpecificity < Specificity)
|
|
|
|
MaxSpecificity = Specificity;
|
|
|
|
RetKinds.insert(LeastDerivedKind);
|
|
|
|
for (unsigned Arg = 0; Arg != NumArgs; ++Arg)
|
2015-08-13 03:00:39 +08:00
|
|
|
Matcher->getArgKinds(Kind.getMatcherKind(), Arg, ArgsKinds[Arg]);
|
2014-01-24 06:48:38 +08:00
|
|
|
if (IsPolymorphic)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RetKinds.empty() && MaxSpecificity > 0) {
|
|
|
|
std::string Decl;
|
|
|
|
llvm::raw_string_ostream OS(Decl);
|
|
|
|
|
|
|
|
if (IsPolymorphic) {
|
2015-08-13 03:00:39 +08:00
|
|
|
OS << "Matcher<T> " << Name << "(Matcher<T>";
|
2014-01-24 06:48:38 +08:00
|
|
|
} else {
|
2015-08-13 03:00:39 +08:00
|
|
|
OS << "Matcher<" << RetKinds << "> " << Name << "(";
|
2014-08-13 05:11:37 +08:00
|
|
|
for (const std::vector<ArgKind> &Arg : ArgsKinds) {
|
|
|
|
if (&Arg != &ArgsKinds[0])
|
2014-01-24 06:48:38 +08:00
|
|
|
OS << ", ";
|
2014-10-10 06:08:52 +08:00
|
|
|
|
|
|
|
bool FirstArgKind = true;
|
|
|
|
std::set<ASTNodeKind> MatcherKinds;
|
|
|
|
// Two steps. First all non-matchers, then matchers only.
|
|
|
|
for (const ArgKind &AK : Arg) {
|
|
|
|
if (AK.getArgKind() == ArgKind::AK_Matcher) {
|
|
|
|
MatcherKinds.insert(AK.getMatcherKind());
|
|
|
|
} else {
|
|
|
|
if (!FirstArgKind) OS << "|";
|
|
|
|
FirstArgKind = false;
|
|
|
|
OS << AK.asString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!MatcherKinds.empty()) {
|
|
|
|
if (!FirstArgKind) OS << "|";
|
2014-01-24 06:48:38 +08:00
|
|
|
OS << "Matcher<" << MatcherKinds << ">";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-13 03:00:39 +08:00
|
|
|
if (Matcher->isVariadic())
|
2014-01-24 06:48:38 +08:00
|
|
|
OS << "...";
|
|
|
|
OS << ")";
|
|
|
|
|
2015-08-13 03:00:39 +08:00
|
|
|
std::string TypedText = Name;
|
2014-01-24 06:48:38 +08:00
|
|
|
TypedText += "(";
|
|
|
|
if (ArgsKinds.empty())
|
|
|
|
TypedText += ")";
|
2014-08-13 05:11:37 +08:00
|
|
|
else if (ArgsKinds[0][0].getArgKind() == ArgKind::AK_String)
|
2014-01-24 06:48:38 +08:00
|
|
|
TypedText += "\"";
|
|
|
|
|
2014-08-13 05:11:37 +08:00
|
|
|
Completions.emplace_back(TypedText, OS.str(), MaxSpecificity);
|
2014-01-24 06:48:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-13 05:11:37 +08:00
|
|
|
return Completions;
|
2014-01-24 06:48:38 +08:00
|
|
|
}
|
|
|
|
|
2013-11-23 09:13:16 +08:00
|
|
|
// static
|
|
|
|
VariantMatcher Registry::constructMatcher(MatcherCtor Ctor,
|
|
|
|
const SourceRange &NameRange,
|
|
|
|
ArrayRef<ParserValue> Args,
|
|
|
|
Diagnostics *Error) {
|
2013-11-23 09:34:36 +08:00
|
|
|
return Ctor->create(NameRange, Args, Error);
|
2013-05-14 17:13:00 +08:00
|
|
|
}
|
|
|
|
|
2013-06-04 03:31:08 +08:00
|
|
|
// static
|
2013-11-23 09:13:16 +08:00
|
|
|
VariantMatcher Registry::constructBoundMatcher(MatcherCtor Ctor,
|
2013-08-13 22:54:51 +08:00
|
|
|
const SourceRange &NameRange,
|
|
|
|
StringRef BindID,
|
|
|
|
ArrayRef<ParserValue> Args,
|
|
|
|
Diagnostics *Error) {
|
2013-11-23 09:13:16 +08:00
|
|
|
VariantMatcher Out = constructMatcher(Ctor, NameRange, Args, Error);
|
2013-08-13 22:54:51 +08:00
|
|
|
if (Out.isNull()) return Out;
|
|
|
|
|
2013-10-29 22:37:15 +08:00
|
|
|
llvm::Optional<DynTypedMatcher> Result = Out.getSingleMatcher();
|
|
|
|
if (Result.hasValue()) {
|
|
|
|
llvm::Optional<DynTypedMatcher> Bound = Result->tryBind(BindID);
|
|
|
|
if (Bound.hasValue()) {
|
2013-08-13 22:54:51 +08:00
|
|
|
return VariantMatcher::SingleMatcher(*Bound);
|
2013-06-21 23:51:31 +08:00
|
|
|
}
|
2013-06-04 03:31:08 +08:00
|
|
|
}
|
2013-07-19 03:47:59 +08:00
|
|
|
Error->addError(NameRange, Error->ET_RegistryNotBindable);
|
2013-08-13 22:54:51 +08:00
|
|
|
return VariantMatcher();
|
2013-06-04 03:31:08 +08:00
|
|
|
}
|
|
|
|
|
2013-05-14 17:13:00 +08:00
|
|
|
} // namespace dynamic
|
|
|
|
} // namespace ast_matchers
|
|
|
|
} // namespace clang
|