use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeArgumentInference method specifiedParameters.
private static boolean[] specifiedParameters(Tree.NamedArgumentList args, ParameterList parameters) {
List<Parameter> params = parameters.getParameters();
boolean[] specified = new boolean[params.size()];
for (Tree.NamedArgument arg : args.getNamedArguments()) {
Parameter p = arg.getParameter();
if (p != null) {
int loc = params.indexOf(p);
if (loc >= 0) {
specified[loc] = true;
}
}
}
Tree.SequencedArgument arg = args.getSequencedArgument();
if (arg != null) {
Parameter p = arg.getParameter();
if (p != null) {
int loc = params.indexOf(p);
if (loc >= 0) {
specified[loc] = true;
}
}
}
return specified;
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeArgumentInference method inferTypeArgFromNamedArg.
private void inferTypeArgFromNamedArg(Tree.NamedArgument arg, TypeParameter tp, Type receiverType, ParameterList parameters, boolean findingUpperBounds, List<Type> inferredTypes, Declaration invoked, Set<Parameter> foundParameters) {
Type type = null;
if (arg instanceof Tree.SpecifiedArgument) {
Tree.SpecifiedArgument sa = (Tree.SpecifiedArgument) arg;
Tree.SpecifierExpression se = sa.getSpecifierExpression();
Tree.Expression e = se.getExpression();
if (e != null) {
type = e.getTypeModel();
}
} else if (arg instanceof Tree.TypedArgument) {
// copy/pasted from checkNamedArgument()
Tree.TypedArgument ta = (Tree.TypedArgument) arg;
type = ta.getDeclarationModel().getTypedReference().getFullType();
}
if (type != null) {
Parameter parameter = getMatchingParameter(parameters, arg, foundParameters);
if (parameter != null) {
foundParameters.add(parameter);
Type paramType = parameterType(receiverType, parameter, invoked);
addToUnionOrIntersection(findingUpperBounds, inferredTypes, inferTypeArg(tp, paramType, type, findingUpperBounds, arg));
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.InitializerParameter that) {
super.visit(that);
Parameter p = that.getParameterModel();
String name = p.getName();
Declaration a = that.getScope().getDirectMember(name, null, false);
if (a == null) {
// Now done in ExpressionVisitor!
// that.addError("parameter is not defined: '" + p.getName() + "'");
} else if (!isLegalParameter(a)) {
that.addError("parameter is not a reference value or function: '" + name + "' is not a value or function");
} else {
if (a.isFormal()) {
that.addError("parameter is a formal attribute: '" + name + "' is annotated 'formal'", 320);
}
FunctionOrValue mov = (FunctionOrValue) a;
if (mov.getInitializerParameter() != null) {
that.addError("duplicate parameter: '" + name + "' already occurs in the parameter list");
} else {
mov.setInitializerParameter(p);
p.setModel(mov);
}
}
/*if (isGeneric(a)) {
that.addError("parameter declaration is generic: '" +
name + "' may not declare type parameters");
}*/
if (p.isDefaulted()) {
checkDefaultArg(that.getSpecifierExpression(), p);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.AnyAttribute that) {
super.visit(that);
Tree.Type type = that.getType();
if (type instanceof Tree.SequencedType) {
Value v = (Value) that.getDeclarationModel();
Parameter p = v.getInitializerParameter();
if (p == null) {
type.addError("value is not a parameter, so may not be variadic: '" + v.getName() + "'");
} else {
p.setSequenced(true);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypesDirectly.
/**
* Infer parameter types of anonymous function arguments
* in a direct invocation with positional arguments.
*/
private boolean[] inferParameterTypesDirectly(Tree.PositionalArgumentList pal, Tree.MemberOrTypeExpression mte, Declaration dec, boolean error) {
List<Tree.PositionalArgument> args = pal.getPositionalArguments();
int argCount = args.size();
boolean[] delayed = new boolean[argCount];
Functional fun = (Functional) dec;
List<ParameterList> pls = fun.getParameterLists();
if (!pls.isEmpty()) {
List<Parameter> params = pls.get(0).getParameters();
Reference reference = getInvokedProducedReference(dec, mte);
int paramsSize = params.size();
for (int i = 0, j = 0; i < argCount && j < paramsSize; i++) {
Parameter param = params.get(j);
Tree.PositionalArgument arg = args.get(i);
arg.setParameter(param);
if (arg instanceof Tree.ListedArgument) {
Tree.ListedArgument la = (Tree.ListedArgument) arg;
delayed[i] = !inferParameterTypes(reference, param, la.getExpression(), param.isSequenced(), error);
}
if (!param.isSequenced()) {
j++;
}
}
}
return delayed;
}
Aggregations