@@ -45,7 +45,7 @@ class Parser {
45
45
// matcher tokens.
46
46
class Sema {
47
47
public:
48
- virtual ~Sema ();
48
+ virtual ~Sema () = default ;
49
49
50
50
// Process a matcher expression. The caller takes ownership of the Matcher
51
51
// object returned.
@@ -58,47 +58,51 @@ class Parser {
58
58
virtual std::optional<MatcherCtor>
59
59
lookupMatcherCtor (llvm::StringRef matcherName) = 0 ;
60
60
61
- virtual bool isBuilderMatcher (MatcherCtor) const = 0;
61
+ virtual bool isBuilderMatcher (MatcherCtor ctor ) const = 0;
62
62
63
63
virtual internal::MatcherDescriptorPtr
64
- buildMatcherCtor (MatcherCtor, SourceRange nameRange,
64
+ buildMatcherCtor (MatcherCtor ctor , SourceRange nameRange,
65
65
ArrayRef<ParserValue> args, Diagnostics *error) const = 0 ;
66
66
67
- // Compute the list of completion types for Context.
68
67
virtual std::vector<ArgKind> getAcceptedCompletionTypes (
69
- llvm::ArrayRef<std::pair<MatcherCtor, unsigned >> Context);
68
+ llvm::ArrayRef<std::pair<MatcherCtor, unsigned >> context) {
69
+ return {};
70
+ }
70
71
71
- // Compute the list of completions that match any of acceptedTypes.
72
72
virtual std::vector<MatcherCompletion>
73
- getMatcherCompletions (llvm::ArrayRef<ArgKind> acceptedTypes);
73
+ getMatcherCompletions (llvm::ArrayRef<ArgKind> acceptedTypes) {
74
+ return {};
75
+ }
74
76
};
75
77
76
78
// RegistrySema class - an implementation of the Sema interface that uses the
77
79
// matcher registry to process tokens.
78
80
class RegistrySema : public Parser ::Sema {
79
81
public:
80
- ~RegistrySema () override ;
82
+ ~RegistrySema () override = default ;
81
83
82
84
std::optional<MatcherCtor>
83
- lookupMatcherCtor (llvm::StringRef matcherName) override ;
85
+ lookupMatcherCtor (llvm::StringRef matcherName) override {
86
+ return Registry::lookupMatcherCtor (matcherName);
87
+ }
84
88
85
89
VariantMatcher actOnMatcherExpression (MatcherCtor ctor,
86
90
SourceRange nameRange,
87
91
ArrayRef<ParserValue> args,
88
- Diagnostics *error) override ;
92
+ Diagnostics *error) override {
93
+ return Registry::constructMatcher (ctor, nameRange, args, error);
94
+ }
89
95
90
- bool isBuilderMatcher (MatcherCtor ctor) const override ;
91
-
92
- std::vector<ArgKind> getAcceptedCompletionTypes (
93
- llvm::ArrayRef<std::pair<MatcherCtor, unsigned >> context) override ;
96
+ bool isBuilderMatcher (MatcherCtor ctor) const override {
97
+ return Registry::isBuilderMatcher (ctor);
98
+ }
94
99
95
100
internal::MatcherDescriptorPtr
96
- buildMatcherCtor (MatcherCtor, SourceRange nameRange,
101
+ buildMatcherCtor (MatcherCtor ctor , SourceRange nameRange,
97
102
ArrayRef<ParserValue> args,
98
- Diagnostics *error) const override ;
99
-
100
- std::vector<MatcherCompletion>
101
- getMatcherCompletions (llvm::ArrayRef<ArgKind> acceptedTypes) override ;
103
+ Diagnostics *error) const override {
104
+ return Registry::buildMatcherCtor (ctor, nameRange, args, error);
105
+ }
102
106
};
103
107
104
108
using NamedValueMap = llvm::StringMap<VariantValue>;
@@ -108,17 +112,18 @@ class Parser {
108
112
static std::optional<DynMatcher>
109
113
parseMatcherExpression (llvm::StringRef &matcherCode, Sema *sema,
110
114
const NamedValueMap *namedValues, Diagnostics *error);
115
+
111
116
static std::optional<DynMatcher>
112
117
parseMatcherExpression (llvm::StringRef &matcherCode, Sema *sema,
113
118
Diagnostics *error) {
114
119
return parseMatcherExpression (matcherCode, sema, nullptr , error);
115
120
}
121
+
116
122
static std::optional<DynMatcher>
117
123
parseMatcherExpression (llvm::StringRef &matcherCode, Diagnostics *error) {
118
124
return parseMatcherExpression (matcherCode, nullptr , error);
119
125
}
120
126
121
- // Methods to parse any expression supported by this parser.
122
127
static bool parseExpression (llvm::StringRef &code, Sema *sema,
123
128
const NamedValueMap *namedValues,
124
129
VariantValue *value, Diagnostics *error);
@@ -127,20 +132,22 @@ class Parser {
127
132
VariantValue *value, Diagnostics *error) {
128
133
return parseExpression (code, sema, nullptr , value, error);
129
134
}
135
+
130
136
static bool parseExpression (llvm::StringRef &code, VariantValue *value,
131
137
Diagnostics *error) {
132
138
return parseExpression (code, nullptr , value, error);
133
139
}
134
140
135
- // Methods to complete an expression at a given offset.
136
141
static std::vector<MatcherCompletion>
137
142
completeExpression (llvm::StringRef &code, unsigned completionOffset,
138
143
Sema *sema, const NamedValueMap *namedValues);
144
+
139
145
static std::vector<MatcherCompletion>
140
146
completeExpression (llvm::StringRef &code, unsigned completionOffset,
141
147
Sema *sema) {
142
148
return completeExpression (code, completionOffset, sema, nullptr );
143
149
}
150
+
144
151
static std::vector<MatcherCompletion>
145
152
completeExpression (llvm::StringRef &code, unsigned completionOffset) {
146
153
return completeExpression (code, completionOffset, nullptr );
@@ -160,11 +167,14 @@ class Parser {
160
167
const TokenInfo &nameToken,
161
168
const TokenInfo &openToken,
162
169
const TokenInfo &endToken, VariantValue *value);
170
+
163
171
bool parseMatcherArgs (bool isBuilder, std::vector<ParserValue> &args,
164
172
MatcherCtor ctor, const TokenInfo &nameToken,
165
173
TokenInfo &endToken);
174
+
166
175
bool parseMatcherBuilder (MatcherCtor ctor, const TokenInfo &nameToken,
167
176
const TokenInfo &openToken, VariantValue *value);
177
+
168
178
bool parseMatcherExpressionImpl (const TokenInfo &nameToken,
169
179
const TokenInfo &openToken,
170
180
std::optional<MatcherCtor> ctor,
@@ -174,6 +184,7 @@ class Parser {
174
184
175
185
void addCompletion (const TokenInfo &compToken,
176
186
const MatcherCompletion &completion);
187
+
177
188
void addExpressionCompletions ();
178
189
179
190
std::vector<MatcherCompletion>
@@ -185,7 +196,6 @@ class Parser {
185
196
Diagnostics *const error;
186
197
187
198
using ContextStackTy = std::vector<std::pair<MatcherCtor, unsigned >>;
188
-
189
199
ContextStackTy contextStack;
190
200
std::vector<MatcherCompletion> completions;
191
201
};
0 commit comments