From 0610dd36faf687a48fc72390a7c923285665cc3b Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 21 Sep 2015 18:44:39 +0300 Subject: [PATCH] ConstantExpressionEvaluator: avoid calling KotlinBuiltIns.getInstance() --- .../evaluate/ConstantExpressionEvaluator.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt index c83139a3cb0..befe2567fc3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt @@ -36,8 +36,7 @@ import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.JetTypeChecker import org.jetbrains.kotlin.types.expressions.OperatorConventions import java.math.BigInteger -import java.util.ArrayList -import java.util.HashMap +import java.util.* public class ConstantExpressionEvaluator( internal val builtIns: KotlinBuiltIns @@ -656,6 +655,24 @@ private class ConstantExpressionEvaluatorVisitor( return createOperationArgument(argumentExpression, parameter.getType(), argumentCompileTimeType) } + + private fun getCompileTimeType(c: JetType): CompileTimeType? { + val builtIns = constantExpressionEvaluator.builtIns + return when (TypeUtils.makeNotNullable(c)) { + builtIns.intType -> INT + builtIns.byteType -> BYTE + builtIns.shortType -> SHORT + builtIns.longType -> LONG + builtIns.doubleType -> DOUBLE + builtIns.floatType -> FLOAT + builtIns.charType -> CHAR + builtIns.booleanType -> BOOLEAN + builtIns.stringType -> STRING + builtIns.anyType -> ANY + else -> null + } + } + private fun createOperationArgument(expression: JetExpression, expressionType: JetType, compileTimeType: CompileTimeType<*>): OperationArgument? { val compileTimeConstant = constantExpressionEvaluator.evaluateExpression(expression, trace, expressionType) ?: return null val evaluationResult = compileTimeConstant.getValue(expressionType) ?: return null @@ -820,23 +837,6 @@ private fun getReceiverExpressionType(resolvedCall: ResolvedCall<*>): JetType? { } } -private fun getCompileTimeType(c: JetType): CompileTimeType? { - val builtIns = KotlinBuiltIns.getInstance() - return when (TypeUtils.makeNotNullable(c)) { - builtIns.getIntType() -> INT - builtIns.getByteType() -> BYTE - builtIns.getShortType() -> SHORT - builtIns.getLongType() -> LONG - builtIns.getDoubleType() -> DOUBLE - builtIns.getFloatType() -> FLOAT - builtIns.getCharType() -> CHAR - builtIns.getBooleanType() -> BOOLEAN - builtIns.getStringType() -> STRING - builtIns.getAnyType() -> ANY - else -> null - } -} - private class CompileTimeType internal val BYTE = CompileTimeType()