@@ -136,8 +136,8 @@ SourceFile::~SourceFile() = default;
136
136
class swift ::SourceLookupCache {
137
137
// / A lookup map for value decls. When declarations are added they are added
138
138
// / under all variants of the name they can be found under.
139
- class DeclMap {
140
- llvm::DenseMap<DeclName, TinyPtrVector<ValueDecl*>> Members;
139
+ class ValueDeclMap {
140
+ llvm::DenseMap<DeclName, TinyPtrVector<ValueDecl *>> Members;
141
141
142
142
public:
143
143
void add (ValueDecl *VD) {
@@ -156,10 +156,15 @@ class swift::SourceLookupCache {
156
156
}
157
157
};
158
158
159
- DeclMap TopLevelValues;
160
- DeclMap ClassMembers;
159
+ ValueDeclMap TopLevelValues;
160
+ ValueDeclMap ClassMembers;
161
161
bool MemberCachePopulated = false ;
162
162
163
+ template <typename T>
164
+ using OperatorMap = llvm::DenseMap<Identifier, TinyPtrVector<T *>>;
165
+ OperatorMap<OperatorDecl> Operators;
166
+ OperatorMap<PrecedenceGroupDecl> PrecedenceGroups;
167
+
163
168
template <typename Range>
164
169
void addToUnqualifiedLookupCache (Range decls, bool onlyOperators);
165
170
template <typename Range>
@@ -175,7 +180,28 @@ class swift::SourceLookupCache {
175
180
176
181
void lookupValue (DeclName Name, NLKind LookupKind,
177
182
SmallVectorImpl<ValueDecl*> &Result);
178
-
183
+
184
+ // / Retrieves all the operator decls. The order of the results is not
185
+ // / guaranteed to be meaningful.
186
+ void getOperatorDecls (SmallVectorImpl<OperatorDecl *> &results);
187
+
188
+ // / Retrieves all the precedence groups. The order of the results is not
189
+ // / guaranteed to be meaningful.
190
+ void getPrecedenceGroups (SmallVectorImpl<PrecedenceGroupDecl *> &results);
191
+
192
+ // / Look up an operator declaration.
193
+ // /
194
+ // / \param name The operator name ("+", ">>", etc.)
195
+ // / \param fixity The fixity of the operator (infix, prefix or postfix).
196
+ void lookupOperator (Identifier name, OperatorFixity fixity,
197
+ TinyPtrVector<OperatorDecl *> &results);
198
+
199
+ // / Look up a precedence group.
200
+ // /
201
+ // / \param name The operator name ("+", ">>", etc.)
202
+ void lookupPrecedenceGroup (Identifier name,
203
+ TinyPtrVector<PrecedenceGroupDecl *> &results);
204
+
179
205
void lookupVisibleDecls (AccessPathTy AccessPath,
180
206
VisibleDeclConsumer &Consumer,
181
207
NLKind LookupKind);
@@ -224,6 +250,12 @@ void SourceLookupCache::addToUnqualifiedLookupCache(Range decls,
224
250
if (!ED->hasUnparsedMembers () || ED->maybeHasOperatorDeclarations ())
225
251
addToUnqualifiedLookupCache (ED->getMembers (), true );
226
252
}
253
+
254
+ if (auto *OD = dyn_cast<OperatorDecl>(D))
255
+ Operators[OD->getName ()].push_back (OD);
256
+
257
+ if (auto *PG = dyn_cast<PrecedenceGroupDecl>(D))
258
+ PrecedenceGroups[PG->getName ()].push_back (PG);
227
259
}
228
260
}
229
261
@@ -300,6 +332,39 @@ void SourceLookupCache::lookupValue(DeclName Name, NLKind LookupKind,
300
332
Result.push_back (Elt);
301
333
}
302
334
335
+ void SourceLookupCache::getPrecedenceGroups (
336
+ SmallVectorImpl<PrecedenceGroupDecl *> &results) {
337
+ for (auto &groups : PrecedenceGroups)
338
+ results.append (groups.second .begin (), groups.second .end ());
339
+ }
340
+
341
+ void SourceLookupCache::getOperatorDecls (
342
+ SmallVectorImpl<OperatorDecl *> &results) {
343
+ for (auto &ops : Operators)
344
+ results.append (ops.second .begin (), ops.second .end ());
345
+ }
346
+
347
+ void SourceLookupCache::lookupOperator (Identifier name, OperatorFixity fixity,
348
+ TinyPtrVector<OperatorDecl *> &results) {
349
+ auto ops = Operators.find (name);
350
+ if (ops == Operators.end ())
351
+ return ;
352
+
353
+ for (auto *op : ops->second )
354
+ if (op->getFixity () == fixity)
355
+ results.push_back (op);
356
+ }
357
+
358
+ void SourceLookupCache::lookupPrecedenceGroup (
359
+ Identifier name, TinyPtrVector<PrecedenceGroupDecl *> &results) {
360
+ auto groups = PrecedenceGroups.find (name);
361
+ if (groups == PrecedenceGroups.end ())
362
+ return ;
363
+
364
+ for (auto *group : groups->second )
365
+ results.push_back (group);
366
+ }
367
+
303
368
void SourceLookupCache::lookupVisibleDecls (AccessPathTy AccessPath,
304
369
VisibleDeclConsumer &Consumer,
305
370
NLKind LookupKind) {
0 commit comments