Skip to content

Commit e026700

Browse files
committed
AST: Refactor unqualified lookup a little bit
1 parent a628b9c commit e026700

File tree

3 files changed

+86
-164
lines changed

3 files changed

+86
-164
lines changed

include/swift/AST/ASTScope.h

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -482,45 +482,33 @@ class Portion : public ASTAllocated<ASTScopeImpl> {
482482

483483
virtual NullablePtr<ASTScopeImpl>
484484
insertionPointForDeferredExpansion(IterableTypeScope *) const = 0;
485-
};
486-
487-
// For the whole Decl scope of a GenericType or an Extension
488-
class GenericTypeOrExtensionWholePortion final : public Portion {
489-
public:
490-
GenericTypeOrExtensionWholePortion() : Portion("Decl") {}
491-
virtual ~GenericTypeOrExtensionWholePortion() {}
492-
493-
// Just for TypeAlias
494-
ASTScopeImpl *expandScope(GenericTypeOrExtensionScope *,
495-
ScopeCreator &) const override;
485+
};
496486

497-
SourceRange getChildlessSourceRangeOf(const GenericTypeOrExtensionScope *,
498-
bool omitAssertions) const override;
487+
// For the whole Decl scope of a GenericType or an Extension
488+
class GenericTypeOrExtensionWholePortion final : public Portion {
489+
public:
490+
GenericTypeOrExtensionWholePortion() : Portion("Decl") {}
491+
virtual ~GenericTypeOrExtensionWholePortion() {}
499492

500-
NullablePtr<const ASTScopeImpl>
501-
getLookupLimitFor(const GenericTypeOrExtensionScope *) const override;
493+
// Just for TypeAlias
494+
ASTScopeImpl *expandScope(GenericTypeOrExtensionScope *,
495+
ScopeCreator &) const override;
502496

503-
NullablePtr<ASTScopeImpl>
504-
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
505-
};
497+
SourceRange getChildlessSourceRangeOf(const GenericTypeOrExtensionScope *,
498+
bool omitAssertions) const override;
506499

507-
/// GenericTypeOrExtension = GenericType or Extension
508-
class GenericTypeOrExtensionWhereOrBodyPortion : public Portion {
509-
public:
510-
GenericTypeOrExtensionWhereOrBodyPortion(const char *n) : Portion(n) {}
511-
virtual ~GenericTypeOrExtensionWhereOrBodyPortion() {}
500+
NullablePtr<const ASTScopeImpl>
501+
getLookupLimitFor(const GenericTypeOrExtensionScope *) const override;
512502

513-
bool lookupMembersOf(const GenericTypeOrExtensionScope *scope,
514-
ASTScopeImpl::DeclConsumer consumer) const override;
503+
NullablePtr<ASTScopeImpl>
504+
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
515505
};
516506

517507
/// Behavior specific to representing the trailing where clause of a
518508
/// GenericTypeDecl or ExtensionDecl scope.
519-
class GenericTypeOrExtensionWherePortion final
520-
: public GenericTypeOrExtensionWhereOrBodyPortion {
509+
class GenericTypeOrExtensionWherePortion final : public Portion {
521510
public:
522-
GenericTypeOrExtensionWherePortion()
523-
: GenericTypeOrExtensionWhereOrBodyPortion("Where") {}
511+
GenericTypeOrExtensionWherePortion() : Portion("Where") {}
524512

525513
bool lookupMembersOf(const GenericTypeOrExtensionScope *scope,
526514
ASTScopeImpl::DeclConsumer consumer) const override;
@@ -537,11 +525,12 @@ class GenericTypeOrExtensionWherePortion final
537525

538526
/// Behavior specific to representing the Body of a NominalTypeDecl or
539527
/// ExtensionDecl scope
540-
class IterableTypeBodyPortion final
541-
: public GenericTypeOrExtensionWhereOrBodyPortion {
528+
class IterableTypeBodyPortion final : public Portion {
542529
public:
543-
IterableTypeBodyPortion()
544-
: GenericTypeOrExtensionWhereOrBodyPortion("Body") {}
530+
IterableTypeBodyPortion() : Portion("Body") {}
531+
532+
bool lookupMembersOf(const GenericTypeOrExtensionScope *scope,
533+
ASTScopeImpl::DeclConsumer consumer) const override;
545534

546535
ASTScopeImpl *expandScope(GenericTypeOrExtensionScope *,
547536
ScopeCreator &) const override;

lib/AST/ASTScopeLookup.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,24 @@ bool Portion::lookupMembersOf(const GenericTypeOrExtensionScope *,
274274
return false;
275275
}
276276

277-
bool GenericTypeOrExtensionWhereOrBodyPortion::lookupMembersOf(
277+
bool GenericTypeOrExtensionWherePortion::lookupMembersOf(
278278
const GenericTypeOrExtensionScope *scope,
279279
ASTScopeImpl::DeclConsumer consumer) const {
280280
if (scope->getCorrespondingNominalTypeDecl().isNull())
281281
return false;
282+
283+
if (!scope->areMembersVisibleFromWhereClause())
284+
return false;
285+
282286
return consumer.lookInMembers(scope->getGenericContext());
283287
}
284288

285-
bool GenericTypeOrExtensionWherePortion::lookupMembersOf(
289+
bool IterableTypeBodyPortion::lookupMembersOf(
286290
const GenericTypeOrExtensionScope *scope,
287291
ASTScopeImpl::DeclConsumer consumer) const {
288-
if (!scope->areMembersVisibleFromWhereClause())
292+
if (scope->getCorrespondingNominalTypeDecl().isNull())
289293
return false;
290-
291-
return GenericTypeOrExtensionWhereOrBodyPortion::lookupMembersOf(
292-
scope, consumer);
294+
return consumer.lookInMembers(scope->getGenericContext());
293295
}
294296

295297
bool GenericTypeOrExtensionScope::areMembersVisibleFromWhereClause() const {

0 commit comments

Comments
 (0)