Search in sources :

Example 96 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class ExpressionCodegen method addLeaveTaskToRemoveNamedFunctionFromFrameMap.

private void addLeaveTaskToRemoveNamedFunctionFromFrameMap(@NotNull final KtNamedFunction statement, final Label blockEnd, @NotNull List<Function<StackValue, Void>> leaveTasks) {
    final FunctionDescriptor functionDescriptor = (FunctionDescriptor) bindingContext.get(DECLARATION_TO_DESCRIPTOR, statement);
    assert functionDescriptor != null;
    final Type type = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
    final Label scopeStart = new Label();
    v.mark(scopeStart);
    leaveTasks.add(new Function<StackValue, Void>() {

        @Override
        public Void fun(StackValue answer) {
            int index = myFrameMap.leave(functionDescriptor);
            assert !functionDescriptor.getName().isSpecial() : "Local variable should be generated only for function with name: " + statement.getText();
            v.visitLocalVariable(functionDescriptor.getName().asString() + "$", type.getDescriptor(), null, scopeStart, blockEnd, index);
            return null;
        }
    });
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Label(org.jetbrains.org.objectweb.asm.Label)

Example 97 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class ExpressionCodegen method generateExpressionWithNullFallback.

private StackValue generateExpressionWithNullFallback(@NotNull KtExpression expression, @NotNull Label ifnull) {
    KtExpression deparenthesized = KtPsiUtil.deparenthesize(expression);
    assert deparenthesized != null : "Unexpected empty expression";
    expression = deparenthesized;
    Type type = expressionType(expression);
    if (expression instanceof KtSafeQualifiedExpression && !isPrimitive(type)) {
        return StackValue.coercion(generateSafeQualifiedExpression((KtSafeQualifiedExpression) expression, ifnull), type);
    } else {
        return genLazy(expression, type);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 98 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class ImplementationBodyCodegen method initializeEnumConstant.

private void initializeEnumConstant(@NotNull List<KtEnumEntry> enumEntries, int ordinal) {
    ExpressionCodegen codegen = createOrGetClInitCodegen();
    InstructionAdapter iv = codegen.v;
    KtEnumEntry enumEntry = enumEntries.get(ordinal);
    iv.dup();
    iv.iconst(ordinal);
    ClassDescriptor classDescriptor = getNotNull(bindingContext, BindingContext.CLASS, enumEntry);
    Type implClass = typeMapper.mapClass(classDescriptor);
    iv.anew(implClass);
    iv.dup();
    iv.aconst(enumEntry.getName());
    iv.iconst(ordinal);
    List<KtSuperTypeListEntry> delegationSpecifiers = enumEntry.getSuperTypeListEntries();
    ResolvedCall<?> defaultArgumentsConstructorCall = CallUtilKt.getResolvedCall(enumEntry, bindingContext);
    boolean enumEntryHasSubclass = CodegenBinding.enumEntryNeedSubclass(bindingContext, classDescriptor);
    if (delegationSpecifiers.size() == 1 && !enumEntryNeedSubclass(bindingContext, enumEntry)) {
        ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCallWithAssert(delegationSpecifiers.get(0), bindingContext);
        CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor(), false);
        codegen.invokeMethodWithArguments(method, resolvedCall, StackValue.none());
    } else if (defaultArgumentsConstructorCall != null && !enumEntryHasSubclass) {
        codegen.invokeFunction(defaultArgumentsConstructorCall, StackValue.none()).put(Type.VOID_TYPE, iv);
    } else {
        iv.invokespecial(implClass.getInternalName(), "<init>", "(Ljava/lang/String;I)V", false);
    }
    iv.dup();
    iv.putstatic(classAsmType.getInternalName(), enumEntry.getName(), classAsmType.getDescriptor());
    iv.astore(OBJECT_TYPE);
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Type.getObjectType(org.jetbrains.org.objectweb.asm.Type.getObjectType) InstructionAdapter(org.jetbrains.org.objectweb.asm.commons.InstructionAdapter) JavaClassDescriptor(org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)

Example 99 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class FunctionReferenceGenerationStrategy method computeAndSaveArguments.

private void computeAndSaveArguments(@NotNull List<? extends ValueArgument> fakeArguments, @NotNull ExpressionCodegen codegen) {
    int receivers = (referencedFunction.getDispatchReceiverParameter() != null ? 1 : 0) + (referencedFunction.getExtensionReceiverParameter() != null ? 1 : 0) - (receiverType != null ? 1 : 0);
    if (receivers < 0 && referencedFunction instanceof ConstructorDescriptor && isObject(referencedFunction.getContainingDeclaration().getContainingDeclaration())) {
        //reference to object nested class
        //TODO: seems problem should be fixed on frontend side (note that object instance are captured by generated class)
        receivers = 0;
    }
    List<ValueParameterDescriptor> parameters = CollectionsKt.drop(functionDescriptor.getValueParameters(), receivers);
    for (int i = 0; i < parameters.size(); i++) {
        ValueParameterDescriptor parameter = parameters.get(i);
        ValueArgument fakeArgument = fakeArguments.get(i);
        Type type = state.getTypeMapper().mapType(parameter);
        int localIndex = codegen.myFrameMap.getIndex(parameter);
        codegen.tempVariables.put(fakeArgument.getArgumentExpression(), StackValue.local(localIndex, type));
    }
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) ExpressionValueArgument(org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument) ResolvedValueArgument(org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument)

Example 100 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class ExpressionCodegen method visitClassOrObject.

private StackValue visitClassOrObject(KtClassOrObject declaration) {
    ClassDescriptor descriptor = bindingContext.get(CLASS, declaration);
    assert descriptor != null;
    Type asmType = asmTypeForAnonymousClass(bindingContext, declaration);
    ClassBuilder classBuilder = state.getFactory().newVisitor(JvmDeclarationOriginKt.OtherOrigin(declaration, descriptor), asmType, declaration.getContainingFile());
    ClassContext objectContext = context.intoAnonymousClass(descriptor, this, OwnerKind.IMPLEMENTATION);
    new ImplementationBodyCodegen(declaration, objectContext, classBuilder, state, getParentCodegen(), /* isLocal = */
    true).generate();
    if (declaration instanceof KtClass && ((KtClass) declaration).isInterface()) {
        Type traitImplType = state.getTypeMapper().mapDefaultImpls(descriptor);
        ClassBuilder traitImplBuilder = state.getFactory().newVisitor(JvmDeclarationOriginKt.DefaultImpls(declaration, descriptor), traitImplType, declaration.getContainingFile());
        ClassContext traitImplContext = context.intoAnonymousClass(descriptor, this, OwnerKind.DEFAULT_IMPLS);
        new InterfaceImplBodyCodegen(declaration, traitImplContext, traitImplBuilder, state, parentCodegen).generate();
    }
    return StackValue.none();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Aggregations

Type (org.jetbrains.org.objectweb.asm.Type)104 KotlinType (org.jetbrains.kotlin.types.KotlinType)66 IElementType (com.intellij.psi.tree.IElementType)45 NotNull (org.jetbrains.annotations.NotNull)23 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)16 Label (org.jetbrains.org.objectweb.asm.Label)12 Type.getObjectType (org.jetbrains.org.objectweb.asm.Type.getObjectType)10 Method (org.jetbrains.org.objectweb.asm.commons.Method)9 Unit (kotlin.Unit)8 LocalVariableDescriptor (org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor)7 ArrayList (java.util.ArrayList)5 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)5 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)5 PrimitiveType (org.jetbrains.kotlin.builtins.PrimitiveType)4 ValueParameterDescriptor (org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)4 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 ScriptDescriptor (org.jetbrains.kotlin.descriptors.ScriptDescriptor)3 InOut (com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut)2 FunctionClassDescriptor (org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor)2