Pseudocode: Generate proper instructions for when conditions. Eliminate unnecessary magics
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
== foo ==
|
||||
fun foo(a: Number) {
|
||||
val t = when (a) {
|
||||
1 -> "1"
|
||||
in Collections.singleton(2) -> "2"
|
||||
is Int -> "Int"
|
||||
!in Collections.singleton(3) -> "!3"
|
||||
!is Number -> "!Number"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
<v0>: {<: Number} NEW: magic(a: Number) -> <v0>
|
||||
a <v1>: AND{{<: Any?}, *} NEW: r(a) -> <v1>
|
||||
1 <v2>: * NEW: r(1) -> <v2>
|
||||
1 <v3>: * NEW: magic(1|<v1>, <v2>) -> <v3>
|
||||
"1" <v4>: {<: String?} NEW: r("1") -> <v4>
|
||||
2 <v5>: {<: Int?} NEW: r(2) -> <v5>
|
||||
singleton(2) <v6>: OR{{<: Collection<Int>}, {<: Collection<Int>}} NEW: call(singleton(2), singleton|<v5>) -> <v6>
|
||||
Collections.singleton(2) <v6>: OR{{<: Collection<Int>}, {<: Collection<Int>}} COPY
|
||||
in Collections.singleton(2) <v7>: * NEW: call(in Collections.singleton(2), contains|<v6>, <v1>) -> <v7>
|
||||
"2" <v8>: {<: String?} NEW: r("2") -> <v8>
|
||||
is Int <v9>: * NEW: magic(is Int|<v1>) -> <v9>
|
||||
"Int" <v10>: {<: String?} NEW: r("Int") -> <v10>
|
||||
3 <v11>: {<: Int?} NEW: r(3) -> <v11>
|
||||
singleton(3) <v12>: OR{{<: Collection<Int>}, {<: Collection<Int>}} NEW: call(singleton(3), singleton|<v11>) -> <v12>
|
||||
Collections.singleton(3) <v12>: OR{{<: Collection<Int>}, {<: Collection<Int>}} COPY
|
||||
!in Collections.singleton(3) <v13>: * NEW: call(!in Collections.singleton(3), contains|<v12>, <v1>) -> <v13>
|
||||
"!3" <v14>: {<: String?} NEW: r("!3") -> <v14>
|
||||
!is Number <v15>: * NEW: magic(!is Number|<v1>) -> <v15>
|
||||
"!Number" <v16>: {<: String?} NEW: r("!Number") -> <v16>
|
||||
null <v17>: {<: String?} NEW: r(null) -> <v17>
|
||||
when (a) { 1 -> "1" in Collections.singleton(2) -> "2" is Int -> "Int" !in Collections.singleton(3) -> "!3" !is Number -> "!Number" else -> null } <v18>: {<: String?} NEW: merge(when (a) { 1 -> "1" in Collections.singleton(2) -> "2" is Int -> "Int" !in Collections.singleton(3) -> "!3" !is Number -> "!Number" else -> null }|<v4>, <v8>, <v10>, <v14>, <v16>, <v17>) -> <v18>
|
||||
=====================
|
||||
Reference in New Issue
Block a user