From 3ee6afd51968c44c7a57b14581bcd587af4390a2 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 30 Aug 2012 16:07:00 +0400 Subject: [PATCH] Utility method moved to CodegenUtil --- .../org/jetbrains/jet/codegen/CodegenUtil.java | 4 ++++ .../jetbrains/jet/codegen/ExpressionCodegen.java | 16 ++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index c20500bc513..36ce1e09aeb 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -318,6 +318,10 @@ public class CodegenUtil { return type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE || type == Type.CHAR_TYPE; } + public static boolean isNumberPrimitive(Type type) { + return isIntPrimitive(type) || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.LONG_TYPE; + } + public static boolean isPrimitive(Type type) { return type.getSort() != Type.OBJECT && type.getSort() != Type.ARRAY; } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 8c12b188ad4..67ee707bdd2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2369,7 +2369,7 @@ public class ExpressionCodegen extends JetVisitor implem boolean leftNullable, boolean rightNullable ) { - if ((isNumberPrimitive(leftType) || leftType.getSort() == Type.BOOLEAN) && leftType == rightType) { + if ((CodegenUtil.isNumberPrimitive(leftType) || leftType.getSort() == Type.BOOLEAN) && leftType == rightType) { return compareExpressionsOnStack(opToken, leftType); } else { @@ -2462,7 +2462,7 @@ public class ExpressionCodegen extends JetVisitor implem return StackValue.onStack(exprType); } - private static boolean isNumberPrimitive(DeclarationDescriptor descriptor) { + private static boolean isPrimitiveNumberClassDescriptor(DeclarationDescriptor descriptor) { if (!(descriptor instanceof ClassDescriptor)) { return false; } @@ -2480,10 +2480,6 @@ public class ExpressionCodegen extends JetVisitor implem return className.equals(name); } - private static boolean isNumberPrimitive(Type type) { - return isIntPrimitive(type) || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.LONG_TYPE; - } - private StackValue generateCompareOp(JetExpression left, JetExpression right, IElementType opToken, Type operandType) { gen(left, operandType); gen(right, operandType); @@ -2637,7 +2633,7 @@ public class ExpressionCodegen extends JetVisitor implem else { DeclarationDescriptor cls = op.getContainingDeclaration(); CallableMethod callableMethod = (CallableMethod) callable; - if (isNumberPrimitive(cls) || !(op.getName().getName().equals("inc") || op.getName().getName().equals("dec"))) { + if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().getName().equals("inc") || op.getName().getName().equals("dec"))) { return invokeOperation(expression, (FunctionDescriptor) op, callableMethod); } else { @@ -2697,7 +2693,7 @@ public class ExpressionCodegen extends JetVisitor implem final Type asmType = expressionType(expression); DeclarationDescriptor cls = op.getContainingDeclaration(); if (op.getName().getName().equals("inc") || op.getName().getName().equals("dec")) { - if (isNumberPrimitive(cls)) { + if (isPrimitiveNumberClassDescriptor(cls)) { receiver.put(receiver.type, v); JetExpression operand = expression.getBaseExpression(); if (operand instanceof JetReferenceExpression) { @@ -3285,10 +3281,10 @@ The "returned" value of try expression with no finally is either the last expres boolean patternIsNullable = false; JetType condJetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, condExpression); Type condType; - if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) { + if (CodegenUtil.isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) { assert condJetType != null; condType = asmType(condJetType); - if (!(isNumberPrimitive(condType) || condType.getSort() == Type.BOOLEAN)) { + if (!(CodegenUtil.isNumberPrimitive(condType) || condType.getSort() == Type.BOOLEAN)) { subjectType = boxType(subjectType); expressionToMatch.coerce(subjectType, v); }