[FIR2IR] Fix generating body for for-loop

This commit is contained in:
Dmitriy Novozhilov
2021-03-29 14:12:22 +03:00
committed by TeamCityServer
parent 5d78b0a962
commit d0a148074f
19 changed files with 493 additions and 154 deletions
@@ -4,7 +4,9 @@ fun sum(vararg args: Int): Int {
val <iterator>: IntIterator = args.iterator()
while (<iterator>.hasNext()) { // BLOCK
val arg: Int = <iterator>.next()
result = result.plus(other = arg)
{ // BLOCK
result = result.plus(other = arg)
}
}
}
return result
@@ -53,3 +55,4 @@ fun testArrayAndDefaults() {
}
)
}
@@ -15,10 +15,11 @@ FILE fqName:<root> fileName:/withVarargViewedAsArray.kt
VAR FOR_LOOP_VARIABLE name:arg type:kotlin.Int [val]
CALL 'public final fun next (): kotlin.Int [operator] declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.IntIterator [val] declared in <root>.sum' type=kotlin.collections.IntIterator origin=null
SET_VAR 'var result: kotlin.Int [var] declared in <root>.sum' 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
$this: GET_VAR 'var result: kotlin.Int [var] declared in <root>.sum' type=kotlin.Int origin=null
other: GET_VAR 'val arg: kotlin.Int [val] declared in <root>.sum' type=kotlin.Int origin=null
BLOCK type=kotlin.Unit origin=null
SET_VAR 'var result: kotlin.Int [var] declared in <root>.sum' 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
$this: GET_VAR 'var result: kotlin.Int [var] declared in <root>.sum' type=kotlin.Int origin=null
other: GET_VAR 'val arg: kotlin.Int [val] declared in <root>.sum' type=kotlin.Int origin=null
RETURN type=kotlin.Nothing from='public final fun sum (vararg args: kotlin.Int): kotlin.Int declared in <root>'
GET_VAR 'var result: kotlin.Int [var] declared in <root>.sum' type=kotlin.Int origin=null
FUN name:nsum visibility:public modality:FINAL <> (args:kotlin.Array<out kotlin.Number>) returnType:kotlin.Int
+7 -4
View File
@@ -22,10 +22,12 @@ fun testDestructuring(pp: List<Pair<Int, String>>) {
val <iterator>: Iterator<Pair<Int, String>> = pp.iterator()
while (<iterator>.hasNext()) { // BLOCK
val <destruct>: Pair<Int, String> = <iterator>.next()
val i: Int = <destruct>.component1()
val s: String = <destruct>.component2()
println(message = i)
println(message = s)
{ // BLOCK
val i: Int = <destruct>.component1()
val s: String = <destruct>.component2()
println(message = i)
println(message = s)
}
}
}
}
@@ -38,3 +40,4 @@ fun testRange() {
}
}
}
+11 -10
View File
@@ -43,16 +43,17 @@ FILE fqName:<root> fileName:/for.kt
VAR FOR_LOOP_VARIABLE name:<destruct> type:kotlin.Pair<kotlin.Int, kotlin.String> [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.Pair<kotlin.Int, kotlin.String> origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_2: kotlin.collections.Iterator<kotlin.Pair<kotlin.Int, kotlin.String>> [val] declared in <root>.testDestructuring' type=kotlin.collections.Iterator<kotlin.Pair<kotlin.Int, kotlin.String>> origin=null
VAR name:i type:kotlin.Int [val]
CALL 'public final fun component1 (): A of kotlin.Pair [operator] declared in kotlin.Pair' type=kotlin.Int origin=null
$this: GET_VAR 'val <destruct>: kotlin.Pair<kotlin.Int, kotlin.String> [val] declared in <root>.testDestructuring' type=kotlin.Pair<kotlin.Int, kotlin.String> origin=null
VAR name:s type:kotlin.String [val]
CALL 'public final fun component2 (): B of kotlin.Pair [operator] declared in kotlin.Pair' type=kotlin.String origin=null
$this: GET_VAR 'val <destruct>: kotlin.Pair<kotlin.Int, kotlin.String> [val] declared in <root>.testDestructuring' type=kotlin.Pair<kotlin.Int, kotlin.String> origin=null
CALL 'public final fun println (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null
message: GET_VAR 'val i: kotlin.Int [val] declared in <root>.testDestructuring' type=kotlin.Int origin=null
CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null
message: GET_VAR 'val s: kotlin.String [val] declared in <root>.testDestructuring' type=kotlin.String origin=null
BLOCK type=kotlin.Unit origin=null
VAR name:i type:kotlin.Int [val]
CALL 'public final fun component1 (): A of kotlin.Pair [operator] declared in kotlin.Pair' type=kotlin.Int origin=null
$this: GET_VAR 'val <destruct>: kotlin.Pair<kotlin.Int, kotlin.String> [val] declared in <root>.testDestructuring' type=kotlin.Pair<kotlin.Int, kotlin.String> origin=null
VAR name:s type:kotlin.String [val]
CALL 'public final fun component2 (): B of kotlin.Pair [operator] declared in kotlin.Pair' type=kotlin.String origin=null
$this: GET_VAR 'val <destruct>: kotlin.Pair<kotlin.Int, kotlin.String> [val] declared in <root>.testDestructuring' type=kotlin.Pair<kotlin.Int, kotlin.String> origin=null
CALL 'public final fun println (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null
message: GET_VAR 'val i: kotlin.Int [val] declared in <root>.testDestructuring' type=kotlin.Int origin=null
CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null
message: GET_VAR 'val s: kotlin.String [val] declared in <root>.testDestructuring' type=kotlin.String origin=null
FUN name:testRange visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
BLOCK type=kotlin.Unit origin=FOR_LOOP
@@ -14,15 +14,19 @@ fun testForBreak2(ss: List<String>) {
OUTER@ while (<iterator>.hasNext()) { // BLOCK
val s1: String = <iterator>.next()
{ // BLOCK
val <iterator>: Iterator<String> = ss.iterator()
INNER@ while (<iterator>.hasNext()) { // BLOCK
val s2: String = <iterator>.next()
break@OUTER
break@INNER
break@INNER
{ // BLOCK
val <iterator>: Iterator<String> = ss.iterator()
INNER@ while (<iterator>.hasNext()) { // BLOCK
val s2: String = <iterator>.next()
{ // BLOCK
break@OUTER
break@INNER
break@INNER
}
}
}
break@OUTER
}
break@OUTER
}
}
}
@@ -43,15 +47,20 @@ fun testForContinue2(ss: List<String>) {
OUTER@ while (<iterator>.hasNext()) { // BLOCK
val s1: String = <iterator>.next()
{ // BLOCK
val <iterator>: Iterator<String> = ss.iterator()
INNER@ while (<iterator>.hasNext()) { // BLOCK
val s2: String = <iterator>.next()
continue@OUTER
continue@INNER
continue@INNER
{ // BLOCK
val <iterator>: Iterator<String> = ss.iterator()
INNER@ while (<iterator>.hasNext()) { // BLOCK
val s2: String = <iterator>.next()
{ // BLOCK
continue@OUTER
continue@INNER
continue@INNER
}
}
}
continue@OUTER
}
continue@OUTER
}
}
}
@@ -9,7 +9,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
WHILE label=null origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak1' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Nothing origin=FOR_LOOP_INNER_WHILE
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak1' type=kotlin.collections.Iterator<kotlin.String> origin=null
@@ -24,25 +24,27 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
WHILE label=OUTER origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_1: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak2' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Nothing origin=FOR_LOOP_INNER_WHILE
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s1 type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_1: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak2' type=kotlin.collections.Iterator<kotlin.String> origin=null
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_2 type:kotlin.collections.Iterator<kotlin.String> [val]
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of kotlin.collections.List> [operator] declared in kotlin.collections.List' type=kotlin.collections.Iterator<kotlin.String> origin=FOR_LOOP_ITERATOR
$this: GET_VAR 'ss: kotlin.collections.List<kotlin.String> declared in <root>.testForBreak2' type=kotlin.collections.List<kotlin.String> origin=null
WHILE label=INNER origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_2: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak2' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Nothing origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s2 type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_2: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak2' type=kotlin.collections.Iterator<kotlin.String> origin=null
BREAK label=OUTER loop.label=OUTER
BREAK label=INNER loop.label=INNER
BREAK label=INNER loop.label=INNER
BREAK label=OUTER loop.label=OUTER
BLOCK type=kotlin.Nothing origin=null
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_2 type:kotlin.collections.Iterator<kotlin.String> [val]
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of kotlin.collections.List> [operator] declared in kotlin.collections.List' type=kotlin.collections.Iterator<kotlin.String> origin=FOR_LOOP_ITERATOR
$this: GET_VAR 'ss: kotlin.collections.List<kotlin.String> declared in <root>.testForBreak2' type=kotlin.collections.List<kotlin.String> origin=null
WHILE label=INNER origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_2: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak2' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s2 type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_2: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForBreak2' type=kotlin.collections.Iterator<kotlin.String> origin=null
BLOCK type=kotlin.Nothing origin=null
BREAK label=OUTER loop.label=OUTER
BREAK label=INNER loop.label=INNER
BREAK label=INNER loop.label=INNER
BREAK label=OUTER loop.label=OUTER
FUN name:testForContinue1 visibility:public modality:FINAL <> (ss:kotlin.collections.List<kotlin.String>) returnType:kotlin.Unit
VALUE_PARAMETER name:ss index:0 type:kotlin.collections.List<kotlin.String>
BLOCK_BODY
@@ -53,7 +55,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
WHILE label=null origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_3: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue1' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Nothing origin=FOR_LOOP_INNER_WHILE
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_3: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue1' type=kotlin.collections.Iterator<kotlin.String> origin=null
@@ -68,22 +70,24 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
WHILE label=OUTER origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_4: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue2' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Nothing origin=FOR_LOOP_INNER_WHILE
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s1 type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_4: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue2' type=kotlin.collections.Iterator<kotlin.String> origin=null
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_5 type:kotlin.collections.Iterator<kotlin.String> [val]
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of kotlin.collections.List> [operator] declared in kotlin.collections.List' type=kotlin.collections.Iterator<kotlin.String> origin=FOR_LOOP_ITERATOR
$this: GET_VAR 'ss: kotlin.collections.List<kotlin.String> declared in <root>.testForContinue2' type=kotlin.collections.List<kotlin.String> origin=null
WHILE label=INNER origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_5: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue2' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Nothing origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s2 type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_5: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue2' type=kotlin.collections.Iterator<kotlin.String> origin=null
CONTINUE label=OUTER loop.label=OUTER
CONTINUE label=INNER loop.label=INNER
CONTINUE label=INNER loop.label=INNER
CONTINUE label=OUTER loop.label=OUTER
BLOCK type=kotlin.Nothing origin=null
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_5 type:kotlin.collections.Iterator<kotlin.String> [val]
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of kotlin.collections.List> [operator] declared in kotlin.collections.List' type=kotlin.collections.Iterator<kotlin.String> origin=FOR_LOOP_ITERATOR
$this: GET_VAR 'ss: kotlin.collections.List<kotlin.String> declared in <root>.testForContinue2' type=kotlin.collections.List<kotlin.String> origin=null
WHILE label=INNER origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_5: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue2' type=kotlin.collections.Iterator<kotlin.String> origin=null
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:s2 type:kotlin.String [val]
CALL 'public abstract fun next (): T of kotlin.collections.Iterator [operator] declared in kotlin.collections.Iterator' type=kotlin.String origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_5: kotlin.collections.Iterator<kotlin.String> [val] declared in <root>.testForContinue2' type=kotlin.collections.Iterator<kotlin.String> origin=null
BLOCK type=kotlin.Nothing origin=null
CONTINUE label=OUTER loop.label=OUTER
CONTINUE label=INNER loop.label=INNER
CONTINUE label=INNER loop.label=INNER
CONTINUE label=OUTER loop.label=OUTER