@@ -128,9 +128,7 @@ class UnqualifiedLookupFactory {
128
128
using Options = UnqualifiedLookup::Options;
129
129
130
130
private:
131
-
132
- // TODO: better name than DC
133
- struct DCAndResolvedIsCascadingUse {
131
+ struct ContextAndResolvedIsCascadingUse {
134
132
DeclContext *const DC;
135
133
const bool isCascadingUse;
136
134
};
@@ -146,7 +144,6 @@ class UnqualifiedLookupFactory {
146
144
DeclContext *const dynamicContext;
147
145
// / Types are formally members of the metatype, i.e. the static type of the
148
146
// / activation record.
149
- // DOUG: can you help clarify the above comments?
150
147
DeclContext *const staticContext;
151
148
using NominalTypesThatSelfMustConformTo = SmallVector<NominalTypeDecl *, 2 >;
152
149
NominalTypesThatSelfMustConformTo nominalTypesThatSelfMustConformTo;
@@ -215,12 +212,12 @@ class UnqualifiedLookupFactory {
215
212
void performUnqualifiedLookup ();
216
213
217
214
private:
218
- struct DCAndUnresolvedIsCascadingUse {
215
+ struct ContextAndUnresolvedIsCascadingUse {
219
216
DeclContext *whereToLook;
220
217
Optional<bool > isCascadingUse;
221
- DCAndResolvedIsCascadingUse resolve (const bool resolution) const {
222
- return DCAndResolvedIsCascadingUse{whereToLook,
223
- isCascadingUse.getValueOr (resolution)};
218
+ ContextAndResolvedIsCascadingUse resolve (const bool resolution) const {
219
+ return ContextAndResolvedIsCascadingUse{
220
+ whereToLook, isCascadingUse.getValueOr (resolution)};
224
221
}
225
222
};
226
223
@@ -230,13 +227,13 @@ class UnqualifiedLookupFactory {
230
227
231
228
#pragma mark ASTScope-based-lookup declarations
232
229
233
- void experimentallyLookInASTScopes (DCAndUnresolvedIsCascadingUse );
230
+ void experimentallyLookInASTScopes (ContextAndUnresolvedIsCascadingUse );
234
231
235
232
std::pair<const ASTScope *, bool >
236
- operatorScopeForASTScopeLookup (DCAndUnresolvedIsCascadingUse );
233
+ operatorScopeForASTScopeLookup (ContextAndUnresolvedIsCascadingUse );
237
234
238
- std::pair<const ASTScope *, Optional<bool >>
239
- nonoperatorScopeForASTScopeLookup (DCAndUnresolvedIsCascadingUse ) const ;
235
+ std::pair<const ASTScope *, Optional<bool >> nonoperatorScopeForASTScopeLookup (
236
+ ContextAndUnresolvedIsCascadingUse ) const ;
240
237
241
238
struct ASTScopeLookupState {
242
239
const ASTScope *scope;
@@ -285,10 +282,10 @@ class UnqualifiedLookupFactory {
285
282
}
286
283
287
284
#pragma mark normal (non-ASTScope-based) lookup declarations
288
-
289
- void lookupOperatorInDeclContexts (DCAndUnresolvedIsCascadingUse);
290
285
291
- void lookupNamesIntroducedBy (const DCAndUnresolvedIsCascadingUse);
286
+ void lookupOperatorInDeclContexts (ContextAndUnresolvedIsCascadingUse);
287
+
288
+ void lookupNamesIntroducedBy (const ContextAndUnresolvedIsCascadingUse);
292
289
293
290
void finishLookingInContext (AddGenericParameters addGenericParameters,
294
291
DeclContext *lookupContextForThisContext,
@@ -376,7 +373,7 @@ class UnqualifiedLookupFactory {
376
373
static bool resolveIsCascadingUse (const DeclContext *const dc,
377
374
Optional<bool > isCascadingUse,
378
375
bool onlyCareAboutFunctionBody);
379
- static bool resolveIsCascadingUse (DCAndUnresolvedIsCascadingUse x,
376
+ static bool resolveIsCascadingUse (ContextAndUnresolvedIsCascadingUse x,
380
377
bool onlyCareAboutFunctionBody) {
381
378
return resolveIsCascadingUse (x.whereToLook , x.isCascadingUse ,
382
379
onlyCareAboutFunctionBody);
@@ -405,34 +402,35 @@ UnqualifiedLookupFactory::UnqualifiedLookupFactory(
405
402
Options options,
406
403
UnqualifiedLookup &lookupToBeCreated)
407
404
:
408
- Name(Name),
409
- DC(DC),
410
- M(*DC->getParentModule ()),
411
- Ctx(M.getASTContext()),
412
- TypeResolver(TypeResolver ? TypeResolver : Ctx.getLazyResolver()),
413
- Loc(Loc),
414
- SM(Ctx.SourceMgr),
415
- DebugClient(M.getDebugClient()),
416
- options(options),
417
- isOriginallyTypeLookup(options.contains(Flags::TypeLookup)),
418
- baseNLOptions(computeBaseNLOptions(options, isOriginallyTypeLookup)),
419
- Consumer(Name, lookupToBeCreated.Results, isOriginallyTypeLookup),
420
- Results(lookupToBeCreated.Results),
421
- IndexOfFirstOuterResult(lookupToBeCreated.IndexOfFirstOuterResult)
405
+ Name(Name),
406
+ DC(DC),
407
+ M(*DC->getParentModule ()),
408
+ Ctx(M.getASTContext()),
409
+ TypeResolver(TypeResolver ? TypeResolver : Ctx.getLazyResolver()),
410
+ Loc(Loc),
411
+ SM(Ctx.SourceMgr),
412
+ DebugClient(M.getDebugClient()),
413
+ options(options),
414
+ isOriginallyTypeLookup(options.contains(Flags::TypeLookup)),
415
+ baseNLOptions(computeBaseNLOptions(options, isOriginallyTypeLookup)),
416
+ Consumer(Name, lookupToBeCreated.Results, isOriginallyTypeLookup),
417
+ Results(lookupToBeCreated.Results),
418
+ IndexOfFirstOuterResult(lookupToBeCreated.IndexOfFirstOuterResult)
422
419
{}
423
420
// clang-format on
424
421
425
422
void UnqualifiedLookupFactory::performUnqualifiedLookup () {
426
423
const Optional<bool > isCascadingUseInitial =
427
424
options.contains (Flags::KnownPrivate) ? Optional<bool >(false ) : None;
428
425
429
- DCAndUnresolvedIsCascadingUse dcAndIsCascadingUse{DC, isCascadingUseInitial};
426
+ ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUse{
427
+ DC, isCascadingUseInitial};
430
428
if (useASTScopesForExperimentalLookup ())
431
- experimentallyLookInASTScopes (dcAndIsCascadingUse );
429
+ experimentallyLookInASTScopes (contextAndIsCascadingUse );
432
430
else if (Name.isOperator ())
433
- lookupOperatorInDeclContexts (dcAndIsCascadingUse );
431
+ lookupOperatorInDeclContexts (contextAndIsCascadingUse );
434
432
else
435
- lookupNamesIntroducedBy (dcAndIsCascadingUse );
433
+ lookupNamesIntroducedBy (contextAndIsCascadingUse );
436
434
}
437
435
438
436
void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext (
@@ -465,26 +463,26 @@ bool UnqualifiedLookupFactory::useASTScopesForExperimentalLookup() const {
465
463
#pragma mark ASTScope-based-lookup definitions
466
464
467
465
void UnqualifiedLookupFactory::experimentallyLookInASTScopes (
468
- const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg ) {
466
+ const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg ) {
469
467
const std::pair<const ASTScope *, Optional<bool >>
470
468
lookupScopeAndIsCascadingUse =
471
469
Name.isOperator ()
472
- ? operatorScopeForASTScopeLookup (dcAndIsCascadingUseArg )
473
- : nonoperatorScopeForASTScopeLookup (dcAndIsCascadingUseArg );
470
+ ? operatorScopeForASTScopeLookup (contextAndIsCascadingUseArg )
471
+ : nonoperatorScopeForASTScopeLookup (contextAndIsCascadingUseArg );
474
472
// Walk scopes outward from the innermost scope until we find something.
475
473
476
474
ASTScopeLookupState state{lookupScopeAndIsCascadingUse.first , nullptr ,
477
- dcAndIsCascadingUseArg .whereToLook ,
475
+ contextAndIsCascadingUseArg .whereToLook ,
478
476
lookupScopeAndIsCascadingUse.second };
479
477
lookInScopeForASTScopeLookup (state);
480
478
}
481
479
482
480
std::pair<const ASTScope *, bool >
483
481
UnqualifiedLookupFactory::operatorScopeForASTScopeLookup (
484
- const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg ) {
482
+ const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg ) {
485
483
// Find the source file in which we are performing the lookup.
486
484
SourceFile &sourceFile =
487
- *dcAndIsCascadingUseArg .whereToLook ->getParentSourceFile ();
485
+ *contextAndIsCascadingUseArg .whereToLook ->getParentSourceFile ();
488
486
489
487
// Find the scope from which we will initiate unqualified name lookup.
490
488
const ASTScope *lookupScope =
@@ -494,22 +492,24 @@ UnqualifiedLookupFactory::operatorScopeForASTScopeLookup(
494
492
return std::make_pair (
495
493
&sourceFile.getScope (),
496
494
resolveIsCascadingUse (lookupScope->getInnermostEnclosingDeclContext (),
497
- dcAndIsCascadingUseArg .isCascadingUse ,
495
+ contextAndIsCascadingUseArg .isCascadingUse ,
498
496
/* onlyCareAboutFunctionBody*/ true ));
499
497
}
500
498
501
499
std::pair<const ASTScope *, Optional<bool >>
502
500
UnqualifiedLookupFactory::nonoperatorScopeForASTScopeLookup (
503
- const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg) const {
501
+ const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg)
502
+ const {
504
503
// Find the source file in which we are performing the lookup.
505
504
SourceFile &sourceFile =
506
- *dcAndIsCascadingUseArg .whereToLook ->getParentSourceFile ();
505
+ *contextAndIsCascadingUseArg .whereToLook ->getParentSourceFile ();
507
506
508
507
// Find the scope from which we will initiate unqualified name lookup.
509
508
const ASTScope *lookupScope =
510
509
sourceFile.getScope ().findInnermostEnclosingScope (Loc);
511
510
512
- return std::make_pair (lookupScope, dcAndIsCascadingUseArg.isCascadingUse );
511
+ return std::make_pair (lookupScope,
512
+ contextAndIsCascadingUseArg.isCascadingUse );
513
513
}
514
514
515
515
void UnqualifiedLookupFactory::lookInScopeForASTScopeLookup (
@@ -627,21 +627,22 @@ void UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
627
627
#pragma mark context-based lookup definitions
628
628
629
629
void UnqualifiedLookupFactory::lookupOperatorInDeclContexts (
630
- const DCAndUnresolvedIsCascadingUse dcAndUseArg ) {
631
- DCAndResolvedIsCascadingUse dcAndResolvedIsCascadingUse {
630
+ const ContextAndUnresolvedIsCascadingUse contextAndUseArg ) {
631
+ ContextAndResolvedIsCascadingUse contextAndResolvedIsCascadingUse {
632
632
// Operators are global
633
- dcAndUseArg.whereToLook ->getModuleScopeContext (),
634
- resolveIsCascadingUse (dcAndUseArg, /* onlyCareAboutFunctionBody*/ true )};
635
- lookupInModuleScopeContext (dcAndResolvedIsCascadingUse.DC ,
636
- dcAndResolvedIsCascadingUse.isCascadingUse );
633
+ contextAndUseArg.whereToLook ->getModuleScopeContext (),
634
+ resolveIsCascadingUse (contextAndUseArg,
635
+ /* onlyCareAboutFunctionBody*/ true )};
636
+ lookupInModuleScopeContext (contextAndResolvedIsCascadingUse.DC ,
637
+ contextAndResolvedIsCascadingUse.isCascadingUse );
637
638
}
638
639
639
640
// TODO: Unify with LookupVisibleDecls.cpp::lookupVisibleDeclsImpl
640
641
void UnqualifiedLookupFactory::lookupNamesIntroducedBy (
641
- const DCAndUnresolvedIsCascadingUse dcAndIsCascadingUseArg ) {
642
+ const ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUseArg ) {
642
643
643
- DeclContext *const dc = dcAndIsCascadingUseArg .whereToLook ;
644
- const auto isCascadingUseSoFar = dcAndIsCascadingUseArg .isCascadingUse ;
644
+ DeclContext *const dc = contextAndIsCascadingUseArg .whereToLook ;
645
+ const auto isCascadingUseSoFar = contextAndIsCascadingUseArg .isCascadingUse ;
645
646
if (dc->isModuleScopeContext ())
646
647
lookupInModuleScopeContext (dc, isCascadingUseSoFar);
647
648
else if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc))
@@ -683,7 +684,7 @@ void UnqualifiedLookupFactory::finishLookingInContext(
683
684
},
684
685
// Recurse into the next context.
685
686
[&] {
686
- lookupNamesIntroducedBy (DCAndUnresolvedIsCascadingUse {
687
+ lookupNamesIntroducedBy (ContextAndUnresolvedIsCascadingUse {
687
688
lookupContextForThisContext->getParentForLookup (), isCascadingUse});
688
689
});
689
690
}
0 commit comments