Search in sources :

Example 1 with SyntheticFieldDescriptor

use of org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor in project kotlin by JetBrains.

the class MethodContext method lookupInContext.

@Override
public StackValue lookupInContext(DeclarationDescriptor d, @Nullable StackValue result, GenerationState state, boolean ignoreNoOuter) {
    if (d instanceof SyntheticFieldDescriptor) {
        SyntheticFieldDescriptor fieldDescriptor = (SyntheticFieldDescriptor) d;
        d = fieldDescriptor.getPropertyDescriptor();
    }
    if (getContextDescriptor() == d) {
        return result != null ? result : StackValue.LOCAL_0;
    }
    return getParentContext().lookupInContext(d, result, state, ignoreNoOuter);
}
Also used : SyntheticFieldDescriptor(org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor)

Example 2 with SyntheticFieldDescriptor

use of org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor in project kotlin by JetBrains.

the class StackValue method receiver.

public static StackValue receiver(ResolvedCall<?> resolvedCall, StackValue receiver, ExpressionCodegen codegen, @Nullable Callable callableMethod) {
    ReceiverValue callDispatchReceiver = resolvedCall.getDispatchReceiver();
    CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
    if (descriptor instanceof SyntheticFieldDescriptor) {
        callDispatchReceiver = ((SyntheticFieldDescriptor) descriptor).getDispatchReceiverForBackend();
    }
    ReceiverValue callExtensionReceiver = resolvedCall.getExtensionReceiver();
    if (callDispatchReceiver != null || callExtensionReceiver != null || isLocalFunCall(callableMethod) || isCallToMemberObjectImportedByName(resolvedCall)) {
        ReceiverParameterDescriptor dispatchReceiverParameter = descriptor.getDispatchReceiverParameter();
        ReceiverParameterDescriptor extensionReceiverParameter = descriptor.getExtensionReceiverParameter();
        if (descriptor instanceof SyntheticFieldDescriptor) {
            dispatchReceiverParameter = ((SyntheticFieldDescriptor) descriptor).getDispatchReceiverParameterForBackend();
        }
        boolean hasExtensionReceiver = callExtensionReceiver != null;
        StackValue dispatchReceiver = platformStaticCallIfPresent(genReceiver(hasExtensionReceiver ? none() : receiver, codegen, resolvedCall, callableMethod, callDispatchReceiver, false), descriptor);
        StackValue extensionReceiver = genReceiver(receiver, codegen, resolvedCall, callableMethod, callExtensionReceiver, true);
        Type type = CallReceiver.calcType(resolvedCall, dispatchReceiverParameter, extensionReceiverParameter, codegen.typeMapper, callableMethod, codegen.getState());
        assert type != null : "Could not map receiver type for " + resolvedCall;
        return new CallReceiver(dispatchReceiver, extensionReceiver, type);
    }
    return receiver;
}
Also used : SyntheticFieldDescriptor(org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType) IElementType(com.intellij.psi.tree.IElementType) PrimitiveType(org.jetbrains.kotlin.builtins.PrimitiveType) Type(org.jetbrains.org.objectweb.asm.Type) ImportedFromObjectCallableDescriptor(org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor) ReceiverValue(org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue)

Example 3 with SyntheticFieldDescriptor

use of org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor in project kotlin by JetBrains.

the class BodyResolver method resolveFunctionBody.

private void resolveFunctionBody(@NotNull DataFlowInfo outerDataFlowInfo, @NotNull BindingTrace trace, @NotNull KtDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull LexicalScope scope, @Nullable Function1<LexicalScope, DataFlowInfo> beforeBlockBody, // Creates wrapper scope for header resolution if necessary (see resolveSecondaryConstructorBody)
@Nullable Function1<LexicalScope, LexicalScope> headerScopeFactory) {
    PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace);
    LexicalScope innerScope = FunctionDescriptorUtil.getFunctionInnerScope(scope, functionDescriptor, trace, overloadChecker);
    List<KtParameter> valueParameters = function.getValueParameters();
    List<ValueParameterDescriptor> valueParameterDescriptors = functionDescriptor.getValueParameters();
    LexicalScope headerScope = headerScopeFactory != null ? headerScopeFactory.invoke(innerScope) : innerScope;
    valueParameterResolver.resolveValueParameters(valueParameters, valueParameterDescriptors, headerScope, outerDataFlowInfo, trace);
    // Synthetic "field" creation
    if (functionDescriptor instanceof PropertyAccessorDescriptor && functionDescriptor.getExtensionReceiverParameter() == null) {
        PropertyAccessorDescriptor accessorDescriptor = (PropertyAccessorDescriptor) functionDescriptor;
        KtProperty property = (KtProperty) function.getParent();
        final SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property);
        innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null, LexicalScopeKind.PROPERTY_ACCESSOR_BODY, LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {

            @Override
            public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
                handler.addVariableDescriptor(fieldDescriptor);
                return Unit.INSTANCE;
            }
        });
        // Check parameter name shadowing
        for (KtParameter parameter : function.getValueParameters()) {
            if (SyntheticFieldDescriptor.NAME.equals(parameter.getNameAsName())) {
                trace.report(Errors.ACCESSOR_PARAMETER_NAME_SHADOWING.on(parameter));
            }
        }
    }
    DataFlowInfo dataFlowInfo = null;
    if (beforeBlockBody != null) {
        dataFlowInfo = beforeBlockBody.invoke(headerScope);
    }
    if (function.hasBody()) {
        expressionTypingServices.checkFunctionReturnType(innerScope, function, functionDescriptor, dataFlowInfo != null ? dataFlowInfo : outerDataFlowInfo, null, trace);
    }
    assert functionDescriptor.getReturnType() != null;
}
Also used : SyntheticFieldDescriptor(org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor) Function1(kotlin.jvm.functions.Function1) DataFlowInfo(org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)

