@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); }
public static Type boxType(Type asmType) { JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByAsmType(asmType); if (jvmPrimitiveType != null) { return jvmPrimitiveType.getWrapper().getAsmType(); } else { return asmType; } }
public static Type unboxType(Type type) { JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByWrapperAsmType(type); if (jvmPrimitiveType != null) { return jvmPrimitiveType.getAsmType(); } else { throw new UnsupportedOperationException("Unboxing: " + type); } }
private void initPrimitives() { KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); String name = jvmPrimitiveType.getName(); FqName wrapperFqName = jvmPrimitiveType.getWrapperFqName(); register(wrapperFqName, builtIns.getPrimitiveClassDescriptor(primitiveType)); primitiveTypesMap.put(name, builtIns.getPrimitiveJetType(primitiveType)); primitiveTypesMap.put("[" + name, builtIns.getPrimitiveArrayJetType(primitiveType)); primitiveTypesMap.put( wrapperFqName.asString(), builtIns.getNullablePrimitiveJetType(primitiveType)); } primitiveTypesMap.put("void", KotlinBuiltIns.getInstance().getUnitType()); }
@Override public StackValue generate( ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type expectedType, @Nullable PsiElement element, @Nullable List<JetExpression> arguments, StackValue receiver, @NotNull GenerationState state) { JvmPrimitiveType primitiveType = JvmPrimitiveType.getByAsmType(receiver.type); if (primitiveType != null) { v.getstatic( primitiveType.getWrapper().getAsmType().getInternalName(), "TYPE", "Ljava/lang/Class;"); } else { receiver.put(receiver.type, v); v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;"); } return StackValue.onStack(AsmTypeConstants.getType(Class.class)); }
@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()); } }