MLIR  19.0.0git
RegistryManager.h
Go to the documentation of this file.
1 //===--- RegistryManager.h - Matcher registry -------------------*- C++ -*-===//
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 // RegistryManager to manage registry of all known matchers.
10 //
11 // The registry provides a generic interface to construct any matcher by name.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRYMANAGER_H
16 #define MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRYMANAGER_H
17 
18 #include "Diagnostics.h"
22 #include "llvm/ADT/ArrayRef.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringRef.h"
25 #include <string>
26 
27 namespace mlir::query::matcher {
28 
30 
32  MatcherCompletion() = default;
33  MatcherCompletion(llvm::StringRef typedText, llvm::StringRef matcherDecl)
34  : typedText(typedText.str()), matcherDecl(matcherDecl.str()) {}
35 
36  bool operator==(const MatcherCompletion &other) const {
37  return typedText == other.typedText && matcherDecl == other.matcherDecl;
38  }
39 
40  // The text to type to select this matcher.
41  std::string typedText;
42 
43  // The "declaration" of the matcher, with type information.
44  std::string matcherDecl;
45 };
46 
48 public:
49  RegistryManager() = delete;
50 
51  static std::optional<MatcherCtor>
52  lookupMatcherCtor(llvm::StringRef matcherName,
53  const Registry &matcherRegistry);
54 
55  static std::vector<ArgKind> getAcceptedCompletionTypes(
56  llvm::ArrayRef<std::pair<MatcherCtor, unsigned>> context);
57 
58  static std::vector<MatcherCompletion>
60  const Registry &matcherRegistry);
61 
63  internal::SourceRange nameRange,
64  llvm::StringRef functionName,
66  internal::Diagnostics *error);
67 };
68 
69 } // namespace mlir::query::matcher
70 
71 #endif // MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRYMANAGER_H
static std::vector< MatcherCompletion > getMatcherCompletions(ArrayRef< ArgKind > acceptedTypes, const Registry &matcherRegistry)
static std::vector< ArgKind > getAcceptedCompletionTypes(llvm::ArrayRef< std::pair< MatcherCtor, unsigned >> context)
static std::optional< MatcherCtor > lookupMatcherCtor(llvm::StringRef matcherName, const Registry &matcherRegistry)
static VariantMatcher constructMatcher(MatcherCtor ctor, internal::SourceRange nameRange, llvm::StringRef functionName, ArrayRef< ParserValue > args, internal::Diagnostics *error)
bool operator==(const MatcherCompletion &other) const
MatcherCompletion(llvm::StringRef typedText, llvm::StringRef matcherDecl)