[IrSerializer] Supported all annotations + refactoring
This commit is contained in:
@@ -528,42 +528,44 @@ message NullableIrExpression {
|
|||||||
|
|
||||||
/* ------ Declarations --------------------------------------------- */
|
/* ------ Declarations --------------------------------------------- */
|
||||||
|
|
||||||
message IrTypeAlias {
|
message IrDeclarationBase {
|
||||||
// Nothing for now.
|
|
||||||
}
|
|
||||||
|
|
||||||
message IrFunction {
|
|
||||||
required IrSymbol symbol = 1;
|
required IrSymbol symbol = 1;
|
||||||
required IrFunctionBase base = 2;
|
required IrDeclarationOrigin origin = 2;
|
||||||
required ModalityKind modality = 3;
|
required Coordinates coordinates = 3;
|
||||||
required bool is_tailrec = 4;
|
required Annotations annotations = 4;
|
||||||
required bool is_suspend = 5;
|
|
||||||
repeated IrSymbol overridden = 6;
|
|
||||||
//optional UniqId corresponding_property = 7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrFunctionBase {
|
message IrFunctionBase {
|
||||||
required String name = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required Visibility visibility = 2;
|
required String name = 2;
|
||||||
required bool is_inline = 3;
|
required Visibility visibility = 3;
|
||||||
required bool is_external = 4;
|
required bool is_inline = 4;
|
||||||
required IrTypeParameterContainer type_parameters = 5;
|
required bool is_external = 5;
|
||||||
optional IrDeclaration dispatch_receiver = 6;
|
required IrTypeParameterContainer type_parameters = 6;
|
||||||
optional IrDeclaration extension_receiver = 7;
|
optional IrValueParameter dispatch_receiver = 7;
|
||||||
repeated IrDeclaration value_parameter = 8;
|
optional IrValueParameter extension_receiver = 8;
|
||||||
optional IrStatement body = 9;
|
repeated IrValueParameter value_parameter = 9;
|
||||||
required IrTypeIndex return_type = 10;
|
optional IrStatement body = 10;
|
||||||
|
required IrTypeIndex return_type = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
message IrFunction {
|
||||||
|
required IrFunctionBase base = 1;
|
||||||
|
required ModalityKind modality = 2;
|
||||||
|
required bool is_tailrec = 3;
|
||||||
|
required bool is_suspend = 4;
|
||||||
|
repeated IrSymbol overridden = 5;
|
||||||
|
//optional UniqId corresponding_property = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrConstructor {
|
message IrConstructor {
|
||||||
required IrSymbol symbol = 1;
|
required IrFunctionBase base = 1;
|
||||||
required IrFunctionBase base = 2;
|
required bool is_primary = 2;
|
||||||
required bool is_primary = 3;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrField {
|
message IrField {
|
||||||
required IrSymbol symbol = 1;
|
required IrDeclarationBase base = 1;
|
||||||
optional IrExpression initializer = 2;
|
optional IrExpression initializer = 2;
|
||||||
required String name = 3;
|
required String name = 3;
|
||||||
required Visibility visibility = 4;
|
required Visibility visibility = 4;
|
||||||
@@ -574,17 +576,17 @@ message IrField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IrLocalDelegatedProperty {
|
message IrLocalDelegatedProperty {
|
||||||
required String name = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required IrTypeIndex type = 2;
|
required String name = 2;
|
||||||
required bool is_var = 3;
|
required IrTypeIndex type = 3;
|
||||||
required IrVariable delegate = 4;
|
required bool is_var = 4;
|
||||||
optional IrFunction getter = 5;
|
required IrVariable delegate = 5;
|
||||||
optional IrFunction setter = 6;
|
optional IrFunction getter = 6;
|
||||||
required IrSymbol symbol = 7;
|
optional IrFunction setter = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrProperty {
|
message IrProperty {
|
||||||
required IrSymbol symbol = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required String name = 2;
|
required String name = 2;
|
||||||
required Visibility visibility = 3;
|
required Visibility visibility = 3;
|
||||||
required ModalityKind modality = 4;
|
required ModalityKind modality = 4;
|
||||||
@@ -599,8 +601,8 @@ message IrProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IrVariable {
|
message IrVariable {
|
||||||
required String name = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required IrSymbol symbol = 2;
|
required String name = 2;
|
||||||
required IrTypeIndex type = 3;
|
required IrTypeIndex type = 3;
|
||||||
required bool is_var = 4;
|
required bool is_var = 4;
|
||||||
required bool is_const = 5;
|
required bool is_const = 5;
|
||||||
@@ -625,7 +627,7 @@ enum ModalityKind { // It is ModalityKind to not clash with Modality in descript
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IrValueParameter {
|
message IrValueParameter {
|
||||||
required IrSymbol symbol = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required String name = 2;
|
required String name = 2;
|
||||||
required int32 index = 3;
|
required int32 index = 3;
|
||||||
required IrTypeIndex type = 4;
|
required IrTypeIndex type = 4;
|
||||||
@@ -636,7 +638,7 @@ message IrValueParameter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IrTypeParameter {
|
message IrTypeParameter {
|
||||||
required IrSymbol symbol = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required String name = 2;
|
required String name = 2;
|
||||||
required int32 index = 3;
|
required int32 index = 3;
|
||||||
required IrTypeVariance variance = 4;
|
required IrTypeVariance variance = 4;
|
||||||
@@ -645,11 +647,11 @@ message IrTypeParameter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IrTypeParameterContainer {
|
message IrTypeParameterContainer {
|
||||||
repeated IrDeclaration type_parameter = 1;
|
repeated IrTypeParameter type_parameter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrClass {
|
message IrClass {
|
||||||
required IrSymbol symbol = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required String name = 2;
|
required String name = 2;
|
||||||
required ClassKind kind = 3;
|
required ClassKind kind = 3;
|
||||||
required Visibility visibility = 4;
|
required Visibility visibility = 4;
|
||||||
@@ -660,27 +662,28 @@ message IrClass {
|
|||||||
required bool is_data = 8;
|
required bool is_data = 8;
|
||||||
required bool is_external = 9;
|
required bool is_external = 9;
|
||||||
required bool is_inline = 10;
|
required bool is_inline = 10;
|
||||||
optional IrDeclaration this_receiver = 11;
|
optional IrValueParameter this_receiver = 11;
|
||||||
required IrTypeParameterContainer type_parameters = 12;
|
required IrTypeParameterContainer type_parameters = 12;
|
||||||
required IrDeclarationContainer declaration_container = 13;
|
required IrDeclarationContainer declaration_container = 13;
|
||||||
repeated IrTypeIndex super_type = 14;
|
repeated IrTypeIndex super_type = 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrEnumEntry {
|
message IrEnumEntry {
|
||||||
required IrSymbol symbol = 1;
|
required IrDeclarationBase base = 1;
|
||||||
optional IrExpression initializer = 2;
|
optional IrExpression initializer = 2;
|
||||||
optional IrDeclaration corresponding_class = 3;
|
optional IrClass corresponding_class = 3;
|
||||||
required String name = 4;
|
required String name = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrAnonymousInit {
|
message IrAnonymousInit {
|
||||||
required IrSymbol symbol = 1;
|
required IrDeclarationBase base = 1;
|
||||||
required IrStatement body = 2;
|
required IrStatement body = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: we need an extension mechanism to accomodate new
|
// TODO: we need an extension mechanism to accomodate new
|
||||||
// IR operators in upcoming releases.
|
// IR operators in upcoming releases.
|
||||||
message IrDeclarator {
|
|
||||||
|
message IrDeclaration {
|
||||||
oneof declarator {
|
oneof declarator {
|
||||||
IrAnonymousInit ir_anonymous_init = 1;
|
IrAnonymousInit ir_anonymous_init = 1;
|
||||||
IrClass ir_class = 2;
|
IrClass ir_class = 2;
|
||||||
@@ -689,21 +692,13 @@ message IrDeclarator {
|
|||||||
IrField ir_field = 5;
|
IrField ir_field = 5;
|
||||||
IrFunction ir_function = 6;
|
IrFunction ir_function = 6;
|
||||||
IrProperty ir_property = 7;
|
IrProperty ir_property = 7;
|
||||||
IrTypeAlias ir_type_alias = 8;
|
IrTypeParameter ir_type_parameter = 8;
|
||||||
IrTypeParameter ir_type_parameter = 9;
|
IrVariable ir_variable = 9;
|
||||||
IrVariable ir_variable = 10;
|
IrValueParameter ir_value_parameter = 10;
|
||||||
IrValueParameter ir_value_parameter = 11;
|
IrLocalDelegatedProperty ir_local_delegated_property = 11;
|
||||||
IrLocalDelegatedProperty ir_local_delegated_property = 12;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrDeclaration {
|
|
||||||
required IrDeclarationOrigin origin = 1;
|
|
||||||
required Coordinates coordinates = 2;
|
|
||||||
required Annotations annotations = 3;
|
|
||||||
required IrDeclarator declarator = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------- IrStatements --------------------------------------------- */
|
/* ------- IrStatements --------------------------------------------- */
|
||||||
|
|
||||||
message IrBranch {
|
message IrBranch {
|
||||||
@@ -716,7 +711,7 @@ message IrBlockBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IrCatch {
|
message IrCatch {
|
||||||
required IrDeclaration catch_parameter = 1;
|
required IrVariable catch_parameter = 1;
|
||||||
required IrExpression result = 2;
|
required IrExpression result = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+271
-391
@@ -9,8 +9,11 @@ import org.jetbrains.kotlin.backend.common.LoggingContext
|
|||||||
import org.jetbrains.kotlin.backend.common.descriptors.*
|
import org.jetbrains.kotlin.backend.common.descriptors.*
|
||||||
import org.jetbrains.kotlin.backend.common.ir.DeclarationFactory
|
import org.jetbrains.kotlin.backend.common.ir.DeclarationFactory
|
||||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||||
|
import org.jetbrains.kotlin.backend.common.peek
|
||||||
|
import org.jetbrains.kotlin.backend.common.pop
|
||||||
|
import org.jetbrains.kotlin.backend.common.push
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrConst.ValueCase.*
|
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrConst.ValueCase.*
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrDeclarator.DeclaratorCase.*
|
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrDeclaration.DeclaratorCase.*
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrOperation.OperationCase.*
|
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrOperation.OperationCase.*
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrStatement.StatementCase
|
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrStatement.StatementCase
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrType.KindCase.*
|
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrType.KindCase.*
|
||||||
@@ -54,6 +57,8 @@ abstract class IrModuleDeserializer(
|
|||||||
abstract fun deserializeString(proto: KotlinIr.String): String
|
abstract fun deserializeString(proto: KotlinIr.String): String
|
||||||
abstract fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoopBase): IrLoopBase
|
abstract fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoopBase): IrLoopBase
|
||||||
|
|
||||||
|
private val parentsStack = mutableListOf<IrDeclarationParent>()
|
||||||
|
|
||||||
private fun deserializeName(proto: KotlinIr.String): Name {
|
private fun deserializeName(proto: KotlinIr.String): Name {
|
||||||
val name = deserializeString(proto)
|
val name = deserializeString(proto)
|
||||||
return Name.guessByFirstCharacter(name)
|
return Name.guessByFirstCharacter(name)
|
||||||
@@ -159,12 +164,10 @@ abstract class IrModuleDeserializer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeCatch(proto: KotlinIr.IrCatch, start: Int, end: Int): IrCatch {
|
private fun deserializeCatch(proto: KotlinIr.IrCatch, start: Int, end: Int): IrCatch {
|
||||||
val catchParameter =
|
val catchParameter = deserializeIrVariable(proto.catchParameter)
|
||||||
deserializeDeclaration(proto.catchParameter, null) as IrVariable // TODO: we need a proper parent here
|
|
||||||
val result = deserializeExpression(proto.result)
|
val result = deserializeExpression(proto.result)
|
||||||
|
|
||||||
val catch = IrCatchImpl(start, end, catchParameter, result)
|
return IrCatchImpl(start, end, catchParameter, result)
|
||||||
return catch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeSyntheticBody(proto: KotlinIr.IrSyntheticBody, start: Int, end: Int): IrSyntheticBody {
|
private fun deserializeSyntheticBody(proto: KotlinIr.IrSyntheticBody, start: Int, end: Int): IrSyntheticBody {
|
||||||
@@ -186,7 +189,7 @@ abstract class IrModuleDeserializer(
|
|||||||
StatementCase.CATCH //proto.hasCatch()
|
StatementCase.CATCH //proto.hasCatch()
|
||||||
-> deserializeCatch(proto.catch, start, end)
|
-> deserializeCatch(proto.catch, start, end)
|
||||||
StatementCase.DECLARATION // proto.hasDeclaration()
|
StatementCase.DECLARATION // proto.hasDeclaration()
|
||||||
-> deserializeDeclaration(proto.declaration, null) // TODO: we need a proper parent here.
|
-> deserializeDeclaration(proto.declaration)
|
||||||
StatementCase.EXPRESSION // proto.hasExpression()
|
StatementCase.EXPRESSION // proto.hasExpression()
|
||||||
-> deserializeExpression(proto.expression)
|
-> deserializeExpression(proto.expression)
|
||||||
StatementCase.SYNTHETIC_BODY // proto.hasSyntheticBody()
|
StatementCase.SYNTHETIC_BODY // proto.hasSyntheticBody()
|
||||||
@@ -817,44 +820,52 @@ abstract class IrModuleDeserializer(
|
|||||||
return expression
|
return expression
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeIrTypeParameter(
|
private inline fun <T : IrDeclarationParent, R> usingParent(parent: T, block: (T) -> R): R {
|
||||||
proto: KotlinIr.IrTypeParameter,
|
parentsStack.push(parent)
|
||||||
start: Int,
|
try {
|
||||||
end: Int,
|
return block(parent)
|
||||||
origin: IrDeclarationOrigin
|
} finally {
|
||||||
): IrTypeParameter {
|
parentsStack.pop()
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrTypeParameterSymbol
|
}
|
||||||
val name = deserializeName(proto.name)
|
}
|
||||||
val variance = deserializeIrTypeVariance(proto.variance)
|
|
||||||
val descriptor = symbol.descriptor
|
|
||||||
|
|
||||||
val parameter = if (descriptor is DeserializedTypeParameterDescriptor && descriptor.containingDeclaration is PropertyDescriptor && symbol.isBound) {
|
private inline fun <T : IrDeclarationParent> T.usingParent(block: T.() -> Unit): T =
|
||||||
// TODO: Get rid of once new properties are implemented
|
this.apply { usingParent(this) { block(it) } }
|
||||||
IrTypeParameterImpl(start, end, origin, IrTypeParameterSymbolImpl(descriptor), name, proto.index, proto.isReified, variance)
|
|
||||||
} else {
|
private inline fun <T> withDeserializedIrDeclarationBase(
|
||||||
symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin, descriptor) {
|
proto: KotlinIr.IrDeclarationBase,
|
||||||
IrTypeParameterImpl(start, end, origin, it, name, proto.index, proto.isReified, variance)
|
block: (IrSymbol, Int, Int, IrDeclarationOrigin) -> T
|
||||||
|
): T where T : IrDeclaration, T : IrSymbolOwner {
|
||||||
|
val result = block(
|
||||||
|
deserializeIrSymbol(proto.symbol),
|
||||||
|
proto.coordinates.startOffset, proto.coordinates.endOffset,
|
||||||
|
deserializeIrDeclarationOrigin(proto.origin)
|
||||||
|
)
|
||||||
|
result.annotations.addAll(deserializeAnnotations(proto.annotations))
|
||||||
|
result.parent = parentsStack.peek()!!
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deserializeIrTypeParameter(proto: KotlinIr.IrTypeParameter) =
|
||||||
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
|
val name = deserializeName(proto.name)
|
||||||
|
val variance = deserializeIrTypeVariance(proto.variance)
|
||||||
|
|
||||||
|
val descriptor = (symbol as IrTypeParameterSymbol).descriptor
|
||||||
|
if (descriptor is DeserializedTypeParameterDescriptor && descriptor.containingDeclaration is PropertyDescriptor && symbol.isBound) {
|
||||||
|
// TODO: Get rid of once new properties are implemented
|
||||||
|
IrTypeParameterImpl(startOffset, endOffset, origin, IrTypeParameterSymbolImpl(descriptor), name, proto.index, proto.isReified, variance)
|
||||||
|
} else {
|
||||||
|
symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin, descriptor) {
|
||||||
|
IrTypeParameterImpl(startOffset, endOffset, origin, it, name, proto.index, proto.isReified, variance)
|
||||||
|
}
|
||||||
|
}.apply {
|
||||||
|
proto.superTypeList.mapTo(superTypes) { deserializeIrType(it) }
|
||||||
|
|
||||||
|
(descriptor as? WrappedTypeParameterDescriptor)?.bind(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val superTypes = proto.superTypeList.map { deserializeIrType(it) }
|
|
||||||
parameter.superTypes.addAll(superTypes)
|
|
||||||
|
|
||||||
return parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrTypeParameterContainer(
|
|
||||||
proto: KotlinIr.IrTypeParameterContainer,
|
|
||||||
parent: IrDeclarationParent
|
|
||||||
): List<IrTypeParameter> {
|
|
||||||
return proto.typeParameterList.map {
|
|
||||||
deserializeDeclaration(
|
|
||||||
it,
|
|
||||||
parent
|
|
||||||
) as IrTypeParameter
|
|
||||||
} // TODO: we need proper start, end and origin here?
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeClassKind(kind: KotlinIr.ClassKind) = when (kind) {
|
private fun deserializeClassKind(kind: KotlinIr.ClassKind) = when (kind) {
|
||||||
KotlinIr.ClassKind.CLASS -> ClassKind.CLASS
|
KotlinIr.ClassKind.CLASS -> ClassKind.CLASS
|
||||||
KotlinIr.ClassKind.INTERFACE -> ClassKind.INTERFACE
|
KotlinIr.ClassKind.INTERFACE -> ClassKind.INTERFACE
|
||||||
@@ -864,202 +875,149 @@ abstract class IrModuleDeserializer(
|
|||||||
KotlinIr.ClassKind.OBJECT -> ClassKind.OBJECT
|
KotlinIr.ClassKind.OBJECT -> ClassKind.OBJECT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeIrValueParameter(
|
private fun deserializeIrValueParameter(proto: KotlinIr.IrValueParameter) =
|
||||||
proto: KotlinIr.IrValueParameter,
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
start: Int,
|
|
||||||
end: Int,
|
|
||||||
origin: IrDeclarationOrigin
|
|
||||||
): IrValueParameter {
|
|
||||||
|
|
||||||
val varargElementType = if (proto.hasVarargElementType()) deserializeIrType(proto.varargElementType) else null
|
|
||||||
val paramSymbol = deserializeIrSymbol(proto.symbol) as IrValueParameterSymbol
|
|
||||||
val parameter =
|
|
||||||
IrValueParameterImpl(
|
IrValueParameterImpl(
|
||||||
start, end, origin,
|
startOffset, endOffset, origin,
|
||||||
paramSymbol,
|
symbol as IrValueParameterSymbol,
|
||||||
deserializeName(proto.name),
|
deserializeName(proto.name),
|
||||||
proto.index,
|
proto.index,
|
||||||
deserializeIrType(proto.type),
|
deserializeIrType(proto.type),
|
||||||
varargElementType,
|
if (proto.hasVarargElementType()) deserializeIrType(proto.varargElementType) else null,
|
||||||
proto.isCrossinline,
|
proto.isCrossinline,
|
||||||
proto.isNoinline
|
proto.isNoinline
|
||||||
).apply {
|
).apply {
|
||||||
defaultValue = if (proto.hasDefaultValue()) {
|
if (proto.hasDefaultValue())
|
||||||
val expression = deserializeExpression(proto.defaultValue)
|
defaultValue = IrExpressionBodyImpl(deserializeExpression(proto.defaultValue))
|
||||||
IrExpressionBodyImpl(expression)
|
|
||||||
} else null
|
(descriptor as? WrappedValueParameterDescriptor)?.bind(this)
|
||||||
|
(descriptor as? WrappedReceiverParameterDescriptor)?.bind(this)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return parameter
|
private fun deserializeIrClass(proto: KotlinIr.IrClass) =
|
||||||
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
|
val modality = deserializeModality(proto.modality)
|
||||||
|
|
||||||
|
symbolTable.declareClass(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||||
|
(symbol as IrClassSymbol).descriptor, modality
|
||||||
|
) {
|
||||||
|
IrClassImpl(
|
||||||
|
startOffset, endOffset, origin,
|
||||||
|
it,
|
||||||
|
deserializeName(proto.name),
|
||||||
|
deserializeClassKind(proto.kind),
|
||||||
|
deserializeVisibility(proto.visibility),
|
||||||
|
modality,
|
||||||
|
proto.isCompanion,
|
||||||
|
proto.isInner,
|
||||||
|
proto.isData,
|
||||||
|
proto.isExternal,
|
||||||
|
proto.isInline
|
||||||
|
)
|
||||||
|
}.usingParent {
|
||||||
|
proto.declarationContainer.declarationList.mapTo(declarations) { deserializeDeclaration(it) }
|
||||||
|
|
||||||
|
thisReceiver = deserializeIrValueParameter(proto.thisReceiver)
|
||||||
|
|
||||||
|
proto.typeParameters.typeParameterList.mapTo(typeParameters) { deserializeIrTypeParameter(it) }
|
||||||
|
|
||||||
|
proto.superTypeList.mapTo(superTypes) { deserializeIrType(it) }
|
||||||
|
|
||||||
|
(descriptor as? WrappedClassDescriptor)?.bind(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun <T : IrFunction> withDeserializedIrFunctionBase(
|
||||||
|
proto: KotlinIr.IrFunctionBase,
|
||||||
|
block: (IrFunctionSymbol, Int, Int, IrDeclarationOrigin) -> T
|
||||||
|
) = withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
|
block(symbol as IrFunctionSymbol, startOffset, endOffset, origin).usingParent {
|
||||||
|
proto.typeParameters.typeParameterList.mapTo(typeParameters) { deserializeIrTypeParameter(it) }
|
||||||
|
proto.valueParameterList.mapTo(valueParameters) { deserializeIrValueParameter(it) }
|
||||||
|
if (proto.hasDispatchReceiver())
|
||||||
|
dispatchReceiverParameter = deserializeIrValueParameter(proto.dispatchReceiver)
|
||||||
|
if (proto.hasExtensionReceiver())
|
||||||
|
extensionReceiverParameter = deserializeIrValueParameter(proto.extensionReceiver)
|
||||||
|
if (proto.hasBody())
|
||||||
|
body = deserializeStatement(proto.body) as IrBody
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeIrClass(
|
private fun deserializeIrFunction(proto: KotlinIr.IrFunction) =
|
||||||
proto: KotlinIr.IrClass,
|
withDeserializedIrFunctionBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
start: Int,
|
logger.log { "### deserializing IrFunction ${proto.base.name}" }
|
||||||
end: Int,
|
|
||||||
origin: IrDeclarationOrigin
|
|
||||||
): IrClass {
|
|
||||||
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrClassSymbol
|
symbolTable.declareSimpleFunction(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||||
|
symbol.descriptor
|
||||||
|
) {
|
||||||
|
IrFunctionImpl(
|
||||||
|
startOffset, endOffset, origin,
|
||||||
|
it,
|
||||||
|
deserializeName(proto.base.name),
|
||||||
|
deserializeVisibility(proto.base.visibility),
|
||||||
|
deserializeModality(proto.modality),
|
||||||
|
deserializeIrType(proto.base.returnType),
|
||||||
|
proto.base.isInline,
|
||||||
|
proto.base.isExternal,
|
||||||
|
proto.isTailrec,
|
||||||
|
proto.isSuspend
|
||||||
|
)
|
||||||
|
}.apply {
|
||||||
|
proto.overriddenList.mapTo(overriddenSymbols) { deserializeIrSymbol(it) as IrSimpleFunctionSymbol }
|
||||||
|
|
||||||
val modality = deserializeModality(proto.modality)
|
(descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this)
|
||||||
val clazz = symbolTable.declareClass(
|
}
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
}
|
||||||
symbol.descriptor, modality
|
|
||||||
) {
|
private fun deserializeIrVariable(proto: KotlinIr.IrVariable) =
|
||||||
IrClassImpl(
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
start, end, origin,
|
IrVariableImpl(
|
||||||
it,
|
startOffset, endOffset, origin,
|
||||||
|
symbol as IrVariableSymbol,
|
||||||
deserializeName(proto.name),
|
deserializeName(proto.name),
|
||||||
deserializeClassKind(proto.kind),
|
deserializeIrType(proto.type),
|
||||||
deserializeVisibility(proto.visibility),
|
proto.isVar,
|
||||||
modality,
|
proto.isConst,
|
||||||
proto.isCompanion,
|
proto.isLateinit
|
||||||
proto.isInner,
|
).apply {
|
||||||
proto.isData,
|
if (proto.hasInitializer())
|
||||||
proto.isExternal,
|
initializer = deserializeExpression(proto.initializer)
|
||||||
proto.isInline
|
|
||||||
)
|
(descriptor as? WrappedVariableDescriptor)?.bind(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proto.declarationContainer.declarationList.forEach {
|
private fun deserializeIrEnumEntry(proto: KotlinIr.IrEnumEntry): IrEnumEntry =
|
||||||
val member = deserializeDeclaration(it, clazz)
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
clazz.addMember(member)
|
symbolTable.declareEnumEntry(
|
||||||
member.parent = clazz
|
UNDEFINED_OFFSET,
|
||||||
|
UNDEFINED_OFFSET,
|
||||||
|
irrelevantOrigin,
|
||||||
|
(symbol as IrEnumEntrySymbol).descriptor
|
||||||
|
) {
|
||||||
|
IrEnumEntryImpl(startOffset, endOffset, origin, it, deserializeName(proto.name))
|
||||||
|
}.apply {
|
||||||
|
if (proto.hasCorrespondingClass())
|
||||||
|
correspondingClass = deserializeIrClass(proto.correspondingClass)
|
||||||
|
if (proto.hasInitializer())
|
||||||
|
initializerExpression = deserializeExpression(proto.initializer)
|
||||||
|
|
||||||
|
(descriptor as? WrappedEnumEntryDescriptor)?.bind(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clazz.thisReceiver = deserializeDeclaration(proto.thisReceiver, clazz) as IrValueParameter
|
private fun deserializeIrAnonymousInit(proto: KotlinIr.IrAnonymousInit) =
|
||||||
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
|
IrAnonymousInitializerImpl(startOffset, endOffset, origin, symbol as IrAnonymousInitializerSymbol).apply {
|
||||||
|
body = deserializeBlockBody(proto.body.blockBody, startOffset, endOffset)
|
||||||
|
|
||||||
val typeParameters = deserializeIrTypeParameterContainer(proto.typeParameters, clazz)
|
(descriptor as? WrappedClassDescriptor)?.bind(parentsStack.peek() as IrClass)
|
||||||
clazz.typeParameters.addAll(typeParameters)
|
}
|
||||||
|
|
||||||
val superTypes = proto.superTypeList.map { deserializeIrType(it) }
|
|
||||||
clazz.superTypes.addAll(superTypes)
|
|
||||||
|
|
||||||
return clazz
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrFunctionBase(
|
|
||||||
base: KotlinIr.IrFunctionBase,
|
|
||||||
function: IrFunctionBase,
|
|
||||||
start: Int,
|
|
||||||
end: Int,
|
|
||||||
origin: IrDeclarationOrigin
|
|
||||||
) {
|
|
||||||
|
|
||||||
function.body = if (base.hasBody()) deserializeStatement(base.body) as IrBody else null
|
|
||||||
|
|
||||||
val valueParameters = base.valueParameterList.map { deserializeDeclaration(it, function) as IrValueParameter }
|
|
||||||
function.valueParameters.addAll(valueParameters)
|
|
||||||
function.dispatchReceiverParameter = if (base.hasDispatchReceiver()) deserializeDeclaration(
|
|
||||||
base.dispatchReceiver,
|
|
||||||
function
|
|
||||||
) as IrValueParameter else null
|
|
||||||
function.extensionReceiverParameter = if (base.hasExtensionReceiver()) deserializeDeclaration(
|
|
||||||
base.extensionReceiver,
|
|
||||||
function
|
|
||||||
) as IrValueParameter else null
|
|
||||||
val typeParameters = deserializeIrTypeParameterContainer(base.typeParameters, function) // TODO
|
|
||||||
function.typeParameters.addAll(typeParameters)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrFunction(
|
|
||||||
proto: KotlinIr.IrFunction,
|
|
||||||
start: Int, end: Int, origin: IrDeclarationOrigin
|
|
||||||
): IrSimpleFunction {
|
|
||||||
|
|
||||||
logger.log { "### deserializing IrFunction ${proto.base.name}" }
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrSimpleFunctionSymbol
|
|
||||||
|
|
||||||
val function = symbolTable.declareSimpleFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
|
||||||
symbol.descriptor
|
|
||||||
) {
|
|
||||||
IrFunctionImpl(
|
|
||||||
start, end, origin, it,
|
|
||||||
deserializeName(proto.base.name),
|
|
||||||
deserializeVisibility(proto.base.visibility),
|
|
||||||
deserializeModality(proto.modality),
|
|
||||||
deserializeIrType(proto.base.returnType),
|
|
||||||
proto.base.isInline,
|
|
||||||
proto.base.isExternal,
|
|
||||||
proto.isTailrec,
|
|
||||||
proto.isSuspend
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deserializeIrFunctionBase(proto.base, function as IrFunctionBase, start, end, origin)
|
|
||||||
val overridden = proto.overriddenList.map { deserializeIrSymbol(it) as IrSimpleFunctionSymbol }
|
|
||||||
function.overriddenSymbols.addAll(overridden)
|
|
||||||
|
|
||||||
// function.correspondingProperty = correspondingProperty
|
|
||||||
|
|
||||||
return function
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrVariable(
|
|
||||||
proto: KotlinIr.IrVariable,
|
|
||||||
start: Int, end: Int, origin: IrDeclarationOrigin
|
|
||||||
): IrVariable {
|
|
||||||
|
|
||||||
val initializer = if (proto.hasInitializer()) {
|
|
||||||
deserializeExpression(proto.initializer)
|
|
||||||
} else null
|
|
||||||
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrVariableSymbol
|
|
||||||
val type = deserializeIrType(proto.type)
|
|
||||||
|
|
||||||
val variable = IrVariableImpl(
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
origin,
|
|
||||||
symbol,
|
|
||||||
deserializeName(proto.name),
|
|
||||||
type,
|
|
||||||
proto.isVar,
|
|
||||||
proto.isConst,
|
|
||||||
proto.isLateinit
|
|
||||||
)
|
|
||||||
variable.initializer = initializer
|
|
||||||
return variable
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrEnumEntry(
|
|
||||||
proto: KotlinIr.IrEnumEntry,
|
|
||||||
start: Int, end: Int, origin: IrDeclarationOrigin
|
|
||||||
): IrEnumEntry {
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrEnumEntrySymbol
|
|
||||||
|
|
||||||
val enumEntry = symbolTable.declareEnumEntry(
|
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
irrelevantOrigin,
|
|
||||||
symbol.descriptor
|
|
||||||
) {
|
|
||||||
IrEnumEntryImpl(start, end, origin, it, deserializeName(proto.name))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (proto.hasCorrespondingClass()) {
|
|
||||||
enumEntry.correspondingClass = deserializeDeclaration(proto.correspondingClass, null) as IrClass
|
|
||||||
}
|
|
||||||
if (proto.hasInitializer()) {
|
|
||||||
enumEntry.initializerExpression = deserializeExpression(proto.initializer)
|
|
||||||
}
|
|
||||||
|
|
||||||
return enumEntry
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrAnonymousInit(
|
|
||||||
proto: KotlinIr.IrAnonymousInit,
|
|
||||||
start: Int,
|
|
||||||
end: Int,
|
|
||||||
origin: IrDeclarationOrigin
|
|
||||||
): IrAnonymousInitializer {
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrAnonymousInitializerSymbol
|
|
||||||
val initializer = IrAnonymousInitializerImpl(start, end, origin, symbol)
|
|
||||||
initializer.body = deserializeBlockBody(proto.body.blockBody, start, end)
|
|
||||||
return initializer
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeVisibility(value: KotlinIr.Visibility): Visibility { // TODO: switch to enum
|
private fun deserializeVisibility(value: KotlinIr.Visibility): Visibility { // TODO: switch to enum
|
||||||
return when (deserializeString(value.name)) {
|
return when (deserializeString(value.name)) {
|
||||||
"public" -> Visibilities.PUBLIC
|
"public" -> Visibilities.PUBLIC
|
||||||
@@ -1073,50 +1031,38 @@ abstract class IrModuleDeserializer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeIrConstructor(
|
private fun deserializeIrConstructor(proto: KotlinIr.IrConstructor) =
|
||||||
proto: KotlinIr.IrConstructor,
|
withDeserializedIrFunctionBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
start: Int,
|
symbolTable.declareConstructor(
|
||||||
end: Int,
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||||
origin: IrDeclarationOrigin
|
(symbol as IrConstructorSymbol).descriptor
|
||||||
): IrConstructor {
|
) {
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrConstructorSymbol
|
IrConstructorImpl(
|
||||||
|
startOffset, endOffset, origin,
|
||||||
|
it,
|
||||||
|
deserializeName(proto.base.name),
|
||||||
|
deserializeVisibility(proto.base.visibility),
|
||||||
|
deserializeIrType(proto.base.returnType),
|
||||||
|
proto.base.isInline,
|
||||||
|
proto.base.isExternal,
|
||||||
|
proto.isPrimary
|
||||||
|
)
|
||||||
|
}.apply {
|
||||||
|
(descriptor as? WrappedClassConstructorDescriptor)?.bind(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val constructor = symbolTable.declareConstructor(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
private fun deserializeIrField(proto: KotlinIr.IrField) =
|
||||||
symbol.descriptor, {
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
IrConstructorImpl(
|
val type = deserializeIrType(proto.type)
|
||||||
start, end, origin,
|
|
||||||
it,
|
|
||||||
deserializeName(proto.base.name),
|
|
||||||
deserializeVisibility(proto.base.visibility),
|
|
||||||
deserializeIrType(proto.base.returnType),
|
|
||||||
proto.base.isInline,
|
|
||||||
proto.base.isExternal,
|
|
||||||
proto.isPrimary
|
|
||||||
)
|
|
||||||
|
|
||||||
})
|
symbolTable.declareField(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||||
deserializeIrFunctionBase(proto.base, constructor as IrFunctionBase, start, end, origin)
|
(symbol as IrFieldSymbol).descriptor,
|
||||||
return constructor
|
type
|
||||||
}
|
) {
|
||||||
|
|
||||||
private fun deserializeIrField(
|
|
||||||
proto: KotlinIr.IrField,
|
|
||||||
start: Int,
|
|
||||||
end: Int,
|
|
||||||
origin: IrDeclarationOrigin
|
|
||||||
): IrField {
|
|
||||||
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrFieldSymbol
|
|
||||||
val type = deserializeIrType(proto.type)
|
|
||||||
val field = symbolTable.declareField(UNDEFINED_OFFSET,
|
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
irrelevantOrigin,
|
|
||||||
symbol.descriptor,
|
|
||||||
type,
|
|
||||||
{
|
|
||||||
IrFieldImpl(
|
IrFieldImpl(
|
||||||
start, end, origin,
|
startOffset, endOffset, origin,
|
||||||
it,
|
it,
|
||||||
deserializeName(proto.name),
|
deserializeName(proto.name),
|
||||||
type,
|
type,
|
||||||
@@ -1125,14 +1071,13 @@ abstract class IrModuleDeserializer(
|
|||||||
proto.isExternal,
|
proto.isExternal,
|
||||||
proto.isStatic
|
proto.isStatic
|
||||||
)
|
)
|
||||||
|
}.usingParent {
|
||||||
|
if (proto.hasInitializer())
|
||||||
|
initializer = IrExpressionBodyImpl(deserializeExpression(proto.initializer))
|
||||||
|
|
||||||
|
(descriptor as? WrappedFieldDescriptor)?.bind(this)
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
val initializer = if (proto.hasInitializer()) deserializeExpression(proto.initializer) else null
|
|
||||||
field.initializer = initializer?.let { IrExpressionBodyImpl(it) }
|
|
||||||
|
|
||||||
return field
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeModality(modality: KotlinIr.ModalityKind) = when (modality) {
|
private fun deserializeModality(modality: KotlinIr.ModalityKind) = when (modality) {
|
||||||
KotlinIr.ModalityKind.OPEN_MODALITY -> Modality.OPEN
|
KotlinIr.ModalityKind.OPEN_MODALITY -> Modality.OPEN
|
||||||
@@ -1141,58 +1086,33 @@ abstract class IrModuleDeserializer(
|
|||||||
KotlinIr.ModalityKind.ABSTRACT_MODALITY -> Modality.ABSTRACT
|
KotlinIr.ModalityKind.ABSTRACT_MODALITY -> Modality.ABSTRACT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeIrLocalDelegatedProperty(
|
private fun deserializeIrLocalDelegatedProperty(proto: KotlinIr.IrLocalDelegatedProperty) =
|
||||||
proto: KotlinIr.IrLocalDelegatedProperty,
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
start: Int,
|
IrLocalDelegatedPropertyImpl(
|
||||||
end: Int,
|
startOffset, endOffset, origin,
|
||||||
origin: IrDeclarationOrigin
|
symbol as IrLocalDelegatedPropertySymbol,
|
||||||
): IrLocalDelegatedProperty {
|
deserializeName(proto.name),
|
||||||
|
deserializeIrType(proto.type),
|
||||||
|
proto.isVar
|
||||||
|
).apply {
|
||||||
|
delegate = deserializeIrVariable(proto.delegate)
|
||||||
|
getter = deserializeIrFunction(proto.getter)
|
||||||
|
if (proto.hasSetter())
|
||||||
|
setter = deserializeIrFunction(proto.setter)
|
||||||
|
|
||||||
val delegate = deserializeIrVariable(proto.delegate, start, end, origin)
|
(descriptor as? WrappedVariableDescriptorWithAccessor)?.bind(this)
|
||||||
val getter = deserializeIrFunction(proto.getter, start, end, origin)
|
}
|
||||||
val setter = if (proto.hasSetter()) deserializeIrFunction(proto.setter, start, end, origin) else null
|
|
||||||
|
|
||||||
delegate.let { (it.descriptor as? WrappedVariableDescriptor)?.bind(it) }
|
|
||||||
getter.let { (it.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(it) }
|
|
||||||
setter?.let { (it.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(it) }
|
|
||||||
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrLocalDelegatedPropertySymbol
|
|
||||||
|
|
||||||
return IrLocalDelegatedPropertyImpl(
|
|
||||||
start, end, origin,
|
|
||||||
symbol,
|
|
||||||
deserializeName(proto.name),
|
|
||||||
deserializeIrType(proto.type),
|
|
||||||
proto.isVar
|
|
||||||
).also {
|
|
||||||
it.delegate = delegate
|
|
||||||
it.getter = getter
|
|
||||||
it.setter = setter
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrProperty(
|
private fun deserializeIrProperty(proto: KotlinIr.IrProperty) =
|
||||||
proto: KotlinIr.IrProperty,
|
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
start: Int,
|
|
||||||
end: Int,
|
|
||||||
origin: IrDeclarationOrigin
|
|
||||||
): IrProperty {
|
|
||||||
|
|
||||||
val symbol = deserializeIrSymbol(proto.symbol) as IrPropertySymbol
|
|
||||||
|
|
||||||
val backingField =
|
|
||||||
if (proto.hasBackingField()) deserializeIrField(proto.backingField, start, end, origin) else null
|
|
||||||
val getter = if (proto.hasGetter()) deserializeIrFunction(proto.getter, start, end, origin) else null
|
|
||||||
val setter = if (proto.hasSetter()) deserializeIrFunction(proto.setter, start, end, origin) else null
|
|
||||||
|
|
||||||
val property =
|
|
||||||
symbolTable.declareProperty(
|
symbolTable.declareProperty(
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||||
symbol.descriptor, proto.isDelegated
|
(symbol as IrPropertySymbol).descriptor, proto.isDelegated
|
||||||
) {
|
) {
|
||||||
IrPropertyImpl(
|
IrPropertyImpl(
|
||||||
start, end, origin,
|
startOffset, endOffset, origin,
|
||||||
symbol,
|
it,
|
||||||
deserializeName(proto.name),
|
deserializeName(proto.name),
|
||||||
deserializeVisibility(proto.visibility),
|
deserializeVisibility(proto.visibility),
|
||||||
deserializeModality(proto.modality),
|
deserializeModality(proto.modality),
|
||||||
@@ -1202,44 +1122,32 @@ abstract class IrModuleDeserializer(
|
|||||||
proto.isDelegated,
|
proto.isDelegated,
|
||||||
proto.isExternal
|
proto.isExternal
|
||||||
)
|
)
|
||||||
}
|
}.apply {
|
||||||
|
if (proto.hasGetter()) {
|
||||||
|
getter = deserializeIrFunction(proto.getter).also {
|
||||||
|
it.correspondingPropertySymbol = symbol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (proto.hasSetter()) {
|
||||||
|
setter = deserializeIrFunction(proto.setter).also {
|
||||||
|
it.correspondingPropertySymbol = symbol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (proto.hasBackingField()) {
|
||||||
|
backingField = deserializeIrField(proto.backingField).also {
|
||||||
|
// A property symbol and its field symbol share the same descriptor.
|
||||||
|
// Unfortunately symbol deserialization doesn't know anything about that.
|
||||||
|
// So we can end up with two wrapped property descriptors for property and its field.
|
||||||
|
// In that case we need to bind the field's one here.
|
||||||
|
if (descriptor != it.descriptor)
|
||||||
|
(it.descriptor as? WrappedPropertyDescriptor)?.bind(this)
|
||||||
|
it.correspondingPropertySymbol = symbol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
backingField?.let {
|
(descriptor as? WrappedPropertyDescriptor)?.bind(this)
|
||||||
val descriptor = it.descriptor
|
|
||||||
when (descriptor) {
|
|
||||||
is WrappedFieldDescriptor ->
|
|
||||||
descriptor.bind(it)
|
|
||||||
is WrappedPropertyDescriptor ->
|
|
||||||
// A property symbol and its field symbol share the same descriptor.
|
|
||||||
// Unfortunately symbol deserialization doesn't know anything about that.
|
|
||||||
// So we can end up with two wrapped property descriptors for property and its field.
|
|
||||||
// In that case we need to bind the field's one here.
|
|
||||||
if (symbol.descriptor != descriptor) descriptor.bind(property)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
getter?.let { (it.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(it) }
|
|
||||||
setter?.let { (it.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(it) }
|
|
||||||
|
|
||||||
property.backingField = backingField
|
|
||||||
property.getter = getter
|
|
||||||
property.setter = setter
|
|
||||||
|
|
||||||
backingField?.let { it.correspondingPropertySymbol = symbol }
|
|
||||||
getter?.let { it.correspondingPropertySymbol = symbol }
|
|
||||||
setter?.let { it.correspondingPropertySymbol = symbol }
|
|
||||||
|
|
||||||
return property
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deserializeIrTypeAlias(
|
|
||||||
proto: KotlinIr.IrTypeAlias,
|
|
||||||
start: Int,
|
|
||||||
end: Int,
|
|
||||||
origin: IrDeclarationOrigin
|
|
||||||
): IrDeclaration {
|
|
||||||
return IrErrorDeclarationImpl(start, end, WrappedClassDescriptor())
|
|
||||||
}
|
|
||||||
|
|
||||||
private val allKnownDeclarationOrigins =
|
private val allKnownDeclarationOrigins =
|
||||||
IrDeclarationOrigin::class.nestedClasses.toList() + DeclarationFactory.FIELD_FOR_OUTER_THIS::class
|
IrDeclarationOrigin::class.nestedClasses.toList() + DeclarationFactory.FIELD_FOR_OUTER_THIS::class
|
||||||
@@ -1270,71 +1178,43 @@ abstract class IrModuleDeserializer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun deserializeDeclaration(proto: KotlinIr.IrDeclaration, parent: IrDeclarationParent?): IrDeclaration {
|
private fun deserializeDeclaration(proto: KotlinIr.IrDeclaration): IrDeclaration {
|
||||||
|
val declaration: IrDeclaration = when (proto.declaratorCase!!) {
|
||||||
val start = proto.coordinates.startOffset
|
|
||||||
val end = proto.coordinates.endOffset
|
|
||||||
val origin = deserializeIrDeclarationOrigin(proto.origin)
|
|
||||||
|
|
||||||
val declarator = proto.declarator
|
|
||||||
|
|
||||||
val declaration: IrDeclaration = when (declarator.declaratorCase!!) {
|
|
||||||
IR_ANONYMOUS_INIT
|
IR_ANONYMOUS_INIT
|
||||||
-> deserializeIrAnonymousInit(declarator.irAnonymousInit, start, end, origin)
|
-> deserializeIrAnonymousInit(proto.irAnonymousInit)
|
||||||
IR_CONSTRUCTOR
|
IR_CONSTRUCTOR
|
||||||
-> deserializeIrConstructor(declarator.irConstructor, start, end, origin)
|
-> deserializeIrConstructor(proto.irConstructor)
|
||||||
IR_FIELD
|
IR_FIELD
|
||||||
-> deserializeIrField(declarator.irField, start, end, origin)
|
-> deserializeIrField(proto.irField)
|
||||||
IR_CLASS
|
IR_CLASS
|
||||||
-> deserializeIrClass(declarator.irClass, start, end, origin)
|
-> deserializeIrClass(proto.irClass)
|
||||||
IR_FUNCTION
|
IR_FUNCTION
|
||||||
-> deserializeIrFunction(declarator.irFunction, start, end, origin)
|
-> deserializeIrFunction(proto.irFunction)
|
||||||
IR_PROPERTY
|
IR_PROPERTY
|
||||||
-> deserializeIrProperty(declarator.irProperty, start, end, origin)
|
-> deserializeIrProperty(proto.irProperty)
|
||||||
IR_TYPE_ALIAS
|
|
||||||
-> deserializeIrTypeAlias(declarator.irTypeAlias, start, end, origin)
|
|
||||||
IR_TYPE_PARAMETER
|
IR_TYPE_PARAMETER
|
||||||
-> deserializeIrTypeParameter(declarator.irTypeParameter, start, end, origin)
|
-> deserializeIrTypeParameter(proto.irTypeParameter)
|
||||||
IR_VARIABLE
|
IR_VARIABLE
|
||||||
-> deserializeIrVariable(declarator.irVariable, start, end, origin)
|
-> deserializeIrVariable(proto.irVariable)
|
||||||
IR_VALUE_PARAMETER
|
IR_VALUE_PARAMETER
|
||||||
-> deserializeIrValueParameter(declarator.irValueParameter, start, end, origin)
|
-> deserializeIrValueParameter(proto.irValueParameter)
|
||||||
IR_ENUM_ENTRY
|
IR_ENUM_ENTRY
|
||||||
-> deserializeIrEnumEntry(declarator.irEnumEntry, start, end, origin)
|
-> deserializeIrEnumEntry(proto.irEnumEntry)
|
||||||
IR_LOCAL_DELEGATED_PROPERTY
|
IR_LOCAL_DELEGATED_PROPERTY
|
||||||
-> deserializeIrLocalDelegatedProperty(declarator.irLocalDelegatedProperty, start, end, origin)
|
-> deserializeIrLocalDelegatedProperty(proto.irLocalDelegatedProperty)
|
||||||
DECLARATOR_NOT_SET
|
DECLARATOR_NOT_SET
|
||||||
-> error("Declaration deserialization not implemented: ${declarator.declaratorCase}")
|
-> error("Declaration deserialization not implemented: ${proto.declaratorCase}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val annotations = deserializeAnnotations(proto.annotations)
|
logger.log { "### Deserialized declaration: ${declaration.descriptor} -> ${ir2string(declaration)}" }
|
||||||
declaration.annotations.addAll(annotations)
|
|
||||||
|
|
||||||
parent?.let { declaration.parent = it }
|
|
||||||
|
|
||||||
val descriptor = declaration.descriptor
|
|
||||||
|
|
||||||
if (descriptor is WrappedDeclarationDescriptor<*>) {
|
|
||||||
when (declaration) {
|
|
||||||
is IrValueParameter ->
|
|
||||||
if (descriptor is WrappedValueParameterDescriptor) descriptor.bind(declaration)
|
|
||||||
else (descriptor as WrappedReceiverParameterDescriptor).bind(declaration)
|
|
||||||
is IrVariable -> (descriptor as WrappedVariableDescriptor).bind(declaration)
|
|
||||||
is IrTypeParameter -> (descriptor as WrappedTypeParameterDescriptor).bind(declaration)
|
|
||||||
is IrAnonymousInitializer -> (descriptor as WrappedClassDescriptor).bind(parent!! as IrClass)
|
|
||||||
is IrClass -> (descriptor as WrappedClassDescriptor).bind(declaration)
|
|
||||||
is IrConstructor -> (descriptor as WrappedClassConstructorDescriptor).bind(declaration)
|
|
||||||
is IrField -> (descriptor as WrappedFieldDescriptor).bind(declaration)
|
|
||||||
is IrProperty -> (descriptor as WrappedPropertyDescriptor).bind(declaration)
|
|
||||||
is IrEnumEntry -> (descriptor as WrappedEnumEntryDescriptor).bind(declaration)
|
|
||||||
is IrSimpleFunction -> (descriptor as WrappedSimpleFunctionDescriptor).bind(declaration)
|
|
||||||
is IrLocalDelegatedProperty -> (descriptor as WrappedVariableDescriptorWithAccessor).bind(declaration)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger.log { "### Deserialized declaration: ${descriptor} -> ${ir2string(declaration)}" }
|
|
||||||
|
|
||||||
return declaration
|
return declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deserializeDeclaration(proto: KotlinIr.IrDeclaration, parent: IrDeclarationParent) =
|
||||||
|
usingParent(parent) {
|
||||||
|
deserializeDeclaration(proto)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val irrelevantOrigin = object : IrDeclarationOriginImpl("irrelevant") {}
|
val irrelevantOrigin = object : IrDeclarationOriginImpl("irrelevant") {}
|
||||||
|
|||||||
+46
-59
@@ -342,7 +342,7 @@ open class IrModuleSerializer(
|
|||||||
|
|
||||||
private fun serializeCatch(catch: IrCatch): KotlinIr.IrCatch {
|
private fun serializeCatch(catch: IrCatch): KotlinIr.IrCatch {
|
||||||
val proto = KotlinIr.IrCatch.newBuilder()
|
val proto = KotlinIr.IrCatch.newBuilder()
|
||||||
.setCatchParameter(serializeDeclaration(catch.catchParameter))
|
.setCatchParameter(serializeIrVariable(catch.catchParameter))
|
||||||
.setResult(serializeExpression(catch.result))
|
.setResult(serializeExpression(catch.result))
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
@@ -878,9 +878,17 @@ open class IrModuleSerializer(
|
|||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun serializeIrDeclarationBase(declaration: IrDeclaration) =
|
||||||
|
KotlinIr.IrDeclarationBase.newBuilder()
|
||||||
|
.setSymbol(serializeIrSymbol((declaration as IrSymbolOwner).symbol))
|
||||||
|
.setCoordinates(serializeCoordinates(declaration.startOffset, declaration.endOffset))
|
||||||
|
.setAnnotations(serializeAnnotations(declaration.annotations))
|
||||||
|
.setOrigin(serializeIrDeclarationOrigin(declaration.origin))
|
||||||
|
.build()
|
||||||
|
|
||||||
private fun serializeIrValueParameter(parameter: IrValueParameter): KotlinIr.IrValueParameter {
|
private fun serializeIrValueParameter(parameter: IrValueParameter): KotlinIr.IrValueParameter {
|
||||||
val proto = KotlinIr.IrValueParameter.newBuilder()
|
val proto = KotlinIr.IrValueParameter.newBuilder()
|
||||||
.setSymbol(serializeIrSymbol(parameter.symbol))
|
.setBase(serializeIrDeclarationBase(parameter))
|
||||||
.setName(serializeName(parameter.name))
|
.setName(serializeName(parameter.name))
|
||||||
.setIndex(parameter.index)
|
.setIndex(parameter.index)
|
||||||
.setType(serializeIrType(parameter.type))
|
.setType(serializeIrType(parameter.type))
|
||||||
@@ -895,7 +903,7 @@ open class IrModuleSerializer(
|
|||||||
|
|
||||||
private fun serializeIrTypeParameter(parameter: IrTypeParameter): KotlinIr.IrTypeParameter {
|
private fun serializeIrTypeParameter(parameter: IrTypeParameter): KotlinIr.IrTypeParameter {
|
||||||
val proto = KotlinIr.IrTypeParameter.newBuilder()
|
val proto = KotlinIr.IrTypeParameter.newBuilder()
|
||||||
.setSymbol(serializeIrSymbol(parameter.symbol))
|
.setBase(serializeIrDeclarationBase(parameter))
|
||||||
.setName(serializeName(parameter.name))
|
.setName(serializeName(parameter.name))
|
||||||
.setIndex(parameter.index)
|
.setIndex(parameter.index)
|
||||||
.setVariance(serializeIrTypeVariance(parameter.variance))
|
.setVariance(serializeIrTypeVariance(parameter.variance))
|
||||||
@@ -909,13 +917,14 @@ open class IrModuleSerializer(
|
|||||||
private fun serializeIrTypeParameterContainer(typeParameters: List<IrTypeParameter>): KotlinIr.IrTypeParameterContainer {
|
private fun serializeIrTypeParameterContainer(typeParameters: List<IrTypeParameter>): KotlinIr.IrTypeParameterContainer {
|
||||||
val proto = KotlinIr.IrTypeParameterContainer.newBuilder()
|
val proto = KotlinIr.IrTypeParameterContainer.newBuilder()
|
||||||
typeParameters.forEach {
|
typeParameters.forEach {
|
||||||
proto.addTypeParameter(serializeDeclaration(it))
|
proto.addTypeParameter(serializeIrTypeParameter(it))
|
||||||
}
|
}
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serializeIrFunctionBase(function: IrFunction): KotlinIr.IrFunctionBase {
|
private fun serializeIrFunctionBase(function: IrFunction): KotlinIr.IrFunctionBase {
|
||||||
val proto = KotlinIr.IrFunctionBase.newBuilder()
|
val proto = KotlinIr.IrFunctionBase.newBuilder()
|
||||||
|
.setBase(serializeIrDeclarationBase(function))
|
||||||
.setName(serializeName(function.name))
|
.setName(serializeName(function.name))
|
||||||
.setVisibility(serializeVisibility(function.visibility))
|
.setVisibility(serializeVisibility(function.visibility))
|
||||||
.setIsInline(function.isInline)
|
.setIsInline(function.isInline)
|
||||||
@@ -923,11 +932,10 @@ open class IrModuleSerializer(
|
|||||||
.setReturnType(serializeIrType(function.returnType))
|
.setReturnType(serializeIrType(function.returnType))
|
||||||
.setTypeParameters(serializeIrTypeParameterContainer(function.typeParameters))
|
.setTypeParameters(serializeIrTypeParameterContainer(function.typeParameters))
|
||||||
|
|
||||||
function.dispatchReceiverParameter?.let { proto.setDispatchReceiver(serializeDeclaration(it)) }
|
function.dispatchReceiverParameter?.let { proto.setDispatchReceiver(serializeIrValueParameter(it)) }
|
||||||
function.extensionReceiverParameter?.let { proto.setExtensionReceiver(serializeDeclaration(it)) }
|
function.extensionReceiverParameter?.let { proto.setExtensionReceiver(serializeIrValueParameter(it)) }
|
||||||
function.valueParameters.forEach {
|
function.valueParameters.forEach {
|
||||||
//proto.addValueParameter(serializeIrValueParameter(it))
|
proto.addValueParameter(serializeIrValueParameter(it))
|
||||||
proto.addValueParameter(serializeDeclaration(it))
|
|
||||||
}
|
}
|
||||||
if (!bodiesOnlyForInlines || function.isInline) {
|
if (!bodiesOnlyForInlines || function.isInline) {
|
||||||
function.body?.let { proto.body = serializeStatement(it) }
|
function.body?.let { proto.body = serializeStatement(it) }
|
||||||
@@ -944,48 +952,38 @@ open class IrModuleSerializer(
|
|||||||
|
|
||||||
private fun serializeIrConstructor(declaration: IrConstructor): KotlinIr.IrConstructor =
|
private fun serializeIrConstructor(declaration: IrConstructor): KotlinIr.IrConstructor =
|
||||||
KotlinIr.IrConstructor.newBuilder()
|
KotlinIr.IrConstructor.newBuilder()
|
||||||
.setSymbol(serializeIrSymbol(declaration.symbol))
|
|
||||||
.setBase(serializeIrFunctionBase(declaration))
|
.setBase(serializeIrFunctionBase(declaration))
|
||||||
.setIsPrimary(declaration.isPrimary)
|
.setIsPrimary(declaration.isPrimary)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
private fun serializeIrFunction(declaration: IrSimpleFunction): KotlinIr.IrFunction {
|
private fun serializeIrFunction(declaration: IrSimpleFunction): KotlinIr.IrFunction {
|
||||||
val function = declaration// as IrFunctionImpl
|
|
||||||
val proto = KotlinIr.IrFunction.newBuilder()
|
val proto = KotlinIr.IrFunction.newBuilder()
|
||||||
.setSymbol(serializeIrSymbol(function.symbol))
|
.setBase(serializeIrFunctionBase(declaration))
|
||||||
.setModality(serializeModality(function.modality))
|
.setModality(serializeModality(declaration.modality))
|
||||||
.setIsTailrec(function.isTailrec)
|
.setIsTailrec(declaration.isTailrec)
|
||||||
.setIsSuspend(function.isSuspend)
|
.setIsSuspend(declaration.isSuspend)
|
||||||
|
|
||||||
function.overriddenSymbols.forEach {
|
declaration.overriddenSymbols.forEach {
|
||||||
proto.addOverridden(serializeIrSymbol(it))
|
proto.addOverridden(serializeIrSymbol(it))
|
||||||
}
|
}
|
||||||
|
|
||||||
//function.correspondingProperty?.let {
|
|
||||||
// val uniqId = declarationTable.uniqIdByDeclaration(it)
|
|
||||||
// proto.setCorrespondingProperty(protoUniqId(uniqId))
|
|
||||||
//}
|
|
||||||
|
|
||||||
val base = serializeIrFunctionBase(function)
|
|
||||||
proto.setBase(base)
|
|
||||||
|
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serializeIrAnonymousInit(declaration: IrAnonymousInitializer) = KotlinIr.IrAnonymousInit.newBuilder()
|
private fun serializeIrAnonymousInit(declaration: IrAnonymousInitializer) =
|
||||||
.setSymbol(serializeIrSymbol(declaration.symbol))
|
KotlinIr.IrAnonymousInit.newBuilder()
|
||||||
.setBody(serializeStatement(declaration.body))
|
.setBase(serializeIrDeclarationBase(declaration))
|
||||||
.build()
|
.setBody(serializeStatement(declaration.body))
|
||||||
|
.build()
|
||||||
|
|
||||||
private fun serializeIrLocalDelegatedProperty(variable: IrLocalDelegatedProperty): KotlinIr.IrLocalDelegatedProperty {
|
private fun serializeIrLocalDelegatedProperty(variable: IrLocalDelegatedProperty): KotlinIr.IrLocalDelegatedProperty {
|
||||||
|
|
||||||
val proto = KotlinIr.IrLocalDelegatedProperty.newBuilder()
|
val proto = KotlinIr.IrLocalDelegatedProperty.newBuilder()
|
||||||
|
.setBase(serializeIrDeclarationBase(variable))
|
||||||
.setName(serializeString(variable.name.toString()))
|
.setName(serializeString(variable.name.toString()))
|
||||||
.setIsVar(variable.isVar)
|
.setIsVar(variable.isVar)
|
||||||
.setType(serializeIrType(variable.type))
|
.setType(serializeIrType(variable.type))
|
||||||
.setDelegate(serializeIrVariable(variable.delegate))
|
.setDelegate(serializeIrVariable(variable.delegate))
|
||||||
.setGetter(serializeIrFunction(variable.getter as IrSimpleFunction)) // TODO: can it be non simple?
|
.setGetter(serializeIrFunction(variable.getter as IrSimpleFunction)) // TODO: can it be non simple?
|
||||||
.setSymbol(serializeIrSymbol(variable.symbol))
|
|
||||||
|
|
||||||
variable.setter?.let { proto.setSetter(serializeIrFunction(it as IrSimpleFunction)) } // TODO: ditto.
|
variable.setter?.let { proto.setSetter(serializeIrFunction(it as IrSimpleFunction)) } // TODO: ditto.
|
||||||
|
|
||||||
@@ -996,6 +994,7 @@ open class IrModuleSerializer(
|
|||||||
declarationTable.uniqIdByDeclaration(property)
|
declarationTable.uniqIdByDeclaration(property)
|
||||||
|
|
||||||
val proto = KotlinIr.IrProperty.newBuilder()
|
val proto = KotlinIr.IrProperty.newBuilder()
|
||||||
|
.setBase(serializeIrDeclarationBase(property))
|
||||||
.setIsDelegated(property.isDelegated)
|
.setIsDelegated(property.isDelegated)
|
||||||
.setName(serializeName(property.name))
|
.setName(serializeName(property.name))
|
||||||
.setVisibility(serializeVisibility(property.visibility))
|
.setVisibility(serializeVisibility(property.visibility))
|
||||||
@@ -1005,7 +1004,6 @@ open class IrModuleSerializer(
|
|||||||
.setIsLateinit(property.isLateinit)
|
.setIsLateinit(property.isLateinit)
|
||||||
.setIsDelegated(property.isDelegated)
|
.setIsDelegated(property.isDelegated)
|
||||||
.setIsExternal(property.isExternal)
|
.setIsExternal(property.isExternal)
|
||||||
.setSymbol(serializeIrSymbol(property.symbol))
|
|
||||||
|
|
||||||
val backingField = property.backingField
|
val backingField = property.backingField
|
||||||
val getter = property.getter
|
val getter = property.getter
|
||||||
@@ -1022,7 +1020,7 @@ open class IrModuleSerializer(
|
|||||||
|
|
||||||
private fun serializeIrField(field: IrField): KotlinIr.IrField {
|
private fun serializeIrField(field: IrField): KotlinIr.IrField {
|
||||||
val proto = KotlinIr.IrField.newBuilder()
|
val proto = KotlinIr.IrField.newBuilder()
|
||||||
.setSymbol(serializeIrSymbol(field.symbol))
|
.setBase(serializeIrDeclarationBase(field))
|
||||||
.setName(serializeName(field.name))
|
.setName(serializeName(field.name))
|
||||||
.setVisibility(serializeVisibility(field.visibility))
|
.setVisibility(serializeVisibility(field.visibility))
|
||||||
.setIsFinal(field.isFinal)
|
.setIsFinal(field.isFinal)
|
||||||
@@ -1038,7 +1036,7 @@ open class IrModuleSerializer(
|
|||||||
|
|
||||||
private fun serializeIrVariable(variable: IrVariable): KotlinIr.IrVariable {
|
private fun serializeIrVariable(variable: IrVariable): KotlinIr.IrVariable {
|
||||||
val proto = KotlinIr.IrVariable.newBuilder()
|
val proto = KotlinIr.IrVariable.newBuilder()
|
||||||
.setSymbol(serializeIrSymbol(variable.symbol))
|
.setBase(serializeIrDeclarationBase(variable))
|
||||||
.setName(serializeName(variable.name))
|
.setName(serializeName(variable.name))
|
||||||
.setType(serializeIrType(variable.type))
|
.setType(serializeIrType(variable.type))
|
||||||
.setIsConst(variable.isConst)
|
.setIsConst(variable.isConst)
|
||||||
@@ -1068,8 +1066,8 @@ open class IrModuleSerializer(
|
|||||||
|
|
||||||
private fun serializeIrClass(clazz: IrClass): KotlinIr.IrClass {
|
private fun serializeIrClass(clazz: IrClass): KotlinIr.IrClass {
|
||||||
val proto = KotlinIr.IrClass.newBuilder()
|
val proto = KotlinIr.IrClass.newBuilder()
|
||||||
|
.setBase(serializeIrDeclarationBase(clazz))
|
||||||
.setName(serializeName(clazz.name))
|
.setName(serializeName(clazz.name))
|
||||||
.setSymbol(serializeIrSymbol(clazz.symbol))
|
|
||||||
.setKind(serializeClassKind(clazz.kind))
|
.setKind(serializeClassKind(clazz.kind))
|
||||||
.setVisibility(serializeVisibility(clazz.visibility))
|
.setVisibility(serializeVisibility(clazz.visibility))
|
||||||
.setModality(serializeModality(clazz.modality))
|
.setModality(serializeModality(clazz.modality))
|
||||||
@@ -1083,21 +1081,21 @@ open class IrModuleSerializer(
|
|||||||
clazz.superTypes.forEach {
|
clazz.superTypes.forEach {
|
||||||
proto.addSuperType(serializeIrType(it))
|
proto.addSuperType(serializeIrType(it))
|
||||||
}
|
}
|
||||||
clazz.thisReceiver?.let { proto.thisReceiver = serializeDeclaration(it) }
|
clazz.thisReceiver?.let { proto.thisReceiver = serializeIrValueParameter(it) }
|
||||||
|
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serializeIrEnumEntry(enumEntry: IrEnumEntry): KotlinIr.IrEnumEntry {
|
private fun serializeIrEnumEntry(enumEntry: IrEnumEntry): KotlinIr.IrEnumEntry {
|
||||||
val proto = KotlinIr.IrEnumEntry.newBuilder()
|
val proto = KotlinIr.IrEnumEntry.newBuilder()
|
||||||
|
.setBase(serializeIrDeclarationBase(enumEntry))
|
||||||
.setName(serializeName(enumEntry.name))
|
.setName(serializeName(enumEntry.name))
|
||||||
.setSymbol(serializeIrSymbol(enumEntry.symbol))
|
|
||||||
|
|
||||||
enumEntry.initializerExpression?.let {
|
enumEntry.initializerExpression?.let {
|
||||||
proto.initializer = serializeExpression(it)
|
proto.initializer = serializeExpression(it)
|
||||||
}
|
}
|
||||||
enumEntry.correspondingClass?.let {
|
enumEntry.correspondingClass?.let {
|
||||||
proto.correspondingClass = serializeDeclaration(it)
|
proto.correspondingClass = serializeIrClass(it)
|
||||||
}
|
}
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
@@ -1105,46 +1103,35 @@ open class IrModuleSerializer(
|
|||||||
private fun serializeDeclaration(declaration: IrDeclaration): KotlinIr.IrDeclaration {
|
private fun serializeDeclaration(declaration: IrDeclaration): KotlinIr.IrDeclaration {
|
||||||
logger.log { "### serializing Declaration: ${ir2string(declaration)}" }
|
logger.log { "### serializing Declaration: ${ir2string(declaration)}" }
|
||||||
|
|
||||||
val declarator = KotlinIr.IrDeclarator.newBuilder()
|
val proto = KotlinIr.IrDeclaration.newBuilder()
|
||||||
|
|
||||||
when (declaration) {
|
when (declaration) {
|
||||||
is IrAnonymousInitializer ->
|
is IrAnonymousInitializer ->
|
||||||
declarator.irAnonymousInit = serializeIrAnonymousInit(declaration)
|
proto.irAnonymousInit = serializeIrAnonymousInit(declaration)
|
||||||
is IrConstructor ->
|
is IrConstructor ->
|
||||||
declarator.irConstructor = serializeIrConstructor(declaration)
|
proto.irConstructor = serializeIrConstructor(declaration)
|
||||||
is IrField ->
|
is IrField ->
|
||||||
declarator.irField = serializeIrField(declaration)
|
proto.irField = serializeIrField(declaration)
|
||||||
is IrSimpleFunction ->
|
is IrSimpleFunction ->
|
||||||
declarator.irFunction = serializeIrFunction(declaration)
|
proto.irFunction = serializeIrFunction(declaration)
|
||||||
is IrTypeParameter ->
|
is IrTypeParameter ->
|
||||||
declarator.irTypeParameter = serializeIrTypeParameter(declaration)
|
proto.irTypeParameter = serializeIrTypeParameter(declaration)
|
||||||
is IrVariable ->
|
is IrVariable ->
|
||||||
declarator.irVariable = serializeIrVariable(declaration)
|
proto.irVariable = serializeIrVariable(declaration)
|
||||||
is IrValueParameter ->
|
is IrValueParameter ->
|
||||||
declarator.irValueParameter = serializeIrValueParameter(declaration)
|
proto.irValueParameter = serializeIrValueParameter(declaration)
|
||||||
is IrClass ->
|
is IrClass ->
|
||||||
declarator.irClass = serializeIrClass(declaration)
|
proto.irClass = serializeIrClass(declaration)
|
||||||
is IrEnumEntry ->
|
is IrEnumEntry ->
|
||||||
declarator.irEnumEntry = serializeIrEnumEntry(declaration)
|
proto.irEnumEntry = serializeIrEnumEntry(declaration)
|
||||||
is IrProperty ->
|
is IrProperty ->
|
||||||
declarator.irProperty = serializeIrProperty(declaration)
|
proto.irProperty = serializeIrProperty(declaration)
|
||||||
is IrLocalDelegatedProperty ->
|
is IrLocalDelegatedProperty ->
|
||||||
declarator.irLocalDelegatedProperty = serializeIrLocalDelegatedProperty(declaration)
|
proto.irLocalDelegatedProperty = serializeIrLocalDelegatedProperty(declaration)
|
||||||
else
|
else
|
||||||
-> TODO("Declaration serialization not supported yet: $declaration")
|
-> TODO("Declaration serialization not supported yet: $declaration")
|
||||||
}
|
}
|
||||||
|
|
||||||
val coordinates = serializeCoordinates(declaration.startOffset, declaration.endOffset)
|
|
||||||
val annotations = serializeAnnotations(declaration.annotations)
|
|
||||||
val origin = serializeIrDeclarationOrigin(declaration.origin)
|
|
||||||
val proto = KotlinIr.IrDeclaration.newBuilder()
|
|
||||||
.setCoordinates(coordinates)
|
|
||||||
.setAnnotations(annotations)
|
|
||||||
.setOrigin(origin)
|
|
||||||
|
|
||||||
|
|
||||||
proto.setDeclarator(declarator)
|
|
||||||
|
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2893
-3548
File diff suppressed because it is too large
Load Diff
+1
-4
@@ -271,9 +271,7 @@ abstract class KotlinIrLinker(
|
|||||||
val files = proto.fileList.map {
|
val files = proto.fileList.map {
|
||||||
deserializeIrFile(it)
|
deserializeIrFile(it)
|
||||||
}
|
}
|
||||||
val module = IrModuleFragmentImpl(moduleDescriptor, builtIns, files)
|
return IrModuleFragmentImpl(moduleDescriptor, builtIns, files)
|
||||||
module.patchDeclarationParents(null)
|
|
||||||
return module
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +360,6 @@ abstract class KotlinIrLinker(
|
|||||||
val reachable = deserializeTopLevelDeclaration(key)
|
val reachable = deserializeTopLevelDeclaration(key)
|
||||||
val file = reversedFileIndex[key]!!
|
val file = reversedFileIndex[key]!!
|
||||||
file.declarations.add(reachable)
|
file.declarations.add(reachable)
|
||||||
reachable.patchDeclarationParents(file)
|
|
||||||
deserializeFileAnnotationsIfFirstUse(moduleOfOrigin, file)
|
deserializeFileAnnotationsIfFirstUse(moduleOfOrigin, file)
|
||||||
|
|
||||||
reachableTopLevels.remove(key)
|
reachableTopLevels.remove(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user