translator: fix comparison classes with null

This commit is contained in:
Alexey Stepanov
2016-08-17 14:15:27 +03:00
parent d060e600e7
commit f737c298bc
4 changed files with 17 additions and 10 deletions
@@ -785,8 +785,8 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
KtTokens.LTEQ -> firstOp.type!!.operatorLeq(firstNativeOp, secondNativeOp) KtTokens.LTEQ -> firstOp.type!!.operatorLeq(firstNativeOp, secondNativeOp)
KtTokens.GTEQ -> firstOp.type!!.operatorGeq(firstNativeOp, secondNativeOp) KtTokens.GTEQ -> firstOp.type!!.operatorGeq(firstNativeOp, secondNativeOp)
KtTokens.EQEQ -> KtTokens.EQEQ ->
if (firstOp.type is LLVMReferenceType) if (firstOp.type is LLVMReferred)
if (secondOp.type is LLVMReferenceType) { if (secondOp.type is LLVMReferred) {
val firstPointedArgument = receivePointedArgument(firstOp, 1) val firstPointedArgument = receivePointedArgument(firstOp, 1)
val secondPointedArgument = receivePointedArgument(secondOp, 1) val secondPointedArgument = receivePointedArgument(secondOp, 1)
firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument) firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument)
@@ -800,8 +800,8 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument) firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument)
} }
KtTokens.EXCLEQ -> { KtTokens.EXCLEQ -> {
if (firstOp.type is LLVMReferenceType) if (firstOp.type is LLVMReferred)
if (secondOp.type is LLVMReferenceType) { if (secondOp.type is LLVMReferred) {
val firstPointedArgument = receivePointedArgument(firstOp, 1) val firstPointedArgument = receivePointedArgument(firstOp, 1)
val secondPointedArgument = receivePointedArgument(secondOp, 1) val secondPointedArgument = receivePointedArgument(secondOp, 1)
firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument) firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument)
@@ -1,13 +1,16 @@
package org.kotlinnative.translator.llvm.types package org.kotlinnative.translator.llvm.types
class LLVMNullType() : LLVMType() { import org.kotlinnative.translator.llvm.LLVMExpression
override val align: Int = 0 import org.kotlinnative.translator.llvm.LLVMSingleValue
class LLVMNullType(var basetype: LLVMType? = null) : LLVMReferred, LLVMType() {
override val align: Int = 1
override var size: Int = 0 override var size: Int = 0
override val defaultValue: String = "0" override val defaultValue: String = "null"
override fun mangle() = "" override fun mangle() = ""
override val typename = "" override val typename = basetype?.typename ?: ""
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
return other is LLVMNullType return other is LLVMNullType
@@ -4,9 +4,9 @@ import org.kotlinnative.translator.llvm.LLVMExpression
import org.kotlinnative.translator.llvm.LLVMSingleValue import org.kotlinnative.translator.llvm.LLVMSingleValue
import java.util.* import java.util.*
class LLVMReferenceType(val type: String, var prefix: String = "", override var align: Int = 4, override var size: Int = 4, var byRef: Boolean = true) : LLVMType() { class LLVMReferenceType(val type: String, var prefix: String = "", override var align: Int = 4, override var size: Int = 4, var byRef: Boolean = true) : LLVMReferred, LLVMType() {
override val defaultValue: String = "" override val defaultValue: String = "null"
override val typename: String override val typename: String
get() = "$prefix${if (prefix.length > 0) "." else ""}${ get() = "$prefix${if (prefix.length > 0) "." else ""}${
@@ -0,0 +1,4 @@
package org.kotlinnative.translator.llvm.types
interface LLVMReferred {
}