Avoid hard-coded operator names in CompileTimeConstantEvaluator
This commit is contained in:
-16
@@ -183,22 +183,6 @@ class CompileTimeConstantEvaluator {
|
||||
private fun <T : Number> FirConstKind<T>.toConstExpression(source: FirSourceElement?, value: Number): FirConstExpression<T> =
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
buildConstExpression(source, this, value as T)
|
||||
|
||||
// TODO: extension functions, e.g., Byte.and
|
||||
// TODO: toChar?, toString?
|
||||
companion object {
|
||||
private val unaryOperatorNames: Set<String> = setOf(
|
||||
"hashCode",
|
||||
"dec", "inc", "unaryMinus", "unaryPlus",
|
||||
"toByte", "toDouble", "toFloat", "toInt", "toLong", "toShort"
|
||||
)
|
||||
|
||||
// TODO: rangeTo?
|
||||
private val binaryOperatorNames: Set<String> = setOf(
|
||||
// TODO: "compareTo", "equals",
|
||||
"div", "minus", "mod", "plus", "rem", "times"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val <T> FirConstExpression<T>.typedValue: T
|
||||
|
||||
+3
@@ -291,3 +291,6 @@ internal val binaryOperations: HashMap<BinaryOperationKey<*, *>, Function2<Numbe
|
||||
binaryOperation(FirConstKind.Short, FirConstKind.Long, "times", { a, b -> a.times(b) }),
|
||||
binaryOperation(FirConstKind.Short, FirConstKind.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()
|
||||
|
||||
@@ -73,6 +73,14 @@ fun generateFirMap(): String {
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user