From 7450899b8786f4ee62d0d32f51b6e75779ede036 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 26 Jul 2017 14:55:22 +0300 Subject: [PATCH] Minor: extract get*CompileTimeConstant Get rid of code duplication. --- .../kotlin/codegen/ExpressionCodegen.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 305c35ede40..ab2b0515803 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -750,11 +750,21 @@ public class ExpressionCodegen extends KtVisitor impleme @Override public StackValue visitConstantExpression(@NotNull KtConstantExpression expression, StackValue receiver) { - ConstantValue compileTimeValue = getPrimitiveOrStringCompileTimeConstant(expression, bindingContext, state.getShouldInlineConstVals()); + ConstantValue compileTimeValue = getPrimitiveOrStringCompileTimeConstant(expression); assert compileTimeValue != null; return StackValue.constant(compileTimeValue.getValue(), expressionType(expression)); } + @Nullable + public ConstantValue getCompileTimeConstant(@NotNull KtExpression expression) { + return getCompileTimeConstant(expression, bindingContext, state.getShouldInlineConstVals()); + } + + @Nullable + public ConstantValue getPrimitiveOrStringCompileTimeConstant(@NotNull KtExpression expression) { + return getPrimitiveOrStringCompileTimeConstant(expression, bindingContext, state.getShouldInlineConstVals()); + } + @Nullable public static ConstantValue getPrimitiveOrStringCompileTimeConstant( @NotNull KtExpression expression, @@ -910,8 +920,7 @@ public class ExpressionCodegen extends KtVisitor impleme KtExpression entryExpression = entry.getExpression(); if (entryExpression == null) throw new AssertionError("No expression in " + entry); - ConstantValue compileTimeConstant = - getPrimitiveOrStringCompileTimeConstant(entryExpression, bindingContext, state.getShouldInlineConstVals()); + ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(entryExpression); if (compileTimeConstant != null && isConstantValueInlinableInStringTemplate(compileTimeConstant)) { constantValue.append(String.valueOf(compileTimeConstant.getValue())); @@ -2837,7 +2846,7 @@ public class ExpressionCodegen extends KtVisitor impleme expression.getRight(), reference); } else { - ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expression, bindingContext, state.getShouldInlineConstVals()); + ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expression); if (compileTimeConstant != null) { return StackValue.constant(compileTimeConstant.getValue(), expressionType(expression)); } @@ -3120,7 +3129,7 @@ public class ExpressionCodegen extends KtVisitor impleme } private boolean isIntZero(KtExpression expr, Type exprType) { - ConstantValue exprValue = getPrimitiveOrStringCompileTimeConstant(expr, bindingContext, state.getShouldInlineConstVals()); + ConstantValue exprValue = getPrimitiveOrStringCompileTimeConstant(expr); return isIntPrimitive(exprType) && exprValue != null && Integer.valueOf(0).equals(exprValue.getValue()); } @@ -3249,7 +3258,7 @@ public class ExpressionCodegen extends KtVisitor impleme public void invokeAppend(InstructionAdapter v, KtExpression expr) { expr = KtPsiUtil.safeDeparenthesize(expr); - ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expr, bindingContext, state.getShouldInlineConstVals()); + ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expr); if (compileTimeConstant == null) { if (expr instanceof KtBinaryExpression) { @@ -3299,7 +3308,7 @@ public class ExpressionCodegen extends KtVisitor impleme @Override public StackValue visitPrefixExpression(@NotNull KtPrefixExpression expression, @NotNull StackValue receiver) { - ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expression, bindingContext, state.getShouldInlineConstVals()); + ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expression); if (compileTimeConstant != null) { return StackValue.constant(compileTimeConstant.getValue(), expressionType(expression)); }