translator: fixes for method calls, class return, this arg
This commit is contained in:
@@ -36,6 +36,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
||||
is KtBinaryExpression -> evaluateBinaryExpression(expr, scopeDepth)
|
||||
is KtCallExpression -> evaluateCallExpression(expr, scopeDepth)
|
||||
is KtDoWhileExpression -> evaluateDoWhileExpression(expr.firstChild, scopeDepth + 1)
|
||||
is KtDotQualifiedExpression -> evaluateDotExpression(expr, scopeDepth)
|
||||
is PsiElement -> evaluateExpression(expr.firstChild, scopeDepth + 1)
|
||||
null -> {
|
||||
variableManager.pullUpwardsLevel(scopeDepth)
|
||||
@@ -60,9 +61,9 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
||||
is KtConstantExpression -> evaluateConstantExpression(expr)
|
||||
is KtCallExpression -> evaluateCallExpression(expr, scopeDepth)
|
||||
is KtCallableReferenceExpression -> evaluateCallableReferenceExpression(expr)
|
||||
is KtDotQualifiedExpression -> evaluateDotExpression(expr, scopeDepth)
|
||||
is KtReferenceExpression -> evaluateReferenceExpression(expr, scopeDepth)
|
||||
is KtIfExpression -> evaluateIfOperator(expr.firstChild as LeafPsiElement, scopeDepth + 1, true)
|
||||
is KtDotQualifiedExpression -> evaluateDotExpression(expr, scopeDepth)
|
||||
is KtStringTemplateExpression -> evaluateStringTemplateExpression(expr)
|
||||
is PsiWhiteSpace -> null
|
||||
is PsiElement -> evaluatePsiElement(expr, scopeDepth)
|
||||
@@ -102,12 +103,14 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
||||
val methodName = clazz.structName + '.' + selectorName.substringBefore('(')
|
||||
val method = clazz.methods[methodName]!!
|
||||
val returnType = clazz.methods[methodName]!!.returnType!!.type
|
||||
val methodArgs = mutableListOf<LLVMSingleValue>(receiver)
|
||||
|
||||
val names = parseArgList(expr.lastChild as KtCallExpression, scopeDepth)
|
||||
methodArgs.addAll(names)
|
||||
val loadedArgs = loadArgsIfRequired(names, method.args)
|
||||
val callArgs = mutableListOf<LLVMSingleValue>(receiver)
|
||||
callArgs.addAll(loadedArgs)
|
||||
|
||||
return evaluateFunctionCallExpression(LLVMVariable(methodName, returnType, scope = LLVMVariableScope()), loadArgsIfRequired(methodArgs, method.args))
|
||||
|
||||
return evaluateFunctionCallExpression(LLVMVariable(methodName, returnType, scope = LLVMVariableScope()), callArgs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ import org.kotlinnative.translator.llvm.types.LLVMVoidType
|
||||
import java.util.*
|
||||
|
||||
|
||||
class FunctionCodegen(override val state: TranslationState, override val variableManager: VariableManager, val function: KtNamedFunction, override val codeBuilder: LLVMBuilder) :
|
||||
class FunctionCodegen(override val state: TranslationState, override val variableManager: VariableManager, val function: KtNamedFunction,
|
||||
override val codeBuilder: LLVMBuilder) :
|
||||
BlockCodegen(state, variableManager, codeBuilder) {
|
||||
|
||||
var name = function.fqName.toString()
|
||||
@@ -23,6 +24,7 @@ class FunctionCodegen(override val state: TranslationState, override val variabl
|
||||
LLVMMapStandardType(it.name.toString(), it.type)
|
||||
})
|
||||
|
||||
|
||||
returnType = LLVMMapStandardType("instance", descriptor.returnType!!)
|
||||
val retType = returnType!!.type
|
||||
when (retType) {
|
||||
@@ -57,9 +59,6 @@ class FunctionCodegen(override val state: TranslationState, override val variabl
|
||||
private fun generateDeclaration(this_type: LLVMVariable? = null): Boolean {
|
||||
var external = false
|
||||
|
||||
if (this_type != null) {
|
||||
args.addFirst(this_type)
|
||||
}
|
||||
args.forEach {
|
||||
val type = it.type
|
||||
if (type is LLVMReferenceType && state.classes.containsKey(type.type)) {
|
||||
@@ -85,6 +84,10 @@ class FunctionCodegen(override val state: TranslationState, override val variabl
|
||||
actualArgs.add(returnType!!)
|
||||
}
|
||||
|
||||
if (this_type != null) {
|
||||
actualArgs.add(this_type)
|
||||
}
|
||||
|
||||
actualArgs.addAll(args)
|
||||
|
||||
codeBuilder.addLLVMCode(LLVMFunctionDescriptor(function.fqName.toString(), actualArgs, actualReturnType, external, state.arm))
|
||||
|
||||
Reference in New Issue
Block a user