FIR: rewrite evaluator to use eval utils in frontend.common
This commit is contained in:
@@ -4,7 +4,8 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile(project(":compiler:fir:tree"))
|
implementation(project(":compiler:fir:tree"))
|
||||||
|
implementation(project(":compiler:frontend.common"))
|
||||||
|
|
||||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core", rootProject = rootProject) }
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core", rootProject = rootProject) }
|
||||||
}
|
}
|
||||||
|
|||||||
+95
-91
@@ -13,8 +13,10 @@ import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
|||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
|
import org.jetbrains.kotlin.fir.types.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitIntTypeRef
|
import org.jetbrains.kotlin.resolve.constants.evaluate.CompileTimeType
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.evaluate.evalBinaryOp
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.evaluate.evalUnaryOp
|
||||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,48 +33,24 @@ class FirCompileTimeConstantEvaluator {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Rework to handle nested expressions
|
||||||
|
// This is no longer used during FIR2IR where an inner expression is recursively rewritten to ConstExpression if possible.
|
||||||
|
// Maybe rewrite this to a recursive version with caching either here or in provider.
|
||||||
private fun evaluate(functionCall: FirFunctionCall): FirConstExpression<*>? {
|
private fun evaluate(functionCall: FirFunctionCall): FirConstExpression<*>? {
|
||||||
if (!functionCall.isNumericOperatorCall) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
val function = functionCall.getOriginalFunction()!! as FirSimpleFunction
|
val function = functionCall.getOriginalFunction()!! as FirSimpleFunction
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
val opr1 = functionCall.explicitReceiver as? FirConstExpression<*> ?: return null
|
||||||
val opr1 = functionCall.explicitReceiver!! as FirConstExpression<out Number>
|
opr1.evaluate(function)?.let {
|
||||||
if (function.name.asString() in unaryOperatorNames) {
|
return it.adjustType(functionCall.typeRef)
|
||||||
opr1.evaluate(function)?.let {
|
|
||||||
return it.adjustType(functionCall.typeRef)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
assert(function.name.asString() in binaryOperatorNames) {
|
|
||||||
"Inconsistency in isNumericOperatorCall and operator names: ${function.name.asString()}."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
val opr2 = functionCall.argument as? FirConstExpression<*> ?: return null
|
||||||
val opr2 = functionCall.argument as FirConstExpression<out Number>
|
|
||||||
opr1.evaluate(function, opr2)?.let {
|
opr1.evaluate(function, opr2)?.let {
|
||||||
return it.adjustType(functionCall.typeRef)
|
return it.adjustType(functionCall.typeRef)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private val FirFunctionCall.isNumericOperatorCall: Boolean
|
|
||||||
get() {
|
|
||||||
val function = getOriginalFunction() ?: return false
|
|
||||||
return typeRef.toConstantValueKind() != null &&
|
|
||||||
// LHS is const expression with numeric constant value.
|
|
||||||
explicitReceiver != null && explicitReceiver!!.isNumericConst &&
|
|
||||||
function is FirSimpleFunction &&
|
|
||||||
// Either unary operator (which doesn't need RHS) or RHS is also const expression with numeric constant value.
|
|
||||||
((function.name.asString() in unaryOperatorNames && arguments.isEmpty()) ||
|
|
||||||
(function.name.asString() in binaryOperatorNames && arguments.size == 1 && argument.isNumericConst))
|
|
||||||
}
|
|
||||||
|
|
||||||
private val FirExpression.isNumericConst: Boolean
|
|
||||||
get() =
|
|
||||||
this is FirConstExpression<*> && typedValue is Number
|
|
||||||
|
|
||||||
private fun FirConstExpression<*>.adjustType(expectedType: FirTypeRef): FirConstExpression<*> {
|
private fun FirConstExpression<*>.adjustType(expectedType: FirTypeRef): FirConstExpression<*> {
|
||||||
val expectedKind = expectedType.toConstantValueKind()
|
val expectedKind = expectedType.toConstantValueKind()
|
||||||
// Note that the resolved type for the const expression is not always matched with the const kind. For example,
|
// Note that the resolved type for the const expression is not always matched with the const kind. For example,
|
||||||
@@ -84,7 +62,7 @@ class FirCompileTimeConstantEvaluator {
|
|||||||
// After computing the compile time constant, we need to adjust its type here.
|
// After computing the compile time constant, we need to adjust its type here.
|
||||||
val expression =
|
val expression =
|
||||||
if (expectedKind != null && expectedKind != kind && value is Number) {
|
if (expectedKind != null && expectedKind != kind && value is Number) {
|
||||||
val typeAdjustedValue = expectedKind.convert(value as Number)!!
|
val typeAdjustedValue = expectedKind.convertToNumber(value as Number)!!
|
||||||
expectedKind.toConstExpression(source, typeAdjustedValue)
|
expectedKind.toConstExpression(source, typeAdjustedValue)
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
@@ -92,60 +70,79 @@ class FirCompileTimeConstantEvaluator {
|
|||||||
// Lastly, we should preserve the resolved type of the original function call.
|
// Lastly, we should preserve the resolved type of the original function call.
|
||||||
return expression.apply {
|
return expression.apply {
|
||||||
replaceTypeRef(expectedType)
|
replaceTypeRef(expectedType)
|
||||||
|
} ?: this
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> ConstantValueKind<T>.toCompileTimeType(): CompileTimeType {
|
||||||
|
return when (this) {
|
||||||
|
ConstantValueKind.Byte -> CompileTimeType.BYTE
|
||||||
|
ConstantValueKind.Short -> CompileTimeType.SHORT
|
||||||
|
ConstantValueKind.Int -> CompileTimeType.INT
|
||||||
|
ConstantValueKind.Long -> CompileTimeType.LONG
|
||||||
|
ConstantValueKind.Double -> CompileTimeType.DOUBLE
|
||||||
|
ConstantValueKind.Float -> CompileTimeType.FLOAT
|
||||||
|
ConstantValueKind.Char -> CompileTimeType.CHAR
|
||||||
|
ConstantValueKind.Boolean -> CompileTimeType.BOOLEAN
|
||||||
|
ConstantValueKind.String -> CompileTimeType.STRING
|
||||||
|
|
||||||
|
else -> CompileTimeType.ANY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unary operators
|
// Unary operators
|
||||||
private fun FirConstExpression<out Number>.evaluate(function: FirSimpleFunction): FirConstExpression<out Number>? {
|
private fun FirConstExpression<*>.evaluate(function: FirSimpleFunction): FirConstExpression<*>? {
|
||||||
val f = unaryOperations[UnaryOperationKey(kind, function.name.asString())] ?: return null
|
if (value == null) return null
|
||||||
// TODO: need some systematic check, e.g., integer overflow
|
return evalUnaryOp(
|
||||||
return try {
|
function.name.asString(),
|
||||||
val r = f(typedValue)
|
kind.toCompileTimeType(),
|
||||||
r.toConstantValueKind()!!.toConstExpression(source, r)
|
value!!
|
||||||
} catch (e: Exception) {
|
)?.let {
|
||||||
null
|
it.toConstantValueKind()?.toConstExpression(source, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binary operators
|
// Binary operators
|
||||||
private fun FirConstExpression<out Number>.evaluate(
|
private fun FirConstExpression<*>.evaluate(
|
||||||
function: FirSimpleFunction,
|
function: FirSimpleFunction,
|
||||||
other: FirConstExpression<out Number>
|
other: FirConstExpression<*>
|
||||||
): FirConstExpression<out Number>? {
|
): FirConstExpression<*>? {
|
||||||
val f = binaryOperations[BinaryOperationKey(kind, other.kind, function.name.asString())] ?: return null
|
if (value == null || other.value == null) return null
|
||||||
// TODO: need some systematic check, e.g., div by zero (1 / 0 v.s. 1 / 0.f)
|
return evalBinaryOp(
|
||||||
return try {
|
function.name.asString(),
|
||||||
val r = f(typedValue, other.typedValue)
|
kind.toCompileTimeType(),
|
||||||
r.toConstantValueKind()!!.toConstExpression(source, r)
|
value!!,
|
||||||
} catch (e: Exception) {
|
other.kind.toCompileTimeType(),
|
||||||
null
|
other.value!!
|
||||||
|
)?.let {
|
||||||
|
it.toConstantValueKind()?.toConstExpression(source, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////// KINDS
|
////// KINDS
|
||||||
|
|
||||||
private fun FirTypeRef.toConstantValueKind(): ConstantValueKind<out Number>? =
|
private fun FirTypeRef.toConstantValueKind(): ConstantValueKind<*>? =
|
||||||
when (this) {
|
when (this) {
|
||||||
!is FirResolvedTypeRef -> null
|
!is FirResolvedTypeRef -> null
|
||||||
!is FirImplicitBuiltinTypeRef -> type.toConstantValueKind()
|
!is FirImplicitBuiltinTypeRef -> type.toConstantValueKind()
|
||||||
|
|
||||||
|
is FirImplicitByteTypeRef -> ConstantValueKind.Byte
|
||||||
|
is FirImplicitDoubleTypeRef -> ConstantValueKind.Double
|
||||||
|
is FirImplicitFloatTypeRef -> ConstantValueKind.Float
|
||||||
is FirImplicitIntTypeRef -> ConstantValueKind.Int
|
is FirImplicitIntTypeRef -> ConstantValueKind.Int
|
||||||
|
is FirImplicitLongTypeRef -> ConstantValueKind.Long
|
||||||
|
is FirImplicitShortTypeRef -> ConstantValueKind.Short
|
||||||
|
|
||||||
|
is FirImplicitCharTypeRef -> ConstantValueKind.Char
|
||||||
|
is FirImplicitStringTypeRef -> ConstantValueKind.String
|
||||||
|
is FirImplicitBooleanTypeRef -> ConstantValueKind.Boolean
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConeKotlinType.toConstantValueKind(): ConstantValueKind<out Number>? =
|
private fun ConeKotlinType.toConstantValueKind(): ConstantValueKind<*>? =
|
||||||
when (this) {
|
when (this) {
|
||||||
is ConeKotlinErrorType -> null
|
is ConeKotlinErrorType -> null
|
||||||
is ConeLookupTagBasedType -> {
|
is ConeLookupTagBasedType -> lookupTag.name.asString().toConstantValueKind()
|
||||||
when (lookupTag.name.asString()) {
|
|
||||||
"Byte" -> ConstantValueKind.Byte
|
|
||||||
"Double" -> ConstantValueKind.Double
|
|
||||||
"Float" -> ConstantValueKind.Float
|
|
||||||
"Int" -> ConstantValueKind.Int
|
|
||||||
"Long" -> ConstantValueKind.Long
|
|
||||||
"Short" -> ConstantValueKind.Short
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is ConeFlexibleType -> upperBound.toConstantValueKind()
|
is ConeFlexibleType -> upperBound.toConstantValueKind()
|
||||||
is ConeCapturedType -> lowerType?.toConstantValueKind() ?: constructor.supertypes!!.first().toConstantValueKind()
|
is ConeCapturedType -> lowerType?.toConstantValueKind() ?: constructor.supertypes!!.first().toConstantValueKind()
|
||||||
is ConeDefinitelyNotNullType -> original.toConstantValueKind()
|
is ConeDefinitelyNotNullType -> original.toConstantValueKind()
|
||||||
@@ -154,7 +151,23 @@ class FirCompileTimeConstantEvaluator {
|
|||||||
is ConeIntegerLiteralType -> null
|
is ConeIntegerLiteralType -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T : Number> T.toConstantValueKind(): ConstantValueKind<out Number>? =
|
private fun String.toConstantValueKind(): ConstantValueKind<*>? =
|
||||||
|
when (this) {
|
||||||
|
"Byte" -> ConstantValueKind.Byte
|
||||||
|
"Double" -> ConstantValueKind.Double
|
||||||
|
"Float" -> ConstantValueKind.Float
|
||||||
|
"Int" -> ConstantValueKind.Int
|
||||||
|
"Long" -> ConstantValueKind.Long
|
||||||
|
"Short" -> ConstantValueKind.Short
|
||||||
|
|
||||||
|
"Char" -> ConstantValueKind.Char
|
||||||
|
"String" -> ConstantValueKind.String
|
||||||
|
"Boolean" -> ConstantValueKind.Boolean
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T : Any> T.toConstantValueKind(): ConstantValueKind<*>? =
|
||||||
when (this) {
|
when (this) {
|
||||||
is Byte -> ConstantValueKind.Byte
|
is Byte -> ConstantValueKind.Byte
|
||||||
is Double -> ConstantValueKind.Double
|
is Double -> ConstantValueKind.Double
|
||||||
@@ -162,10 +175,15 @@ class FirCompileTimeConstantEvaluator {
|
|||||||
is Int -> ConstantValueKind.Int
|
is Int -> ConstantValueKind.Int
|
||||||
is Long -> ConstantValueKind.Long
|
is Long -> ConstantValueKind.Long
|
||||||
is Short -> ConstantValueKind.Short
|
is Short -> ConstantValueKind.Short
|
||||||
|
|
||||||
|
is Char -> ConstantValueKind.Char
|
||||||
|
is String -> ConstantValueKind.String
|
||||||
|
is Boolean -> ConstantValueKind.Boolean
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConstantValueKind<*>.convert(value: Number?): Number? {
|
private fun ConstantValueKind<*>.convertToNumber(value: Number?): Number? {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -180,30 +198,16 @@ class FirCompileTimeConstantEvaluator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T : Number> ConstantValueKind<T>.toConstExpression(source: FirSourceElement?, value: Number): FirConstExpression<T> =
|
private fun <T> ConstantValueKind<T>?.toConstExpression(source: FirSourceElement?, value: Any): FirConstExpression<T>? =
|
||||||
@Suppress("UNCHECKED_CAST")
|
if (this == null) null else
|
||||||
buildConstExpression(source, this, value as T)
|
@Suppress("UNCHECKED_CAST")
|
||||||
}
|
buildConstExpression(source, this, value as T)
|
||||||
|
|
||||||
val <T> FirConstExpression<T>.typedValue: T
|
private fun FirFunctionCall.getOriginalFunction(): FirCallableDeclaration<*>? {
|
||||||
@Suppress("UNCHECKED_CAST")
|
val symbol: AbstractFirBasedSymbol<*>? = when (val reference = calleeReference) {
|
||||||
get() =
|
is FirResolvedNamedReference -> reference.resolvedSymbol
|
||||||
(value as? Long)?.let {
|
else -> null
|
||||||
when (kind) {
|
}
|
||||||
ConstantValueKind.Byte -> it.toByte()
|
return symbol?.fir as? FirCallableDeclaration<*>
|
||||||
ConstantValueKind.Short -> it.toShort()
|
|
||||||
ConstantValueKind.Int -> it.toInt()
|
|
||||||
ConstantValueKind.Float -> it.toFloat()
|
|
||||||
ConstantValueKind.Double -> it.toDouble()
|
|
||||||
else -> it
|
|
||||||
}
|
|
||||||
} as T ?: value
|
|
||||||
|
|
||||||
fun FirFunctionCall.getOriginalFunction(): FirCallableDeclaration<*>? {
|
|
||||||
val symbol: AbstractFirBasedSymbol<*>? = when (val reference = calleeReference) {
|
|
||||||
is FirResolvedNamedReference -> reference.resolvedSymbol
|
|
||||||
// is FirNamedReferenceWithCandidate -> reference.candidateSymbol
|
|
||||||
else -> null
|
|
||||||
}
|
}
|
||||||
return symbol?.fir as? FirCallableDeclaration<*>
|
|
||||||
}
|
}
|
||||||
|
|||||||
-286
@@ -1,286 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 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.
|
|
||||||
*/
|
|
||||||
@file:Suppress("DEPRECATION", "DEPRECATION_ERROR")
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.fir.evaluate
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
|
||||||
|
|
||||||
/** This file is generated by org.jetbrains.kotlin.generators.evaluate:generateFirMap(). DO NOT MODIFY MANUALLY */
|
|
||||||
|
|
||||||
internal data class UnaryOperationKey<out T>(val opr: ConstantValueKind<out T>, val opName: String)
|
|
||||||
internal data class BinaryOperationKey<out T, out U>(val opr1: ConstantValueKind<out T>, val opr2: ConstantValueKind<out U>, val opName: String)
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
private fun <T> unaryOperation(
|
|
||||||
t: ConstantValueKind<T>,
|
|
||||||
opName: String,
|
|
||||||
operation: Function1<T, Number>
|
|
||||||
) = UnaryOperationKey(t, opName) to operation as Function1<Number, Number>
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
private fun <T, U> binaryOperation(
|
|
||||||
t: ConstantValueKind<T>,
|
|
||||||
u: ConstantValueKind<U>,
|
|
||||||
opName: String,
|
|
||||||
operation: Function2<T, U, Number>
|
|
||||||
) = BinaryOperationKey(t, u, opName) to operation as Function2<Number, Number, Number>
|
|
||||||
|
|
||||||
internal val unaryOperations: HashMap<UnaryOperationKey<*>, Function1<Number, Number>> = hashMapOf(
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "dec", { a -> a.dec() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "hashCode", { a -> a.hashCode() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "inc", { a -> a.inc() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "toByte", { a -> a.toByte() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "toDouble", { a -> a.toDouble() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "toFloat", { a -> a.toFloat() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "toInt", { a -> a.toInt() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "toLong", { a -> a.toLong() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "toShort", { a -> a.toShort() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "unaryMinus", { a -> a.unaryMinus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Byte, "unaryPlus", { a -> a.unaryPlus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "dec", { a -> a.dec() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "hashCode", { a -> a.hashCode() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "inc", { a -> a.inc() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "toByte", { a -> a.toByte() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "toDouble", { a -> a.toDouble() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "toFloat", { a -> a.toFloat() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "toInt", { a -> a.toInt() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "toLong", { a -> a.toLong() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "toShort", { a -> a.toShort() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "unaryMinus", { a -> a.unaryMinus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Double, "unaryPlus", { a -> a.unaryPlus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "dec", { a -> a.dec() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "hashCode", { a -> a.hashCode() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "inc", { a -> a.inc() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "toByte", { a -> a.toByte() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "toDouble", { a -> a.toDouble() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "toFloat", { a -> a.toFloat() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "toInt", { a -> a.toInt() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "toLong", { a -> a.toLong() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "toShort", { a -> a.toShort() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "unaryMinus", { a -> a.unaryMinus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Float, "unaryPlus", { a -> a.unaryPlus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "dec", { a -> a.dec() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "hashCode", { a -> a.hashCode() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "inc", { a -> a.inc() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "inv", { a -> a.inv() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "toByte", { a -> a.toByte() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "toDouble", { a -> a.toDouble() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "toFloat", { a -> a.toFloat() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "toInt", { a -> a.toInt() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "toLong", { a -> a.toLong() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "toShort", { a -> a.toShort() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "unaryMinus", { a -> a.unaryMinus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Int, "unaryPlus", { a -> a.unaryPlus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "dec", { a -> a.dec() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "hashCode", { a -> a.hashCode() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "inc", { a -> a.inc() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "inv", { a -> a.inv() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "toByte", { a -> a.toByte() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "toDouble", { a -> a.toDouble() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "toFloat", { a -> a.toFloat() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "toInt", { a -> a.toInt() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "toLong", { a -> a.toLong() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "toShort", { a -> a.toShort() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "unaryMinus", { a -> a.unaryMinus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Long, "unaryPlus", { a -> a.unaryPlus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "dec", { a -> a.dec() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "hashCode", { a -> a.hashCode() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "inc", { a -> a.inc() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "toByte", { a -> a.toByte() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "toDouble", { a -> a.toDouble() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "toFloat", { a -> a.toFloat() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "toInt", { a -> a.toInt() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "toLong", { a -> a.toLong() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "toShort", { a -> a.toShort() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "unaryMinus", { a -> a.unaryMinus() }),
|
|
||||||
unaryOperation(ConstantValueKind.Short, "unaryPlus", { a -> a.unaryPlus() }),
|
|
||||||
)
|
|
||||||
|
|
||||||
internal val binaryOperations: HashMap<BinaryOperationKey<*, *>, Function2<Number, Number, Number>> = hashMapOf(
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Byte, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Double, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Float, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Int, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Long, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Short, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Byte, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Double, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Float, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Int, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Long, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Short, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Byte, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Double, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Float, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Int, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Long, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Short, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Byte, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Double, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Float, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Int, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Long, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Short, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Byte, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Double, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Float, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Int, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Long, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Byte, ConstantValueKind.Short, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Byte, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Double, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Float, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Int, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Long, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Short, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Byte, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Double, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Float, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Int, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Long, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Short, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Byte, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Double, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Float, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Int, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Long, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Short, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Byte, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Double, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Float, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Int, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Long, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Short, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Byte, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Double, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Float, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Int, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Long, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Double, ConstantValueKind.Short, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Byte, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Double, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Float, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Int, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Long, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Short, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Byte, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Double, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Float, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Int, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Long, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Short, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Byte, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Double, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Float, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Int, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Long, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Short, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Byte, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Double, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Float, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Int, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Long, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Short, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Byte, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Double, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Float, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Int, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Long, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Float, ConstantValueKind.Short, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Byte, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Double, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Float, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Int, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Long, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Short, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Byte, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Double, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Float, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Int, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Long, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Short, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Byte, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Double, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Float, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Int, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Long, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Short, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Byte, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Double, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Float, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Int, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Long, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Short, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Byte, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Double, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Float, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Int, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Long, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Int, ConstantValueKind.Short, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Byte, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Double, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Float, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Int, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Long, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Short, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Byte, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Double, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Float, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Int, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Long, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Short, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Byte, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Double, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Float, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Int, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Long, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Short, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Byte, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Double, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Float, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Int, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Long, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Short, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Byte, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Double, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Float, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Int, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Long, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Long, ConstantValueKind.Short, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Byte, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Double, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Float, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Int, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Long, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Short, "div", { a, b -> a.div(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Byte, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Double, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Float, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Int, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Long, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Short, "minus", { a, b -> a.minus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Byte, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Double, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Float, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Int, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Long, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Short, "plus", { a, b -> a.plus(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Byte, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Double, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Float, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Int, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Long, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Short, "rem", { a, b -> a.rem(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Byte, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Double, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Float, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Int, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Long, "times", { a, b -> a.times(b) }),
|
|
||||||
binaryOperation(ConstantValueKind.Short, ConstantValueKind.Short, "times", { a, b -> a.times(b) }),
|
|
||||||
)
|
|
||||||
|
|
||||||
internal val unaryOperatorNames = unaryOperations.map { it.key.opName }.toHashSet()
|
|
||||||
internal val binaryOperatorNames = binaryOperations.map { it.key.opName }.toHashSet()
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 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.generators.evaluate
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
val FIR_DEST_FILE: File = File("compiler/fir/evaluate/src/org/jetbrains/kotlin/fir/evaluate/FirOperationsMapGenerated.kt")
|
|
||||||
private val EXCLUDED_FUNCTIONS: List<String> = listOf(
|
|
||||||
"not", "toChar", "toString",
|
|
||||||
"and", "or", "xor", "shl", "shr", "ushr",
|
|
||||||
"compareTo", "equals",
|
|
||||||
"rangeTo", "subSequence"
|
|
||||||
)
|
|
||||||
private val EXCLUDED_TYPES: List<String> = listOf("Boolean", "Char", "String")
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
GeneratorsFileUtil.writeFileIfContentChanged(FIR_DEST_FILE, generateFirMap())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun generateFirMap(): String {
|
|
||||||
val sb = StringBuilder()
|
|
||||||
val p = Printer(sb)
|
|
||||||
p.println(File("license/COPYRIGHT_HEADER.txt").readText())
|
|
||||||
p.println("@file:Suppress(\"DEPRECATION\", \"DEPRECATION_ERROR\")")
|
|
||||||
|
|
||||||
p.println(
|
|
||||||
"""
|
|
||||||
|package org.jetbrains.kotlin.fir.evaluate
|
|
||||||
|
|
|
||||||
|import org.jetbrains.kotlin.types.ConstantValueKind
|
|
||||||
|
|
|
||||||
|/** This file is generated by org.jetbrains.kotlin.generators.evaluate:generateFirMap(). DO NOT MODIFY MANUALLY */
|
|
||||||
|
|
|
||||||
|internal data class UnaryOperationKey<out T>(val opr: ConstantValueKind<out T>, val opName: String)
|
|
||||||
|internal data class BinaryOperationKey<out T, out U>(val opr1: ConstantValueKind<out T>, val opr2: ConstantValueKind<out U>, val opName: String)
|
|
||||||
|
|
|
||||||
|@Suppress("UNCHECKED_CAST")
|
|
||||||
|private fun <T> unaryOperation(
|
|
||||||
| t: ConstantValueKind<T>,
|
|
||||||
| opName: String,
|
|
||||||
| operation: Function1<T, Number>
|
|
||||||
|) = UnaryOperationKey(t, opName) to operation as Function1<Number, Number>
|
|
||||||
|
|
|
||||||
|@Suppress("UNCHECKED_CAST")
|
|
||||||
|private fun <T, U> binaryOperation(
|
|
||||||
| t: ConstantValueKind<T>,
|
|
||||||
| u: ConstantValueKind<U>,
|
|
||||||
| opName: String,
|
|
||||||
| operation: Function2<T, U, Number>
|
|
||||||
|) = BinaryOperationKey(t, u, opName) to operation as Function2<Number, Number, Number>
|
|
||||||
""".trimMargin()
|
|
||||||
)
|
|
||||||
p.println()
|
|
||||||
|
|
||||||
val unaryOperationsMap = arrayListOf<Triple<String, List<KotlinType>, Boolean>>()
|
|
||||||
val binaryOperationsMap = arrayListOf<Pair<String, List<KotlinType>>>()
|
|
||||||
populateOperationsMap(unaryOperationsMap, binaryOperationsMap, EXCLUDED_FUNCTIONS)
|
|
||||||
|
|
||||||
p.println("internal val unaryOperations: HashMap<UnaryOperationKey<*>, Function1<Number, Number>> = hashMapOf(")
|
|
||||||
p.pushIndent()
|
|
||||||
p.renderUnaryOperations(unaryOperationsMap)
|
|
||||||
p.popIndent()
|
|
||||||
p.println(")")
|
|
||||||
p.println()
|
|
||||||
|
|
||||||
p.println("internal val binaryOperations: HashMap<BinaryOperationKey<*, *>, Function2<Number, Number, Number>> = hashMapOf(")
|
|
||||||
p.pushIndent()
|
|
||||||
p.renderBinaryOperations(binaryOperationsMap)
|
|
||||||
p.popIndent()
|
|
||||||
p.println(")")
|
|
||||||
p.println()
|
|
||||||
|
|
||||||
p.println(
|
|
||||||
"""
|
|
||||||
|internal val unaryOperatorNames = unaryOperations.map { it.key.opName }.toHashSet()
|
|
||||||
|internal val binaryOperatorNames = binaryOperations.map { it.key.opName }.toHashSet()
|
|
||||||
""".trimMargin()
|
|
||||||
)
|
|
||||||
|
|
||||||
return sb.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Printer.renderUnaryOperations(unaryOperationsMap: List<Triple<String, List<KotlinType>, Boolean>>) {
|
|
||||||
val unaryOperationsMapIterator = unaryOperationsMap.iterator()
|
|
||||||
while (unaryOperationsMapIterator.hasNext()) {
|
|
||||||
val (funcName, parameters, isFunction) = unaryOperationsMapIterator.next()
|
|
||||||
if (parameters.first().constructor.declarationDescriptor!!.name.asString() in EXCLUDED_TYPES) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val parenthesesOrBlank = if (isFunction) "()" else ""
|
|
||||||
this.println(
|
|
||||||
"unaryOperation(",
|
|
||||||
parameters.joinToString(", ") { it.asString() },
|
|
||||||
", ",
|
|
||||||
"\"$funcName\"",
|
|
||||||
", { a -> a.$funcName$parenthesesOrBlank })",
|
|
||||||
if (unaryOperationsMapIterator.hasNext()) "," else ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Printer.renderBinaryOperations(binaryOperationsMap: List<Pair<String, List<KotlinType>>>) {
|
|
||||||
val binaryOperationsMapIterator = binaryOperationsMap.iterator()
|
|
||||||
while (binaryOperationsMapIterator.hasNext()) {
|
|
||||||
val (funcName, parameters) = binaryOperationsMapIterator.next()
|
|
||||||
if (parameters.first().constructor.declarationDescriptor!!.name.asString() in EXCLUDED_TYPES) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
this.println(
|
|
||||||
"binaryOperation(",
|
|
||||||
parameters.joinToString(", ") { it.asString() },
|
|
||||||
", ",
|
|
||||||
"\"$funcName\"",
|
|
||||||
", { a, b -> a.$funcName(b) })",
|
|
||||||
if (binaryOperationsMapIterator.hasNext()) "," else ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun KotlinType.asString(): String = "ConstantValueKind." + constructor.declarationDescriptor!!.name.asString()
|
|
||||||
@@ -7,9 +7,12 @@ package org.jetbrains.kotlin.generators.evaluate
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
|
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -37,7 +40,6 @@ fun generate(): String {
|
|||||||
|
|
||||||
val unaryOperationsMap = arrayListOf<Triple<String, List<KotlinType>, Boolean>>()
|
val unaryOperationsMap = arrayListOf<Triple<String, List<KotlinType>, Boolean>>()
|
||||||
val binaryOperationsMap = arrayListOf<Pair<String, List<KotlinType>>>()
|
val binaryOperationsMap = arrayListOf<Pair<String, List<KotlinType>>>()
|
||||||
populateOperationsMap(unaryOperationsMap, binaryOperationsMap, EXCLUDED_FUNCTIONS)
|
|
||||||
|
|
||||||
val builtIns = DefaultBuiltIns.Instance
|
val builtIns = DefaultBuiltIns.Instance
|
||||||
|
|
||||||
@@ -48,6 +50,24 @@ fun generate(): String {
|
|||||||
val integerTypes = allPrimitiveTypes.map { it.defaultType }.filter { it.isIntegerType() }
|
val integerTypes = allPrimitiveTypes.map { it.defaultType }.filter { it.isIntegerType() }
|
||||||
val fpTypes = allPrimitiveTypes.map { it.defaultType }.filter { it.isFpType() }
|
val fpTypes = allPrimitiveTypes.map { it.defaultType }.filter { it.isFpType() }
|
||||||
|
|
||||||
|
for (descriptor in allPrimitiveTypes + builtIns.string) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val functions = descriptor.getMemberScope(listOf()).getContributedDescriptors()
|
||||||
|
.filter { it is CallableDescriptor && !EXCLUDED_FUNCTIONS.contains(it.getName().asString()) } as List<CallableDescriptor>
|
||||||
|
|
||||||
|
for (function in functions) {
|
||||||
|
val parametersTypes = function.getParametersTypes()
|
||||||
|
|
||||||
|
when (parametersTypes.size) {
|
||||||
|
1 -> unaryOperationsMap.add(Triple(function.name.asString(), parametersTypes, function is FunctionDescriptor))
|
||||||
|
2 -> binaryOperationsMap.add(function.name.asString() to parametersTypes)
|
||||||
|
else -> throw IllegalStateException(
|
||||||
|
"Couldn't add following method from builtins to operations map: ${function.name} in class ${descriptor.name}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unaryOperationsMap.add(Triple("code", listOf(builtIns.charType), false))
|
unaryOperationsMap.add(Triple("code", listOf(builtIns.charType), false))
|
||||||
|
|
||||||
for (type in integerTypes) {
|
for (type in integerTypes) {
|
||||||
@@ -165,6 +185,10 @@ private fun KotlinType.isIntegerType(): Boolean =
|
|||||||
private fun KotlinType.isFpType(): Boolean =
|
private fun KotlinType.isFpType(): Boolean =
|
||||||
KotlinBuiltIns.isDouble(this) || KotlinBuiltIns.isFloat(this)
|
KotlinBuiltIns.isDouble(this) || KotlinBuiltIns.isFloat(this)
|
||||||
|
|
||||||
|
private fun CallableDescriptor.getParametersTypes(): List<KotlinType> =
|
||||||
|
listOf((containingDeclaration as ClassDescriptor).defaultType) +
|
||||||
|
valueParameters.map { it.type.makeNotNullable() }
|
||||||
|
|
||||||
private fun KotlinType.asString(): String = typeName.uppercase()
|
private fun KotlinType.asString(): String = typeName.uppercase()
|
||||||
|
|
||||||
private val KotlinType.typeName: String
|
private val KotlinType.typeName: String
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 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.generators.evaluate
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
|
||||||
|
|
||||||
internal fun populateOperationsMap(
|
|
||||||
unaryOperationsMap: ArrayList<Triple<String, List<KotlinType>, Boolean>>,
|
|
||||||
binaryOperationsMap: ArrayList<Pair<String, List<KotlinType>>>,
|
|
||||||
excludedFunctions: List<String>
|
|
||||||
) {
|
|
||||||
val builtIns = DefaultBuiltIns.Instance
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val allPrimitiveTypes = builtIns.builtInsPackageScope.getContributedDescriptors()
|
|
||||||
.filter { it is ClassDescriptor && KotlinBuiltIns.isPrimitiveType(it.defaultType) } as List<ClassDescriptor>
|
|
||||||
|
|
||||||
for (descriptor in allPrimitiveTypes + builtIns.string) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val functions = descriptor.getMemberScope(listOf()).getContributedDescriptors()
|
|
||||||
.filter { it is CallableDescriptor && !excludedFunctions.contains(it.getName().asString()) } as List<CallableDescriptor>
|
|
||||||
|
|
||||||
for (function in functions) {
|
|
||||||
val parametersTypes = function.getParametersTypes()
|
|
||||||
|
|
||||||
when (parametersTypes.size) {
|
|
||||||
1 -> unaryOperationsMap.add(Triple(function.name.asString(), parametersTypes, function is FunctionDescriptor))
|
|
||||||
2 -> binaryOperationsMap.add(function.name.asString() to parametersTypes)
|
|
||||||
else -> throw IllegalStateException(
|
|
||||||
"Couldn't add following method from builtins to operations map: ${function.name} in class ${descriptor.name}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun CallableDescriptor.getParametersTypes(): List<KotlinType> =
|
|
||||||
listOf((containingDeclaration as ClassDescriptor).defaultType) +
|
|
||||||
valueParameters.map { it.type.makeNotNullable() }
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 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.generators.test.evaluate
|
|
||||||
|
|
||||||
import junit.framework.TestCase
|
|
||||||
import org.jetbrains.kotlin.generators.evaluate.FIR_DEST_FILE
|
|
||||||
import org.jetbrains.kotlin.generators.evaluate.generateFirMap
|
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
|
||||||
|
|
||||||
class GenerateFirOperationsMapTest : TestCase() {
|
|
||||||
fun testGeneratedDataIsUpToDate() {
|
|
||||||
val text = generateFirMap()
|
|
||||||
KotlinTestUtils.assertEqualsToFile(FIR_DEST_FILE, text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user