translator: fix class comparison in expressions, tests

This commit is contained in:
Alexey Stepanov
2016-08-12 12:18:46 +03:00
parent 143985a887
commit abdc44b0a0
4 changed files with 70 additions and 6 deletions
@@ -734,6 +734,14 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
}
}
private fun receivePointedArgument(variable: LLVMSingleValue, pointer: Int): LLVMSingleValue {
var currentVariable = variable
while (currentVariable.pointer > pointer) {
currentVariable = codeBuilder.receiveNativeValue(variable)
}
return currentVariable
}
private fun addPrimitiveBinaryOperation(operator: IElementType, referenceName: KtSimpleNameExpression?, firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMVariable {
val firstNativeOp = codeBuilder.receiveNativeValue(firstOp)
val secondNativeOp = codeBuilder.receiveNativeValue(secondOp)
@@ -746,14 +754,36 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
KtTokens.LTEQ -> firstOp.type!!.operatorLeq(firstNativeOp, secondNativeOp)
KtTokens.GTEQ -> firstOp.type!!.operatorGeq(firstNativeOp, secondNativeOp)
KtTokens.EQEQ ->
if ((firstOp.type is LLVMReferenceType) && (secondOp.type !is LLVMReferenceType))
firstOp.type!!.operatorEq(firstNativeOp, secondOp)
if (firstOp.type is LLVMReferenceType)
if (secondOp.type is LLVMReferenceType) {
val firstPointedArgument = receivePointedArgument(firstOp, 1)
val secondPointedArgument = receivePointedArgument(secondOp, 1)
firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument)
} else
firstOp.type!!.operatorEq(firstNativeOp, secondOp)
else
firstOp.type!!.operatorEq(firstNativeOp, secondNativeOp)
KtTokens.EQEQEQ ->
firstOp.type!!.operatorEq(firstNativeOp, secondNativeOp)
KtTokens.EXCLEQ -> firstOp.type!!.operatorNeq(firstNativeOp, secondNativeOp)
KtTokens.EXCLEQEQEQ -> firstOp.type!!.operatorNeq(firstNativeOp, secondNativeOp)
KtTokens.EQEQEQ -> {
val firstPointedArgument = receivePointedArgument(firstOp, 1)
val secondPointedArgument = receivePointedArgument(secondOp, 1)
firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument)
}
KtTokens.EXCLEQ -> {
if (firstOp.type is LLVMReferenceType)
if (secondOp.type is LLVMReferenceType) {
val firstPointedArgument = receivePointedArgument(firstOp, 1)
val secondPointedArgument = receivePointedArgument(secondOp, 1)
firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument)
} else
firstOp.type!!.operatorNeq(firstNativeOp, secondOp)
else
firstOp.type!!.operatorNeq(firstNativeOp, secondNativeOp)
}
KtTokens.EXCLEQEQEQ -> {
val firstPointedArgument = receivePointedArgument(firstOp, 1)
val secondPointedArgument = receivePointedArgument(secondOp, 1)
firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument)
}
KtTokens.EQ -> {
if (secondOp.type is LLVMNullType) {
val result = codeBuilder.getNewVariable(firstOp.type!!, firstOp.pointer)
@@ -9,6 +9,10 @@ class LLVMVoidType() : LLVMType() {
override fun mangle() = ""
override val typename = "void"
override fun equals(other: Any?): Boolean {
return other is LLVMVoidType
}
override fun hashCode() =
typename.hashCode()
@@ -0,0 +1,2 @@
referential_equality_2_EQ_master() == 1
referential_equality_2_NEQ_master() == 1
@@ -0,0 +1,28 @@
class referential_equality_2_A
fun referential_equality_2_build(): referential_equality_2_A {
return referential_equality_2_A()
}
fun referential_equality_2_EQ_slave(second_msg: referential_equality_2_A): Int {
if (second_msg == referential_equality_2_build()) {
return 0
}
return 1
}
fun referential_equality_2_NEQ_slave(second_msg: referential_equality_2_A): Int {
if (second_msg != referential_equality_2_build()) {
return 1
}
return 0
}
fun referential_equality_2_EQ_master(): Int {
return referential_equality_2_EQ_slave(referential_equality_2_build())
}
fun referential_equality_2_NEQ_master(): Int {
return referential_equality_2_NEQ_slave(referential_equality_2_build())
}