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);
}
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);
}
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;
}
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);
}
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);
}
}
Aggregations