Search in sources :

Example 1 with EnclosedValueDescriptor

use of org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor in project kotlin by JetBrains.

the class LambdaInfo method getCapturedVars.

@NotNull
public List<CapturedParamDesc> getCapturedVars() {
    //lazy initialization cause it would be calculated after object creation
    if (capturedVars == null) {
        capturedVars = new ArrayList<CapturedParamDesc>();
        if (closure.getCaptureThis() != null) {
            Type type = typeMapper.mapType(closure.getCaptureThis());
            EnclosedValueDescriptor descriptor = new EnclosedValueDescriptor(AsmUtil.CAPTURED_THIS_FIELD, /* descriptor = */
            null, StackValue.field(type, closureClassType, AsmUtil.CAPTURED_THIS_FIELD, false, StackValue.LOCAL_0), type);
            capturedVars.add(getCapturedParamInfo(descriptor));
        }
        if (closure.getCaptureReceiverType() != null) {
            Type type = typeMapper.mapType(closure.getCaptureReceiverType());
            EnclosedValueDescriptor descriptor = new EnclosedValueDescriptor(AsmUtil.CAPTURED_RECEIVER_FIELD, /* descriptor = */
            null, StackValue.field(type, closureClassType, AsmUtil.CAPTURED_RECEIVER_FIELD, false, StackValue.LOCAL_0), type);
            capturedVars.add(getCapturedParamInfo(descriptor));
        }
        for (EnclosedValueDescriptor descriptor : closure.getCaptureVariables().values()) {
            capturedVars.add(getCapturedParamInfo(descriptor));
        }
    }
    return capturedVars;
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) EnclosedValueDescriptor(org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with EnclosedValueDescriptor

use of org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor 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)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)2 EnclosedValueDescriptor (org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor)2 Type (org.jetbrains.org.objectweb.asm.Type)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)1