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:
|
|
|
|
// loc
|
|
|
|
// 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);
|
|
|
|
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(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-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);
|
|
|
|
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);
|
2013-08-15 08:33:08 +08:00
|
|
|
REGISTER_MATCHER(ctorInitializer);
|
2013-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(decl);
|
|
|
|
REGISTER_MATCHER(declCountIs);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(declRefExpr);
|
|
|
|
REGISTER_MATCHER(declStmt);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(declaratorDecl);
|
2013-05-14 17:13:00 +08:00
|
|
|
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);
|
2013-05-14 17:13:00 +08:00
|
|
|
REGISTER_MATCHER(explicitCastExpr);
|
|
|
|
REGISTER_MATCHER(expr);
|
|
|
|
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);
|
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(functionalCastExpr);
|
|
|
|
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);
|
|
|
|
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-06-04 23:46:22 +08:00
|
|
|
REGISTER_MATCHER(hasDeclContext);
|
2013-11-18 22:53:42 +08:00
|
|
|
REGISTER_MATCHER(hasDeclaration);
|
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);
|
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);
|
2013-08-17 00:19:42 +08:00
|
|
|
REGISTER_MATCHER(hasParent);
|
2013-06-04 23:46:22 +08:00
|
|
|
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);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(hasTypeLoc);
|
2013-05-14 17:13:00 +08:00
|
|
|
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);
|
2013-11-25 23:03:44 +08:00
|
|
|
REGISTER_MATCHER(isConst);
|
2013-05-14 17:13:00 +08:00
|
|
|
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);
|
2014-02-07 05:52:24 +08:00
|
|
|
REGISTER_MATCHER(isListInitialization);
|
2013-06-04 23:46:22 +08:00
|
|
|
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-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);
|
|
|
|
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);
|
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);
|
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-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);
|
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-11-23 09:13:16 +08:00
|
|
|
llvm::Optional<MatcherCtor>
|
|
|
|
Registry::lookupMatcherCtor(StringRef MatcherName, const SourceRange &NameRange,
|
|
|
|
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-11-23 09:13:16 +08:00
|
|
|
return llvm::Optional<MatcherCtor>();
|
2013-05-14 17:13:00 +08:00
|
|
|
}
|
|
|
|
|
2013-11-23 09:13:16 +08:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ReverseSpecificityThenName {
|
|
|
|
bool operator()(const std::pair<unsigned, std::string> &A,
|
|
|
|
const std::pair<unsigned, std::string> &B) const {
|
|
|
|
return A.first > B.first || (A.first == B.first && A.second < B.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MatcherCompletion> Registry::getCompletions(
|
|
|
|
llvm::ArrayRef<std::pair<MatcherCtor, unsigned> > Context) {
|
|
|
|
ASTNodeKind InitialTypes[] = {
|
|
|
|
ASTNodeKind::getFromNodeKind<Decl>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<QualType>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<Type>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<Stmt>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<NestedNameSpecifier>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>(),
|
|
|
|
ASTNodeKind::getFromNodeKind<TypeLoc>()
|
|
|
|
};
|
|
|
|
llvm::ArrayRef<ASTNodeKind> InitialTypesRef(InitialTypes);
|
|
|
|
|
|
|
|
// Starting with the above seed of acceptable top-level matcher types, compute
|
|
|
|
// the acceptable type set for the argument indicated by each context element.
|
|
|
|
std::set<ASTNodeKind> TypeSet(InitialTypesRef.begin(), InitialTypesRef.end());
|
|
|
|
for (llvm::ArrayRef<std::pair<MatcherCtor, unsigned> >::iterator
|
|
|
|
CtxI = Context.begin(),
|
|
|
|
CtxE = Context.end();
|
|
|
|
CtxI != CtxE; ++CtxI) {
|
|
|
|
std::vector<internal::ArgKind> NextTypeSet;
|
|
|
|
for (std::set<ASTNodeKind>::iterator I = TypeSet.begin(), E = TypeSet.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (CtxI->first->isConvertibleTo(*I) &&
|
|
|
|
(CtxI->first->isVariadic() ||
|
|
|
|
CtxI->second < CtxI->first->getNumArgs()))
|
|
|
|
CtxI->first->getArgKinds(*I, CtxI->second, NextTypeSet);
|
|
|
|
}
|
|
|
|
TypeSet.clear();
|
|
|
|
for (std::vector<internal::ArgKind>::iterator I = NextTypeSet.begin(),
|
|
|
|
E = NextTypeSet.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I->getArgKind() == internal::ArgKind::AK_Matcher)
|
|
|
|
TypeSet.insert(I->getMatcherKind());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::map<std::pair<unsigned, std::string>, MatcherCompletion,
|
|
|
|
ReverseSpecificityThenName> CompletionsTy;
|
|
|
|
CompletionsTy Completions;
|
|
|
|
|
|
|
|
// TypeSet now contains the list of acceptable types for the argument we are
|
|
|
|
// completing. Search the registry for acceptable matchers.
|
|
|
|
for (ConstructorMap::const_iterator I = RegistryData->constructors().begin(),
|
|
|
|
E = RegistryData->constructors().end();
|
|
|
|
I != E; ++I) {
|
|
|
|
std::set<ASTNodeKind> RetKinds;
|
|
|
|
unsigned NumArgs = I->second->isVariadic() ? 1 : I->second->getNumArgs();
|
|
|
|
bool IsPolymorphic = I->second->isPolymorphic();
|
|
|
|
std::vector<std::vector<internal::ArgKind> > ArgsKinds(NumArgs);
|
|
|
|
unsigned MaxSpecificity = 0;
|
|
|
|
for (std::set<ASTNodeKind>::iterator TI = TypeSet.begin(),
|
|
|
|
TE = TypeSet.end();
|
|
|
|
TI != TE; ++TI) {
|
|
|
|
unsigned Specificity;
|
|
|
|
ASTNodeKind LeastDerivedKind;
|
|
|
|
if (I->second->isConvertibleTo(*TI, &Specificity, &LeastDerivedKind)) {
|
|
|
|
if (MaxSpecificity < Specificity)
|
|
|
|
MaxSpecificity = Specificity;
|
|
|
|
RetKinds.insert(LeastDerivedKind);
|
|
|
|
for (unsigned Arg = 0; Arg != NumArgs; ++Arg)
|
|
|
|
I->second->getArgKinds(*TI, Arg, ArgsKinds[Arg]);
|
|
|
|
if (IsPolymorphic)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RetKinds.empty() && MaxSpecificity > 0) {
|
|
|
|
std::string Decl;
|
|
|
|
llvm::raw_string_ostream OS(Decl);
|
|
|
|
|
|
|
|
if (IsPolymorphic) {
|
|
|
|
OS << "Matcher<T> " << I->first() << "(Matcher<T>";
|
|
|
|
} else {
|
|
|
|
OS << "Matcher<" << RetKinds << "> " << I->first() << "(";
|
|
|
|
for (std::vector<std::vector<internal::ArgKind> >::iterator
|
|
|
|
KI = ArgsKinds.begin(),
|
|
|
|
KE = ArgsKinds.end();
|
|
|
|
KI != KE; ++KI) {
|
|
|
|
if (KI != ArgsKinds.begin())
|
|
|
|
OS << ", ";
|
|
|
|
// This currently assumes that a matcher may not overload a
|
|
|
|
// non-matcher, and all non-matcher overloads have identical
|
|
|
|
// arguments.
|
|
|
|
if ((*KI)[0].getArgKind() == internal::ArgKind::AK_Matcher) {
|
|
|
|
std::set<ASTNodeKind> MatcherKinds;
|
|
|
|
std::transform(
|
|
|
|
KI->begin(), KI->end(),
|
|
|
|
std::inserter(MatcherKinds, MatcherKinds.end()),
|
|
|
|
std::mem_fun_ref(&internal::ArgKind::getMatcherKind));
|
|
|
|
OS << "Matcher<" << MatcherKinds << ">";
|
|
|
|
} else {
|
|
|
|
OS << (*KI)[0].asString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (I->second->isVariadic())
|
|
|
|
OS << "...";
|
|
|
|
OS << ")";
|
|
|
|
|
|
|
|
std::string TypedText = I->first();
|
|
|
|
TypedText += "(";
|
|
|
|
if (ArgsKinds.empty())
|
|
|
|
TypedText += ")";
|
|
|
|
else if (ArgsKinds[0][0].getArgKind() == internal::ArgKind::AK_String)
|
|
|
|
TypedText += "\"";
|
|
|
|
|
|
|
|
Completions[std::make_pair(MaxSpecificity, I->first())] =
|
|
|
|
MatcherCompletion(TypedText, OS.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MatcherCompletion> RetVal;
|
|
|
|
for (CompletionsTy::iterator I = Completions.begin(), E = Completions.end();
|
|
|
|
I != E; ++I)
|
|
|
|
RetVal.push_back(I->second);
|
|
|
|
return RetVal;
|
|
|
|
}
|
|
|
|
|
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
|