Migrate DescriptorsFactory.getInnerClassConstructorWithOuterThisParameter() API to symbols
This commit is contained in:
+2
-2
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.common.descriptors
|
package org.jetbrains.kotlin.backend.common.descriptors
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
||||||
@@ -15,6 +15,6 @@ import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
|||||||
interface DescriptorsFactory {
|
interface DescriptorsFactory {
|
||||||
fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol
|
fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol
|
||||||
fun getOuterThisFieldSymbol(innerClass: IrClass): IrFieldSymbol
|
fun getOuterThisFieldSymbol(innerClass: IrClass): IrFieldSymbol
|
||||||
fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: ClassConstructorDescriptor): IrConstructorSymbol
|
fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol
|
||||||
fun getSymbolForObjectInstance(singleton: IrClassSymbol): IrFieldSymbol
|
fun getSymbolForObjectInstance(singleton: IrClassSymbol): IrFieldSymbol
|
||||||
}
|
}
|
||||||
+10
-10
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.common.lower
|
|||||||
import org.jetbrains.kotlin.backend.common.BackendContext
|
import org.jetbrains.kotlin.backend.common.BackendContext
|
||||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
|
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
|
||||||
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueDescriptor
|
||||||
@@ -19,6 +18,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.createParameterDeclarations
|
import org.jetbrains.kotlin.ir.util.createParameterDeclarations
|
||||||
import org.jetbrains.kotlin.ir.util.dump
|
import org.jetbrains.kotlin.ir.util.dump
|
||||||
@@ -90,11 +90,10 @@ class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun lowerConstructor(irConstructor: IrConstructor): IrConstructor {
|
private fun lowerConstructor(irConstructor: IrConstructor): IrConstructor {
|
||||||
val oldDescriptor = irConstructor.descriptor
|
|
||||||
val startOffset = irConstructor.startOffset
|
val startOffset = irConstructor.startOffset
|
||||||
val endOffset = irConstructor.endOffset
|
val endOffset = irConstructor.endOffset
|
||||||
|
|
||||||
val newSymbol = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(oldDescriptor)
|
val newSymbol = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(irConstructor)
|
||||||
val loweredConstructor = IrConstructorImpl(
|
val loweredConstructor = IrConstructorImpl(
|
||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
irConstructor.origin, // TODO special origin for lowered inner class constructors?
|
irConstructor.origin, // TODO special origin for lowered inner class constructors?
|
||||||
@@ -104,7 +103,7 @@ class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass {
|
|||||||
loweredConstructor.createParameterDeclarations()
|
loweredConstructor.createParameterDeclarations()
|
||||||
val outerThisValueParameter = loweredConstructor.valueParameters[0].symbol
|
val outerThisValueParameter = loweredConstructor.valueParameters[0].symbol
|
||||||
|
|
||||||
oldDescriptor.valueParameters.forEach { oldValueParameter ->
|
irConstructor.descriptor.valueParameters.forEach { oldValueParameter ->
|
||||||
oldConstructorParameterToNew[oldValueParameter] = loweredConstructor.valueParameters[oldValueParameter.index + 1]
|
oldConstructorParameterToNew[oldValueParameter] = loweredConstructor.valueParameters[oldValueParameter.index + 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,10 +200,11 @@ class InnerClassConstructorCallsLowering(val context: BackendContext) : BodyLowe
|
|||||||
expression.transformChildrenVoid(this)
|
expression.transformChildrenVoid(this)
|
||||||
|
|
||||||
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
||||||
val callee = expression.descriptor as? ClassConstructorDescriptor ?: return expression
|
val callee = expression.symbol as? IrConstructorSymbol ?: return expression
|
||||||
if (!callee.constructedClass.isInner) return expression
|
val parent = callee.owner.parent as? IrClass ?: return expression
|
||||||
|
if (!parent.descriptor.isInner) return expression
|
||||||
|
|
||||||
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(callee)
|
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(callee.owner)
|
||||||
val newCall = IrCallImpl(
|
val newCall = IrCallImpl(
|
||||||
expression.startOffset, expression.endOffset, newCallee, newCallee.descriptor,
|
expression.startOffset, expression.endOffset, newCallee, newCallee.descriptor,
|
||||||
null, // TODO type arguments map
|
null, // TODO type arguments map
|
||||||
@@ -223,10 +223,10 @@ class InnerClassConstructorCallsLowering(val context: BackendContext) : BodyLowe
|
|||||||
expression.transformChildrenVoid(this)
|
expression.transformChildrenVoid(this)
|
||||||
|
|
||||||
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
||||||
val callee = expression.descriptor
|
val callee = expression.symbol
|
||||||
if (!callee.constructedClass.isInner) return expression
|
if (!callee.descriptor.containingDeclaration.isInner) return expression
|
||||||
|
|
||||||
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(callee)
|
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(callee.owner)
|
||||||
val newCall = IrDelegatingConstructorCallImpl(
|
val newCall = IrDelegatingConstructorCallImpl(
|
||||||
expression.startOffset, expression.endOffset, newCallee, newCallee.descriptor,
|
expression.startOffset, expression.endOffset, newCallee, newCallee.descriptor,
|
||||||
null // TODO type arguments map
|
null // TODO type arguments map
|
||||||
|
|||||||
+8
-6
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
@@ -38,7 +39,7 @@ class JsDescriptorsFactory(
|
|||||||
) : DescriptorsFactory {
|
) : DescriptorsFactory {
|
||||||
private val singletonFieldDescriptors = HashMap<IrBindableSymbol<*, *>, IrFieldSymbol>()
|
private val singletonFieldDescriptors = HashMap<IrBindableSymbol<*, *>, IrFieldSymbol>()
|
||||||
private val outerThisFieldSymbols = HashMap<IrClass, IrFieldSymbol>()
|
private val outerThisFieldSymbols = HashMap<IrClass, IrFieldSymbol>()
|
||||||
private val innerClassConstructors = HashMap<ClassConstructorDescriptor, IrConstructorSymbol>()
|
private val innerClassConstructors = HashMap<IrConstructorSymbol, IrConstructorSymbol>()
|
||||||
|
|
||||||
override fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol = TODO()
|
override fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol = TODO()
|
||||||
|
|
||||||
@@ -74,12 +75,13 @@ class JsDescriptorsFactory(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: ClassConstructorDescriptor): IrConstructorSymbol {
|
|
||||||
val innerClass = innerClassConstructor.containingDeclaration
|
|
||||||
assert(innerClass.isInner) { "Class is not inner: $innerClass" }
|
|
||||||
|
|
||||||
return innerClassConstructors.getOrPut(innerClassConstructor) {
|
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol {
|
||||||
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor)
|
val innerClass = innerClassConstructor.parent as IrClass
|
||||||
|
assert(innerClass.descriptor.isInner) { "Class is not inner: $innerClass" }
|
||||||
|
|
||||||
|
return innerClassConstructors.getOrPut(innerClassConstructor.symbol) {
|
||||||
|
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor.descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||||
import org.jetbrains.kotlin.ir.SourceManager
|
import org.jetbrains.kotlin.ir.SourceManager
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
@@ -45,7 +46,7 @@ class JvmDescriptorsFactory(
|
|||||||
) : DescriptorsFactory {
|
) : DescriptorsFactory {
|
||||||
private val singletonFieldDescriptors = HashMap<IrBindableSymbol<*, *>, IrFieldSymbol>()
|
private val singletonFieldDescriptors = HashMap<IrBindableSymbol<*, *>, IrFieldSymbol>()
|
||||||
private val outerThisDescriptors = HashMap<IrClass, IrFieldSymbol>()
|
private val outerThisDescriptors = HashMap<IrClass, IrFieldSymbol>()
|
||||||
private val innerClassConstructors = HashMap<ClassConstructorDescriptor, IrConstructorSymbol>()
|
private val innerClassConstructors = HashMap<IrConstructorSymbol, IrConstructorSymbol>()
|
||||||
|
|
||||||
override fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol =
|
override fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol =
|
||||||
singletonFieldDescriptors.getOrPut(enumEntry) {
|
singletonFieldDescriptors.getOrPut(enumEntry) {
|
||||||
@@ -79,16 +80,16 @@ class JvmDescriptorsFactory(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: ClassConstructorDescriptor): IrConstructorSymbol {
|
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol {
|
||||||
val innerClass = innerClassConstructor.containingDeclaration
|
assert((innerClassConstructor.parent as IrClass).descriptor.isInner) { "Class is not inner: ${(innerClassConstructor.parent as IrClass).dump()}" }
|
||||||
assert(innerClass.isInner) { "Class is not inner: $innerClass" }
|
|
||||||
|
|
||||||
return innerClassConstructors.getOrPut(innerClassConstructor) {
|
return innerClassConstructors.getOrPut(innerClassConstructor.symbol) {
|
||||||
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor)
|
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createInnerClassConstructorWithOuterThisParameter(oldDescriptor: ClassConstructorDescriptor): IrConstructorSymbol {
|
private fun createInnerClassConstructorWithOuterThisParameter(oldConstructor: IrConstructor): IrConstructorSymbol {
|
||||||
|
val oldDescriptor = oldConstructor.descriptor
|
||||||
val classDescriptor = oldDescriptor.containingDeclaration
|
val classDescriptor = oldDescriptor.containingDeclaration
|
||||||
val outerThisType = (classDescriptor.containingDeclaration as ClassDescriptor).defaultType
|
val outerThisType = (classDescriptor.containingDeclaration as ClassDescriptor).defaultType
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user