diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt index e5a6a193f34..72121763e29 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt @@ -67,7 +67,6 @@ fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironme // Translate AST to high level IR. val translator = Psi2IrTranslator(Psi2IrConfiguration(false)) val generatorContext = translator.createGeneratorContext(context.moduleDescriptor, bindingContext) - @Suppress("DEPRECATION") context.psi2IrGeneratorContext = generatorContext val symbols = KonanSymbols(context, generatorContext.symbolTable) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt index 32f8409a3ad..4547b46b314 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt @@ -40,7 +40,7 @@ internal class KonanLower(val context: Context) { } } - private fun lowerModule(irModule: IrModuleFragment) { + fun lowerModule(irModule: IrModuleFragment) { val phaser = PhaseManager(context) phaser.phase(KonanPhase.REMOVE_EXPECT_DECLARATIONS) { @@ -72,12 +72,11 @@ internal class KonanLower(val context: Context) { irModule.files.forEach(InteropLoweringPart1(context)::lower) } - @Suppress("DEPRECATION") irModule.replaceUnboundSymbols(context) validateIrModule(context, irModule) } - private fun lowerFile(irFile: IrFile) { + fun lowerFile(irFile: IrFile) { val phaser = PhaseManager(context) phaser.phase(KonanPhase.LOWER_STRING_CONCAT) { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 4f58627b11b..ae39ccd87fb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -1401,8 +1401,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map): LLVMValueRef { context.log{"evaluateConst : ${ir2string(value)}"} - /* This suppression against IrConst */ - @Suppress("UNCHECKED_CAST") when (value.kind) { IrConstKind.Null -> return codegen.kNullObjHeaderPtr IrConstKind.Boolean -> when (value.value) { @@ -1414,7 +1412,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map return LLVMConstInt(LLVMInt16Type(), (value.value as Short).toLong(), 1)!! IrConstKind.Int -> return LLVMConstInt(LLVMInt32Type(), (value.value as Int).toLong(), 1)!! IrConstKind.Long -> return LLVMConstInt(LLVMInt64Type(), value.value as Long, 1)!! - IrConstKind.String -> return evaluateStringConst(value as IrConst) + IrConstKind.String -> return evaluateStringConst(@Suppress("UNCHECKED_CAST") value as IrConst) IrConstKind.Float -> return LLVMConstRealOfString(LLVMFloatType(), (value.value as Float).toString())!! IrConstKind.Double -> return LLVMConstRealOfString(LLVMDoubleType(), (value.value as Double).toString())!! } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt index 4b6b3956caa..ba592710f57 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt @@ -146,10 +146,7 @@ private fun Context.getDeclaredFields(classDescriptor: ClassDescriptor): List): LLVMTypeRef { - val fieldTypes = fields.map { - @Suppress("DEPRECATION") - getLLVMType(if (it.isDelegated) context.builtIns.nullableAnyType else it.type) - } + val fieldTypes = fields.map { getLLVMType(if (it.isDelegated) context.builtIns.nullableAnyType else it.type) } val classType = LLVMStructCreateNamed(LLVMGetModuleContext(context.llvmModule), name)!! diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt index b3b8f7d7ce5..abed4b09a34 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt @@ -43,7 +43,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, val parentDescriptor: DeclarationDescriptor, - val context: CommonBackendContext) { + context: CommonBackendContext) { private val descriptorSubstituteMap: MutableMap = mutableMapOf() private var typeSubstitutor: TypeSubstitutor? = null @@ -276,7 +276,6 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, val oldContainingDeclaration = oldDescriptor.containingDeclaration val newContainingDeclaration = descriptorSubstituteMap.getOrDefault(oldContainingDeclaration, oldContainingDeclaration) as ClassDescriptor - @Suppress("DEPRECATION") return PropertyDescriptorImpl.create( /* containingDeclaration = */ newContainingDeclaration, /* annotations = */ oldDescriptor.annotations, @@ -289,7 +288,7 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, /* lateInit = */ oldDescriptor.isLateInit, /* isConst = */ oldDescriptor.isConst, /* isExpect = */ oldDescriptor.isExpect, - /* isActual = */ oldDescriptor.isActual, + /* isActual = */ oldDescriptor.isActual, /* isExternal = */ oldDescriptor.isExternal, /* isDelegated = */ oldDescriptor.isDelegated ).apply { @@ -381,7 +380,6 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, //-----------------------------------------------------------------------------// - @Suppress("DEPRECATION") inner class InlineCopyIr : DeepCopyIrTree() { override fun mapClassDeclaration (descriptor: ClassDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ClassDescriptor @@ -600,6 +598,8 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, } } + val context = context + } class SubstitutedDescriptor(val inlinedFunction: FunctionDescriptor, val descriptor: DeclarationDescriptor) @@ -635,11 +635,10 @@ class DescriptorSubstitutorForExternalScope(val globalSubstituteMap: MutableMap< startOffset = oldExpression.startOffset, endOffset = oldExpression.endOffset, type = oldExpression.type, - symbol = createFunctionSymbol(newDescriptor), - descriptor = newDescriptor, + calleeDescriptor = newDescriptor, typeArguments = oldExpression.typeArguments, origin = oldExpression.origin, - superQualifierSymbol = createClassSymbolOrNull(oldExpression.superQualifier) + superQualifierDescriptor = oldExpression.superQualifier ).apply { oldExpression.descriptor.valueParameters.forEach { val valueArgument = oldExpression.getValueArgument(it) @@ -662,7 +661,7 @@ class DescriptorSubstitutorForExternalScope(val globalSubstituteMap: MutableMap< if (newDescriptor == oldDescriptor) return oldExpression - return oldExpression.shallowCopy(oldExpression.origin, createFunctionSymbol(newDescriptor), oldExpression.superQualifierSymbol) + return oldExpression.shallowCopy(oldExpression.origin, newDescriptor, oldExpression.superQualifier) } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 72d1a21b70e..987fc10c45c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -41,7 +41,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrMemberAccessExpressionBase import org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl -import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe @@ -348,7 +347,7 @@ private class Inliner(val globalSubstituteMap: MutableMap error(target) } val properties = context.config.platform.configurables as AppleConfigurables - val minimumOsVersion = properties.osVersionMin + val minimumOsVersion = properties.osVersionMin!! val contents = StringBuilder() contents.append(""" @@ -112,7 +113,7 @@ internal class ObjCExport(val context: Context) { CFBundleExecutable - $name + $bundleExecutable CFBundleIdentifier $bundleId CFBundleInfoDictionaryVersion diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt index 0e73ee2e5c3..b246a275d9f 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt @@ -42,8 +42,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol import org.jetbrains.kotlin.ir.util.getArguments import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid @@ -197,7 +195,7 @@ private class ExpressionValuesExtractor(val returnableBlockValues: Map { if ((expression.type.isUnit() || expression.type.isNothing())) { block(IrGetObjectValueImpl(expression.startOffset, expression.endOffset, - expression.type, IrClassSymbolImpl(expression.type.constructor.declarationDescriptor as ClassDescriptor))) + expression.type, (expression.type.constructor.declarationDescriptor as ClassDescriptor))) } else TODO(ir2stringWhole(expression)) } @@ -562,7 +560,7 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag is IrDelegatingConstructorCall -> { val thiz = IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, - createValueSymbol((descriptor as ConstructorDescriptor).constructedClass.thisAsReceiverParameter)) + (descriptor as ConstructorDescriptor).constructedClass.thisAsReceiverParameter) val arguments = listOf(thiz) + value.getArguments().map { it.second } DataFlowIR.Node.StaticCall( symbolTable.mapFunction(value.descriptor), diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt index cc64eb69f2e..4b2f2950374 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.backend.konan.optimizations import org.jetbrains.kotlin.backend.konan.DirectedGraphCondensationBuilder import org.jetbrains.kotlin.backend.konan.DirectedGraphMultiNode import org.jetbrains.kotlin.backend.konan.llvm.Lifetime +import org.jetbrains.kotlin.backend.konan.optimizations.* import org.jetbrains.kotlin.descriptors.ParameterDescriptor import org.jetbrains.kotlin.ir.IrElement @@ -161,7 +162,6 @@ internal object EscapeAnalysis { assignRole(value.node, Role.FIELD_WRITTEN, RoleInfoEntry(node)) } } - else -> TODO() } } FunctionAnalysisResult(function, nodesRoles) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt index 54eff72895f..2b82f8fb827 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.* import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirementTable +import org.jetbrains.kotlin.types.KotlinType // This class knows how to construct contexts for // MemberDeserializer to deserialize descriptors declared in IR. @@ -100,7 +101,12 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) { contextStack.pop() } - fun deserializeInlineType(type: ProtoBuf.Type) = typeDeserializer.type(type) + fun deserializeInlineType(type: ProtoBuf.Type): KotlinType { + + val result = typeDeserializer.type(type) + + return result + } fun deserializeClass(irProto: KonanIr.KotlinDescriptor): ClassDescriptor { return DeserializedClassDescriptor(parentContext, irProto.irLocalDeclaration.descriptor.clazz, nameResolver, SourceElement.NO_SOURCE) @@ -115,8 +121,9 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) { val proto = irProto.irLocalDeclaration.descriptor.constructor val isPrimary = !Flags.IS_SECONDARY.get(proto.flags) + val constructor = memberDeserializer.loadConstructor(proto, isPrimary) - return memberDeserializer.loadConstructor(proto, isPrimary) + return constructor } fun deserializeProperty(irProto: KonanIr.KotlinDescriptor): VariableDescriptor { @@ -131,17 +138,18 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) { } } - private fun propertyToVariable(property: PropertyDescriptor): LocalVariableDescriptor { - // TODO: Should we transform the getter and the setter too? - @Suppress("DEPRECATION") - return LocalVariableDescriptor( + fun propertyToVariable(property: PropertyDescriptor): LocalVariableDescriptor { + val variable = LocalVariableDescriptor( property.containingDeclaration, property.annotations, property.name, property.type, - property.isVar, + property.isVar, property.isDelegated, SourceElement.NO_SOURCE) + + // TODO: Should we transform the getter and the setter too? + return variable } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationSerializer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationSerializer.kt index 17a4c282ce9..2ce24a10984 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationSerializer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationSerializer.kt @@ -97,9 +97,8 @@ internal class LocalDeclarationSerializer(val context: Context, val rootFunction // serialization to serialize variables for now. // Need to introduce an extension protobuf message // and serialize variables directly. - private fun variableAsProperty(variable: VariableDescriptor): PropertyDescriptor { + fun variableAsProperty(variable: VariableDescriptor): PropertyDescriptor { - @Suppress("DEPRECATION") val isDelegated = when (variable) { is LocalVariableDescriptor -> variable.isDelegated is IrTemporaryVariableDescriptor -> false diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt index ed8d5c3ffa8..81bf5040437 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/SerializeIr.kt @@ -36,7 +36,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* -import org.jetbrains.kotlin.ir.symbols.impl.* +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol import org.jetbrains.kotlin.ir.util.addFakeOverrides import org.jetbrains.kotlin.ir.util.createParameterDeclarations import org.jetbrains.kotlin.serialization.KonanDescriptorSerializer @@ -52,17 +52,17 @@ import org.jetbrains.kotlin.types.TypeProjectionImpl import org.jetbrains.kotlin.types.TypeSubstitutor -internal class IrSerializer(val context: Context, - descriptorTable: DescriptorTable, - stringTable: KonanStringTable, - rootFunctionSerializer: KonanDescriptorSerializer, - private var rootFunction: FunctionDescriptor) { +internal class IrSerializer(val context: Context, + val descriptorTable: DescriptorTable, + val stringTable: KonanStringTable, + val rootFunctionSerializer: KonanDescriptorSerializer, + var rootFunction: FunctionDescriptor) { - private val loopIndex = mutableMapOf() + val loopIndex = mutableMapOf() var currentLoopIndex = 0 - private val localDeclarationSerializer + val localDeclarationSerializer = LocalDeclarationSerializer(context, rootFunctionSerializer) - private val irDescriptorSerializer + val irDescriptorSerializer = IrDescriptorSerializer(context, descriptorTable, stringTable, localDeclarationSerializer, rootFunction) @@ -72,12 +72,12 @@ internal class IrSerializer(val context: Context, return encodeDeclaration(declaration) } - private fun serializeKotlinType(type: KotlinType): KonanIr.KotlinType { + fun serializeKotlinType(type: KotlinType): KonanIr.KotlinType { context.log{"### serializing KotlinType: " + type} return irDescriptorSerializer.serializeKotlinType(type) } - private fun serializeDescriptor(descriptor: DeclarationDescriptor): KonanIr.KotlinDescriptor { + fun serializeDescriptor(descriptor: DeclarationDescriptor): KonanIr.KotlinDescriptor { context.log{"### serializeDescriptor $descriptor"} // Behind this call starts a large world of @@ -85,14 +85,15 @@ internal class IrSerializer(val context: Context, return irDescriptorSerializer.serializeDescriptor(descriptor) } - private fun serializeCoordinates(start: Int, end: Int): KonanIr.Coordinates { - return KonanIr.Coordinates.newBuilder() + fun serializeCoordinates(start: Int, end: Int): KonanIr.Coordinates { + val proto = KonanIr.Coordinates.newBuilder() .setStartOffset(start) .setEndOffset(end) .build() + return proto } - private fun serializeTypeMap(typeArguments: Map): KonanIr.TypeMap { + fun serializeTypeMap(typeArguments: Map): KonanIr.TypeMap { val proto = KonanIr.TypeMap.newBuilder() typeArguments.forEach { key, value -> val pair = KonanIr.TypeMap.Pair.newBuilder() @@ -104,12 +105,12 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeMap { + fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeMap { val typeMap = mutableMapOf() call.descriptor.original.typeParameters.forEach { val type = call.getTypeArgument(it) - if (type != null) typeMap[it] = type + if (type != null) typeMap.put(it, type) } return serializeTypeMap(typeMap) @@ -118,7 +119,7 @@ internal class IrSerializer(val context: Context, /* -------------------------------------------------------------------------- */ - private fun serializeBlockBody(expression: IrBlockBody): KonanIr.IrBlockBody { + fun serializeBlockBody(expression: IrBlockBody): KonanIr.IrBlockBody { val proto = KonanIr.IrBlockBody.newBuilder() expression.statements.forEach { proto.addStatement(serializeStatement(it)) @@ -126,16 +127,16 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeBranch(branch: IrBranch): KonanIr.IrBranch { + fun serializeBranch(branch: IrBranch): KonanIr.IrBranch { val proto = KonanIr.IrBranch.newBuilder() - proto.condition = serializeExpression(branch.condition) - proto.result = serializeExpression(branch.result) + proto.setCondition(serializeExpression(branch.condition)) + proto.setResult(serializeExpression(branch.result)) return proto.build() } - private fun serializeBlock(block: IrBlock): KonanIr.IrBlock { + fun serializeBlock(block: IrBlock): KonanIr.IrBlock { val isLambdaOrigin = block.origin == IrStatementOrigin.LAMBDA || block.origin == IrStatementOrigin.ANONYMOUS_FUNCTION @@ -147,7 +148,7 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeComposite(composite: IrComposite): KonanIr.IrComposite { + fun serializeComposite(composite: IrComposite): KonanIr.IrComposite { val proto = KonanIr.IrComposite.newBuilder() composite.statements.forEach { proto.addStatement(serializeStatement(it)) @@ -155,14 +156,14 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeCatch(catch: IrCatch): KonanIr.IrCatch { + fun serializeCatch(catch: IrCatch): KonanIr.IrCatch { val proto = KonanIr.IrCatch.newBuilder() .setCatchParameter(serializeDeclaration(catch.catchParameter)) .setResult(serializeExpression(catch.result)) return proto.build() } - private fun serializeStringConcat(expression: IrStringConcatenation): KonanIr.IrStringConcat { + fun serializeStringConcat(expression: IrStringConcatenation): KonanIr.IrStringConcat { val proto = KonanIr.IrStringConcat.newBuilder() expression.arguments.forEach { proto.addArgument(serializeExpression(it)) @@ -170,7 +171,7 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun irCallToPrimitiveKind(call: IrCall): KonanIr.IrCall.Primitive = when (call) { + fun irCallToPrimitiveKind(call: IrCall): KonanIr.IrCall.Primitive = when (call) { is IrNullaryPrimitiveImpl -> KonanIr.IrCall.Primitive.NULLARY is IrUnaryPrimitiveImpl @@ -181,16 +182,16 @@ internal class IrSerializer(val context: Context, -> KonanIr.IrCall.Primitive.NOT_PRIMITIVE } - private fun serializeMemberAccessCommon(call: IrMemberAccessExpression): KonanIr.MemberAccessCommon { + fun serializeMemberAccessCommon(call: IrMemberAccessExpression): KonanIr.MemberAccessCommon { val proto = KonanIr.MemberAccessCommon.newBuilder() if (call.extensionReceiver != null) { - proto.extensionReceiver = serializeExpression(call.extensionReceiver!!) + proto.setExtensionReceiver(serializeExpression(call.extensionReceiver!!)) } if (call.dispatchReceiver != null) { - proto.dispatchReceiver = serializeExpression(call.dispatchReceiver!!) + proto.setDispatchReceiver(serializeExpression(call.dispatchReceiver!!)) } - proto.typeMap = serializeTypeArguments(call) + proto.setTypeMap(serializeTypeArguments(call)) call.descriptor.valueParameters.forEach { val actual = call.getValueArgument(it.index) @@ -201,51 +202,52 @@ internal class IrSerializer(val context: Context, assert(it.varargElementType != null || it.declaresDefaultValue()) } else { - val argProto = serializeExpression(actual) + val arg = actual + val argProto = serializeExpression(arg) proto.addValueArgument(argProto) } } return proto.build() } - private fun serializeCall(call: IrCall): KonanIr.IrCall { + fun serializeCall(call: IrCall): KonanIr.IrCall { val proto = KonanIr.IrCall.newBuilder() - proto.kind = irCallToPrimitiveKind(call) - proto.descriptor = serializeDescriptor(call.descriptor) + proto.setKind(irCallToPrimitiveKind(call)) + proto.setDescriptor(serializeDescriptor(call.descriptor)) if (call.superQualifier != null) { - proto.`super` = serializeDescriptor(call.superQualifier!!) + proto.setSuper(serializeDescriptor(call.superQualifier!!)) } - proto.memberAccess = serializeMemberAccessCommon(call) + proto.setMemberAccess(serializeMemberAccessCommon(call)) return proto.build() } - private fun serializeCallableReference(callable: IrCallableReference): KonanIr.IrCallableReference { + fun serializeCallableReference(callable: IrCallableReference): KonanIr.IrCallableReference { val proto = KonanIr.IrCallableReference.newBuilder() .setDescriptor(serializeDescriptor(callable.descriptor)) .setTypeMap(serializeTypeArguments(callable)) return proto.build() } - private fun serializeClassReference(expression: IrClassReference): KonanIr.IrClassReference { + fun serializeClassReference(expression: IrClassReference): KonanIr.IrClassReference { val proto = KonanIr.IrClassReference.newBuilder() .setClassDescriptor(serializeDescriptor(expression.symbol.descriptor)) return proto.build() } - private fun serializeConst(value: IrConst<*>): KonanIr.IrConst { + fun serializeConst(value: IrConst<*>): KonanIr.IrConst { val proto = KonanIr.IrConst.newBuilder() when (value.kind) { - IrConstKind.Null -> proto.`null` = true - IrConstKind.Boolean -> proto.boolean = value.value as Boolean - IrConstKind.Byte -> proto.byte = (value.value as Byte).toInt() - IrConstKind.Short -> proto.short = (value.value as Short).toInt() - IrConstKind.Int -> proto.int = value.value as Int - IrConstKind.Long -> proto.long = value.value as Long - IrConstKind.String -> proto.string = value.value as String - IrConstKind.Float -> proto.float = value.value as Float - IrConstKind.Double -> proto.double = value.value as Double + IrConstKind.Null -> proto.setNull(true) + IrConstKind.Boolean -> proto.setBoolean(value.value as Boolean) + IrConstKind.Byte -> proto.setByte((value.value as Byte).toInt()) + IrConstKind.Short -> proto.setShort((value.value as Short).toInt()) + IrConstKind.Int -> proto.setInt(value.value as Int) + IrConstKind.Long -> proto.setLong(value.value as Long) + IrConstKind.String -> proto.setString(value.value as String) + IrConstKind.Float -> proto.setFloat(value.value as Float) + IrConstKind.Double -> proto.setDouble(value.value as Double) else -> { TODO("Const type serialization not implemented yet: ${ir2string(value)}") } @@ -253,14 +255,14 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeDelegatingConstructorCall(call: IrDelegatingConstructorCall): KonanIr.IrDelegatingConstructorCall { + fun serializeDelegatingConstructorCall(call: IrDelegatingConstructorCall): KonanIr.IrDelegatingConstructorCall { val proto = KonanIr.IrDelegatingConstructorCall.newBuilder() .setDescriptor(serializeDescriptor(call.descriptor)) .setMemberAccess(serializeMemberAccessCommon(call)) return proto.build() } - private fun serializeDoWhile(expression: IrDoWhileLoop): KonanIr.IrDoWhile { + fun serializeDoWhile(expression: IrDoWhileLoop): KonanIr.IrDoWhile { val proto = KonanIr.IrDoWhile.newBuilder() .setLoop(serializeLoop(expression)) @@ -274,85 +276,85 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeGetClass(expression: IrGetClass): KonanIr.IrGetClass { + fun serializeGetClass(expression: IrGetClass): KonanIr.IrGetClass { val proto = KonanIr.IrGetClass.newBuilder() .setArgument(serializeExpression(expression.argument)) return proto.build() } - private fun serializeGetEnumValue(expression: IrGetEnumValue): KonanIr.IrGetEnumValue { + fun serializeGetEnumValue(expression: IrGetEnumValue): KonanIr.IrGetEnumValue { val proto = KonanIr.IrGetEnumValue.newBuilder() .setType(serializeKotlinType(expression.type)) .setDescriptor(serializeDescriptor(expression.descriptor)) return proto.build() } - private fun serializeFieldAccessCommon(expression: IrFieldAccessExpression): KonanIr.FieldAccessCommon { + fun serializeFieldAccessCommon(expression: IrFieldAccessExpression): KonanIr.FieldAccessCommon { val proto = KonanIr.FieldAccessCommon.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) val superQualifier = expression.superQualifier if (superQualifier != null) - proto.`super` = serializeDescriptor(superQualifier) + proto.setSuper(serializeDescriptor(superQualifier)) val receiver = expression.receiver - if (receiver != null) - proto.receiver = serializeExpression(receiver) + if (receiver != null) + proto.setReceiver(serializeExpression(receiver)) return proto.build() } - private fun serializeGetField(expression: IrGetField): KonanIr.IrGetField { + fun serializeGetField(expression: IrGetField): KonanIr.IrGetField { val proto = KonanIr.IrGetField.newBuilder() .setFieldAccess(serializeFieldAccessCommon(expression)) return proto.build() } - private fun serializeGetValue(expression: IrGetValue): KonanIr.IrGetValue { + fun serializeGetValue(expression: IrGetValue): KonanIr.IrGetValue { val proto = KonanIr.IrGetValue.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) return proto.build() } - private fun serializeGetObject(expression: IrGetObjectValue): KonanIr.IrGetObject { + fun serializeGetObject(expression: IrGetObjectValue): KonanIr.IrGetObject { val proto = KonanIr.IrGetObject.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) return proto.build() } - private fun serializeInstanceInitializerCall(call: IrInstanceInitializerCall): KonanIr.IrInstanceInitializerCall { + fun serializeInstanceInitializerCall(call: IrInstanceInitializerCall): KonanIr.IrInstanceInitializerCall { val proto = KonanIr.IrInstanceInitializerCall.newBuilder() - proto.descriptor = serializeDescriptor(call.classDescriptor) + proto.setDescriptor(serializeDescriptor(call.classDescriptor)) return proto.build() } - private fun serializeReturn(expression: IrReturn): KonanIr.IrReturn { + fun serializeReturn(expression: IrReturn): KonanIr.IrReturn { val proto = KonanIr.IrReturn.newBuilder() .setReturnTarget(serializeDescriptor(expression.returnTarget)) .setValue(serializeExpression(expression.value)) return proto.build() } - private fun serializeSetField(expression: IrSetField): KonanIr.IrSetField { + fun serializeSetField(expression: IrSetField): KonanIr.IrSetField { val proto = KonanIr.IrSetField.newBuilder() .setFieldAccess(serializeFieldAccessCommon(expression)) .setValue(serializeExpression(expression.value)) return proto.build() } - private fun serializeSetVariable(expression: IrSetVariable): KonanIr.IrSetVariable { + fun serializeSetVariable(expression: IrSetVariable): KonanIr.IrSetVariable { val proto = KonanIr.IrSetVariable.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) .setValue(serializeExpression(expression.value)) return proto.build() } - private fun serializeThrow(expression: IrThrow): KonanIr.IrThrow { + fun serializeThrow(expression: IrThrow): KonanIr.IrThrow { val proto = KonanIr.IrThrow.newBuilder() .setValue(serializeExpression(expression.value)) return proto.build() } - private fun serializeTry(expression: IrTry): KonanIr.IrTry { + fun serializeTry(expression: IrTry): KonanIr.IrTry { val proto = KonanIr.IrTry.newBuilder() .setResult(serializeExpression(expression.tryResult)) val catchList = expression.catches @@ -361,12 +363,12 @@ internal class IrSerializer(val context: Context, } val finallyExpression = expression.finallyExpression if (finallyExpression != null) { - proto.finally = serializeExpression(finallyExpression) + proto.setFinally(serializeExpression(finallyExpression)) } return proto.build() } - private fun serializeTypeOperator(operator: IrTypeOperator): KonanIr.IrTypeOperator = when (operator) { + fun serializeTypeOperator(operator: IrTypeOperator): KonanIr.IrTypeOperator = when (operator) { IrTypeOperator.CAST -> KonanIr.IrTypeOperator.CAST IrTypeOperator.IMPLICIT_CAST @@ -384,7 +386,7 @@ internal class IrSerializer(val context: Context, else -> TODO("Unknown type operator") } - private fun serializeTypeOp(expression: IrTypeOperatorCall): KonanIr.IrTypeOp { + fun serializeTypeOp(expression: IrTypeOperatorCall): KonanIr.IrTypeOp { val proto = KonanIr.IrTypeOp.newBuilder() .setOperator(serializeTypeOperator(expression.operator)) .setOperand(serializeKotlinType(expression.typeOperand)) @@ -393,13 +395,13 @@ internal class IrSerializer(val context: Context, } - private fun serializeVararg(expression: IrVararg): KonanIr.IrVararg { + fun serializeVararg(expression: IrVararg): KonanIr.IrVararg { val proto = KonanIr.IrVararg.newBuilder() .setElementType(serializeKotlinType(expression.varargElementType)) return proto.build() } - private fun serializeWhen(expression: IrWhen): KonanIr.IrWhen { + fun serializeWhen(expression: IrWhen): KonanIr.IrWhen { val proto = KonanIr.IrWhen.newBuilder() val branches = expression.branches @@ -410,57 +412,57 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeLoop(expression: IrLoop): KonanIr.Loop { + fun serializeLoop(expression: IrLoop): KonanIr.Loop { val proto = KonanIr.Loop.newBuilder() .setCondition(serializeExpression(expression.condition)) val label = expression.label if (label != null) { - proto.label = label + proto.setLabel(label) } - proto.loopId = currentLoopIndex - loopIndex[expression] = currentLoopIndex++ + proto.setLoopId(currentLoopIndex) + loopIndex.put(expression, currentLoopIndex++) val body = expression.body if (body != null) { - proto.body = serializeExpression(body) + proto.setBody(serializeExpression(body)) } return proto.build() } - private fun serializeWhile(expression: IrWhileLoop): KonanIr.IrWhile { + fun serializeWhile(expression: IrWhileLoop): KonanIr.IrWhile { val proto = KonanIr.IrWhile.newBuilder() .setLoop(serializeLoop(expression)) return proto.build() } - private fun serializeBreak(expression: IrBreak): KonanIr.IrBreak { + fun serializeBreak(expression: IrBreak): KonanIr.IrBreak { val proto = KonanIr.IrBreak.newBuilder() val label = expression.label if (label != null) { - proto.label = label + proto.setLabel(label) } val loopId = loopIndex[expression.loop]!! - proto.loopId = loopId + proto.setLoopId(loopId) return proto.build() } - private fun serializeContinue(expression: IrContinue): KonanIr.IrContinue { + fun serializeContinue(expression: IrContinue): KonanIr.IrContinue { val proto = KonanIr.IrContinue.newBuilder() val label = expression.label if (label != null) { - proto.label = label + proto.setLabel(label) } val loopId = loopIndex[expression.loop]!! - proto.loopId = loopId + proto.setLoopId(loopId) return proto.build() } - private fun serializeExpression(expression: IrExpression): KonanIr.IrExpression { + fun serializeExpression(expression: IrExpression): KonanIr.IrExpression { context.log{"### serializing Expression: ${ir2string(expression)}"} val coordinates = serializeCoordinates(expression.startOffset, expression.endOffset) @@ -471,40 +473,40 @@ internal class IrSerializer(val context: Context, val operationProto = KonanIr.IrOperation.newBuilder() when (expression) { - is IrBlock -> operationProto.block = serializeBlock(expression) - is IrBreak -> operationProto.`break` = serializeBreak(expression) + is IrBlock -> operationProto.setBlock(serializeBlock(expression)) + is IrBreak -> operationProto.setBreak(serializeBreak(expression)) is IrClassReference - -> operationProto.classReference = serializeClassReference(expression) - is IrCall -> operationProto.call = serializeCall(expression) + -> operationProto.setClassReference(serializeClassReference(expression)) + is IrCall -> operationProto.setCall(serializeCall(expression)) is IrCallableReference - -> operationProto.callableReference = serializeCallableReference(expression) - is IrComposite -> operationProto.composite = serializeComposite(expression) - is IrConst<*> -> operationProto.const = serializeConst(expression) - is IrContinue -> operationProto.`continue` = serializeContinue(expression) + -> operationProto.setCallableReference(serializeCallableReference(expression)) + is IrComposite -> operationProto.setComposite(serializeComposite(expression)) + is IrConst<*> -> operationProto.setConst(serializeConst(expression)) + is IrContinue -> operationProto.setContinue(serializeContinue(expression)) is IrDelegatingConstructorCall - -> operationProto.delegatingConstructorCall = serializeDelegatingConstructorCall(expression) - is IrDoWhileLoop -> operationProto.doWhile = serializeDoWhile(expression) - is IrGetClass -> operationProto.getClass = serializeGetClass(expression) - is IrGetField -> operationProto.getField = serializeGetField(expression) - is IrGetValue -> operationProto.getValue = serializeGetValue(expression) + -> operationProto.setDelegatingConstructorCall(serializeDelegatingConstructorCall(expression)) + is IrDoWhileLoop -> operationProto.setDoWhile(serializeDoWhile(expression)) + is IrGetClass -> operationProto.setGetClass(serializeGetClass(expression)) + is IrGetField -> operationProto.setGetField(serializeGetField(expression)) + is IrGetValue -> operationProto.setGetValue(serializeGetValue(expression)) is IrGetEnumValue - -> operationProto.getEnumValue = serializeGetEnumValue(expression) + -> operationProto.setGetEnumValue(serializeGetEnumValue(expression)) is IrGetObjectValue - -> operationProto.getObject = serializeGetObject(expression) + -> operationProto.setGetObject(serializeGetObject(expression)) is IrInstanceInitializerCall - -> operationProto.instanceInitializerCall = serializeInstanceInitializerCall(expression) - is IrReturn -> operationProto.`return` = serializeReturn(expression) - is IrSetField -> operationProto.setField = serializeSetField(expression) - is IrSetVariable -> operationProto.setVariable = serializeSetVariable(expression) + -> operationProto.setInstanceInitializerCall(serializeInstanceInitializerCall(expression)) + is IrReturn -> operationProto.setReturn(serializeReturn(expression)) + is IrSetField -> operationProto.setSetField(serializeSetField(expression)) + is IrSetVariable -> operationProto.setSetVariable(serializeSetVariable(expression)) is IrStringConcatenation - -> operationProto.stringConcat = serializeStringConcat(expression) - is IrThrow -> operationProto.`throw` = serializeThrow(expression) - is IrTry -> operationProto.`try` = serializeTry(expression) + -> operationProto.setStringConcat(serializeStringConcat(expression)) + is IrThrow -> operationProto.setThrow(serializeThrow(expression)) + is IrTry -> operationProto.setTry(serializeTry(expression)) is IrTypeOperatorCall - -> operationProto.typeOp = serializeTypeOp(expression) - is IrVararg -> operationProto.vararg = serializeVararg(expression) - is IrWhen -> operationProto.`when` = serializeWhen(expression) - is IrWhileLoop -> operationProto.`while` = serializeWhile(expression) + -> operationProto.setTypeOp(serializeTypeOp(expression)) + is IrVararg -> operationProto.setVararg(serializeVararg(expression)) + is IrWhen -> operationProto.setWhen(serializeWhen(expression)) + is IrWhileLoop -> operationProto.setWhile(serializeWhile(expression)) else -> { TODO("Expression serialization not implemented yet: ${ir2string(expression)}.") } @@ -514,7 +516,7 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeStatement(statement: IrElement): KonanIr.IrStatement { + fun serializeStatement(statement: IrElement): KonanIr.IrStatement { context.log{"### serializing Statement: ${ir2string(statement)}"} val coordinates = serializeCoordinates(statement.startOffset, statement.endOffset) @@ -522,11 +524,11 @@ internal class IrSerializer(val context: Context, .setCoordinates(coordinates) when (statement) { - is IrDeclaration -> proto.declaration = serializeDeclaration(statement) - is IrExpression -> proto.expression = serializeExpression(statement) - is IrBlockBody -> proto.blockBody = serializeBlockBody(statement) - is IrBranch -> proto.branch = serializeBranch(statement) - is IrCatch -> proto.catch = serializeCatch(statement) + is IrDeclaration -> proto.setDeclaration(serializeDeclaration(statement)) + is IrExpression -> proto.setExpression(serializeExpression(statement)) + is IrBlockBody -> proto.setBlockBody(serializeBlockBody(statement)) + is IrBranch -> proto.setBranch(serializeBranch(statement)) + is IrCatch -> proto.setCatch(serializeCatch(statement)) else -> { TODO("Statement not implemented yet: ${ir2string(statement)}") } @@ -534,10 +536,10 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeIrFunction(function: IrFunction): KonanIr.IrFunction { + fun serializeIrFunction(function: IrFunction): KonanIr.IrFunction { val proto = KonanIr.IrFunction.newBuilder() val body = function.body - if (body != null) proto.body = serializeStatement(body) + if (body != null) proto.setBody(serializeStatement(body)) function.descriptor.valueParameters.forEachIndexed { index, it -> val default = function.getDefault(it) @@ -551,41 +553,42 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeIrProperty(property: IrProperty): KonanIr.IrProperty { + fun serializeIrProperty(property: IrProperty): KonanIr.IrProperty { val proto = KonanIr.IrProperty.newBuilder() .setIsDelegated(property.isDelegated) val backingField = property.backingField val getter = property.getter val setter = property.setter - if (backingField != null) - proto.backingField = serializeIrField(backingField) - if (getter != null) - proto.getter = serializeIrFunction(getter) - if (setter != null) - proto.setter = serializeIrFunction(setter) + if (backingField != null) + proto.setBackingField(serializeIrField(backingField)) + if (getter != null) + proto.setGetter(serializeIrFunction(getter)) + if (setter != null) + proto.setSetter(serializeIrFunction(setter)) return proto.build() } - private fun serializeIrField(field: IrField): KonanIr.IrProperty.IrField { + fun serializeIrField(field: IrField): KonanIr.IrProperty.IrField { val proto = KonanIr.IrProperty.IrField.newBuilder() val initializer = field.initializer?.expression if (initializer != null) { - proto.initializer = serializeExpression(initializer) + proto.setInitializer( + serializeExpression(initializer)) } return proto.build() } - private fun serializeIrVariable(variable: IrVariable): KonanIr.IrVar { + fun serializeIrVariable(variable: IrVariable): KonanIr.IrVar { val proto = KonanIr.IrVar.newBuilder() val initializer = variable.initializer if (initializer != null) { - proto.initializer = serializeExpression(initializer) + proto.setInitializer(serializeExpression(initializer)) } return proto.build() } - private fun serializeIrClass(@Suppress("UNUSED_PARAMETER") clazz: IrClass): KonanIr.IrClass { + fun serializeIrClass(@Suppress("UNUSED_PARAMETER") clazz: IrClass): KonanIr.IrClass { val proto = KonanIr.IrClass.newBuilder() // TODO: As of now we get here only for anonymous local objects. @@ -604,24 +607,24 @@ internal class IrSerializer(val context: Context, return proto.build() } - private fun serializeIrEnumEntry(enumEntry: IrEnumEntry): KonanIr.IrEnumEntry { + fun serializeIrEnumEntry(enumEntry: IrEnumEntry): KonanIr.IrEnumEntry { val proto = KonanIr.IrEnumEntry.newBuilder() val initializer = enumEntry.initializerExpression!! - proto.initializer = serializeExpression(initializer) + proto.setInitializer(serializeExpression(initializer)) val correspondingClass = enumEntry.correspondingClass if (correspondingClass != null) { - proto.correspondingClass = serializeDeclaration(correspondingClass) + proto.setCorrespondingClass(serializeDeclaration(correspondingClass)) } return proto.build() } - private fun serializeDeclaration(declaration: IrDeclaration): KonanIr.IrDeclaration { + fun serializeDeclaration(declaration: IrDeclaration): KonanIr.IrDeclaration { context.log{"### serializing Declaration: ${ir2string(declaration)}"} val descriptor = declaration.descriptor if (descriptor != rootFunction && - declaration !is IrVariable) { + !(declaration is IrVariable)) { localDeclarationSerializer.pushContext(descriptor) } @@ -634,22 +637,22 @@ internal class IrSerializer(val context: Context, when (declaration) { is IrFunction - -> declarator.function = serializeIrFunction(declaration) + -> declarator.setFunction(serializeIrFunction(declaration)) is IrVariable - -> declarator.variable = serializeIrVariable(declaration) + -> declarator.setVariable(serializeIrVariable(declaration)) is IrClass - -> declarator.irClass = serializeIrClass(declaration) + -> declarator.setIrClass(serializeIrClass(declaration)) is IrEnumEntry - -> declarator.irEnumEntry = serializeIrEnumEntry(declaration) + -> declarator.setIrEnumEntry(serializeIrEnumEntry(declaration)) is IrProperty - -> declarator.irProperty = serializeIrProperty(declaration) + -> declarator.setIrProperty(serializeIrProperty(declaration)) else -> { TODO("Declaration serialization not supported yet: $declaration") } } - if (declaration !is IrVariable) { + if (!(declaration is IrVariable)) { localDeclarationSerializer.popContext() } @@ -673,15 +676,16 @@ internal class IrSerializer(val context: Context, proto.setDeclarator(declarator) val fileName = context.ir.originalModuleIndex.declarationToFile[declaration.descriptor] - proto.fileName = fileName + proto.setFileName(fileName) return proto.build() } - private fun encodeDeclaration(declaration: IrDeclaration): String { + fun encodeDeclaration(declaration: IrDeclaration): String { val proto = serializeDeclaration(declaration) val byteArray = proto.toByteArray() - return base64Encode(byteArray) + val base64 = base64Encode(byteArray) + return base64 } @@ -689,42 +693,43 @@ internal class IrSerializer(val context: Context, // --------- Deserializer part ----------------------------- -internal class IrDeserializer(val context: Context, - private val rootFunction: FunctionDescriptor) { +internal class IrDeserializer(val context: Context, + val rootFunction: FunctionDescriptor) { - private val loopIndex = mutableMapOf() + val loopIndex = mutableMapOf() - private val rootMember = rootFunction.deserializedPropertyIfAccessor - private val localDeserializer = LocalDeclarationDeserializer(rootMember) + val rootMember = rootFunction.deserializedPropertyIfAccessor + val localDeserializer = LocalDeclarationDeserializer(rootMember) - private val descriptorDeserializer = IrDescriptorDeserializer( + val descriptorDeserializer = IrDescriptorDeserializer( context, rootMember, localDeserializer) - private fun deserializeKotlinType(proto: KonanIr.KotlinType) + fun deserializeKotlinType(proto: KonanIr.KotlinType) = descriptorDeserializer.deserializeKotlinType(proto) - private fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor) + fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor) = descriptorDeserializer.deserializeDescriptor(proto) - private fun deserializeTypeMap(descriptor: CallableDescriptor, proto: KonanIr.TypeMap): + fun deserializeTypeMap(descriptor: CallableDescriptor, proto: KonanIr.TypeMap): Map { val typeMap = mutableMapOf() - val pairProtos = proto.pairList + val pairProtos = proto.getPairList() pairProtos.forEachIndexed { index, pair -> val typeParameter = descriptor.original.typeParameters[index] - typeMap[typeParameter] = deserializeKotlinType(pair.type) + typeMap.put(typeParameter, + deserializeKotlinType(pair.getType())) } context.log{"### deserialized typeMap = $typeMap"} return typeMap } - private fun deserializeBlockBody(proto: KonanIr.IrBlockBody, - start: Int, end: Int): IrBlockBody { + fun deserializeBlockBody(proto: KonanIr.IrBlockBody, + start: Int, end: Int): IrBlockBody { val statements = mutableListOf() - val statementProtos = proto.statementList + val statementProtos = proto.getStatementList() statementProtos.forEach { statements.add(deserializeStatement(it) as IrStatement) } @@ -732,35 +737,35 @@ internal class IrDeserializer(val context: Context, return IrBlockBodyImpl(start, end, statements) } - private fun deserializeBranch(proto: KonanIr.IrBranch, start: Int, end: Int): IrBranch { + fun deserializeBranch(proto: KonanIr.IrBranch, start: Int, end: Int): IrBranch { - val condition = deserializeExpression(proto.condition) - val result = deserializeExpression(proto.result) + val condition = deserializeExpression(proto.getCondition()) + val result = deserializeExpression(proto.getResult()) return IrBranchImpl(start, end, condition, result) } - private fun deserializeCatch(proto: KonanIr.IrCatch, start: Int, end: Int): IrCatch { + fun deserializeCatch(proto: KonanIr.IrCatch, start: Int, end: Int): IrCatch { val catchParameter = deserializeDeclaration(proto.catchParameter) as IrVariable - val result = deserializeExpression(proto.result) + val result = deserializeExpression(proto.getResult()) return IrCatchImpl(start, end, catchParameter, result) } - private fun deserializeStatement(proto: KonanIr.IrStatement): IrElement { - val start = proto.coordinates.startOffset - val end = proto.coordinates.endOffset + fun deserializeStatement(proto: KonanIr.IrStatement): IrElement { + val start = proto.getCoordinates().getStartOffset() + val end = proto.getCoordinates().getEndOffset() val element = when { proto.hasBlockBody() - -> deserializeBlockBody(proto.blockBody, start, end) + -> deserializeBlockBody(proto.getBlockBody(), start, end) proto.hasBranch() - -> deserializeBranch(proto.branch, start, end) + -> deserializeBranch(proto.getBranch(), start, end) proto.hasCatch() - -> deserializeCatch(proto.catch, start, end) + -> deserializeCatch(proto.getCatch(), start, end) proto.hasDeclaration() - -> deserializeDeclaration(proto.declaration) + -> deserializeDeclaration(proto.getDeclaration()) proto.hasExpression() - -> deserializeExpression(proto.expression) + -> deserializeExpression(proto.getExpression()) else -> { TODO("Statement deserialization not implemented") } @@ -771,19 +776,21 @@ internal class IrDeserializer(val context: Context, return element } - private fun deserializeBlock(proto: KonanIr.IrBlock, start: Int, end: Int, type: KotlinType): IrBlock { + fun deserializeBlock(proto: KonanIr.IrBlock, start: Int, end: Int, type: KotlinType): IrBlock { val statements = mutableListOf() - val statementProtos = proto.statementList + val statementProtos = proto.getStatementList() statementProtos.forEach { statements.add(deserializeStatement(it) as IrStatement) } val isLambdaOrigin = if (proto.isLambdaOrigin) IrStatementOrigin.LAMBDA else null - return IrBlockImpl(start, end, type, isLambdaOrigin, statements) + val block = IrBlockImpl(start, end, type, isLambdaOrigin, statements) + + return block } - private fun deserializeMemberAccessCommon(access: IrMemberAccessExpression, proto: KonanIr.MemberAccessCommon) { + fun deserializeMemberAccessCommon(access: IrMemberAccessExpression, proto: KonanIr.MemberAccessCommon) { proto.valueArgumentList.mapIndexed { i, expr -> access.putValueArgument(i, deserializeExpression(expr)) @@ -797,49 +804,48 @@ internal class IrDeserializer(val context: Context, } } - private fun deserializeClassReference(proto: KonanIr.IrClassReference, start: Int, end: Int, type: KotlinType): IrClassReference { + fun deserializeClassReference(proto: KonanIr.IrClassReference, start: Int, end: Int, type: KotlinType): IrClassReference { val descriptor = deserializeDescriptor(proto.classDescriptor) as ClassifierDescriptor - /** TODO: [createClassifierSymbolForClassReference] is internal function */ - @Suppress("DEPRECATION") return IrClassReferenceImpl(start, end, type, descriptor, descriptor.defaultType) } - private fun deserializeCall(proto: KonanIr.IrCall, start: Int, end: Int, type: KotlinType): IrCall { - val descriptor = deserializeDescriptor(proto.descriptor) as FunctionDescriptor + fun deserializeCall(proto: KonanIr.IrCall, start: Int, end: Int, type: KotlinType): IrCall { + val descriptor = deserializeDescriptor(proto.getDescriptor()) as FunctionDescriptor val superDescriptor = if (proto.hasSuper()) { - deserializeDescriptor(proto.`super`) as ClassDescriptor + deserializeDescriptor(proto.getSuper()) as ClassDescriptor } else null val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.getTypeMap()) val call: IrCall = when (proto.kind) { KonanIr.IrCall.Primitive.NOT_PRIMITIVE -> // TODO: implement the last three args here. - IrCallImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, typeArgs , null, createClassSymbolOrNull(superDescriptor)) + IrCallImpl(start, end, type, descriptor, typeArgs , null, superDescriptor) KonanIr.IrCall.Primitive.NULLARY -> IrNullaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor)) KonanIr.IrCall.Primitive.UNARY -> - IrUnaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor)) + IrUnaryPrimitiveImpl(start, end, null, descriptor) KonanIr.IrCall.Primitive.BINARY -> - IrBinaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor)) + IrBinaryPrimitiveImpl(start, end, null, descriptor) else -> TODO("Unexpected primitive IrCall.") } deserializeMemberAccessCommon(call, proto.memberAccess) return call } - private fun deserializeCallableReference(proto: KonanIr.IrCallableReference, - start: Int, end: Int, type: KotlinType): IrCallableReference { + fun deserializeCallableReference(proto: KonanIr.IrCallableReference, + start: Int, end: Int, type: KotlinType): IrCallableReference { - val descriptor = deserializeDescriptor(proto.descriptor) as CallableDescriptor + val descriptor = deserializeDescriptor(proto.getDescriptor()) as CallableDescriptor val typeMap = deserializeTypeMap(descriptor, proto.typeMap) - return when (descriptor) { - is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, typeMap, null) + val callable = when (descriptor) { + is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, descriptor, typeMap, null) else -> TODO() } + return callable } - private fun deserializeComposite(proto: KonanIr.IrComposite, start: Int, end: Int, type: KotlinType): IrComposite { + fun deserializeComposite(proto: KonanIr.IrComposite, start: Int, end: Int, type: KotlinType): IrComposite { val statements = mutableListOf() val statementProtos = proto.getStatementList() statementProtos.forEach { @@ -848,95 +854,95 @@ internal class IrDeserializer(val context: Context, return IrCompositeImpl(start, end, type, null, statements) } - private fun deserializeDelegatingConstructorCall(proto: KonanIr.IrDelegatingConstructorCall, start: Int, end: Int): IrDelegatingConstructorCall { + fun deserializeDelegatingConstructorCall(proto: KonanIr.IrDelegatingConstructorCall, start: Int, end: Int): IrDelegatingConstructorCall { val descriptor = deserializeDescriptor(proto.getDescriptor()) as ClassConstructorDescriptor - val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.typeMap) + val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.getTypeMap()) - val call = IrDelegatingConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor), descriptor, typeArgs) + val call = IrDelegatingConstructorCallImpl(start, end, descriptor, typeArgs) deserializeMemberAccessCommon(call, proto.memberAccess) return call } fun deserializeEnumConstructorCall(proto: KonanIr.IrEnumConstructorCall, start: Int, end: Int): IrEnumConstructorCall { - val descriptor = deserializeDescriptor(proto.descriptor) as ClassConstructorDescriptor - val call = IrEnumConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor)) + val descriptor = deserializeDescriptor(proto.getDescriptor()) as ClassConstructorDescriptor + val call = IrEnumConstructorCallImpl(start, end, descriptor) deserializeMemberAccessCommon(call, proto.memberAccess) return call } - private fun deserializeGetClass(proto: KonanIr.IrGetClass, start: Int, end: Int, type: KotlinType): IrGetClass { + fun deserializeGetClass(proto: KonanIr.IrGetClass, start: Int, end: Int, type: KotlinType): IrGetClass { val argument = deserializeExpression(proto.argument) return IrGetClassImpl(start, end, type, argument) } - private fun deserializeGetField(proto: KonanIr.IrGetField, start: Int, end: Int): IrGetField { + fun deserializeGetField(proto: KonanIr.IrGetField, start: Int, end: Int): IrGetField { val access = proto.fieldAccess - val descriptor = deserializeDescriptor(access.descriptor) as PropertyDescriptor + val descriptor = deserializeDescriptor(access.getDescriptor()) as PropertyDescriptor val superQualifier = if (access.hasSuper()) { - deserializeDescriptor(access.descriptor) as ClassDescriptor + deserializeDescriptor(access.getDescriptor()) as ClassDescriptor } else null val receiver = if (access.hasReceiver()) { deserializeExpression(access.receiver) } else null - return IrGetFieldImpl(start, end, IrFieldSymbolImpl(descriptor), receiver, null, createClassSymbolOrNull(superQualifier)) + return IrGetFieldImpl(start, end, descriptor, receiver, null, superQualifier) } - private fun deserializeGetValue(proto: KonanIr.IrGetValue, start: Int, end: Int): IrGetValue { + fun deserializeGetValue(proto: KonanIr.IrGetValue, start: Int, end: Int): IrGetValue { val descriptor = deserializeDescriptor(proto.descriptor) as ValueDescriptor // TODO: origin! - return IrGetValueImpl(start, end, createValueSymbol(descriptor), null) + return IrGetValueImpl(start, end, descriptor, null) } - private fun deserializeGetEnumValue(proto: KonanIr.IrGetEnumValue, start: Int, end: Int): IrGetEnumValue { + fun deserializeGetEnumValue(proto: KonanIr.IrGetEnumValue, start: Int, end: Int): IrGetEnumValue { val type = deserializeKotlinType(proto.type) val descriptor = deserializeDescriptor(proto.descriptor) as ClassDescriptor - return IrGetEnumValueImpl(start, end, type, IrEnumEntrySymbolImpl(descriptor)) + return IrGetEnumValueImpl(start, end, type, descriptor) } - private fun deserializeGetObject(proto: KonanIr.IrGetObject, start: Int, end: Int, type: KotlinType): IrGetObjectValue { + fun deserializeGetObject(proto: KonanIr.IrGetObject, start: Int, end: Int, type: KotlinType): IrGetObjectValue { val descriptor = deserializeDescriptor(proto.descriptor) as ClassDescriptor - return IrGetObjectValueImpl(start, end, type, IrClassSymbolImpl(descriptor)) + return IrGetObjectValueImpl(start, end, type, descriptor) } - private fun deserializeInstanceInitializerCall(proto: KonanIr.IrInstanceInitializerCall, start: Int, end: Int): IrInstanceInitializerCall { - val descriptor = deserializeDescriptor(proto.descriptor) as ClassDescriptor + fun deserializeInstanceInitializerCall(proto: KonanIr.IrInstanceInitializerCall, start: Int, end: Int): IrInstanceInitializerCall { + val descriptor = deserializeDescriptor(proto.getDescriptor()) as ClassDescriptor - return IrInstanceInitializerCallImpl(start, end, IrClassSymbolImpl(descriptor)) + return IrInstanceInitializerCallImpl(start, end, descriptor) } - private fun deserializeReturn(proto: KonanIr.IrReturn, start: Int, end: Int, type: KotlinType): IrReturn { + fun deserializeReturn(proto: KonanIr.IrReturn, start: Int, end: Int, type: KotlinType): IrReturn { val descriptor = - deserializeDescriptor(proto.returnTarget) as FunctionDescriptor - val value = deserializeExpression(proto.value) - return IrReturnImpl(start, end, type, createFunctionSymbol(descriptor), value) + deserializeDescriptor(proto.getReturnTarget()) as FunctionDescriptor + val value = deserializeExpression(proto.getValue()) + return IrReturnImpl(start, end, type, descriptor, value) } - private fun deserializeSetField(proto: KonanIr.IrSetField, start: Int, end: Int): IrSetField { + fun deserializeSetField(proto: KonanIr.IrSetField, start: Int, end: Int): IrSetField { val access = proto.fieldAccess - val descriptor = deserializeDescriptor(access.descriptor) as PropertyDescriptor + val descriptor = deserializeDescriptor(access.getDescriptor()) as PropertyDescriptor val superQualifier = if (access.hasSuper()) { - deserializeDescriptor(access.descriptor) as ClassDescriptor + deserializeDescriptor(access.getDescriptor()) as ClassDescriptor } else null val receiver = if (access.hasReceiver()) { deserializeExpression(access.receiver) } else null val value = deserializeExpression(proto.value) - return IrSetFieldImpl(start, end, IrFieldSymbolImpl(descriptor), receiver, value, null, createClassSymbolOrNull(superQualifier)) + return IrSetFieldImpl(start, end, descriptor, receiver, value, null, superQualifier) } - private fun deserializeSetVariable(proto: KonanIr.IrSetVariable, start: Int, end: Int): IrSetVariable { - val descriptor = deserializeDescriptor(proto.descriptor) as VariableDescriptor - val value = deserializeExpression(proto.value) - return IrSetVariableImpl(start, end, IrVariableSymbolImpl(descriptor), value, null) + fun deserializeSetVariable(proto: KonanIr.IrSetVariable, start: Int, end: Int): IrSetVariable { + val descriptor = deserializeDescriptor(proto.getDescriptor()) as VariableDescriptor + val value = deserializeExpression(proto.getValue()) + return IrSetVariableImpl(start, end, descriptor, value, null) } - private fun deserializeStringConcat(proto: KonanIr.IrStringConcat, start: Int, end: Int, type: KotlinType): IrStringConcatenation { - val argumentProtos = proto.argumentList + fun deserializeStringConcat(proto: KonanIr.IrStringConcat, start: Int, end: Int, type: KotlinType): IrStringConcatenation { + val argumentProtos = proto.getArgumentList() val arguments = mutableListOf() argumentProtos.forEach { @@ -945,14 +951,14 @@ internal class IrDeserializer(val context: Context, return IrStringConcatenationImpl(start, end, type, arguments) } - private fun deserializeThrow(proto: KonanIr.IrThrow, start: Int, end: Int, type: KotlinType): IrThrowImpl { - return IrThrowImpl(start, end, type, deserializeExpression(proto.value)) + fun deserializeThrow(proto: KonanIr.IrThrow, start: Int, end: Int, type: KotlinType): IrThrowImpl { + return IrThrowImpl(start, end, type, deserializeExpression(proto.getValue())) } - private fun deserializeTry(proto: KonanIr.IrTry, start: Int, end: Int, type: KotlinType): IrTryImpl { - val result = deserializeExpression(proto.result) + fun deserializeTry(proto: KonanIr.IrTry, start: Int, end: Int, type: KotlinType): IrTryImpl { + val result = deserializeExpression(proto.getResult()) val catches = mutableListOf() - proto.catchList.forEach { + proto.getCatchList().forEach { catches.add(deserializeStatement(it) as IrCatch) } val finallyExpression = @@ -960,7 +966,7 @@ internal class IrDeserializer(val context: Context, return IrTryImpl(start, end, type, result, catches, finallyExpression) } - private fun deserializeTypeOperator(operator: KonanIr.IrTypeOperator): IrTypeOperator { + fun deserializeTypeOperator(operator: KonanIr.IrTypeOperator): IrTypeOperator { when (operator) { KonanIr.IrTypeOperator.CAST -> return IrTypeOperator.CAST @@ -980,22 +986,22 @@ internal class IrDeserializer(val context: Context, } } - private fun deserializeTypeOp(proto: KonanIr.IrTypeOp, start: Int, end: Int, type: KotlinType) : IrTypeOperatorCall { - val operator = deserializeTypeOperator(proto.operator) - val operand = deserializeKotlinType(proto.operand) - val argument = deserializeExpression(proto.argument) + fun deserializeTypeOp(proto: KonanIr.IrTypeOp, start: Int, end: Int, type: KotlinType) : IrTypeOperatorCall { + val operator = deserializeTypeOperator(proto.getOperator()) + val operand = deserializeKotlinType(proto.getOperand()) + val argument = deserializeExpression(proto.getArgument()) return IrTypeOperatorCallImpl(start, end, type, operator, operand, argument) } - private fun deserializeVararg(proto: KonanIr.IrVararg, start: Int, end: Int, type: KotlinType): IrVararg { - val elementType = deserializeKotlinType(proto.elementType) + fun deserializeVararg(proto: KonanIr.IrVararg, start: Int, end: Int, type: KotlinType): IrVararg { + val elementType = deserializeKotlinType(proto.getElementType()) return IrVarargImpl(start, end, type, elementType) } - private fun deserializeWhen(proto: KonanIr.IrWhen, start: Int, end: Int, type: KotlinType): IrWhen { + fun deserializeWhen(proto: KonanIr.IrWhen, start: Int, end: Int, type: KotlinType): IrWhen { val branches = mutableListOf() - proto.branchList.forEach { + proto.getBranchList().forEach { branches.add(deserializeStatement(it) as IrBranch) } @@ -1003,13 +1009,13 @@ internal class IrDeserializer(val context: Context, return IrWhenImpl(start, end, type, null, branches) } - private fun deserializeLoop(proto: KonanIr.Loop, loop: IrLoopBase): IrLoopBase { - val loopId = proto.loopId + fun deserializeLoop(proto: KonanIr.Loop, loop: IrLoopBase): IrLoopBase { + val loopId = proto.getLoopId() loopIndex.getOrPut(loopId){loop} - val label = if (proto.hasLabel()) proto.label else null - val body = if (proto.hasBody()) deserializeExpression(proto.body) else null - val condition = deserializeExpression(proto.condition) + val label = if (proto.hasLabel()) proto.getLabel() else null + val body = if (proto.hasBody()) deserializeExpression(proto.getBody()) else null + val condition = deserializeExpression(proto.getCondition()) loop.label = label loop.condition = condition @@ -1018,7 +1024,7 @@ internal class IrDeserializer(val context: Context, return loop } - private fun deserializeDoWhile(proto: KonanIr.IrDoWhile, start: Int, end: Int, type: KotlinType): IrDoWhileLoop { + fun deserializeDoWhile(proto: KonanIr.IrDoWhile, start: Int, end: Int, type: KotlinType): IrDoWhileLoop { // we create the loop before deserializing the body, so that // IrBreak statements have something to put into 'loop' field. val loop = IrDoWhileLoopImpl(start, end, type, null) @@ -1026,7 +1032,7 @@ internal class IrDeserializer(val context: Context, return loop } - private fun deserializeWhile(proto: KonanIr.IrWhile, start: Int, end: Int, type: KotlinType): IrWhileLoop { + fun deserializeWhile(proto: KonanIr.IrWhile, start: Int, end: Int, type: KotlinType): IrWhileLoop { // we create the loop before deserializing the body, so that // IrBreak statements have something to put into 'loop' field. val loop = IrWhileLoopImpl(start, end, type, null) @@ -1034,9 +1040,9 @@ internal class IrDeserializer(val context: Context, return loop } - private fun deserializeBreak(proto: KonanIr.IrBreak, start: Int, end: Int, type: KotlinType): IrBreak { - val label = if(proto.hasLabel()) proto.label else null - val loopId = proto.loopId + fun deserializeBreak(proto: KonanIr.IrBreak, start: Int, end: Int, type: KotlinType): IrBreak { + val label = if(proto.hasLabel()) proto.getLabel() else null + val loopId = proto.getLoopId() val loop = loopIndex[loopId]!! val irBreak = IrBreakImpl(start, end, type, loop) irBreak.label = label @@ -1044,9 +1050,9 @@ internal class IrDeserializer(val context: Context, return irBreak } - private fun deserializeContinue(proto: KonanIr.IrContinue, start: Int, end: Int, type: KotlinType): IrContinue { - val label = if(proto.hasLabel()) proto.label else null - val loopId = proto.loopId + fun deserializeContinue(proto: KonanIr.IrContinue, start: Int, end: Int, type: KotlinType): IrContinue { + val label = if(proto.hasLabel()) proto.getLabel() else null + val loopId = proto.getLoopId() val loop = loopIndex[loopId]!! val irContinue = IrContinueImpl(start, end, type, loop) irContinue.label = label @@ -1054,7 +1060,7 @@ internal class IrDeserializer(val context: Context, return irContinue } - private fun deserializeConst(proto: KonanIr.IrConst, start: Int, end: Int, type: KotlinType): IrExpression = + fun deserializeConst(proto: KonanIr.IrConst, start: Int, end: Int, type: KotlinType): IrExpression = when(proto.valueCase) { NULL -> IrConstImpl.constNull(start, end, type) @@ -1079,12 +1085,12 @@ internal class IrDeserializer(val context: Context, } } - private fun deserializeOperation(proto: KonanIr.IrOperation, start: Int, end: Int, type: KotlinType): IrExpression = + fun deserializeOperation(proto: KonanIr.IrOperation, start: Int, end: Int, type: KotlinType): IrExpression = when (proto.operationCase) { BLOCK -> deserializeBlock(proto.block, start, end, type) BREAK - -> deserializeBreak(proto.`break`, start, end, type) + -> deserializeBreak(proto.getBreak(), start, end, type) CLASS_REFERENCE -> deserializeClassReference(proto.classReference, start, end, type) CALL @@ -1096,7 +1102,7 @@ internal class IrDeserializer(val context: Context, CONST -> deserializeConst(proto.const, start, end, type) CONTINUE - -> deserializeContinue(proto.`continue`, start, end, type) + -> deserializeContinue(proto.getContinue(), start, end, type) DELEGATING_CONSTRUCTOR_CALL -> deserializeDelegatingConstructorCall(proto.delegatingConstructorCall, start, end) DO_WHILE @@ -1114,7 +1120,7 @@ internal class IrDeserializer(val context: Context, INSTANCE_INITIALIZER_CALL -> deserializeInstanceInitializerCall(proto.instanceInitializerCall, start, end) RETURN - -> deserializeReturn(proto.`return`, start, end, type) + -> deserializeReturn(proto.getReturn(), start, end, type) SET_FIELD -> deserializeSetField(proto.setField, start, end) SET_VARIABLE @@ -1122,37 +1128,37 @@ internal class IrDeserializer(val context: Context, STRING_CONCAT -> deserializeStringConcat(proto.stringConcat, start, end, type) THROW - -> deserializeThrow(proto.`throw`, start, end, type) + -> deserializeThrow(proto.getThrow(), start, end, type) TRY - -> deserializeTry(proto.`try`, start, end, type) + -> deserializeTry(proto.getTry(), start, end, type) TYPE_OP -> deserializeTypeOp(proto.typeOp, start, end, type) VARARG -> deserializeVararg(proto.vararg, start, end, type) WHEN - -> deserializeWhen(proto.`when`, start, end, type) + -> deserializeWhen(proto.getWhen(), start, end, type) WHILE - -> deserializeWhile(proto.`while`, start, end, type) + -> deserializeWhile(proto.getWhile(), start, end, type) else -> { TODO("Expression deserialization not implemented: ${proto.operationCase}") } } - private fun deserializeExpression(proto: KonanIr.IrExpression): IrExpression { - val start = proto.coordinates.startOffset - val end = proto.coordinates.endOffset - val type = deserializeKotlinType(proto.type) - val operation = proto.operation + fun deserializeExpression(proto: KonanIr.IrExpression): IrExpression { + val start = proto.getCoordinates().getStartOffset() + val end = proto.getCoordinates().getEndOffset() + val type = deserializeKotlinType(proto.getType()) + val operation = proto.getOperation() val expression = deserializeOperation(operation, start, end, type) context.log{"### Deserialized expression: ${ir2string(expression)}"} return expression } - private fun deserializeIrClass(proto: KonanIr.IrClass, descriptor: ClassDescriptor, start: Int, end: Int, origin: IrDeclarationOrigin): IrClass { + fun deserializeIrClass(proto: KonanIr.IrClass, descriptor: ClassDescriptor, start: Int, end: Int, origin: IrDeclarationOrigin): IrClass { val members = mutableListOf() - proto.memberList.forEach { + proto.getMemberList().forEach { members.add(deserializeDeclaration(it)) } @@ -1165,10 +1171,10 @@ internal class IrDeserializer(val context: Context, } - private fun deserializeIrFunction(proto: KonanIr.IrFunction, descriptor: FunctionDescriptor, - start: Int, end: Int, origin: IrDeclarationOrigin): IrFunction { + fun deserializeIrFunction(proto: KonanIr.IrFunction, descriptor: FunctionDescriptor, + start: Int, end: Int, origin: IrDeclarationOrigin): IrFunction { - val body = deserializeStatement(proto.body) + val body = deserializeStatement(proto.getBody()) val function = IrFunctionImpl(start, end, origin, descriptor, body as IrBody) @@ -1178,24 +1184,26 @@ internal class IrDeserializer(val context: Context, val expr = deserializeExpression(it.value) function.putDefault( - descriptor.valueParameters[it.position], - IrExpressionBodyImpl(start, end, expr)) + descriptor.valueParameters.get(it.position), + IrExpressionBodyImpl(start, end, expr)) } return function } - private fun deserializeIrVariable(proto: KonanIr.IrVar, descriptor: VariableDescriptor, - start: Int, end: Int, origin: IrDeclarationOrigin): IrVariable { + fun deserializeIrVariable(proto: KonanIr.IrVar, descriptor: VariableDescriptor, + start: Int, end: Int, origin: IrDeclarationOrigin): IrVariable { val initializer = if (proto.hasInitializer()) { - deserializeExpression(proto.initializer) + deserializeExpression(proto.getInitializer()) } else null - return IrVariableImpl(start, end, origin, descriptor, initializer) + val variable = IrVariableImpl(start, end, origin, descriptor, initializer) + + return variable } - private fun deserializeIrEnumEntry(proto: KonanIr.IrEnumEntry, descriptor: ClassDescriptor, - start: Int, end: Int, origin: IrDeclarationOrigin): IrEnumEntry { + fun deserializeIrEnumEntry(proto: KonanIr.IrEnumEntry, descriptor: ClassDescriptor, + start: Int, end: Int, origin: IrDeclarationOrigin): IrEnumEntry { val enumEntry = IrEnumEntryImpl(start, end, origin, descriptor) if (proto.hasCorrespondingClass()) { @@ -1206,17 +1214,17 @@ internal class IrDeserializer(val context: Context, return enumEntry } - private fun deserializeDeclaration(proto: KonanIr.IrDeclaration): IrDeclaration { + fun deserializeDeclaration(proto: KonanIr.IrDeclaration): IrDeclaration { val descriptor = deserializeDescriptor(proto.descriptor) - if (descriptor !is VariableDescriptor && descriptor != rootFunction) + if (!(descriptor is VariableDescriptor) && descriptor != rootFunction) localDeserializer.pushContext(descriptor) - val start = proto.coordinates.startOffset - val end = proto.coordinates.endOffset + val start = proto.getCoordinates().getStartOffset() + val end = proto.getCoordinates().getEndOffset() val origin = DEFINED // TODO: retore the real origins - val declarator = proto.declarator + val declarator = proto.getDeclarator() val declaration: IrDeclaration = when { declarator.hasIrClass() diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUnboundSymbolReplacer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUnboundSymbolReplacer.kt index 033c348c363..b40552a420b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUnboundSymbolReplacer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUnboundSymbolReplacer.kt @@ -55,7 +55,6 @@ internal fun IrModuleFragment.replaceUnboundSymbols(context: Context) { // Generate missing external stubs: // TODO: ModuleGenerator::generateUnboundSymbolsAsDependencies(IRModuleFragment) is private function :/ - @Suppress("DEPRECATION") ExternalDependenciesGenerator(symbolTable = context.psi2IrGeneratorContext.symbolTable, irBuiltIns = context.irBuiltIns).generateUnboundSymbolsAsDependencies(this) // Merge duplicated module and package declarations: diff --git a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/KLibInstall.kt b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/KLibInstall.kt index fbc9f95c959..fd43cf42b3f 100644 --- a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/KLibInstall.kt +++ b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/KLibInstall.kt @@ -28,8 +28,7 @@ open class KlibInstall: Exec() { override fun configure(config: Closure<*>): Task { val result = super.configure(config) - val konanHomePath = project.findProperty("konan.home") ?: "dist" - val konanHome = project.rootProject.file(konanHomePath) + val konanHome = project.rootProject.file(project.findProperty("konan.home") ?: "dist") val suffix = if (TargetManager.host == KonanTarget.MINGW) ".bat" else "" val klibProgram = "$konanHome/bin/klib$suffix" @@ -44,4 +43,4 @@ open class KlibInstall: Exec() { } return result } -} \ No newline at end of file +}