FIR2IR: Move util methods closer to the single usage
This commit is contained in:
committed by
TeamCityServer
parent
9ef0909e39
commit
082dc3332e
+35
-8
@@ -5,17 +5,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.backend.generators
|
package org.jetbrains.kotlin.fir.backend.generators
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
import org.jetbrains.kotlin.fir.backend.*
|
||||||
import org.jetbrains.kotlin.fir.backend.generateOverriddenAccessorSymbols
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.backend.generateOverriddenFunctionSymbols
|
import org.jetbrains.kotlin.fir.isIntersectionOverride
|
||||||
import org.jetbrains.kotlin.fir.backend.generateOverriddenPropertySymbols
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirField
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
|
||||||
import org.jetbrains.kotlin.fir.isJavaDefault
|
import org.jetbrains.kotlin.fir.isJavaDefault
|
||||||
import org.jetbrains.kotlin.fir.scopes.*
|
import org.jetbrains.kotlin.fir.scopes.*
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.unwrapDelegateTarget
|
import org.jetbrains.kotlin.fir.scopes.impl.unwrapDelegateTarget
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
|
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
|
||||||
@@ -202,3 +200,32 @@ internal class DelegatedMemberGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun <S : FirCallableSymbol<D>, D : FirCallableMemberDeclaration> S.unwrapDelegateTarget(
|
||||||
|
subClassLookupTag: ConeClassLikeLookupTag,
|
||||||
|
directOverridden: S.() -> List<S>,
|
||||||
|
firField: FirField,
|
||||||
|
firSubClass: FirClass,
|
||||||
|
): D? {
|
||||||
|
firSubClass.hashCode()
|
||||||
|
val unwrappedIntersectionSymbol = this.unwrapIntersectionOverride(directOverridden) ?: return null
|
||||||
|
|
||||||
|
val callable = unwrappedIntersectionSymbol.fir as? D ?: return null
|
||||||
|
|
||||||
|
val delegatedWrapperData = callable.delegatedWrapperData ?: return null
|
||||||
|
if (delegatedWrapperData.containingClass != subClassLookupTag) return null
|
||||||
|
if (delegatedWrapperData.delegateField != firField) return null
|
||||||
|
|
||||||
|
val wrapped = delegatedWrapperData.wrapped as? D ?: return null
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val wrappedSymbol = wrapped.symbol as? S ?: return null
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return wrappedSymbol.unwrapCallRepresentative().fir as D
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <S : FirCallableSymbol<*>> S.unwrapIntersectionOverride(directOverridden: S.() -> List<S>): S? {
|
||||||
|
if (this.fir.isIntersectionOverride) return directOverridden().firstOrNull { it.fir.delegatedWrapperData != null }
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|||||||
-31
@@ -12,8 +12,6 @@ import org.jetbrains.kotlin.fir.declarations.*
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||||
import org.jetbrains.kotlin.fir.isIntersectionOverride
|
import org.jetbrains.kotlin.fir.isIntersectionOverride
|
||||||
import org.jetbrains.kotlin.fir.isSubstitutionOverride
|
|
||||||
import org.jetbrains.kotlin.fir.originalForSubstitutionOverride
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||||
import org.jetbrains.kotlin.fir.scopes.*
|
import org.jetbrains.kotlin.fir.scopes.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||||
@@ -170,35 +168,6 @@ class DelegatedWrapperData<D : FirCallableDeclaration>(
|
|||||||
var <D : FirCallableDeclaration>
|
var <D : FirCallableDeclaration>
|
||||||
D.delegatedWrapperData: DelegatedWrapperData<D>? by FirDeclarationDataRegistry.data(DelegatedWrapperDataKey)
|
D.delegatedWrapperData: DelegatedWrapperData<D>? by FirDeclarationDataRegistry.data(DelegatedWrapperDataKey)
|
||||||
|
|
||||||
inline fun <reified S : FirCallableSymbol<D>, reified D : FirCallableMemberDeclaration> S.unwrapDelegateTarget(
|
|
||||||
subClassLookupTag: ConeClassLikeLookupTag,
|
|
||||||
noinline directOverridden: S.() -> List<S>,
|
|
||||||
firField: FirField,
|
|
||||||
firSubClass: FirClass,
|
|
||||||
): D? {
|
|
||||||
val unwrappedIntersectionSymbol = this.unwrapIntersectionOverride(directOverridden) ?: return null
|
|
||||||
|
|
||||||
val callable = unwrappedIntersectionSymbol.fir as? D ?: return null
|
|
||||||
|
|
||||||
val delegatedWrapperData = callable.delegatedWrapperData ?: return null
|
|
||||||
if (delegatedWrapperData.containingClass != subClassLookupTag) return null
|
|
||||||
if (delegatedWrapperData.delegateField != firField) return null
|
|
||||||
|
|
||||||
val wrapped = delegatedWrapperData.wrapped as? D ?: return null
|
|
||||||
val wrappedSymbol = wrapped.symbol as? S ?: return null
|
|
||||||
|
|
||||||
return when {
|
|
||||||
wrappedSymbol.fir.isSubstitutionOverride &&
|
|
||||||
(wrappedSymbol.fir.dispatchReceiverType as? ConeClassLikeType)?.lookupTag == firSubClass.symbol.toLookupTag() ->
|
|
||||||
wrapped.originalForSubstitutionOverride
|
|
||||||
else -> wrapped
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <S : FirCallableSymbol<*>> S.unwrapIntersectionOverride(directOverridden: S.() -> List<S>): S? {
|
|
||||||
if (this.fir.isIntersectionOverride) return directOverridden().firstOrNull { it.fir.delegatedWrapperData != null }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
// From the definition of function interfaces in the Java specification (pt. 9.8):
|
// From the definition of function interfaces in the Java specification (pt. 9.8):
|
||||||
// "methods that are members of I that do not have the same signature as any public instance method of the class Object"
|
// "methods that are members of I that do not have the same signature as any public instance method of the class Object"
|
||||||
|
|||||||
Reference in New Issue
Block a user