[FIR] Introduce FirTypeScope.processOverriddenFunctionWithDepth
This commit is contained in:
+2
-2
@@ -73,8 +73,8 @@ class JavaClassMembersEnhancementScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processOverriddenFunctions(
|
override fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
): ProcessorAction = doProcessOverriddenFunctions(functionSymbol, processor, overriddenFunctions, useSiteMemberScope)
|
): ProcessorAction = doProcessOverriddenFunctions(functionSymbol, processor, overriddenFunctions, useSiteMemberScope)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ class JvmMappedScope(
|
|||||||
// JvmMappedScope is basically used as declaration scope but it's being wrapped into substitution scopes where
|
// JvmMappedScope is basically used as declaration scope but it's being wrapped into substitution scopes where
|
||||||
// a use-site (FirOverrideAwareScope) is expected
|
// a use-site (FirOverrideAwareScope) is expected
|
||||||
// So, we put here a stub implementation
|
// So, we put here a stub implementation
|
||||||
override fun processOverriddenFunctions(
|
override fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
) = ProcessorAction.NONE
|
) = ProcessorAction.NONE
|
||||||
|
|
||||||
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
|
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ data class ConeSubstitutionScopeKey(
|
|||||||
val classId: ClassId?, val isFromExpectClass: Boolean, val substitutor: ConeSubstitutor
|
val classId: ClassId?, val isFromExpectClass: Boolean, val substitutor: ConeSubstitutor
|
||||||
) : ScopeSessionKey<FirClass<*>, FirClassSubstitutionScope>()
|
) : ScopeSessionKey<FirClass<*>, FirClassSubstitutionScope>()
|
||||||
|
|
||||||
fun FirClass<*>.unsubstitutedScope(useSiteSession: FirSession, scopeSession: ScopeSession): FirScope {
|
fun FirClass<*>.unsubstitutedScope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope {
|
||||||
return scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession)
|
return scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -137,9 +137,9 @@ abstract class AbstractFirUseSiteMemberScope(
|
|||||||
isVararg = parameter.isVararg
|
isVararg = parameter.isVararg
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processOverriddenFunctions(
|
override fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
): ProcessorAction = doProcessOverriddenFunctions(functionSymbol, processor, directOverridden, superTypesScope)
|
): ProcessorAction = doProcessOverriddenFunctions(functionSymbol, processor, directOverridden, superTypesScope)
|
||||||
|
|
||||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||||
|
|||||||
+9
-3
@@ -64,12 +64,18 @@ class FirClassSubstitutionScope(
|
|||||||
return super.processFunctionsByName(name, processor)
|
return super.processFunctionsByName(name, processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processOverriddenFunctions(
|
override fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
): ProcessorAction {
|
): ProcessorAction {
|
||||||
val unwrapped = functionSymbol.overriddenSymbol as FirFunctionSymbol<*>? ?: functionSymbol
|
val unwrapped = functionSymbol.overriddenSymbol as FirFunctionSymbol<*>? ?: functionSymbol
|
||||||
return useSiteMemberScope.processOverriddenFunctions(unwrapped, processor)
|
val overriddenDepth = if (unwrapped != functionSymbol) 1 else 0
|
||||||
|
if (!processor(unwrapped, overriddenDepth)) {
|
||||||
|
return ProcessorAction.STOP
|
||||||
|
}
|
||||||
|
return useSiteMemberScope.processOverriddenFunctionsWithDepth(unwrapped) { symbol, depth ->
|
||||||
|
processor(symbol, depth + overriddenDepth)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
|
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
|
||||||
|
|||||||
+2
-2
@@ -96,9 +96,9 @@ class FirIntegerLiteralTypeScope(private val session: FirSession, val isUnsigned
|
|||||||
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
|
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processOverriddenFunctions(
|
override fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
): ProcessorAction = ProcessorAction.NEXT
|
): ProcessorAction = ProcessorAction.NEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -232,9 +232,9 @@ class FirTypeIntersectionScope private constructor(
|
|||||||
super.processClassifiersByNameWithSubstitution(name, processor)
|
super.processClassifiersByNameWithSubstitution(name, processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processOverriddenFunctions(
|
override fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
): ProcessorAction {
|
): ProcessorAction {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val directOverriddenSymbols =
|
val directOverriddenSymbols =
|
||||||
@@ -244,8 +244,11 @@ class FirTypeIntersectionScope private constructor(
|
|||||||
for (directOverridden in directOverriddenSymbols) {
|
for (directOverridden in directOverriddenSymbols) {
|
||||||
// TODO: Preserve the scope where directOverridden came from
|
// TODO: Preserve the scope where directOverridden came from
|
||||||
for (scope in scopes) {
|
for (scope in scopes) {
|
||||||
if (!processor(directOverridden)) return ProcessorAction.STOP
|
if (!processor(directOverridden, 0)) return ProcessorAction.STOP
|
||||||
if (!scope.processOverriddenFunctions(directOverridden, processor)) return ProcessorAction.STOP
|
if (!scope.processOverriddenFunctionsWithDepth(directOverridden) { symbol, depth ->
|
||||||
|
processor(symbol, depth)
|
||||||
|
}
|
||||||
|
) return ProcessorAction.STOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.scopes
|
package org.jetbrains.kotlin.fir.scopes
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
|
|
||||||
abstract class FirTypeScope : FirScope() {
|
abstract class FirTypeScope : FirScope() {
|
||||||
// Currently, this function has very weak guarantees
|
// Currently, this function has very weak guarantees
|
||||||
@@ -14,33 +15,55 @@ abstract class FirTypeScope : FirScope() {
|
|||||||
// - It doesn't guarantee any specific order in which overridden tree will be traversed
|
// - It doesn't guarantee any specific order in which overridden tree will be traversed
|
||||||
// But if the scope instance is the same as the one from which the symbol was originated, this function will enumarate all members
|
// But if the scope instance is the same as the one from which the symbol was originated, this function will enumarate all members
|
||||||
// of the overridden tree
|
// of the overridden tree
|
||||||
abstract fun processOverriddenFunctions(
|
abstract fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
): ProcessorAction
|
): ProcessorAction
|
||||||
|
|
||||||
|
inline fun processOverriddenFunctions(
|
||||||
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
|
crossinline processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
||||||
|
): ProcessorAction = processOverriddenFunctionsWithDepth(functionSymbol) { symbol, _ ->
|
||||||
|
processor(symbol)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun processDirectlyOverriddenFunctions(
|
||||||
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
|
crossinline processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
||||||
|
): ProcessorAction = processOverriddenFunctionsWithDepth(functionSymbol) { symbol, depth ->
|
||||||
|
if (depth == 1) {
|
||||||
|
processor(symbol)
|
||||||
|
} else {
|
||||||
|
ProcessorAction.NEXT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This is just a helper for a common implementation
|
// This is just a helper for a common implementation
|
||||||
protected fun doProcessOverriddenFunctions(
|
protected fun doProcessOverriddenFunctions(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction,
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction,
|
||||||
directOverriddenMap: Map<FirFunctionSymbol<*>, Collection<FirFunctionSymbol<*>>>,
|
directOverriddenMap: Map<FirFunctionSymbol<*>, Collection<FirFunctionSymbol<*>>>,
|
||||||
baseScope: FirTypeScope
|
baseScope: FirTypeScope
|
||||||
): ProcessorAction {
|
): ProcessorAction {
|
||||||
val directOverridden =
|
val directOverridden =
|
||||||
directOverriddenMap[functionSymbol] ?: return baseScope.processOverriddenFunctions(functionSymbol, processor)
|
directOverriddenMap[functionSymbol] ?: return baseScope.processOverriddenFunctionsWithDepth(functionSymbol, processor)
|
||||||
|
|
||||||
for (overridden in directOverridden) {
|
for (overridden in directOverridden) {
|
||||||
if (!processor(overridden)) return ProcessorAction.STOP
|
val overriddenDepth = if (overridden is FirNamedFunctionSymbol && overridden.isFakeOverride) 0 else 1
|
||||||
if (!baseScope.processOverriddenFunctions(overridden, processor)) return ProcessorAction.STOP
|
if (!processor(overridden, overriddenDepth)) return ProcessorAction.STOP
|
||||||
|
if (!baseScope.processOverriddenFunctionsWithDepth(overridden) { symbol, depth ->
|
||||||
|
processor(symbol, depth + overriddenDepth)
|
||||||
|
}
|
||||||
|
) return ProcessorAction.STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseScope.processOverriddenFunctions(functionSymbol, processor)
|
return baseScope.processOverriddenFunctionsWithDepth(functionSymbol, processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
object Empty : FirTypeScope() {
|
object Empty : FirTypeScope() {
|
||||||
override fun processOverriddenFunctions(
|
override fun processOverriddenFunctionsWithDepth(
|
||||||
functionSymbol: FirFunctionSymbol<*>,
|
functionSymbol: FirFunctionSymbol<*>,
|
||||||
processor: (FirFunctionSymbol<*>) -> ProcessorAction
|
processor: (FirFunctionSymbol<*>, Int) -> ProcessorAction
|
||||||
): ProcessorAction = ProcessorAction.NEXT
|
): ProcessorAction = ProcessorAction.NEXT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user