Search in sources :

Example 86 with Type

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

the class ImplementationBodyCodegen method generateCompanionObjectBackingFieldCopies.

private void generateCompanionObjectBackingFieldCopies() {
    if (companionObjectPropertiesToCopy == null)
        return;
    for (PropertyAndDefaultValue info : companionObjectPropertiesToCopy) {
        PropertyDescriptor property = info.descriptor;
        Type type = typeMapper.mapType(property);
        int modifiers = ACC_STATIC | ACC_FINAL | ACC_PUBLIC;
        FieldVisitor fv = v.newField(JvmDeclarationOriginKt.Synthetic(DescriptorToSourceUtils.descriptorToDeclaration(property), property), modifiers, context.getFieldName(property, false), type.getDescriptor(), typeMapper.mapFieldSignature(property.getType(), property), info.defaultValue);
        AnnotationCodegen.forField(fv, this, typeMapper).genAnnotations(property, type);
        // TODO: test this code
        if (state.getClassBuilderMode().generateBodies && info.defaultValue == null) {
            ExpressionCodegen codegen = createOrGetClInitCodegen();
            int companionObjectIndex = putCompanionObjectInLocalVar(codegen);
            StackValue.local(companionObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
            copyFieldFromCompanionObject(property);
        }
    }
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Type.getObjectType(org.jetbrains.org.objectweb.asm.Type.getObjectType) FieldVisitor(org.jetbrains.org.objectweb.asm.FieldVisitor)

Example 87 with Type

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

the class ImplementationBodyCodegen method generateDefaultImplsIfNeeded.

@Override
protected void generateDefaultImplsIfNeeded() {
    if (isInterface(descriptor) && !isLocal && (!JvmCodegenUtil.isJvm8InterfaceWithDefaults(descriptor, state) || state.getGenerateDefaultImplsForJvm8())) {
        Type defaultImplsType = state.getTypeMapper().mapDefaultImpls(descriptor);
        ClassBuilder defaultImplsBuilder = state.getFactory().newVisitor(JvmDeclarationOriginKt.DefaultImpls(myClass.getPsiOrParent(), descriptor), defaultImplsType, myClass.getContainingKtFile());
        CodegenContext parentContext = context.getParentContext();
        assert parentContext != null : "Parent context of interface declaration should not be null";
        ClassContext defaultImplsContext = parentContext.intoDefaultImplsClass(descriptor, (ClassContext) context, state);
        new InterfaceImplBodyCodegen(myClass, defaultImplsContext, defaultImplsBuilder, state, this).generate();
    }
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Type.getObjectType(org.jetbrains.org.objectweb.asm.Type.getObjectType)

Example 88 with Type

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

the class ImplementationBodyCodegen method getDelegationFieldsInfo.

@NotNull
private DelegationFieldsInfo getDelegationFieldsInfo(@NotNull List<KtSuperTypeListEntry> delegationSpecifiers) {
    DelegationFieldsInfo result = new DelegationFieldsInfo();
    int n = 0;
    for (KtSuperTypeListEntry specifier : delegationSpecifiers) {
        if (specifier instanceof KtDelegatedSuperTypeEntry) {
            KtExpression expression = ((KtDelegatedSuperTypeEntry) specifier).getDelegateExpression();
            PropertyDescriptor propertyDescriptor = CodegenUtil.getDelegatePropertyIfAny(expression, descriptor, bindingContext);
            if (CodegenUtil.isFinalPropertyWithBackingField(propertyDescriptor, bindingContext)) {
                result.addField((KtDelegatedSuperTypeEntry) specifier, propertyDescriptor);
            } else {
                KotlinType expressionType = expression != null ? bindingContext.getType(expression) : null;
                Type asmType = expressionType != null ? typeMapper.mapType(expressionType) : typeMapper.mapType(getSuperClass(specifier));
                result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, JvmAbi.DELEGATE_SUPER_FIELD_PREFIX + n);
            }
            n++;
        }
    }
    return result;
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Type.getObjectType(org.jetbrains.org.objectweb.asm.Type.getObjectType) KotlinType(org.jetbrains.kotlin.types.KotlinType) NotNull(org.jetbrains.annotations.NotNull) BindingContextUtils.getNotNull(org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull)

Example 89 with Type

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

the class ExpressionCodegen method generateEquals.

private StackValue generateEquals(@Nullable KtExpression left, @Nullable KtExpression right, @NotNull IElementType opToken) {
    Type leftType = expressionType(left);
    Type rightType = expressionType(right);
    if (KtPsiUtil.isNullConstant(left)) {
        return genCmpWithNull(right, opToken);
    }
    if (KtPsiUtil.isNullConstant(right)) {
        return genCmpWithNull(left, opToken);
    }
    if (isIntZero(left, leftType) && isIntPrimitive(rightType)) {
        return genCmpWithZero(right, opToken);
    }
    if (isIntZero(right, rightType) && isIntPrimitive(leftType)) {
        return genCmpWithZero(left, opToken);
    }
    if (isPrimitive(leftType) != isPrimitive(rightType)) {
        leftType = boxType(leftType);
        rightType = boxType(rightType);
    }
    if (opToken == KtTokens.EQEQEQ || opToken == KtTokens.EXCLEQEQEQ) {
        // TODO: always casting to the type of the left operand in case of primitives looks wrong
        Type operandType = isPrimitive(leftType) ? leftType : OBJECT_TYPE;
        return StackValue.cmp(opToken, operandType, genLazy(left, leftType), genLazy(right, rightType));
    }
    return genEqualsForExpressionsPreferIEEE754Arithmetic(left, right, opToken, leftType, rightType, null);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 90 with Type

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

the class ExpressionCodegen method intermediateValueForSyntheticExtensionProperty.

@NotNull
private StackValue.Property intermediateValueForSyntheticExtensionProperty(@NotNull SyntheticJavaPropertyDescriptor propertyDescriptor, @NotNull StackValue receiver) {
    Type type = typeMapper.mapType(propertyDescriptor.getOriginal().getType());
    CallableMethod callableGetter = typeMapper.mapToCallableMethod(context.accessibleDescriptor(propertyDescriptor.getGetMethod(), null), false);
    FunctionDescriptor setMethod = propertyDescriptor.getSetMethod();
    CallableMethod callableSetter = setMethod != null ? typeMapper.mapToCallableMethod(context.accessibleDescriptor(setMethod, null), false) : null;
    return StackValue.property(propertyDescriptor, null, type, false, null, callableGetter, callableSetter, receiver, this, null);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) NotNull(org.jetbrains.annotations.NotNull)

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