Search in sources :

Example 1 with ValueArgument

use of org.jetbrains.kotlin.psi.ValueArgument in project kotlin by JetBrains.

the class ResolvedCallImpl method setResultingSubstitutor.

@Override
public void setResultingSubstitutor(@NotNull TypeSubstitutor substitutor) {
    resultingDescriptor = (D) candidateDescriptor.substitute(substitutor);
    assert resultingDescriptor != null : candidateDescriptor;
    for (TypeParameterDescriptor typeParameter : candidateDescriptor.getTypeParameters()) {
        TypeProjection typeArgumentProjection = substitutor.getSubstitution().get(typeParameter.getDefaultType());
        if (typeArgumentProjection != null) {
            typeArguments.put(typeParameter, typeArgumentProjection.getType());
        }
    }
    if (candidateDescriptor.getValueParameters().isEmpty())
        return;
    List<ValueParameterDescriptor> substitutedParameters = resultingDescriptor.getValueParameters();
    Collection<Map.Entry<ValueParameterDescriptor, ResolvedValueArgument>> valueArgumentsBeforeSubstitution = new SmartList<Map.Entry<ValueParameterDescriptor, ResolvedValueArgument>>(valueArguments.entrySet());
    valueArguments.clear();
    for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : valueArgumentsBeforeSubstitution) {
        ValueParameterDescriptor substitutedVersion = substitutedParameters.get(entry.getKey().getIndex());
        assert substitutedVersion != null : entry.getKey();
        valueArguments.put(substitutedVersion, entry.getValue());
    }
    Collection<Map.Entry<ValueArgument, ArgumentMatchImpl>> unsubstitutedArgumentMappings = new SmartList<Map.Entry<ValueArgument, ArgumentMatchImpl>>(argumentToParameterMap.entrySet());
    argumentToParameterMap.clear();
    for (Map.Entry<ValueArgument, ArgumentMatchImpl> entry : unsubstitutedArgumentMappings) {
        ArgumentMatchImpl argumentMatch = entry.getValue();
        ValueParameterDescriptor valueParameterDescriptor = argumentMatch.getValueParameter();
        ValueParameterDescriptor substitutedVersion = substitutedParameters.get(valueParameterDescriptor.getIndex());
        assert substitutedVersion != null : valueParameterDescriptor;
        argumentToParameterMap.put(entry.getKey(), argumentMatch.replaceValueParameter(substitutedVersion));
    }
}
Also used : TypeParameterDescriptor(org.jetbrains.kotlin.descriptors.TypeParameterDescriptor) TypeProjection(org.jetbrains.kotlin.types.TypeProjection) ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) ValueParameterDescriptor(org.jetbrains.kotlin.descriptors.ValueParameterDescriptor) SmartList(com.intellij.util.SmartList)

Example 2 with ValueArgument

use of org.jetbrains.kotlin.psi.ValueArgument in project kotlin by JetBrains.

the class TailRecursionCodegen method assignParameterValues.

private void assignParameterValues(CallableDescriptor fd, CallableMethod callableMethod, List<ResolvedValueArgument> valueArguments) {
    List<Type> types = callableMethod.getValueParameterTypes();
    for (ValueParameterDescriptor parameterDescriptor : Lists.reverse(fd.getValueParameters())) {
        ResolvedValueArgument arg = valueArguments.get(parameterDescriptor.getIndex());
        Type type = types.get(parameterDescriptor.getIndex());
        if (arg instanceof ExpressionValueArgument) {
            ExpressionValueArgument ev = (ExpressionValueArgument) arg;
            ValueArgument argument = ev.getValueArgument();
            KtExpression argumentExpression = argument == null ? null : argument.getArgumentExpression();
            if (argumentExpression instanceof KtSimpleNameExpression) {
                ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(argumentExpression, state.getBindingContext());
                if (resolvedCall != null && resolvedCall.getResultingDescriptor().equals(parameterDescriptor.getOriginal())) {
                    // do nothing: we shouldn't store argument to itself again
                    AsmUtil.pop(v, type);
                    continue;
                }
            }
        //assign the parameter below
        } else if (arg instanceof DefaultValueArgument) {
            AsmUtil.pop(v, type);
            DefaultParameterValueLoader.DEFAULT.genValue(parameterDescriptor, codegen).put(type, v);
        } else if (arg instanceof VarargValueArgument) {
        // assign the parameter below
        } else {
            throw new UnsupportedOperationException("Unknown argument type: " + arg + " in " + fd);
        }
        store(parameterDescriptor, type);
    }
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) KtExpression(org.jetbrains.kotlin.psi.KtExpression) KtSimpleNameExpression(org.jetbrains.kotlin.psi.KtSimpleNameExpression) ValueParameterDescriptor(org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)

