IR serialization: migrate to new generated Java classes structure
This commit is contained in:
+221
-142
@@ -12,14 +12,14 @@ 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.IrDeclaration.DeclaratorCase.*
|
||||
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.IrType.KindCase.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrTypeArgument.KindCase.STAR
|
||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrTypeArgument.KindCase.TYPE
|
||||
import org.jetbrains.kotlin.backend.common.serialization.KotlinIr.IrVarargElement.VarargElementCase
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrConst.ValueCase.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDeclaration.DeclaratorCase.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrOperation.OperationCase.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrStatement.StatementCase
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrType.KindCase.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeArgument.KindCase.STAR
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeArgument.KindCase.TYPE
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrVarargElement.VarargElementCase
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
@@ -31,13 +31,92 @@ import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.IrDynamicType
|
||||
import org.jetbrains.kotlin.ir.types.IrErrorType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.*
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.Annotations as ProtoAnnotations
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.ClassKind as ProtoClassKind
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.DescriptorReference as ProtoDescriptorReference
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrAnonymousInit as ProtoAnonymousInit
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrBlock as ProtoBlock
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrBlockBody as ProtoBlockBody
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrBranch as ProtoBranch
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrBreak as ProtoBreak
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrCall as ProtoCall
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrCatch as ProtoCatch
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrClass as ProtoClass
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrClassReference as ProtoClassReference
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrComposite as ProtoComposite
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrConst as ProtoConst
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrConstructor as ProtoConstructor
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrConstructorCall as ProtoConstructorCall
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrContinue as ProtoContinue
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDeclaration as ProtoDeclaration
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDeclarationBase as ProtoDeclarationBase
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDeclarationOrigin as ProtoDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDelegatingConstructorCall as ProtoDelegatingConstructorCall
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDoWhile as ProtoDoWhile
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDynamicMemberExpression as ProtoDynamicMemberExpression
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDynamicOperatorExpression as ProtoDynamicOperatorExpression
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDynamicType as ProtoDynamicType
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrEnumConstructorCall as ProtoEnumConstructorCall
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrEnumEntry as ProtoEnumEntry
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrErrorType as ProtoErrorType
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrExpression as ProtoExpression
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrField as ProtoField
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrFunction as ProtoFunction
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrFunctionBase as ProtoFunctionBase
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrFunctionReference as ProtoFunctionReference
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrGetClass as ProtoGetClass
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrGetEnumValue as ProtoGetEnumValue
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrGetField as ProtoGetField
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrGetObject as ProtoGetObject
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrGetValue as ProtoGetValue
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrInstanceInitializerCall as ProtoInstanceInitializerCall
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrLocalDelegatedProperty as ProtoLocalDelegatedProperty
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrLocalDelegatedPropertyReference as ProtoLocalDelegatedPropertyReference
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrOperation as ProtoOperation
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrProperty as ProtoProperty
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrPropertyReference as ProtoPropertyReference
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrReturn as ProtoReturn
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSetField as ProtoSetField
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSetVariable as ProtoSetVariable
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSimpleType as ProtoSimpleType
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSpreadElement as ProtoSpreadElement
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrStatement as ProtoStatement
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrStatementOrigin as ProtoStatementOrigin
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrStringConcat as ProtoStringConcat
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSymbol as ProtoSymbol
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSyntheticBody as ProtoSyntheticBody
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSyntheticBodyKind as ProtoSyntheticBodyKind
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrThrow as ProtoThrow
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTry as ProtoTry
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrType as ProtoType
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeArgument as ProtoTypeArgument
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeIndex as ProtoTypeIndex
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeOp as ProtoTypeOp
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeOperator as ProtoTypeOperator
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeParameter as ProtoTypeParameter
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeVariance as ProtoTypeVariance
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrValueParameter as ProtoValueParameter
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrVararg as ProtoVararg
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrVarargElement as ProtoVarargElement
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrVariable as ProtoVariable
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrWhen as ProtoWhen
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrWhile as ProtoWhile
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.Loop as ProtoLoop
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.MemberAccessCommon as ProtoMemberAccessCommon
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.ModalityKind as ProtoModalityKind
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.String as ProtoString
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.TypeArguments as ProtoTypeArguments
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.Visibility as ProtoVisibility
|
||||
|
||||
// TODO: This code still has some uses of descriptors:
|
||||
// 1. We use descriptors as keys for symbolTable -- probably symbol table related code should be refactored out from
|
||||
@@ -51,20 +130,20 @@ abstract class IrModuleDeserializer(
|
||||
val symbolTable: SymbolTable
|
||||
) {
|
||||
|
||||
abstract fun deserializeIrSymbol(proto: KotlinIr.IrSymbol): IrSymbol
|
||||
abstract fun deserializeIrType(proto: KotlinIr.IrTypeIndex): IrType
|
||||
abstract fun deserializeDescriptorReference(proto: KotlinIr.DescriptorReference): DeclarationDescriptor
|
||||
abstract fun deserializeString(proto: KotlinIr.String): String
|
||||
abstract fun deserializeIrSymbol(proto: ProtoSymbol): IrSymbol
|
||||
abstract fun deserializeIrType(proto: ProtoTypeIndex): IrType
|
||||
abstract fun deserializeDescriptorReference(proto: ProtoDescriptorReference): DeclarationDescriptor
|
||||
abstract fun deserializeString(proto: ProtoString): String
|
||||
abstract fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoopBase): IrLoopBase
|
||||
|
||||
private val parentsStack = mutableListOf<IrDeclarationParent>()
|
||||
|
||||
private fun deserializeName(proto: KotlinIr.String): Name {
|
||||
private fun deserializeName(proto: ProtoString): Name {
|
||||
val name = deserializeString(proto)
|
||||
return Name.guessByFirstCharacter(name)
|
||||
}
|
||||
|
||||
private fun deserializeTypeArguments(proto: KotlinIr.TypeArguments): List<IrType> {
|
||||
private fun deserializeTypeArguments(proto: ProtoTypeArguments): List<IrType> {
|
||||
logger.log { "### deserializeTypeArguments" }
|
||||
val result = mutableListOf<IrType>()
|
||||
proto.typeArgumentList.forEach { typeProto ->
|
||||
@@ -75,13 +154,13 @@ abstract class IrModuleDeserializer(
|
||||
return result
|
||||
}
|
||||
|
||||
fun deserializeIrTypeVariance(variance: KotlinIr.IrTypeVariance) = when (variance) {
|
||||
KotlinIr.IrTypeVariance.IN -> Variance.IN_VARIANCE
|
||||
KotlinIr.IrTypeVariance.OUT -> Variance.OUT_VARIANCE
|
||||
KotlinIr.IrTypeVariance.INV -> Variance.INVARIANT
|
||||
fun deserializeIrTypeVariance(variance: ProtoTypeVariance) = when (variance) {
|
||||
ProtoTypeVariance.IN -> Variance.IN_VARIANCE
|
||||
ProtoTypeVariance.OUT -> Variance.OUT_VARIANCE
|
||||
ProtoTypeVariance.INV -> Variance.INVARIANT
|
||||
}
|
||||
|
||||
fun deserializeIrTypeArgument(proto: KotlinIr.IrTypeArgument) = when (proto.kindCase) {
|
||||
fun deserializeIrTypeArgument(proto: ProtoTypeArgument) = when (proto.kindCase) {
|
||||
STAR -> IrStarProjectionImpl
|
||||
TYPE -> makeTypeProjection(
|
||||
deserializeIrType(proto.type.type), deserializeIrTypeVariance(proto.type.variance)
|
||||
@@ -90,7 +169,7 @@ abstract class IrModuleDeserializer(
|
||||
|
||||
}
|
||||
|
||||
fun deserializeAnnotations(annotations: KotlinIr.Annotations): List<IrConstructorCall> {
|
||||
fun deserializeAnnotations(annotations: ProtoAnnotations): List<IrConstructorCall> {
|
||||
return annotations.annotationList.map {
|
||||
deserializeConstructorCall(it, 0, 0, builtIns.unitType) // TODO: need a proper deserialization here
|
||||
}
|
||||
@@ -98,7 +177,7 @@ abstract class IrModuleDeserializer(
|
||||
|
||||
open fun getPrimitiveTypeOrNull(symbol: IrClassifierSymbol, hasQuestionMark: Boolean): IrSimpleType? = null
|
||||
|
||||
fun deserializeSimpleType(proto: KotlinIr.IrSimpleType): IrSimpleType {
|
||||
fun deserializeSimpleType(proto: ProtoSimpleType): IrSimpleType {
|
||||
val symbol = deserializeIrSymbol(proto.classifier) as? IrClassifierSymbol
|
||||
?: error("could not convert sym to ClassifierSymbol")
|
||||
logger.log { "deserializeSimpleType: symbol=$symbol" }
|
||||
@@ -119,17 +198,17 @@ abstract class IrModuleDeserializer(
|
||||
|
||||
}
|
||||
|
||||
fun deserializeDynamicType(proto: KotlinIr.IrDynamicType): IrDynamicType {
|
||||
fun deserializeDynamicType(proto: ProtoDynamicType): IrDynamicType {
|
||||
val annotations = deserializeAnnotations(proto.annotations)
|
||||
return IrDynamicTypeImpl(null, annotations, Variance.INVARIANT)
|
||||
}
|
||||
|
||||
fun deserializeErrorType(proto: KotlinIr.IrErrorType): IrErrorType {
|
||||
fun deserializeErrorType(proto: ProtoErrorType): IrErrorType {
|
||||
val annotations = deserializeAnnotations(proto.annotations)
|
||||
return IrErrorTypeImpl(null, annotations, Variance.INVARIANT)
|
||||
}
|
||||
|
||||
fun deserializeIrTypeData(proto: KotlinIr.IrType): IrType {
|
||||
fun deserializeIrTypeData(proto: ProtoType): IrType {
|
||||
return when (proto.kindCase) {
|
||||
SIMPLE -> deserializeSimpleType(proto.simple)
|
||||
DYNAMIC -> deserializeDynamicType(proto.dynamic)
|
||||
@@ -141,7 +220,7 @@ abstract class IrModuleDeserializer(
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
private fun deserializeBlockBody(
|
||||
proto: KotlinIr.IrBlockBody,
|
||||
proto: ProtoBlockBody,
|
||||
start: Int, end: Int
|
||||
): IrBlockBody {
|
||||
|
||||
@@ -155,7 +234,7 @@ abstract class IrModuleDeserializer(
|
||||
return IrBlockBodyImpl(start, end, statements)
|
||||
}
|
||||
|
||||
private fun deserializeBranch(proto: KotlinIr.IrBranch, start: Int, end: Int): IrBranch {
|
||||
private fun deserializeBranch(proto: ProtoBranch, start: Int, end: Int): IrBranch {
|
||||
|
||||
val condition = deserializeExpression(proto.condition)
|
||||
val result = deserializeExpression(proto.result)
|
||||
@@ -163,22 +242,22 @@ abstract class IrModuleDeserializer(
|
||||
return IrBranchImpl(start, end, condition, result)
|
||||
}
|
||||
|
||||
private fun deserializeCatch(proto: KotlinIr.IrCatch, start: Int, end: Int): IrCatch {
|
||||
private fun deserializeCatch(proto: ProtoCatch, start: Int, end: Int): IrCatch {
|
||||
val catchParameter = deserializeIrVariable(proto.catchParameter)
|
||||
val result = deserializeExpression(proto.result)
|
||||
|
||||
return IrCatchImpl(start, end, catchParameter, result)
|
||||
}
|
||||
|
||||
private fun deserializeSyntheticBody(proto: KotlinIr.IrSyntheticBody, start: Int, end: Int): IrSyntheticBody {
|
||||
private fun deserializeSyntheticBody(proto: ProtoSyntheticBody, start: Int, end: Int): IrSyntheticBody {
|
||||
val kind = when (proto.kind!!) {
|
||||
KotlinIr.IrSyntheticBodyKind.ENUM_VALUES -> IrSyntheticBodyKind.ENUM_VALUES
|
||||
KotlinIr.IrSyntheticBodyKind.ENUM_VALUEOF -> IrSyntheticBodyKind.ENUM_VALUEOF
|
||||
ProtoSyntheticBodyKind.ENUM_VALUES -> IrSyntheticBodyKind.ENUM_VALUES
|
||||
ProtoSyntheticBodyKind.ENUM_VALUEOF -> IrSyntheticBodyKind.ENUM_VALUEOF
|
||||
}
|
||||
return IrSyntheticBodyImpl(start, end, kind)
|
||||
}
|
||||
|
||||
private fun deserializeStatement(proto: KotlinIr.IrStatement): IrElement {
|
||||
private fun deserializeStatement(proto: ProtoStatement): IrElement {
|
||||
val start = proto.coordinates.startOffset
|
||||
val end = proto.coordinates.endOffset
|
||||
val element = when (proto.statementCase) {
|
||||
@@ -203,7 +282,7 @@ abstract class IrModuleDeserializer(
|
||||
return element
|
||||
}
|
||||
|
||||
private fun deserializeBlock(proto: KotlinIr.IrBlock, start: Int, end: Int, type: IrType): IrBlock {
|
||||
private fun deserializeBlock(proto: ProtoBlock, start: Int, end: Int, type: IrType): IrBlock {
|
||||
val statements = mutableListOf<IrStatement>()
|
||||
val statementProtos = proto.statementList
|
||||
val origin = if (proto.hasOrigin()) deserializeIrStatementOrigin(proto.origin) else null
|
||||
@@ -215,7 +294,7 @@ abstract class IrModuleDeserializer(
|
||||
return IrBlockImpl(start, end, type, origin, statements)
|
||||
}
|
||||
|
||||
private fun deserializeMemberAccessCommon(access: IrMemberAccessExpression, proto: KotlinIr.MemberAccessCommon) {
|
||||
private fun deserializeMemberAccessCommon(access: IrMemberAccessExpression, proto: ProtoMemberAccessCommon) {
|
||||
|
||||
proto.valueArgumentList.mapIndexed { i, arg ->
|
||||
if (arg.hasExpression()) {
|
||||
@@ -237,7 +316,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeClassReference(
|
||||
proto: KotlinIr.IrClassReference,
|
||||
proto: ProtoClassReference,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -248,7 +327,7 @@ abstract class IrModuleDeserializer(
|
||||
return IrClassReferenceImpl(start, end, type, symbol, classType)
|
||||
}
|
||||
|
||||
private fun deserializeConstructorCall(proto: KotlinIr.IrConstructorCall, start: Int, end: Int, type: IrType): IrConstructorCall {
|
||||
private fun deserializeConstructorCall(proto: ProtoConstructorCall, start: Int, end: Int, type: IrType): IrConstructorCall {
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrConstructorSymbol
|
||||
return IrConstructorCallImpl(
|
||||
start, end, type,
|
||||
@@ -261,7 +340,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeCall(proto: KotlinIr.IrCall, start: Int, end: Int, type: IrType): IrCall {
|
||||
private fun deserializeCall(proto: ProtoCall, start: Int, end: Int, type: IrType): IrCall {
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrFunctionSymbol
|
||||
|
||||
val superSymbol = if (proto.hasSuper()) {
|
||||
@@ -284,7 +363,7 @@ abstract class IrModuleDeserializer(
|
||||
return call
|
||||
}
|
||||
|
||||
private fun deserializeComposite(proto: KotlinIr.IrComposite, start: Int, end: Int, type: IrType): IrComposite {
|
||||
private fun deserializeComposite(proto: ProtoComposite, start: Int, end: Int, type: IrType): IrComposite {
|
||||
val statements = mutableListOf<IrStatement>()
|
||||
val statementProtos = proto.statementList
|
||||
val origin = if (proto.hasOrigin()) deserializeIrStatementOrigin(proto.origin) else null
|
||||
@@ -296,7 +375,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeDelegatingConstructorCall(
|
||||
proto: KotlinIr.IrDelegatingConstructorCall,
|
||||
proto: ProtoDelegatingConstructorCall,
|
||||
start: Int,
|
||||
end: Int
|
||||
): IrDelegatingConstructorCall {
|
||||
@@ -317,7 +396,7 @@ abstract class IrModuleDeserializer(
|
||||
|
||||
|
||||
fun deserializeEnumConstructorCall(
|
||||
proto: KotlinIr.IrEnumConstructorCall,
|
||||
proto: ProtoEnumConstructorCall,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -337,7 +416,7 @@ abstract class IrModuleDeserializer(
|
||||
|
||||
|
||||
private fun deserializeFunctionReference(
|
||||
proto: KotlinIr.IrFunctionReference,
|
||||
proto: ProtoFunctionReference,
|
||||
start: Int, end: Int, type: IrType
|
||||
): IrFunctionReference {
|
||||
|
||||
@@ -358,12 +437,12 @@ abstract class IrModuleDeserializer(
|
||||
return callable
|
||||
}
|
||||
|
||||
private fun deserializeGetClass(proto: KotlinIr.IrGetClass, start: Int, end: Int, type: IrType): IrGetClass {
|
||||
private fun deserializeGetClass(proto: ProtoGetClass, start: Int, end: Int, type: IrType): IrGetClass {
|
||||
val argument = deserializeExpression(proto.argument)
|
||||
return IrGetClassImpl(start, end, type, argument)
|
||||
}
|
||||
|
||||
private fun deserializeGetField(proto: KotlinIr.IrGetField, start: Int, end: Int, type: IrType): IrGetField {
|
||||
private fun deserializeGetField(proto: ProtoGetField, start: Int, end: Int, type: IrType): IrGetField {
|
||||
val access = proto.fieldAccess
|
||||
val symbol = deserializeIrSymbol(access.symbol) as IrFieldSymbol
|
||||
val origin = if (proto.hasOrigin()) deserializeIrStatementOrigin(proto.origin) else null
|
||||
@@ -378,7 +457,7 @@ abstract class IrModuleDeserializer(
|
||||
return IrGetFieldImpl(start, end, symbol, type, receiver, origin, superQualifier)
|
||||
}
|
||||
|
||||
private fun deserializeGetValue(proto: KotlinIr.IrGetValue, start: Int, end: Int, type: IrType): IrGetValue {
|
||||
private fun deserializeGetValue(proto: ProtoGetValue, start: Int, end: Int, type: IrType): IrGetValue {
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrValueSymbol
|
||||
val origin = if (proto.hasOrigin()) deserializeIrStatementOrigin(proto.origin) else null
|
||||
// TODO: origin!
|
||||
@@ -386,7 +465,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeGetEnumValue(
|
||||
proto: KotlinIr.IrGetEnumValue,
|
||||
proto: ProtoGetEnumValue,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -396,7 +475,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeGetObject(
|
||||
proto: KotlinIr.IrGetObject,
|
||||
proto: ProtoGetObject,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -406,7 +485,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeInstanceInitializerCall(
|
||||
proto: KotlinIr.IrInstanceInitializerCall,
|
||||
proto: ProtoInstanceInitializerCall,
|
||||
start: Int,
|
||||
end: Int
|
||||
): IrInstanceInitializerCall {
|
||||
@@ -415,7 +494,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeIrLocalDelegatedPropertyReference(
|
||||
proto: KotlinIr.IrLocalDelegatedPropertyReference,
|
||||
proto: ProtoLocalDelegatedPropertyReference,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -438,7 +517,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializePropertyReference(
|
||||
proto: KotlinIr.IrPropertyReference,
|
||||
proto: ProtoPropertyReference,
|
||||
start: Int, end: Int, type: IrType
|
||||
): IrPropertyReference {
|
||||
|
||||
@@ -462,13 +541,13 @@ abstract class IrModuleDeserializer(
|
||||
return callable
|
||||
}
|
||||
|
||||
private fun deserializeReturn(proto: KotlinIr.IrReturn, start: Int, end: Int, type: IrType): IrReturn {
|
||||
private fun deserializeReturn(proto: ProtoReturn, start: Int, end: Int, type: IrType): IrReturn {
|
||||
val symbol = deserializeIrSymbol(proto.returnTarget) as IrReturnTargetSymbol
|
||||
val value = deserializeExpression(proto.value)
|
||||
return IrReturnImpl(start, end, builtIns.nothingType, symbol, value)
|
||||
}
|
||||
|
||||
private fun deserializeSetField(proto: KotlinIr.IrSetField, start: Int, end: Int): IrSetField {
|
||||
private fun deserializeSetField(proto: ProtoSetField, start: Int, end: Int): IrSetField {
|
||||
val access = proto.fieldAccess
|
||||
val symbol = deserializeIrSymbol(access.symbol) as IrFieldSymbol
|
||||
val superQualifier = if (access.hasSuper()) {
|
||||
@@ -483,20 +562,20 @@ abstract class IrModuleDeserializer(
|
||||
return IrSetFieldImpl(start, end, symbol, receiver, value, builtIns.unitType, origin, superQualifier)
|
||||
}
|
||||
|
||||
private fun deserializeSetVariable(proto: KotlinIr.IrSetVariable, start: Int, end: Int): IrSetVariable {
|
||||
private fun deserializeSetVariable(proto: ProtoSetVariable, start: Int, end: Int): IrSetVariable {
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrVariableSymbol
|
||||
val value = deserializeExpression(proto.value)
|
||||
val origin = if (proto.hasOrigin()) deserializeIrStatementOrigin(proto.origin) else null
|
||||
return IrSetVariableImpl(start, end, builtIns.unitType, symbol, value, origin)
|
||||
}
|
||||
|
||||
private fun deserializeSpreadElement(proto: KotlinIr.IrSpreadElement): IrSpreadElement {
|
||||
private fun deserializeSpreadElement(proto: ProtoSpreadElement): IrSpreadElement {
|
||||
val expression = deserializeExpression(proto.expression)
|
||||
return IrSpreadElementImpl(proto.coordinates.startOffset, proto.coordinates.endOffset, expression)
|
||||
}
|
||||
|
||||
private fun deserializeStringConcat(
|
||||
proto: KotlinIr.IrStringConcat,
|
||||
proto: ProtoStringConcat,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -510,11 +589,11 @@ abstract class IrModuleDeserializer(
|
||||
return IrStringConcatenationImpl(start, end, type, arguments)
|
||||
}
|
||||
|
||||
private fun deserializeThrow(proto: KotlinIr.IrThrow, start: Int, end: Int, type: IrType): IrThrowImpl {
|
||||
private fun deserializeThrow(proto: ProtoThrow, start: Int, end: Int, type: IrType): IrThrowImpl {
|
||||
return IrThrowImpl(start, end, builtIns.nothingType, deserializeExpression(proto.value))
|
||||
}
|
||||
|
||||
private fun deserializeTry(proto: KotlinIr.IrTry, start: Int, end: Int, type: IrType): IrTryImpl {
|
||||
private fun deserializeTry(proto: ProtoTry, start: Int, end: Int, type: IrType): IrTryImpl {
|
||||
val result = deserializeExpression(proto.result)
|
||||
val catches = mutableListOf<IrCatch>()
|
||||
proto.catchList.forEach {
|
||||
@@ -525,30 +604,30 @@ abstract class IrModuleDeserializer(
|
||||
return IrTryImpl(start, end, type, result, catches, finallyExpression)
|
||||
}
|
||||
|
||||
private fun deserializeTypeOperator(operator: KotlinIr.IrTypeOperator) = when (operator) {
|
||||
KotlinIr.IrTypeOperator.CAST ->
|
||||
private fun deserializeTypeOperator(operator: ProtoTypeOperator) = when (operator) {
|
||||
ProtoTypeOperator.CAST ->
|
||||
IrTypeOperator.CAST
|
||||
KotlinIr.IrTypeOperator.IMPLICIT_CAST ->
|
||||
ProtoTypeOperator.IMPLICIT_CAST ->
|
||||
IrTypeOperator.IMPLICIT_CAST
|
||||
KotlinIr.IrTypeOperator.IMPLICIT_NOTNULL ->
|
||||
ProtoTypeOperator.IMPLICIT_NOTNULL ->
|
||||
IrTypeOperator.IMPLICIT_NOTNULL
|
||||
KotlinIr.IrTypeOperator.IMPLICIT_COERCION_TO_UNIT ->
|
||||
ProtoTypeOperator.IMPLICIT_COERCION_TO_UNIT ->
|
||||
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT
|
||||
KotlinIr.IrTypeOperator.IMPLICIT_INTEGER_COERCION ->
|
||||
ProtoTypeOperator.IMPLICIT_INTEGER_COERCION ->
|
||||
IrTypeOperator.IMPLICIT_INTEGER_COERCION
|
||||
KotlinIr.IrTypeOperator.SAFE_CAST ->
|
||||
ProtoTypeOperator.SAFE_CAST ->
|
||||
IrTypeOperator.SAFE_CAST
|
||||
KotlinIr.IrTypeOperator.INSTANCEOF ->
|
||||
ProtoTypeOperator.INSTANCEOF ->
|
||||
IrTypeOperator.INSTANCEOF
|
||||
KotlinIr.IrTypeOperator.NOT_INSTANCEOF ->
|
||||
ProtoTypeOperator.NOT_INSTANCEOF ->
|
||||
IrTypeOperator.NOT_INSTANCEOF
|
||||
KotlinIr.IrTypeOperator.SAM_CONVERSION ->
|
||||
ProtoTypeOperator.SAM_CONVERSION ->
|
||||
IrTypeOperator.SAM_CONVERSION
|
||||
KotlinIr.IrTypeOperator.IMPLICIT_DYNAMIC_CAST ->
|
||||
ProtoTypeOperator.IMPLICIT_DYNAMIC_CAST ->
|
||||
IrTypeOperator.IMPLICIT_DYNAMIC_CAST
|
||||
}
|
||||
|
||||
private fun deserializeTypeOp(proto: KotlinIr.IrTypeOp, start: Int, end: Int, type: IrType): IrTypeOperatorCall {
|
||||
private fun deserializeTypeOp(proto: ProtoTypeOp, start: Int, end: Int, type: IrType): IrTypeOperatorCall {
|
||||
val operator = deserializeTypeOperator(proto.operator)
|
||||
val operand = deserializeIrType(proto.operand)//.brokenIr
|
||||
val argument = deserializeExpression(proto.argument)
|
||||
@@ -557,7 +636,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeVararg(proto: KotlinIr.IrVararg, start: Int, end: Int, type: IrType): IrVararg {
|
||||
private fun deserializeVararg(proto: ProtoVararg, start: Int, end: Int, type: IrType): IrVararg {
|
||||
val elementType = deserializeIrType(proto.elementType)
|
||||
|
||||
val elements = mutableListOf<IrVarargElement>()
|
||||
@@ -567,7 +646,7 @@ abstract class IrModuleDeserializer(
|
||||
return IrVarargImpl(start, end, type, elementType, elements)
|
||||
}
|
||||
|
||||
private fun deserializeVarargElement(element: KotlinIr.IrVarargElement): IrVarargElement {
|
||||
private fun deserializeVarargElement(element: ProtoVarargElement): IrVarargElement {
|
||||
return when (element.varargElementCase) {
|
||||
VarargElementCase.EXPRESSION
|
||||
-> deserializeExpression(element.expression)
|
||||
@@ -578,7 +657,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeWhen(proto: KotlinIr.IrWhen, start: Int, end: Int, type: IrType): IrWhen {
|
||||
private fun deserializeWhen(proto: ProtoWhen, start: Int, end: Int, type: IrType): IrWhen {
|
||||
val branches = mutableListOf<IrBranch>()
|
||||
val origin = if (proto.hasOrigin()) deserializeIrStatementOrigin(proto.origin) else null
|
||||
|
||||
@@ -590,7 +669,7 @@ abstract class IrModuleDeserializer(
|
||||
return IrWhenImpl(start, end, type, origin, branches)
|
||||
}
|
||||
|
||||
private fun deserializeLoop(proto: KotlinIr.Loop, loop: IrLoopBase): IrLoopBase {
|
||||
private fun deserializeLoop(proto: ProtoLoop, loop: IrLoopBase): IrLoopBase {
|
||||
val label = if (proto.hasLabel()) deserializeString(proto.label) else null
|
||||
val body = if (proto.hasBody()) deserializeExpression(proto.body) else null
|
||||
val condition = deserializeExpression(proto.condition)
|
||||
@@ -604,20 +683,20 @@ abstract class IrModuleDeserializer(
|
||||
|
||||
// we create the loop before deserializing the body, so that
|
||||
// IrBreak statements have something to put into 'loop' field.
|
||||
private fun deserializeDoWhile(proto: KotlinIr.IrDoWhile, start: Int, end: Int, type: IrType) =
|
||||
private fun deserializeDoWhile(proto: ProtoDoWhile, start: Int, end: Int, type: IrType) =
|
||||
deserializeLoop(proto.loop, deserializeLoopHeader(proto.loop.loopId) {
|
||||
val origin = if (proto.loop.hasOrigin()) deserializeIrStatementOrigin(proto.loop.origin) else null
|
||||
IrDoWhileLoopImpl(start, end, type, origin)
|
||||
})
|
||||
|
||||
private fun deserializeWhile(proto: KotlinIr.IrWhile, start: Int, end: Int, type: IrType) =
|
||||
private fun deserializeWhile(proto: ProtoWhile, start: Int, end: Int, type: IrType) =
|
||||
deserializeLoop(proto.loop, deserializeLoopHeader(proto.loop.loopId) {
|
||||
val origin = if (proto.loop.hasOrigin()) deserializeIrStatementOrigin(proto.loop.origin) else null
|
||||
IrWhileLoopImpl(start, end, type, origin)
|
||||
})
|
||||
|
||||
private fun deserializeDynamicMemberExpression(
|
||||
proto: KotlinIr.IrDynamicMemberExpression,
|
||||
proto: ProtoDynamicMemberExpression,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -631,7 +710,7 @@ abstract class IrModuleDeserializer(
|
||||
)
|
||||
|
||||
private fun deserializeDynamicOperatorExpression(
|
||||
proto: KotlinIr.IrDynamicOperatorExpression,
|
||||
proto: ProtoDynamicOperatorExpression,
|
||||
start: Int,
|
||||
end: Int,
|
||||
type: IrType
|
||||
@@ -641,52 +720,52 @@ abstract class IrModuleDeserializer(
|
||||
proto.argumentList.mapTo(arguments) { deserializeExpression(it) }
|
||||
}
|
||||
|
||||
private fun deserializeDynamicOperator(operator: KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator) =
|
||||
private fun deserializeDynamicOperator(operator: ProtoDynamicOperatorExpression.IrDynamicOperator) =
|
||||
when (operator) {
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.UNARY_PLUS -> IrDynamicOperator.UNARY_PLUS
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.UNARY_MINUS -> IrDynamicOperator.UNARY_MINUS
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.UNARY_PLUS -> IrDynamicOperator.UNARY_PLUS
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.UNARY_MINUS -> IrDynamicOperator.UNARY_MINUS
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.EXCL -> IrDynamicOperator.EXCL
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.EXCL -> IrDynamicOperator.EXCL
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.PREFIX_INCREMENT -> IrDynamicOperator.PREFIX_INCREMENT
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.PREFIX_DECREMENT -> IrDynamicOperator.PREFIX_DECREMENT
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.PREFIX_INCREMENT -> IrDynamicOperator.PREFIX_INCREMENT
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.PREFIX_DECREMENT -> IrDynamicOperator.PREFIX_DECREMENT
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.POSTFIX_INCREMENT -> IrDynamicOperator.POSTFIX_INCREMENT
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.POSTFIX_DECREMENT -> IrDynamicOperator.POSTFIX_DECREMENT
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.POSTFIX_INCREMENT -> IrDynamicOperator.POSTFIX_INCREMENT
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.POSTFIX_DECREMENT -> IrDynamicOperator.POSTFIX_DECREMENT
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.BINARY_PLUS -> IrDynamicOperator.BINARY_PLUS
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.BINARY_MINUS -> IrDynamicOperator.BINARY_MINUS
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.MUL -> IrDynamicOperator.MUL
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.DIV -> IrDynamicOperator.DIV
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.MOD -> IrDynamicOperator.MOD
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.BINARY_PLUS -> IrDynamicOperator.BINARY_PLUS
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.BINARY_MINUS -> IrDynamicOperator.BINARY_MINUS
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.MUL -> IrDynamicOperator.MUL
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.DIV -> IrDynamicOperator.DIV
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.MOD -> IrDynamicOperator.MOD
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.GT -> IrDynamicOperator.GT
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.LT -> IrDynamicOperator.LT
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.GE -> IrDynamicOperator.GE
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.LE -> IrDynamicOperator.LE
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.GT -> IrDynamicOperator.GT
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.LT -> IrDynamicOperator.LT
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.GE -> IrDynamicOperator.GE
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.LE -> IrDynamicOperator.LE
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.EQEQ -> IrDynamicOperator.EQEQ
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.EXCLEQ -> IrDynamicOperator.EXCLEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.EQEQ -> IrDynamicOperator.EQEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.EXCLEQ -> IrDynamicOperator.EXCLEQ
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.EQEQEQ -> IrDynamicOperator.EQEQEQ
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.EXCLEQEQ -> IrDynamicOperator.EXCLEQEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.EQEQEQ -> IrDynamicOperator.EQEQEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.EXCLEQEQ -> IrDynamicOperator.EXCLEQEQ
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.ANDAND -> IrDynamicOperator.ANDAND
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.OROR -> IrDynamicOperator.OROR
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.ANDAND -> IrDynamicOperator.ANDAND
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.OROR -> IrDynamicOperator.OROR
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.EQ -> IrDynamicOperator.EQ
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.PLUSEQ -> IrDynamicOperator.PLUSEQ
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.MINUSEQ -> IrDynamicOperator.MINUSEQ
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.MULEQ -> IrDynamicOperator.MULEQ
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.DIVEQ -> IrDynamicOperator.DIVEQ
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.MODEQ -> IrDynamicOperator.MODEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.EQ -> IrDynamicOperator.EQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.PLUSEQ -> IrDynamicOperator.PLUSEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.MINUSEQ -> IrDynamicOperator.MINUSEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.MULEQ -> IrDynamicOperator.MULEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.DIVEQ -> IrDynamicOperator.DIVEQ
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.MODEQ -> IrDynamicOperator.MODEQ
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.ARRAY_ACCESS -> IrDynamicOperator.ARRAY_ACCESS
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.ARRAY_ACCESS -> IrDynamicOperator.ARRAY_ACCESS
|
||||
|
||||
KotlinIr.IrDynamicOperatorExpression.IrDynamicOperator.INVOKE -> IrDynamicOperator.INVOKE
|
||||
ProtoDynamicOperatorExpression.IrDynamicOperator.INVOKE -> IrDynamicOperator.INVOKE
|
||||
}
|
||||
|
||||
private fun deserializeBreak(proto: KotlinIr.IrBreak, start: Int, end: Int, type: IrType): IrBreak {
|
||||
private fun deserializeBreak(proto: ProtoBreak, start: Int, end: Int, type: IrType): IrBreak {
|
||||
val label = if (proto.hasLabel()) deserializeString(proto.label) else null
|
||||
val loopId = proto.loopId
|
||||
val loop = deserializeLoopHeader(loopId) { error("break clause before loop header") }
|
||||
@@ -696,7 +775,7 @@ abstract class IrModuleDeserializer(
|
||||
return irBreak
|
||||
}
|
||||
|
||||
private fun deserializeContinue(proto: KotlinIr.IrContinue, start: Int, end: Int, type: IrType): IrContinue {
|
||||
private fun deserializeContinue(proto: ProtoContinue, start: Int, end: Int, type: IrType): IrContinue {
|
||||
val label = if (proto.hasLabel()) deserializeString(proto.label) else null
|
||||
val loopId = proto.loopId
|
||||
val loop = deserializeLoopHeader(loopId) { error("continue clause before loop header") }
|
||||
@@ -706,7 +785,7 @@ abstract class IrModuleDeserializer(
|
||||
return irContinue
|
||||
}
|
||||
|
||||
private fun deserializeConst(proto: KotlinIr.IrConst, start: Int, end: Int, type: IrType): IrExpression =
|
||||
private fun deserializeConst(proto: ProtoConst, start: Int, end: Int, type: IrType): IrExpression =
|
||||
when (proto.valueCase!!) {
|
||||
NULL
|
||||
-> IrConstImpl.constNull(start, end, type)
|
||||
@@ -732,7 +811,7 @@ abstract class IrModuleDeserializer(
|
||||
-> error("Const deserialization error: ${proto.valueCase} ")
|
||||
}
|
||||
|
||||
private fun deserializeOperation(proto: KotlinIr.IrOperation, start: Int, end: Int, type: IrType): IrExpression =
|
||||
private fun deserializeOperation(proto: ProtoOperation, start: Int, end: Int, type: IrType): IrExpression =
|
||||
when (proto.operationCase!!) {
|
||||
BLOCK
|
||||
-> deserializeBlock(proto.block, start, end, type)
|
||||
@@ -802,7 +881,7 @@ abstract class IrModuleDeserializer(
|
||||
-> error("Expression deserialization not implemented: ${proto.operationCase}")
|
||||
}
|
||||
|
||||
private fun deserializeExpression(proto: KotlinIr.IrExpression): IrExpression {
|
||||
private fun deserializeExpression(proto: ProtoExpression): IrExpression {
|
||||
val start = proto.coordinates.startOffset
|
||||
val end = proto.coordinates.endOffset
|
||||
val type = deserializeIrType(proto.type)
|
||||
@@ -826,7 +905,7 @@ abstract class IrModuleDeserializer(
|
||||
this.apply { usingParent(this) { block(it) } }
|
||||
|
||||
private inline fun <T> withDeserializedIrDeclarationBase(
|
||||
proto: KotlinIr.IrDeclarationBase,
|
||||
proto: ProtoDeclarationBase,
|
||||
block: (IrSymbol, Int, Int, IrDeclarationOrigin) -> T
|
||||
): T where T : IrDeclaration, T : IrSymbolOwner {
|
||||
val result = block(
|
||||
@@ -839,7 +918,7 @@ abstract class IrModuleDeserializer(
|
||||
return result
|
||||
}
|
||||
|
||||
private fun deserializeIrTypeParameter(proto: KotlinIr.IrTypeParameter) =
|
||||
private fun deserializeIrTypeParameter(proto: ProtoTypeParameter) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
val name = deserializeName(proto.name)
|
||||
val variance = deserializeIrTypeVariance(proto.variance)
|
||||
@@ -859,16 +938,16 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeClassKind(kind: KotlinIr.ClassKind) = when (kind) {
|
||||
KotlinIr.ClassKind.CLASS -> ClassKind.CLASS
|
||||
KotlinIr.ClassKind.INTERFACE -> ClassKind.INTERFACE
|
||||
KotlinIr.ClassKind.ENUM_CLASS -> ClassKind.ENUM_CLASS
|
||||
KotlinIr.ClassKind.ENUM_ENTRY -> ClassKind.ENUM_ENTRY
|
||||
KotlinIr.ClassKind.ANNOTATION_CLASS -> ClassKind.ANNOTATION_CLASS
|
||||
KotlinIr.ClassKind.OBJECT -> ClassKind.OBJECT
|
||||
private fun deserializeClassKind(kind: ProtoClassKind) = when (kind) {
|
||||
ProtoClassKind.CLASS -> ClassKind.CLASS
|
||||
ProtoClassKind.INTERFACE -> ClassKind.INTERFACE
|
||||
ProtoClassKind.ENUM_CLASS -> ClassKind.ENUM_CLASS
|
||||
ProtoClassKind.ENUM_ENTRY -> ClassKind.ENUM_ENTRY
|
||||
ProtoClassKind.ANNOTATION_CLASS -> ClassKind.ANNOTATION_CLASS
|
||||
ProtoClassKind.OBJECT -> ClassKind.OBJECT
|
||||
}
|
||||
|
||||
private fun deserializeIrValueParameter(proto: KotlinIr.IrValueParameter) =
|
||||
private fun deserializeIrValueParameter(proto: ProtoValueParameter) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
IrValueParameterImpl(
|
||||
startOffset, endOffset, origin,
|
||||
@@ -888,7 +967,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrClass(proto: KotlinIr.IrClass) =
|
||||
private fun deserializeIrClass(proto: ProtoClass) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
val modality = deserializeModality(proto.modality)
|
||||
|
||||
@@ -923,7 +1002,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
|
||||
private inline fun <T : IrFunction> withDeserializedIrFunctionBase(
|
||||
proto: KotlinIr.IrFunctionBase,
|
||||
proto: ProtoFunctionBase,
|
||||
block: (IrFunctionSymbol, Int, Int, IrDeclarationOrigin) -> T
|
||||
) = withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
block(symbol as IrFunctionSymbol, startOffset, endOffset, origin).usingParent {
|
||||
@@ -938,7 +1017,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrFunction(proto: KotlinIr.IrFunction) =
|
||||
private fun deserializeIrFunction(proto: ProtoFunction) =
|
||||
withDeserializedIrFunctionBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
logger.log { "### deserializing IrFunction ${proto.base.name}" }
|
||||
|
||||
@@ -965,7 +1044,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrVariable(proto: KotlinIr.IrVariable) =
|
||||
private fun deserializeIrVariable(proto: ProtoVariable) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
IrVariableImpl(
|
||||
startOffset, endOffset, origin,
|
||||
@@ -983,7 +1062,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrEnumEntry(proto: KotlinIr.IrEnumEntry): IrEnumEntry =
|
||||
private fun deserializeIrEnumEntry(proto: ProtoEnumEntry): IrEnumEntry =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
symbolTable.declareEnumEntry(
|
||||
UNDEFINED_OFFSET,
|
||||
@@ -1002,7 +1081,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrAnonymousInit(proto: KotlinIr.IrAnonymousInit) =
|
||||
private fun deserializeIrAnonymousInit(proto: ProtoAnonymousInit) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
IrAnonymousInitializerImpl(startOffset, endOffset, origin, symbol as IrAnonymousInitializerSymbol).apply {
|
||||
body = deserializeBlockBody(proto.body.blockBody, startOffset, endOffset)
|
||||
@@ -1011,7 +1090,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeVisibility(value: KotlinIr.Visibility): Visibility { // TODO: switch to enum
|
||||
private fun deserializeVisibility(value: ProtoVisibility): Visibility { // TODO: switch to enum
|
||||
return when (deserializeString(value.name)) {
|
||||
"public" -> Visibilities.PUBLIC
|
||||
"private" -> Visibilities.PRIVATE
|
||||
@@ -1024,7 +1103,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrConstructor(proto: KotlinIr.IrConstructor) =
|
||||
private fun deserializeIrConstructor(proto: ProtoConstructor) =
|
||||
withDeserializedIrFunctionBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
symbolTable.declareConstructor(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||
@@ -1045,7 +1124,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrField(proto: KotlinIr.IrField) =
|
||||
private fun deserializeIrField(proto: ProtoField) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
val type = deserializeIrType(proto.type)
|
||||
|
||||
@@ -1072,14 +1151,14 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeModality(modality: KotlinIr.ModalityKind) = when (modality) {
|
||||
KotlinIr.ModalityKind.OPEN_MODALITY -> Modality.OPEN
|
||||
KotlinIr.ModalityKind.SEALED_MODALITY -> Modality.SEALED
|
||||
KotlinIr.ModalityKind.FINAL_MODALITY -> Modality.FINAL
|
||||
KotlinIr.ModalityKind.ABSTRACT_MODALITY -> Modality.ABSTRACT
|
||||
private fun deserializeModality(modality: ProtoModalityKind) = when (modality) {
|
||||
ProtoModalityKind.OPEN_MODALITY -> Modality.OPEN
|
||||
ProtoModalityKind.SEALED_MODALITY -> Modality.SEALED
|
||||
ProtoModalityKind.FINAL_MODALITY -> Modality.FINAL
|
||||
ProtoModalityKind.ABSTRACT_MODALITY -> Modality.ABSTRACT
|
||||
}
|
||||
|
||||
private fun deserializeIrLocalDelegatedProperty(proto: KotlinIr.IrLocalDelegatedProperty) =
|
||||
private fun deserializeIrLocalDelegatedProperty(proto: ProtoLocalDelegatedProperty) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
IrLocalDelegatedPropertyImpl(
|
||||
startOffset, endOffset, origin,
|
||||
@@ -1097,7 +1176,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeIrProperty(proto: KotlinIr.IrProperty) =
|
||||
private fun deserializeIrProperty(proto: ProtoProperty) =
|
||||
withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||
symbolTable.declareProperty(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||
@@ -1149,7 +1228,7 @@ abstract class IrModuleDeserializer(
|
||||
allKnownDeclarationOrigins.map { it.objectInstance as IrDeclarationOriginImpl }.associateBy { it.name }
|
||||
|
||||
|
||||
fun deserializeIrDeclarationOrigin(proto: KotlinIr.IrDeclarationOrigin): IrDeclarationOriginImpl {
|
||||
fun deserializeIrDeclarationOrigin(proto: ProtoDeclarationOrigin): IrDeclarationOriginImpl {
|
||||
val originName = deserializeString(proto.custom)
|
||||
return declarationOriginIndex[originName] ?: object : IrDeclarationOriginImpl(originName) {}
|
||||
}
|
||||
@@ -1159,7 +1238,7 @@ abstract class IrModuleDeserializer(
|
||||
val statementOriginIndex =
|
||||
allKnownStatementOrigins.map { it.objectInstance as? IrStatementOriginImpl }.filterNotNull().associateBy { it.debugName }
|
||||
|
||||
fun deserializeIrStatementOrigin(proto: KotlinIr.IrStatementOrigin): IrStatementOrigin {
|
||||
fun deserializeIrStatementOrigin(proto: ProtoStatementOrigin): IrStatementOrigin {
|
||||
return deserializeString(proto.name).let {
|
||||
val componentPrefix = "COMPONENT_"
|
||||
when {
|
||||
@@ -1171,7 +1250,7 @@ abstract class IrModuleDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeDeclaration(proto: KotlinIr.IrDeclaration): IrDeclaration {
|
||||
private fun deserializeDeclaration(proto: ProtoDeclaration): IrDeclaration {
|
||||
val declaration: IrDeclaration = when (proto.declaratorCase!!) {
|
||||
IR_ANONYMOUS_INIT
|
||||
-> deserializeIrAnonymousInit(proto.irAnonymousInit)
|
||||
@@ -1204,7 +1283,7 @@ abstract class IrModuleDeserializer(
|
||||
return declaration
|
||||
}
|
||||
|
||||
fun deserializeDeclaration(proto: KotlinIr.IrDeclaration, parent: IrDeclarationParent) =
|
||||
fun deserializeDeclaration(proto: ProtoDeclaration, parent: IrDeclarationParent) =
|
||||
usingParent(parent) {
|
||||
deserializeDeclaration(proto)
|
||||
}
|
||||
|
||||
+320
-236
File diff suppressed because it is too large
Load Diff
+46
-36
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||
@@ -28,12 +27,22 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.IrDeserializer
|
||||
import org.jetbrains.kotlin.ir.util.NaiveSourceBasedFileEntryImpl
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite.newInstance
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.Annotations as ProtoAnnotations
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.DescriptorReference as ProtoDescriptorReference
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrDeclaration as ProtoDeclaration
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrFile as ProtoFile
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrModule as ProtoModule
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSymbol as ProtoSymbol
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSymbolData as ProtoSymbolData
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSymbolKind as ProtoSymbolKind
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrType as ProtoType
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrTypeIndex as ProtoTypeIndex
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.String as ProtoString
|
||||
|
||||
abstract class KotlinIrLinker(
|
||||
val logger: LoggingContext,
|
||||
@@ -53,95 +62,95 @@ abstract class KotlinIrLinker(
|
||||
val resolvedForwardDeclarations = mutableMapOf<UniqIdKey, UniqIdKey>()
|
||||
|
||||
protected val deserializersForModules = mutableMapOf<ModuleDescriptor, IrDeserializerForModule>()
|
||||
val fileAnnotations = mutableMapOf<IrFile, KotlinIr.Annotations>()
|
||||
val fileAnnotations = mutableMapOf<IrFile, ProtoAnnotations>()
|
||||
|
||||
inner class IrDeserializerForModule(
|
||||
private val moduleDescriptor: ModuleDescriptor,
|
||||
private val moduleProto: KotlinIr.IrModule,
|
||||
private val moduleProto: ProtoModule,
|
||||
private val deserializationStrategy: DeserializationStrategy
|
||||
) : IrModuleDeserializer(logger, builtIns, symbolTable) {
|
||||
|
||||
private var moduleLoops = mutableMapOf<Int, IrLoopBase>()
|
||||
|
||||
private val symbolProtosCache = mutableMapOf<Int, KotlinIr.IrSymbolData>()
|
||||
private val typeProtosCache = mutableMapOf<Int, KotlinIr.IrType>()
|
||||
private val symbolProtosCache = mutableMapOf<Int, ProtoSymbolData>()
|
||||
private val typeProtosCache = mutableMapOf<Int, ProtoType>()
|
||||
private val stringsCache = mutableMapOf<Int, String>()
|
||||
|
||||
// This is a heavy initializer
|
||||
val module = deserializeIrModuleHeader(moduleProto)
|
||||
|
||||
private fun referenceDeserializedSymbol(
|
||||
proto: KotlinIr.IrSymbolData,
|
||||
proto: ProtoSymbolData,
|
||||
descriptor: DeclarationDescriptor?
|
||||
): IrSymbol = when (proto.kind) {
|
||||
KotlinIr.IrSymbolKind.ANONYMOUS_INIT_SYMBOL ->
|
||||
ProtoSymbolKind.ANONYMOUS_INIT_SYMBOL ->
|
||||
IrAnonymousInitializerSymbolImpl(
|
||||
descriptor as ClassDescriptor?
|
||||
?: WrappedClassDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.CLASS_SYMBOL ->
|
||||
ProtoSymbolKind.CLASS_SYMBOL ->
|
||||
symbolTable.referenceClass(
|
||||
descriptor as ClassDescriptor?
|
||||
?: WrappedClassDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.CONSTRUCTOR_SYMBOL ->
|
||||
ProtoSymbolKind.CONSTRUCTOR_SYMBOL ->
|
||||
symbolTable.referenceConstructor(
|
||||
descriptor as ClassConstructorDescriptor?
|
||||
?: WrappedClassConstructorDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.TYPE_PARAMETER_SYMBOL ->
|
||||
ProtoSymbolKind.TYPE_PARAMETER_SYMBOL ->
|
||||
symbolTable.referenceTypeParameter(
|
||||
descriptor as TypeParameterDescriptor?
|
||||
?: WrappedTypeParameterDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.ENUM_ENTRY_SYMBOL ->
|
||||
ProtoSymbolKind.ENUM_ENTRY_SYMBOL ->
|
||||
symbolTable.referenceEnumEntry(
|
||||
descriptor as ClassDescriptor?
|
||||
?: WrappedEnumEntryDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.STANDALONE_FIELD_SYMBOL ->
|
||||
ProtoSymbolKind.STANDALONE_FIELD_SYMBOL ->
|
||||
symbolTable.referenceField(WrappedFieldDescriptor())
|
||||
|
||||
KotlinIr.IrSymbolKind.FIELD_SYMBOL ->
|
||||
ProtoSymbolKind.FIELD_SYMBOL ->
|
||||
symbolTable.referenceField(
|
||||
descriptor as PropertyDescriptor?
|
||||
?: WrappedPropertyDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.FUNCTION_SYMBOL ->
|
||||
ProtoSymbolKind.FUNCTION_SYMBOL ->
|
||||
symbolTable.referenceSimpleFunction(
|
||||
descriptor as FunctionDescriptor?
|
||||
?: WrappedSimpleFunctionDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.VARIABLE_SYMBOL ->
|
||||
ProtoSymbolKind.VARIABLE_SYMBOL ->
|
||||
IrVariableSymbolImpl(
|
||||
descriptor as VariableDescriptor?
|
||||
?: WrappedVariableDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.VALUE_PARAMETER_SYMBOL ->
|
||||
ProtoSymbolKind.VALUE_PARAMETER_SYMBOL ->
|
||||
IrValueParameterSymbolImpl(
|
||||
descriptor as ParameterDescriptor?
|
||||
?: WrappedValueParameterDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.RECEIVER_PARAMETER_SYMBOL ->
|
||||
ProtoSymbolKind.RECEIVER_PARAMETER_SYMBOL ->
|
||||
IrValueParameterSymbolImpl(
|
||||
descriptor as ParameterDescriptor? ?: WrappedReceiverParameterDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.PROPERTY_SYMBOL ->
|
||||
ProtoSymbolKind.PROPERTY_SYMBOL ->
|
||||
symbolTable.referenceProperty(
|
||||
descriptor as PropertyDescriptor? ?: WrappedPropertyDescriptor()
|
||||
)
|
||||
KotlinIr.IrSymbolKind.LOCAL_DELEGATED_PROPERTY_SYMBOL ->
|
||||
ProtoSymbolKind.LOCAL_DELEGATED_PROPERTY_SYMBOL ->
|
||||
IrLocalDelegatedPropertySymbolImpl(descriptor as? VariableDescriptorWithAccessors ?: WrappedVariableDescriptorWithAccessor())
|
||||
else -> TODO("Unexpected classifier symbol kind: ${proto.kind}")
|
||||
}
|
||||
|
||||
private fun loadSymbolProto(index: Int): KotlinIr.IrSymbolData {
|
||||
private fun loadSymbolProto(index: Int): ProtoSymbolData {
|
||||
return symbolProtosCache.getOrPut(index) {
|
||||
loadSymbolProto(moduleDescriptor, index)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadTypeProto(index: Int): KotlinIr.IrType {
|
||||
private fun loadTypeProto(index: Int): ProtoType {
|
||||
return typeProtosCache.getOrPut(index) {
|
||||
loadTypeProto(moduleDescriptor, index)
|
||||
}
|
||||
@@ -153,23 +162,23 @@ abstract class KotlinIrLinker(
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserializeIrSymbol(proto: KotlinIr.IrSymbol): IrSymbol {
|
||||
override fun deserializeIrSymbol(proto: ProtoSymbol): IrSymbol {
|
||||
val symbolData = loadSymbolProto(proto.index)
|
||||
return deserializeIrSymbolData(symbolData)
|
||||
}
|
||||
|
||||
override fun deserializeIrType(proto: KotlinIr.IrTypeIndex): IrType {
|
||||
override fun deserializeIrType(proto: ProtoTypeIndex): IrType {
|
||||
val typeData = loadTypeProto(proto.index)
|
||||
return deserializeIrTypeData(typeData)
|
||||
}
|
||||
|
||||
override fun deserializeString(proto: KotlinIr.String): String =
|
||||
override fun deserializeString(proto: ProtoString): String =
|
||||
loadString(proto.index)
|
||||
|
||||
override fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoopBase) =
|
||||
moduleLoops.getOrPut(loopIndex, loopBuilder)
|
||||
|
||||
private fun deserializeIrSymbolData(proto: KotlinIr.IrSymbolData): IrSymbol {
|
||||
private fun deserializeIrSymbolData(proto: ProtoSymbolData): IrSymbol {
|
||||
val key = proto.uniqId.uniqIdKey(moduleDescriptor)
|
||||
val topLevelKey = proto.topLevelUniqId.uniqIdKey(moduleDescriptor)
|
||||
|
||||
@@ -204,7 +213,7 @@ abstract class KotlinIrLinker(
|
||||
return symbol
|
||||
}
|
||||
|
||||
override fun deserializeDescriptorReference(proto: KotlinIr.DescriptorReference) =
|
||||
override fun deserializeDescriptorReference(proto: ProtoDescriptorReference) =
|
||||
descriptorReferenceDeserializer.deserializeDescriptorReference(
|
||||
deserializeString(proto.packageFqName),
|
||||
deserializeString(proto.classFqName),
|
||||
@@ -218,11 +227,12 @@ abstract class KotlinIrLinker(
|
||||
isSetter = proto.isSetter,
|
||||
isTypeParameter = proto.isTypeParameter
|
||||
)
|
||||
|
||||
// TODO: this is JS specific. Eliminate me.
|
||||
override fun getPrimitiveTypeOrNull(symbol: IrClassifierSymbol, hasQuestionMark: Boolean) =
|
||||
this@KotlinIrLinker.getPrimitiveTypeOrNull(symbol, hasQuestionMark)
|
||||
|
||||
fun deserializeIrFile(fileProto: KotlinIr.IrFile): IrFile {
|
||||
fun deserializeIrFile(fileProto: ProtoFile): IrFile {
|
||||
|
||||
val fileEntry = NaiveSourceBasedFileEntryImpl(
|
||||
this.deserializeString(fileProto.fileEntry.name),
|
||||
@@ -266,7 +276,7 @@ abstract class KotlinIrLinker(
|
||||
}
|
||||
|
||||
fun deserializeIrModuleHeader(
|
||||
proto: KotlinIr.IrModule
|
||||
proto: ProtoModule
|
||||
): IrModuleFragment {
|
||||
val files = proto.fileList.map {
|
||||
deserializeIrFile(it)
|
||||
@@ -324,19 +334,19 @@ abstract class KotlinIrLinker(
|
||||
"[${this.joinToString { it.packageFragmentDescriptor.containingDeclaration.name.asString() }}]")
|
||||
}
|
||||
|
||||
private fun loadTopLevelDeclarationProto(uniqIdKey: UniqIdKey): KotlinIr.IrDeclaration {
|
||||
private fun loadTopLevelDeclarationProto(uniqIdKey: UniqIdKey): ProtoDeclaration {
|
||||
val stream = reader(uniqIdKey.moduleOfOrigin!!, uniqIdKey.uniqId).codedInputStream
|
||||
return KotlinIr.IrDeclaration.parseFrom(stream, newInstance())
|
||||
return ProtoDeclaration.parseFrom(stream, newInstance())
|
||||
}
|
||||
|
||||
private fun loadSymbolProto(moduleDescriptor: ModuleDescriptor, index: Int): KotlinIr.IrSymbolData {
|
||||
private fun loadSymbolProto(moduleDescriptor: ModuleDescriptor, index: Int): ProtoSymbolData {
|
||||
val stream = readSymbol(moduleDescriptor, index).codedInputStream
|
||||
return KotlinIr.IrSymbolData.parseFrom(stream, newInstance())
|
||||
return ProtoSymbolData.parseFrom(stream, newInstance())
|
||||
}
|
||||
|
||||
private fun loadTypeProto(moduleDescriptor: ModuleDescriptor, index: Int): KotlinIr.IrType {
|
||||
private fun loadTypeProto(moduleDescriptor: ModuleDescriptor, index: Int): ProtoType {
|
||||
val stream = readType(moduleDescriptor, index).codedInputStream
|
||||
return KotlinIr.IrType.parseFrom(stream, newInstance())
|
||||
return ProtoType.parseFrom(stream, newInstance())
|
||||
}
|
||||
|
||||
private fun loadString(moduleDescriptor: ModuleDescriptor, index: Int): String {
|
||||
@@ -453,7 +463,7 @@ abstract class KotlinIrLinker(
|
||||
deserializationStrategy: DeserializationStrategy = DeserializationStrategy.ONLY_REFERENCED
|
||||
): IrModuleFragment {
|
||||
val deserializerForModule = deserializersForModules.getOrPut(moduleDescriptor) {
|
||||
val proto = KotlinIr.IrModule.parseFrom(byteArray.codedInputStream, newInstance())
|
||||
val proto = ProtoModule.parseFrom(byteArray.codedInputStream, newInstance())
|
||||
IrDeserializerForModule(moduleDescriptor, proto, deserializationStrategy)
|
||||
}
|
||||
// The IrModule and its IrFiles have been created during module initialization.
|
||||
|
||||
+6
-5
@@ -5,20 +5,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.DescriptorReference as ProtoDescriptorReference
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.String as ProtoString
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.util.isAccessor
|
||||
import org.jetbrains.kotlin.ir.util.isGetter
|
||||
import org.jetbrains.kotlin.ir.util.isSetter
|
||||
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
||||
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
|
||||
|
||||
open class DescriptorReferenceSerializer(
|
||||
val declarationTable: DeclarationTable,
|
||||
val serializeString: (String) -> KotlinIr.String,
|
||||
val serializeString: (String) -> ProtoString,
|
||||
mangler: KotlinMangler): KotlinMangler by mangler {
|
||||
|
||||
private fun isEnumSpecialMember(descriptor: DeclarationDescriptor): Boolean {
|
||||
@@ -46,7 +47,7 @@ open class DescriptorReferenceSerializer(
|
||||
// Those created descriptors can't carry the uniqIdIndex, since it is available only for deserialized descriptors.
|
||||
// So we record the uniq id of some other "discoverable" descriptor for which we know for sure that it will be
|
||||
// available as deserialized descriptor, plus the path to find the needed descriptor from that one.
|
||||
fun serializeDescriptorReference(declaration: IrDeclaration): KotlinIr.DescriptorReference? {
|
||||
fun serializeDescriptorReference(declaration: IrDeclaration): ProtoDescriptorReference? {
|
||||
|
||||
val descriptor = declaration.descriptor
|
||||
|
||||
@@ -109,7 +110,7 @@ open class DescriptorReferenceSerializer(
|
||||
val uniqId = discoverableDescriptorsDeclaration?.let { declarationTable.uniqIdByDeclaration(it) }
|
||||
uniqId?.let { declarationTable.descriptors.put(discoverableDescriptorsDeclaration.descriptor, it) }
|
||||
|
||||
val proto = KotlinIr.DescriptorReference.newBuilder()
|
||||
val proto = ProtoDescriptorReference.newBuilder()
|
||||
.setPackageFqName(serializeString(packageFqName))
|
||||
.setClassFqName(serializeString(classFqName))
|
||||
.setName(serializeString(nameString))
|
||||
|
||||
+11
-10
@@ -8,11 +8,12 @@ package org.jetbrains.kotlin.backend.common.serialization
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
//import org.jetbrains.kotlin.ir.backend.js.lower.serialization.metadata.JsKlibMetadataProtoBuf
|
||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.UniqId as ProtoUniqId
|
||||
|
||||
// This is an abstract uniqIdIndex any serialized IR declarations gets.
|
||||
// It is either isLocal and then just gets and ordinary number within its module.
|
||||
// Or is visible across modules and then gets a hash of mangled name as its index.
|
||||
data class UniqId (
|
||||
data class UniqId(
|
||||
val index: Long,
|
||||
val isLocal: Boolean
|
||||
)
|
||||
@@ -28,18 +29,18 @@ data class UniqIdKey private constructor(val uniqId: UniqId, val moduleDescripto
|
||||
: this(uniqId, if (uniqId.isLocal) moduleDescriptor!! else null)
|
||||
}
|
||||
|
||||
fun protoUniqId(uniqId: UniqId): KotlinIr.UniqId =
|
||||
KotlinIr.UniqId.newBuilder()
|
||||
.setIndex(uniqId.index)
|
||||
.setIsLocal(uniqId.isLocal)
|
||||
.build()
|
||||
fun protoUniqId(uniqId: UniqId): ProtoUniqId =
|
||||
ProtoUniqId.newBuilder()
|
||||
.setIndex(uniqId.index)
|
||||
.setIsLocal(uniqId.isLocal)
|
||||
.build()
|
||||
|
||||
fun KotlinIr.UniqId.uniqId(): UniqId = UniqId(this.index, this.isLocal)
|
||||
fun KotlinIr.UniqId.uniqIdKey(moduleDescriptor: ModuleDescriptor) =
|
||||
fun ProtoUniqId.uniqId(): UniqId = UniqId(this.index, this.isLocal)
|
||||
fun ProtoUniqId.uniqIdKey(moduleDescriptor: ModuleDescriptor) =
|
||||
UniqIdKey(moduleDescriptor, this.uniqId())
|
||||
|
||||
fun <T, M:GeneratedMessageLite.ExtendableMessage<M>> M.tryGetExtension(extension: GeneratedMessageLite.GeneratedExtension<M, T>)
|
||||
= if (this.hasExtension(extension)) this.getExtension<T>(extension) else null
|
||||
fun <T, M : GeneratedMessageLite.ExtendableMessage<M>> M.tryGetExtension(extension: GeneratedMessageLite.GeneratedExtension<M, T>) =
|
||||
if (this.hasExtension(extension)) this.getExtension<T>(extension) else null
|
||||
|
||||
interface DescriptorUniqIdAware {
|
||||
fun DeclarationDescriptor.getUniqId(): Long?
|
||||
|
||||
Reference in New Issue
Block a user