translator: fix for null return from function
This commit is contained in:
@@ -816,6 +816,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument)
|
firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument)
|
||||||
}
|
}
|
||||||
KtTokens.EQ -> {
|
KtTokens.EQ -> {
|
||||||
|
codeBuilder.addComment("start variable assignment")
|
||||||
if (secondOp.type is LLVMNullType) {
|
if (secondOp.type is LLVMNullType) {
|
||||||
val result = codeBuilder.getNewVariable(firstOp.type!!, firstOp.pointer)
|
val result = codeBuilder.getNewVariable(firstOp.type!!, firstOp.pointer)
|
||||||
codeBuilder.allocStaticVar(result)
|
codeBuilder.allocStaticVar(result)
|
||||||
@@ -828,6 +829,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
val result = firstOp as LLVMVariable
|
val result = firstOp as LLVMVariable
|
||||||
val sourceArgument = if (result.pointer == secondOp.pointer + 1) secondOp else secondNativeOp
|
val sourceArgument = if (result.pointer == secondOp.pointer + 1) secondOp else secondNativeOp
|
||||||
codeBuilder.storeVariable(result, sourceArgument)
|
codeBuilder.storeVariable(result, sourceArgument)
|
||||||
|
codeBuilder.addComment("end variable assignment")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
else -> addPrimitiveReferenceOperation(referenceName!!, firstOp, secondNativeOp)
|
else -> addPrimitiveReferenceOperation(referenceName!!, firstOp, secondNativeOp)
|
||||||
@@ -1059,13 +1061,20 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
|
|
||||||
private fun evaluateReturnInstruction(element: PsiElement, scopeDepth: Int): LLVMVariable? {
|
private fun evaluateReturnInstruction(element: PsiElement, scopeDepth: Int): LLVMVariable? {
|
||||||
val next = element.getNextSiblingIgnoringWhitespaceAndComments()
|
val next = element.getNextSiblingIgnoringWhitespaceAndComments()
|
||||||
val retVar = evaluateExpression(next, scopeDepth)
|
var retVar = evaluateExpression(next, scopeDepth)
|
||||||
val type = retVar?.type ?: LLVMVoidType()
|
val type = retVar?.type ?: LLVMVoidType()
|
||||||
|
|
||||||
when (type) {
|
when (type) {
|
||||||
is LLVMReferenceType -> genReferenceReturn(retVar!!)
|
is LLVMReferenceType -> genReferenceReturn(retVar!!)
|
||||||
is LLVMVoidType,
|
|
||||||
is LLVMNullType -> {
|
is LLVMNullType -> {
|
||||||
|
retVar = when (retVar) {
|
||||||
|
is LLVMConstant -> LLVMConstant(retVar.value, LLVMNullType(returnType!!.type), returnType!!.pointer - 1)
|
||||||
|
is LLVMVariable -> LLVMVariable(retVar.label, LLVMNullType(returnType!!.type), retVar.kotlinName, retVar.scope, returnType!!.pointer - 1)
|
||||||
|
else -> throw IllegalStateException()
|
||||||
|
}
|
||||||
|
genReferenceReturn(retVar)
|
||||||
|
}
|
||||||
|
is LLVMVoidType -> {
|
||||||
codeBuilder.addAnyReturn(LLVMVoidType())
|
codeBuilder.addAnyReturn(LLVMVoidType())
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ class LLVMNullType(var basetype: LLVMType? = null) : LLVMReferred, LLVMType() {
|
|||||||
return other is LLVMNullType
|
return other is LLVMNullType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun parseArg(inputArg: String) = "null"
|
||||||
|
|
||||||
override fun hashCode() =
|
override fun hashCode() =
|
||||||
"null".hashCode()
|
"null".hashCode()
|
||||||
|
|
||||||
|
override fun toString() = basetype?.toString() ?: ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
null_comparison_1() == 87
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
class null_comparison_1_class
|
||||||
|
|
||||||
|
fun null_comparison_1_getClass(): null_comparison_1_class? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun null_comparison_1(): Int {
|
||||||
|
val a: null_comparison_1_class? = null_comparison_1_getClass()
|
||||||
|
println(if (a == null) 555 else 9990)
|
||||||
|
if (a == null) {
|
||||||
|
return 87
|
||||||
|
}
|
||||||
|
return 945
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user