Example 4 with SyntheticFieldDescriptor

use of org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor in project kotlin by JetBrains.

the class ExpressionCodegen method visitSimpleNameExpression.

@Override
public StackValue visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression, @NotNull StackValue receiver) {
    ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expression, bindingContext);
    DeclarationDescriptor descriptor;
    if (resolvedCall == null) {
        descriptor = bindingContext.get(REFERENCE_TARGET, expression);
    } else {
        if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
            VariableAsFunctionResolvedCall call = (VariableAsFunctionResolvedCall) resolvedCall;
            resolvedCall = call.getVariableCall();
        }
        descriptor = resolvedCall.getResultingDescriptor();
        //Check early if KCallableNameProperty is applicable to prevent closure generation
        StackValue intrinsicResult = applyIntrinsic(descriptor, KCallableNameProperty.class, resolvedCall, receiver);
        if (intrinsicResult != null)
            return intrinsicResult;
        receiver = StackValue.receiver(resolvedCall, receiver, this, null);
        if (descriptor instanceof FakeCallableDescriptorForObject) {
            descriptor = ((FakeCallableDescriptorForObject) descriptor).getReferencedDescriptor();
        }
    }
    assert descriptor != null : "Couldn't find descriptor for '" + expression.getText() + "'";
    descriptor = descriptor.getOriginal();
    boolean isSyntheticField = descriptor instanceof SyntheticFieldDescriptor;
    if (isSyntheticField) {
        descriptor = ((SyntheticFieldDescriptor) descriptor).getPropertyDescriptor();
    }
    StackValue intrinsicResult = applyIntrinsic(descriptor, IntrinsicPropertyGetter.class, resolvedCall, receiver);
    if (intrinsicResult != null)
        return intrinsicResult;
    if (descriptor instanceof PropertyDescriptor) {
        PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
        Collection<ExpressionCodegenExtension> codegenExtensions = ExpressionCodegenExtension.Companion.getInstances(state.getProject());
        if (!codegenExtensions.isEmpty() && resolvedCall != null) {
            ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(typeMapper, v);
            KotlinType returnType = propertyDescriptor.getReturnType();
            for (ExpressionCodegenExtension extension : codegenExtensions) {
                if (returnType != null) {
                    StackValue value = extension.applyProperty(receiver, resolvedCall, context);
                    if (value != null)
                        return value;
                }
            }
        }
        boolean directToField = isSyntheticField && contextKind() != OwnerKind.DEFAULT_IMPLS;
        ClassDescriptor superCallTarget = resolvedCall == null ? null : getSuperCallTarget(resolvedCall.getCall());
        if (directToField) {
            receiver = StackValue.receiverWithoutReceiverArgument(receiver);
        }
        return intermediateValueForProperty(propertyDescriptor, directToField, directToField, superCallTarget, false, receiver, resolvedCall);
    }
    if (descriptor instanceof TypeAliasDescriptor) {
        ClassDescriptor classDescriptor = ((TypeAliasDescriptor) descriptor).getClassDescriptor();
        if (classDescriptor == null) {
            throw new IllegalStateException("Type alias " + descriptor + " static member refernece should be rejected by type checker, " + "since there is no class corresponding to this type alias.");
        }
        descriptor = classDescriptor;
    }
    if (descriptor instanceof ClassDescriptor) {
        ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
        if (isObject(classDescriptor)) {
            return StackValue.singleton(classDescriptor, typeMapper);
        }
        if (isEnumEntry(classDescriptor)) {
            return StackValue.enumEntry(classDescriptor, typeMapper);
        }
        ClassDescriptor companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor();
        if (companionObjectDescriptor != null) {
            return StackValue.singleton(companionObjectDescriptor, typeMapper);
        }
        return StackValue.none();
    }
    StackValue localOrCaptured = findLocalOrCapturedValue(descriptor);
    if (localOrCaptured != null) {
        return localOrCaptured;
    }
    throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
}
Also used : BindingContext(org.jetbrains.kotlin.resolve.BindingContext) SyntheticFieldDescriptor(org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor) FakeCallableDescriptorForObject(org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject) SyntheticJavaPropertyDescriptor(org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType) ExpressionCodegenExtension(org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension)

Aggregations

SyntheticFieldDescriptor (org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor)4 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 IElementType (com.intellij.psi.tree.IElementType)1 Function1 (kotlin.jvm.functions.Function1)1 PrimitiveType (org.jetbrains.kotlin.builtins.PrimitiveType)1 ExpressionCodegenExtension (org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1 ImportedFromObjectCallableDescriptor (org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor)1 DataFlowInfo (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)1 FakeCallableDescriptorForObject (org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject)1 ReceiverValue (org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue)1 SyntheticJavaPropertyDescriptor (org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor)1 Type (org.jetbrains.org.objectweb.asm.Type)1