Add methods from arrays classes in ir builtins map
This commit is contained in:
+9
-9
@@ -14,23 +14,23 @@ data class CompileTimeFunction(val methodName: String, val args: List<String>)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> unaryOperation(
|
||||
methodName: String, receiverType: String, function: (T) -> Any
|
||||
): Pair<CompileTimeFunction, Function1<Any?, Any>> {
|
||||
return CompileTimeFunction(methodName, listOf(receiverType)) to function as Function1<Any?, Any>
|
||||
methodName: String, receiverType: String, function: (T) -> Any?
|
||||
): Pair<CompileTimeFunction, Function1<Any?, Any?>> {
|
||||
return CompileTimeFunction(methodName, listOf(receiverType)) to function as Function1<Any?, Any?>
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T, E> binaryOperation(
|
||||
methodName: String, receiverType: String, parameterType: String, function: (T, E) -> Any
|
||||
): Pair<CompileTimeFunction, Function2<Any?, Any?, Any>> {
|
||||
return CompileTimeFunction(methodName, listOfNotNull(receiverType, parameterType)) to function as Function2<Any?, Any?, Any>
|
||||
methodName: String, receiverType: String, parameterType: String, function: (T, E) -> Any?
|
||||
): Pair<CompileTimeFunction, Function2<Any?, Any?, Any?>> {
|
||||
return CompileTimeFunction(methodName, listOfNotNull(receiverType, parameterType)) to function as Function2<Any?, Any?, Any?>
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T, E, R> ternaryOperation(
|
||||
methodName: String, receiverType: String, firstParameterType: String, secondParameterType: String, function: (T, E, R) -> Any
|
||||
): Pair<CompileTimeFunction, Function3<Any?, Any?, Any?, Any>> {
|
||||
methodName: String, receiverType: String, firstParameterType: String, secondParameterType: String, function: (T, E, R) -> Any?
|
||||
): Pair<CompileTimeFunction, Function3<Any?, Any?, Any?, Any?>> {
|
||||
return CompileTimeFunction(
|
||||
methodName, listOfNotNull(receiverType, firstParameterType, secondParameterType)
|
||||
) to function as Function3<Any?, Any?, Any?, Any>
|
||||
) to function as Function3<Any?, Any?, Any?, Any?>
|
||||
}
|
||||
|
||||
+55
-19
@@ -20,7 +20,7 @@ package org.jetbrains.kotlin.backend.common.interpreter.builtins
|
||||
|
||||
/** This file is generated by org.jetbrains.kotlin.backend.common.interpreter.builtins.GenerateBuiltInsMap.generateMap(). DO NOT MODIFY MANUALLY */
|
||||
|
||||
val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any>>(
|
||||
val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
|
||||
unaryOperation<Boolean>("not", "Boolean") { a -> a.not() },
|
||||
unaryOperation<Boolean>("toString", "Boolean") { a -> a.toString() },
|
||||
unaryOperation<Byte>("toByte", "Byte") { a -> a.toByte() },
|
||||
@@ -94,13 +94,31 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any>>(
|
||||
unaryOperation<Short>("unaryMinus", "Short") { a -> a.unaryMinus() },
|
||||
unaryOperation<Short>("unaryPlus", "Short") { a -> a.unaryPlus() },
|
||||
unaryOperation<String>("length", "String") { a -> a.length },
|
||||
unaryOperation<String>("toString", "String") { a -> a.toString() }
|
||||
unaryOperation<String>("toString", "String") { a -> a.toString() },
|
||||
unaryOperation<Array<Any?>>("size", "Array<T>") { a -> a.size },
|
||||
unaryOperation<Array<Any?>>("iterator", "Array<T>") { a -> a.iterator() },
|
||||
unaryOperation<BooleanArray>("size", "BooleanArray") { a -> a.size },
|
||||
unaryOperation<BooleanArray>("iterator", "BooleanArray") { a -> a.iterator() },
|
||||
unaryOperation<CharArray>("size", "CharArray") { a -> a.size },
|
||||
unaryOperation<CharArray>("iterator", "CharArray") { a -> a.iterator() },
|
||||
unaryOperation<ByteArray>("size", "ByteArray") { a -> a.size },
|
||||
unaryOperation<ByteArray>("iterator", "ByteArray") { a -> a.iterator() },
|
||||
unaryOperation<ShortArray>("size", "ShortArray") { a -> a.size },
|
||||
unaryOperation<ShortArray>("iterator", "ShortArray") { a -> a.iterator() },
|
||||
unaryOperation<IntArray>("size", "IntArray") { a -> a.size },
|
||||
unaryOperation<IntArray>("iterator", "IntArray") { a -> a.iterator() },
|
||||
unaryOperation<FloatArray>("size", "FloatArray") { a -> a.size },
|
||||
unaryOperation<FloatArray>("iterator", "FloatArray") { a -> a.iterator() },
|
||||
unaryOperation<LongArray>("size", "LongArray") { a -> a.size },
|
||||
unaryOperation<LongArray>("iterator", "LongArray") { a -> a.iterator() },
|
||||
unaryOperation<DoubleArray>("size", "DoubleArray") { a -> a.size },
|
||||
unaryOperation<DoubleArray>("iterator", "DoubleArray") { a -> a.iterator() }
|
||||
)
|
||||
|
||||
val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
|
||||
binaryOperation<Boolean, Boolean>("and", "Boolean", "Boolean") { a, b -> a.and(b) },
|
||||
binaryOperation<Boolean, Boolean>("compareTo", "Boolean", "Boolean") { a, b -> a.compareTo(b) },
|
||||
binaryOperation<Boolean, Any>("equals", "Boolean", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Boolean, Any?>("equals", "Boolean", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Boolean, Boolean>("or", "Boolean", "Boolean") { a, b -> a.or(b) },
|
||||
binaryOperation<Boolean, Boolean>("xor", "Boolean", "Boolean") { a, b -> a.xor(b) },
|
||||
binaryOperation<Byte, Byte>("compareTo", "Byte", "Byte") { a, b -> a.compareTo(b) },
|
||||
@@ -115,7 +133,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Byte, Int>("div", "Byte", "Int") { a, b -> a.div(b) },
|
||||
binaryOperation<Byte, Long>("div", "Byte", "Long") { a, b -> a.div(b) },
|
||||
binaryOperation<Byte, Short>("div", "Byte", "Short") { a, b -> a.div(b) },
|
||||
binaryOperation<Byte, Any>("equals", "Byte", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Byte, Any?>("equals", "Byte", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Byte, Byte>("minus", "Byte", "Byte") { a, b -> a.minus(b) },
|
||||
binaryOperation<Byte, Double>("minus", "Byte", "Double") { a, b -> a.minus(b) },
|
||||
binaryOperation<Byte, Float>("minus", "Byte", "Float") { a, b -> a.minus(b) },
|
||||
@@ -145,7 +163,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Byte, Long>("times", "Byte", "Long") { a, b -> a.times(b) },
|
||||
binaryOperation<Byte, Short>("times", "Byte", "Short") { a, b -> a.times(b) },
|
||||
binaryOperation<Char, Char>("compareTo", "Char", "Char") { a, b -> a.compareTo(b) },
|
||||
binaryOperation<Char, Any>("equals", "Char", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Char, Any?>("equals", "Char", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Char, Char>("minus", "Char", "Char") { a, b -> a.minus(b) },
|
||||
binaryOperation<Char, Int>("minus", "Char", "Int") { a, b -> a.minus(b) },
|
||||
binaryOperation<Char, Int>("plus", "Char", "Int") { a, b -> a.plus(b) },
|
||||
@@ -161,7 +179,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Double, Int>("div", "Double", "Int") { a, b -> a.div(b) },
|
||||
binaryOperation<Double, Long>("div", "Double", "Long") { a, b -> a.div(b) },
|
||||
binaryOperation<Double, Short>("div", "Double", "Short") { a, b -> a.div(b) },
|
||||
binaryOperation<Double, Any>("equals", "Double", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Double, Any?>("equals", "Double", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Double, Byte>("minus", "Double", "Byte") { a, b -> a.minus(b) },
|
||||
binaryOperation<Double, Double>("minus", "Double", "Double") { a, b -> a.minus(b) },
|
||||
binaryOperation<Double, Float>("minus", "Double", "Float") { a, b -> a.minus(b) },
|
||||
@@ -198,7 +216,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Float, Int>("div", "Float", "Int") { a, b -> a.div(b) },
|
||||
binaryOperation<Float, Long>("div", "Float", "Long") { a, b -> a.div(b) },
|
||||
binaryOperation<Float, Short>("div", "Float", "Short") { a, b -> a.div(b) },
|
||||
binaryOperation<Float, Any>("equals", "Float", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Float, Any?>("equals", "Float", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Float, Byte>("minus", "Float", "Byte") { a, b -> a.minus(b) },
|
||||
binaryOperation<Float, Double>("minus", "Float", "Double") { a, b -> a.minus(b) },
|
||||
binaryOperation<Float, Float>("minus", "Float", "Float") { a, b -> a.minus(b) },
|
||||
@@ -236,7 +254,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Int, Int>("div", "Int", "Int") { a, b -> a.div(b) },
|
||||
binaryOperation<Int, Long>("div", "Int", "Long") { a, b -> a.div(b) },
|
||||
binaryOperation<Int, Short>("div", "Int", "Short") { a, b -> a.div(b) },
|
||||
binaryOperation<Int, Any>("equals", "Int", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Int, Any?>("equals", "Int", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Int, Byte>("minus", "Int", "Byte") { a, b -> a.minus(b) },
|
||||
binaryOperation<Int, Double>("minus", "Int", "Double") { a, b -> a.minus(b) },
|
||||
binaryOperation<Int, Float>("minus", "Int", "Float") { a, b -> a.minus(b) },
|
||||
@@ -283,7 +301,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Long, Int>("div", "Long", "Int") { a, b -> a.div(b) },
|
||||
binaryOperation<Long, Long>("div", "Long", "Long") { a, b -> a.div(b) },
|
||||
binaryOperation<Long, Short>("div", "Long", "Short") { a, b -> a.div(b) },
|
||||
binaryOperation<Long, Any>("equals", "Long", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Long, Any?>("equals", "Long", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Long, Byte>("minus", "Long", "Byte") { a, b -> a.minus(b) },
|
||||
binaryOperation<Long, Double>("minus", "Long", "Double") { a, b -> a.minus(b) },
|
||||
binaryOperation<Long, Float>("minus", "Long", "Float") { a, b -> a.minus(b) },
|
||||
@@ -329,7 +347,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Short, Int>("div", "Short", "Int") { a, b -> a.div(b) },
|
||||
binaryOperation<Short, Long>("div", "Short", "Long") { a, b -> a.div(b) },
|
||||
binaryOperation<Short, Short>("div", "Short", "Short") { a, b -> a.div(b) },
|
||||
binaryOperation<Short, Any>("equals", "Short", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<Short, Any?>("equals", "Short", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<Short, Byte>("minus", "Short", "Byte") { a, b -> a.minus(b) },
|
||||
binaryOperation<Short, Double>("minus", "Short", "Double") { a, b -> a.minus(b) },
|
||||
binaryOperation<Short, Float>("minus", "Short", "Float") { a, b -> a.minus(b) },
|
||||
@@ -359,9 +377,18 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Short, Long>("times", "Short", "Long") { a, b -> a.times(b) },
|
||||
binaryOperation<Short, Short>("times", "Short", "Short") { a, b -> a.times(b) },
|
||||
binaryOperation<String, String>("compareTo", "String", "String") { a, b -> a.compareTo(b) },
|
||||
binaryOperation<String, Any>("equals", "String", "Any") { a, b -> a.equals(b) },
|
||||
binaryOperation<String, Any?>("equals", "String", "Any?") { a, b -> a.equals(b) },
|
||||
binaryOperation<String, Int>("get", "String", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<String, Any>("plus", "String", "Any") { a, b -> a.plus(b) },
|
||||
binaryOperation<String, Any?>("plus", "String", "Any?") { a, b -> a.plus(b) },
|
||||
binaryOperation<Array<Any?>, Int>("get", "Array<T>", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<BooleanArray, Int>("get", "BooleanArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<CharArray, Int>("get", "CharArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<ByteArray, Int>("get", "ByteArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<ShortArray, Int>("get", "ShortArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<IntArray, Int>("get", "IntArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<FloatArray, Int>("get", "FloatArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<LongArray, Int>("get", "LongArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<DoubleArray, Int>("get", "DoubleArray", "Int") { a, b -> a.get(b) },
|
||||
binaryOperation<Char, Char>("less", "Char", "Char") { a, b -> a < b },
|
||||
binaryOperation<Byte, Byte>("less", "Byte", "Byte") { a, b -> a < b },
|
||||
binaryOperation<Short, Short>("less", "Short", "Short") { a, b -> a < b },
|
||||
@@ -390,14 +417,23 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(
|
||||
binaryOperation<Float, Float>("greaterOrEqual", "Float", "Float") { a, b -> a >= b },
|
||||
binaryOperation<Long, Long>("greaterOrEqual", "Long", "Long") { a, b -> a >= b },
|
||||
binaryOperation<Double, Double>("greaterOrEqual", "Double", "Double") { a, b -> a >= b },
|
||||
binaryOperation<Any, Any>("EQEQ", "Any", "Any") { a, b -> a == b },
|
||||
binaryOperation<Any, Any>("EQEQEQ", "Any", "Any") { a, b -> a === b },
|
||||
binaryOperation<Float, Float>("ieee754equals", "Float", "Float") { a, b -> a == b },
|
||||
binaryOperation<Double, Double>("ieee754equals", "Double", "Double") { a, b -> a == b },
|
||||
binaryOperation<Any?, Any?>("EQEQ", "Any?", "Any?") { a, b -> a == b },
|
||||
binaryOperation<Any?, Any?>("EQEQEQ", "Any?", "Any?") { a, b -> a === b },
|
||||
binaryOperation<Float?, Float?>("ieee754equals", "Float?", "Float?") { a, b -> a == b },
|
||||
binaryOperation<Double?, Double?>("ieee754equals", "Double?", "Double?") { a, b -> a == b },
|
||||
binaryOperation<Boolean, Boolean>("ANDAND", "Boolean", "Boolean") { a, b -> a && b },
|
||||
binaryOperation<Boolean, Boolean>("OROR", "Boolean", "Boolean") { a, b -> a || b }
|
||||
)
|
||||
val ternaryFunctions = mapOf<CompileTimeFunction, Function3<Any?, Any?, Any?, Any>>(
|
||||
ternaryOperation<String, Int, Int>("subSequence", "String", "Int", "Int") { a, b, c -> a.subSequence(b, c) }
|
||||
val ternaryFunctions = mapOf<CompileTimeFunction, Function3<Any?, Any?, Any?, Any?>>(
|
||||
ternaryOperation<String, Int, Int>("subSequence", "String", "Int", "Int") { a, b, c -> a.subSequence(b, c) },
|
||||
ternaryOperation<Array<Any?>, Int, Any?>("set", "Array<T>", "Int", "T") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<BooleanArray, Int, Boolean>("set", "BooleanArray", "Int", "Boolean") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<CharArray, Int, Char>("set", "CharArray", "Int", "Char") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<ByteArray, Int, Byte>("set", "ByteArray", "Int", "Byte") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<ShortArray, Int, Short>("set", "ShortArray", "Int", "Short") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<IntArray, Int, Int>("set", "IntArray", "Int", "Int") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<FloatArray, Int, Float>("set", "FloatArray", "Int", "Float") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<LongArray, Int, Long>("set", "LongArray", "Int", "Long") { a, b, c -> a.set(b, c) },
|
||||
ternaryOperation<DoubleArray, Int, Double>("set", "DoubleArray", "Int", "Double") { a, b, c -> a.set(b, c) }
|
||||
)
|
||||
|
||||
|
||||
@@ -9,10 +9,12 @@ import org.jetbrains.kotlin.backend.common.interpreter.builtins.compileTimeAnnot
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmIdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
@@ -21,11 +23,9 @@ import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
|
||||
@@ -46,9 +46,9 @@ fun generateMap(): String {
|
||||
p.println("/** This file is generated by org.jetbrains.kotlin.backend.common.interpreter.builtins.GenerateBuiltInsMap.generateMap(). DO NOT MODIFY MANUALLY */")
|
||||
p.println()
|
||||
|
||||
val unaryOperationsMap = mutableMapOf<CallableDescriptor, List<KotlinType>>()
|
||||
val binaryOperationsMap = mutableMapOf<CallableDescriptor, List<KotlinType>>()
|
||||
val ternaryOperationsMap = mutableMapOf<CallableDescriptor, List<KotlinType>>()
|
||||
val unaryOperationsMap = mutableMapOf<CallableDescriptor, Pair<String, String>>()
|
||||
val binaryOperationsMap = mutableMapOf<CallableDescriptor, Pair<String, String>>()
|
||||
val ternaryOperationsMap = mutableMapOf<CallableDescriptor, Pair<String, String>>()
|
||||
val builtIns = DefaultBuiltIns.Instance
|
||||
|
||||
//save common built ins
|
||||
@@ -56,26 +56,38 @@ fun generateMap(): String {
|
||||
val allPrimitiveTypes = builtIns.builtInsPackageScope.getContributedDescriptors()
|
||||
.filter { it is ClassDescriptor && KotlinBuiltIns.isPrimitiveType(it.defaultType) } as List<ClassDescriptor>
|
||||
|
||||
for (descriptor in allPrimitiveTypes + builtIns.string) {
|
||||
val arrays = listOf(builtIns.array) + PrimitiveType.values().map { builtIns.getPrimitiveArrayClassDescriptor(it) }
|
||||
|
||||
for (descriptor in allPrimitiveTypes + builtIns.string + arrays) {
|
||||
val typeParameters = descriptor.typeConstructor.parameters.map { it.name.asString() }
|
||||
val typeParametersAsAny = if (typeParameters.isNotEmpty()) typeParameters.joinToString(prefix = "<", postfix = ">") { "Any?" } else ""
|
||||
val descriptorType = descriptor.defaultType
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val functions = descriptor.getMemberScope(listOf()).getContributedDescriptors()
|
||||
.filter { it is CallableDescriptor && it.annotations.hasAnnotation(compileTimeAnnotation) } as List<CallableDescriptor>
|
||||
.filter {
|
||||
it is CallableDescriptor &&
|
||||
(it as? FunctionDescriptor)?.kind != CallableMemberDescriptor.Kind.FAKE_OVERRIDE &&
|
||||
(it.annotations.hasAnnotation(compileTimeAnnotation) || descriptor.annotations.hasAnnotation(compileTimeAnnotation))
|
||||
} as List<CallableDescriptor>
|
||||
|
||||
for (function in functions) {
|
||||
val parametersTypes = function.valueParameters.map { TypeUtils.makeNotNullable(it.type) } + listOf(descriptorType)
|
||||
val operationArguments = (listOf(descriptorType) + function.valueParameters.map { it.type }).joinToString { "\"" + it + "\"" }
|
||||
|
||||
when (parametersTypes.size) {
|
||||
1 -> unaryOperationsMap[function] = parametersTypes
|
||||
2 -> binaryOperationsMap[function] = parametersTypes
|
||||
3 -> ternaryOperationsMap[function] = parametersTypes
|
||||
val functionTypeParameters = (listOf(descriptorType.constructor.toString() + typeParametersAsAny) +
|
||||
function.valueParameters.map { if (typeParameters.contains(it.type.toString())) "Any?" else it.type.toString() })
|
||||
.joinToString(prefix = "<", postfix = ">")
|
||||
|
||||
when (function.valueParameters.size + 1) { // +1 for receiver
|
||||
1 -> unaryOperationsMap[function] = functionTypeParameters to operationArguments
|
||||
2 -> binaryOperationsMap[function] = functionTypeParameters to operationArguments
|
||||
3 -> ternaryOperationsMap[function] = functionTypeParameters to operationArguments
|
||||
else -> throw IllegalStateException("Couldn't add following method from builtins to operations map: ${function.name} in class ${descriptor.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//save ir built ins
|
||||
val binaryIrOperationsMap = mutableMapOf<CallableDescriptor, List<KotlinType>>()
|
||||
val binaryIrOperationsMap = mutableMapOf<CallableDescriptor, Pair<String, String>>()
|
||||
val irBuiltIns = getIrBuiltIns()
|
||||
val irFunSymbols =
|
||||
(irBuiltIns.lessFunByOperandType.values +
|
||||
@@ -91,33 +103,30 @@ fun generateMap(): String {
|
||||
.filter { it.annotations.hasAnnotation(compileTimeAnnotation) }
|
||||
|
||||
for (function in irFunSymbols) {
|
||||
val parametersTypes = function.valueParameters.map { TypeUtils.makeNotNullable(it.type) }
|
||||
val parametersTypes = function.valueParameters.map { it.type }
|
||||
val operationArguments = parametersTypes.joinToString { "\"" + it + "\"" }
|
||||
val functionTypeParameters = parametersTypes.joinToString(prefix = "<", postfix = ">")
|
||||
|
||||
check(parametersTypes.size == 2) { "Couldn't add following method from ir builtins to operations map: ${function.name}" }
|
||||
binaryIrOperationsMap[function] = parametersTypes
|
||||
binaryIrOperationsMap[function] = functionTypeParameters to operationArguments
|
||||
}
|
||||
|
||||
//save to file
|
||||
p.println("val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any>>(")
|
||||
p.println("val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(")
|
||||
val unaryBody = unaryOperationsMap.entries.joinToString(",\n") { (function, parameters) ->
|
||||
val receiverType = parameters.last().toString()
|
||||
val methodName = "${function.name}"
|
||||
val parentheses = if (function is FunctionDescriptor) "()" else ""
|
||||
" unaryOperation<$receiverType>(\"$methodName\", \"$receiverType\") { a -> a.$methodName$parentheses }"
|
||||
" unaryOperation${parameters.first}(\"$methodName\", ${parameters.second}) { a -> a.$methodName$parentheses }"
|
||||
}
|
||||
p.println(unaryBody)
|
||||
p.println(")")
|
||||
p.println()
|
||||
|
||||
p.println("val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any>>(")
|
||||
p.println("val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(")
|
||||
val binaryBody = binaryOperationsMap.entries.joinToString(",\n", postfix = ",\n") { (function, parameters) ->
|
||||
val receiverType = parameters.last().toString()
|
||||
val parameter = parameters.first().toString()
|
||||
val methodName = "${function.name}"
|
||||
" binaryOperation<$receiverType, $parameter>(\"$methodName\", \"$receiverType\", \"$parameter\") { a, b -> a.$methodName(b) }"
|
||||
" binaryOperation${parameters.first}(\"$methodName\", ${parameters.second}) { a, b -> a.$methodName(b) }"
|
||||
} + binaryIrOperationsMap.entries.joinToString(",\n") { (function, parameters) ->
|
||||
val firstParameterType = parameters.last().toString()
|
||||
val secondParameterType = parameters.first().toString()
|
||||
val methodName = "${function.name}"
|
||||
val methodSymbol = when (methodName) {
|
||||
IrBuiltIns.OperatorNames.LESS -> "<"
|
||||
@@ -131,19 +140,15 @@ fun generateMap(): String {
|
||||
IrBuiltIns.OperatorNames.OROR -> "||"
|
||||
else -> throw UnsupportedOperationException("Unknown ir operation \"$methodName\"")
|
||||
}
|
||||
" binaryOperation<$firstParameterType, $secondParameterType>(\"$methodName\", \"$firstParameterType\", \"$secondParameterType\") { a, b -> a $methodSymbol b }"
|
||||
" binaryOperation${parameters.first}(\"$methodName\", ${parameters.second}) { a, b -> a $methodSymbol b }"
|
||||
}
|
||||
p.println(binaryBody)
|
||||
p.println(")")
|
||||
|
||||
p.println("val ternaryFunctions = mapOf<CompileTimeFunction, Function3<Any?, Any?, Any?, Any>>(")
|
||||
p.println("val ternaryFunctions = mapOf<CompileTimeFunction, Function3<Any?, Any?, Any?, Any?>>(")
|
||||
val ternaryBody = ternaryOperationsMap.entries.joinToString(",\n") { (function, parameters) ->
|
||||
val receiverType = parameters.last().toString()
|
||||
val firstParameter = parameters[0].toString()
|
||||
val secondParameter = parameters[1].toString()
|
||||
val methodName = "${function.name}"
|
||||
" ternaryOperation<$receiverType, $firstParameter, $secondParameter>" +
|
||||
"(\"$methodName\", \"$receiverType\", \"$firstParameter\", \"$secondParameter\") { a, b, c -> a.$methodName(b, c) }"
|
||||
" ternaryOperation${parameters.first}(\"$methodName\", ${parameters.second}) { a, b, c -> a.$methodName(b, c) }"
|
||||
}
|
||||
p.println(ternaryBody)
|
||||
p.println(")")
|
||||
|
||||
Reference in New Issue
Block a user