use of org.jetbrains.kotlin.codegen.state.GenerationState in project kotlin by JetBrains.
the class InlineCodegen method generateMethodBody.
@NotNull
private static SMAP generateMethodBody(@NotNull MethodVisitor adapter, @NotNull FunctionDescriptor descriptor, @NotNull MethodContext context, @NotNull KtExpression expression, @NotNull JvmMethodSignature jvmMethodSignature, @NotNull ExpressionCodegen codegen, @Nullable LambdaInfo lambdaInfo) {
boolean isLambda = lambdaInfo != null;
GenerationState state = codegen.getState();
// Wrapping for preventing marking actual parent codegen as containing reified markers
FakeMemberCodegen parentCodegen = new FakeMemberCodegen(codegen.getParentCodegen(), expression, (FieldOwnerContext) context.getParentContext(), isLambda ? codegen.getParentCodegen().getClassName() : state.getTypeMapper().mapImplementationOwner(descriptor).getInternalName());
FunctionGenerationStrategy strategy;
if (expression instanceof KtCallableReferenceExpression) {
KtCallableReferenceExpression callableReferenceExpression = (KtCallableReferenceExpression) expression;
KtExpression receiverExpression = callableReferenceExpression.getReceiverExpression();
Type receiverType = receiverExpression != null && codegen.getBindingContext().getType(receiverExpression) != null ? codegen.getState().getTypeMapper().mapType(codegen.getBindingContext().getType(receiverExpression)) : null;
if (isLambda && lambdaInfo.isPropertyReference()) {
Type asmType = state.getTypeMapper().mapClass(lambdaInfo.getClassDescriptor());
PropertyReferenceInfo info = lambdaInfo.getPropertyReferenceInfo();
strategy = new PropertyReferenceCodegen.PropertyReferenceGenerationStrategy(true, info.getGetFunction(), info.getTarget(), asmType, receiverType, lambdaInfo.expression, state, true);
} else {
strategy = new FunctionReferenceGenerationStrategy(state, descriptor, CallUtilKt.getResolvedCallWithAssert(callableReferenceExpression.getCallableReference(), codegen.getBindingContext()), receiverType, null, true);
}
} else if (expression instanceof KtFunctionLiteral) {
strategy = new ClosureGenerationStrategy(state, (KtDeclarationWithBody) expression);
} else if (descriptor.isSuspend() && expression instanceof KtFunction) {
strategy = new SuspendFunctionGenerationStrategy(state, CoroutineCodegenUtilKt.<FunctionDescriptor>unwrapInitialDescriptorForSuspendFunction(descriptor), (KtFunction) expression);
} else {
strategy = new FunctionGenerationStrategy.FunctionDefault(state, (KtDeclarationWithBody) expression);
}
FunctionCodegen.generateMethodBody(adapter, descriptor, context, jvmMethodSignature, strategy, parentCodegen);
if (isLambda) {
codegen.propagateChildReifiedTypeParametersUsages(parentCodegen.getReifiedTypeParametersUsages());
}
return createSMAPWithDefaultMapping(expression, parentCodegen.getOrCreateSourceMapper().getResultMappings());
}
Aggregations