@@ -239,7 +239,8 @@ class UnqualifiedLookupFactory {
239
239
240
240
bool useASTScopesForExperimentalLookup () const ;
241
241
242
- void lookInModuleScopeContext (DCAndResolvedIsCascadingUse dcAndIsCascadingUse);
242
+ void lookupNonlocalsInModuleScopeContext (
243
+ DCAndResolvedIsCascadingUse dcAndIsCascadingUse);
243
244
244
245
#pragma mark ASTScope-based-lookup declarations
245
246
@@ -297,7 +298,7 @@ class UnqualifiedLookupFactory {
297
298
Optional<PlacesToSearch> &&placesToSearch,
298
299
Optional<bool > isCascadingUse);
299
300
300
- void lookupLocalsInAppropriateContext (DCAndUnresolvedIsCascadingUse );
301
+ void lookupInModuleScopeContext (DeclContext *, Optional< bool > isCascadingUse );
301
302
302
303
// TODO: use objects & virtuals
303
304
@@ -330,7 +331,7 @@ class UnqualifiedLookupFactory {
330
331
static GenericParamList *getGenericParams (const DeclContext *const dc);
331
332
332
333
// / Return true if lookup is done
333
- bool addLocalVariableResults (DeclContext *dc);
334
+ void addLocalVariableResults (DeclContext *dc);
334
335
335
336
void setAsideUnavailableResults (size_t firstPossiblyUnavailableResult);
336
337
@@ -339,13 +340,11 @@ class UnqualifiedLookupFactory {
339
340
340
341
void addPrivateImports (DeclContext *const dc);
341
342
342
- // / Return true if done
343
- bool addNamesKnownToDebugClient (DeclContext *dc);
343
+ void addNamesKnownToDebugClient (DeclContext *dc);
344
344
345
- // / Return true if done
346
- bool addUnavailableInnerResults ();
345
+ void addUnavailableInnerResults ();
347
346
348
- bool lookForAModuleWithTheGivenName (DeclContext *const dc);
347
+ void lookForAModuleWithTheGivenName (DeclContext *const dc);
349
348
350
349
#pragma mark common helper declarations
351
350
static NLOptions
@@ -408,7 +407,7 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
408
407
lookupStartingWith (dcAndIsCascadingUse);
409
408
}
410
409
411
- void UnqualifiedLookupFactory::lookInModuleScopeContext (
410
+ void UnqualifiedLookupFactory::lookupNonlocalsInModuleScopeContext (
412
411
DCAndResolvedIsCascadingUse dcAndIsCascadingUse) {
413
412
DeclContext *const DC = dcAndIsCascadingUse.DC ;
414
413
const bool isCascadingUse = dcAndIsCascadingUse.isCascadingUse ;
@@ -422,17 +421,16 @@ void UnqualifiedLookupFactory::lookInModuleScopeContext(
422
421
return ;
423
422
424
423
addPrivateImports (DC);
425
- if (addNamesKnownToDebugClient (DC))
426
- return ;
427
- // If we still haven't found anything, but we do have some
428
- // declarations that are "unavailable in the current Swift", drop
429
- // those in.
430
- if (addUnavailableInnerResults ())
431
- return ;
432
- if (lookForAModuleWithTheGivenName (DC))
433
- return ;
434
- // Make sure we've recorded the inner-result-boundary.
435
- recordCompletionOfAScope (); // DMU elim?
424
+ addNamesKnownToDebugClient (DC);
425
+ if (Results.empty ()) {
426
+ // If we still haven't found anything, but we do have some
427
+ // declarations that are "unavailable in the current Swift", drop
428
+ // those in.
429
+ addUnavailableInnerResults ();
430
+ if (Results.empty ())
431
+ lookForAModuleWithTheGivenName (DC);
432
+ }
433
+ recordCompletionOfAScope ();
436
434
}
437
435
438
436
bool UnqualifiedLookupFactory::useASTScopesForExperimentalLookup () const {
@@ -583,7 +581,7 @@ void UnqualifiedLookupFactory::lookIntoDeclarationContextForASTScopeLookup(
583
581
}
584
582
// Lookup in the source file's scope marks the end.
585
583
if (isa<SourceFile>(scopeDC)) {
586
- lookInModuleScopeContext (
584
+ lookupNonlocalsInModuleScopeContext (
587
585
DCAndResolvedIsCascadingUse{scopeDC, isCascadingUseResult});
588
586
return ;
589
587
}
@@ -650,8 +648,8 @@ void UnqualifiedLookupFactory::lookupOperatorInDeclContexts(
650
648
dcAndUseArg.whereToLook ->getModuleScopeContext (),
651
649
resolveIsCascadingUse (dcAndUseArg,
652
650
/* onlyCareAboutFunctionBody*/ true )};
653
- if (! addLocalVariableResults ( dcAndResolvedIsCascadingUse.DC ))
654
- lookInModuleScopeContext ( dcAndResolvedIsCascadingUse);
651
+ lookupInModuleScopeContext ( dcAndResolvedIsCascadingUse.DC ,
652
+ dcAndResolvedIsCascadingUse. isCascadingUse );
655
653
}
656
654
657
655
// TODO: Unify with LookupVisibleDecls.cpp::lookupVisibleDeclsImpl
@@ -662,12 +660,24 @@ void UnqualifiedLookupFactory::lookupStartingWith(
662
660
// scope, and if so, whether this is a reference to one of them.
663
661
// FIXME: We should persist this information between lookups.
664
662
665
- if (dcAndIsCascadingUseArg.whereToLook ->isModuleScopeContext ()) {
666
- if (!addLocalVariableResults (dcAndIsCascadingUseArg.whereToLook ))
667
- lookInModuleScopeContext (dcAndIsCascadingUseArg.resolve (true ));
668
- return ;
669
- }
670
- lookupLocalsInAppropriateContext (dcAndIsCascadingUseArg);
663
+ DeclContext *const dc = dcAndIsCascadingUseArg.whereToLook ;
664
+ const auto isCascadingUseSoFar = dcAndIsCascadingUseArg.isCascadingUse ;
665
+ if (dc->isModuleScopeContext ())
666
+ lookupInModuleScopeContext (dc, isCascadingUseSoFar);
667
+ else if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc))
668
+ lookupLocalsInPatternBindingInitializer (PBI, isCascadingUseSoFar);
669
+ else if (auto *AFD = dyn_cast<AbstractFunctionDecl>(dc))
670
+ lookupLocalsInFunctionDecl (AFD, isCascadingUseSoFar);
671
+ else if (auto *ACE = dyn_cast<AbstractClosureExpr>(dc))
672
+ lookupLocalsInClosure (ACE, isCascadingUseSoFar);
673
+ else if (auto *ED = dyn_cast<ExtensionDecl>(dc))
674
+ lookupLocalsInNominalTypeOrExtension (ED, isCascadingUseSoFar);
675
+ else if (auto *ND = dyn_cast<NominalTypeDecl>(dc))
676
+ lookupLocalsInNominalTypeOrExtension (ND, isCascadingUseSoFar);
677
+ else if (auto I = dyn_cast<DefaultArgumentInitializer>(dc))
678
+ lookupLocalsInDefaultArgumentInitializer (I, isCascadingUseSoFar);
679
+ else
680
+ lookupLocalsInMiscContext (dc, isCascadingUseSoFar);
671
681
}
672
682
673
683
void UnqualifiedLookupFactory::finishLookingInContext (
@@ -701,24 +711,14 @@ void UnqualifiedLookupFactory::finishLookingInContext(
701
711
lookupContextForThisContext->getParentForLookup (), isCascadingUse});
702
712
}
703
713
704
- void UnqualifiedLookupFactory::lookupLocalsInAppropriateContext (
705
- const DCAndUnresolvedIsCascadingUse dcAndIsCasc) {
706
- DeclContext *const dc = dcAndIsCasc.whereToLook ;
707
- const auto isCascadingUseSoFar = dcAndIsCasc.isCascadingUse ;
708
- if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc))
709
- lookupLocalsInPatternBindingInitializer (PBI, isCascadingUseSoFar);
710
- else if (auto *AFD = dyn_cast<AbstractFunctionDecl>(dc))
711
- lookupLocalsInFunctionDecl (AFD, isCascadingUseSoFar);
712
- else if (auto *ACE = dyn_cast<AbstractClosureExpr>(dc))
713
- lookupLocalsInClosure (ACE, isCascadingUseSoFar);
714
- else if (auto *ED = dyn_cast<ExtensionDecl>(dc))
715
- lookupLocalsInNominalTypeOrExtension (ED, isCascadingUseSoFar);
716
- else if (auto *ND = dyn_cast<NominalTypeDecl>(dc))
717
- lookupLocalsInNominalTypeOrExtension (ND, isCascadingUseSoFar);
718
- else if (auto I = dyn_cast<DefaultArgumentInitializer>(dc))
719
- lookupLocalsInDefaultArgumentInitializer (I, isCascadingUseSoFar);
720
- else
721
- lookupLocalsInMiscContext (dc, isCascadingUseSoFar);
714
+ void UnqualifiedLookupFactory::lookupInModuleScopeContext (
715
+ DeclContext *dc, Optional<bool > isCascadingUse) {
716
+ addLocalVariableResults (dc);
717
+ recordCompletionOfAScope ();
718
+ if (isFirstResultEnough ())
719
+ return ;
720
+ lookupNonlocalsInModuleScopeContext (
721
+ DCAndUnresolvedIsCascadingUse{dc, isCascadingUse}.resolve (true ));
722
722
}
723
723
724
724
void UnqualifiedLookupFactory::lookupLocalsInPatternBindingInitializer (
@@ -945,21 +945,16 @@ void UnqualifiedLookupFactory::addGenericParametersForFunction(
945
945
}
946
946
}
947
947
948
- // TODO enum instead of bool for return type?
949
- bool UnqualifiedLookupFactory::addLocalVariableResults (DeclContext *dc) {
948
+ void UnqualifiedLookupFactory::addLocalVariableResults (DeclContext *dc) {
950
949
if (auto SF = dyn_cast<SourceFile>(dc)) {
951
950
if (Loc.isValid ()) {
952
951
// Look for local variables in top-level code; normally, the parser
953
952
// resolves these for us, but it can't do the right thing for
954
953
// local types.
955
954
namelookup::FindLocalVal localVal (SM, Loc, Consumer);
956
955
localVal.checkSourceFile (*SF);
957
- recordCompletionOfAScope ();
958
- if (isFirstResultEnough ())
959
- return true ;
960
956
}
961
957
}
962
- return false ;
963
958
}
964
959
965
960
void UnqualifiedLookupFactory::PlacesToSearch::addToResults (
@@ -1032,32 +1027,26 @@ void UnqualifiedLookupFactory::addPrivateImports(DeclContext *const dc) {
1032
1027
filterForDiscriminator (Results, DebugClient);
1033
1028
}
1034
1029
1035
- bool UnqualifiedLookupFactory::addNamesKnownToDebugClient (DeclContext *dc) {
1030
+ void UnqualifiedLookupFactory::addNamesKnownToDebugClient (DeclContext *dc) {
1036
1031
if (Name.isSimpleName () && DebugClient)
1037
1032
DebugClient->lookupAdditions (Name.getBaseName (), dc, Loc,
1038
1033
isOriginallyTypeLookup, Results);
1039
- recordCompletionOfAScope ();
1040
- // If we've found something, we're done.
1041
- return !Results.empty ();
1042
1034
}
1043
1035
1044
- bool UnqualifiedLookupFactory::addUnavailableInnerResults () {
1036
+ void UnqualifiedLookupFactory::addUnavailableInnerResults () {
1045
1037
Results = std::move (UnavailableInnerResults);
1046
- recordCompletionOfAScope ();
1047
- return !Results.empty ();
1048
1038
}
1049
1039
1050
- bool UnqualifiedLookupFactory::lookForAModuleWithTheGivenName (
1040
+ void UnqualifiedLookupFactory::lookForAModuleWithTheGivenName (
1051
1041
DeclContext *const dc) {
1052
1042
using namespace namelookup ;
1053
1043
if (!Name.isSimpleName ())
1054
- return true ;
1044
+ return ;
1055
1045
1056
1046
// Look for a module with the given name.
1057
1047
if (Name.isSimpleName (M.getName ())) {
1058
1048
Results.push_back (LookupResultEntry (&M));
1059
- recordCompletionOfAScope ();
1060
- return true ;
1049
+ return ;
1061
1050
}
1062
1051
ModuleDecl *desiredModule = Ctx.getLoadedModule (Name.getBaseIdentifier ());
1063
1052
if (!desiredModule && Name == Ctx.TheBuiltinModule ->getName ())
@@ -1072,7 +1061,6 @@ bool UnqualifiedLookupFactory::lookForAModuleWithTheGivenName(
1072
1061
return true ;
1073
1062
});
1074
1063
}
1075
- return false ;
1076
1064
}
1077
1065
1078
1066
#pragma mark common helper definitions
0 commit comments