Search in sources :

Example 31 with KotlinType

use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.

the class ImplementationBodyCodegen method generateDelegates.

private void generateDelegates(DelegationFieldsInfo delegationFieldsInfo) {
    for (KtSuperTypeListEntry specifier : myClass.getSuperTypeListEntries()) {
        if (specifier instanceof KtDelegatedSuperTypeEntry) {
            DelegationFieldsInfo.Field field = delegationFieldsInfo.getInfo((KtDelegatedSuperTypeEntry) specifier);
            generateDelegateField(field);
            KtExpression delegateExpression = ((KtDelegatedSuperTypeEntry) specifier).getDelegateExpression();
            KotlinType delegateExpressionType = delegateExpression != null ? bindingContext.getType(delegateExpression) : null;
            generateDelegates(getSuperClass(specifier), delegateExpressionType, field);
        }
    }
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 32 with KotlinType

use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.

the class PropertyCodegen method generatePropertyDelegateAccess.

private void generatePropertyDelegateAccess(@NotNull KtProperty p, @NotNull PropertyDescriptor propertyDescriptor, @NotNull Annotations annotations) {
    KotlinType delegateType = getDelegateTypeForProperty(p, propertyDescriptor);
    generateBackingField(p, propertyDescriptor, true, delegateType, null, annotations);
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 33 with KotlinType

use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.

the class ExpressionCodegen method generateExpressionMatch.

private StackValue generateExpressionMatch(StackValue expressionToMatch, KtExpression subjectExpression, KtExpression patternExpression) {
    if (expressionToMatch != null) {
        Type subjectType = expressionToMatch.type;
        markStartLineNumber(patternExpression);
        KotlinType condJetType = bindingContext.getType(patternExpression);
        Type condType;
        if (isNumberPrimitiveOrBoolean(subjectType)) {
            assert condJetType != null;
            condType = asmType(condJetType);
            if (!isNumberPrimitiveOrBoolean(condType)) {
                subjectType = boxType(subjectType);
            }
        } else {
            condType = OBJECT_TYPE;
        }
        return genEqualsForExpressionsPreferIEEE754Arithmetic(subjectExpression, patternExpression, KtTokens.EQEQ, subjectType, condType, expressionToMatch);
    } else {
        return gen(patternExpression);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 34 with KotlinType

use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.

the class ExpressionCodegen method generateIsCheck.

private StackValue generateIsCheck(StackValue expressionToMatch, KtTypeReference typeReference, boolean negated) {
    KotlinType jetType = bindingContext.get(TYPE, typeReference);
    markStartLineNumber(typeReference);
    StackValue value = generateIsCheck(expressionToMatch, jetType, false);
    return negated ? StackValue.not(value) : value;
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 35 with KotlinType

use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.

the class ExpressionCodegen method intermediateValueForProperty.

public StackValue.Property intermediateValueForProperty(@NotNull PropertyDescriptor propertyDescriptor, boolean forceField, boolean syntheticBackingField, @Nullable ClassDescriptor superCallTarget, boolean skipAccessorsForPrivateFieldInOuterClass, @NotNull StackValue receiver, @Nullable ResolvedCall resolvedCall) {
    if (propertyDescriptor instanceof SyntheticJavaPropertyDescriptor) {
        return intermediateValueForSyntheticExtensionProperty((SyntheticJavaPropertyDescriptor) propertyDescriptor, receiver);
    }
    DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
    FieldAccessorKind fieldAccessorKind = FieldAccessorKind.NORMAL;
    boolean isBackingFieldInClassCompanion = JvmAbi.isPropertyWithBackingFieldInOuterClass(propertyDescriptor);
    if (isBackingFieldInClassCompanion && (forceField || propertyDescriptor.isConst() && Visibilities.isPrivate(propertyDescriptor.getVisibility()))) {
        fieldAccessorKind = FieldAccessorKind.IN_CLASS_COMPANION;
    } else if (syntheticBackingField && context.getFirstCrossInlineOrNonInlineContext().getParentContext().getContextDescriptor() != containingDeclaration) {
        fieldAccessorKind = FieldAccessorKind.FIELD_FROM_LOCAL;
    }
    boolean isStaticBackingField = DescriptorUtils.isStaticDeclaration(propertyDescriptor) || AsmUtil.isInstancePropertyWithStaticBackingField(propertyDescriptor);
    boolean isSuper = superCallTarget != null;
    boolean isExtensionProperty = propertyDescriptor.getExtensionReceiverParameter() != null;
    KotlinType delegateType = JvmCodegenUtil.getPropertyDelegateType(propertyDescriptor, bindingContext);
    boolean isDelegatedProperty = delegateType != null;
    CallableMethod callableGetter = null;
    CallableMethod callableSetter = null;
    CodegenContext backingFieldContext = getBackingFieldContext(fieldAccessorKind, containingDeclaration);
    DeclarationDescriptor ownerDescriptor = containingDeclaration;
    boolean skipPropertyAccessors;
    PropertyDescriptor originalPropertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor);
    if (fieldAccessorKind != FieldAccessorKind.NORMAL) {
        int flags = AsmUtil.getVisibilityForBackingField(propertyDescriptor, isDelegatedProperty);
        boolean isInlinedConst = propertyDescriptor.isConst() && state.getShouldInlineConstVals();
        skipPropertyAccessors = isInlinedConst || (flags & ACC_PRIVATE) == 0 || skipAccessorsForPrivateFieldInOuterClass;
        if (!skipPropertyAccessors) {
            //noinspection ConstantConditions
            propertyDescriptor = (PropertyDescriptor) backingFieldContext.getAccessor(propertyDescriptor, fieldAccessorKind, delegateType, superCallTarget);
            assert propertyDescriptor instanceof AccessorForPropertyBackingField : "Unexpected accessor descriptor: " + propertyDescriptor;
            ownerDescriptor = propertyDescriptor;
        }
    } else {
        if (!isBackingFieldInClassCompanion) {
            ownerDescriptor = propertyDescriptor;
        }
        skipPropertyAccessors = forceField;
    }
    if (!skipPropertyAccessors) {
        if (!couldUseDirectAccessToProperty(propertyDescriptor, true, isDelegatedProperty, context, state.getShouldInlineConstVals())) {
            propertyDescriptor = context.getAccessorForSuperCallIfNeeded(propertyDescriptor, superCallTarget, state);
            propertyDescriptor = context.accessibleDescriptor(propertyDescriptor, superCallTarget);
            PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
            if (getter != null && !isConstOrHasJvmFieldAnnotation(propertyDescriptor)) {
                callableGetter = typeMapper.mapToCallableMethod(getter, isSuper);
            }
        }
        if (propertyDescriptor.isVar()) {
            PropertySetterDescriptor setter = propertyDescriptor.getSetter();
            if (setter != null && !couldUseDirectAccessToProperty(propertyDescriptor, false, isDelegatedProperty, context, state.getShouldInlineConstVals()) && !isConstOrHasJvmFieldAnnotation(propertyDescriptor)) {
                callableSetter = typeMapper.mapToCallableMethod(setter, isSuper);
            }
        }
    }
    if (!isStaticBackingField) {
        propertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor);
    }
    Type backingFieldOwner = typeMapper.mapOwner(ownerDescriptor);
    String fieldName;
    if (isExtensionProperty && !isDelegatedProperty) {
        fieldName = null;
    } else if (originalPropertyDescriptor.getContainingDeclaration() == backingFieldContext.getContextDescriptor()) {
        assert backingFieldContext instanceof FieldOwnerContext : "Actual context is " + backingFieldContext + " but should be instance of FieldOwnerContext";
        fieldName = ((FieldOwnerContext) backingFieldContext).getFieldName(propertyDescriptor, isDelegatedProperty);
    } else {
        fieldName = KotlinTypeMapper.mapDefaultFieldName(propertyDescriptor, isDelegatedProperty);
    }
    return StackValue.property(propertyDescriptor, backingFieldOwner, typeMapper.mapType(isDelegatedProperty && forceField ? delegateType : propertyDescriptor.getOriginal().getType()), isStaticBackingField, fieldName, callableGetter, callableSetter, receiver, this, resolvedCall);
}
Also used : SyntheticJavaPropertyDescriptor(org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor) SyntheticJavaPropertyDescriptor(org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType) IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Aggregations

KotlinType (org.jetbrains.kotlin.types.KotlinType)110 NotNull (org.jetbrains.annotations.NotNull)34 IElementType (com.intellij.psi.tree.IElementType)16 Type (org.jetbrains.org.objectweb.asm.Type)16 Nullable (org.jetbrains.annotations.Nullable)10 JsExpression (org.jetbrains.kotlin.js.backend.ast.JsExpression)7 PsiElement (com.intellij.psi.PsiElement)6 Name (org.jetbrains.kotlin.name.Name)6 ArrayList (java.util.ArrayList)4 KtExpression (org.jetbrains.kotlin.psi.KtExpression)4 Map (java.util.Map)3 BothSignatureWriter (org.jetbrains.kotlin.codegen.signature.BothSignatureWriter)3 JvmSignatureWriter (org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter)3 VariableDescriptor (org.jetbrains.kotlin.descriptors.VariableDescriptor)3 LocalVariableDescriptor (org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor)3 DataFlowInfo (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)3 ExpressionReceiver (org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver)3 PrimitiveType (org.jetbrains.kotlin.builtins.PrimitiveType)2 CallableDescriptor (org.jetbrains.kotlin.descriptors.CallableDescriptor)2 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)2