1//===--- Registry.h - Matcher registry -----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9/// 10/// \file 11/// \brief Registry of all known matchers. 12/// 13/// The registry provides a generic interface to construct any matcher by name. 14/// 15//===----------------------------------------------------------------------===// 16 17#ifndef LLVM_CLANG_AST_MATCHERS_DYNAMIC_REGISTRY_H 18#define LLVM_CLANG_AST_MATCHERS_DYNAMIC_REGISTRY_H 19 20#include "clang/ASTMatchers/Dynamic/Diagnostics.h" 21#include "clang/ASTMatchers/Dynamic/VariantValue.h" 22#include "clang/Basic/LLVM.h" 23#include "llvm/ADT/ArrayRef.h" 24#include "llvm/ADT/StringRef.h" 25 26namespace clang { 27namespace ast_matchers { 28namespace dynamic { 29 30class Registry { 31public: 32 /// \brief Construct a matcher from the registry by name. 33 /// 34 /// Consult the registry of known matchers and construct the appropriate 35 /// matcher by name. 36 /// 37 /// \param MatcherName The name of the matcher to instantiate. 38 /// 39 /// \param NameRange The location of the name in the matcher source. 40 /// Useful for error reporting. 41 /// 42 /// \param Args The argument list for the matcher. The number and types of the 43 /// values must be valid for the matcher requested. Otherwise, the function 44 /// will return an error. 45 /// 46 /// \return The matcher object constructed if no error was found. 47 /// A null matcher if the matcher is not found, or if the number of 48 /// arguments or argument types do not match the signature. 49 /// In that case \c Error will contain the description of the error. 50 static VariantMatcher constructMatcher(StringRef MatcherName, 51 const SourceRange &NameRange, 52 ArrayRef<ParserValue> Args, 53 Diagnostics *Error); 54 55 /// \brief Construct a matcher from the registry and bind it. 56 /// 57 /// Similar the \c constructMatcher() above, but it then tries to bind the 58 /// matcher to the specified \c BindID. 59 /// If the matcher is not bindable, it sets an error in \c Error and returns 60 /// a null matcher. 61 static VariantMatcher constructBoundMatcher(StringRef MatcherName, 62 const SourceRange &NameRange, 63 StringRef BindID, 64 ArrayRef<ParserValue> Args, 65 Diagnostics *Error); 66 67private: 68 Registry() LLVM_DELETED_FUNCTION; 69}; 70 71} // namespace dynamic 72} // namespace ast_matchers 73} // namespace clang 74 75#endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_REGISTRY_H 76