use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.InitializerParameter that) {
super.visit(that);
Parameter p = that.getParameterModel();
if (p != null) {
Declaration a = that.getScope().getDirectMember(p.getName(), null, false);
if (a != null && a == declaration) {
specify();
hasParameter = true;
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeArgumentInference method inferTypeArgumentFromNamedArgs.
private Type inferTypeArgumentFromNamedArgs(TypeParameter tp, ParameterList parameters, Type qt, Tree.NamedArgumentList nal, Declaration invoked) {
boolean findingUpperBounds = isEffectivelyContravariant(tp, invoked, specifiedParameters(nal, parameters), false);
List<NamedArgument> namedArgs = nal.getNamedArguments();
Set<Parameter> foundParameters = new HashSet<Parameter>();
List<Type> inferredTypes = new ArrayList<Type>(namedArgs.size());
for (Tree.NamedArgument arg : namedArgs) {
inferTypeArgFromNamedArg(arg, tp, qt, parameters, findingUpperBounds, inferredTypes, invoked, foundParameters);
}
Parameter sp = getUnspecifiedParameter(null, parameters, foundParameters);
if (sp != null) {
Tree.SequencedArgument sarg = nal.getSequencedArgument();
inferTypeArgFromSequencedArg(sarg, tp, sp, findingUpperBounds, inferredTypes, sarg);
}
return unionOrIntersection(findingUpperBounds, inferredTypes);
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeArgumentInference method inferFunctionRefTypeArgs.
/**
* Infer type arguments for a direct function
* ref (i.e. not a value ref with a type
* constructor type) that occurs as an argument
* to a callable parameter.
*/
private List<Type> inferFunctionRefTypeArgs(Tree.StaticMemberOrTypeExpression smte, Type receiverType, boolean secondList, Declaration reference, List<TypeParameter> typeParameters, TypedReference paramTypedRef, Declaration paramDec, Declaration parameterizedDec) {
Reference arg = appliedReference(smte);
Functional fun = (Functional) reference;
List<ParameterList> apls = fun.getParameterLists();
Functional pfun = (Functional) paramDec;
List<ParameterList> ppls = pfun.getParameterLists();
if (apls.isEmpty() || ppls.isEmpty()) {
// TODO: to give a nicer error
return null;
} else {
ParameterList aplf = apls.get(secondList ? 1 : 0);
ParameterList pplf = ppls.get(0);
List<Parameter> apl = aplf.getParameters();
List<Parameter> ppl = pplf.getParameters();
boolean[] specifiedParams = specifiedParameters(apl.size(), ppl.size());
List<Type> inferredTypes = new ArrayList<Type>(typeParameters.size());
for (TypeParameter tp : typeParameters) {
boolean findUpperBounds = isEffectivelyContravariant(tp, reference, specifiedParams, secondList);
Type it = inferFunctionRefTypeArg(smte, tp, typeParameters, paramTypedRef, parameterizedDec, arg, apl, ppl, findUpperBounds);
inferredTypes.add(it);
}
return constrainInferredTypes(typeParameters, inferredTypes, receiverType, reference);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeArgumentInference method inferFunctionRefTypeArg.
/**
* Infer the type arguments for a reference to a
* generic function that occurs as a parameter in
* an invocation. This implementation is used when
* have a direct ref to the actual declaration.
*/
private Type inferFunctionRefTypeArg(Tree.StaticMemberOrTypeExpression smte, TypeParameter tp, List<TypeParameter> typeParams, TypedReference param, Declaration pd, Reference arg, List<Parameter> apl, List<Parameter> ppl, boolean findingUpperBounds) {
List<Type> list = new ArrayList<Type>();
// first look at the parameter types
for (int i = 0; i < apl.size() && i < ppl.size(); i++) {
Parameter ap = apl.get(i);
Parameter pp = ppl.get(i);
Type type = param.getTypedParameter(pp).getFullType();
Type template = arg.getTypedParameter(ap).getFullType();
Type it = inferTypeArg(tp, template, type, findingUpperBounds, smte);
if (!(isTypeUnknown(it) || // it.involvesTypeParameters(typeParams) ||
involvesTypeParams(pd, it))) {
addToUnionOrIntersection(findingUpperBounds, list, it);
}
}
// now look at the return type
Type it = inferTypeArg(tp, arg.getType(), param.getType(), false, true, findingUpperBounds, new ArrayList<TypeParameter>(), smte);
if (!(isTypeUnknown(it) || // it.involvesTypeParameters(typeParams) ||
involvesTypeParams(pd, it))) {
addToUnionOrIntersection(findingUpperBounds, list, it);
}
return unionOrIntersection(findingUpperBounds, list);
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeArgumentInference method specifiedParameters.
private static boolean[] specifiedParameters(Tree.PositionalArgumentList args, ParameterList parameters) {
List<Parameter> params = parameters.getParameters();
boolean[] specified = new boolean[params.size()];
for (Tree.PositionalArgument arg : args.getPositionalArguments()) {
Parameter p = arg.getParameter();
if (p != null) {
int loc = params.indexOf(p);
if (loc >= 0) {
specified[loc] = true;
}
}
}
return specified;
}
Aggregations