コード例 #1
0
 @Override
 public StackValue generate(
     ExpressionCodegen codegen,
     InstructionAdapter v,
     @NotNull Type expectedType,
     @Nullable PsiElement element,
     @Nullable List<JetExpression> arguments,
     StackValue receiver,
     @NotNull GenerationState state) {
   JetCallExpression call = (JetCallExpression) element;
   ResolvedCall<? extends CallableDescriptor> resolvedCall =
       codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression());
   CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
   Type type =
       state
           .getInjector()
           .getJetTypeMapper()
           .mapType(
               resultingDescriptor.getReturnType().getArguments().get(0).getType(),
               MapTypeMode.VALUE);
   JvmPrimitiveType primitiveType = JvmPrimitiveType.getByAsmType(type);
   if (primitiveType != null) {
     v.getstatic(
         primitiveType.getWrapper().getAsmType().getInternalName(), "TYPE", "Ljava/lang/Class;");
   } else {
     v.aconst(type);
   }
   return StackValue.onStack(JetTypeMapper.JL_CLASS_TYPE);
 }
コード例 #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
ファイル: ArrayIterator.java プロジェクト: djcsdy/kotlin
 @Override
 public StackValue generate(
     ExpressionCodegen codegen,
     InstructionAdapter v,
     @NotNull Type expectedType,
     PsiElement element,
     List<JetExpression> arguments,
     StackValue receiver,
     @NotNull GenerationState state) {
   receiver.put(AsmTypeConstants.OBJECT_TYPE, v);
   JetCallExpression call = (JetCallExpression) element;
   FunctionDescriptor funDescriptor =
       (FunctionDescriptor)
           codegen
               .getBindingContext()
               .get(
                   BindingContext.REFERENCE_TARGET,
                   (JetSimpleNameExpression) call.getCalleeExpression());
   assert funDescriptor != null;
   ClassDescriptor containingDeclaration =
       (ClassDescriptor) funDescriptor.getContainingDeclaration().getOriginal();
   if (containingDeclaration.equals(JetStandardLibrary.getInstance().getArray())) {
     v.invokestatic(
         "jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
     return StackValue.onStack(AsmTypeConstants.JET_ITERATOR_TYPE);
   } else {
     for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
       PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
       if (primitiveType.getArrayClassName().is(containingDeclaration)) {
         String methodSignature =
             "(["
                 + jvmPrimitiveType.getJvmLetter()
                 + ")"
                 + jvmPrimitiveType.getIterator().getDescriptor();
         v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
         return StackValue.onStack(jvmPrimitiveType.getIterator().getAsmType());
       }
     }
     throw new UnsupportedOperationException(containingDeclaration.toString());
   }
 }