예제 #1
0
파일: UpTo.java 프로젝트: yang/kotlin
 @Override
 public StackValue generate(
     ExpressionCodegen codegen,
     InstructionAdapter v,
     @NotNull Type expectedType,
     PsiElement element,
     List<JetExpression> arguments,
     StackValue receiver,
     @NotNull GenerationState state) {
   if (arguments.size() == 1) {
     final Type leftType = receiver.type;
     final Type rightType = codegen.expressionType(arguments.get(0));
     receiver.put(Type.INT_TYPE, v);
     codegen.gen(arguments.get(0), rightType);
     v.invokestatic(
         "jet/runtime/Ranges",
         forward ? "upTo" : "downTo",
         "("
             + receiver.type.getDescriptor()
             + leftType.getDescriptor()
             + ")"
             + expectedType.getDescriptor());
     return StackValue.onStack(expectedType);
   } else {
     JetBinaryExpression expression = (JetBinaryExpression) element;
     final Type leftType = codegen.expressionType(expression.getLeft());
     final Type rightType = codegen.expressionType(expression.getRight());
     //            if (JetTypeMapper.isIntPrimitive(leftType)) {
     codegen.gen(expression.getLeft(), leftType);
     codegen.gen(expression.getRight(), rightType);
     v.invokestatic(
         "jet/runtime/Ranges",
         forward ? "upTo" : "downTo",
         "("
             + leftType.getDescriptor()
             + rightType.getDescriptor()
             + ")"
             + expectedType.getDescriptor());
     return StackValue.onStack(expectedType);
     //            }
     //            else {
     //                throw new UnsupportedOperationException("ranges are only supported for int
     // objects");
     //            }
   }
 }
예제 #2
0
파일: Equals.java 프로젝트: parroit/kotlin
  @Override
  public StackValue generate(
      ExpressionCodegen codegen,
      InstructionAdapter v,
      @NotNull Type expectedType,
      PsiElement element,
      List<JetExpression> arguments,
      StackValue receiver,
      @NotNull GenerationState state) {

    boolean leftNullable = true;
    JetExpression rightExpr;
    if (element instanceof JetCallExpression) {
      receiver.put(JetTypeMapper.TYPE_OBJECT, v);
      JetCallExpression jetCallExpression = (JetCallExpression) element;
      JetExpression calleeExpression = jetCallExpression.getCalleeExpression();
      if (calleeExpression != null) {
        JetType leftType =
            codegen.getBindingContext().get(BindingContext.EXPRESSION_TYPE, calleeExpression);
        if (leftType != null) leftNullable = leftType.isNullable();
      }
      rightExpr = arguments.get(0);
    } else {
      JetExpression leftExpr = arguments.get(0);
      leftNullable =
          codegen.getBindingContext().get(BindingContext.EXPRESSION_TYPE, leftExpr).isNullable();
      codegen.gen(leftExpr).put(JetTypeMapper.TYPE_OBJECT, v);
      rightExpr = arguments.get(1);
    }

    JetType rightType = codegen.getBindingContext().get(BindingContext.EXPRESSION_TYPE, rightExpr);
    codegen.gen(rightExpr).put(JetTypeMapper.TYPE_OBJECT, v);

    return codegen.generateEqualsForExpressionsOnStack(
        JetTokens.EQEQ,
        JetTypeMapper.TYPE_OBJECT,
        JetTypeMapper.TYPE_OBJECT,
        leftNullable,
        rightType.isNullable());
  }
예제 #3
0
파일: Not.java 프로젝트: goodwinnk/kotlin
 @NotNull
 @Override
 public Type generateImpl(
     @NotNull ExpressionCodegen codegen,
     @NotNull InstructionAdapter v,
     @NotNull Type returnType,
     PsiElement element,
     List<JetExpression> arguments,
     StackValue receiver) {
   StackValue stackValue;
   if (arguments.size() == 1) {
     stackValue = codegen.gen(arguments.get(0));
   } else {
     stackValue = receiver;
   }
   stackValue.put(Type.BOOLEAN_TYPE, v);
   StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(returnType, v);
   return returnType;
 }
예제 #4
0
 @Override
 public StackValue generate(
     ExpressionCodegen codegen,
     InstructionAdapter v,
     @NotNull Type expectedType,
     @Nullable PsiElement element,
     @Nullable List<JetExpression> arguments,
     StackValue receiver,
     @NotNull GenerationState state) {
   boolean nullable = expectedType.getSort() == Type.OBJECT;
   if (nullable) {
     expectedType = JetTypeMapper.unboxType(expectedType);
   }
   if (receiver != null && receiver != StackValue.none()) receiver.put(expectedType, v);
   else {
     assert arguments != null;
     codegen.gen(arguments.get(0), expectedType);
   }
   return StackValue.onStack(expectedType);
 }