Example 3 with ValueArgument

use of org.jetbrains.kotlin.psi.ValueArgument in project kotlin by JetBrains.

the class DataFlowInfoForArgumentsImpl method updateInfo.

@Override
public void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo dataFlowInfo) {
    ValueArgument next = nextArgument == null ? null : nextArgument.get(valueArgument);
    if (next != null) {
        if (infoMap == null) {
            infoMap = new HashMap<ValueArgument, DataFlowInfo>();
        }
        infoMap.put(next, dataFlowInfo);
        return;
    }
    //TODO assert resultInfo == null
    resultInfo = dataFlowInfo;
}
Also used : ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) DataFlowInfo(org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)

Example 4 with ValueArgument

use of org.jetbrains.kotlin.psi.ValueArgument in project kotlin by JetBrains.

the class DataFlowInfoForArgumentsImpl method initNextArgMap.

private void initNextArgMap(@NotNull List<? extends ValueArgument> valueArguments) {
    Iterator<? extends ValueArgument> iterator = valueArguments.iterator();
    ValueArgument prev = null;
    while (iterator.hasNext()) {
        ValueArgument argument = iterator.next();
        if (prev != null) {
            if (nextArgument == null) {
                nextArgument = new HashMap<ValueArgument, ValueArgument>();
            }
            nextArgument.put(prev, argument);
        }
        prev = argument;
    }
}
Also used : ValueArgument(org.jetbrains.kotlin.psi.ValueArgument)

Example 5 with ValueArgument

use of org.jetbrains.kotlin.psi.ValueArgument in project kotlin by JetBrains.

the class VarargValueArgument method toString.

@Override
public String toString() {
    StringBuilder builder = new StringBuilder("vararg:{");
    for (Iterator<ValueArgument> iterator = arguments.iterator(); iterator.hasNext(); ) {
        ValueArgument valueArgument = iterator.next();
        KtExpression expression = valueArgument.getArgumentExpression();
        builder.append(expression == null ? "no expression" : expression.getText());
        if (iterator.hasNext()) {
            builder.append(", ");
        }
    }
    return builder.append("}").toString();
}
Also used : ValueArgument(org.jetbrains.kotlin.psi.ValueArgument) KtExpression(org.jetbrains.kotlin.psi.KtExpression)

Aggregations

ValueArgument (org.jetbrains.kotlin.psi.ValueArgument)7 KtExpression (org.jetbrains.kotlin.psi.KtExpression)4 ValueParameterDescriptor (org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)3 Type (org.jetbrains.org.objectweb.asm.Type)2 SmartList (com.intellij.util.SmartList)1 NotNull (org.jetbrains.annotations.NotNull)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 TypeParameterDescriptor (org.jetbrains.kotlin.descriptors.TypeParameterDescriptor)1 KtSimpleNameExpression (org.jetbrains.kotlin.psi.KtSimpleNameExpression)1 ExpressionValueArgument (org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument)1 ResolvedValueArgument (org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument)1 DataFlowInfo (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)1 TypeProjection (org.jetbrains.kotlin.types.TypeProjection)1