translator: nested class methods call

This commit is contained in:
e5l
2016-07-20 18:14:09 +03:00
parent bd517508be
commit 622043e2a5
3 changed files with 16 additions and 6 deletions
@@ -106,19 +106,19 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
}
private fun evaluateMemberMethodOrField(receiver: LLVMVariable, selectorName: String, scopeDepth: Int, call: PsiElement): LLVMSingleValue? {
val type = receiver.type as LLVMReferenceType
val clazz = resolveClassOrObjectLocation(type)
val field = clazz.fieldsIndex[selectorName]
if (field != null) {
val result = codeBuilder.getNewVariable(field.type, pointer = 1)
codeBuilder.loadClassField(result, receiver, field.offset)
return result
}
val methodName = clazz.structName + '.' + selectorName.substringBefore('(')
val typePath = type.location.joinToString(".")
val methodName = "${if (typePath.length > 0) "$typePath." else "" }${clazz.structName}.${selectorName.substringBefore('(')}"
val method = clazz.methods[methodName]!!
val returnType = clazz.methods[methodName]!!.returnType!!.type
@@ -133,7 +133,6 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
private fun resolveClassOrObjectLocation(type: LLVMReferenceType): StructCodegen {
if (type.location.size == 0) {
return state.classes[type.type] ?: state.objects[type.type]!!
}
var codegen = state.classes[type.location[0]]!!
@@ -1 +1,2 @@
nested_test_1(1) == 1
nested_test_1(1) == 1
nested_test_2(1) == 1
@@ -2,6 +2,10 @@
class Outer() {
class Nested(var i: Int) {
fun test(): Int {
return 1
}
}
}
@@ -10,4 +14,10 @@ fun nested_test_1(k: Int): Int {
j.i = k
return j.i
}
fun nested_test_2(k: Int): Int {
val j = Outer.Nested(k - 1)
return j.test()
}