[JS IR BE] Move IrSerializer from native to JS
* Fix issues
This commit is contained in:
+1
@@ -64,6 +64,7 @@ abstract class IrLazyDeclarationBase(
|
||||
}
|
||||
is ClassDescriptor -> stubGenerator.generateClassStub(containingDeclaration)
|
||||
is FunctionDescriptor -> stubGenerator.generateFunctionStub(containingDeclaration)
|
||||
is PropertyDescriptor -> stubGenerator.generateFunctionStub(containingDeclaration.run { getter ?: setter!! })
|
||||
else -> throw AssertionError("Package or class expected: $containingDeclaration; for $currentDescriptor")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,12 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrExternalPackageFragmentSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.withHasQuestionMark
|
||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
@@ -72,68 +78,97 @@ class IrBuiltIns(
|
||||
private fun List<SimpleType>.defineComparisonOperatorForEachType(name: String) =
|
||||
associate { it to defineComparisonOperator(name, it) }
|
||||
|
||||
private class IrTypeMapper(val type: () -> IrType, val nType: () -> IrType)
|
||||
|
||||
private fun buildNullableType(irType: IrType) = with(irType as IrSimpleType) {
|
||||
IrSimpleTypeImpl(classifier, true, arguments, annotations)
|
||||
}
|
||||
|
||||
private val primitiveTypesLazyMapping = mapOf<ClassifierDescriptor, IrTypeMapper>(
|
||||
builtIns.any to IrTypeMapper({ anyType }, { anyNType }),
|
||||
builtIns.boolean to IrTypeMapper({ booleanType }, { buildNullableType(booleanType) }),
|
||||
builtIns.char to IrTypeMapper({ charType }, { buildNullableType(charType) }),
|
||||
builtIns.number to IrTypeMapper({ numberType }, { buildNullableType(numberType) }),
|
||||
builtIns.byte to IrTypeMapper({ byteType }, { buildNullableType(byteType) }),
|
||||
builtIns.short to IrTypeMapper({ shortType }, { buildNullableType(shortType) }),
|
||||
builtIns.int to IrTypeMapper({ intType }, { buildNullableType(intType) }),
|
||||
builtIns.long to IrTypeMapper({ longType }, { buildNullableType(longType) }),
|
||||
builtIns.float to IrTypeMapper({ floatType }, { buildNullableType(floatType) }),
|
||||
builtIns.double to IrTypeMapper({ doubleType }, { buildNullableType(doubleType) }),
|
||||
builtIns.nothing to IrTypeMapper({ nothingType }, { nothingNType }),
|
||||
builtIns.unit to IrTypeMapper({ unitType }, { buildNullableType(unitType) }),
|
||||
builtIns.string to IrTypeMapper({ stringType }, { buildNullableType(stringType) }),
|
||||
builtIns.throwable to IrTypeMapper({ throwableType }, { buildNullableType(throwableType) })
|
||||
// builtIns.array to { arrayClass.owner.defaultType }
|
||||
)
|
||||
|
||||
fun getPrimitiveTypeOrNullByDescriptor(descriptor: ClassifierDescriptor, isNullable: Boolean) =
|
||||
primitiveTypesLazyMapping[descriptor]?.let {
|
||||
if (isNullable) it.nType() else it.type()
|
||||
} as IrSimpleType?
|
||||
|
||||
val any = builtIns.anyType
|
||||
val anyN = builtIns.nullableAnyType
|
||||
val anyType = any.toIrType()
|
||||
val anyClass = builtIns.any.toIrSymbol()
|
||||
val anyNType = anyType.withHasQuestionMark(true)
|
||||
val anyType by lazy { any.toIrType() }
|
||||
val anyClass by lazy { builtIns.any.toIrSymbol() }
|
||||
val anyNType by lazy { anyType.withHasQuestionMark(true) }
|
||||
|
||||
val bool = builtIns.booleanType
|
||||
val booleanType = bool.toIrType()
|
||||
val booleanClass = builtIns.boolean.toIrSymbol()
|
||||
val booleanType by lazy { bool.toIrType() }
|
||||
val booleanClass by lazy { builtIns.boolean.toIrSymbol() }
|
||||
|
||||
val char = builtIns.charType
|
||||
val charType = char.toIrType()
|
||||
val charClass = builtIns.char.toIrSymbol()
|
||||
val charType by lazy { char.toIrType() }
|
||||
val charClass by lazy { builtIns.char.toIrSymbol() }
|
||||
|
||||
val number = builtIns.number.defaultType
|
||||
val numberType = number.toIrType()
|
||||
val numberClass = builtIns.number.toIrSymbol()
|
||||
val numberType by lazy { number.toIrType() }
|
||||
val numberClass by lazy { builtIns.number.toIrSymbol() }
|
||||
|
||||
val byte = builtIns.byteType
|
||||
val byteType = byte.toIrType()
|
||||
val byteClass = builtIns.byte.toIrSymbol()
|
||||
val byteType by lazy { byte.toIrType() }
|
||||
val byteClass by lazy { builtIns.byte.toIrSymbol() }
|
||||
|
||||
val short = builtIns.shortType
|
||||
val shortType = short.toIrType()
|
||||
val shortClass = builtIns.short.toIrSymbol()
|
||||
val shortType by lazy { short.toIrType() }
|
||||
val shortClass by lazy { builtIns.short.toIrSymbol() }
|
||||
|
||||
val int = builtIns.intType
|
||||
val intType = int.toIrType()
|
||||
val intClass = builtIns.int.toIrSymbol()
|
||||
val intType by lazy { int.toIrType() }
|
||||
val intClass by lazy { builtIns.int.toIrSymbol() }
|
||||
|
||||
val long = builtIns.longType
|
||||
val longType = long.toIrType()
|
||||
val longClass = builtIns.long.toIrSymbol()
|
||||
val longType by lazy { long.toIrType() }
|
||||
val longClass by lazy { builtIns.long.toIrSymbol() }
|
||||
|
||||
val float = builtIns.floatType
|
||||
val floatType = float.toIrType()
|
||||
val floatClass = builtIns.float.toIrSymbol()
|
||||
val floatType by lazy { float.toIrType() }
|
||||
val floatClass by lazy { builtIns.float.toIrSymbol() }
|
||||
|
||||
val double = builtIns.doubleType
|
||||
val doubleType = double.toIrType()
|
||||
val doubleClass = builtIns.double.toIrSymbol()
|
||||
val doubleType by lazy { double.toIrType() }
|
||||
val doubleClass by lazy { builtIns.double.toIrSymbol() }
|
||||
|
||||
val nothing = builtIns.nothingType
|
||||
val nothingN = builtIns.nullableNothingType
|
||||
val nothingType = nothing.toIrType()
|
||||
val nothingClass = builtIns.nothing.toIrSymbol()
|
||||
val nothingNType = nothingType.withHasQuestionMark(true)
|
||||
val nothingType by lazy { nothing.toIrType() }
|
||||
val nothingClass by lazy { builtIns.nothing.toIrSymbol() }
|
||||
val nothingNType by lazy { nothingType.withHasQuestionMark(true) }
|
||||
|
||||
val unit = builtIns.unitType
|
||||
val unitType = unit.toIrType()
|
||||
val unitClass = builtIns.unit.toIrSymbol()
|
||||
val unitType by lazy { unit.toIrType() }
|
||||
val unitClass by lazy { builtIns.unit.toIrSymbol() }
|
||||
|
||||
val string = builtIns.stringType
|
||||
val stringType = string.toIrType()
|
||||
val stringClass = builtIns.string.toIrSymbol()
|
||||
val stringType by lazy { string.toIrType() }
|
||||
val stringClass by lazy { builtIns.string.toIrSymbol() }
|
||||
|
||||
val collectionClass = builtIns.collection.toIrSymbol()
|
||||
val collectionClass by lazy { builtIns.collection.toIrSymbol() }
|
||||
|
||||
val arrayClass = builtIns.array.toIrSymbol()
|
||||
val arrayClass by lazy { builtIns.array.toIrSymbol() }
|
||||
|
||||
val throwableType = builtIns.throwable.defaultType.toIrType()
|
||||
val throwableClass = builtIns.throwable.toIrSymbol()
|
||||
val throwableType by lazy { builtIns.throwable.defaultType.toIrType() }
|
||||
val throwableClass by lazy { builtIns.throwable.toIrSymbol() }
|
||||
|
||||
val kCallableClass = builtIns.getBuiltInClassByFqName(KotlinBuiltIns.FQ_NAMES.kCallable.toSafe()).toIrSymbol()
|
||||
val kPropertyClass = builtIns.getBuiltInClassByFqName(KotlinBuiltIns.FQ_NAMES.kPropertyFqName.toSafe()).toIrSymbol()
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.types
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
@@ -68,6 +70,8 @@ fun IrType.makeNullable(addKotlinType:Boolean = true) =
|
||||
else
|
||||
this
|
||||
|
||||
var irTypeKotlinBuiltIns: KotlinBuiltIns? = null
|
||||
|
||||
fun IrType.toKotlinType(): KotlinType {
|
||||
originalKotlinType?.let {
|
||||
return it
|
||||
@@ -75,6 +79,7 @@ fun IrType.toKotlinType(): KotlinType {
|
||||
|
||||
return when (this) {
|
||||
is IrSimpleType -> makeKotlinType(classifier, arguments, hasQuestionMark)
|
||||
is IrDynamicType -> createDynamicType(irTypeKotlinBuiltIns!!)
|
||||
else -> TODO(toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,16 +21,21 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.hasBackingField
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
|
||||
class DeclarationStubGenerator(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
|
||||
Reference in New Issue
Block a user