Skip to content

Commit 19b7801

Browse files
committed
Minor rearrangement.
1 parent d45ab0b commit 19b7801

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,12 @@ class UnqualifiedLookupFactory {
145145

146146
private:
147147
struct PlacesToSearch {
148-
// TODO: constify members?
149-
/// The context in which the places where found.
150-
DeclContext *fromWhence;
148+
/// The context in which the places were found.
149+
DeclContext *const fromWhence;
151150
/// Nontypes are formally members of the base type
152-
DeclContext *whereNonTypesAreMembers;
151+
DeclContext *const whereNonTypesAreMembers;
153152
/// Types are formally members of the metatype
154-
DeclContext *whereTypesAreMembers;
153+
DeclContext *const whereTypesAreMembers;
155154
/// Places to search for the lookup.
156155
SmallVector<NominalTypeDecl *, 2> places;
157156

@@ -759,7 +758,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
759758
false,
760759
parent,
761760
PlacesToSearch(parent, PBI, parent, parent),
762-
resolveIsCascadingUse(PBI,isCascadingUse,
761+
resolveIsCascadingUse(PBI, isCascadingUse,
763762
/*onlyCareAboutFunctionBody=*/false)};
764763
// clang-format no
765764
}
@@ -802,6 +801,7 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
802801

803802
namelookup::FindLocalVal localVal(SM, Loc, Consumer);
804803
localVal.visit(AFD->getBody());
804+
805805
setIndexOfFirstOuterResultIfNotSetAlready();
806806
if (isLookupDoneWithoutIncludingOuterResults())
807807
return None;
@@ -813,48 +813,46 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
813813
if (isLookupDoneWithoutIncludingOuterResults())
814814
return None;
815815
}
816+
// TODO: is isOutsideBodyOfFunction better than the disjunction below?
816817
const bool returnValueForIsCascadingUse =
817818
AFD->isCascadingContextForLookup(false) &&
818819
(isCascadingUse.hasValue()
819820
? isCascadingUse.getValue()
820821
: !Loc.isValid() || !AFD->getBody() ||
821822
!SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc));
822823

823-
if (AFD->getDeclContext()->isTypeContext()) {
824-
DeclContext *fnDeclContext = AFD->getDeclContext();
825-
DeclContext *fnParent = AFD->getParent();
826-
addGenericParametersForFunction(AFD);
827-
setIndexOfFirstOuterResultIfNotSetAlready();
828-
if (isLookupDoneWithoutIncludingOuterResults())
829-
return None;
830-
// clang-format off
831-
return PerDeclInfo{
832-
false,
833-
fnParent,
834-
PlacesToSearch(
835-
fnParent,
836-
// If we're not in the body of the function (for example, we
837-
// might be type checking a default argument expression and
838-
// performing name lookup from there), the base declaration
839-
// is the nominal type, not 'self'.
840-
isOutsideBodyOfFunction(AFD) ? fnDeclContext : AFD,
841-
fnDeclContext,
842-
AFD->getDeclContext()),
843-
returnValueForIsCascadingUse};
844-
// clang-format on
845-
}
846824
// Look in the generic parameters after checking our local declaration.
847825
addGenericParametersForFunction(AFD);
848826
setIndexOfFirstOuterResultIfNotSetAlready();
849827
if (isLookupDoneWithoutIncludingOuterResults())
850828
return None;
829+
830+
if (!AFD->getDeclContext()->isTypeContext())
831+
// clang-format off
832+
return PerDeclInfo{
833+
false,
834+
AFD,
835+
None,
836+
returnValueForIsCascadingUse};
837+
// clang-format on
838+
839+
DeclContext *const fnDeclContext = AFD->getDeclContext();
840+
// If we're not in the body of the function (for example, we
841+
// might be type checking a default argument expression and
842+
// performing name lookup from there), the base declaration
843+
// is the nominal type, not 'self'.
844+
DeclContext *const BaseDC = isOutsideBodyOfFunction(AFD) ? fnDeclContext : AFD;
845+
DeclContext *const fnParent = AFD->getParent();
851846
// clang-format off
852847
return PerDeclInfo{
853848
false,
854-
AFD,
855-
None,
849+
fnParent,
850+
PlacesToSearch(fnParent,
851+
BaseDC,
852+
fnDeclContext,
853+
fnDeclContext),
856854
returnValueForIsCascadingUse};
857-
// clang-format on
855+
// clang-format on
858856
}
859857

860858
Optional<UnqualifiedLookupFactory::PerDeclInfo>

0 commit comments

Comments
 (0)