Search in sources :

Example 71 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class CallBasedArgumentGenerator method generateExpression.

@Override
protected void generateExpression(int i, @NotNull ExpressionValueArgument argument) {
    ValueParameterDescriptor parameter = valueParameters.get(i);
    Type type = valueParameterTypes.get(i);
    ValueArgument valueArgument = argument.getValueArgument();
    assert valueArgument != null;
    KtExpression argumentExpression = valueArgument.getArgumentExpression();
    assert argumentExpression != null : valueArgument.asElement().getText();
    callGenerator.genValueAndPut(parameter, argumentExpression, type, i);
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) KtExpression(org.jetbrains.kotlin.psi.KtExpression) ValueParameterDescriptor(org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)

Example 72 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class CallBasedArgumentGenerator method generateDefault.

@Override
protected void generateDefault(int i, @NotNull DefaultValueArgument argument) {
    Type type = valueParameterTypes.get(i);
    pushDefaultValueOnStack(type, codegen.v);
    callGenerator.afterParameterPut(type, null, i);
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type)

Example 73 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class ClosureCodegen method calculateConstructorParameters.

@NotNull
public static List<FieldInfo> calculateConstructorParameters(@NotNull KotlinTypeMapper typeMapper, @NotNull CalculatedClosure closure, @NotNull Type ownerType) {
    List<FieldInfo> args = Lists.newArrayList();
    ClassDescriptor captureThis = closure.getCaptureThis();
    if (captureThis != null) {
        Type type = typeMapper.mapType(captureThis);
        args.add(FieldInfo.createForHiddenField(ownerType, type, CAPTURED_THIS_FIELD));
    }
    KotlinType captureReceiverType = closure.getCaptureReceiverType();
    if (captureReceiverType != null) {
        args.add(FieldInfo.createForHiddenField(ownerType, typeMapper.mapType(captureReceiverType), CAPTURED_RECEIVER_FIELD));
    }
    for (EnclosedValueDescriptor enclosedValueDescriptor : closure.getCaptureVariables().values()) {
        DeclarationDescriptor descriptor = enclosedValueDescriptor.getDescriptor();
        if ((descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) || ExpressionTypingUtils.isLocalFunction(descriptor)) {
            args.add(FieldInfo.createForHiddenField(ownerType, enclosedValueDescriptor.getType(), enclosedValueDescriptor.getFieldName()));
        } else if (descriptor instanceof FunctionDescriptor) {
            assert captureReceiverType != null;
        }
    }
    return args;
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) EnclosedValueDescriptor(org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 74 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class ExpressionCodegen method getOrCreateCallGenerator.

@NotNull
CallGenerator getOrCreateCallGenerator(@NotNull ResolvedCall<?> resolvedCall, @NotNull CallableDescriptor descriptor) {
    Map<TypeParameterDescriptor, KotlinType> typeArguments = getTypeArgumentsForResolvedCall(resolvedCall, descriptor);
    TypeParameterMappings mappings = new TypeParameterMappings();
    for (Map.Entry<TypeParameterDescriptor, KotlinType> entry : typeArguments.entrySet()) {
        TypeParameterDescriptor key = entry.getKey();
        KotlinType type = entry.getValue();
        boolean isReified = key.isReified() || InlineUtil.isArrayConstructorWithLambda(resolvedCall.getResultingDescriptor());
        Pair<TypeParameterDescriptor, ReificationArgument> typeParameterAndReificationArgument = extractReificationArgument(type);
        if (typeParameterAndReificationArgument == null) {
            KotlinType approximatedType = CapturedTypeApproximationKt.approximateCapturedTypes(entry.getValue()).getUpper();
            // type is not generic
            JvmSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.TYPE);
            Type asmType = typeMapper.mapTypeParameter(approximatedType, signatureWriter);
            mappings.addParameterMappingToType(key.getName().getIdentifier(), approximatedType, asmType, signatureWriter.toString(), isReified);
        } else {
            mappings.addParameterMappingForFurtherReification(key.getName().getIdentifier(), type, typeParameterAndReificationArgument.getSecond(), isReified);
        }
    }
    return getOrCreateCallGenerator(descriptor, resolvedCall.getCall().getCallElement(), mappings, false);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) JvmSignatureWriter(org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter) BothSignatureWriter(org.jetbrains.kotlin.codegen.signature.BothSignatureWriter) KotlinType(org.jetbrains.kotlin.types.KotlinType) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class ExpressionCodegen method putReceiverAndInlineMarkerIfNeeded.

private void putReceiverAndInlineMarkerIfNeeded(@NotNull Callable callableMethod, @NotNull ResolvedCall<?> resolvedCall, @NotNull StackValue receiver, boolean isSuspensionPoint, boolean isConstructor) {
    boolean isSafeCallOrOnStack = receiver instanceof StackValue.SafeCall || receiver instanceof StackValue.OnStack;
    if (isSuspensionPoint && !isSafeCallOrOnStack) {
        // Inline markers are used to spill the stack before coroutine suspension
        addInlineMarker(v, true);
    }
    if (!isConstructor) {
        // otherwise already
        receiver = StackValue.receiver(resolvedCall, receiver, this, callableMethod);
        receiver.put(receiver.type, v);
        // But the problem is that we should leave the receiver itself on the stack, so we store it in a temporary variable.
        if (isSuspensionPoint && isSafeCallOrOnStack) {
            boolean bothReceivers = receiver instanceof StackValue.CallReceiver && ((StackValue.CallReceiver) receiver).getDispatchReceiver().type.getSort() != Type.VOID && ((StackValue.CallReceiver) receiver).getExtensionReceiver().type.getSort() != Type.VOID;
            Type firstReceiverType = bothReceivers ? ((StackValue.CallReceiver) receiver).getDispatchReceiver().type : receiver.type;
            Type secondReceiverType = bothReceivers ? receiver.type : null;
            int tmpVarForFirstReceiver = myFrameMap.enterTemp(firstReceiverType);
            int tmpVarForSecondReceiver = -1;
            if (secondReceiverType != null) {
                tmpVarForSecondReceiver = myFrameMap.enterTemp(secondReceiverType);
                v.store(tmpVarForSecondReceiver, secondReceiverType);
            }
            v.store(tmpVarForFirstReceiver, firstReceiverType);
            addInlineMarker(v, true);
            v.load(tmpVarForFirstReceiver, firstReceiverType);
            if (secondReceiverType != null) {
                v.load(tmpVarForSecondReceiver, secondReceiverType);
                myFrameMap.leaveTemp(secondReceiverType);
            }
            myFrameMap.leaveTemp(firstReceiverType);
        }
        callableMethod.afterReceiverGeneration(v);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Aggregations

Type (org.jetbrains.org.objectweb.asm.Type)104 KotlinType (org.jetbrains.kotlin.types.KotlinType)66 IElementType (com.intellij.psi.tree.IElementType)45 NotNull (org.jetbrains.annotations.NotNull)23 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)16 Label (org.jetbrains.org.objectweb.asm.Label)12 Type.getObjectType (org.jetbrains.org.objectweb.asm.Type.getObjectType)10 Method (org.jetbrains.org.objectweb.asm.commons.Method)9 Unit (kotlin.Unit)8 LocalVariableDescriptor (org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor)7 ArrayList (java.util.ArrayList)5 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)5 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)5 PrimitiveType (org.jetbrains.kotlin.builtins.PrimitiveType)4 ValueParameterDescriptor (org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)4 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 ScriptDescriptor (org.jetbrains.kotlin.descriptors.ScriptDescriptor)3 InOut (com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut)2 FunctionClassDescriptor (org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor)2