Review fix: unify irTemporary variants
This commit is contained in:
+1
-3
@@ -200,9 +200,7 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
|
|||||||
replacement.body = context.createIrBuilder(replacement.symbol, replacement.startOffset, replacement.endOffset).irBlockBody(
|
replacement.body = context.createIrBuilder(replacement.symbol, replacement.startOffset, replacement.endOffset).irBlockBody(
|
||||||
replacement
|
replacement
|
||||||
) {
|
) {
|
||||||
val thisVar = irTemporaryVarDeclaration(
|
val thisVar = irTemporary(irType = replacement.returnType, nameHint = "\$this")
|
||||||
replacement.returnType, nameHint = "\$this", isMutable = false
|
|
||||||
)
|
|
||||||
valueMap[constructor.constructedClass.thisReceiver!!.symbol] = thisVar
|
valueMap[constructor.constructedClass.thisReceiver!!.symbol] = thisVar
|
||||||
|
|
||||||
constructor.body?.statements?.forEach { statement ->
|
constructor.body?.statements?.forEach { statement ->
|
||||||
|
|||||||
@@ -42,39 +42,18 @@ inline fun IrBuilderWithScope.irLetS(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun <T : IrElement> IrStatementsBuilder<T>.irTemporary(
|
fun <T : IrElement> IrStatementsBuilder<T>.irTemporary(
|
||||||
value: IrExpression,
|
value: IrExpression? = null,
|
||||||
nameHint: String? = null,
|
nameHint: String? = null,
|
||||||
typeHint: KotlinType? = null,
|
irType: IrType = value?.type!!, // either value or irType should be supplied at callsite
|
||||||
irType: IrType? = null
|
isMutable: Boolean = false,
|
||||||
): IrVariable {
|
): IrVariable {
|
||||||
val temporary = scope.createTemporaryVariable(value, nameHint, irType = irType)
|
val temporary = scope.createTemporaryVariableDeclaration(irType, nameHint, isMutable)
|
||||||
|
value?.let { temporary.initializer = it }
|
||||||
+temporary
|
+temporary
|
||||||
return temporary
|
return temporary
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : IrElement> IrStatementsBuilder<T>.irTemporaryVarDeclaration(
|
|
||||||
type: IrType,
|
|
||||||
nameHint: String? = null,
|
|
||||||
isMutable: Boolean = true
|
|
||||||
): IrVariable {
|
|
||||||
val temporary = scope.createTemporaryVariableDeclaration(type, nameHint, isMutable = isMutable)
|
|
||||||
+temporary
|
|
||||||
return temporary
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T : IrElement> IrStatementsBuilder<T>.irTemporaryVar(
|
|
||||||
value: IrExpression,
|
|
||||||
nameHint: String? = null,
|
|
||||||
irType: IrType? = null
|
|
||||||
): IrVariable {
|
|
||||||
val temporary = scope.createTemporaryVariable(value, nameHint, isMutable = true)
|
|
||||||
+temporary
|
|
||||||
return temporary
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun IrBuilderWithScope.irExprBody(value: IrExpression) =
|
fun IrBuilderWithScope.irExprBody(value: IrExpression) =
|
||||||
context.irFactory.createExpressionBody(startOffset, endOffset, value)
|
context.irFactory.createExpressionBody(startOffset, endOffset, value)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -271,7 +271,7 @@ class IrSparseArrayParcelSerializer(
|
|||||||
) : IrParcelSerializer {
|
) : IrParcelSerializer {
|
||||||
override fun AndroidIrBuilder.readParcel(parcel: IrValueDeclaration): IrExpression =
|
override fun AndroidIrBuilder.readParcel(parcel: IrValueDeclaration): IrExpression =
|
||||||
irBlock {
|
irBlock {
|
||||||
val remainingSizeTemporary = irTemporaryVar(parcelReadInt(irGet(parcel)))
|
val remainingSizeTemporary = irTemporary(parcelReadInt(irGet(parcel)), isMutable = true)
|
||||||
|
|
||||||
val sparseArrayConstructor = sparseArrayClass.constructors.first { irConstructor ->
|
val sparseArrayConstructor = sparseArrayClass.constructors.first { irConstructor ->
|
||||||
irConstructor.valueParameters.size == 1 && irConstructor.valueParameters.single().type.isInt()
|
irConstructor.valueParameters.size == 1 && irConstructor.valueParameters.single().type.isInt()
|
||||||
|
|||||||
+1
-1
@@ -125,7 +125,7 @@ fun IrClass.isSubclassOfFqName(fqName: String): Boolean =
|
|||||||
fqNameWhenAvailable?.asString() == fqName || superTypes.any { it.erasedUpperBound.isSubclassOfFqName(fqName) }
|
fqNameWhenAvailable?.asString() == fqName || superTypes.any { it.erasedUpperBound.isSubclassOfFqName(fqName) }
|
||||||
|
|
||||||
inline fun IrBlockBuilder.forUntil(upperBound: IrExpression, loopBody: IrBlockBuilder.(IrValueDeclaration) -> Unit) {
|
inline fun IrBlockBuilder.forUntil(upperBound: IrExpression, loopBody: IrBlockBuilder.(IrValueDeclaration) -> Unit) {
|
||||||
val indexTemporary = irTemporaryVar(irInt(0))
|
val indexTemporary = irTemporary(irInt(0), isMutable = true)
|
||||||
+irWhile().apply {
|
+irWhile().apply {
|
||||||
condition = irNotEquals(irGet(indexTemporary), upperBound)
|
condition = irNotEquals(irGet(indexTemporary), upperBound)
|
||||||
body = irBlock {
|
body = irBlock {
|
||||||
|
|||||||
+4
-8
@@ -367,23 +367,19 @@ open class SerializerIrGenerator(
|
|||||||
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
||||||
|
|
||||||
// workaround due to unavailability of labels (KT-25386)
|
// workaround due to unavailability of labels (KT-25386)
|
||||||
val flagVar = irTemporaryVar(irBoolean(true), "flag")
|
val flagVar = irTemporary(irBoolean(true), "flag", isMutable = true)
|
||||||
|
|
||||||
val indexVar = irTemporaryVar(irInt(0), "index")
|
val indexVar = irTemporary(irInt(0), "index", isMutable = true)
|
||||||
|
|
||||||
// calculating bit mask vars
|
// calculating bit mask vars
|
||||||
val blocksCnt = serializableProperties.bitMaskSlotCount()
|
val blocksCnt = serializableProperties.bitMaskSlotCount()
|
||||||
|
|
||||||
// var bitMask0 = 0, bitMask1 = 0...
|
// var bitMask0 = 0, bitMask1 = 0...
|
||||||
val bitMasks = (0 until blocksCnt).map { irTemporaryVar(irInt(0), "bitMask$it") }
|
val bitMasks = (0 until blocksCnt).map { irTemporary(irInt(0), "bitMask$it", isMutable = true) }
|
||||||
// var local0 = null, local1 = null ...
|
// var local0 = null, local1 = null ...
|
||||||
val localProps = serializableProperties.mapIndexed { i, prop ->
|
val localProps = serializableProperties.mapIndexed { i, prop ->
|
||||||
val (expr, type) = defaultValueAndType(prop)
|
val (expr, type) = defaultValueAndType(prop)
|
||||||
irTemporaryVar(
|
irTemporary(expr, "local$i", type, isMutable = true)
|
||||||
expr,
|
|
||||||
"local$i",
|
|
||||||
type
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//input = input.beginStructure(...)
|
//input = input.beginStructure(...)
|
||||||
|
|||||||
+1
-1
@@ -292,7 +292,7 @@ class IrSparseArrayParcelSerializer(
|
|||||||
) : IrParcelSerializer {
|
) : IrParcelSerializer {
|
||||||
override fun AndroidIrBuilder.readParcel(parcel: IrValueDeclaration): IrExpression {
|
override fun AndroidIrBuilder.readParcel(parcel: IrValueDeclaration): IrExpression {
|
||||||
return irBlock {
|
return irBlock {
|
||||||
val remainingSizeTemporary = irTemporaryVar(parcelReadInt(irGet(parcel)))
|
val remainingSizeTemporary = irTemporary(parcelReadInt(irGet(parcel)), isMutable = true)
|
||||||
|
|
||||||
val sparseArrayConstructor = sparseArrayClass.constructors.first { irConstructor ->
|
val sparseArrayConstructor = sparseArrayClass.constructors.first { irConstructor ->
|
||||||
irConstructor.valueParameters.size == 1 && irConstructor.valueParameters.single().type.isInt()
|
irConstructor.valueParameters.size == 1 && irConstructor.valueParameters.single().type.isInt()
|
||||||
|
|||||||
+1
-1
@@ -134,7 +134,7 @@ fun IrClass.isSubclassOfFqName(fqName: String): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun IrBlockBuilder.forUntil(upperBound: IrExpression, loopBody: IrBlockBuilder.(IrValueDeclaration) -> Unit) {
|
inline fun IrBlockBuilder.forUntil(upperBound: IrExpression, loopBody: IrBlockBuilder.(IrValueDeclaration) -> Unit) {
|
||||||
val indexTemporary = irTemporaryVar(irInt(0))
|
val indexTemporary = irTemporary(irInt(0), isMutable = true)
|
||||||
+irWhile().apply {
|
+irWhile().apply {
|
||||||
condition = irNotEquals(irGet(indexTemporary), upperBound)
|
condition = irNotEquals(irGet(indexTemporary), upperBound)
|
||||||
body = irBlock {
|
body = irBlock {
|
||||||
|
|||||||
Reference in New Issue
Block a user