translator: fix enum loading and reference type class

This commit is contained in:
e5l
2016-08-10 11:00:52 +03:00
parent 5b5587869b
commit 986b95dc88
4 changed files with 12 additions and 15 deletions
@@ -20,7 +20,7 @@ import org.kotlinnative.translator.llvm.types.*
import java.util.*
abstract class BlockCodegen(open val state: TranslationState, open val variableManager: VariableManager, open val codeBuilder: LLVMBuilder) {
abstract class BlockCodegen(val state: TranslationState, val variableManager: VariableManager, val codeBuilder: LLVMBuilder) {
val topLevel = 2
var returnType: LLVMVariable? = null
@@ -103,7 +103,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
}
private fun evaluateThisExpression(): LLVMSingleValue? {
return variableManager.get("this")
return variableManager["this"]
}
fun evaluateStringTemplateExpression(expr: KtStringTemplateExpression): LLVMSingleValue? {
@@ -177,16 +177,16 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
is KtBinaryExpression -> evaluateExpression(receiverExpr, scopeDepth) as LLVMVariable
is KtNameReferenceExpression -> {
val referenceContext = state.bindingContext.get(BindingContext.REFERENCE_TARGET, receiverExpr)
variableManager.get(receiverName)
variableManager[receiverName]
when (referenceContext) {
is PropertyDescriptorImpl -> {
val receiverThis = variableManager.get("this")!!
val receiverThis = variableManager["this"]!!
evaluateMemberMethodOrField(receiverThis, receiverName, topLevel, call = null)!! as LLVMVariable
}
else -> variableManager.get(receiverName)
else -> variableManager[receiverName]
}
}
else -> variableManager.get(receiverName)
else -> variableManager[receiverName]
}
if (receiver != null) {
@@ -233,7 +233,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
val fieldName = state.bindingContext.get(BindingContext.REFERENCE_TARGET, expr)!!.name.toString()
val field = classScope!!.companionFieldsIndex[fieldName]
val companionObject = classScope.companionFieldsSource[fieldName]
val receiver = variableManager.get(companionObject!!.fullName)!!
val receiver = variableManager[companionObject!!.fullName]!!
val result = codeBuilder.getNewVariable(field!!.type, pointer = 1)
codeBuilder.loadClassField(result, receiver, field.offset)
@@ -307,7 +307,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
val returnType = clazz.methods[methodName]!!.returnType!!.type
val loadedArgs = loadArgsIfRequired(names, method.args)
val callArgs = mutableListOf<LLVMSingleValue>(pureReceiver)
val callArgs = mutableListOf(pureReceiver)
callArgs.addAll(loadedArgs)
return evaluateFunctionCallExpression(LLVMVariable(methodName, returnType, scope = LLVMVariableScope()), callArgs)
@@ -344,8 +344,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
}
private fun resolveEnumClassField(expr: KtReferenceExpression): LLVMSingleValue {
val field = state.classes[expr.getType(state.bindingContext).toString()]!!.enumFields[expr.text]!!
return codeBuilder.loadAndGetVariable(codeBuilder.loadAndGetVariable(field))
return state.classes[expr.getType(state.bindingContext).toString()]!!.enumFields[expr.text]!!
}
private fun isEnumClassField(expr: KtReferenceExpression): Boolean {
@@ -858,7 +857,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
}
codeBuilder.allocStackVar(reference)
reference.pointer += 1
reference.pointer++
codeBuilder.storeNull(reference)
variableManager.addVariable(identifier, reference, scopeDepth)
@@ -2,7 +2,6 @@ package org.kotlinnative.translator
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.resolve.BindingContext
import org.kotlinnative.translator.exceptions.TranslationException
@@ -1,7 +1,6 @@
package org.kotlinnative.translator
import com.intellij.psi.PsiElement
import jdk.nashorn.internal.ir.Block
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -75,7 +74,7 @@ abstract class StructCodegen(val state: TranslationState,
field.offset = offset
offset++
if ((declaration.initializer != null) && !(this is ObjectCodegen)) {
if ((declaration.initializer != null) && this !is ObjectCodegen) {
initializedFields.put(field, declaration.initializer!!)
}
fields.add(field)
@@ -26,7 +26,7 @@ fun LLVMInstanceOfStandardType(name: String, type: KotlinType, scope: LLVMScope
type.nameIfStandardType.toString() == "Nothing" -> LLVMVariable(name, LLVMNullType(), name, scope)
type.isUnit() -> LLVMVariable("", LLVMVoidType(), name, scope)
type.isMarkedNullable -> LLVMVariable(name, LLVMReferenceType(type.toString().dropLast(1)), name, scope, pointer = 1)
else -> LLVMVariable(name, LLVMReferenceType(type.toString()), name, scope, pointer = 1)
else -> LLVMVariable(name, LLVMReferenceType(type.toString(), prefix = "class"), name, scope, pointer = 1)
}
fun LLVMMapStandardType(type: KotlinType): LLVMType =