use of org.jetbrains.kotlin.codegen.binding.MutableClosure in project kotlin by JetBrains.
the class ImplementationBodyCodegen method generateClosureInitialization.
private void generateClosureInitialization(@NotNull InstructionAdapter iv) {
MutableClosure closure = context.closure;
if (closure != null) {
List<FieldInfo> argsFromClosure = ClosureCodegen.calculateConstructorParameters(typeMapper, closure, classAsmType);
int k = 1;
for (FieldInfo info : argsFromClosure) {
k = AsmUtil.genAssignInstanceFieldFromParam(info, k, iv);
}
}
}
use of org.jetbrains.kotlin.codegen.binding.MutableClosure in project kotlin by JetBrains.
the class KotlinTypeMapper method writeAdditionalConstructorParameters.
private void writeAdditionalConstructorParameters(@NotNull ClassConstructorDescriptor descriptor, @NotNull JvmSignatureWriter sw) {
boolean isSynthesized = descriptor.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED;
//if (isSynthesized) return;
MutableClosure closure = bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration());
ClassDescriptor captureThis = getDispatchReceiverParameterForConstructorCall(descriptor, closure);
if (!isSynthesized && captureThis != null) {
writeParameter(sw, JvmMethodParameterKind.OUTER, captureThis.getDefaultType(), descriptor);
}
KotlinType captureReceiverType = closure != null ? closure.getCaptureReceiverType() : null;
if (captureReceiverType != null) {
writeParameter(sw, JvmMethodParameterKind.RECEIVER, captureReceiverType, descriptor);
}
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (!isSynthesized) {
if (containingDeclaration.getKind() == ClassKind.ENUM_CLASS || containingDeclaration.getKind() == ClassKind.ENUM_ENTRY) {
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, DescriptorUtilsKt.getBuiltIns(descriptor).getStringType(), descriptor);
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, DescriptorUtilsKt.getBuiltIns(descriptor).getIntType(), descriptor);
}
}
if (closure == null)
return;
for (DeclarationDescriptor variableDescriptor : closure.getCaptureVariables().keySet()) {
Type type;
if (variableDescriptor instanceof VariableDescriptor && !(variableDescriptor instanceof PropertyDescriptor)) {
Type sharedVarType = getSharedVarType(variableDescriptor);
if (sharedVarType == null) {
if (isDelegatedLocalVariable(variableDescriptor)) {
VariableDescriptor delegateVariableDescriptor = bindingContext.get(LOCAL_VARIABLE_DELEGATE, (VariableDescriptor) variableDescriptor);
assert delegateVariableDescriptor != null : "Local delegated property " + variableDescriptor + " delegate descriptor should be not null";
sharedVarType = mapType(delegateVariableDescriptor.getType());
} else {
sharedVarType = mapType(((VariableDescriptor) variableDescriptor).getType());
}
}
type = sharedVarType;
} else if (isLocalFunction(variableDescriptor)) {
//noinspection CastConflictsWithInstanceof
type = asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) variableDescriptor);
} else {
type = null;
}
if (type != null) {
closure.setCapturedParameterOffsetInConstructor(variableDescriptor, sw.getCurrentSignatureSize() + 1);
writeParameter(sw, JvmMethodParameterKind.CAPTURED_LOCAL_VARIABLE, type);
}
}
// because such classes are not accessible from the outside world
if (classBuilderMode.generateBodies) {
ResolvedCall<ConstructorDescriptor> superCall = findFirstDelegatingSuperCall(descriptor);
if (superCall == null)
return;
writeSuperConstructorCallParameters(sw, descriptor, superCall, captureThis != null);
}
}
Aggregations