JVM IR: minimize public API of IrTypeMapper
This commit is contained in:
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.jvm
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.IrTypeMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
||||
@@ -37,6 +38,8 @@ class JvmBackendContext(
|
||||
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(state)
|
||||
override val sharedVariablesManager = JvmSharedVariablesManager(state.module, builtIns, irBuiltIns)
|
||||
|
||||
val typeMapper = IrTypeMapper(this)
|
||||
|
||||
private val symbolTable = symbolTable.lazyWrapper
|
||||
override val ir = JvmIr(irModuleFragment, this.symbolTable)
|
||||
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ open class ClassCodegen protected constructor(
|
||||
|
||||
val state = context.state
|
||||
|
||||
val typeMapper = IrTypeMapper(context.state.typeMapper)
|
||||
val typeMapper = context.typeMapper
|
||||
|
||||
val descriptor = irClass.descriptor
|
||||
|
||||
@@ -202,7 +202,7 @@ open class ClassCodegen protected constructor(
|
||||
if (field.origin == IrDeclarationOrigin.FAKE_OVERRIDE) return
|
||||
|
||||
val fieldType = typeMapper.mapType(field)
|
||||
val fieldSignature = typeMapper.mapFieldSignature(field.type, field)
|
||||
val fieldSignature = typeMapper.mapFieldSignature(field)
|
||||
val fieldName = field.name.asString()
|
||||
// The ConstantValue attribute makes the initializer part of the ABI, which is why since 1.4
|
||||
// it is no longer set unless the property is explicitly `const`.
|
||||
|
||||
+13
-26
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.codegen
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter
|
||||
@@ -14,8 +15,10 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
class IrTypeMapper(val kotlinTypeMapper: KotlinTypeMapper) {
|
||||
class IrTypeMapper(private val context: JvmBackendContext) {
|
||||
val kotlinTypeMapper: KotlinTypeMapper = context.state.typeMapper
|
||||
|
||||
val classBuilderMode get() = kotlinTypeMapper.classBuilderMode
|
||||
|
||||
@@ -23,10 +26,8 @@ class IrTypeMapper(val kotlinTypeMapper: KotlinTypeMapper) {
|
||||
|
||||
fun mapAsmMethod(irFunction: IrFunction) = kotlinTypeMapper.mapAsmMethod(irFunction.descriptor)
|
||||
|
||||
fun mapClass(irClass: IrClass) = kotlinTypeMapper.mapClass(irClass.descriptor)
|
||||
|
||||
fun mapFieldSignature(irType: IrType, irFrield: IrField) =
|
||||
kotlinTypeMapper.mapFieldSignature(irType.toKotlinType(), irFrield.descriptor)
|
||||
fun mapFieldSignature(irField: IrField) =
|
||||
kotlinTypeMapper.mapFieldSignature(irField.type.toKotlinType(), irField.descriptor)
|
||||
|
||||
fun mapFunctionName(irReturnTarget: IrReturnTarget, ownerKind: OwnerKind) =
|
||||
kotlinTypeMapper.mapFunctionName(irReturnTarget.descriptor, ownerKind)
|
||||
@@ -40,33 +41,19 @@ class IrTypeMapper(val kotlinTypeMapper: KotlinTypeMapper) {
|
||||
|
||||
fun mapSignatureWithGeneric(f: IrFunction, kind: OwnerKind) = kotlinTypeMapper.mapSignatureWithGeneric(f.descriptor, kind)
|
||||
|
||||
fun mapSupertype(irType: IrType, sw: JvmSignatureWriter) = kotlinTypeMapper.mapSupertype(irType.toKotlinType(), sw)
|
||||
|
||||
fun mapToCallableMethod(f: IrFunction, superCall: Boolean, kind: OwnerKind? = null, resolvedCall: ResolvedCall<*>? = null) =
|
||||
kotlinTypeMapper.mapToCallableMethod(f.descriptor, superCall, kind, resolvedCall)
|
||||
|
||||
fun mapType(irType: IrType) = kotlinTypeMapper.mapType(irType.toKotlinType())
|
||||
|
||||
fun mapType(irClass: IrClass) = kotlinTypeMapper.mapType(irClass.descriptor)
|
||||
|
||||
fun mapType(irField: IrField) = kotlinTypeMapper.mapType(irField.descriptor)
|
||||
|
||||
fun mapType(irValueParameter: IrValueParameter) = kotlinTypeMapper.mapType(irValueParameter.descriptor)
|
||||
|
||||
fun mapType(irVariable: IrVariable) = kotlinTypeMapper.mapType(irVariable.descriptor)
|
||||
|
||||
fun mapType(irType: IrType, sw: JvmSignatureWriter, mode: TypeMappingMode) =
|
||||
kotlinTypeMapper.mapType(irType.toKotlinType(), sw, mode)
|
||||
|
||||
fun mapTypeAsDeclaration(irType: IrType) =
|
||||
kotlinTypeMapper.mapTypeAsDeclaration(irType.toKotlinType())
|
||||
|
||||
fun mapTypeParameter(irType: IrType, signatureWriter: JvmSignatureWriter) =
|
||||
kotlinTypeMapper.mapTypeParameter(irType.toKotlinType(), signatureWriter)
|
||||
|
||||
fun writeFormalTypeParameters(irParameters: List<IrTypeParameter>, sw: JvmSignatureWriter) =
|
||||
kotlinTypeMapper.writeFormalTypeParameters(irParameters.map { it.descriptor }, sw)
|
||||
|
||||
fun boxType(irType: IrType) =
|
||||
AsmUtil.boxType(mapType(irType), irType.toKotlinType(), kotlinTypeMapper)
|
||||
|
||||
fun mapType(
|
||||
type: IrType,
|
||||
mode: TypeMappingMode = TypeMappingMode.DEFAULT,
|
||||
sw: JvmSignatureWriter? = null
|
||||
): Type =
|
||||
kotlinTypeMapper.mapType(type.toKotlinType(), sw, mode)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.codegen
|
||||
|
||||
import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
fun IrTypeMapper.mapType(irVariable: IrVariable): Type =
|
||||
mapType(irVariable.type)
|
||||
|
||||
fun IrTypeMapper.mapType(irValueParameter: IrValueParameter): Type =
|
||||
mapType(irValueParameter.type)
|
||||
|
||||
fun IrTypeMapper.mapType(irField: IrField): Type =
|
||||
mapType(irField.type)
|
||||
|
||||
fun IrTypeMapper.mapSupertype(irType: IrType, sw: JvmSignatureWriter): Type =
|
||||
mapType(irType, TypeMappingMode.SUPER_TYPE, sw)
|
||||
|
||||
fun IrTypeMapper.mapClass(irClass: IrClass): Type =
|
||||
mapType(irClass.defaultType, TypeMappingMode.CLASS_DECLARATION)
|
||||
|
||||
fun IrTypeMapper.mapTypeAsDeclaration(irType: IrType): Type =
|
||||
mapType(irType, TypeMappingMode.CLASS_DECLARATION)
|
||||
|
||||
fun IrTypeMapper.mapTypeParameter(irType: IrType, sw: JvmSignatureWriter): Type =
|
||||
mapType(irType, TypeMappingMode.GENERIC_ARGUMENT, sw)
|
||||
+1
-3
@@ -40,8 +40,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import java.util.ArrayList
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
class IrFrameMap : FrameMapBase<IrSymbol>() {
|
||||
private val typeMap = mutableMapOf<IrSymbol,Type>()
|
||||
@@ -390,7 +388,7 @@ internal fun getSignature(
|
||||
if (typeMapper.classBuilderMode === ClassBuilderMode.LIGHT_CLASSES) {
|
||||
sw.writeInterface()
|
||||
val kotlinCollectionType =
|
||||
typeMapper.mapType(superClass.defaultType, sw, TypeMappingMode.SUPER_TYPE_KOTLIN_COLLECTIONS_AS_IS)
|
||||
typeMapper.mapType(superClass.defaultType, TypeMappingMode.SUPER_TYPE_KOTLIN_COLLECTIONS_AS_IS, sw)
|
||||
sw.writeInterfaceEnd()
|
||||
superInterfaces.add(kotlinCollectionType.internalName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user