From 4b12f1c54c002ed3ea9efcd555d33af9bef1cebc Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Thu, 8 Feb 2018 16:14:01 +0300 Subject: [PATCH] [warnings] g/c some warnings and idea inspections --- .../kotlin/backend/konan/KonanDriver.kt | 1 + .../kotlin/backend/konan/KonanLower.kt | 5 +- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 4 +- .../backend/konan/llvm/LlvmDeclarations.kt | 5 +- .../lower/DeepCopyIrTreeWithDescriptors.kt | 17 +- .../backend/konan/lower/FunctionInlining.kt | 3 +- .../lower/InlineConstructorsTransformation.kt | 13 +- .../backend/konan/objcexport/ObjCExport.kt | 5 +- .../backend/konan/optimizations/DFGBuilder.kt | 6 +- .../konan/optimizations/EscapeAnalysis.kt | 2 +- .../LocalDeclarationDeserializer.kt | 22 +- .../LocalDeclarationSerializer.kt | 3 +- .../konan/serialization/SerializeIr.kt | 570 +++++++++--------- .../kotlin/ir/util/IrUnboundSymbolReplacer.kt | 1 + .../org/jetbrains/kotlin/KLibInstall.kt | 3 +- 15 files changed, 330 insertions(+), 330 deletions(-) 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 72121763e29..e5a6a193f34 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,6 +67,7 @@ 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 4547b46b314..32f8409a3ad 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) { } } - fun lowerModule(irModule: IrModuleFragment) { + private fun lowerModule(irModule: IrModuleFragment) { val phaser = PhaseManager(context) phaser.phase(KonanPhase.REMOVE_EXPECT_DECLARATIONS) { @@ -72,11 +72,12 @@ internal class KonanLower(val context: Context) { irModule.files.forEach(InteropLoweringPart1(context)::lower) } + @Suppress("DEPRECATION") irModule.replaceUnboundSymbols(context) validateIrModule(context, irModule) } - fun lowerFile(irFile: IrFile) { + private 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 ae39ccd87fb..4f58627b11b 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,6 +1401,8 @@ 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) { @@ -1412,7 +1414,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(@Suppress("UNCHECKED_CAST") value as IrConst) + IrConstKind.String -> return evaluateStringConst(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 ba592710f57..4b6b3956caa 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,7 +146,10 @@ private fun Context.getDeclaredFields(classDescriptor: ClassDescriptor): List): LLVMTypeRef { - val fieldTypes = fields.map { getLLVMType(if (it.isDelegated) context.builtIns.nullableAnyType else it.type) } + val fieldTypes = fields.map { + @Suppress("DEPRECATION") + 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 b4b04cfac3c..a1222bd1fb9 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 @@ -28,6 +28,8 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl import org.jetbrains.kotlin.ir.descriptors.IrTemporaryVariableDescriptorImpl import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.impl.createClassSymbolOrNull +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol import org.jetbrains.kotlin.ir.util.DeepCopyIrTree import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.name.Name @@ -41,7 +43,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, val parentDescriptor: DeclarationDescriptor, - context: CommonBackendContext) { + val context: CommonBackendContext) { private val descriptorSubstituteMap: MutableMap = mutableMapOf() private var typeSubstitutor: TypeSubstitutor? = null @@ -274,6 +276,7 @@ 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, @@ -286,7 +289,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 { @@ -378,6 +381,7 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, //-----------------------------------------------------------------------------// + @Suppress("DEPRECATION") inner class InlineCopyIr : DeepCopyIrTree() { override fun mapClassDeclaration (descriptor: ClassDescriptor) = descriptorSubstituteMap.getOrDefault(descriptor, descriptor) as ClassDescriptor @@ -596,8 +600,6 @@ class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescriptor, } } - val context = context - } class SubstitutedDescriptor(val inlinedFunction: FunctionDescriptor, val descriptor: DeclarationDescriptor) @@ -633,10 +635,11 @@ class DescriptorSubstitutorForExternalScope(val globalSubstituteMap: MutableMap< startOffset = oldExpression.startOffset, endOffset = oldExpression.endOffset, type = oldExpression.type, - calleeDescriptor = newDescriptor, + symbol = createFunctionSymbol(newDescriptor), + descriptor = newDescriptor, typeArguments = oldExpression.typeArguments, origin = oldExpression.origin, - superQualifierDescriptor = oldExpression.superQualifier + superQualifierSymbol = createClassSymbolOrNull(oldExpression.superQualifier) ).apply { oldExpression.descriptor.valueParameters.forEach { val valueArgument = oldExpression.getValueArgument(it) @@ -659,7 +662,7 @@ class DescriptorSubstitutorForExternalScope(val globalSubstituteMap: MutableMap< if (newDescriptor == oldDescriptor) return oldExpression - return oldExpression.shallowCopy(oldExpression.origin, newDescriptor, oldExpression.superQualifier) + return oldExpression.shallowCopy(oldExpression.origin, createFunctionSymbol(newDescriptor), oldExpression.superQualifierSymbol) } } 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 987fc10c45c..72d1a21b70e 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,6 +41,7 @@ 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 @@ -347,7 +348,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(""" @@ -113,7 +112,7 @@ internal class ObjCExport(val context: Context) { CFBundleExecutable - $bundleExecutable + $name 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 b246a275d9f..0e73ee2e5c3 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,6 +42,8 @@ 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 @@ -195,7 +197,7 @@ private class ExpressionValuesExtractor(val returnableBlockValues: Map { if ((expression.type.isUnit() || expression.type.isNothing())) { block(IrGetObjectValueImpl(expression.startOffset, expression.endOffset, - expression.type, (expression.type.constructor.declarationDescriptor as ClassDescriptor))) + expression.type, IrClassSymbolImpl(expression.type.constructor.declarationDescriptor as ClassDescriptor))) } else TODO(ir2stringWhole(expression)) } @@ -560,7 +562,7 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag is IrDelegatingConstructorCall -> { val thiz = IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, - (descriptor as ConstructorDescriptor).constructedClass.thisAsReceiverParameter) + createValueSymbol((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 4b2f2950374..cc64eb69f2e 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,7 +19,6 @@ 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 @@ -162,6 +161,7 @@ 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 2b82f8fb827..54eff72895f 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,7 +29,6 @@ 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. @@ -101,12 +100,7 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) { contextStack.pop() } - fun deserializeInlineType(type: ProtoBuf.Type): KotlinType { - - val result = typeDeserializer.type(type) - - return result - } + fun deserializeInlineType(type: ProtoBuf.Type) = typeDeserializer.type(type) fun deserializeClass(irProto: KonanIr.KotlinDescriptor): ClassDescriptor { return DeserializedClassDescriptor(parentContext, irProto.irLocalDeclaration.descriptor.clazz, nameResolver, SourceElement.NO_SOURCE) @@ -121,9 +115,8 @@ 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 constructor + return memberDeserializer.loadConstructor(proto, isPrimary) } fun deserializeProperty(irProto: KonanIr.KotlinDescriptor): VariableDescriptor { @@ -138,18 +131,17 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) { } } - fun propertyToVariable(property: PropertyDescriptor): LocalVariableDescriptor { - val variable = LocalVariableDescriptor( + private fun propertyToVariable(property: PropertyDescriptor): LocalVariableDescriptor { + // TODO: Should we transform the getter and the setter too? + @Suppress("DEPRECATION") + return 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 2ce24a10984..17a4c282ce9 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,8 +97,9 @@ 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. - fun variableAsProperty(variable: VariableDescriptor): PropertyDescriptor { + private 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 81bf5040437..ed8d5c3ffa8 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.createFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.impl.* 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, - val descriptorTable: DescriptorTable, - val stringTable: KonanStringTable, - val rootFunctionSerializer: KonanDescriptorSerializer, - var rootFunction: FunctionDescriptor) { +internal class IrSerializer(val context: Context, + descriptorTable: DescriptorTable, + stringTable: KonanStringTable, + rootFunctionSerializer: KonanDescriptorSerializer, + private var rootFunction: FunctionDescriptor) { - val loopIndex = mutableMapOf() + private val loopIndex = mutableMapOf() var currentLoopIndex = 0 - val localDeclarationSerializer + private val localDeclarationSerializer = LocalDeclarationSerializer(context, rootFunctionSerializer) - val irDescriptorSerializer + private val irDescriptorSerializer = IrDescriptorSerializer(context, descriptorTable, stringTable, localDeclarationSerializer, rootFunction) @@ -72,12 +72,12 @@ internal class IrSerializer(val context: Context, return encodeDeclaration(declaration) } - fun serializeKotlinType(type: KotlinType): KonanIr.KotlinType { + private fun serializeKotlinType(type: KotlinType): KonanIr.KotlinType { context.log{"### serializing KotlinType: " + type} return irDescriptorSerializer.serializeKotlinType(type) } - fun serializeDescriptor(descriptor: DeclarationDescriptor): KonanIr.KotlinDescriptor { + private fun serializeDescriptor(descriptor: DeclarationDescriptor): KonanIr.KotlinDescriptor { context.log{"### serializeDescriptor $descriptor"} // Behind this call starts a large world of @@ -85,15 +85,14 @@ internal class IrSerializer(val context: Context, return irDescriptorSerializer.serializeDescriptor(descriptor) } - fun serializeCoordinates(start: Int, end: Int): KonanIr.Coordinates { - val proto = KonanIr.Coordinates.newBuilder() + private fun serializeCoordinates(start: Int, end: Int): KonanIr.Coordinates { + return KonanIr.Coordinates.newBuilder() .setStartOffset(start) .setEndOffset(end) .build() - return proto } - fun serializeTypeMap(typeArguments: Map): KonanIr.TypeMap { + private fun serializeTypeMap(typeArguments: Map): KonanIr.TypeMap { val proto = KonanIr.TypeMap.newBuilder() typeArguments.forEach { key, value -> val pair = KonanIr.TypeMap.Pair.newBuilder() @@ -105,12 +104,12 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeMap { + private fun serializeTypeArguments(call: IrMemberAccessExpression): KonanIr.TypeMap { val typeMap = mutableMapOf() call.descriptor.original.typeParameters.forEach { val type = call.getTypeArgument(it) - if (type != null) typeMap.put(it, type) + if (type != null) typeMap[it] = type } return serializeTypeMap(typeMap) @@ -119,7 +118,7 @@ internal class IrSerializer(val context: Context, /* -------------------------------------------------------------------------- */ - fun serializeBlockBody(expression: IrBlockBody): KonanIr.IrBlockBody { + private fun serializeBlockBody(expression: IrBlockBody): KonanIr.IrBlockBody { val proto = KonanIr.IrBlockBody.newBuilder() expression.statements.forEach { proto.addStatement(serializeStatement(it)) @@ -127,16 +126,16 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeBranch(branch: IrBranch): KonanIr.IrBranch { + private fun serializeBranch(branch: IrBranch): KonanIr.IrBranch { val proto = KonanIr.IrBranch.newBuilder() - proto.setCondition(serializeExpression(branch.condition)) - proto.setResult(serializeExpression(branch.result)) + proto.condition = serializeExpression(branch.condition) + proto.result = serializeExpression(branch.result) return proto.build() } - fun serializeBlock(block: IrBlock): KonanIr.IrBlock { + private fun serializeBlock(block: IrBlock): KonanIr.IrBlock { val isLambdaOrigin = block.origin == IrStatementOrigin.LAMBDA || block.origin == IrStatementOrigin.ANONYMOUS_FUNCTION @@ -148,7 +147,7 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeComposite(composite: IrComposite): KonanIr.IrComposite { + private fun serializeComposite(composite: IrComposite): KonanIr.IrComposite { val proto = KonanIr.IrComposite.newBuilder() composite.statements.forEach { proto.addStatement(serializeStatement(it)) @@ -156,14 +155,14 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeCatch(catch: IrCatch): KonanIr.IrCatch { + private fun serializeCatch(catch: IrCatch): KonanIr.IrCatch { val proto = KonanIr.IrCatch.newBuilder() .setCatchParameter(serializeDeclaration(catch.catchParameter)) .setResult(serializeExpression(catch.result)) return proto.build() } - fun serializeStringConcat(expression: IrStringConcatenation): KonanIr.IrStringConcat { + private fun serializeStringConcat(expression: IrStringConcatenation): KonanIr.IrStringConcat { val proto = KonanIr.IrStringConcat.newBuilder() expression.arguments.forEach { proto.addArgument(serializeExpression(it)) @@ -171,7 +170,7 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun irCallToPrimitiveKind(call: IrCall): KonanIr.IrCall.Primitive = when (call) { + private fun irCallToPrimitiveKind(call: IrCall): KonanIr.IrCall.Primitive = when (call) { is IrNullaryPrimitiveImpl -> KonanIr.IrCall.Primitive.NULLARY is IrUnaryPrimitiveImpl @@ -182,16 +181,16 @@ internal class IrSerializer(val context: Context, -> KonanIr.IrCall.Primitive.NOT_PRIMITIVE } - fun serializeMemberAccessCommon(call: IrMemberAccessExpression): KonanIr.MemberAccessCommon { + private fun serializeMemberAccessCommon(call: IrMemberAccessExpression): KonanIr.MemberAccessCommon { val proto = KonanIr.MemberAccessCommon.newBuilder() if (call.extensionReceiver != null) { - proto.setExtensionReceiver(serializeExpression(call.extensionReceiver!!)) + proto.extensionReceiver = serializeExpression(call.extensionReceiver!!) } if (call.dispatchReceiver != null) { - proto.setDispatchReceiver(serializeExpression(call.dispatchReceiver!!)) + proto.dispatchReceiver = serializeExpression(call.dispatchReceiver!!) } - proto.setTypeMap(serializeTypeArguments(call)) + proto.typeMap = serializeTypeArguments(call) call.descriptor.valueParameters.forEach { val actual = call.getValueArgument(it.index) @@ -202,52 +201,51 @@ internal class IrSerializer(val context: Context, assert(it.varargElementType != null || it.declaresDefaultValue()) } else { - val arg = actual - val argProto = serializeExpression(arg) + val argProto = serializeExpression(actual) proto.addValueArgument(argProto) } } return proto.build() } - fun serializeCall(call: IrCall): KonanIr.IrCall { + private fun serializeCall(call: IrCall): KonanIr.IrCall { val proto = KonanIr.IrCall.newBuilder() - proto.setKind(irCallToPrimitiveKind(call)) - proto.setDescriptor(serializeDescriptor(call.descriptor)) + proto.kind = irCallToPrimitiveKind(call) + proto.descriptor = serializeDescriptor(call.descriptor) if (call.superQualifier != null) { - proto.setSuper(serializeDescriptor(call.superQualifier!!)) + proto.`super` = serializeDescriptor(call.superQualifier!!) } - proto.setMemberAccess(serializeMemberAccessCommon(call)) + proto.memberAccess = serializeMemberAccessCommon(call) return proto.build() } - fun serializeCallableReference(callable: IrCallableReference): KonanIr.IrCallableReference { + private fun serializeCallableReference(callable: IrCallableReference): KonanIr.IrCallableReference { val proto = KonanIr.IrCallableReference.newBuilder() .setDescriptor(serializeDescriptor(callable.descriptor)) .setTypeMap(serializeTypeArguments(callable)) return proto.build() } - fun serializeClassReference(expression: IrClassReference): KonanIr.IrClassReference { + private fun serializeClassReference(expression: IrClassReference): KonanIr.IrClassReference { val proto = KonanIr.IrClassReference.newBuilder() .setClassDescriptor(serializeDescriptor(expression.symbol.descriptor)) return proto.build() } - fun serializeConst(value: IrConst<*>): KonanIr.IrConst { + private fun serializeConst(value: IrConst<*>): KonanIr.IrConst { val proto = KonanIr.IrConst.newBuilder() when (value.kind) { - 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) + 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 else -> { TODO("Const type serialization not implemented yet: ${ir2string(value)}") } @@ -255,14 +253,14 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeDelegatingConstructorCall(call: IrDelegatingConstructorCall): KonanIr.IrDelegatingConstructorCall { + private fun serializeDelegatingConstructorCall(call: IrDelegatingConstructorCall): KonanIr.IrDelegatingConstructorCall { val proto = KonanIr.IrDelegatingConstructorCall.newBuilder() .setDescriptor(serializeDescriptor(call.descriptor)) .setMemberAccess(serializeMemberAccessCommon(call)) return proto.build() } - fun serializeDoWhile(expression: IrDoWhileLoop): KonanIr.IrDoWhile { + private fun serializeDoWhile(expression: IrDoWhileLoop): KonanIr.IrDoWhile { val proto = KonanIr.IrDoWhile.newBuilder() .setLoop(serializeLoop(expression)) @@ -276,85 +274,85 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeGetClass(expression: IrGetClass): KonanIr.IrGetClass { + private fun serializeGetClass(expression: IrGetClass): KonanIr.IrGetClass { val proto = KonanIr.IrGetClass.newBuilder() .setArgument(serializeExpression(expression.argument)) return proto.build() } - fun serializeGetEnumValue(expression: IrGetEnumValue): KonanIr.IrGetEnumValue { + private fun serializeGetEnumValue(expression: IrGetEnumValue): KonanIr.IrGetEnumValue { val proto = KonanIr.IrGetEnumValue.newBuilder() .setType(serializeKotlinType(expression.type)) .setDescriptor(serializeDescriptor(expression.descriptor)) return proto.build() } - fun serializeFieldAccessCommon(expression: IrFieldAccessExpression): KonanIr.FieldAccessCommon { + private fun serializeFieldAccessCommon(expression: IrFieldAccessExpression): KonanIr.FieldAccessCommon { val proto = KonanIr.FieldAccessCommon.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) val superQualifier = expression.superQualifier if (superQualifier != null) - proto.setSuper(serializeDescriptor(superQualifier)) + proto.`super` = serializeDescriptor(superQualifier) val receiver = expression.receiver - if (receiver != null) - proto.setReceiver(serializeExpression(receiver)) + if (receiver != null) + proto.receiver = serializeExpression(receiver) return proto.build() } - fun serializeGetField(expression: IrGetField): KonanIr.IrGetField { + private fun serializeGetField(expression: IrGetField): KonanIr.IrGetField { val proto = KonanIr.IrGetField.newBuilder() .setFieldAccess(serializeFieldAccessCommon(expression)) return proto.build() } - fun serializeGetValue(expression: IrGetValue): KonanIr.IrGetValue { + private fun serializeGetValue(expression: IrGetValue): KonanIr.IrGetValue { val proto = KonanIr.IrGetValue.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) return proto.build() } - fun serializeGetObject(expression: IrGetObjectValue): KonanIr.IrGetObject { + private fun serializeGetObject(expression: IrGetObjectValue): KonanIr.IrGetObject { val proto = KonanIr.IrGetObject.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) return proto.build() } - fun serializeInstanceInitializerCall(call: IrInstanceInitializerCall): KonanIr.IrInstanceInitializerCall { + private fun serializeInstanceInitializerCall(call: IrInstanceInitializerCall): KonanIr.IrInstanceInitializerCall { val proto = KonanIr.IrInstanceInitializerCall.newBuilder() - proto.setDescriptor(serializeDescriptor(call.classDescriptor)) + proto.descriptor = serializeDescriptor(call.classDescriptor) return proto.build() } - fun serializeReturn(expression: IrReturn): KonanIr.IrReturn { + private fun serializeReturn(expression: IrReturn): KonanIr.IrReturn { val proto = KonanIr.IrReturn.newBuilder() .setReturnTarget(serializeDescriptor(expression.returnTarget)) .setValue(serializeExpression(expression.value)) return proto.build() } - fun serializeSetField(expression: IrSetField): KonanIr.IrSetField { + private fun serializeSetField(expression: IrSetField): KonanIr.IrSetField { val proto = KonanIr.IrSetField.newBuilder() .setFieldAccess(serializeFieldAccessCommon(expression)) .setValue(serializeExpression(expression.value)) return proto.build() } - fun serializeSetVariable(expression: IrSetVariable): KonanIr.IrSetVariable { + private fun serializeSetVariable(expression: IrSetVariable): KonanIr.IrSetVariable { val proto = KonanIr.IrSetVariable.newBuilder() .setDescriptor(serializeDescriptor(expression.descriptor)) .setValue(serializeExpression(expression.value)) return proto.build() } - fun serializeThrow(expression: IrThrow): KonanIr.IrThrow { + private fun serializeThrow(expression: IrThrow): KonanIr.IrThrow { val proto = KonanIr.IrThrow.newBuilder() .setValue(serializeExpression(expression.value)) return proto.build() } - fun serializeTry(expression: IrTry): KonanIr.IrTry { + private fun serializeTry(expression: IrTry): KonanIr.IrTry { val proto = KonanIr.IrTry.newBuilder() .setResult(serializeExpression(expression.tryResult)) val catchList = expression.catches @@ -363,12 +361,12 @@ internal class IrSerializer(val context: Context, } val finallyExpression = expression.finallyExpression if (finallyExpression != null) { - proto.setFinally(serializeExpression(finallyExpression)) + proto.finally = serializeExpression(finallyExpression) } return proto.build() } - fun serializeTypeOperator(operator: IrTypeOperator): KonanIr.IrTypeOperator = when (operator) { + private fun serializeTypeOperator(operator: IrTypeOperator): KonanIr.IrTypeOperator = when (operator) { IrTypeOperator.CAST -> KonanIr.IrTypeOperator.CAST IrTypeOperator.IMPLICIT_CAST @@ -386,7 +384,7 @@ internal class IrSerializer(val context: Context, else -> TODO("Unknown type operator") } - fun serializeTypeOp(expression: IrTypeOperatorCall): KonanIr.IrTypeOp { + private fun serializeTypeOp(expression: IrTypeOperatorCall): KonanIr.IrTypeOp { val proto = KonanIr.IrTypeOp.newBuilder() .setOperator(serializeTypeOperator(expression.operator)) .setOperand(serializeKotlinType(expression.typeOperand)) @@ -395,13 +393,13 @@ internal class IrSerializer(val context: Context, } - fun serializeVararg(expression: IrVararg): KonanIr.IrVararg { + private fun serializeVararg(expression: IrVararg): KonanIr.IrVararg { val proto = KonanIr.IrVararg.newBuilder() .setElementType(serializeKotlinType(expression.varargElementType)) return proto.build() } - fun serializeWhen(expression: IrWhen): KonanIr.IrWhen { + private fun serializeWhen(expression: IrWhen): KonanIr.IrWhen { val proto = KonanIr.IrWhen.newBuilder() val branches = expression.branches @@ -412,57 +410,57 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeLoop(expression: IrLoop): KonanIr.Loop { + private fun serializeLoop(expression: IrLoop): KonanIr.Loop { val proto = KonanIr.Loop.newBuilder() .setCondition(serializeExpression(expression.condition)) val label = expression.label if (label != null) { - proto.setLabel(label) + proto.label = label } - proto.setLoopId(currentLoopIndex) - loopIndex.put(expression, currentLoopIndex++) + proto.loopId = currentLoopIndex + loopIndex[expression] = currentLoopIndex++ val body = expression.body if (body != null) { - proto.setBody(serializeExpression(body)) + proto.body = serializeExpression(body) } return proto.build() } - fun serializeWhile(expression: IrWhileLoop): KonanIr.IrWhile { + private fun serializeWhile(expression: IrWhileLoop): KonanIr.IrWhile { val proto = KonanIr.IrWhile.newBuilder() .setLoop(serializeLoop(expression)) return proto.build() } - fun serializeBreak(expression: IrBreak): KonanIr.IrBreak { + private fun serializeBreak(expression: IrBreak): KonanIr.IrBreak { val proto = KonanIr.IrBreak.newBuilder() val label = expression.label if (label != null) { - proto.setLabel(label) + proto.label = label } val loopId = loopIndex[expression.loop]!! - proto.setLoopId(loopId) + proto.loopId = loopId return proto.build() } - fun serializeContinue(expression: IrContinue): KonanIr.IrContinue { + private fun serializeContinue(expression: IrContinue): KonanIr.IrContinue { val proto = KonanIr.IrContinue.newBuilder() val label = expression.label if (label != null) { - proto.setLabel(label) + proto.label = label } val loopId = loopIndex[expression.loop]!! - proto.setLoopId(loopId) + proto.loopId = loopId return proto.build() } - fun serializeExpression(expression: IrExpression): KonanIr.IrExpression { + private fun serializeExpression(expression: IrExpression): KonanIr.IrExpression { context.log{"### serializing Expression: ${ir2string(expression)}"} val coordinates = serializeCoordinates(expression.startOffset, expression.endOffset) @@ -473,40 +471,40 @@ internal class IrSerializer(val context: Context, val operationProto = KonanIr.IrOperation.newBuilder() when (expression) { - is IrBlock -> operationProto.setBlock(serializeBlock(expression)) - is IrBreak -> operationProto.setBreak(serializeBreak(expression)) + is IrBlock -> operationProto.block = serializeBlock(expression) + is IrBreak -> operationProto.`break` = serializeBreak(expression) is IrClassReference - -> operationProto.setClassReference(serializeClassReference(expression)) - is IrCall -> operationProto.setCall(serializeCall(expression)) + -> operationProto.classReference = serializeClassReference(expression) + is IrCall -> operationProto.call = serializeCall(expression) is IrCallableReference - -> operationProto.setCallableReference(serializeCallableReference(expression)) - is IrComposite -> operationProto.setComposite(serializeComposite(expression)) - is IrConst<*> -> operationProto.setConst(serializeConst(expression)) - is IrContinue -> operationProto.setContinue(serializeContinue(expression)) + -> operationProto.callableReference = serializeCallableReference(expression) + is IrComposite -> operationProto.composite = serializeComposite(expression) + is IrConst<*> -> operationProto.const = serializeConst(expression) + is IrContinue -> operationProto.`continue` = serializeContinue(expression) is IrDelegatingConstructorCall - -> 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)) + -> 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) is IrGetEnumValue - -> operationProto.setGetEnumValue(serializeGetEnumValue(expression)) + -> operationProto.getEnumValue = serializeGetEnumValue(expression) is IrGetObjectValue - -> operationProto.setGetObject(serializeGetObject(expression)) + -> operationProto.getObject = serializeGetObject(expression) is IrInstanceInitializerCall - -> operationProto.setInstanceInitializerCall(serializeInstanceInitializerCall(expression)) - is IrReturn -> operationProto.setReturn(serializeReturn(expression)) - is IrSetField -> operationProto.setSetField(serializeSetField(expression)) - is IrSetVariable -> operationProto.setSetVariable(serializeSetVariable(expression)) + -> operationProto.instanceInitializerCall = serializeInstanceInitializerCall(expression) + is IrReturn -> operationProto.`return` = serializeReturn(expression) + is IrSetField -> operationProto.setField = serializeSetField(expression) + is IrSetVariable -> operationProto.setVariable = serializeSetVariable(expression) is IrStringConcatenation - -> operationProto.setStringConcat(serializeStringConcat(expression)) - is IrThrow -> operationProto.setThrow(serializeThrow(expression)) - is IrTry -> operationProto.setTry(serializeTry(expression)) + -> operationProto.stringConcat = serializeStringConcat(expression) + is IrThrow -> operationProto.`throw` = serializeThrow(expression) + is IrTry -> operationProto.`try` = serializeTry(expression) is IrTypeOperatorCall - -> operationProto.setTypeOp(serializeTypeOp(expression)) - is IrVararg -> operationProto.setVararg(serializeVararg(expression)) - is IrWhen -> operationProto.setWhen(serializeWhen(expression)) - is IrWhileLoop -> operationProto.setWhile(serializeWhile(expression)) + -> operationProto.typeOp = serializeTypeOp(expression) + is IrVararg -> operationProto.vararg = serializeVararg(expression) + is IrWhen -> operationProto.`when` = serializeWhen(expression) + is IrWhileLoop -> operationProto.`while` = serializeWhile(expression) else -> { TODO("Expression serialization not implemented yet: ${ir2string(expression)}.") } @@ -516,7 +514,7 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeStatement(statement: IrElement): KonanIr.IrStatement { + private fun serializeStatement(statement: IrElement): KonanIr.IrStatement { context.log{"### serializing Statement: ${ir2string(statement)}"} val coordinates = serializeCoordinates(statement.startOffset, statement.endOffset) @@ -524,11 +522,11 @@ internal class IrSerializer(val context: Context, .setCoordinates(coordinates) when (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)) + 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) else -> { TODO("Statement not implemented yet: ${ir2string(statement)}") } @@ -536,10 +534,10 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeIrFunction(function: IrFunction): KonanIr.IrFunction { + private fun serializeIrFunction(function: IrFunction): KonanIr.IrFunction { val proto = KonanIr.IrFunction.newBuilder() val body = function.body - if (body != null) proto.setBody(serializeStatement(body)) + if (body != null) proto.body = serializeStatement(body) function.descriptor.valueParameters.forEachIndexed { index, it -> val default = function.getDefault(it) @@ -553,42 +551,41 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeIrProperty(property: IrProperty): KonanIr.IrProperty { + private 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.setBackingField(serializeIrField(backingField)) - if (getter != null) - proto.setGetter(serializeIrFunction(getter)) - if (setter != null) - proto.setSetter(serializeIrFunction(setter)) + if (backingField != null) + proto.backingField = serializeIrField(backingField) + if (getter != null) + proto.getter = serializeIrFunction(getter) + if (setter != null) + proto.setter = serializeIrFunction(setter) return proto.build() } - fun serializeIrField(field: IrField): KonanIr.IrProperty.IrField { + private fun serializeIrField(field: IrField): KonanIr.IrProperty.IrField { val proto = KonanIr.IrProperty.IrField.newBuilder() val initializer = field.initializer?.expression if (initializer != null) { - proto.setInitializer( - serializeExpression(initializer)) + proto.initializer = serializeExpression(initializer) } return proto.build() } - fun serializeIrVariable(variable: IrVariable): KonanIr.IrVar { + private fun serializeIrVariable(variable: IrVariable): KonanIr.IrVar { val proto = KonanIr.IrVar.newBuilder() val initializer = variable.initializer if (initializer != null) { - proto.setInitializer(serializeExpression(initializer)) + proto.initializer = serializeExpression(initializer) } return proto.build() } - fun serializeIrClass(@Suppress("UNUSED_PARAMETER") clazz: IrClass): KonanIr.IrClass { + private 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. @@ -607,24 +604,24 @@ internal class IrSerializer(val context: Context, return proto.build() } - fun serializeIrEnumEntry(enumEntry: IrEnumEntry): KonanIr.IrEnumEntry { + private fun serializeIrEnumEntry(enumEntry: IrEnumEntry): KonanIr.IrEnumEntry { val proto = KonanIr.IrEnumEntry.newBuilder() val initializer = enumEntry.initializerExpression!! - proto.setInitializer(serializeExpression(initializer)) + proto.initializer = serializeExpression(initializer) val correspondingClass = enumEntry.correspondingClass if (correspondingClass != null) { - proto.setCorrespondingClass(serializeDeclaration(correspondingClass)) + proto.correspondingClass = serializeDeclaration(correspondingClass) } return proto.build() } - fun serializeDeclaration(declaration: IrDeclaration): KonanIr.IrDeclaration { + private 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) } @@ -637,22 +634,22 @@ internal class IrSerializer(val context: Context, when (declaration) { is IrFunction - -> declarator.setFunction(serializeIrFunction(declaration)) + -> declarator.function = serializeIrFunction(declaration) is IrVariable - -> declarator.setVariable(serializeIrVariable(declaration)) + -> declarator.variable = serializeIrVariable(declaration) is IrClass - -> declarator.setIrClass(serializeIrClass(declaration)) + -> declarator.irClass = serializeIrClass(declaration) is IrEnumEntry - -> declarator.setIrEnumEntry(serializeIrEnumEntry(declaration)) + -> declarator.irEnumEntry = serializeIrEnumEntry(declaration) is IrProperty - -> declarator.setIrProperty(serializeIrProperty(declaration)) + -> declarator.irProperty = serializeIrProperty(declaration) else -> { TODO("Declaration serialization not supported yet: $declaration") } } - if (!(declaration is IrVariable)) { + if (declaration !is IrVariable) { localDeclarationSerializer.popContext() } @@ -676,16 +673,15 @@ internal class IrSerializer(val context: Context, proto.setDeclarator(declarator) val fileName = context.ir.originalModuleIndex.declarationToFile[declaration.descriptor] - proto.setFileName(fileName) + proto.fileName = fileName return proto.build() } - fun encodeDeclaration(declaration: IrDeclaration): String { + private fun encodeDeclaration(declaration: IrDeclaration): String { val proto = serializeDeclaration(declaration) val byteArray = proto.toByteArray() - val base64 = base64Encode(byteArray) - return base64 + return base64Encode(byteArray) } @@ -693,43 +689,42 @@ internal class IrSerializer(val context: Context, // --------- Deserializer part ----------------------------- -internal class IrDeserializer(val context: Context, - val rootFunction: FunctionDescriptor) { +internal class IrDeserializer(val context: Context, + private val rootFunction: FunctionDescriptor) { - val loopIndex = mutableMapOf() + private val loopIndex = mutableMapOf() - val rootMember = rootFunction.deserializedPropertyIfAccessor - val localDeserializer = LocalDeclarationDeserializer(rootMember) + private val rootMember = rootFunction.deserializedPropertyIfAccessor + private val localDeserializer = LocalDeclarationDeserializer(rootMember) - val descriptorDeserializer = IrDescriptorDeserializer( + private val descriptorDeserializer = IrDescriptorDeserializer( context, rootMember, localDeserializer) - fun deserializeKotlinType(proto: KonanIr.KotlinType) + private fun deserializeKotlinType(proto: KonanIr.KotlinType) = descriptorDeserializer.deserializeKotlinType(proto) - fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor) + private fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor) = descriptorDeserializer.deserializeDescriptor(proto) - fun deserializeTypeMap(descriptor: CallableDescriptor, proto: KonanIr.TypeMap): + private fun deserializeTypeMap(descriptor: CallableDescriptor, proto: KonanIr.TypeMap): Map { val typeMap = mutableMapOf() - val pairProtos = proto.getPairList() + val pairProtos = proto.pairList pairProtos.forEachIndexed { index, pair -> val typeParameter = descriptor.original.typeParameters[index] - typeMap.put(typeParameter, - deserializeKotlinType(pair.getType())) + typeMap[typeParameter] = deserializeKotlinType(pair.type) } context.log{"### deserialized typeMap = $typeMap"} return typeMap } - fun deserializeBlockBody(proto: KonanIr.IrBlockBody, - start: Int, end: Int): IrBlockBody { + private fun deserializeBlockBody(proto: KonanIr.IrBlockBody, + start: Int, end: Int): IrBlockBody { val statements = mutableListOf() - val statementProtos = proto.getStatementList() + val statementProtos = proto.statementList statementProtos.forEach { statements.add(deserializeStatement(it) as IrStatement) } @@ -737,35 +732,35 @@ internal class IrDeserializer(val context: Context, return IrBlockBodyImpl(start, end, statements) } - fun deserializeBranch(proto: KonanIr.IrBranch, start: Int, end: Int): IrBranch { + private fun deserializeBranch(proto: KonanIr.IrBranch, start: Int, end: Int): IrBranch { - val condition = deserializeExpression(proto.getCondition()) - val result = deserializeExpression(proto.getResult()) + val condition = deserializeExpression(proto.condition) + val result = deserializeExpression(proto.result) return IrBranchImpl(start, end, condition, result) } - fun deserializeCatch(proto: KonanIr.IrCatch, start: Int, end: Int): IrCatch { + private fun deserializeCatch(proto: KonanIr.IrCatch, start: Int, end: Int): IrCatch { val catchParameter = deserializeDeclaration(proto.catchParameter) as IrVariable - val result = deserializeExpression(proto.getResult()) + val result = deserializeExpression(proto.result) return IrCatchImpl(start, end, catchParameter, result) } - fun deserializeStatement(proto: KonanIr.IrStatement): IrElement { - val start = proto.getCoordinates().getStartOffset() - val end = proto.getCoordinates().getEndOffset() + private fun deserializeStatement(proto: KonanIr.IrStatement): IrElement { + val start = proto.coordinates.startOffset + val end = proto.coordinates.endOffset val element = when { proto.hasBlockBody() - -> deserializeBlockBody(proto.getBlockBody(), start, end) + -> deserializeBlockBody(proto.blockBody, start, end) proto.hasBranch() - -> deserializeBranch(proto.getBranch(), start, end) + -> deserializeBranch(proto.branch, start, end) proto.hasCatch() - -> deserializeCatch(proto.getCatch(), start, end) + -> deserializeCatch(proto.catch, start, end) proto.hasDeclaration() - -> deserializeDeclaration(proto.getDeclaration()) + -> deserializeDeclaration(proto.declaration) proto.hasExpression() - -> deserializeExpression(proto.getExpression()) + -> deserializeExpression(proto.expression) else -> { TODO("Statement deserialization not implemented") } @@ -776,21 +771,19 @@ internal class IrDeserializer(val context: Context, return element } - fun deserializeBlock(proto: KonanIr.IrBlock, start: Int, end: Int, type: KotlinType): IrBlock { + private fun deserializeBlock(proto: KonanIr.IrBlock, start: Int, end: Int, type: KotlinType): IrBlock { val statements = mutableListOf() - val statementProtos = proto.getStatementList() + val statementProtos = proto.statementList statementProtos.forEach { statements.add(deserializeStatement(it) as IrStatement) } val isLambdaOrigin = if (proto.isLambdaOrigin) IrStatementOrigin.LAMBDA else null - val block = IrBlockImpl(start, end, type, isLambdaOrigin, statements) - - return block + return IrBlockImpl(start, end, type, isLambdaOrigin, statements) } - fun deserializeMemberAccessCommon(access: IrMemberAccessExpression, proto: KonanIr.MemberAccessCommon) { + private fun deserializeMemberAccessCommon(access: IrMemberAccessExpression, proto: KonanIr.MemberAccessCommon) { proto.valueArgumentList.mapIndexed { i, expr -> access.putValueArgument(i, deserializeExpression(expr)) @@ -804,48 +797,49 @@ internal class IrDeserializer(val context: Context, } } - fun deserializeClassReference(proto: KonanIr.IrClassReference, start: Int, end: Int, type: KotlinType): IrClassReference { + private 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) } - fun deserializeCall(proto: KonanIr.IrCall, start: Int, end: Int, type: KotlinType): IrCall { - val descriptor = deserializeDescriptor(proto.getDescriptor()) as FunctionDescriptor + private fun deserializeCall(proto: KonanIr.IrCall, start: Int, end: Int, type: KotlinType): IrCall { + val descriptor = deserializeDescriptor(proto.descriptor) as FunctionDescriptor val superDescriptor = if (proto.hasSuper()) { - deserializeDescriptor(proto.getSuper()) as ClassDescriptor + deserializeDescriptor(proto.`super`) 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, descriptor, typeArgs , null, superDescriptor) + IrCallImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, typeArgs , null, createClassSymbolOrNull(superDescriptor)) KonanIr.IrCall.Primitive.NULLARY -> IrNullaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor)) KonanIr.IrCall.Primitive.UNARY -> - IrUnaryPrimitiveImpl(start, end, null, descriptor) + IrUnaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor)) KonanIr.IrCall.Primitive.BINARY -> - IrBinaryPrimitiveImpl(start, end, null, descriptor) + IrBinaryPrimitiveImpl(start, end, null, createFunctionSymbol(descriptor)) else -> TODO("Unexpected primitive IrCall.") } deserializeMemberAccessCommon(call, proto.memberAccess) return call } - fun deserializeCallableReference(proto: KonanIr.IrCallableReference, - start: Int, end: Int, type: KotlinType): IrCallableReference { + private fun deserializeCallableReference(proto: KonanIr.IrCallableReference, + start: Int, end: Int, type: KotlinType): IrCallableReference { - val descriptor = deserializeDescriptor(proto.getDescriptor()) as CallableDescriptor + val descriptor = deserializeDescriptor(proto.descriptor) as CallableDescriptor val typeMap = deserializeTypeMap(descriptor, proto.typeMap) - val callable = when (descriptor) { - is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, descriptor, typeMap, null) + return when (descriptor) { + is FunctionDescriptor -> IrFunctionReferenceImpl(start, end, type, createFunctionSymbol(descriptor), descriptor, typeMap, null) else -> TODO() } - return callable } - fun deserializeComposite(proto: KonanIr.IrComposite, start: Int, end: Int, type: KotlinType): IrComposite { + private fun deserializeComposite(proto: KonanIr.IrComposite, start: Int, end: Int, type: KotlinType): IrComposite { val statements = mutableListOf() val statementProtos = proto.getStatementList() statementProtos.forEach { @@ -854,95 +848,95 @@ internal class IrDeserializer(val context: Context, return IrCompositeImpl(start, end, type, null, statements) } - fun deserializeDelegatingConstructorCall(proto: KonanIr.IrDelegatingConstructorCall, start: Int, end: Int): IrDelegatingConstructorCall { + private fun deserializeDelegatingConstructorCall(proto: KonanIr.IrDelegatingConstructorCall, start: Int, end: Int): IrDelegatingConstructorCall { val descriptor = deserializeDescriptor(proto.getDescriptor()) as ClassConstructorDescriptor - val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.getTypeMap()) + val typeArgs = deserializeTypeMap(descriptor, proto.memberAccess.typeMap) - val call = IrDelegatingConstructorCallImpl(start, end, descriptor, typeArgs) + val call = IrDelegatingConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor), descriptor, typeArgs) deserializeMemberAccessCommon(call, proto.memberAccess) return call } fun deserializeEnumConstructorCall(proto: KonanIr.IrEnumConstructorCall, start: Int, end: Int): IrEnumConstructorCall { - val descriptor = deserializeDescriptor(proto.getDescriptor()) as ClassConstructorDescriptor - val call = IrEnumConstructorCallImpl(start, end, descriptor) + val descriptor = deserializeDescriptor(proto.descriptor) as ClassConstructorDescriptor + val call = IrEnumConstructorCallImpl(start, end, IrConstructorSymbolImpl(descriptor)) deserializeMemberAccessCommon(call, proto.memberAccess) return call } - fun deserializeGetClass(proto: KonanIr.IrGetClass, start: Int, end: Int, type: KotlinType): IrGetClass { + private fun deserializeGetClass(proto: KonanIr.IrGetClass, start: Int, end: Int, type: KotlinType): IrGetClass { val argument = deserializeExpression(proto.argument) return IrGetClassImpl(start, end, type, argument) } - fun deserializeGetField(proto: KonanIr.IrGetField, start: Int, end: Int): IrGetField { + private fun deserializeGetField(proto: KonanIr.IrGetField, start: Int, end: Int): IrGetField { val access = proto.fieldAccess - val descriptor = deserializeDescriptor(access.getDescriptor()) as PropertyDescriptor + val descriptor = deserializeDescriptor(access.descriptor) as PropertyDescriptor val superQualifier = if (access.hasSuper()) { - deserializeDescriptor(access.getDescriptor()) as ClassDescriptor + deserializeDescriptor(access.descriptor) as ClassDescriptor } else null val receiver = if (access.hasReceiver()) { deserializeExpression(access.receiver) } else null - return IrGetFieldImpl(start, end, descriptor, receiver, null, superQualifier) + return IrGetFieldImpl(start, end, IrFieldSymbolImpl(descriptor), receiver, null, createClassSymbolOrNull(superQualifier)) } - fun deserializeGetValue(proto: KonanIr.IrGetValue, start: Int, end: Int): IrGetValue { + private fun deserializeGetValue(proto: KonanIr.IrGetValue, start: Int, end: Int): IrGetValue { val descriptor = deserializeDescriptor(proto.descriptor) as ValueDescriptor // TODO: origin! - return IrGetValueImpl(start, end, descriptor, null) + return IrGetValueImpl(start, end, createValueSymbol(descriptor), null) } - fun deserializeGetEnumValue(proto: KonanIr.IrGetEnumValue, start: Int, end: Int): IrGetEnumValue { + private 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, descriptor) + return IrGetEnumValueImpl(start, end, type, IrEnumEntrySymbolImpl(descriptor)) } - fun deserializeGetObject(proto: KonanIr.IrGetObject, start: Int, end: Int, type: KotlinType): IrGetObjectValue { + private fun deserializeGetObject(proto: KonanIr.IrGetObject, start: Int, end: Int, type: KotlinType): IrGetObjectValue { val descriptor = deserializeDescriptor(proto.descriptor) as ClassDescriptor - return IrGetObjectValueImpl(start, end, type, descriptor) + return IrGetObjectValueImpl(start, end, type, IrClassSymbolImpl(descriptor)) } - fun deserializeInstanceInitializerCall(proto: KonanIr.IrInstanceInitializerCall, start: Int, end: Int): IrInstanceInitializerCall { - val descriptor = deserializeDescriptor(proto.getDescriptor()) as ClassDescriptor + private fun deserializeInstanceInitializerCall(proto: KonanIr.IrInstanceInitializerCall, start: Int, end: Int): IrInstanceInitializerCall { + val descriptor = deserializeDescriptor(proto.descriptor) as ClassDescriptor - return IrInstanceInitializerCallImpl(start, end, descriptor) + return IrInstanceInitializerCallImpl(start, end, IrClassSymbolImpl(descriptor)) } - fun deserializeReturn(proto: KonanIr.IrReturn, start: Int, end: Int, type: KotlinType): IrReturn { + private fun deserializeReturn(proto: KonanIr.IrReturn, start: Int, end: Int, type: KotlinType): IrReturn { val descriptor = - deserializeDescriptor(proto.getReturnTarget()) as FunctionDescriptor - val value = deserializeExpression(proto.getValue()) - return IrReturnImpl(start, end, type, descriptor, value) + deserializeDescriptor(proto.returnTarget) as FunctionDescriptor + val value = deserializeExpression(proto.value) + return IrReturnImpl(start, end, type, createFunctionSymbol(descriptor), value) } - fun deserializeSetField(proto: KonanIr.IrSetField, start: Int, end: Int): IrSetField { + private fun deserializeSetField(proto: KonanIr.IrSetField, start: Int, end: Int): IrSetField { val access = proto.fieldAccess - val descriptor = deserializeDescriptor(access.getDescriptor()) as PropertyDescriptor + val descriptor = deserializeDescriptor(access.descriptor) as PropertyDescriptor val superQualifier = if (access.hasSuper()) { - deserializeDescriptor(access.getDescriptor()) as ClassDescriptor + deserializeDescriptor(access.descriptor) as ClassDescriptor } else null val receiver = if (access.hasReceiver()) { deserializeExpression(access.receiver) } else null val value = deserializeExpression(proto.value) - return IrSetFieldImpl(start, end, descriptor, receiver, value, null, superQualifier) + return IrSetFieldImpl(start, end, IrFieldSymbolImpl(descriptor), receiver, value, null, createClassSymbolOrNull(superQualifier)) } - 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 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 deserializeStringConcat(proto: KonanIr.IrStringConcat, start: Int, end: Int, type: KotlinType): IrStringConcatenation { - val argumentProtos = proto.getArgumentList() + private fun deserializeStringConcat(proto: KonanIr.IrStringConcat, start: Int, end: Int, type: KotlinType): IrStringConcatenation { + val argumentProtos = proto.argumentList val arguments = mutableListOf() argumentProtos.forEach { @@ -951,14 +945,14 @@ internal class IrDeserializer(val context: Context, return IrStringConcatenationImpl(start, end, type, arguments) } - fun deserializeThrow(proto: KonanIr.IrThrow, start: Int, end: Int, type: KotlinType): IrThrowImpl { - return IrThrowImpl(start, end, type, deserializeExpression(proto.getValue())) + private fun deserializeThrow(proto: KonanIr.IrThrow, start: Int, end: Int, type: KotlinType): IrThrowImpl { + return IrThrowImpl(start, end, type, deserializeExpression(proto.value)) } - fun deserializeTry(proto: KonanIr.IrTry, start: Int, end: Int, type: KotlinType): IrTryImpl { - val result = deserializeExpression(proto.getResult()) + private fun deserializeTry(proto: KonanIr.IrTry, start: Int, end: Int, type: KotlinType): IrTryImpl { + val result = deserializeExpression(proto.result) val catches = mutableListOf() - proto.getCatchList().forEach { + proto.catchList.forEach { catches.add(deserializeStatement(it) as IrCatch) } val finallyExpression = @@ -966,7 +960,7 @@ internal class IrDeserializer(val context: Context, return IrTryImpl(start, end, type, result, catches, finallyExpression) } - fun deserializeTypeOperator(operator: KonanIr.IrTypeOperator): IrTypeOperator { + private fun deserializeTypeOperator(operator: KonanIr.IrTypeOperator): IrTypeOperator { when (operator) { KonanIr.IrTypeOperator.CAST -> return IrTypeOperator.CAST @@ -986,22 +980,22 @@ internal class IrDeserializer(val context: Context, } } - 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()) + 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) return IrTypeOperatorCallImpl(start, end, type, operator, operand, argument) } - fun deserializeVararg(proto: KonanIr.IrVararg, start: Int, end: Int, type: KotlinType): IrVararg { - val elementType = deserializeKotlinType(proto.getElementType()) + private fun deserializeVararg(proto: KonanIr.IrVararg, start: Int, end: Int, type: KotlinType): IrVararg { + val elementType = deserializeKotlinType(proto.elementType) return IrVarargImpl(start, end, type, elementType) } - fun deserializeWhen(proto: KonanIr.IrWhen, start: Int, end: Int, type: KotlinType): IrWhen { + private fun deserializeWhen(proto: KonanIr.IrWhen, start: Int, end: Int, type: KotlinType): IrWhen { val branches = mutableListOf() - proto.getBranchList().forEach { + proto.branchList.forEach { branches.add(deserializeStatement(it) as IrBranch) } @@ -1009,13 +1003,13 @@ internal class IrDeserializer(val context: Context, return IrWhenImpl(start, end, type, null, branches) } - fun deserializeLoop(proto: KonanIr.Loop, loop: IrLoopBase): IrLoopBase { - val loopId = proto.getLoopId() + private fun deserializeLoop(proto: KonanIr.Loop, loop: IrLoopBase): IrLoopBase { + val loopId = proto.loopId loopIndex.getOrPut(loopId){loop} - val label = if (proto.hasLabel()) proto.getLabel() else null - val body = if (proto.hasBody()) deserializeExpression(proto.getBody()) else null - val condition = deserializeExpression(proto.getCondition()) + val label = if (proto.hasLabel()) proto.label else null + val body = if (proto.hasBody()) deserializeExpression(proto.body) else null + val condition = deserializeExpression(proto.condition) loop.label = label loop.condition = condition @@ -1024,7 +1018,7 @@ internal class IrDeserializer(val context: Context, return loop } - fun deserializeDoWhile(proto: KonanIr.IrDoWhile, start: Int, end: Int, type: KotlinType): IrDoWhileLoop { + private 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) @@ -1032,7 +1026,7 @@ internal class IrDeserializer(val context: Context, return loop } - fun deserializeWhile(proto: KonanIr.IrWhile, start: Int, end: Int, type: KotlinType): IrWhileLoop { + private 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) @@ -1040,9 +1034,9 @@ internal class IrDeserializer(val context: Context, return loop } - 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() + 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 val loop = loopIndex[loopId]!! val irBreak = IrBreakImpl(start, end, type, loop) irBreak.label = label @@ -1050,9 +1044,9 @@ internal class IrDeserializer(val context: Context, return irBreak } - 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() + 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 val loop = loopIndex[loopId]!! val irContinue = IrContinueImpl(start, end, type, loop) irContinue.label = label @@ -1060,7 +1054,7 @@ internal class IrDeserializer(val context: Context, return irContinue } - fun deserializeConst(proto: KonanIr.IrConst, start: Int, end: Int, type: KotlinType): IrExpression = + private fun deserializeConst(proto: KonanIr.IrConst, start: Int, end: Int, type: KotlinType): IrExpression = when(proto.valueCase) { NULL -> IrConstImpl.constNull(start, end, type) @@ -1085,12 +1079,12 @@ internal class IrDeserializer(val context: Context, } } - fun deserializeOperation(proto: KonanIr.IrOperation, start: Int, end: Int, type: KotlinType): IrExpression = + private 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.getBreak(), start, end, type) + -> deserializeBreak(proto.`break`, start, end, type) CLASS_REFERENCE -> deserializeClassReference(proto.classReference, start, end, type) CALL @@ -1102,7 +1096,7 @@ internal class IrDeserializer(val context: Context, CONST -> deserializeConst(proto.const, start, end, type) CONTINUE - -> deserializeContinue(proto.getContinue(), start, end, type) + -> deserializeContinue(proto.`continue`, start, end, type) DELEGATING_CONSTRUCTOR_CALL -> deserializeDelegatingConstructorCall(proto.delegatingConstructorCall, start, end) DO_WHILE @@ -1120,7 +1114,7 @@ internal class IrDeserializer(val context: Context, INSTANCE_INITIALIZER_CALL -> deserializeInstanceInitializerCall(proto.instanceInitializerCall, start, end) RETURN - -> deserializeReturn(proto.getReturn(), start, end, type) + -> deserializeReturn(proto.`return`, start, end, type) SET_FIELD -> deserializeSetField(proto.setField, start, end) SET_VARIABLE @@ -1128,37 +1122,37 @@ internal class IrDeserializer(val context: Context, STRING_CONCAT -> deserializeStringConcat(proto.stringConcat, start, end, type) THROW - -> deserializeThrow(proto.getThrow(), start, end, type) + -> deserializeThrow(proto.`throw`, start, end, type) TRY - -> deserializeTry(proto.getTry(), start, end, type) + -> deserializeTry(proto.`try`, start, end, type) TYPE_OP -> deserializeTypeOp(proto.typeOp, start, end, type) VARARG -> deserializeVararg(proto.vararg, start, end, type) WHEN - -> deserializeWhen(proto.getWhen(), start, end, type) + -> deserializeWhen(proto.`when`, start, end, type) WHILE - -> deserializeWhile(proto.getWhile(), start, end, type) + -> deserializeWhile(proto.`while`, start, end, type) else -> { TODO("Expression deserialization not implemented: ${proto.operationCase}") } } - 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() + 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 val expression = deserializeOperation(operation, start, end, type) context.log{"### Deserialized expression: ${ir2string(expression)}"} return expression } - fun deserializeIrClass(proto: KonanIr.IrClass, descriptor: ClassDescriptor, start: Int, end: Int, origin: IrDeclarationOrigin): IrClass { + private fun deserializeIrClass(proto: KonanIr.IrClass, descriptor: ClassDescriptor, start: Int, end: Int, origin: IrDeclarationOrigin): IrClass { val members = mutableListOf() - proto.getMemberList().forEach { + proto.memberList.forEach { members.add(deserializeDeclaration(it)) } @@ -1171,10 +1165,10 @@ internal class IrDeserializer(val context: Context, } - fun deserializeIrFunction(proto: KonanIr.IrFunction, descriptor: FunctionDescriptor, - start: Int, end: Int, origin: IrDeclarationOrigin): IrFunction { + private fun deserializeIrFunction(proto: KonanIr.IrFunction, descriptor: FunctionDescriptor, + start: Int, end: Int, origin: IrDeclarationOrigin): IrFunction { - val body = deserializeStatement(proto.getBody()) + val body = deserializeStatement(proto.body) val function = IrFunctionImpl(start, end, origin, descriptor, body as IrBody) @@ -1184,26 +1178,24 @@ internal class IrDeserializer(val context: Context, val expr = deserializeExpression(it.value) function.putDefault( - descriptor.valueParameters.get(it.position), - IrExpressionBodyImpl(start, end, expr)) + descriptor.valueParameters[it.position], + IrExpressionBodyImpl(start, end, expr)) } return function } - fun deserializeIrVariable(proto: KonanIr.IrVar, descriptor: VariableDescriptor, - start: Int, end: Int, origin: IrDeclarationOrigin): IrVariable { + private fun deserializeIrVariable(proto: KonanIr.IrVar, descriptor: VariableDescriptor, + start: Int, end: Int, origin: IrDeclarationOrigin): IrVariable { val initializer = if (proto.hasInitializer()) { - deserializeExpression(proto.getInitializer()) + deserializeExpression(proto.initializer) } else null - val variable = IrVariableImpl(start, end, origin, descriptor, initializer) - - return variable + return IrVariableImpl(start, end, origin, descriptor, initializer) } - fun deserializeIrEnumEntry(proto: KonanIr.IrEnumEntry, descriptor: ClassDescriptor, - start: Int, end: Int, origin: IrDeclarationOrigin): IrEnumEntry { + private fun deserializeIrEnumEntry(proto: KonanIr.IrEnumEntry, descriptor: ClassDescriptor, + start: Int, end: Int, origin: IrDeclarationOrigin): IrEnumEntry { val enumEntry = IrEnumEntryImpl(start, end, origin, descriptor) if (proto.hasCorrespondingClass()) { @@ -1214,17 +1206,17 @@ internal class IrDeserializer(val context: Context, return enumEntry } - fun deserializeDeclaration(proto: KonanIr.IrDeclaration): IrDeclaration { + private 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.getCoordinates().getStartOffset() - val end = proto.getCoordinates().getEndOffset() + val start = proto.coordinates.startOffset + val end = proto.coordinates.endOffset val origin = DEFINED // TODO: retore the real origins - val declarator = proto.getDeclarator() + val declarator = proto.declarator 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 b40552a420b..033c348c363 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,6 +55,7 @@ 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 c533d6f90bc..53bbfa77592 100644 --- a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/KLibInstall.kt +++ b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/KLibInstall.kt @@ -28,7 +28,8 @@ open class KlibInstall: Exec() { override fun configure(config: Closure<*>): Task { val result = super.configure(config) - val konanHome = project.rootProject.file(project.findProperty("konan.home") ?: "dist") + val konanHomePath = project.findProperty("konan.home") ?: "dist" // Makes kotlin analyzer happy. + val konanHome = project.rootProject.file(konanHomePath) val suffix = if (TargetManager.host == KonanTarget.MINGW) ".bat" else "" val klibProgram = "$konanHome/bin/klib$suffix"