translator: fix if expressions with variable conditions, add test
This commit is contained in:
@@ -294,7 +294,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
||||
val expression = explicitReceiver.expression as KtReferenceExpression
|
||||
|
||||
val receiver = evaluateReferenceExpression(expression, scope)!! as LLVMVariable
|
||||
val pureReceiver = loadArgumentIfRequired(receiver, LLVMVariable("", receiver.type, pointer = 1))
|
||||
val pureReceiver = downLoadArgument(receiver, 1)
|
||||
|
||||
val targetClassName = (receiver.type as LLVMReferenceType).type
|
||||
|
||||
@@ -466,6 +466,9 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
||||
return result
|
||||
}
|
||||
|
||||
private fun downLoadArgument(value: LLVMSingleValue, pointer: Int): LLVMSingleValue =
|
||||
loadArgumentIfRequired(value, LLVMVariable("", value.type!!, pointer = pointer))
|
||||
|
||||
private fun loadArgsIfRequired(names: List<LLVMSingleValue>, args: List<LLVMVariable>) =
|
||||
names.mapIndexed(fun(i: Int, value: LLVMSingleValue): LLVMSingleValue {
|
||||
return loadArgumentIfRequired(value, args[i])
|
||||
@@ -778,11 +781,12 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
||||
|
||||
private fun evaluateIfOperator(element: KtIfExpression, scopeDepth: Int, isExpression: Boolean = true): LLVMVariable? {
|
||||
val conditionResult = evaluateExpression(element.condition, scopeDepth)!!
|
||||
val conditionNativeResult = downLoadArgument(conditionResult, 0)
|
||||
|
||||
return if (isExpression)
|
||||
executeIfExpression(conditionResult, element.then!!, element.`else`, element, scopeDepth + 1)
|
||||
executeIfExpression(conditionNativeResult, element.then!!, element.`else`, element, scopeDepth + 1)
|
||||
else
|
||||
executeIfBlock(conditionResult, element.then!!, element.`else`, scopeDepth + 1)
|
||||
executeIfBlock(conditionNativeResult, element.then!!, element.`else`, scopeDepth + 1)
|
||||
}
|
||||
|
||||
private fun executeIfExpression(conditionResult: LLVMSingleValue, thenExpression: KtExpression, elseExpression: PsiElement?, ifExpression: KtIfExpression, scopeDepth: Int): LLVMVariable? {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
if_boolean_argument_1_Boolean(1) == 11
|
||||
if_boolean_argument_1_Boolean(0) == 411
|
||||
@@ -0,0 +1,3 @@
|
||||
fun if_boolean_argument_1(value: Boolean): Int {
|
||||
return if (value) 11 else 411
|
||||
}
|
||||
Reference in New Issue
Block a user