[JS IR BE] Proper support for String and Any constructors
Remove workarounds from codegen
This commit is contained in:
@@ -190,6 +190,15 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
|||||||
val charClassSymbol = getInternalClassWithoutPackage("kotlin.Char")
|
val charClassSymbol = getInternalClassWithoutPackage("kotlin.Char")
|
||||||
val charConstructor = charClassSymbol.constructors.single().owner
|
val charConstructor = charClassSymbol.constructors.single().owner
|
||||||
|
|
||||||
|
val stringClassSymbol = getInternalClassWithoutPackage("kotlin.String")
|
||||||
|
val stringConstructorSymbol = stringClassSymbol.constructors.single()
|
||||||
|
|
||||||
|
val anyClassSymbol = getInternalClassWithoutPackage("kotlin.Any")
|
||||||
|
val anyConstructorSymbol = anyClassSymbol.constructors.single()
|
||||||
|
|
||||||
|
val jsObjectClassSymbol = getInternalClassWithoutPackage("kotlin.js.JsObject")
|
||||||
|
val jsObjectConstructorSymbol by lazy { jsObjectClassSymbol.constructors.single() }
|
||||||
|
|
||||||
val uByteClassSymbol by lazy { getInternalClassWithoutPackage("kotlin.UByte") }
|
val uByteClassSymbol by lazy { getInternalClassWithoutPackage("kotlin.UByte") }
|
||||||
val uShortClassSymbol by lazy { getInternalClassWithoutPackage("kotlin.UShort") }
|
val uShortClassSymbol by lazy { getInternalClassWithoutPackage("kotlin.UShort") }
|
||||||
val uIntClassSymbol by lazy { getInternalClassWithoutPackage("kotlin.UInt") }
|
val uIntClassSymbol by lazy { getInternalClassWithoutPackage("kotlin.UInt") }
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.ir.backend.js.lower.calls
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||||
|
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||||
|
import org.jetbrains.kotlin.ir.util.irCall
|
||||||
|
import org.jetbrains.kotlin.ir.util.irConstructorCall
|
||||||
|
|
||||||
|
|
||||||
|
class BuiltInConstructorCalls(val context: JsIrBackendContext) : CallsTransformer {
|
||||||
|
val intrinsics = context.intrinsics
|
||||||
|
|
||||||
|
override fun transformFunctionAccess(call: IrFunctionAccessExpression): IrExpression =
|
||||||
|
when (call.symbol) {
|
||||||
|
intrinsics.stringConstructorSymbol -> JsIrBuilder.buildString(context.irBuiltIns.stringType, "")
|
||||||
|
intrinsics.anyConstructorSymbol -> irConstructorCall(call, intrinsics.jsObjectConstructorSymbol)
|
||||||
|
else -> call
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -26,6 +26,7 @@ class CallsLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
|||||||
ReflectionCallsTransformer(context),
|
ReflectionCallsTransformer(context),
|
||||||
EnumIntrinsicsTransformer(context),
|
EnumIntrinsicsTransformer(context),
|
||||||
ExceptionHelperCallsTransformer(context),
|
ExceptionHelperCallsTransformer(context),
|
||||||
|
BuiltInConstructorCalls(context),
|
||||||
JsonIntrinsics(context)
|
JsonIntrinsics(context)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
-7
@@ -33,13 +33,6 @@ class IrModuleToJsTransformer(
|
|||||||
JsStringLiteral("use strict").makeStmt()
|
JsStringLiteral("use strict").makeStmt()
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: fix it up with new name generator
|
|
||||||
val anyName = context.getNameForClass(backendContext.irBuiltIns.anyClass.owner)
|
|
||||||
val stringName = context.getNameForClass(backendContext.irBuiltIns.stringClass.owner)
|
|
||||||
|
|
||||||
statements += JsVars(JsVars.JsVar(anyName, Namer.JS_OBJECT))
|
|
||||||
statements += JsVars(JsVars.JsVar(stringName, JsNameRef("String")))
|
|
||||||
|
|
||||||
val preDeclarationBlock = JsBlock()
|
val preDeclarationBlock = JsBlock()
|
||||||
val postDeclarationBlock = JsBlock()
|
val postDeclarationBlock = JsBlock()
|
||||||
|
|
||||||
|
|||||||
@@ -100,5 +100,8 @@ internal fun extendThrowable(this_: dynamic, message: String?, cause: Throwable?
|
|||||||
captureStack(this_)
|
captureStack(this_)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsName("Object")
|
||||||
|
internal external class JsObject
|
||||||
|
|
||||||
internal fun <T, R> boxIntrinsic(x: T): R = error("Should be lowered")
|
internal fun <T, R> boxIntrinsic(x: T): R = error("Should be lowered")
|
||||||
internal fun <T, R> unboxIntrinsic(x: T): R = error("Should be lowered")
|
internal fun <T, R> unboxIntrinsic(x: T): R = error("Should be lowered")
|
||||||
|
|||||||
Reference in New Issue
Block a user