mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-10 08:31:32 +00:00
ThrowableLowering
This commit is contained in:
committed by
Anton Bannykh
parent
15b2312cec
commit
05ab17f1e1
@@ -5,21 +5,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.isNullableString
|
||||
import org.jetbrains.kotlin.ir.types.makeNotNull
|
||||
import org.jetbrains.kotlin.ir.util.isThrowable
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
|
||||
|
||||
class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
class ThrowableLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
private val nothingNType get() = context.irBuiltIns.nothingNType
|
||||
|
||||
private val throwableConstructors = context.throwableConstructors
|
||||
@@ -33,8 +33,10 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
val cause: IrExpression
|
||||
)
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.transformChildren(Transformer(), irFile)
|
||||
override fun lower(irBody: IrBody, container: IrDeclaration) {
|
||||
container.parentClassOrNull.let { enclosingClass ->
|
||||
irBody.transformChildren(Transformer(), enclosingClass ?: container.file)
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrFunctionAccessExpression.extractThrowableArguments(): ThrowableArguments =
|
||||
|
||||
@@ -609,6 +609,15 @@ val IrDeclaration.fileOrNull: IrFile?
|
||||
val IrDeclaration.file: IrFile
|
||||
get() = fileOrNull ?: TODO("Unknown file")
|
||||
|
||||
val IrDeclaration.parentClassOrNull: IrClass?
|
||||
get() = parent.let {
|
||||
when (it) {
|
||||
is IrClass -> it
|
||||
is IrDeclaration -> it.parentClassOrNull
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val IrFunction.allTypeParameters: List<IrTypeParameter>
|
||||
get() = if (this is IrConstructor)
|
||||
parentAsClass.typeParameters + typeParameters
|
||||
|
||||
Reference in New Issue
Block a user