[JS IR BE] Add noWhenBranchMatchedException

* refact exception helpers
This commit is contained in:
Roman Artemev
2018-10-19 20:02:11 +03:00
committed by romanart
parent 3bea3eca2b
commit 6a05b1eee5
3 changed files with 35 additions and 2 deletions
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.expressions.IrCall
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.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
@@ -26,7 +25,8 @@ class CallsLowering(val context: JsIrBackendContext) : FileLoweringPass {
PrimitiveContainerMemberCallTransformer(context),
MethodsOfAnyCallsTransformer(context),
ReflectionCallsTransformer(context),
EnumIntrinsicsTransformer(context)
EnumIntrinsicsTransformer(context),
ExceptionHelperCallsTransformer(context)
)
override fun lower(irFile: IrFile) {
@@ -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
}
+3
View File
@@ -48,6 +48,9 @@ public inline fun longArrayOf(vararg a: Long) = a
internal fun throwUninitializedPropertyAccessException(name: String): Nothing =
throw UninitializedPropertyAccessException("lateinit property $name has not been initialized")
internal fun noWhenBranchMatchedException(): Nothing = throw NoWhenBranchMatchedException()
fun THROW_ISE() {
throw IllegalStateException()
}