KT-63273: Swift IR passes to support functions with numeric parameters
Merge-request: KT-MR-13290 Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
This commit is contained in:
@@ -27,6 +27,8 @@ sourceSets {
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
testsJar()
|
||||
|
||||
projectTest(jUnitMode = JUnitMode.JUnit5) {
|
||||
workingDir = rootDir
|
||||
useJUnitPlatform { }
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.sir
|
||||
|
||||
sealed interface KotlinEntity
|
||||
|
||||
interface KotlinFunction : KotlinEntity {
|
||||
val fqName: List<String>
|
||||
val parameters: List<KotlinParameter>
|
||||
val returnType: KotlinType
|
||||
}
|
||||
|
||||
interface KotlinParameter : KotlinEntity {
|
||||
val name: String
|
||||
val type: KotlinType
|
||||
}
|
||||
|
||||
interface KotlinType : KotlinEntity {
|
||||
val name: String
|
||||
}
|
||||
@@ -6,15 +6,15 @@
|
||||
package org.jetbrains.kotlin.sir
|
||||
|
||||
sealed interface SirOrigin {
|
||||
sealed interface Synthetic : SirOrigin
|
||||
sealed interface Synthetic : SirOrigin
|
||||
|
||||
data class ExternallyDefined(val name: String) : Synthetic
|
||||
|
||||
data class KotlinEntity(val path: List<String>) : SirOrigin
|
||||
data class ForeignEntity(val entity: KotlinEntity): SirOrigin
|
||||
|
||||
/**
|
||||
* Value for nodes of unknown or non-viable origin
|
||||
* (e.g. objects created in/for tests)
|
||||
*/
|
||||
data object Unknown: SirOrigin
|
||||
}
|
||||
data object Unknown : SirOrigin
|
||||
}
|
||||
|
||||
@@ -10,7 +10,23 @@ sealed interface SirType
|
||||
class SirNominalType(
|
||||
val type: SirNamedDeclaration,
|
||||
val parent: SirNominalType? = null,
|
||||
) : SirType
|
||||
) : SirType {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is SirNominalType) return false
|
||||
|
||||
if (type != other.type) return false
|
||||
if (parent != other.parent) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = type.hashCode()
|
||||
result = 31 * result + (parent?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class SirExistentialType(
|
||||
// TODO: Protocols. For now, only `any Any` is supported
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.sir.constants
|
||||
|
||||
private const val KOTLIN_PACKAGE = "kotlin"
|
||||
private const val DELIMITER = "/"
|
||||
private const val KOTLIN_NUMERIC_TYPE_PREFIX = "${KOTLIN_PACKAGE}${DELIMITER}"
|
||||
|
||||
const val BYTE = "${KOTLIN_NUMERIC_TYPE_PREFIX}Byte"
|
||||
const val SHORT = "${KOTLIN_NUMERIC_TYPE_PREFIX}Short"
|
||||
const val INT = "${KOTLIN_NUMERIC_TYPE_PREFIX}Int"
|
||||
const val LONG = "${KOTLIN_NUMERIC_TYPE_PREFIX}Long"
|
||||
const val BOOLEAN = "${KOTLIN_NUMERIC_TYPE_PREFIX}Boolean"
|
||||
const val DOUBLE = "${KOTLIN_NUMERIC_TYPE_PREFIX}Double"
|
||||
const val FLOAT = "${KOTLIN_NUMERIC_TYPE_PREFIX}Float"
|
||||
@@ -6,6 +6,10 @@
|
||||
package org.jetbrains.kotlin.sir
|
||||
|
||||
import org.jetbrains.kotlin.sir.builder.buildEnum
|
||||
import org.jetbrains.kotlin.sir.constants.BYTE
|
||||
import org.jetbrains.kotlin.sir.mock.MockFunction
|
||||
import org.jetbrains.kotlin.sir.mock.MockKotlinType
|
||||
import org.jetbrains.kotlin.sir.mock.MockParameter
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@@ -22,7 +26,18 @@ class SirTest {
|
||||
|
||||
private fun produceSwiftElement(): Any {
|
||||
return buildEnum {
|
||||
origin = SirOrigin.KotlinEntity(path = listOf("org.me.MyEnum"))
|
||||
origin = SirOrigin.ForeignEntity(
|
||||
MockFunction(
|
||||
fqName = listOf("foo"),
|
||||
parameters = listOf(
|
||||
MockParameter(
|
||||
name = "arg1",
|
||||
type = MockKotlinType(BYTE),
|
||||
)
|
||||
),
|
||||
returnType = MockKotlinType("kotlin/Byte")
|
||||
)
|
||||
)
|
||||
name = "MyEnum"
|
||||
visibility = SirVisibility.PUBLIC
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.sir.mock
|
||||
|
||||
import org.jetbrains.kotlin.sir.KotlinFunction
|
||||
import org.jetbrains.kotlin.sir.KotlinType
|
||||
import org.jetbrains.kotlin.sir.KotlinParameter
|
||||
|
||||
data class MockFunction(
|
||||
override val fqName: List<String>,
|
||||
override val parameters: List<KotlinParameter>,
|
||||
override val returnType: KotlinType,
|
||||
) : KotlinFunction
|
||||
|
||||
data class MockParameter(
|
||||
override val name: String,
|
||||
override val type: KotlinType,
|
||||
) : KotlinParameter
|
||||
|
||||
data class MockKotlinType(
|
||||
override val name: String
|
||||
) : KotlinType
|
||||
Reference in New Issue
Block a user