translator: compare references, null compare
This commit is contained in:
@@ -81,7 +81,11 @@ class LLVMBuilder(val arm: Boolean) {
|
||||
KtTokens.GT -> firstOp.type!!.operatorGt(firstNativeOp, secondNativeOp)
|
||||
KtTokens.LTEQ -> firstOp.type!!.operatorLeq(firstNativeOp, secondNativeOp)
|
||||
KtTokens.GTEQ -> firstOp.type!!.operatorGeq(firstNativeOp, secondNativeOp)
|
||||
KtTokens.EQEQ -> firstOp.type!!.operatorEq(firstNativeOp, secondNativeOp)
|
||||
KtTokens.EQEQ ->
|
||||
if (firstOp.type is LLVMReferenceType)
|
||||
firstOp.type!!.operatorEq(firstOp, secondOp)
|
||||
else
|
||||
firstOp.type!!.operatorEq(firstNativeOp, secondNativeOp)
|
||||
KtTokens.EXCLEQ -> firstOp.type!!.operatorNeq(firstNativeOp, secondNativeOp)
|
||||
KtTokens.EQ -> {
|
||||
if (secondOp.type is LLVMNullType) {
|
||||
|
||||
+6
-1
@@ -1,5 +1,7 @@
|
||||
package org.kotlinnative.translator.llvm.types
|
||||
|
||||
import org.kotlinnative.translator.llvm.LLVMExpression
|
||||
import org.kotlinnative.translator.llvm.LLVMSingleValue
|
||||
import java.util.*
|
||||
|
||||
class LLVMReferenceType(val type: String, var prefix: String = "", override val align: Int = 4, var byRef: Boolean = true) : LLVMType() {
|
||||
@@ -8,7 +10,7 @@ class LLVMReferenceType(val type: String, var prefix: String = "", override val
|
||||
|
||||
override var size: Int = 4
|
||||
override fun toString() = "%$prefix${if (prefix.length > 0) "." else ""}${
|
||||
if (location.size > 0) "${location.joinToString(".")}." else ""
|
||||
if (location.size > 0) "${location.joinToString(".")}." else ""
|
||||
}$type"
|
||||
|
||||
private val params = ArrayList<String>()
|
||||
@@ -18,4 +20,7 @@ class LLVMReferenceType(val type: String, var prefix: String = "", override val
|
||||
fun addParam(param: String) {
|
||||
params.add(param)
|
||||
}
|
||||
|
||||
override fun operatorEq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||
LLVMExpression(LLVMBooleanType(), "icmp eq ${firstOp.getType()} $firstOp, ${if (secondOp.type is LLVMNullType) "null" else "$secondOp"}")
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
if_test_1(11) == 10
|
||||
if_test_1(0) == 0
|
||||
if_test_null(0) == 1
|
||||
if_test_null_2(0) == 0
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
nested_test_1(1) == 1
|
||||
nested_test_2(1) == 1
|
||||
nested_test_2(1) == 5
|
||||
@@ -6,4 +6,26 @@ fun if_test_1(x: Int): Int {
|
||||
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
class MyClass(i: Int)
|
||||
|
||||
fun if_test_null(x: Int): Int {
|
||||
|
||||
val y: MyClass? = null
|
||||
if (y == null) {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
fun if_test_null_2(x: Int): Int {
|
||||
val y: MyClass? = MyClass(1)
|
||||
|
||||
if (y == null) {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ class Outer() {
|
||||
class Nested(var i: Int) {
|
||||
|
||||
fun test(): Int {
|
||||
return 1
|
||||
this.i = 5
|
||||
return this.i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user