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 <utility>
|
|
|
|
|
|
|
|
#include "Marshallers.h"
|
|
|
|
#include "clang/ASTMatchers/ASTMatchers.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace ast_matchers {
|
|
|
|
namespace dynamic {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using internal::MatcherCreateCallback;
|
|
|
|
|
|
|
|
typedef llvm::StringMap<const MatcherCreateCallback *> ConstructorMap;
|
|
|
|
class RegistryMaps {
|
|
|
|
public:
|
|
|
|
RegistryMaps();
|
|
|
|
~RegistryMaps();
|
|
|
|
|
|
|
|
const ConstructorMap &constructors() const { return Constructors; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void registerMatcher(StringRef MatcherName, MatcherCreateCallback *Callback);
|
|
|
|
ConstructorMap Constructors;
|
|
|
|
};
|
|
|
|
|
|
|
|
void RegistryMaps::registerMatcher(StringRef MatcherName,
|
|
|
|
MatcherCreateCallback *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;
|
|
|
|
}
|
|
|
|
|
2013-07-23 00:13:57 +08:00
|
|
|
/// \brief MatcherCreateCallback that wraps multiple "overloads" of the same
|
|
|
|
/// matcher.
|
|
|
|
///
|
|
|
|
/// It will try every overload and generate appropriate errors for when none or
|
|
|
|
/// more than one overloads match the arguments.
|
|
|
|
class OverloadedMatcherCreateCallback : public MatcherCreateCallback {
|
|
|
|
public:
|
|
|
|
OverloadedMatcherCreateCallback(ArrayRef<MatcherCreateCallback *> Callbacks)
|
|
|
|
: Overloads(Callbacks) {}
|
|
|
|
|
|
|
|
virtual ~OverloadedMatcherCreateCallback() {
|
|
|
|
for (size_t i = 0, e = Overloads.size(); i != e; ++i)
|
|
|
|
delete Overloads[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual MatcherList run(const SourceRange &NameRange,
|
|
|
|
ArrayRef<ParserValue> Args,
|
|
|
|
Diagnostics *Error) const {
|
|
|
|
std::vector<MatcherList> Constructed;
|
|
|
|
Diagnostics::OverloadContext Ctx(Error);
|
|
|
|
for (size_t i = 0, e = Overloads.size(); i != e; ++i) {
|
|
|
|
MatcherList SubMatcher = Overloads[i]->run(NameRange, Args, Error);
|
|
|
|
if (!SubMatcher.empty()) {
|
|
|
|
Constructed.push_back(SubMatcher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Constructed.empty()) return MatcherList(); // No overload matched.
|
|
|
|
// We ignore the errors if any matcher succeeded.
|
|
|
|
Ctx.revertErrors();
|
|
|
|
if (Constructed.size() > 1) {
|
|
|
|
// More than one constructed. It is ambiguous.
|
|
|
|
Error->addError(NameRange, Error->ET_RegistryAmbiguousOverload);
|
|
|
|
return MatcherList();
|
|
|
|
}
|
|
|
|
return Constructed[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<MatcherCreateCallback*> Overloads;
|
|
|
|
};
|
|
|
|
|
2013-05-14 17:13:00 +08:00
|
|
|
#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 { \
|
|
|
|
MatcherCreateCallback *Callbacks[] = { \
|
|
|
|
internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 0), \
|
|
|
|
#name), \
|
|
|
|
internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 1), \
|
|
|
|
#name) \
|
|
|
|
}; \
|
|
|
|
registerMatcher(#name, new OverloadedMatcherCreateCallback(Callbacks)); \
|
|
|
|
} 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:
|
|
|
|
// unless
|
|
|
|
// eachOf
|
|
|
|
// anyOf
|
|
|
|
// allOf
|
|
|
|
// findAll
|
|
|
|
//
|
|
|
|
// Adaptative matcher (similar to polymorphic matcher):
|
|
|
|
// has
|
|
|
|
// forEach
|
|
|
|
// forEachDescendant
|
|
|
|
// hasDescendant
|
|
|
|
// hasParent
|
|
|
|
// hasAncestor
|
|
|
|
//
|
|
|
|
// Other:
|
|
|
|
// loc
|
|
|
|
// equals
|
|
|
|
// equalsNode
|
|
|
|
// hasDeclaration
|
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);
|
|
|
|
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-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(asString);
|
|
|
|
REGISTER_MATCHER(asmStmt);
|
|
|
|
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);
|
|
|
|
REGISTER_MATCHER(cStyleCastExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(callExpr);
|
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);
|
|
|
|
REGISTER_MATCHER(constCastExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(constantArrayType);
|
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);
|
|
|
|
REGISTER_MATCHER(decl);
|
|
|
|
REGISTER_MATCHER(declCountIs);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(declRefExpr);
|
|
|
|
REGISTER_MATCHER(declStmt);
|
|
|
|
REGISTER_MATCHER(defaultArgExpr);
|
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-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(elaboratedType);
|
|
|
|
REGISTER_MATCHER(enumConstantDecl);
|
|
|
|
REGISTER_MATCHER(enumDecl);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(explicitCastExpr);
|
|
|
|
REGISTER_MATCHER(expr);
|
|
|
|
REGISTER_MATCHER(fieldDecl);
|
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);
|
|
|
|
REGISTER_MATCHER(functionDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(functionTemplateDecl);
|
|
|
|
REGISTER_MATCHER(functionType);
|
|
|
|
REGISTER_MATCHER(functionalCastExpr);
|
|
|
|
REGISTER_MATCHER(gotoStmt);
|
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);
|
|
|
|
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-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(hasCondition);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasConditionVariableStatement);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasDeclContext);
|
2013-07-16 03:25:06 +08:00
|
|
|
REGISTER_MATCHER(hasDeducedType);
|
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);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasFalseExpression);
|
|
|
|
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);
|
|
|
|
REGISTER_MATCHER(hasLHS);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasLocalQualifiers);
|
|
|
|
REGISTER_MATCHER(hasLoopInit);
|
|
|
|
REGISTER_MATCHER(hasMethod);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasName);
|
|
|
|
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);
|
|
|
|
REGISTER_MATCHER(hasQualifier);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasRHS);
|
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);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(hasTrueExpression);
|
|
|
|
REGISTER_MATCHER(hasUnaryOperand);
|
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);
|
|
|
|
REGISTER_MATCHER(isConstQualified);
|
2013-06-21 23:51:31 +08:00
|
|
|
REGISTER_MATCHER(isDefinition);
|
|
|
|
REGISTER_MATCHER(isExplicitTemplateSpecialization);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(isExternC);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(isImplicit);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(isInteger);
|
|
|
|
REGISTER_MATCHER(isOverride);
|
|
|
|
REGISTER_MATCHER(isPrivate);
|
|
|
|
REGISTER_MATCHER(isProtected);
|
|
|
|
REGISTER_MATCHER(isPublic);
|
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(lValueReferenceType);
|
|
|
|
REGISTER_MATCHER(labelStmt);
|
|
|
|
REGISTER_MATCHER(lambdaExpr);
|
|
|
|
REGISTER_MATCHER(matchesName);
|
|
|
|
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(namesType);
|
|
|
|
REGISTER_MATCHER(namespaceDecl);
|
|
|
|
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);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(ofClass);
|
|
|
|
REGISTER_MATCHER(on);
|
|
|
|
REGISTER_MATCHER(onImplicitObjectArgument);
|
|
|
|
REGISTER_MATCHER(operatorCallExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(parameterCountIs);
|
|
|
|
REGISTER_MATCHER(parenType);
|
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);
|
|
|
|
REGISTER_MATCHER(rValueReferenceType);
|
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);
|
|
|
|
REGISTER_MATCHER(refersToType);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(reinterpretCastExpr);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(returnStmt);
|
|
|
|
REGISTER_MATCHER(returns);
|
|
|
|
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);
|
|
|
|
REGISTER_MATCHER(stmt);
|
|
|
|
REGISTER_MATCHER(stringLiteral);
|
|
|
|
REGISTER_MATCHER(switchCase);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(switchStmt);
|
|
|
|
REGISTER_MATCHER(templateSpecializationType);
|
|
|
|
REGISTER_MATCHER(thisExpr);
|
|
|
|
REGISTER_MATCHER(throughUsingDecl);
|
|
|
|
REGISTER_MATCHER(throwExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(to);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(tryStmt);
|
|
|
|
REGISTER_MATCHER(type);
|
|
|
|
REGISTER_MATCHER(typeLoc);
|
|
|
|
REGISTER_MATCHER(typedefType);
|
|
|
|
REGISTER_MATCHER(unaryExprOrTypeTraitExpr);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(unaryOperator);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(userDefinedLiteral);
|
|
|
|
REGISTER_MATCHER(usingDecl);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(varDecl);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(variableArrayType);
|
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() {
|
|
|
|
for (ConstructorMap::iterator it = Constructors.begin(),
|
|
|
|
end = Constructors.end();
|
|
|
|
it != end; ++it) {
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static llvm::ManagedStatic<RegistryMaps> RegistryData;
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// static
|
2013-06-21 23:51:31 +08:00
|
|
|
MatcherList Registry::constructMatcher(StringRef MatcherName,
|
|
|
|
const SourceRange &NameRange,
|
|
|
|
ArrayRef<ParserValue> Args,
|
|
|
|
Diagnostics *Error) {
|
2013-05-14 17:13:00 +08:00
|
|
|
ConstructorMap::const_iterator it =
|
|
|
|
RegistryData->constructors().find(MatcherName);
|
|
|
|
if (it == RegistryData->constructors().end()) {
|
2013-07-19 03:47:59 +08:00
|
|
|
Error->addError(NameRange, Error->ET_RegistryNotFound) << MatcherName;
|
2013-06-21 23:51:31 +08:00
|
|
|
return MatcherList();
|
2013-05-14 17:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return it->second->run(NameRange, Args, Error);
|
|
|
|
}
|
|
|
|
|
2013-06-04 03:31:08 +08:00
|
|
|
// static
|
2013-06-21 23:51:31 +08:00
|
|
|
MatcherList Registry::constructBoundMatcher(StringRef MatcherName,
|
|
|
|
const SourceRange &NameRange,
|
|
|
|
StringRef BindID,
|
|
|
|
ArrayRef<ParserValue> Args,
|
|
|
|
Diagnostics *Error) {
|
|
|
|
MatcherList Out = constructMatcher(MatcherName, NameRange, Args, Error);
|
|
|
|
if (Out.empty()) return Out;
|
|
|
|
|
|
|
|
ArrayRef<const DynTypedMatcher*> Matchers = Out.matchers();
|
|
|
|
if (Matchers.size() == 1) {
|
|
|
|
OwningPtr<DynTypedMatcher> Bound(Matchers[0]->tryBind(BindID));
|
|
|
|
if (Bound) {
|
|
|
|
return *Bound;
|
|
|
|
}
|
2013-06-04 03:31:08 +08:00
|
|
|
}
|
2013-07-19 03:47:59 +08:00
|
|
|
Error->addError(NameRange, Error->ET_RegistryNotBindable);
|
2013-06-21 23:51:31 +08:00
|
|
|
return MatcherList();
|
2013-06-04 03:31:08 +08:00
|
|
|
}
|
|
|
|
|
2013-05-14 17:13:00 +08:00
|
|
|
} // namespace dynamic
|
|
|
|
} // namespace ast_matchers
|
|
|
|
} // namespace clang
|