Migrate CompileTimeType and OperationsMap to frontend.common

This commit is contained in:
Jinseong Jeon
2021-06-11 15:42:09 -07:00
parent 833761ac3c
commit 477c1c8cd7
4 changed files with 26 additions and 15 deletions
@@ -0,0 +1,19 @@
/*
* 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.
*/
package org.jetbrains.kotlin.resolve.constants.evaluate
enum class CompileTimeType {
BYTE,
SHORT,
INT,
LONG,
DOUBLE,
FLOAT,
CHAR,
BOOLEAN,
STRING,
ANY
}
@@ -11,7 +11,7 @@ import java.math.BigInteger
/** This file is generated by `./gradlew generateOperationsMap`. DO NOT MODIFY MANUALLY */ /** This file is generated by `./gradlew generateOperationsMap`. DO NOT MODIFY MANUALLY */
internal fun evalUnaryOp(name: String, type: CompileTimeType, value: Any): Any? { fun evalUnaryOp(name: String, type: CompileTimeType, value: Any): Any? {
when (type) { when (type) {
BOOLEAN -> when (name) { BOOLEAN -> when (name) {
"not" -> return (value as Boolean).not() "not" -> return (value as Boolean).not()
@@ -110,8 +110,7 @@ internal fun evalUnaryOp(name: String, type: CompileTimeType, value: Any): Any?
return null return null
} }
fun evalBinaryOp(name: String, leftType: CompileTimeType, left: Any, rightType: CompileTimeType, right: Any): Any? {
internal fun evalBinaryOp(name: String, leftType: CompileTimeType, left: Any, rightType: CompileTimeType, right: Any): Any? {
when (leftType) { when (leftType) {
BOOLEAN -> when (rightType) { BOOLEAN -> when (rightType) {
BOOLEAN -> when (name) { BOOLEAN -> when (name) {
@@ -519,7 +518,7 @@ internal fun evalBinaryOp(name: String, leftType: CompileTimeType, left: Any, ri
return null return null
} }
internal fun checkBinaryOp( fun checkBinaryOp(
name: String, leftType: CompileTimeType, left: BigInteger, rightType: CompileTimeType, right: BigInteger name: String, leftType: CompileTimeType, left: BigInteger, rightType: CompileTimeType, right: BigInteger
): BigInteger? { ): BigInteger? {
when (leftType) { when (leftType) {
@@ -12,7 +12,6 @@ import com.intellij.psi.util.TypeConversionUtil
import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.UnsignedType
import org.jetbrains.kotlin.builtins.UnsignedTypes import org.jetbrains.kotlin.builtins.UnsignedTypes
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
@@ -1140,11 +1139,6 @@ private fun getReceiverExpressionType(resolvedCall: ResolvedCall<*>): KotlinType
} }
} }
internal enum class CompileTimeType {
BYTE, SHORT, INT, LONG, DOUBLE, FLOAT, CHAR, BOOLEAN,
STRING, ANY
}
fun ConstantValue<*>.isStandaloneOnlyConstant(): Boolean { fun ConstantValue<*>.isStandaloneOnlyConstant(): Boolean {
return this is KClassValue || this is EnumValue || this is AnnotationValue || this is ArrayValue return this is KClassValue || this is EnumValue || this is AnnotationValue || this is ArrayValue
} }
+4 -5
View File
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import java.io.File import java.io.File
val DEST_FILE: File = File("compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/OperationsMapGenerated.kt") val DEST_FILE: File = File("compiler/frontend.common/src/org/jetbrains/kotlin/resolve/constants/evaluate/OperationsMapGenerated.kt")
private val EXCLUDED_FUNCTIONS: List<String> = listOf("rangeTo", "hashCode", "inc", "dec", "subSequence") private val EXCLUDED_FUNCTIONS: List<String> = listOf("rangeTo", "hashCode", "inc", "dec", "subSequence")
fun main() { fun main() {
@@ -65,7 +65,7 @@ fun generate(): String {
} }
} }
p.println("internal fun evalUnaryOp(name: String, type: CompileTimeType, value: Any): Any? {") p.println("fun evalUnaryOp(name: String, type: CompileTimeType, value: Any): Any? {")
p.pushIndent() p.pushIndent()
p.println("when (type) {") p.println("when (type) {")
p.pushIndent() p.pushIndent()
@@ -85,9 +85,8 @@ fun generate(): String {
p.popIndent() p.popIndent()
p.println("}") p.println("}")
p.println() p.println()
p.println()
p.println("internal fun evalBinaryOp(name: String, leftType: CompileTimeType, left: Any, rightType: CompileTimeType, right: Any): Any? {") p.println("fun evalBinaryOp(name: String, leftType: CompileTimeType, left: Any, rightType: CompileTimeType, right: Any): Any? {")
p.pushIndent() p.pushIndent()
p.println("when (leftType) {") p.println("when (leftType) {")
p.pushIndent() p.pushIndent()
@@ -114,7 +113,7 @@ fun generate(): String {
p.println("}") p.println("}")
p.println() p.println()
p.println("internal fun checkBinaryOp(") p.println("fun checkBinaryOp(")
p.println(" name: String, leftType: CompileTimeType, left: BigInteger, rightType: CompileTimeType, right: BigInteger") p.println(" name: String, leftType: CompileTimeType, left: BigInteger, rightType: CompileTimeType, right: BigInteger")
p.println("): BigInteger? {") p.println("): BigInteger? {")
p.pushIndent() p.pushIndent()