Rewrite primitives' generation using simple DSL

This commit is contained in:
Ivan Kylchik
2023-03-02 16:27:27 +01:00
committed by Space Team
parent dd0267f4ad
commit 2e836494f5
12 changed files with 1455 additions and 1359 deletions
+9 -3
View File
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.generators.builtins.numbers.primitives
import org.jetbrains.kotlin.generators.builtins.PrimitiveType
internal const val END_LINE = "\n"
internal fun PrimitiveType.castToIfNecessary(otherType: PrimitiveType): String {
if (this !in PrimitiveType.onlyNumeric || otherType !in PrimitiveType.onlyNumeric) {
throw IllegalArgumentException("Cannot cast to non-numeric type")
@@ -21,13 +23,17 @@ internal fun PrimitiveType.castToIfNecessary(otherType: PrimitiveType): String {
return ""
}
internal fun String.asSign(): String {
return when (this) {
internal fun operatorSign(methodName: String): String {
return when (methodName) {
"plus" -> "+"
"minus" -> "-"
"times" -> "*"
"div" -> "/"
"rem" -> "%"
else -> throw IllegalArgumentException("Unsupported binary operation: ${this}")
else -> throw IllegalArgumentException("Unsupported binary operation: ${methodName}")
}
}
internal fun String.toPrimitiveType(): PrimitiveType {
return PrimitiveType.valueOf(this.uppercase())
}