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));
}
}
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);
}
}
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;
}
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;
}
}
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();
}
Aggregations