@@ -1392,9 +1392,9 @@ namespace {
1392
1392
}
1393
1393
// Never perform local lookup for operators.
1394
1394
else if (Name.isOperator ()) {
1395
- if (operatorLookup ())
1395
+ if (!(DC = operatorLookup (DC) ))
1396
1396
return ;
1397
- } else if (nonASTScopeBasedLookup ())
1397
+ } else if (!(DC = nonASTScopeBasedLookup (DC) ))
1398
1398
return ;
1399
1399
1400
1400
// TODO: Does the debugger client care about compound names?
@@ -1636,77 +1636,78 @@ namespace {
1636
1636
}
1637
1637
}
1638
1638
1639
- bool operatorLookup () {
1640
- updateIsCascadingForOperator (DC);
1641
- DC = DC->getModuleScopeContext ();
1642
- return addLocalVariableResults ();
1639
+ // return nullptr if lookup done
1640
+ DeclContext * operatorLookup (DeclContext *dc) {
1641
+ updateIsCascadingForOperator (dc);
1642
+ auto *msc = dc->getModuleScopeContext ();
1643
+ return addLocalVariableResults (msc) ? nullptr : msc;
1643
1644
}
1644
1645
1645
- // / Return true if done looking up.
1646
- bool nonASTScopeBasedLookup () {
1646
+ // / Return nullptr if done looking up.
1647
+ DeclContext * nonASTScopeBasedLookup (DeclContext * const dc ) {
1647
1648
// If we are inside of a method, check to see if there are any ivars in
1648
1649
// scope, and if so, whether this is a reference to one of them.
1649
1650
// FIXME: We should persist this information between lookups.
1650
- while (!DC->isModuleScopeContext ()) {
1651
- auto resultAndDC = lookupInOneDeclContext (DC);
1652
- DeclContext *oldDC = DC; // CLEAN UP
1653
- DC = resultAndDC.second ;
1654
- switch (resultAndDC.first ) {
1655
- case ScopeLookupResult::next:
1656
- assert (DC != oldDC && " non-termination" );
1657
- continue ;
1658
- case ScopeLookupResult::stop:
1651
+ DeclContext *nextDC = dc;
1652
+ while (!nextDC->isModuleScopeContext ()) {
1653
+ auto resultAndDC = lookupInOneDeclContext (nextDC);
1654
+ DeclContext *oldDC = nextDC; // CLEAN UP
1655
+ nextDC = resultAndDC.second ;
1656
+ switch (resultAndDC.first ) {
1657
+ case ScopeLookupResult::next:
1658
+ assert (nextDC != oldDC && " non-termination" );
1659
+ continue ;
1660
+ case ScopeLookupResult::stop:
1661
+ break ;
1662
+ case ScopeLookupResult::finished:
1663
+ return nullptr ;
1664
+ }
1659
1665
break ;
1660
- case ScopeLookupResult::finished:
1661
- return true ;
1662
1666
}
1663
- break ;
1667
+
1668
+ if (!isCascadingUse.hasValue ())
1669
+ isCascadingUse = true ;
1670
+
1671
+ return addLocalVariableResults (nextDC) ? nullptr : nextDC;
1664
1672
}
1665
1673
1666
- if (!isCascadingUse.hasValue ())
1667
- isCascadingUse = true ;
1668
-
1669
- return addLocalVariableResults ();
1670
- }
1671
-
1672
1674
// / Return the next context to search.
1673
1675
std::pair<ScopeLookupResult, DeclContext *>
1674
- lookupInOneDeclContext (DeclContext *DC ) {
1676
+ lookupInOneDeclContext (DeclContext *dc ) {
1675
1677
PerScopeLookupState results =
1676
- lookupInAppropriateContext (DC , isCascadingUse);
1678
+ lookupInAppropriateContext (dc , isCascadingUse);
1677
1679
breadcrumbs.push_back (results);
1678
1680
1679
- DC = results.nextDC ;
1680
1681
isCascadingUse = results.isCascadingUse ;
1681
1682
switch (results.result ) {
1682
1683
case ScopeLookupResult::next:
1683
1684
break ;
1684
1685
case ScopeLookupResult::stop:
1685
- return std::make_pair (ScopeLookupResult::next, results.nextDC );
1686
+ return std::make_pair (ScopeLookupResult::next, results.childOfNextDC );
1686
1687
case ScopeLookupResult::finished:
1687
- return std::make_pair (ScopeLookupResult::finished, results.nextDC );
1688
+ return std::make_pair (ScopeLookupResult::finished, results.childOfNextDC );
1688
1689
}
1689
- if (addGenericParametersHereAndInEnclosingScopes (DC ))
1690
- return std::make_pair (ScopeLookupResult::finished, DC );
1690
+ if (addGenericParametersHereAndInEnclosingScopes (results. childOfNextDC ))
1691
+ return std::make_pair (ScopeLookupResult::finished, results. childOfNextDC );
1691
1692
1692
1693
if (results.placesToSearch .hasValue () &&
1693
1694
!results.placesToSearch .getValue ().empty ()) {
1694
1695
auto startIndexOfInnerResults = Results.size ();
1695
1696
searchPlacesToSearch (std::move (results.placesToSearch .getValue ()), Name,
1696
- isCascadingUse.getValue (), baseNLOptions, DC );
1697
+ isCascadingUse.getValue (), baseNLOptions, results. childOfNextDC );
1697
1698
if (handleUnavailableInnerResults (startIndexOfInnerResults))
1698
- return std::make_pair (ScopeLookupResult::finished, DC );
1699
+ return std::make_pair (ScopeLookupResult::finished, results. childOfNextDC );
1699
1700
}
1700
1701
// TODO: What if !BaseDC && lookupDecls non-empty?
1701
- DC = DC ->getParentForLookup ();
1702
- return std::make_pair (ScopeLookupResult::next, DC );
1702
+ DeclContext *nextDC = results. childOfNextDC ->getParentForLookup ();
1703
+ return std::make_pair (ScopeLookupResult::next, nextDC );
1703
1704
}
1704
1705
1705
1706
// / Check the generic parameters of our context.
1706
1707
// / Return true if done with lookup
1707
1708
// / TODO: Factor with addGenericParmeters below
1708
- bool addGenericParametersHereAndInEnclosingScopes (DeclContext *DC ) {
1709
- for (GenericParamList *dcGenericParams = getGenericParams (DC );
1709
+ bool addGenericParametersHereAndInEnclosingScopes (DeclContext *dc ) {
1710
+ for (GenericParamList *dcGenericParams = getGenericParams (dc );
1710
1711
dcGenericParams;
1711
1712
dcGenericParams = dcGenericParams->getOuterParameters ()) {
1712
1713
namelookup::FindLocalVal localVal (SM, Loc, Consumer);
@@ -1730,32 +1731,32 @@ namespace {
1730
1731
}
1731
1732
}
1732
1733
1733
- static GenericParamList *getGenericParams (const DeclContext *const DC ) {
1734
- if (auto nominal = dyn_cast<NominalTypeDecl>(DC ))
1734
+ static GenericParamList *getGenericParams (const DeclContext *const dc ) {
1735
+ if (auto nominal = dyn_cast<NominalTypeDecl>(dc ))
1735
1736
return nominal->getGenericParams ();
1736
- if (auto ext = dyn_cast<ExtensionDecl>(DC ))
1737
+ if (auto ext = dyn_cast<ExtensionDecl>(dc ))
1737
1738
return ext->getGenericParams ();
1738
- if (auto subscript = dyn_cast<SubscriptDecl>(DC ))
1739
+ if (auto subscript = dyn_cast<SubscriptDecl>(dc ))
1739
1740
return subscript->getGenericParams ();
1740
1741
return nullptr ;
1741
1742
}
1742
1743
1743
1744
PerScopeLookupState
1744
- lookupInAppropriateContext (DeclContext *DC , Optional<bool > isCascadingUse) {
1745
- if (auto *PBI = dyn_cast<PatternBindingInitializer>(DC ))
1745
+ lookupInAppropriateContext (DeclContext *dc , Optional<bool > isCascadingUse) {
1746
+ if (auto *PBI = dyn_cast<PatternBindingInitializer>(dc ))
1746
1747
return lookupInPatternBindingInitializer (PBI, isCascadingUse);
1747
- if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC ))
1748
+ if (auto *AFD = dyn_cast<AbstractFunctionDecl>(dc ))
1748
1749
return lookupInFunctionDecl (AFD, isCascadingUse);
1749
- if (auto *ACE = dyn_cast<AbstractClosureExpr>(DC ))
1750
+ if (auto *ACE = dyn_cast<AbstractClosureExpr>(dc ))
1750
1751
return lookupInClosure (ACE, isCascadingUse);
1751
- if (auto *ED = dyn_cast<ExtensionDecl>(DC ))
1752
+ if (auto *ED = dyn_cast<ExtensionDecl>(dc ))
1752
1753
return lookupInExtension (ED, isCascadingUse);
1753
- if (auto *ND = dyn_cast<NominalTypeDecl>(DC ))
1754
+ if (auto *ND = dyn_cast<NominalTypeDecl>(dc ))
1754
1755
return lookupInNominalType (ND, isCascadingUse);
1755
- if (auto I = dyn_cast<DefaultArgumentInitializer>(DC ))
1756
+ if (auto I = dyn_cast<DefaultArgumentInitializer>(dc ))
1756
1757
return lookupInDefaultArgumentInitializer (I, isCascadingUse);
1757
1758
1758
- return lookupInMiscContext (DC , isCascadingUse);
1759
+ return lookupInMiscContext (dc , isCascadingUse);
1759
1760
}
1760
1761
1761
1762
PerScopeLookupState
@@ -1782,7 +1783,7 @@ namespace {
1782
1783
PlacesToSearch (parent, PBI, parent, parent),
1783
1784
isCascadingUse.hasValue ()
1784
1785
? isCascadingUse.getValue ()
1785
- : DC ->isCascadingContextForLookup (false )};
1786
+ : PBI ->isCascadingContextForLookup (false )};
1786
1787
}
1787
1788
// Initializers for stored properties of types perform static
1788
1789
// lookup into the surrounding context.
@@ -1889,7 +1890,7 @@ namespace {
1889
1890
}
1890
1891
}
1891
1892
}
1892
- return PerScopeLookupState{ScopeLookupResult::next, DC , None,
1893
+ return PerScopeLookupState{ScopeLookupResult::next, ACE , None,
1893
1894
isCascadingUse.hasValue ()
1894
1895
? isCascadingUse.getValue ()
1895
1896
: ACE->isCascadingContextForLookup (false )};
@@ -1932,18 +1933,19 @@ namespace {
1932
1933
!SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc);
1933
1934
}
1934
1935
1935
- PerScopeLookupState lookupInMiscContext (DeclContext *DC ,
1936
+ PerScopeLookupState lookupInMiscContext (DeclContext *dc ,
1936
1937
Optional<bool > isCascadingUse) {
1937
- assert (isa<TopLevelCodeDecl>(DC ) || isa<Initializer>(DC ) ||
1938
- isa<TypeAliasDecl>(DC ) || isa<SubscriptDecl>(DC ));
1939
- return PerScopeLookupState{ScopeLookupResult::next, DC , None,
1938
+ assert (isa<TopLevelCodeDecl>(dc ) || isa<Initializer>(dc ) ||
1939
+ isa<TypeAliasDecl>(dc ) || isa<SubscriptDecl>(dc ));
1940
+ return PerScopeLookupState{ScopeLookupResult::next, dc , None,
1940
1941
isCascadingUse.hasValue ()
1941
1942
? isCascadingUse.getValue ()
1942
- : DC ->isCascadingContextForLookup (false )};
1943
+ : dc ->isCascadingContextForLookup (false )};
1943
1944
}
1944
1945
1945
- bool addLocalVariableResults () {
1946
- if (auto SF = dyn_cast<SourceFile>(DC)) {
1946
+ // / return true if lookup is done
1947
+ bool addLocalVariableResults (DeclContext *dc) {
1948
+ if (auto SF = dyn_cast<SourceFile>(dc)) {
1947
1949
if (Loc.isValid ()) {
1948
1950
// Look for local variables in top-level code; normally, the parser
1949
1951
// resolves these for us, but it can't do the right thing for
@@ -1968,7 +1970,7 @@ namespace {
1968
1970
: NL_KnownNonCascadingDependency);
1969
1971
1970
1972
SmallVector<ValueDecl *, 4 > Lookup;
1971
- DC ->lookupQualified (placesToSearch.places , Name, options, Lookup);
1973
+ contextForLookup ->lookupQualified (placesToSearch.places , Name, options, Lookup);
1972
1974
for (auto Result : Lookup)
1973
1975
Results.push_back (LookupResultEntry (
1974
1976
placesToSearch.whereValueIsMember (Result), Result));
@@ -2138,7 +2140,7 @@ void ExpUnqualifiedLookup::PerScopeLookupState::dump() const {
2138
2140
break ;
2139
2141
}
2140
2142
e << " dc: " ;
2141
- nextDC ->dumpContext ();
2143
+ childOfNextDC ->dumpContext ();
2142
2144
if (placesToSearch.hasValue ())
2143
2145
placesToSearch.getValue ().dump ();
2144
2146
}
0 commit comments