[IR-plugin] New symbol tables
This commit is contained in:
@@ -8,7 +8,7 @@ configureJvmProject(project)
|
||||
configurePublishing(project)
|
||||
|
||||
group = 'org.jetbrains.kotlinx'
|
||||
version = '0.6.2'
|
||||
version = '0.7.1'
|
||||
if (!project.hasProperty("deploy")) {
|
||||
version = "$version-SNAPSHOT"
|
||||
}
|
||||
@@ -47,7 +47,7 @@ jar {
|
||||
manifestAttributes(manifest, project)
|
||||
}
|
||||
|
||||
ArtifactsKt.runtimeJar(project, EmbeddableKt.rewriteDepsToShadedCompiler(project, jar, {}), {})
|
||||
//ArtifactsKt.runtimeJar(project, EmbeddableKt.rewriteDepsToShadedCompiler(project, jar, {}), {})
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
|
||||
+2
-2
@@ -45,14 +45,14 @@ class SerializationKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile
|
||||
}
|
||||
|
||||
private val log = Logging.getLogger(this.javaClass)
|
||||
private val pluginVersion = "0.6.2-SNAPSHOT"
|
||||
private val pluginVersion = "0.7.1-SNAPSHOT"
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile) = SerializationGradleSubplugin.isEnabled(project)
|
||||
|
||||
override fun apply(
|
||||
project: Project,
|
||||
kotlinCompile: AbstractCompile,
|
||||
javaCompile: AbstractCompile,
|
||||
javaCompile: AbstractCompile?,
|
||||
variantData: Any?,
|
||||
androidProjectHandler: Any?,
|
||||
javaSourceSet: SourceSet?
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<expressionCodegenExtension implementation="org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationCodegenExtension"/>
|
||||
<syntheticResolveExtension implementation="org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationResolveExtension"/>
|
||||
<jsSyntheticTranslateExtension implementation="org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationJsExtension"/>
|
||||
<irGenerationExtension implementation="org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationLoweringExtension"/>
|
||||
|
||||
<gradleProjectImportHandler implementation="org.jetbrains.kotlinx.serialization.idea.KotlinSerializationGradleImportHandler"/>
|
||||
<mavenProjectImportHandler implementation="org.jetbrains.kotlinx.serialization.idea.KotlinSerializationMavenImportHandler"/>
|
||||
|
||||
+30
-16
@@ -22,24 +22,26 @@ import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.util.declareSimpleFunctionWithOverrides
|
||||
import org.jetbrains.kotlin.ir.util.withScope
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlinx.serialization.compiler.resolve.SerializableProperty
|
||||
|
||||
val BackendContext.externalSymbols: ReferenceSymbolTable get() = ir.symbols.externalSymbolTable
|
||||
|
||||
interface IrBuilderExtension {
|
||||
val compilerContext: BackendContext
|
||||
val translator: TypeTranslator
|
||||
|
||||
fun IrClass.contributeFunction(descriptor: FunctionDescriptor, bodyGen: IrBlockBodyBuilder.(IrFunction) -> Unit) {
|
||||
val f = compilerContext.symbolTable.declareSimpleFunctionWithOverrides(
|
||||
val BackendContext.localSymbolTable: SymbolTable
|
||||
|
||||
fun IrClass.contributeFunction(descriptor: FunctionDescriptor, fromStubs: Boolean = false, bodyGen: IrBlockBodyBuilder.(IrFunction) -> Unit) {
|
||||
val f: IrSimpleFunction = if (!fromStubs) compilerContext.localSymbolTable.declareSimpleFunctionWithOverrides(
|
||||
this.startOffset,
|
||||
this.endOffset,
|
||||
SERIALIZABLE_PLUGIN_ORIGIN,
|
||||
descriptor
|
||||
)
|
||||
) else compilerContext.externalSymbols.referenceSimpleFunction(descriptor).owner
|
||||
f.parent = this
|
||||
f.returnType = descriptor.returnType!!.toIrType()
|
||||
f.createParameterDeclarations()
|
||||
@@ -51,7 +53,7 @@ interface IrBuilderExtension {
|
||||
descriptor: ClassConstructorDescriptor,
|
||||
bodyGen: IrBlockBodyBuilder.(IrConstructor) -> Unit
|
||||
) {
|
||||
val c = compilerContext.symbolTable.declareConstructor(
|
||||
val c = compilerContext.localSymbolTable.declareConstructor(
|
||||
this.startOffset,
|
||||
this.endOffset,
|
||||
SERIALIZABLE_PLUGIN_ORIGIN,
|
||||
@@ -90,12 +92,20 @@ interface IrBuilderExtension {
|
||||
startOffset,
|
||||
endOffset,
|
||||
classDescriptor.defaultType.toIrType(),
|
||||
compilerContext.symbolTable.referenceClass(classDescriptor)
|
||||
compilerContext.externalSymbols.referenceClass(classDescriptor)
|
||||
)
|
||||
|
||||
fun IrBuilderWithScope.irGetObject(irObject: IrClass) =
|
||||
IrGetObjectValueImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
irObject.defaultType,
|
||||
irObject.symbol
|
||||
)
|
||||
|
||||
fun <T : IrDeclaration> T.buildWithScope(builder: (T) -> Unit): T =
|
||||
also { irDeclaration ->
|
||||
compilerContext.symbolTable.withScope(irDeclaration.descriptor) {
|
||||
compilerContext.localSymbolTable.withScope(irDeclaration.descriptor) {
|
||||
builder(irDeclaration)
|
||||
}
|
||||
}
|
||||
@@ -139,8 +149,12 @@ interface IrBuilderExtension {
|
||||
fun KotlinType.toIrType() = translateType(this)
|
||||
|
||||
|
||||
val SerializableProperty.irField: IrField
|
||||
get () = compilerContext.symbolTable.referenceField(this.descriptor).owner
|
||||
val SerializableProperty.irField: IrField get() = compilerContext.externalSymbols.referenceField(this.descriptor).owner
|
||||
// get () {
|
||||
// val symb = compilerContext.localSymbolTable.referenceField(this.descriptor)
|
||||
// return if (symb.isBound) symb.owner
|
||||
// else compilerContext.localSymbolTable.declareField()
|
||||
// }
|
||||
|
||||
/*
|
||||
The rest of the file is mainly copied from FunctionGenerator.
|
||||
@@ -155,7 +169,7 @@ interface IrBuilderExtension {
|
||||
+IrDelegatingConstructorCallImpl(
|
||||
startOffset, endOffset,
|
||||
compilerContext.irBuiltIns.unitType,
|
||||
compilerContext.symbolTable.referenceConstructor(anyConstructor),
|
||||
compilerContext.externalSymbols.referenceConstructor(anyConstructor),
|
||||
anyConstructor
|
||||
)
|
||||
}
|
||||
@@ -182,7 +196,7 @@ interface IrBuilderExtension {
|
||||
}
|
||||
|
||||
fun generatePropertyBackingField(propertyDescriptor: PropertyDescriptor): IrField {
|
||||
return compilerContext.symbolTable.declareField(
|
||||
return compilerContext.localSymbolTable.declareField(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
SERIALIZABLE_PLUGIN_ORIGIN,
|
||||
@@ -196,7 +210,7 @@ interface IrBuilderExtension {
|
||||
fieldSymbol: IrFieldSymbol,
|
||||
ownerSymbol: IrValueSymbol
|
||||
): IrSimpleFunction {
|
||||
return compilerContext.symbolTable.declareSimpleFunctionWithOverrides(
|
||||
return compilerContext.localSymbolTable.declareSimpleFunctionWithOverrides(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
SERIALIZABLE_PLUGIN_ORIGIN, descriptor
|
||||
).buildWithScope { irAccessor ->
|
||||
@@ -228,7 +242,7 @@ interface IrBuilderExtension {
|
||||
irAccessor.symbol,
|
||||
IrGetFieldImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
compilerContext.symbolTable.referenceField(property),
|
||||
compilerContext.localSymbolTable.referenceField(property),
|
||||
property.type.toIrType(),
|
||||
receiver
|
||||
)
|
||||
@@ -254,7 +268,7 @@ interface IrBuilderExtension {
|
||||
irBody.statements.add(
|
||||
IrSetFieldImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
compilerContext.symbolTable.referenceField(property),
|
||||
compilerContext.localSymbolTable.referenceField(property),
|
||||
receiver,
|
||||
IrGetValueImpl(startOffset, endOffset, irValueParameter.type, irValueParameter.symbol),
|
||||
compilerContext.irBuiltIns.unitType
|
||||
|
||||
+8
-3
@@ -6,6 +6,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.builders.irReturn
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializableCompanionCodegen
|
||||
@@ -19,7 +20,10 @@ class SerializableCompanionIrGenerator(
|
||||
override val compilerContext: BackendContext,
|
||||
bindingContext: BindingContext
|
||||
) : SerializableCompanionCodegen(irClass.descriptor), IrBuilderExtension {
|
||||
override val translator: TypeTranslator = TypeTranslator(compilerContext.symbolTable)
|
||||
override val translator: TypeTranslator = TypeTranslator(compilerContext.externalSymbols, compilerContext.irBuiltIns.languageVersionSettings)
|
||||
private val _table = SymbolTable()
|
||||
override val BackendContext.localSymbolTable: SymbolTable
|
||||
get() = _table
|
||||
|
||||
companion object {
|
||||
fun generate(irClass: IrClass,
|
||||
@@ -32,12 +36,13 @@ class SerializableCompanionIrGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
override fun generateSerializerGetter(methodDescriptor: FunctionDescriptor) = irClass.contributeFunction(methodDescriptor) { getter ->
|
||||
override fun generateSerializerGetter(methodDescriptor: FunctionDescriptor) =
|
||||
irClass.contributeFunction(methodDescriptor, fromStubs = true) { getter ->
|
||||
val serializer = serializableDescriptor.classSerializer?.toClassDescriptor!!
|
||||
val expr = if (serializer.kind == ClassKind.OBJECT) {
|
||||
irGetObject(serializer)
|
||||
} else {
|
||||
val ctor = compilerContext.symbolTable.referenceConstructor(serializer.unsubstitutedPrimaryConstructor!!)
|
||||
val ctor = compilerContext.externalSymbols.referenceConstructor(serializer.unsubstitutedPrimaryConstructor!!)
|
||||
val args: List<IrExpression> = emptyList() // todo
|
||||
irInvoke(null, ctor, *args.toTypedArray())
|
||||
}
|
||||
|
||||
+7
-4
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||
@@ -29,8 +30,10 @@ class SerializableIrGenerator(
|
||||
override val compilerContext: BackendContext,
|
||||
bindingContext: BindingContext
|
||||
) : SerializableCodegen(irClass.descriptor, bindingContext), IrBuilderExtension {
|
||||
override val translator: TypeTranslator = TypeTranslator(compilerContext.symbolTable)
|
||||
|
||||
override val translator: TypeTranslator = TypeTranslator(compilerContext.externalSymbols, compilerContext.irBuiltIns.languageVersionSettings)
|
||||
private val _table = SymbolTable()
|
||||
override val BackendContext.localSymbolTable: SymbolTable
|
||||
get() = _table
|
||||
|
||||
override fun generateInternalConstructor(constructorDescriptor: ClassConstructorDescriptor) =
|
||||
irClass.contributeConstructor(constructorDescriptor) { ctor ->
|
||||
@@ -52,8 +55,8 @@ class SerializableIrGenerator(
|
||||
val exceptionCtor =
|
||||
serializableDescriptor.getClassFromSerializationPackage(MISSING_FIELD_EXC)
|
||||
.unsubstitutedPrimaryConstructor!!
|
||||
val exceptionCtorRef = compilerContext.symbolTable.referenceConstructor(exceptionCtor)
|
||||
val exceptionType = exceptionCtor.returnType.toIrType()
|
||||
val exceptionCtorRef = compilerContext.externalSymbols.referenceConstructor(exceptionCtor)
|
||||
val exceptionType = exceptionCtorRef.owner.returnType
|
||||
|
||||
val thiz = irClass.thisReceiver!!
|
||||
if (KotlinBuiltIns.isAny(irClass.descriptor.getSuperClassOrAny()))
|
||||
|
||||
+22
-21
@@ -21,9 +21,7 @@ import org.jetbrains.kotlin.ir.expressions.mapValueParameters
|
||||
import org.jetbrains.kotlin.ir.expressions.mapValueParametersIndexed
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.ir.util.withScope
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -46,7 +44,10 @@ object SERIALIZABLE_PLUGIN_ORIGIN : IrDeclarationOriginImpl("SERIALIZER")
|
||||
class SerializerIrGenerator(val irClass: IrClass, override val compilerContext: BackendContext, bindingContext: BindingContext) :
|
||||
SerializerCodegen(irClass.descriptor, bindingContext), IrBuilderExtension {
|
||||
|
||||
override val translator: TypeTranslator = TypeTranslator(compilerContext.symbolTable)
|
||||
override val translator: TypeTranslator = TypeTranslator(compilerContext.externalSymbols, compilerContext.irBuiltIns.languageVersionSettings)
|
||||
private val _table = SymbolTable()
|
||||
override val BackendContext.localSymbolTable: SymbolTable
|
||||
get() = _table
|
||||
|
||||
override fun generateSerialDesc() {
|
||||
val desc: PropertyDescriptor = generatedSerialDescPropertyDescriptor ?: return
|
||||
@@ -61,24 +62,24 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
lateinit var prop: IrProperty
|
||||
|
||||
// how to (auto)create backing field and getter/setter?
|
||||
compilerContext.symbolTable.withScope(irClass.descriptor) {
|
||||
compilerContext.localSymbolTable.withScope(irClass.descriptor) {
|
||||
|
||||
introduceValueParameter(thisAsReceiverParameter)
|
||||
prop = generateSimplePropertyWithBackingField(thisAsReceiverParameter.symbol, desc, irClass)
|
||||
irClass.addMember(prop)
|
||||
}
|
||||
|
||||
compilerContext.symbolTable.declareAnonymousInitializer(
|
||||
compilerContext.localSymbolTable.declareAnonymousInitializer(
|
||||
irClass.startOffset, irClass.endOffset, SERIALIZABLE_PLUGIN_ORIGIN, irClass.descriptor
|
||||
).buildWithScope { initIrBody ->
|
||||
val ctor = irClass.declarations.filterIsInstance<IrConstructor>().singleOrNull()
|
||||
val serialClassDescImplCtor = compilerContext.symbolTable.referenceConstructor(serialDescImplConstructor)
|
||||
compilerContext.symbolTable.withScope(initIrBody.descriptor) {
|
||||
val serialClassDescImplCtor = compilerContext.externalSymbols.referenceConstructor(serialDescImplConstructor)
|
||||
compilerContext.localSymbolTable.withScope(initIrBody.descriptor) {
|
||||
initIrBody.body = compilerContext.createIrBuilder(initIrBody.symbol).irBlockBody {
|
||||
val localDesc = irTemporary(
|
||||
irCall(
|
||||
serialClassDescImplCtor,
|
||||
type = serialDescImplConstructor.returnType.toIrType()
|
||||
type = serialClassDescImplCtor.owner.returnType
|
||||
).mapValueParameters { irString(serialName) },
|
||||
nameHint = "serialDesc"
|
||||
)
|
||||
@@ -125,7 +126,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
genericIndex: Int? = null
|
||||
): IrExpression? {
|
||||
val nullableSerClass =
|
||||
compilerContext.symbolTable.referenceClass(module.getClassFromInternalSerializationPackage(SpecialBuiltins.nullableSerializer))
|
||||
compilerContext.externalSymbols.referenceClass(module.getClassFromInternalSerializationPackage(SpecialBuiltins.nullableSerializer))
|
||||
if (serializerClass == null) {
|
||||
if (genericIndex == null) return null
|
||||
return TODO("Saved serializer for generic argument")
|
||||
@@ -146,9 +147,9 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
val serializable = getSerializableClassDescriptorBySerializer(serializerClass)
|
||||
val ctor = if (serializable?.declaredTypeParameters?.isNotEmpty() == true) {
|
||||
KSerializerDescriptorResolver.createTypedSerializerConstructorDescriptor(serializerClass, serializableDescriptor)
|
||||
.let { compilerContext.symbolTable.referenceConstructor(it) }
|
||||
.let { compilerContext.externalSymbols.referenceConstructor(it) }
|
||||
} else {
|
||||
compilerContext.symbolTable.referenceConstructor(serializerClass.unsubstitutedPrimaryConstructor!!)
|
||||
compilerContext.externalSymbols.referenceConstructor(serializerClass.unsubstitutedPrimaryConstructor!!)
|
||||
}
|
||||
return irInvoke(
|
||||
null,
|
||||
@@ -159,7 +160,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
}
|
||||
|
||||
fun ClassDescriptor.referenceMethod(methodName: String) =
|
||||
getFuncDesc(methodName).single().let { compilerContext.symbolTable.referenceFunction(it) }
|
||||
getFuncDesc(methodName).single().let { compilerContext.externalSymbols.referenceFunction(it) }
|
||||
|
||||
override fun generateSave(function: FunctionDescriptor) = irClass.contributeFunction(function) { saveFunc ->
|
||||
|
||||
@@ -168,7 +169,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
|
||||
val kOutputClass = serializerDescriptor.getClassFromSerializationPackage(STRUCTURE_ENCODER_CLASS)
|
||||
|
||||
val descriptorGetterSymbol = compilerContext.symbolTable.referenceFunction(anySerialDescProperty?.getter!!)
|
||||
val descriptorGetterSymbol = compilerContext.localSymbolTable.referenceFunction(anySerialDescProperty?.getter!!) //???
|
||||
|
||||
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
||||
|
||||
@@ -206,7 +207,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
irInt(index),
|
||||
// todo: direct field access?
|
||||
// irInvoke(irGet(serialObjectSymbol), compilerContext.symbolTable.referenceFunction(property.descriptor.getter!!))
|
||||
irGetField(irGet(serialObjectSymbol), compilerContext.symbolTable.referenceField(property.descriptor).owner)
|
||||
irGetField(irGet(serialObjectSymbol), property.irField)
|
||||
)
|
||||
} else {
|
||||
val writeFunc = kOutputClass.referenceMethod("${CallingConventions.encode}${sti.elementMethodPrefix}Serializable${CallingConventions.elementPostfix}")
|
||||
@@ -218,7 +219,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
innerSerial,
|
||||
// todo: direct field access?
|
||||
// irInvoke(irGet(serialObjectSymbol), compilerContext.symbolTable.referenceFunction(property.descriptor.getter!!))
|
||||
irGetField(irGet(serialObjectSymbol), compilerContext.symbolTable.referenceField(property.descriptor).owner)
|
||||
irGetField(irGet(serialObjectSymbol), property.irField)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -256,7 +257,7 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
fun IrVariable.get() = irGet(this)
|
||||
|
||||
val inputClass = serializerDescriptor.getClassFromSerializationPackage(STRUCTURE_DECODER_CLASS)
|
||||
val descriptorGetterSymbol = compilerContext.symbolTable.referenceFunction(anySerialDescProperty?.getter!!)
|
||||
val descriptorGetterSymbol = compilerContext.localSymbolTable.referenceFunction(anySerialDescProperty?.getter!!) //???
|
||||
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
||||
|
||||
// workaround due to unavailability of labels (KT-25386)
|
||||
@@ -332,14 +333,14 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
val exceptionCtor =
|
||||
serializableDescriptor.getClassFromSerializationPackage(UNKNOWN_FIELD_EXC)
|
||||
.unsubstitutedPrimaryConstructor!!
|
||||
val excClassRef = compilerContext.symbolTable.referenceConstructor(exceptionCtor)
|
||||
val excClassRef = compilerContext.externalSymbols.referenceConstructor(exceptionCtor)
|
||||
+elseBranch(
|
||||
irThrow(
|
||||
irInvoke(
|
||||
null,
|
||||
excClassRef,
|
||||
indexVar.get(),
|
||||
typeHint = exceptionCtor.returnType.toIrType()
|
||||
typeHint = excClassRef.owner.returnType
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -358,12 +359,12 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
// todo: set properties in external deserialization
|
||||
var args: List<IrExpression> = localProps.map { it.get() }
|
||||
val ctor: IrConstructorSymbol = if (serializableDescriptor.isInternalSerializable) {
|
||||
val ctorDesc = compilerContext.symbolTable.referenceClass(serializableDescriptor)
|
||||
val ctorDesc = compilerContext.externalSymbols.referenceClass(serializableDescriptor)
|
||||
.owner.constructors.single { it.origin == SERIALIZABLE_PLUGIN_ORIGIN }
|
||||
args = listOf(irGet(bitMasks[0])) + args + irNull()
|
||||
ctorDesc.symbol
|
||||
} else {
|
||||
compilerContext.symbolTable.referenceConstructor(serializableDescriptor.unsubstitutedPrimaryConstructor!!)
|
||||
compilerContext.externalSymbols.referenceConstructor(serializableDescriptor.unsubstitutedPrimaryConstructor!!)
|
||||
}
|
||||
|
||||
+irReturn(irInvoke(null, ctor, *args.toTypedArray()))
|
||||
|
||||
+3
-3
@@ -41,9 +41,9 @@ import org.jetbrains.kotlinx.serialization.compiler.resolve.*
|
||||
import org.jetbrains.kotlinx.serialization.compiler.resolve.SerialEntityNames.SERIAL_DESCRIPTOR_CLASS_IMPL
|
||||
import org.jetbrains.kotlinx.serialization.compiler.resolve.SerialEntityNames.typeArgPrefix
|
||||
|
||||
class SerializerJsTranslator(declaration: KtPureClassOrObject,
|
||||
class SerializerJsTranslator(descriptor: ClassDescriptor,
|
||||
val translator: DeclarationBodyVisitor,
|
||||
val context: TranslationContext) : SerializerCodegen(declaration, context.bindingContext()) {
|
||||
val context: TranslationContext) : SerializerCodegen(descriptor, context.bindingContext()) {
|
||||
|
||||
private fun generateFunction(descriptor: FunctionDescriptor, bodyGen: JsBlockBuilder.(JsFunction, TranslationContext) -> Unit) {
|
||||
val f = context.buildFunction(descriptor, bodyGen)
|
||||
@@ -362,7 +362,7 @@ class SerializerJsTranslator(declaration: KtPureClassOrObject,
|
||||
companion object {
|
||||
fun translate(declaration: KtPureClassOrObject, descriptor: ClassDescriptor, translator: DeclarationBodyVisitor, context: TranslationContext) {
|
||||
if (getSerializableClassDescriptorBySerializer(descriptor) != null)
|
||||
SerializerJsTranslator(declaration, translator, context).generate()
|
||||
SerializerJsTranslator(descriptor, translator, context).generate()
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -32,7 +32,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
class SerializerCodegenImpl(
|
||||
private val codegen: ImplementationBodyCodegen,
|
||||
serializableClass: ClassDescriptor
|
||||
) : SerializerCodegen(codegen.myClass, codegen.bindingContext) {
|
||||
) : SerializerCodegen(codegen.descriptor, codegen.bindingContext) {
|
||||
|
||||
|
||||
private val serialDescField = "\$\$serialDesc"
|
||||
|
||||
+2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlinx.serialization.compiler.extensions
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
@@ -28,5 +29,6 @@ class SerializationComponentRegistrar : ComponentRegistrar {
|
||||
ExpressionCodegenExtension.registerExtension(project, SerializationCodegenExtension())
|
||||
SyntheticResolveExtension.registerExtension(project, SerializationResolveExtension())
|
||||
JsSyntheticTranslateExtension.registerExtension(project, SerializationJsExtension())
|
||||
IrGenerationExtension.registerExtension(project, SerializationLoweringExtension())
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -33,9 +33,9 @@ object SerialEntityNames {
|
||||
val IMPL_NAME = Name.identifier("Impl")
|
||||
|
||||
const val ENCODER_CLASS = "Encoder"
|
||||
const val STRUCTURE_ENCODER_CLASS = "CompositeEncoder"
|
||||
const val STRUCTURE_ENCODER_CLASS = "StructureEncoder"
|
||||
const val DECODER_CLASS = "Decoder"
|
||||
const val STRUCTURE_DECODER_CLASS = "CompositeDecoder"
|
||||
const val STRUCTURE_DECODER_CLASS = "StructureDecoder"
|
||||
|
||||
const val SERIAL_SAVER_CLASS = "SerializationStrategy"
|
||||
const val SERIAL_LOADER_CLASS = "DeserializationStrategy"
|
||||
@@ -75,8 +75,8 @@ object CallingConventions {
|
||||
const val decode = "decode"
|
||||
const val update = "update"
|
||||
const val encode = "encode"
|
||||
const val decodeElementIndex = "decodeElementIndex"
|
||||
const val elementPostfix = "Element"
|
||||
const val decodeElementIndex = "decodeElement"
|
||||
const val elementPostfix = "ElementValue"
|
||||
|
||||
const val addElement = "addElement"
|
||||
const val addAnnotation = "pushAnnotation"
|
||||
|
||||
Reference in New Issue
Block a user