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
|
||||
) {
|
||||
val thisVar = irTemporaryVarDeclaration(
|
||||
replacement.returnType, nameHint = "\$this", isMutable = false
|
||||
)
|
||||
val thisVar = irTemporary(irType = replacement.returnType, nameHint = "\$this")
|
||||
valueMap[constructor.constructedClass.thisReceiver!!.symbol] = thisVar
|
||||
|
||||
constructor.body?.statements?.forEach { statement ->
|
||||
|
||||
@@ -42,39 +42,18 @@ inline fun IrBuilderWithScope.irLetS(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun <T : IrElement> IrStatementsBuilder<T>.irTemporary(
|
||||
value: IrExpression,
|
||||
value: IrExpression? = null,
|
||||
nameHint: String? = null,
|
||||
typeHint: KotlinType? = null,
|
||||
irType: IrType? = null
|
||||
irType: IrType = value?.type!!, // either value or irType should be supplied at callsite
|
||||
isMutable: Boolean = false,
|
||||
): IrVariable {
|
||||
val temporary = scope.createTemporaryVariable(value, nameHint, irType = irType)
|
||||
val temporary = scope.createTemporaryVariableDeclaration(irType, nameHint, isMutable)
|
||||
value?.let { temporary.initializer = it }
|
||||
+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) =
|
||||
context.irFactory.createExpressionBody(startOffset, endOffset, value)
|
||||
|
||||
|
||||
+1
-1
@@ -271,7 +271,7 @@ class IrSparseArrayParcelSerializer(
|
||||
) : IrParcelSerializer {
|
||||
override fun AndroidIrBuilder.readParcel(parcel: IrValueDeclaration): IrExpression =
|
||||
irBlock {
|
||||
val remainingSizeTemporary = irTemporaryVar(parcelReadInt(irGet(parcel)))
|
||||
val remainingSizeTemporary = irTemporary(parcelReadInt(irGet(parcel)), isMutable = true)
|
||||
|
||||
val sparseArrayConstructor = sparseArrayClass.constructors.first { irConstructor ->
|
||||
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) }
|
||||
|
||||
inline fun IrBlockBuilder.forUntil(upperBound: IrExpression, loopBody: IrBlockBuilder.(IrValueDeclaration) -> Unit) {
|
||||
val indexTemporary = irTemporaryVar(irInt(0))
|
||||
val indexTemporary = irTemporary(irInt(0), isMutable = true)
|
||||
+irWhile().apply {
|
||||
condition = irNotEquals(irGet(indexTemporary), upperBound)
|
||||
body = irBlock {
|
||||
|
||||
+4
-8
@@ -367,23 +367,19 @@ open class SerializerIrGenerator(
|
||||
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
||||
|
||||
// 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
|
||||
val blocksCnt = serializableProperties.bitMaskSlotCount()
|
||||
|
||||
// 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 ...
|
||||
val localProps = serializableProperties.mapIndexed { i, prop ->
|
||||
val (expr, type) = defaultValueAndType(prop)
|
||||
irTemporaryVar(
|
||||
expr,
|
||||
"local$i",
|
||||
type
|
||||
)
|
||||
irTemporary(expr, "local$i", type, isMutable = true)
|
||||
}
|
||||
|
||||
//input = input.beginStructure(...)
|
||||
|
||||
+1
-1
@@ -292,7 +292,7 @@ class IrSparseArrayParcelSerializer(
|
||||
) : IrParcelSerializer {
|
||||
override fun AndroidIrBuilder.readParcel(parcel: IrValueDeclaration): IrExpression {
|
||||
return irBlock {
|
||||
val remainingSizeTemporary = irTemporaryVar(parcelReadInt(irGet(parcel)))
|
||||
val remainingSizeTemporary = irTemporary(parcelReadInt(irGet(parcel)), isMutable = true)
|
||||
|
||||
val sparseArrayConstructor = sparseArrayClass.constructors.first { irConstructor ->
|
||||
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) {
|
||||
val indexTemporary = irTemporaryVar(irInt(0))
|
||||
val indexTemporary = irTemporary(irInt(0), isMutable = true)
|
||||
+irWhile().apply {
|
||||
condition = irNotEquals(irGet(indexTemporary), upperBound)
|
||||
body = irBlock {
|
||||
|
||||
Reference in New Issue
Block a user