[JS IR BE] Use symbol instead of declaration
This commit is contained in:
+9
-8
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
|||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrPropertyReferenceImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrPropertyReferenceImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||||
@@ -33,7 +34,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
val STATIC_THIS_PARAMETER = object : IrDeclarationOriginImpl("STATIC_THIS_PARAMETER") {}
|
val STATIC_THIS_PARAMETER = object : IrDeclarationOriginImpl("STATIC_THIS_PARAMETER") {}
|
||||||
|
|
||||||
class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPass {
|
class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPass {
|
||||||
private val memberMap = mutableMapOf<IrSimpleFunction, IrSimpleFunction>()
|
private val memberMap = mutableMapOf<IrSimpleFunctionSymbol, IrSimpleFunction>()
|
||||||
|
|
||||||
override fun lower(irClass: IrClass) {
|
override fun lower(irClass: IrClass) {
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPas
|
|||||||
irClass.declarations.transformFlat {
|
irClass.declarations.transformFlat {
|
||||||
when (it) {
|
when (it) {
|
||||||
is IrSimpleFunction -> transformMemberToStaticFunction(it)?.let { staticFunction ->
|
is IrSimpleFunction -> transformMemberToStaticFunction(it)?.let { staticFunction ->
|
||||||
memberMap[it] = staticFunction
|
memberMap[it.symbol] = staticFunction
|
||||||
listOf(staticFunction)
|
listOf(staticFunction)
|
||||||
}
|
}
|
||||||
is IrProperty -> listOf(it.apply {
|
is IrProperty -> listOf(it.apply {
|
||||||
@@ -56,12 +57,12 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPas
|
|||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
super.visitCall(expression)
|
super.visitCall(expression)
|
||||||
|
|
||||||
return memberMap[expression.symbol.owner]?.let {
|
return memberMap[expression.symbol]?.let {
|
||||||
transformPrivateToStaticCall(expression, it)
|
transformPrivateToStaticCall(expression, it)
|
||||||
} ?: expression
|
} ?: expression
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunctionReference(expression: IrFunctionReference) = memberMap[expression.symbol.owner]?.let {
|
override fun visitFunctionReference(expression: IrFunctionReference) = memberMap[expression.symbol]?.let {
|
||||||
transformPrivateToStaticReference(expression) {
|
transformPrivateToStaticReference(expression) {
|
||||||
IrFunctionReferenceImpl(
|
IrFunctionReferenceImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
@@ -74,7 +75,7 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPas
|
|||||||
} ?: expression
|
} ?: expression
|
||||||
|
|
||||||
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
||||||
return if (expression.getter?.owner in memberMap || expression.setter?.owner in memberMap) {
|
return if (expression.getter in memberMap || expression.setter in memberMap) {
|
||||||
transformPrivateToStaticReference(expression) {
|
transformPrivateToStaticReference(expression) {
|
||||||
IrPropertyReferenceImpl(
|
IrPropertyReferenceImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
@@ -82,8 +83,8 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPas
|
|||||||
expression.descriptor,
|
expression.descriptor,
|
||||||
expression.typeArgumentsCount,
|
expression.typeArgumentsCount,
|
||||||
expression.field,
|
expression.field,
|
||||||
memberMap[expression.getter?.owner]?.symbol ?: expression.getter,
|
memberMap[expression.getter]?.symbol ?: expression.getter,
|
||||||
memberMap[expression.setter?.owner]?.symbol ?: expression.setter,
|
memberMap[expression.setter]?.symbol ?: expression.setter,
|
||||||
expression.origin
|
expression.origin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -132,7 +133,7 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : ClassLoweringPas
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun transformAccessor(accessor: IrSimpleFunction) =
|
private fun transformAccessor(accessor: IrSimpleFunction) =
|
||||||
transformMemberToStaticFunction(accessor)?.also { memberMap[accessor] = it } ?: accessor
|
transformMemberToStaticFunction(accessor)?.also { memberMap[accessor.symbol] = it } ?: accessor
|
||||||
|
|
||||||
private fun transformMemberToStaticFunction(function: IrSimpleFunction): IrSimpleFunction? {
|
private fun transformMemberToStaticFunction(function: IrSimpleFunction): IrSimpleFunction? {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user