diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt index 23134e9f12c..8de6e05dd8e 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt @@ -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(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) diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/ClassCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/ClassCodegen.kt index 7240fbeba7f..fb8731a95fa 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/ClassCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/ClassCodegen.kt @@ -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 diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/StructCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/StructCodegen.kt index 8d0b4eff288..ef9aefda2ca 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/StructCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/StructCodegen.kt @@ -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) diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt index 3354d65ec66..30b7d38bb8a 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt @@ -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 =