translator: fix function extensions for reference classes, fix reference type name resolving
This commit is contained in:
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getFunctionResolvedCallWithAssert
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCallWithAssert
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses
|
||||
@@ -189,6 +190,12 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
else -> variableManager[receiverName]
|
||||
}
|
||||
|
||||
val isExtension = selectorExpr is KtCallExpression && selectorExpr.getFunctionResolvedCallWithAssert(state.bindingContext).extensionReceiver != null
|
||||
|
||||
if (isExtension) {
|
||||
return evaluateExtensionExpression(receiverExpr, selectorExpr as KtCallExpression, scopeDepth)
|
||||
}
|
||||
|
||||
if (receiver != null) {
|
||||
if (receiver.pointer == 2) {
|
||||
receiver = codeBuilder.loadAndGetVariable(receiver)
|
||||
@@ -259,7 +266,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
val names = parseArgList(call!! as KtCallExpression, scopeDepth)
|
||||
val typePath = type.location.joinToString(".")
|
||||
val types = if (names.size > 0) "_${names.joinToString(separator = "_", transform = { it.type!!.mangle() })}" else ""
|
||||
val methodName = "${if (typePath.length > 0) "$typePath." else ""}${clazz.structName}.${selectorName.substringBefore('(')}$types"
|
||||
val methodName = "${if (typePath.length > 0) "$typePath." else ""}${clazz.structName}.${selectorName.substringBefore('(').trim()}$types"
|
||||
|
||||
val method = clazz.methods[methodName] ?: throw UnexpectedException(methodName)
|
||||
val returnType = clazz.methods[methodName]!!.returnType!!.type
|
||||
|
||||
@@ -44,7 +44,7 @@ class FunctionCodegen(state: TranslationState,
|
||||
if (isExtensionDeclaration) {
|
||||
val receiverType = descriptor.extensionReceiverParameter!!.type
|
||||
val translatorType = LLVMMapStandardType(receiverType)
|
||||
functionNamePrefix += translatorType.toString() + "."
|
||||
functionNamePrefix += translatorType.typename + "."
|
||||
|
||||
val extensionFunctionsOfThisType = state.extensionFunctions.getOrDefault(translatorType.toString(), HashMap())
|
||||
extensionFunctionsOfThisType.put(name, this)
|
||||
@@ -105,7 +105,11 @@ class FunctionCodegen(state: TranslationState,
|
||||
val receiverType = receiverParameter.type
|
||||
val translatorType = LLVMMapStandardType(receiverType)
|
||||
|
||||
val classVal = LLVMVariable("classvariable.this", translatorType, pointer = 0)
|
||||
val classVal = when (translatorType) {
|
||||
is LLVMReferenceType -> LLVMVariable("classvariable.this", translatorType, pointer = 1)
|
||||
else -> LLVMVariable("type", translatorType, pointer = 0)
|
||||
}
|
||||
|
||||
variableManager.addVariable("this", classVal, 0)
|
||||
actualArgs.add(classVal)
|
||||
}
|
||||
|
||||
+2
-2
@@ -62,8 +62,8 @@ class LLVMBooleanType() : LLVMType() {
|
||||
override val defaultValue = "0"
|
||||
override fun isPrimitive() = true
|
||||
|
||||
override fun toString() = "i1"
|
||||
override fun hashCode(): Int{
|
||||
override val typename = "i1"
|
||||
override fun hashCode(): Int {
|
||||
var result = align
|
||||
result = 31 * result + size
|
||||
result = 31 * result + defaultValue.hashCode()
|
||||
|
||||
@@ -30,10 +30,10 @@ class LLVMByteType() : LLVMType() {
|
||||
|
||||
override val align = 1
|
||||
override var size: Int = 1
|
||||
override fun toString(): String = "i8"
|
||||
override val typename = "i8"
|
||||
override val defaultValue = "0"
|
||||
override fun isPrimitive() = true
|
||||
override fun hashCode(): Int{
|
||||
override fun hashCode(): Int {
|
||||
var result = align
|
||||
result = 31 * result + size
|
||||
result = 31 * result + defaultValue.hashCode()
|
||||
|
||||
@@ -30,10 +30,10 @@ class LLVMCharType() : LLVMType() {
|
||||
|
||||
override val align = 1
|
||||
override var size: Int = 1
|
||||
override fun toString(): String = "i8"
|
||||
override val typename = "i8"
|
||||
override val defaultValue = "0"
|
||||
override fun isPrimitive() = true
|
||||
override fun hashCode(): Int{
|
||||
override fun hashCode(): Int {
|
||||
var result = align
|
||||
result = 31 * result + size
|
||||
result = 31 * result + defaultValue.hashCode()
|
||||
|
||||
@@ -26,10 +26,10 @@ class LLVMDoubleType() : LLVMType() {
|
||||
|
||||
override val align = 8
|
||||
override var size: Int = 8
|
||||
override fun toString() = "double"
|
||||
override val typename = "double"
|
||||
override val defaultValue = "0.0"
|
||||
override fun isPrimitive() = true
|
||||
override fun hashCode(): Int{
|
||||
override fun hashCode(): Int {
|
||||
var result = align
|
||||
result = 31 * result + size
|
||||
result = 31 * result + defaultValue.hashCode()
|
||||
|
||||
@@ -26,10 +26,10 @@ class LLVMFloatType() : LLVMType() {
|
||||
override var size: Int = 4
|
||||
|
||||
override fun mangle() = "Float"
|
||||
override fun toString() = "float"
|
||||
override val typename = "float"
|
||||
override val defaultValue = "0.0"
|
||||
override fun isPrimitive() = true
|
||||
override fun hashCode(): Int{
|
||||
override fun hashCode(): Int {
|
||||
var result = align
|
||||
result = 31 * result + size
|
||||
result = 31 * result + defaultValue.hashCode()
|
||||
|
||||
@@ -28,4 +28,5 @@ class LLVMFunctionType(type: KotlinType) : LLVMType() {
|
||||
override fun toString(): String =
|
||||
"${returnType.type} (${arguments.map { it.getType() }.joinToString()})"
|
||||
|
||||
override val typename = "FunctionType"
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class LLVMIntType() : LLVMType() {
|
||||
override var size: Int = 4
|
||||
override val defaultValue = "0"
|
||||
|
||||
override fun toString() = "i32"
|
||||
override val typename = "i32"
|
||||
override fun isPrimitive() = true
|
||||
override fun hashCode(): Int{
|
||||
var result = align
|
||||
|
||||
@@ -74,9 +74,9 @@ class LLVMLongType() : LLVMType() {
|
||||
override val defaultValue = "0"
|
||||
|
||||
override fun mangle() = "Long"
|
||||
override fun toString() = "i64"
|
||||
override val typename = "i64"
|
||||
override fun isPrimitive() = true
|
||||
override fun hashCode(): Int{
|
||||
override fun hashCode(): Int {
|
||||
var result = align
|
||||
result = 31 * result + size
|
||||
result = 31 * result + defaultValue.hashCode()
|
||||
|
||||
@@ -6,4 +6,6 @@ class LLVMNullType() : LLVMType() {
|
||||
override val defaultValue: String = "0"
|
||||
|
||||
override fun mangle() = ""
|
||||
|
||||
override val typename = ""
|
||||
}
|
||||
|
||||
+6
-3
@@ -9,9 +9,12 @@ class LLVMReferenceType(val type: String, var prefix: String = "", override val
|
||||
override val defaultValue: String = ""
|
||||
|
||||
override var size: Int = 4
|
||||
override fun toString() = "%$prefix${if (prefix.length > 0) "." else ""}${
|
||||
if (location.size > 0) "${location.joinToString(".")}." else ""
|
||||
}$type"
|
||||
override val typename: String
|
||||
get() = "$prefix${if (prefix.length > 0) "." else ""}${
|
||||
if (location.size > 0) "${location.joinToString(".")}." else ""
|
||||
}$type"
|
||||
|
||||
override fun toString() = "%$typename"
|
||||
|
||||
private val params = ArrayList<String>()
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ class LLVMShortType() : LLVMType() {
|
||||
override val defaultValue = "0"
|
||||
|
||||
override fun mangle() = "Short"
|
||||
override fun toString(): String = "i16"
|
||||
override val typename = "i16"
|
||||
override fun isPrimitive() = true
|
||||
override fun hashCode(): Int{
|
||||
override fun hashCode(): Int {
|
||||
var result = size
|
||||
result = 31 * result + align
|
||||
result = 31 * result + defaultValue.hashCode()
|
||||
|
||||
@@ -9,6 +9,6 @@ class LLVMStringType(override val length: Int) : LLVMArray, LLVMType() {
|
||||
override fun mangle() = "String"
|
||||
|
||||
override fun basicType() = LLVMCharType()
|
||||
override fun toString(): String = "i8*"
|
||||
override val typename = "i8*"
|
||||
override fun fullType() = "[${length + 1} x i8]"
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ abstract class LLVMType() : Cloneable {
|
||||
abstract fun mangle(): String
|
||||
|
||||
abstract val align: Int
|
||||
abstract val typename: String
|
||||
override fun toString() = typename
|
||||
abstract var size: Int
|
||||
abstract val defaultValue: String
|
||||
open fun isPrimitive(): Boolean = false
|
||||
|
||||
@@ -7,5 +7,5 @@ class LLVMVoidType() : LLVMType() {
|
||||
override val defaultValue = ""
|
||||
|
||||
override fun mangle() = ""
|
||||
override fun toString(): String = "void"
|
||||
override val typename = "void"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user