[IR] Properly serialize IrDeclarationOrigin.GeneratedByPlugin to klibs

^KT-56911 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-03-28 12:37:36 +03:00
committed by Space Team
parent 12b11bd034
commit c957a0b43b
14 changed files with 111 additions and 27 deletions
@@ -27,9 +27,9 @@ abstract class AbstractTransformerForGenerator(
protected val irFactory = context.irFactory
protected val irBuiltIns = context.irBuiltIns
abstract fun interestedIn(key: GeneratedDeclarationKey): Boolean
abstract fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey): IrBody?
abstract fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey): IrBody?
abstract fun interestedIn(key: GeneratedDeclarationKey?): Boolean
abstract fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey?): IrBody?
abstract fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey?): IrBody?
final override fun visitElement(element: IrElement) {
if (visitBodies) {
@@ -13,15 +13,15 @@ import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrBody
class TransformerForAdditionalMembersGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context, visitBodies = false) {
override fun interestedIn(key: GeneratedDeclarationKey): Boolean {
override fun interestedIn(key: GeneratedDeclarationKey?): Boolean {
return key == AdditionalMembersGenerator.Key
}
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey): IrBody? {
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey?): IrBody? {
return generateDefaultBodyForMaterializeFunction(function)
}
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey): IrBody? {
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey?): IrBody? {
return constructor.body
}
}
@@ -16,17 +16,17 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
class TransformerForCompanionGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context, visitBodies = true) {
override fun interestedIn(key: GeneratedDeclarationKey): Boolean {
override fun interestedIn(key: GeneratedDeclarationKey?): Boolean {
return key == CompanionGenerator.Key
}
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey): IrBody {
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey?): IrBody {
val const = IrConstImpl(-1, -1, irBuiltIns.intType, IrConstKind.Int, value = 10)
val returnStatement = IrReturnImpl(-1, -1, irBuiltIns.nothingType, function.symbol, const)
return irFactory.createBlockBody(-1, -1, listOf(returnStatement))
}
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey): IrBody? {
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey?): IrBody? {
return generateBodyForDefaultConstructor(constructor)
}
}
@@ -13,15 +13,15 @@ import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrBody
class TransformerForExternalClassGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context, visitBodies = false) {
override fun interestedIn(key: GeneratedDeclarationKey): Boolean {
override fun interestedIn(key: GeneratedDeclarationKey?): Boolean {
return key == ExternalClassGenerator.Key
}
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey): IrBody? {
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey?): IrBody? {
return generateDefaultBodyForMaterializeFunction(function)
}
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey): IrBody? {
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey?): IrBody? {
return generateBodyForDefaultConstructor(constructor)
}
}
@@ -17,18 +17,18 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
import org.jetbrains.kotlin.ir.types.classFqName
class TransformerForTopLevelDeclarationsGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context, visitBodies = false) {
override fun interestedIn(key: GeneratedDeclarationKey): Boolean {
override fun interestedIn(key: GeneratedDeclarationKey?): Boolean {
return key == TopLevelDeclarationsGenerator.Key
}
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey): IrBody {
override fun generateBodyForFunction(function: IrSimpleFunction, key: GeneratedDeclarationKey?): IrBody {
val className = function.valueParameters.single().type.classFqName?.asString() ?: "<error>"
val const = IrConstImpl(-1, -1, irBuiltIns.stringType, IrConstKind.String, className)
val returnExpression = IrReturnImpl(-1, -1, irBuiltIns.nothingType, function.symbol, const)
return irFactory.createBlockBody(-1, -1, listOf(returnExpression))
}
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey): IrBody? {
override fun generateBodyForConstructor(constructor: IrConstructor, key: GeneratedDeclarationKey?): IrBody? {
return null
}
}