FIR: Extract FirScope.toScopeTowerLevel

This commit is contained in:
Denis Zharkov
2020-03-25 11:50:54 +03:00
parent bea9d20557
commit e2ca1f2af4
@@ -79,6 +79,15 @@ class FirTowerResolver(
return implicitReceivers return implicitReceivers
} }
private fun FirScope.toScopeTowerLevel(
extensionReceiver: ReceiverValue? = null,
extensionsOnly: Boolean = false,
noInnerConstructors: Boolean = false
): ScopeTowerLevel = ScopeTowerLevel(
session, components, this,
extensionReceiver, extensionsOnly, noInnerConstructors
)
private suspend fun processQualifierScopes( private suspend fun processQualifierScopes(
manager: TowerResolveManager, manager: TowerResolveManager,
info: CallInfo, qualifierReceiver: QualifierReceiver? info: CallInfo, qualifierReceiver: QualifierReceiver?
@@ -86,7 +95,7 @@ class FirTowerResolver(
if (qualifierReceiver == null) return if (qualifierReceiver == null) return
for ((depth, qualifierScope) in qualifierReceiver.callableScopes().withIndex()) { for ((depth, qualifierScope) in qualifierReceiver.callableScopes().withIndex()) {
manager.processLevel( manager.processLevel(
ScopeTowerLevel(session, components, qualifierScope, noInnerConstructors = true), qualifierScope.toScopeTowerLevel(noInnerConstructors = true),
info.noStubReceiver(), TowerGroup.Qualifier(depth) info.noStubReceiver(), TowerGroup.Qualifier(depth)
) )
} }
@@ -103,7 +112,7 @@ class FirTowerResolver(
) return ) return
val scope = qualifierReceiver.classifierScope() ?: return val scope = qualifierReceiver.classifierScope() ?: return
manager.processLevel( manager.processLevel(
ScopeTowerLevel(session, components, scope, noInnerConstructors = true), info.noStubReceiver(), scope.toScopeTowerLevel(noInnerConstructors = true), info.noStubReceiver(),
if (prioritized) TowerGroup.ClassifierPrioritized else TowerGroup.Classifier if (prioritized) TowerGroup.ClassifierPrioritized else TowerGroup.Classifier
) )
} }
@@ -170,9 +179,10 @@ class FirTowerResolver(
for ((implicitReceiverValue, usableAsValue, depth) in implicitReceivers) { for ((implicitReceiverValue, usableAsValue, depth) in implicitReceivers) {
if (!usableAsValue) continue if (!usableAsValue) continue
manager.processLevel( manager.processLevel(
ScopeTowerLevel( topLevelScope.toScopeTowerLevel(
session, components, topLevelScope, extensionReceiver = implicitReceiverValue, extensionsOnly = true extensionReceiver = implicitReceiverValue, extensionsOnly = true
), info, TowerGroup.TopPrioritized(index).Implicit(depth) ),
info, TowerGroup.TopPrioritized(index).Implicit(depth)
) )
} }
} }
@@ -185,7 +195,7 @@ class FirTowerResolver(
) { ) {
for ((index, localScope) in localScopes.withIndex()) { for ((index, localScope) in localScopes.withIndex()) {
val result = manager.processLevel( val result = manager.processLevel(
ScopeTowerLevel(session, components, localScope), info, TowerGroup.Local(index) localScope.toScopeTowerLevel(), info, TowerGroup.Local(index)
) )
if (result != ProcessorAction.NONE) { if (result != ProcessorAction.NONE) {
nonEmptyLocalScopes += localScope nonEmptyLocalScopes += localScope
@@ -220,11 +230,8 @@ class FirTowerResolver(
val scope = implicitReceiverValue.scope(session, components.scopeSession) val scope = implicitReceiverValue.scope(session, components.scopeSession)
if (scope != null) { if (scope != null) {
manager.processLevel( manager.processLevel(
ScopeTowerLevel( FirStaticScope(scope).toScopeTowerLevel(),
session, info, parentGroup.Static(depth)
components,
FirStaticScope(scope)
), info, parentGroup.Static(depth)
) )
} }
} }
@@ -253,9 +260,8 @@ class FirTowerResolver(
for ((localIndex, localScope) in nonEmptyLocalScopes.withIndex()) { for ((localIndex, localScope) in nonEmptyLocalScopes.withIndex()) {
manager.processLevel( manager.processLevel(
ScopeTowerLevel( localScope.toScopeTowerLevel(extensionReceiver = receiver),
session, components, localScope, extensionReceiver = receiver info, parentGroup.Local(localIndex)
), info, parentGroup.Local(localIndex)
) )
} }
@@ -276,10 +282,8 @@ class FirTowerResolver(
for ((topIndex, topLevelScope) in topLevelScopes.withIndex()) { for ((topIndex, topLevelScope) in topLevelScopes.withIndex()) {
if (topLevelScope in emptyTopLevelScopes) continue if (topLevelScope in emptyTopLevelScopes) continue
val result = manager.processLevel( val result = manager.processLevel(
ScopeTowerLevel( topLevelScope.toScopeTowerLevel(extensionReceiver = receiver),
session, info, parentGroup.Top(topIndex)
components, topLevelScope, extensionReceiver = receiver
), info, parentGroup.Top(topIndex)
) )
if (result == ProcessorAction.NONE) { if (result == ProcessorAction.NONE) {
emptyTopLevelScopes += topLevelScope emptyTopLevelScopes += topLevelScope
@@ -297,7 +301,7 @@ class FirTowerResolver(
// because we do not search for objects if we have extension receiver // because we do not search for objects if we have extension receiver
if (info.callKind != CallKind.VariableAccess && topLevelScope in emptyTopLevelScopes) continue if (info.callKind != CallKind.VariableAccess && topLevelScope in emptyTopLevelScopes) continue
manager.processLevel( manager.processLevel(
ScopeTowerLevel(session, components, topLevelScope), info, TowerGroup.Top(index) topLevelScope.toScopeTowerLevel(), info, TowerGroup.Top(index)
) )
} }
} }
@@ -315,9 +319,10 @@ class FirTowerResolver(
// Special case (extension hides member) // Special case (extension hides member)
for ((index, topLevelScope) in topLevelScopes.withIndex()) { for ((index, topLevelScope) in topLevelScopes.withIndex()) {
manager.processLevel( manager.processLevel(
ScopeTowerLevel( topLevelScope.toScopeTowerLevel(
session, components, topLevelScope, extensionReceiver = explicitReceiverValue, extensionsOnly = true extensionReceiver = explicitReceiverValue, extensionsOnly = true
), info, TowerGroup.TopPrioritized(index), ExplicitReceiverKind.EXTENSION_RECEIVER ),
info, TowerGroup.TopPrioritized(index), ExplicitReceiverKind.EXTENSION_RECEIVER
) )
} }
} }
@@ -338,15 +343,14 @@ class FirTowerResolver(
val nonEmptyLocalScopes = mutableListOf<FirLocalScope>() val nonEmptyLocalScopes = mutableListOf<FirLocalScope>()
for ((index, localScope) in localScopes.withIndex()) { for ((index, localScope) in localScopes.withIndex()) {
val result = manager.processLevel( val result = manager.processLevel(
ScopeTowerLevel( localScope.toScopeTowerLevel(extensionReceiver = explicitReceiverValue),
session, components, localScope, extensionReceiver = explicitReceiverValue info, TowerGroup.Local(index), ExplicitReceiverKind.EXTENSION_RECEIVER
), info, TowerGroup.Local(index), ExplicitReceiverKind.EXTENSION_RECEIVER
) )
if (result != ProcessorAction.NONE) { if (result != ProcessorAction.NONE) {
nonEmptyLocalScopes += localScope nonEmptyLocalScopes += localScope
} }
manager.processLevelForPropertyWithInvoke( manager.processLevelForPropertyWithInvoke(
ScopeTowerLevel(session, components, localScope), info, TowerGroup.Local(index) localScope.toScopeTowerLevel(), info, TowerGroup.Local(index)
) )
} }
for ((implicitReceiverValue, usableAsValue, depth) in implicitReceivers) { for ((implicitReceiverValue, usableAsValue, depth) in implicitReceivers) {
@@ -368,9 +372,8 @@ class FirTowerResolver(
) )
for ((localIndex, localScope) in nonEmptyLocalScopes.withIndex()) { for ((localIndex, localScope) in nonEmptyLocalScopes.withIndex()) {
manager.processLevelForPropertyWithInvoke( manager.processLevelForPropertyWithInvoke(
ScopeTowerLevel( localScope.toScopeTowerLevel(extensionReceiver = implicitReceiverValue),
session, components, localScope, extensionReceiver = implicitReceiverValue info, parentGroup.Local(localIndex)
), info, parentGroup.Local(localIndex)
) )
} }
for ((implicitDispatchReceiverValue, usable, dispatchDepth) in implicitReceivers) { for ((implicitDispatchReceiverValue, usable, dispatchDepth) in implicitReceivers) {
@@ -387,21 +390,19 @@ class FirTowerResolver(
} }
for ((topIndex, topLevelScope) in topLevelScopes.withIndex()) { for ((topIndex, topLevelScope) in topLevelScopes.withIndex()) {
manager.processLevelForPropertyWithInvoke( manager.processLevelForPropertyWithInvoke(
ScopeTowerLevel( topLevelScope.toScopeTowerLevel(extensionReceiver = implicitReceiverValue),
session, components, topLevelScope, extensionReceiver = implicitReceiverValue info, parentGroup.Top(topIndex)
), info, parentGroup.Top(topIndex)
) )
} }
} }
for ((index, topLevelScope) in topLevelScopes.withIndex()) { for ((index, topLevelScope) in topLevelScopes.withIndex()) {
manager.processLevel( manager.processLevel(
ScopeTowerLevel( topLevelScope.toScopeTowerLevel(extensionReceiver = explicitReceiverValue),
session, components, topLevelScope, extensionReceiver = explicitReceiverValue info, TowerGroup.Top(index), ExplicitReceiverKind.EXTENSION_RECEIVER
), info, TowerGroup.Top(index), ExplicitReceiverKind.EXTENSION_RECEIVER
) )
manager.processLevelForPropertyWithInvoke( manager.processLevelForPropertyWithInvoke(
ScopeTowerLevel(session, components, topLevelScope), info, TowerGroup.Top(index) topLevelScope.toScopeTowerLevel(), info, TowerGroup.Top(index)
) )
} }
@@ -420,9 +421,8 @@ class FirTowerResolver(
else -> null else -> null
} ?: return } ?: return
manager.processLevel( manager.processLevel(
ScopeTowerLevel( scope.toScopeTowerLevel(),
session, components, scope info, TowerGroup.Member, explicitReceiverKind = ExplicitReceiverKind.DISPATCH_RECEIVER
), info, TowerGroup.Member, explicitReceiverKind = ExplicitReceiverKind.DISPATCH_RECEIVER
) )
} }
@@ -441,9 +441,7 @@ class FirTowerResolver(
) )
for ((index, localScope) in localScopes.withIndex()) { for ((index, localScope) in localScopes.withIndex()) {
manager.processLevel( manager.processLevel(
ScopeTowerLevel( localScope.toScopeTowerLevel(extensionReceiver = invokeReceiverValue),
session, components, localScope, extensionReceiver = invokeReceiverValue
),
info, TowerGroup.Local(index), info, TowerGroup.Local(index),
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.EXTENSION_RECEIVER,
InvokeResolveMode.IMPLICIT_CALL_ON_GIVEN_RECEIVER InvokeResolveMode.IMPLICIT_CALL_ON_GIVEN_RECEIVER
@@ -465,9 +463,8 @@ class FirTowerResolver(
} }
for ((index, topLevelScope) in topLevelScopes.withIndex()) { for ((index, topLevelScope) in topLevelScopes.withIndex()) {
manager.processLevel( manager.processLevel(
ScopeTowerLevel( topLevelScope.toScopeTowerLevel(extensionReceiver = invokeReceiverValue),
session, components, topLevelScope, extensionReceiver = invokeReceiverValue info, TowerGroup.Top(index),
), info, TowerGroup.Top(index),
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.EXTENSION_RECEIVER,
InvokeResolveMode.IMPLICIT_CALL_ON_GIVEN_RECEIVER InvokeResolveMode.IMPLICIT_CALL_ON_GIVEN_RECEIVER
) )