From c56c2263f0112f0b89aa9606996982aca8482f93 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Thu, 7 Nov 2013 18:10:54 +0400 Subject: [PATCH] Use propagation of constant values in evaluator --- .../evaluate/ConstantExpressionEvaluator.java | 12 ++++++++---- .../jet/lang/resolve/constants/ConstantUtils.kt | 16 +++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.java b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.java index f316e63c999..988f25c9627 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.java @@ -83,11 +83,15 @@ public class ConstantExpressionEvaluator extends JetVisitor visitQualifiedExpression(@NotNull JetQualifiedExpression expression, Void data) { - CompileTimeConstant compileTimeConstant = trace.get(BindingContext.COMPILE_TIME_VALUE, expression); - if (compileTimeConstant != null) { - return compileTimeConstant; - } + JetExpression receiverExpression = expression.getReceiverExpression(); JetExpression selectorExpression = expression.getSelectorExpression(); + if (receiverExpression instanceof JetConstantExpression && selectorExpression instanceof JetCallExpression) { + CompileTimeConstant constant = ConstantsPackage.propagateConstantValues(expression, trace, (JetCallExpression) selectorExpression); + if (constant != null) { + return constant; + } + } + if (selectorExpression != null) { return selectorExpression.accept(this, null); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/ConstantUtils.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/ConstantUtils.kt index 606c57bb914..b568828ed57 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/ConstantUtils.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/ConstantUtils.kt @@ -25,31 +25,31 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.lang.types.expressions.OperatorConventions -public fun propagateConstantValues(expression : JetQualifiedExpression, trace : BindingTrace, selectorExpression : JetCallExpression) { +public fun propagateConstantValues(expression : JetQualifiedExpression, trace : BindingTrace, selectorExpression : JetCallExpression): CompileTimeConstant? { val wholeExpressionValue = trace.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression) if (wholeExpressionValue != null) { - return + return null } val receiverExpression = expression.getReceiverExpression() val receiverValue = trace.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, receiverExpression) if (receiverValue == null || receiverValue is ErrorValue) { - return + return null } val calleeExpression = selectorExpression.getCalleeExpression() if (calleeExpression !is JetSimpleNameExpression) { - return + return null } val declarationDescriptor = trace.getBindingContext().get(BindingContext.REFERENCE_TARGET, calleeExpression) if (declarationDescriptor !is FunctionDescriptor) { - return + return null } val returnType = declarationDescriptor.getReturnType() if (returnType == null || !KotlinBuiltIns.getInstance().isPrimitiveType(returnType)) { - return + return null } val referencedName = calleeExpression.getReferencedNameAsName() @@ -80,9 +80,7 @@ public fun propagateConstantValues(expression : JetQualifiedExpression, trace : else -> null } - if (compileTimeValue != null) { - trace.record(BindingContext.COMPILE_TIME_VALUE, expression,compileTimeValue) - } + return compileTimeValue }