Search in sources :

Example 11 with GenerationState

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());
}
Also used : SuspendFunctionGenerationStrategy(org.jetbrains.kotlin.codegen.coroutines.SuspendFunctionGenerationStrategy) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) SuspendFunctionGenerationStrategy(org.jetbrains.kotlin.codegen.coroutines.SuspendFunctionGenerationStrategy) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)11 NotNull (org.jetbrains.annotations.NotNull)7 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)3 KtFile (org.jetbrains.kotlin.psi.KtFile)3 KotlinType (org.jetbrains.kotlin.types.KotlinType)3 ArrayList (java.util.ArrayList)2 KtScript (org.jetbrains.kotlin.psi.KtScript)2 NoDataException (com.intellij.debugger.NoDataException)1 PositionManager (com.intellij.debugger.PositionManager)1 Disposable (com.intellij.openapi.Disposable)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 ReferenceType (com.sun.jdi.ReferenceType)1 File (java.io.File)1 List (java.util.List)1 TestRunner (junit.textui.TestRunner)1 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)1 OutputFile (org.jetbrains.kotlin.backend.common.output.OutputFile)1 OutputFileCollection (org.jetbrains.kotlin.backend.common.output.OutputFileCollection)1