Implement inline classes in the JVM_IR backend
This commit is contained in:
committed by
Alexander Udalov
parent
ad3e03bdbd
commit
9c957edcea
@@ -170,10 +170,7 @@ fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||
}
|
||||
}
|
||||
|
||||
fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
||||
assert(typeParameters.isEmpty())
|
||||
copyTypeParametersFrom(from)
|
||||
|
||||
fun IrFunction.copyValueParametersFrom(from: IrFunction) {
|
||||
// TODO: should dispatch receiver be copied?
|
||||
dispatchReceiverParameter = from.dispatchReceiverParameter?.let {
|
||||
IrValueParameterImpl(it.startOffset, it.endOffset, it.origin, it.descriptor, it.type, it.varargElementType).also {
|
||||
@@ -186,23 +183,33 @@ fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
||||
valueParameters += from.valueParameters.map { it.copyTo(this, index = it.index + shift) }
|
||||
}
|
||||
|
||||
fun IrTypeParametersContainer.copyTypeParametersFrom(
|
||||
source: IrTypeParametersContainer,
|
||||
fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
||||
assert(typeParameters.isEmpty())
|
||||
copyTypeParametersFrom(from)
|
||||
copyValueParametersFrom(from)
|
||||
}
|
||||
|
||||
fun IrTypeParametersContainer.copyTypeParameters(
|
||||
srcTypeParameters: List<IrTypeParameter>,
|
||||
origin: IrDeclarationOrigin? = null
|
||||
) {
|
||||
val target = this
|
||||
val shift = target.typeParameters.size
|
||||
val shift = typeParameters.size
|
||||
// Any type parameter can figure in a boundary type for any other parameter.
|
||||
// Therefore, we first copy the parameters themselves, then set up their supertypes.
|
||||
source.typeParameters.forEachIndexed { i, sourceParameter ->
|
||||
srcTypeParameters.forEachIndexed { i, sourceParameter ->
|
||||
assert(sourceParameter.index == i)
|
||||
target.typeParameters.add(sourceParameter.copyToWithoutSuperTypes(target, shift = shift, origin = origin ?: sourceParameter.origin))
|
||||
typeParameters.add(sourceParameter.copyToWithoutSuperTypes(this, shift = shift, origin = origin ?: sourceParameter.origin))
|
||||
}
|
||||
source.typeParameters.zip(target.typeParameters.drop(shift)).forEach { (srcParameter, dstParameter) ->
|
||||
srcTypeParameters.zip(typeParameters.drop(shift)).forEach { (srcParameter, dstParameter) ->
|
||||
dstParameter.copySuperTypesFrom(srcParameter)
|
||||
}
|
||||
}
|
||||
|
||||
fun IrTypeParametersContainer.copyTypeParametersFrom(
|
||||
source: IrTypeParametersContainer,
|
||||
origin: IrDeclarationOrigin? = null
|
||||
) = copyTypeParameters(source.typeParameters, origin)
|
||||
|
||||
private fun IrTypeParameter.copySuperTypesFrom(source: IrTypeParameter) {
|
||||
val target = this
|
||||
val sourceParent = source.parent as IrTypeParametersContainer
|
||||
@@ -379,6 +386,9 @@ fun IrClass.simpleFunctions() = declarations.flatMap {
|
||||
}
|
||||
}
|
||||
|
||||
val IrClass.primaryConstructor: IrConstructor?
|
||||
get() = constructors.singleOrNull(IrConstructor::isPrimary)
|
||||
|
||||
fun IrClass.createParameterDeclarations() {
|
||||
assert (thisReceiver == null)
|
||||
|
||||
|
||||
+2
-2
@@ -101,7 +101,7 @@ inline fun IrProperty.addSetter(b: IrFunctionBuilder.() -> Unit = {}): IrSimpleF
|
||||
}
|
||||
}
|
||||
|
||||
fun IrFunctionBuilder.buildFun(): IrSimpleFunction {
|
||||
fun IrFunctionBuilder.buildFun(): IrFunctionImpl {
|
||||
val wrappedDescriptor = WrappedSimpleFunctionDescriptor()
|
||||
return IrFunctionImpl(
|
||||
startOffset, endOffset, origin,
|
||||
@@ -126,7 +126,7 @@ fun IrFunctionBuilder.buildConstructor(): IrConstructor {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun buildFun(b: IrFunctionBuilder.() -> Unit): IrSimpleFunction =
|
||||
inline fun buildFun(b: IrFunctionBuilder.() -> Unit): IrFunctionImpl =
|
||||
IrFunctionBuilder().run {
|
||||
b()
|
||||
buildFun()
|
||||
|
||||
Reference in New Issue
Block a user