FIR2IR: make the scope of body of do-while loop transparent
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1b6c4329d2
commit
e9659d9c8a
@@ -604,10 +604,17 @@ class Fir2IrVisitor(
|
|||||||
val type =
|
val type =
|
||||||
(statements.lastOrNull() as? FirExpression)?.typeRef?.toIrType() ?: irBuiltIns.unitType
|
(statements.lastOrNull() as? FirExpression)?.typeRef?.toIrType() ?: irBuiltIns.unitType
|
||||||
return convertWithOffsets { startOffset, endOffset ->
|
return convertWithOffsets { startOffset, endOffset ->
|
||||||
IrBlockImpl(
|
if (origin == IrStatementOrigin.DO_WHILE_LOOP) {
|
||||||
startOffset, endOffset, type, origin,
|
IrCompositeImpl(
|
||||||
mapToIrStatements().filterNotNull()
|
startOffset, endOffset, type, origin,
|
||||||
)
|
mapToIrStatements().filterNotNull()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
IrBlockImpl(
|
||||||
|
startOffset, endOffset, type, origin,
|
||||||
|
mapToIrStatements().filterNotNull()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,7 +783,7 @@ class Fir2IrVisitor(
|
|||||||
).apply {
|
).apply {
|
||||||
loopMap[doWhileLoop] = this
|
loopMap[doWhileLoop] = this
|
||||||
label = doWhileLoop.label?.name
|
label = doWhileLoop.label?.name
|
||||||
body = doWhileLoop.block.convertToIrExpressionOrBlock()
|
body = doWhileLoop.block.convertToIrExpressionOrBlock(origin)
|
||||||
condition = convertToIrExpression(doWhileLoop.condition)
|
condition = convertToIrExpression(doWhileLoop.condition)
|
||||||
loopMap.remove(doWhileLoop)
|
loopMap.remove(doWhileLoop)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
var x = 0
|
var x = 0
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ FILE fqName:<root> fileName:/localVarInDoWhile.kt
|
|||||||
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DO_WHILE label=null origin=DO_WHILE_LOOP
|
DO_WHILE label=null origin=DO_WHILE_LOOP
|
||||||
body: BLOCK type=kotlin.Unit origin=null
|
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
|
||||||
VAR name:x type:kotlin.Int [val]
|
VAR name:x type:kotlin.Int [val]
|
||||||
CONST Int type=kotlin.Int value=42
|
CONST Int type=kotlin.Int value=42
|
||||||
condition: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
|
condition: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ FILE fqName:<root> fileName:/breakContinueInLoopHeader.kt
|
|||||||
VAR name:j type:kotlin.Int [var]
|
VAR name:j type:kotlin.Int [var]
|
||||||
CONST Int type=kotlin.Int value=0
|
CONST Int type=kotlin.Int value=0
|
||||||
DO_WHILE label=Inner origin=DO_WHILE_LOOP
|
DO_WHILE label=Inner origin=DO_WHILE_LOOP
|
||||||
body: BLOCK type=kotlin.Int origin=null
|
body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP
|
||||||
VAR IR_TEMPORARY_VARIABLE name:tmp_7 type:kotlin.Int [val]
|
VAR IR_TEMPORARY_VARIABLE name:tmp_7 type:kotlin.Int [val]
|
||||||
GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null
|
GET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Int origin=null
|
||||||
SET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Unit origin=EQ
|
SET_VAR 'var j: kotlin.Int [var] declared in <root>.test5' type=kotlin.Unit origin=EQ
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ FILE fqName:<root> fileName:/breakContinueInWhen.kt
|
|||||||
VAR name:s type:kotlin.String [var]
|
VAR name:s type:kotlin.String [var]
|
||||||
CONST String type=kotlin.String value=""
|
CONST String type=kotlin.String value=""
|
||||||
DO_WHILE label=null origin=DO_WHILE_LOOP
|
DO_WHILE label=null origin=DO_WHILE_LOOP
|
||||||
body: BLOCK type=kotlin.Unit origin=null
|
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
|
||||||
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val]
|
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val]
|
||||||
GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null
|
GET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Int origin=null
|
||||||
SET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Unit origin=EQ
|
SET_VAR 'var k: kotlin.Int [var] declared in <root>.testContinueDoWhile' type=kotlin.Unit origin=EQ
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ FILE fqName:<root> fileName:/kt24804.kt
|
|||||||
VAR name:z type:kotlin.Int [var]
|
VAR name:z type:kotlin.Int [var]
|
||||||
CONST Int type=kotlin.Int value=10
|
CONST Int type=kotlin.Int value=10
|
||||||
DO_WHILE label=l2 origin=DO_WHILE_LOOP
|
DO_WHILE label=l2 origin=DO_WHILE_LOOP
|
||||||
body: BLOCK type=kotlin.Unit origin=null
|
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
|
||||||
SET_VAR 'var z: kotlin.Int [var] declared in <root>.run' type=kotlin.Unit origin=EQ
|
SET_VAR 'var z: kotlin.Int [var] declared in <root>.run' type=kotlin.Unit origin=EQ
|
||||||
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
|
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
|
||||||
$this: GET_VAR 'var z: kotlin.Int [var] declared in <root>.run' type=kotlin.Int origin=null
|
$this: GET_VAR 'var z: kotlin.Int [var] declared in <root>.run' type=kotlin.Int origin=null
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ FILE fqName:<root> fileName:/whileDoWhile.kt
|
|||||||
$this: GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
$this: GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
||||||
GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
GET_VAR 'val tmp_1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
||||||
DO_WHILE label=null origin=DO_WHILE_LOOP
|
DO_WHILE label=null origin=DO_WHILE_LOOP
|
||||||
body: BLOCK type=kotlin.Unit origin=null
|
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
|
||||||
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
|
condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
|
||||||
arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
|
arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
|
||||||
arg1: CONST Int type=kotlin.Int value=0
|
arg1: CONST Int type=kotlin.Int value=0
|
||||||
@@ -47,7 +47,7 @@ FILE fqName:<root> fileName:/whileDoWhile.kt
|
|||||||
arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
|
arg0: GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
|
||||||
arg1: CONST Int type=kotlin.Int value=15
|
arg1: CONST Int type=kotlin.Int value=15
|
||||||
DO_WHILE label=null origin=DO_WHILE_LOOP
|
DO_WHILE label=null origin=DO_WHILE_LOOP
|
||||||
body: BLOCK type=kotlin.Int origin=null
|
body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP
|
||||||
VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val]
|
VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val]
|
||||||
GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
|
GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=null
|
||||||
SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ
|
SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ
|
||||||
@@ -71,6 +71,6 @@ FILE fqName:<root> fileName:/whileDoWhile.kt
|
|||||||
GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null
|
GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null
|
||||||
body: BLOCK type=kotlin.Unit origin=WHILE_LOOP
|
body: BLOCK type=kotlin.Unit origin=WHILE_LOOP
|
||||||
DO_WHILE label=null origin=DO_WHILE_LOOP
|
DO_WHILE label=null origin=DO_WHILE_LOOP
|
||||||
body: BLOCK type=kotlin.Unit origin=null
|
body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP
|
||||||
condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean
|
condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean
|
||||||
GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null
|
GET_VAR 'val a: kotlin.Any? [val] declared in <root>.testSmartcastInCondition' type=kotlin.Any? origin=null
|
||||||
|
|||||||
Reference in New Issue
Block a user