Comparisons:

- for primitive types and kotlin.String, use IrBinaryOperatorExpression
- for others, use call to 'compareTo'
This commit is contained in:
Dmitry Petrov
2016-08-18 20:06:45 +03:00
committed by Dmitry Petrov
parent ace98b91cc
commit 1ddf889d8a
8 changed files with 280 additions and 38 deletions
+10 -4
View File
@@ -1,4 +1,10 @@
fun test1(a: String, b: String) = a > b
fun test2(a: String, b: String) = a < b
fun test3(a: String, b: String) = a >= b
fun test4(a: String, b: String) = a <= b
interface IA
interface IB {
operator fun IA.compareTo(other: IA): Int
}
fun IB.test1(a1: IA, a2: IA) = a1 > a2
fun IB.test2(a1: IA, a2: IA) = a1 >= a2
fun IB.test3(a1: IA, a2: IA) = a1 < a2
fun IB.test4(a1: IA, a2: IA) = a1 <= a2
+30 -16
View File
@@ -1,29 +1,43 @@
IrFile /conventionComparisons.kt
IrFunction public fun test1(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
DUMMY IA
DUMMY IB
IrFunction public fun IB.test1(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null
IrFunction public fun test2(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
BINARY_OP operator=GT type=kotlin.Boolean related=null
CALL .compareTo type=kotlin.Int operator=GT
$this: $RECEIVER of: test1 type=IB
$receiver: GET_VAR a1 type=IA operator=null
other: GET_VAR a2 type=IA operator=null
LITERAL Int type=kotlin.Int value='0'
IrFunction public fun IB.test2(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null
IrFunction public fun test3(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
BINARY_OP operator=GTEQ type=kotlin.Boolean related=null
CALL .compareTo type=kotlin.Int operator=GTEQ
$this: $RECEIVER of: test2 type=IB
$receiver: GET_VAR a1 type=IA operator=null
other: GET_VAR a2 type=IA operator=null
LITERAL Int type=kotlin.Int value='0'
IrFunction public fun IB.test3(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null
IrFunction public fun test4(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
BINARY_OP operator=LT type=kotlin.Boolean related=null
CALL .compareTo type=kotlin.Int operator=LT
$this: $RECEIVER of: test3 type=IB
$receiver: GET_VAR a1 type=IA operator=null
other: GET_VAR a2 type=IA operator=null
LITERAL Int type=kotlin.Int value='0'
IrFunction public fun IB.test4(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null
BINARY_OP operator=LTEQ type=kotlin.Boolean related=null
CALL .compareTo type=kotlin.Int operator=LTEQ
$this: $RECEIVER of: test4 type=IB
$receiver: GET_VAR a1 type=IA operator=null
other: GET_VAR a2 type=IA operator=null
LITERAL Int type=kotlin.Int value='0'
+29 -4
View File
@@ -1,4 +1,29 @@
fun test1(a: Int, b: Int) = a > b
fun test2(a: Int, b: Int) = a < b
fun test3(a: Int, b: Int) = a >= b
fun test4(a: Int, b: Int) = a <= b
fun btest1(a: Byte, b: Byte) = a > b
fun btest2(a: Byte, b: Byte) = a < b
fun btest3(a: Byte, b: Byte) = a >= b
fun btest4(a: Byte, b: Byte) = a <= b
fun stest1(a: Short, b: Short) = a > b
fun stest2(a: Short, b: Short) = a < b
fun stest3(a: Short, b: Short) = a >= b
fun stest4(a: Short, b: Short) = a <= b
fun itest1(a: Int, b: Int) = a > b
fun itest2(a: Int, b: Int) = a < b
fun itest3(a: Int, b: Int) = a >= b
fun itest4(a: Int, b: Int) = a <= b
fun ltest1(a: Long, b: Long) = a > b
fun ltest2(a: Long, b: Long) = a < b
fun ltest3(a: Long, b: Long) = a >= b
fun ltest4(a: Long, b: Long) = a <= b
fun ftest1(a: Float, b: Float) = a > b
fun ftest2(a: Float, b: Float) = a < b
fun ftest3(a: Float, b: Float) = a >= b
fun ftest4(a: Float, b: Float) = a <= b
fun dtest1(a: Double, b: Double) = a > b
fun dtest2(a: Double, b: Double) = a < b
fun dtest3(a: Double, b: Double) = a >= b
fun dtest4(a: Double, b: Double) = a <= b
+144 -4
View File
@@ -1,29 +1,169 @@
IrFile /primitiveComparisons.kt
IrFunction public fun test1(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrFunction public fun btest1(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int
GET_VAR a type=kotlin.Byte operator=null
GET_VAR b type=kotlin.Byte operator=null
IrFunction public fun btest2(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int
GET_VAR a type=kotlin.Byte operator=null
GET_VAR b type=kotlin.Byte operator=null
IrFunction public fun btest3(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int
GET_VAR a type=kotlin.Byte operator=null
GET_VAR b type=kotlin.Byte operator=null
IrFunction public fun btest4(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int
GET_VAR a type=kotlin.Byte operator=null
GET_VAR b type=kotlin.Byte operator=null
IrFunction public fun stest1(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int
GET_VAR a type=kotlin.Short operator=null
GET_VAR b type=kotlin.Short operator=null
IrFunction public fun stest2(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int
GET_VAR a type=kotlin.Short operator=null
GET_VAR b type=kotlin.Short operator=null
IrFunction public fun stest3(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int
GET_VAR a type=kotlin.Short operator=null
GET_VAR b type=kotlin.Short operator=null
IrFunction public fun stest4(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int
GET_VAR a type=kotlin.Short operator=null
GET_VAR b type=kotlin.Short operator=null
IrFunction public fun itest1(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int
GET_VAR a type=kotlin.Int operator=null
GET_VAR b type=kotlin.Int operator=null
IrFunction public fun test2(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrFunction public fun itest2(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int
GET_VAR a type=kotlin.Int operator=null
GET_VAR b type=kotlin.Int operator=null
IrFunction public fun test3(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrFunction public fun itest3(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int
GET_VAR a type=kotlin.Int operator=null
GET_VAR b type=kotlin.Int operator=null
IrFunction public fun test4(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrFunction public fun itest4(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int
GET_VAR a type=kotlin.Int operator=null
GET_VAR b type=kotlin.Int operator=null
IrFunction public fun ltest1(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int
GET_VAR a type=kotlin.Long operator=null
GET_VAR b type=kotlin.Long operator=null
IrFunction public fun ltest2(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int
GET_VAR a type=kotlin.Long operator=null
GET_VAR b type=kotlin.Long operator=null
IrFunction public fun ltest3(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int
GET_VAR a type=kotlin.Long operator=null
GET_VAR b type=kotlin.Long operator=null
IrFunction public fun ltest4(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int
GET_VAR a type=kotlin.Long operator=null
GET_VAR b type=kotlin.Long operator=null
IrFunction public fun ftest1(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int
GET_VAR a type=kotlin.Float operator=null
GET_VAR b type=kotlin.Float operator=null
IrFunction public fun ftest2(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int
GET_VAR a type=kotlin.Float operator=null
GET_VAR b type=kotlin.Float operator=null
IrFunction public fun ftest3(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int
GET_VAR a type=kotlin.Float operator=null
GET_VAR b type=kotlin.Float operator=null
IrFunction public fun ftest4(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int
GET_VAR a type=kotlin.Float operator=null
GET_VAR b type=kotlin.Float operator=null
IrFunction public fun dtest1(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int
GET_VAR a type=kotlin.Double operator=null
GET_VAR b type=kotlin.Double operator=null
IrFunction public fun dtest2(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int
GET_VAR a type=kotlin.Double operator=null
GET_VAR b type=kotlin.Double operator=null
IrFunction public fun dtest3(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int
GET_VAR a type=kotlin.Double operator=null
GET_VAR b type=kotlin.Double operator=null
IrFunction public fun dtest4(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int
GET_VAR a type=kotlin.Double operator=null
GET_VAR b type=kotlin.Double operator=null
+4
View File
@@ -0,0 +1,4 @@
fun test1(a: String, b: String) = a > b
fun test2(a: String, b: String) = a < b
fun test3(a: String, b: String) = a >= b
fun test4(a: String, b: String) = a <= b
+29
View File
@@ -0,0 +1,29 @@
IrFile /stringComparisons.kt
IrFunction public fun test1(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null
IrFunction public fun test2(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null
IrFunction public fun test3(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null
IrFunction public fun test4(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
GET_VAR a type=kotlin.String operator=null
GET_VAR b type=kotlin.String operator=null