Move IrReturnTarget.returnType to IrUtils
This commit is contained in:
committed by
Alexander Udalov
parent
ea3bae5fc9
commit
3ce0c336bc
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.common.ir
|
package org.jetbrains.kotlin.backend.common.ir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||||
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
|
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
|
||||||
import org.jetbrains.kotlin.backend.common.deepCopyWithVariables
|
import org.jetbrains.kotlin.backend.common.deepCopyWithVariables
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.*
|
import org.jetbrains.kotlin.backend.common.descriptors.*
|
||||||
@@ -112,6 +113,14 @@ val IrSimpleFunction.isOverridable: Boolean
|
|||||||
|
|
||||||
val IrSimpleFunction.isOverridableOrOverrides: Boolean get() = isOverridable || overriddenSymbols.isNotEmpty()
|
val IrSimpleFunction.isOverridableOrOverrides: Boolean get() = isOverridable || overriddenSymbols.isNotEmpty()
|
||||||
|
|
||||||
|
fun IrReturnTarget.returnType(context: CommonBackendContext) =
|
||||||
|
when (this) {
|
||||||
|
is IrConstructor -> context.irBuiltIns.unitType
|
||||||
|
is IrFunction -> returnType
|
||||||
|
is IrReturnableBlock -> type
|
||||||
|
else -> error("Unknown ReturnTarget: $this")
|
||||||
|
}
|
||||||
|
|
||||||
val IrClass.isFinalClass: Boolean
|
val IrClass.isFinalClass: Boolean
|
||||||
get() = modality == Modality.FINAL && kind != ClassKind.ENUM_CLASS
|
get() = modality == Modality.FINAL && kind != ClassKind.ENUM_CLASS
|
||||||
|
|
||||||
|
|||||||
+2
-9
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.common.lower
|
|||||||
import org.jetbrains.kotlin.backend.common.*
|
import org.jetbrains.kotlin.backend.common.*
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor
|
import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedVariableDescriptor
|
import org.jetbrains.kotlin.backend.common.descriptors.WrappedVariableDescriptor
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.returnType
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
@@ -160,14 +161,6 @@ class FinallyBlocksLowering(val context: CommonBackendContext, private val throw
|
|||||||
return performHighLevelJump(tryScopes, 0, jump, startOffset, endOffset, value)
|
return performHighLevelJump(tryScopes, 0, jump, startOffset, endOffset, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val IrReturnTarget.returnType: IrType
|
|
||||||
get() = when (this) {
|
|
||||||
is IrConstructor -> context.irBuiltIns.unitType
|
|
||||||
is IrFunction -> returnType
|
|
||||||
is IrReturnableBlock -> type
|
|
||||||
else -> error("Unknown ReturnTarget: $this")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun performHighLevelJump(tryScopes: List<TryScope>,
|
private fun performHighLevelJump(tryScopes: List<TryScope>,
|
||||||
index: Int,
|
index: Int,
|
||||||
jump: HighLevelJump,
|
jump: HighLevelJump,
|
||||||
@@ -180,7 +173,7 @@ class FinallyBlocksLowering(val context: CommonBackendContext, private val throw
|
|||||||
|
|
||||||
val currentTryScope = tryScopes[index]
|
val currentTryScope = tryScopes[index]
|
||||||
currentTryScope.jumps.getOrPut(jump) {
|
currentTryScope.jumps.getOrPut(jump) {
|
||||||
val type = (jump as? Return)?.target?.owner?.returnType ?: value.type
|
val type = (jump as? Return)?.target?.owner?.returnType(context) ?: value.type
|
||||||
jump.toString()
|
jump.toString()
|
||||||
val symbol = IrReturnableBlockSymbolImpl(WrappedSimpleFunctionDescriptor())
|
val symbol = IrReturnableBlockSymbolImpl(WrappedSimpleFunctionDescriptor())
|
||||||
with(currentTryScope) {
|
with(currentTryScope) {
|
||||||
|
|||||||
+2
-10
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.jvm.codegen
|
package org.jetbrains.kotlin.backend.jvm.codegen
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.returnType
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
||||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.JavaClassProperty
|
import org.jetbrains.kotlin.backend.jvm.intrinsics.JavaClassProperty
|
||||||
@@ -644,15 +645,6 @@ class ExpressionCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from FinallyBlocksLowering
|
|
||||||
private val IrReturnTarget.returnType: IrType
|
|
||||||
get() = when (this) {
|
|
||||||
is IrConstructor -> context.irBuiltIns.unitType
|
|
||||||
is IrFunction -> returnType
|
|
||||||
is IrReturnableBlock -> type
|
|
||||||
else -> error("Unknown ReturnTarget: $this")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitReturn(expression: IrReturn, data: BlockInfo): PromisedValue {
|
override fun visitReturn(expression: IrReturn, data: BlockInfo): PromisedValue {
|
||||||
val owner = expression.returnTargetSymbol.owner
|
val owner = expression.returnTargetSymbol.owner
|
||||||
//TODO: should be owner != irFunction
|
//TODO: should be owner != irFunction
|
||||||
@@ -670,7 +662,7 @@ class ExpressionCodegen(
|
|||||||
val target = data.findBlock<ReturnableBlockInfo> { it.returnSymbol == expression.returnTargetSymbol }
|
val target = data.findBlock<ReturnableBlockInfo> { it.returnSymbol == expression.returnTargetSymbol }
|
||||||
val returnType = typeMapper.mapReturnType(owner)
|
val returnType = typeMapper.mapReturnType(owner)
|
||||||
val afterReturnLabel = Label()
|
val afterReturnLabel = Label()
|
||||||
expression.value.accept(this, data).coerce(returnType, owner.returnType).materialize()
|
expression.value.accept(this, data).coerce(returnType, owner.returnType(context)).materialize()
|
||||||
generateFinallyBlocksIfNeeded(returnType, afterReturnLabel, data, target)
|
generateFinallyBlocksIfNeeded(returnType, afterReturnLabel, data, target)
|
||||||
expression.markLineNumber(startOffset = true)
|
expression.markLineNumber(startOffset = true)
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user