Block expressions & types.
This commit is contained in:
committed by
Dmitry Petrov
parent
594a553a04
commit
8bba49cba6
+4
-2
@@ -99,8 +99,10 @@ class StatementGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBlockExpression(expression: KtBlockExpression, data: Nothing?): IrStatement {
|
override fun visitBlockExpression(expression: KtBlockExpression, data: Nothing?): IrStatement {
|
||||||
val irBlock = IrBlockImpl(expression.startOffset, expression.endOffset,
|
val isBlockBody = expression.parent is KtNamedFunction
|
||||||
getReturnType(expression), isUsedAsExpression(expression))
|
val hasResult = if (isBlockBody) false else isUsedAsExpression(expression)
|
||||||
|
val returnType = if (isBlockBody || !hasResult) null else getReturnType(expression)
|
||||||
|
val irBlock = IrBlockImpl(expression.startOffset, expression.endOffset, returnType, hasResult)
|
||||||
expression.statements.forEach { irBlock.addStatement(it.genStmt()) }
|
expression.statements.forEach { irBlock.addStatement(it.genStmt()) }
|
||||||
return irBlock
|
return irBlock
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -53,6 +53,16 @@ class InsertImplicitCasts(val builtIns: KotlinBuiltIns): IrElementVisitor<Unit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visitBlock(expression: IrBlock, data: Nothing?) {
|
||||||
|
expression.acceptChildren(this, null)
|
||||||
|
if (!expression.hasResult || expression.type == null) return
|
||||||
|
|
||||||
|
val lastStatement = expression.statements.last()
|
||||||
|
if (lastStatement is IrExpression) {
|
||||||
|
lastStatement.wrapWithImplicitCast(expression.type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitReturn(expression: IrReturn, data: Nothing?) {
|
override fun visitReturn(expression: IrReturn, data: Nothing?) {
|
||||||
expression.acceptChildren(this, null)
|
expression.acceptChildren(this, null)
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ interface IrOperator {
|
|||||||
object EXCL : IrOperatorImpl("EXCL")
|
object EXCL : IrOperatorImpl("EXCL")
|
||||||
object EXCLEXCL : IrOperatorImpl("EXCLEXCL")
|
object EXCLEXCL : IrOperatorImpl("EXCLEXCL")
|
||||||
|
|
||||||
object IMPLICIT_NOTNULL : IrOperatorImpl("IMPLICIT_NOTNULL")
|
|
||||||
|
|
||||||
object ELVIS : IrOperatorImpl("ELVIS")
|
object ELVIS : IrOperatorImpl("ELVIS")
|
||||||
|
|
||||||
object LT : IrOperatorImpl("LT")
|
object LT : IrOperatorImpl("LT")
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ IrFile /arrayAugmentedAssignment1.kt
|
|||||||
other: CONST Int type=kotlin.Int value='2'
|
other: CONST Int type=kotlin.Int value='2'
|
||||||
IrFunction public fun testMember(/*0*/ c: C): kotlin.Unit
|
IrFunction public fun testMember(/*0*/ c: C): kotlin.Unit
|
||||||
IrExpressionBody
|
IrExpressionBody
|
||||||
BLOCK type=kotlin.Int hasResult=true operator=null
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_INCR
|
BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_INCR
|
||||||
VAR val tmp0_array: kotlin.IntArray
|
VAR val tmp0_array: kotlin.IntArray
|
||||||
CALL .<get-x> type=kotlin.IntArray operator=GET_PROPERTY
|
CALL .<get-x> type=kotlin.IntArray operator=GET_PROPERTY
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@ IrFile /augmentedAssignment1.kt
|
|||||||
CONST Int type=kotlin.Int value='0'
|
CONST Int type=kotlin.Int value='0'
|
||||||
IrFunction public fun testVariable(): kotlin.Unit
|
IrFunction public fun testVariable(): kotlin.Unit
|
||||||
IrExpressionBody
|
IrExpressionBody
|
||||||
BLOCK type=kotlin.Int hasResult=true operator=null
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
VAR var x: kotlin.Int
|
VAR var x: kotlin.Int
|
||||||
CONST Int type=kotlin.Int value='0'
|
CONST Int type=kotlin.Int value='0'
|
||||||
SET_VAR x type=<no-type> operator=PLUSEQ
|
SET_VAR x type=<no-type> operator=PLUSEQ
|
||||||
@@ -29,7 +29,7 @@ IrFile /augmentedAssignment1.kt
|
|||||||
other: CONST Int type=kotlin.Int value='5'
|
other: CONST Int type=kotlin.Int value='5'
|
||||||
IrFunction public fun testProperty(): kotlin.Unit
|
IrFunction public fun testProperty(): kotlin.Unit
|
||||||
IrExpressionBody
|
IrExpressionBody
|
||||||
BLOCK type=kotlin.Int hasResult=true operator=null
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
CALL .<set-p> type=kotlin.Unit operator=PLUSEQ
|
CALL .<set-p> type=kotlin.Unit operator=PLUSEQ
|
||||||
<set-?>: CALL .plus type=kotlin.Int operator=PLUSEQ
|
<set-?>: CALL .plus type=kotlin.Int operator=PLUSEQ
|
||||||
$this: CALL .<get-p> type=kotlin.Int operator=PLUSEQ
|
$this: CALL .<get-p> type=kotlin.Int operator=PLUSEQ
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ IrFile /safeCallWithIncrementDecrement.kt
|
|||||||
BLOCK type=<no-type> hasResult=false operator=null
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
IrFunction public fun testProperty(/*0*/ nc: test.C?): kotlin.Unit
|
IrFunction public fun testProperty(/*0*/ nc: test.C?): kotlin.Unit
|
||||||
IrExpressionBody
|
IrExpressionBody
|
||||||
BLOCK type=kotlin.Int? hasResult=true operator=null
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
BLOCK type=kotlin.Int? hasResult=true operator=SAFE_CALL
|
BLOCK type=kotlin.Int? hasResult=true operator=SAFE_CALL
|
||||||
VAR val tmp0_safe_receiver: test.C?
|
VAR val tmp0_safe_receiver: test.C?
|
||||||
GET_VAR nc type=test.C? operator=null
|
GET_VAR nc type=test.C? operator=null
|
||||||
@@ -51,3 +51,28 @@ IrFile /safeCallWithIncrementDecrement.kt
|
|||||||
value: CALL .inc type=kotlin.Int? operator=POSTFIX_INCR
|
value: CALL .inc type=kotlin.Int? operator=POSTFIX_INCR
|
||||||
$receiver: GET_VAR tmp1 type=kotlin.Int operator=null
|
$receiver: GET_VAR tmp1 type=kotlin.Int operator=null
|
||||||
GET_VAR tmp1 type=kotlin.Int operator=null
|
GET_VAR tmp1 type=kotlin.Int operator=null
|
||||||
|
IrFunction public fun testArrayAccess(/*0*/ nc: test.C?): kotlin.Unit
|
||||||
|
IrExpressionBody
|
||||||
|
BLOCK type=<no-type> hasResult=false operator=null
|
||||||
|
BLOCK type=kotlin.Int hasResult=true operator=POSTFIX_INCR
|
||||||
|
VAR val tmp3_array: kotlin.Int?
|
||||||
|
BLOCK type=kotlin.Int? hasResult=true operator=SAFE_CALL
|
||||||
|
VAR val tmp0_safe_receiver: test.C?
|
||||||
|
GET_VAR nc type=test.C? operator=null
|
||||||
|
WHEN type=kotlin.Int? operator=SAFE_CALL
|
||||||
|
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
|
||||||
|
arg0: GET_VAR tmp0_safe_receiver type=test.C? operator=null
|
||||||
|
arg1: CONST Null type=kotlin.Nothing? value='null'
|
||||||
|
then: CONST Null type=kotlin.Nothing? value='null'
|
||||||
|
else: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
|
||||||
|
$this: GET_VAR tmp0_safe_receiver type=test.C? operator=null
|
||||||
|
VAR val tmp4: kotlin.Int
|
||||||
|
CALL .get type=kotlin.Int operator=POSTFIX_INCR
|
||||||
|
$receiver: GET_VAR tmp3_array type=kotlin.Int? operator=null
|
||||||
|
index: CONST Int type=kotlin.Int value='0'
|
||||||
|
CALL .set type=kotlin.Unit operator=POSTFIX_INCR
|
||||||
|
$receiver: GET_VAR tmp3_array type=kotlin.Int? operator=null
|
||||||
|
index: CONST Int type=kotlin.Int value='0'
|
||||||
|
value: CALL .inc type=kotlin.Int operator=POSTFIX_INCR
|
||||||
|
$this: GET_VAR tmp4 type=kotlin.Int operator=null
|
||||||
|
GET_VAR tmp4 type=kotlin.Int operator=null
|
||||||
|
|||||||
Reference in New Issue
Block a user