[JS IR BE] Add noWhenBranchMatchedException
* refact exception helpers
This commit is contained in:
+2
-2
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.types.isLong
|
|
||||||
import org.jetbrains.kotlin.ir.util.hasAnnotation
|
import org.jetbrains.kotlin.ir.util.hasAnnotation
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
@@ -26,7 +25,8 @@ class CallsLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
|||||||
PrimitiveContainerMemberCallTransformer(context),
|
PrimitiveContainerMemberCallTransformer(context),
|
||||||
MethodsOfAnyCallsTransformer(context),
|
MethodsOfAnyCallsTransformer(context),
|
||||||
ReflectionCallsTransformer(context),
|
ReflectionCallsTransformer(context),
|
||||||
EnumIntrinsicsTransformer(context)
|
EnumIntrinsicsTransformer(context),
|
||||||
|
ExceptionHelperCallsTransformer(context)
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun lower(irFile: IrFile) {
|
override fun lower(irFile: IrFile) {
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. 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.irCall
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
|
import org.jetbrains.kotlin.ir.util.kotlinPackageFqn
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
|
class ExceptionHelperCallsTransformer(private val context: JsIrBackendContext) : CallsTransformer {
|
||||||
|
|
||||||
|
private fun referenceFunction(fqn: FqName) = context.getFunctions(fqn).singleOrNull()?.let {
|
||||||
|
context.symbolTable.referenceSimpleFunction(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val helperMapping = mapOf(
|
||||||
|
context.irBuiltIns.throwNpeSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))),
|
||||||
|
context.irBuiltIns.throwCceSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))),
|
||||||
|
context.irBuiltIns.throwIseSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))),
|
||||||
|
context.irBuiltIns.noWhenBranchMatchedExceptionSymbol to referenceFunction(kotlinPackageFqn.child(Name.identifier("noWhenBranchMatchedException")))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
override fun transformCall(call: IrCall) = helperMapping[call.symbol]?.let { irCall(call, it) } ?: call
|
||||||
|
}
|
||||||
@@ -48,6 +48,9 @@ public inline fun longArrayOf(vararg a: Long) = a
|
|||||||
internal fun throwUninitializedPropertyAccessException(name: String): Nothing =
|
internal fun throwUninitializedPropertyAccessException(name: String): Nothing =
|
||||||
throw UninitializedPropertyAccessException("lateinit property $name has not been initialized")
|
throw UninitializedPropertyAccessException("lateinit property $name has not been initialized")
|
||||||
|
|
||||||
|
internal fun noWhenBranchMatchedException(): Nothing = throw NoWhenBranchMatchedException()
|
||||||
|
|
||||||
|
|
||||||
fun THROW_ISE() {
|
fun THROW_ISE() {
|
||||||
throw IllegalStateException()
|
throw IllegalStateException()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user