Add JVM ABI K1/K2 consistency tests
This commit is contained in:
committed by
Space Team
parent
5a1fb78fcd
commit
34bac48541
@@ -13,6 +13,10 @@ private object SpecialCharacters {
|
||||
const val TYPE_ALIAS_MARKER = '^'
|
||||
}
|
||||
|
||||
fun printFunction(function: KmFunction, settings: KotlinpSettings): String {
|
||||
return StringBuilder().also { visitFunction(function, settings, it) }.toString()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContextReceivers::class, ExperimentalContracts::class)
|
||||
private fun visitFunction(
|
||||
function: KmFunction,
|
||||
@@ -153,7 +157,7 @@ private fun visitTypeAlias(
|
||||
sb.appendLine()
|
||||
}
|
||||
|
||||
private fun printType(type: KmType): String {
|
||||
fun printType(type: KmType): String {
|
||||
val classifier = when (val cls = type.classifier) {
|
||||
is KmClassifier.Class -> cls.name
|
||||
is KmClassifier.TypeParameter -> "T#${cls.id}"
|
||||
@@ -221,7 +225,7 @@ private fun printType(type: KmType): String {
|
||||
}
|
||||
}
|
||||
|
||||
private fun printTypeParameter(
|
||||
fun printTypeParameter(
|
||||
typeParameter: KmTypeParameter,
|
||||
settings: KotlinpSettings
|
||||
): String = buildString {
|
||||
@@ -241,7 +245,7 @@ private fun printTypeParameter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun printValueParameter(
|
||||
fun printValueParameter(
|
||||
valueParameter: KmValueParameter
|
||||
): String {
|
||||
val type = printType(valueParameter.type)
|
||||
@@ -259,7 +263,7 @@ private fun printValueParameter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderAnnotation(annotation: KmAnnotation): String =
|
||||
fun renderAnnotation(annotation: KmAnnotation): String =
|
||||
annotation.className + if (annotation.arguments.isEmpty()) "" else
|
||||
annotation.arguments.entries.joinToString(prefix = "(", postfix = ")") { (name, argument) ->
|
||||
"$name = ${renderAnnotationArgument(argument)}"
|
||||
@@ -313,7 +317,7 @@ private fun String.sanitize(quote: Char): String =
|
||||
}
|
||||
}
|
||||
|
||||
private fun printVersionRequirement(versionRequirement: KmVersionRequirement): String {
|
||||
fun printVersionRequirement(versionRequirement: KmVersionRequirement): String {
|
||||
val version = with(versionRequirement.version) { "$major.$minor.$patch" }
|
||||
|
||||
return buildString {
|
||||
@@ -363,7 +367,7 @@ private fun <T, R : Comparable<R>> Iterable<T>.sortIfNeededBy(settings: KotlinpS
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
private fun printContract(kmContract: KmContract): String = buildString {
|
||||
fun printContract(kmContract: KmContract): String = buildString {
|
||||
appendLine("contract {")
|
||||
kmContract.effects.map(::printEffect).forEach { effect ->
|
||||
appendLine(" $effect")
|
||||
@@ -746,7 +750,7 @@ private fun StringBuilder.appendClassModifiers(kmClass: KmClass) {
|
||||
append(CLASS_KIND_MAP[kmClass.kind])
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendConstructorModifiers(kmConstructor: KmConstructor) {
|
||||
fun printConstructorModifiers(kmConstructor: KmConstructor) = buildString {
|
||||
append(VISIBILITY_MAP[kmConstructor.visibility])
|
||||
appendFlags(
|
||||
kmConstructor.isSecondary to "/* secondary */",
|
||||
@@ -754,7 +758,11 @@ private fun StringBuilder.appendConstructorModifiers(kmConstructor: KmConstructo
|
||||
)
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendFunctionModifiers(kmFunction: KmFunction) {
|
||||
private fun StringBuilder.appendConstructorModifiers(kmConstructor: KmConstructor) {
|
||||
append(printConstructorModifiers(kmConstructor))
|
||||
}
|
||||
|
||||
fun printFunctionModifiers(kmFunction: KmFunction) = buildString {
|
||||
append(VISIBILITY_MAP[kmFunction.visibility])
|
||||
append(MODALITY_MAP[kmFunction.modality])
|
||||
append(MEMBER_KIND_MAP[kmFunction.kind])
|
||||
@@ -770,7 +778,11 @@ private fun StringBuilder.appendFunctionModifiers(kmFunction: KmFunction) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendPropertyModifiers(kmProperty: KmProperty) {
|
||||
private fun StringBuilder.appendFunctionModifiers(kmFunction: KmFunction) {
|
||||
append(printFunctionModifiers(kmFunction))
|
||||
}
|
||||
|
||||
fun printPropertyModifiers(kmProperty: KmProperty) = buildString {
|
||||
append(VISIBILITY_MAP[kmProperty.visibility])
|
||||
append(MODALITY_MAP[kmProperty.modality])
|
||||
append(MEMBER_KIND_MAP[kmProperty.kind])
|
||||
@@ -783,7 +795,11 @@ private fun StringBuilder.appendPropertyModifiers(kmProperty: KmProperty) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendPropertyAccessorModifiers(accessorAttributes: KmPropertyAccessorAttributes) {
|
||||
private fun StringBuilder.appendPropertyModifiers(kmProperty: KmProperty) {
|
||||
append(printPropertyModifiers(kmProperty))
|
||||
}
|
||||
|
||||
fun printPropertyAccessorModifiers(accessorAttributes: KmPropertyAccessorAttributes) = buildString {
|
||||
append(VISIBILITY_MAP[accessorAttributes.visibility])
|
||||
append(MODALITY_MAP[accessorAttributes.modality])
|
||||
appendFlags(
|
||||
@@ -793,6 +809,10 @@ private fun StringBuilder.appendPropertyAccessorModifiers(accessorAttributes: Km
|
||||
)
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendPropertyAccessorModifiers(accessorAttributes: KmPropertyAccessorAttributes) {
|
||||
append(printPropertyAccessorModifiers(accessorAttributes))
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendValueParameterModifiers(valueParameter: KmValueParameter) = appendFlags(
|
||||
valueParameter.isCrossinline to "crossinline",
|
||||
valueParameter.isNoinline to "noinline"
|
||||
|
||||
@@ -10,12 +10,14 @@ import org.jetbrains.org.objectweb.asm.*
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
internal fun File.readKotlinClassHeader(): Metadata? {
|
||||
internal fun File.readKotlinClassHeader(): Metadata? = ClassReader(FileInputStream(this)).readKotlinClassHeader()
|
||||
|
||||
fun ClassReader.readKotlinClassHeader(): Metadata? {
|
||||
var header: Metadata? = null
|
||||
|
||||
try {
|
||||
val metadataDesc = Type.getDescriptor(Metadata::class.java)
|
||||
ClassReader(FileInputStream(this)).accept(object : ClassVisitor(Opcodes.API_VERSION) {
|
||||
accept(object : ClassVisitor(Opcodes.API_VERSION) {
|
||||
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? =
|
||||
if (desc == metadataDesc) readMetadataVisitor { header = it }
|
||||
else null
|
||||
|
||||
Reference in New Issue
Block a user