@@ -174,9 +174,9 @@ class UnqualifiedLookupFactory {
174
174
void dump () const ;
175
175
};
176
176
177
- struct PerScopeLookupState {
178
- bool isDone ;
179
- DeclContext *childOfNextDC ;
177
+ struct PerDeclInfo {
178
+ bool isDoneWithThisDecl ;
179
+ DeclContext *lookupContextForThisDecl ;
180
180
Optional<PlacesToSearch> placesToSearch;
181
181
Optional<bool > isCascadingUse;
182
182
@@ -204,7 +204,7 @@ class UnqualifiedLookupFactory {
204
204
SmallVector<LookupResultEntry, 4 > UnavailableInnerResults;
205
205
206
206
public: // for exp debugging
207
- std::vector<PerScopeLookupState > breadcrumbs;
207
+ std::vector<PerDeclInfo > breadcrumbs;
208
208
SourceFile const *recordedSF = nullptr ;
209
209
DeclName recordedName;
210
210
bool recordedIsCascadingUse = false ;
@@ -280,7 +280,7 @@ class UnqualifiedLookupFactory {
280
280
const Optional<bool > isCascadingUseArg);
281
281
282
282
struct LookupInOneDeclContextResult {
283
- DeclContext *dc ;
283
+ DeclContext *completedDC ;
284
284
Optional<bool > isCascadingUse;
285
285
};
286
286
@@ -289,34 +289,33 @@ class UnqualifiedLookupFactory {
289
289
lookupInOneDeclContext (DeclContext *dc,
290
290
const Optional<bool > isCascadingUseArg);
291
291
292
- Optional<PerScopeLookupState >
292
+ Optional<PerDeclInfo >
293
293
lookupInAppropriateContext (DeclContext *dc, Optional<bool > isCascadingUse);
294
294
295
295
// TODO: use objects & virtuals
296
296
297
- Optional<PerScopeLookupState >
297
+ Optional<PerDeclInfo >
298
298
lookupInPatternBindingInitializer (PatternBindingInitializer *PBI,
299
299
Optional<bool > isCascadingUse);
300
300
301
- Optional<PerScopeLookupState>
302
- lookupInFunctionDecl (AbstractFunctionDecl *AFD,
303
- Optional<bool > isCascadingUse);
301
+ Optional<PerDeclInfo> lookupInFunctionDecl (AbstractFunctionDecl *AFD,
302
+ Optional<bool > isCascadingUse);
304
303
305
- Optional<PerScopeLookupState > lookupInClosure (AbstractClosureExpr *ACE,
306
- Optional<bool > isCascadingUse);
304
+ Optional<PerDeclInfo > lookupInClosure (AbstractClosureExpr *ACE,
305
+ Optional<bool > isCascadingUse);
307
306
308
307
template <typename NominalTypeDeclOrExtensionDecl>
309
- Optional<PerScopeLookupState >
308
+ Optional<PerDeclInfo >
310
309
lookupInNominalTypeOrExtension (NominalTypeDeclOrExtensionDecl *D,
311
310
Optional<bool > isCascadingUse) const ;
312
311
313
- Optional<PerScopeLookupState >
312
+ Optional<PerDeclInfo >
314
313
lookupInDefaultArgumentInitializer (DefaultArgumentInitializer *I,
315
314
Optional<bool > isCascadingUse) const ;
316
315
317
316
bool isOutsideBodyOfFunction (const AbstractFunctionDecl *const AFD) const ;
318
317
319
- Optional<PerScopeLookupState >
318
+ Optional<PerDeclInfo >
320
319
lookupInMiscContext (DeclContext *dc, Optional<bool > isCascadingUse) const ;
321
320
322
321
// / Check the generic parameters of our context.
@@ -677,7 +676,7 @@ UnqualifiedLookupFactory::nonASTScopeBasedLookup(
677
676
auto r = lookupInOneDeclContext (nextDC, isCascadingUse);
678
677
if (!r.hasValue ())
679
678
return None;
680
- nextDC = r.getValue ().dc ;
679
+ nextDC = r.getValue ().completedDC -> getParentForLookup () ;
681
680
isCascadingUse = r.getValue ().isCascadingUse ;
682
681
assert (nextDC != priorDC && " non-termination" );
683
682
priorDC = nextDC;
@@ -697,31 +696,33 @@ UnqualifiedLookupFactory::lookupInOneDeclContext(
697
696
const auto r = lookupInAppropriateContext (dc, isCascadingUseArg);
698
697
if (!r.hasValue ())
699
698
return None;
700
- const bool isDone = r.getValue ().isDone ;
699
+ const bool isDoneWithThisDecl = r.getValue ().isDoneWithThisDecl ;
701
700
breadcrumbs.push_back (r.getValue ());
702
- auto childOfNextDC = r.getValue ().childOfNextDC ;
701
+ auto lookupContextForThisDecl = r.getValue ().lookupContextForThisDecl ;
703
702
auto placesToSearch = std::move (r.getValue ().placesToSearch );
704
703
auto isCascadingUse = r.getValue ().isCascadingUse ;
705
704
706
- if (isDone)
707
- return LookupInOneDeclContextResult{childOfNextDC, isCascadingUse};
705
+ if (isDoneWithThisDecl)
706
+ return LookupInOneDeclContextResult{lookupContextForThisDecl,
707
+ isCascadingUse};
708
708
709
- if (addGenericParametersHereAndInEnclosingScopes (childOfNextDC ))
709
+ if (addGenericParametersHereAndInEnclosingScopes (lookupContextForThisDecl ))
710
710
return None;
711
711
if (placesToSearch.hasValue () && !placesToSearch.getValue ().empty ()) {
712
712
auto startIndexOfInnerResults = Results.size ();
713
- placesToSearch.getValue ().addToResults (
714
- Name, isCascadingUse.getValue (), baseNLOptions, childOfNextDC, Results);
713
+ placesToSearch.getValue ().addToResults (Name, isCascadingUse.getValue (),
714
+ baseNLOptions,
715
+ lookupContextForThisDecl, Results);
715
716
if (handleUnavailableInnerResults (startIndexOfInnerResults))
716
717
return None;
717
718
}
718
719
// TODO: What if !BaseDC && lookupDecls non-empty?
719
- DeclContext *nextDC = childOfNextDC-> getParentForLookup ();
720
- return LookupInOneDeclContextResult{nextDC, isCascadingUse};
720
+ return LookupInOneDeclContextResult{lookupContextForThisDecl,
721
+ isCascadingUse};
721
722
}
722
723
// clang-format on
723
724
724
- Optional<UnqualifiedLookupFactory::PerScopeLookupState >
725
+ Optional<UnqualifiedLookupFactory::PerDeclInfo >
725
726
UnqualifiedLookupFactory::lookupInAppropriateContext (
726
727
DeclContext *dc, Optional<bool > isCascadingUse) {
727
728
if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc))
@@ -740,7 +741,7 @@ UnqualifiedLookupFactory::lookupInAppropriateContext(
740
741
return lookupInMiscContext (dc, isCascadingUse);
741
742
}
742
743
743
- Optional<UnqualifiedLookupFactory::PerScopeLookupState >
744
+ Optional<UnqualifiedLookupFactory::PerDeclInfo >
744
745
UnqualifiedLookupFactory::lookupInPatternBindingInitializer (
745
746
PatternBindingInitializer *PBI, Optional<bool > isCascadingUse) {
746
747
auto *PBD = PBI->getBinding ();
@@ -754,7 +755,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
754
755
return None;
755
756
DeclContext *const parent = PBI->getParent ();
756
757
// clang-format off
757
- return PerScopeLookupState {
758
+ return PerDeclInfo {
758
759
false ,
759
760
parent,
760
761
PlacesToSearch (parent, PBI, parent, parent),
@@ -767,7 +768,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
767
768
if (PBD->getDeclContext ()->isTypeContext ()) {
768
769
DeclContext *const surroundingContext = PBI->getParent ();
769
770
// clang-format off
770
- return PerScopeLookupState {
771
+ return PerDeclInfo {
771
772
false ,
772
773
surroundingContext,
773
774
PlacesToSearch (surroundingContext, surroundingContext,
@@ -781,7 +782,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
781
782
// There's not much to find here, we'll keep going up to a parent
782
783
// context.
783
784
// clang-format off
784
- return PerScopeLookupState {
785
+ return PerDeclInfo {
785
786
false ,
786
787
PBI,
787
788
None,
@@ -790,7 +791,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
790
791
// clang-format on
791
792
}
792
793
793
- Optional<UnqualifiedLookupFactory::PerScopeLookupState >
794
+ Optional<UnqualifiedLookupFactory::PerDeclInfo >
794
795
UnqualifiedLookupFactory::lookupInFunctionDecl (AbstractFunctionDecl *AFD,
795
796
Optional<bool > isCascadingUse) {
796
797
// Look for local variables; normally, the parser resolves these
@@ -827,7 +828,7 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
827
828
if (isLookupDoneWithoutIncludingOuterResults ())
828
829
return None;
829
830
// clang-format off
830
- return PerScopeLookupState {
831
+ return PerDeclInfo {
831
832
false ,
832
833
fnParent,
833
834
PlacesToSearch (
@@ -848,15 +849,15 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
848
849
if (isLookupDoneWithoutIncludingOuterResults ())
849
850
return None;
850
851
// clang-format off
851
- return PerScopeLookupState {
852
+ return PerDeclInfo {
852
853
false ,
853
854
AFD,
854
855
None,
855
856
returnValueForIsCascadingUse};
856
857
// clang-format on
857
858
}
858
859
859
- Optional<UnqualifiedLookupFactory::PerScopeLookupState >
860
+ Optional<UnqualifiedLookupFactory::PerDeclInfo >
860
861
UnqualifiedLookupFactory::lookupInClosure (AbstractClosureExpr *ACE,
861
862
Optional<bool > isCascadingUse) {
862
863
// Look for local variables; normally, the parser resolves these
@@ -877,7 +878,7 @@ UnqualifiedLookupFactory::lookupInClosure(AbstractClosureExpr *ACE,
877
878
}
878
879
}
879
880
// clang-format off
880
- return PerScopeLookupState {
881
+ return PerDeclInfo {
881
882
false ,
882
883
ACE,
883
884
None,
@@ -887,11 +888,11 @@ UnqualifiedLookupFactory::lookupInClosure(AbstractClosureExpr *ACE,
887
888
}
888
889
889
890
template <typename NominalTypeDeclOrExtensionDecl>
890
- Optional<UnqualifiedLookupFactory::PerScopeLookupState >
891
+ Optional<UnqualifiedLookupFactory::PerDeclInfo >
891
892
UnqualifiedLookupFactory::lookupInNominalTypeOrExtension (
892
893
NominalTypeDeclOrExtensionDecl *D, Optional<bool > isCascadingUse) const {
893
894
// clang-format off
894
- return PerScopeLookupState {
895
+ return PerDeclInfo {
895
896
false ,
896
897
D,
897
898
shouldLookupMembers (D, Loc)
@@ -903,14 +904,15 @@ UnqualifiedLookupFactory::lookupInNominalTypeOrExtension(
903
904
// clang-format on
904
905
}
905
906
906
- Optional<UnqualifiedLookupFactory::PerScopeLookupState >
907
+ Optional<UnqualifiedLookupFactory::PerDeclInfo >
907
908
UnqualifiedLookupFactory::lookupInDefaultArgumentInitializer (
908
909
DefaultArgumentInitializer *I, Optional<bool > isCascadingUse) const {
909
910
// In a default argument, skip immediately out of both the
910
911
// initializer and the function.
911
912
// clang-format off
912
- return PerScopeLookupState{true ,
913
- I->getParent ()->getParent (),
913
+ return PerDeclInfo{
914
+ true ,
915
+ I->getParent (),
914
916
None,
915
917
false };
916
918
// clang-format on
@@ -923,15 +925,15 @@ bool UnqualifiedLookupFactory::isOutsideBodyOfFunction(
923
925
!SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc);
924
926
}
925
927
926
- Optional<UnqualifiedLookupFactory::PerScopeLookupState >
928
+ Optional<UnqualifiedLookupFactory::PerDeclInfo >
927
929
UnqualifiedLookupFactory::lookupInMiscContext (
928
930
DeclContext *dc, Optional<bool > isCascadingUse) const {
929
931
// clang-format off
930
932
assert (isa<TopLevelCodeDecl>(dc) ||
931
933
isa<Initializer>(dc) ||
932
934
isa<TypeAliasDecl>(dc) ||
933
935
isa<SubscriptDecl>(dc));
934
- return PerScopeLookupState {
936
+ return PerDeclInfo {
935
937
false ,
936
938
dc,
937
939
None,
@@ -1757,16 +1759,16 @@ void UnqualifiedLookupFactory::dumpBreadcrumbs() const {
1757
1759
auto &e = llvm::errs ();
1758
1760
for (size_t i : indices (breadcrumbs)) {
1759
1761
e << i << " \n " ;
1760
- const PerScopeLookupState &s = breadcrumbs[i];
1762
+ const PerDeclInfo &s = breadcrumbs[i];
1761
1763
s.dump ();
1762
1764
}
1763
1765
}
1764
1766
1765
- void UnqualifiedLookupFactory::PerScopeLookupState ::dump () const {
1767
+ void UnqualifiedLookupFactory::PerDeclInfo ::dump () const {
1766
1768
auto &e = llvm::errs ();
1767
- e << (isDone ? " done: " : " not done: " );
1769
+ e << (isDoneWithThisDecl ? " done: " : " not done: " );
1768
1770
e << " dc: " ;
1769
- childOfNextDC ->dumpContext ();
1771
+ lookupContextForThisDecl ->dumpContext ();
1770
1772
if (placesToSearch.hasValue ())
1771
1773
placesToSearch.getValue ().dump ();
1772
1774
}
0 commit comments