Parcelize: Refactor AndroidSymbols

This commit is contained in:
Steven Schäfer
2021-08-27 11:50:21 +02:00
committed by Alexander Udalov
parent 2f7bc8ca79
commit 34a200bf09
4 changed files with 4 additions and 9 deletions
@@ -13,9 +13,7 @@ import org.jetbrains.kotlin.parcelize.ir.ParcelizeIrTransformer
class ParcelizeIrGeneratorExtension : IrGenerationExtension { class ParcelizeIrGeneratorExtension : IrGenerationExtension {
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
val arrayOfNulls = pluginContext.irBuiltIns.arrayOfNulls val androidSymbols = AndroidSymbols(pluginContext.irBuiltIns, moduleFragment)
val charSequence = pluginContext.irBuiltIns.charSequenceClass
val androidSymbols = AndroidSymbols(pluginContext.irBuiltIns, arrayOfNulls, charSequence, moduleFragment)
ParcelizeIrTransformer(pluginContext, androidSymbols).transform(moduleFragment) ParcelizeIrTransformer(pluginContext, androidSymbols).transform(moduleFragment)
} }
} }
@@ -2,7 +2,6 @@
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
// This file was autogenerated based on android.jar, do not edit it directly.
package org.jetbrains.kotlin.parcelize.ir package org.jetbrains.kotlin.parcelize.ir
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
@@ -29,8 +28,6 @@ import org.jetbrains.kotlin.name.Name
// supertypes, which are not needed to produce correct bytecode. // supertypes, which are not needed to produce correct bytecode.
class AndroidSymbols( class AndroidSymbols(
val irBuiltIns: IrBuiltIns, val irBuiltIns: IrBuiltIns,
val arrayOfNulls: IrSimpleFunctionSymbol,
private val charSequence: IrClassSymbol,
private val moduleFragment: IrModuleFragment private val moduleFragment: IrModuleFragment
) { ) {
private val irFactory: IrFactory = IrFactoryImpl private val irFactory: IrFactory = IrFactoryImpl
@@ -380,7 +377,7 @@ class AndroidSymbols(
val textUtilsWriteToParcel: IrSimpleFunctionSymbol = val textUtilsWriteToParcel: IrSimpleFunctionSymbol =
androidTextTextUtils.owner.addFunction("writeToParcel", irBuiltIns.unitType, isStatic = true).apply { androidTextTextUtils.owner.addFunction("writeToParcel", irBuiltIns.unitType, isStatic = true).apply {
addValueParameter("cs", charSequence.defaultType) addValueParameter("cs", irBuiltIns.charSequenceClass.defaultType)
addValueParameter("p", androidOsParcel.defaultType) addValueParameter("p", androidOsParcel.defaultType)
addValueParameter("parcelableFlags", irBuiltIns.intType) addValueParameter("parcelableFlags", irBuiltIns.intType)
}.symbol }.symbol
@@ -234,7 +234,7 @@ class IrArrayParcelSerializer(
) : IrParcelSerializer { ) : IrParcelSerializer {
private fun AndroidIrBuilder.newArray(size: IrExpression): IrExpression { private fun AndroidIrBuilder.newArray(size: IrExpression): IrExpression {
val arrayConstructor: IrFunctionSymbol = if (arrayType.isBoxedArray) { val arrayConstructor: IrFunctionSymbol = if (arrayType.isBoxedArray) {
androidSymbols.arrayOfNulls context.irBuiltIns.arrayOfNulls
} else { } else {
arrayType.classOrNull!!.constructors.single { it.owner.valueParameters.size == 1 } arrayType.classOrNull!!.constructors.single { it.owner.valueParameters.size == 1 }
} }
@@ -226,7 +226,7 @@ class ParcelizeIrTransformer(private val context: IrPluginContext, private val a
body = context.createIrBuilder(symbol).run { body = context.createIrBuilder(symbol).run {
irExprBody( irExprBody(
parcelerNewArray(parcelerObject, sizeParameter) parcelerNewArray(parcelerObject, sizeParameter)
?: irCall(androidSymbols.arrayOfNulls, arrayType).apply { ?: irCall(context.irBuiltIns.arrayOfNulls, arrayType).apply {
putTypeArgument(0, arrayType) putTypeArgument(0, arrayType)
putValueArgument(0, irGet(sizeParameter)) putValueArgument(0, irGet(sizeParameter))
} }