translator: fix nested types resolve
This commit is contained in:
@@ -401,9 +401,9 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
}
|
||||
|
||||
if (classScope != null) {
|
||||
val methodShortName = classScope.structName + "." + function
|
||||
if (classScope != null && classScope.methods.containsKey(methodShortName)) {
|
||||
val descriptor = classScope.methods[methodShortName] ?: return null
|
||||
val methodShortName = "${classScope.fullName}.$function"
|
||||
if (classScope.methods.containsKey(methodShortName)) {
|
||||
val descriptor = classScope.methods[methodShortName]!!
|
||||
val parentDescriptor = descriptor.parentCodegen!!
|
||||
val receiver = variableManager[parentDescriptor.fullName]!!
|
||||
val methodFullName = descriptor.name
|
||||
@@ -828,9 +828,6 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
val whenExpression = expr.subjectExpression
|
||||
val kotlinType = state.bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, expr)!!.type!!
|
||||
val expressionType = LLVMMapStandardType(kotlinType)
|
||||
if (state.classes.containsKey(kotlinType.toString())) {
|
||||
(expressionType as LLVMReferenceType).prefix = "class"
|
||||
}
|
||||
|
||||
val targetExpression = evaluateExpression(whenExpression, scopeDepth + 1)!!
|
||||
val resultVariable = codeBuilder.getNewVariable(expressionType, pointer = 1)
|
||||
|
||||
@@ -26,6 +26,11 @@ class ClassCodegen(state: TranslationState,
|
||||
|
||||
init {
|
||||
type = LLVMReferenceType(structName, "class", byRef = true)
|
||||
if (parentCodegen != null) {
|
||||
type.location.addAll(parentCodegen.type.location)
|
||||
type.location.add(parentCodegen.structName)
|
||||
}
|
||||
|
||||
val descriptor = state.bindingContext.get(BindingContext.CLASS, clazz) ?: throw TranslationException()
|
||||
val parameterList = clazz.getPrimaryConstructorParameterList()?.parameters ?: listOf()
|
||||
|
||||
@@ -35,11 +40,6 @@ class ClassCodegen(state: TranslationState,
|
||||
indexFields(parameterList)
|
||||
generateInnerFields(clazz.declarations)
|
||||
|
||||
if (parentCodegen != null) {
|
||||
type.location.addAll(parentCodegen.type.location)
|
||||
type.location.add(parentCodegen.structName)
|
||||
}
|
||||
|
||||
type.size = size
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.kotlinnative.translator
|
||||
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.getSubtypesPredicate
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
||||
@@ -36,7 +35,6 @@ class FunctionCodegen(state: TranslationState,
|
||||
|
||||
returnType = LLVMInstanceOfStandardType("instance", descriptor.returnType!!)
|
||||
if (returnType!!.type is LLVMReferenceType) {
|
||||
(returnType!!.type as LLVMReferenceType).location.addAll(descriptor.returnType!!.getSubtypesPredicate().toString().split(".").dropLast(1))
|
||||
returnType!!.pointer = 2
|
||||
}
|
||||
external = isExternal()
|
||||
@@ -86,13 +84,6 @@ class FunctionCodegen(state: TranslationState,
|
||||
}
|
||||
|
||||
private fun generateDeclaration(this_type: LLVMVariable? = null) {
|
||||
args.forEach {
|
||||
val type = it.type
|
||||
if (type is LLVMReferenceType && state.classes.containsKey(type.type)) {
|
||||
type.prefix = "class"
|
||||
}
|
||||
}
|
||||
|
||||
var actualReturnType: LLVMType = returnType!!.type
|
||||
val actualArgs = ArrayList<LLVMVariable>()
|
||||
|
||||
|
||||
@@ -30,12 +30,13 @@ class ObjectCodegen(state: TranslationState,
|
||||
|
||||
override fun prepareForGenerate() {
|
||||
super.prepareForGenerate()
|
||||
}
|
||||
|
||||
override fun generate() {
|
||||
super.generate()
|
||||
val classInstance = LLVMVariable("object.instance.$fullName", type, objectDeclaration.name, LLVMVariableScope(), pointer = 1)
|
||||
codeBuilder.addGlobalInitialize(classInstance, type)
|
||||
variableManager.addGlobalVariable(fullName, classInstance)
|
||||
}
|
||||
|
||||
override fun generate() {
|
||||
super.generate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.kotlinnative.translator
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.getSubtypesPredicate
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -198,9 +197,6 @@ abstract class StructCodegen(val state: TranslationState,
|
||||
val type = result.type as LLVMReferenceType
|
||||
type.prefix = "class"
|
||||
type.byRef = true
|
||||
|
||||
val location = ktType.getSubtypesPredicate().toString().split(".").dropLast(1)
|
||||
type.location.addAll(location)
|
||||
}
|
||||
|
||||
if (annotations.contains("Plain")) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.kotlinnative.translator.llvm
|
||||
|
||||
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.getSubtypesPredicate
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.nameIfStandardType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
@@ -26,8 +27,13 @@ fun LLVMInstanceOfStandardType(name: String, type: KotlinType, scope: LLVMScope
|
||||
type.toString() == "String" -> LLVMVariable(name, LLVMStringType(0), name, scope)
|
||||
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(), prefix = "class"), name, scope, pointer = 1)
|
||||
type.isMarkedNullable -> LLVMVariable(name, LLVMReferenceType(type.toString().dropLast(1), prefix = "class"), name, scope, pointer = 1)
|
||||
else -> {
|
||||
val refType = LLVMReferenceType(type.toString(), prefix = "class")
|
||||
val result = LLVMVariable(name, refType, name, scope, pointer = 1)
|
||||
refType.location.addAll(type.getSubtypesPredicate().toString().split(".").dropLast(1))
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
fun LLVMMapStandardType(type: KotlinType): LLVMType =
|
||||
|
||||
Reference in New Issue
Block a user