use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class ExpressionVisitor method setArgumentParameters.
/**
* Set up references from positional arguments to
* parameters for later use during type inference. This
* is only necessary here because in the case of an
* overloaded Java function or constructors, the
* overload has not been resolved the first time we
* visit the arguments. So we need to revisit them here
* with the fully-resolved overloaded version.
*
* @param that an invocation
* @param invoked the thing being invoked
*/
private void setArgumentParameters(Tree.InvocationExpression that, Declaration invoked) {
if (invoked instanceof Functional) {
Functional fun = (Functional) invoked;
List<ParameterList> pls = fun.getParameterLists();
if (!pls.isEmpty()) {
ParameterList pl = pls.get(0);
// no need to do named arg lists because
// they can't be used with overloaded decs
Tree.PositionalArgumentList pal = that.getPositionalArgumentList();
if (pal != null) {
List<Tree.PositionalArgument> args = pal.getPositionalArguments();
List<Parameter> params = pl.getParameters();
for (int i = 0, j = 0; i < args.size() && j < params.size(); i++) {
Tree.PositionalArgument arg = args.get(i);
Parameter param = params.get(j);
if (arg != null && param != null) {
arg.setParameter(param);
}
if (param == null || !param.isSequenced()) {
j++;
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class ExpressionVisitor method checkClassAliasParameters.
private void checkClassAliasParameters(Class alias, Tree.ClassDeclaration that, Tree.InvocationExpression ie) {
Tree.Primary primary = ie.getPrimary();
Tree.ExtendedTypeExpression smte = (Tree.ExtendedTypeExpression) primary;
Functional classOrConstructor = (Functional) smte.getDeclaration();
ParameterList cpl = classOrConstructor.getFirstParameterList();
ParameterList apl = alias.getParameterList();
if (cpl != null && apl != null) {
List<Parameter> cplps = cpl.getParameters();
List<Parameter> aplps = apl.getParameters();
int cps = cplps.size();
int aps = aplps.size();
if (cps != aps) {
that.getParameterList().addUnsupportedError("wrong number of initializer parameters declared by class alias: '" + alias.getName() + "'");
}
for (int i = 0; i < cps && i < aps; i++) {
Parameter ap = aplps.get(i);
Parameter cp = cplps.get(i);
Reference target = smte.getTarget();
FunctionOrValue apm = ap.getModel();
if (apm != null && target != null) {
Type pt = target.getTypedParameter(cp).getFullType();
Type apt = apm.getReference().getFullType();
if (!isTypeUnknown(pt) && !isTypeUnknown(apt) && !apt.isSubtypeOf(pt)) {
that.addUnsupportedError("alias parameter '" + ap.getName() + "' must be assignable to corresponding class parameter '" + cp.getName() + "'" + notAssignableMessage(apt, pt, that));
}
}
}
// temporary restrictions
checkAliasedClass(that, cpl, apl);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class ExpressionVisitor method checkAliasedClass.
private void checkAliasedClass(Tree.ClassDeclaration that, ParameterList cpl, ParameterList apl) {
// temporary restrictions
// TODO: all this can be removed once the backend
// implements full support for the new class
// alias stuff
Tree.InvocationExpression ie = that.getClassSpecifier().getInvocationExpression();
Tree.PositionalArgumentList pal = ie.getPositionalArgumentList();
if (pal != null) {
List<Tree.PositionalArgument> pas = pal.getPositionalArguments();
int cps = cpl.getParameters().size();
int aps = apl.getParameters().size();
int size = pas.size();
if (cps != size) {
pal.addUnsupportedError("wrong number of arguments for aliased class: '" + that.getDeclarationModel().getName() + "' has " + cps + " parameters");
}
for (int i = 0; i < size && i < cps && i < aps; i++) {
Tree.PositionalArgument pa = pas.get(i);
Parameter aparam = apl.getParameters().get(i);
Parameter cparam = cpl.getParameters().get(i);
if (pa instanceof Tree.ListedArgument) {
if (cparam.isSequenced()) {
pa.addUnsupportedError("argument to variadic parameter of aliased class must be spread");
}
Tree.ListedArgument la = (Tree.ListedArgument) pa;
Tree.Expression e = la.getExpression();
checkAliasArg(aparam, e);
} else if (pa instanceof Tree.SpreadArgument) {
if (!cparam.isSequenced()) {
pa.addUnsupportedError("argument to non-variadic parameter of aliased class may not be spread");
}
Tree.SpreadArgument sa = (Tree.SpreadArgument) pa;
Tree.Expression e = sa.getExpression();
checkAliasArg(aparam, e);
} else if (pa != null) {
pa.addUnsupportedError("argument to parameter or aliased class must be listed or spread");
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class RefinementVisitor method createRefiningParameter.
private void createRefiningParameter(final Reference rm, Function method, final Parameter p, ParameterList l, Tree.ParameterList tpl, int j, final Map<TypeParameter, Type> subs, Unit unit) {
if (tpl == null || tpl.getParameters().size() <= j) {
Parameter vp = new Parameter();
Value v = new Value();
vp.setModel(v);
v.setInitializerParameter(vp);
vp.setSequenced(p.isSequenced());
vp.setAtLeastOne(p.isAtLeastOne());
// vp.setDefaulted(p.isDefaulted());
vp.setName(p.getName());
v.setName(p.getName());
vp.setDeclaration(method);
v.setContainer(method);
v.setScope(method);
l.getParameters().add(vp);
v.setType(new LazyType(unit) {
private Type type() {
return rm.getTypedParameter(p).getFullType().substitute(subs, null);
}
@Override
public Type initQualifyingType() {
Type type = type();
return type == null ? null : type.getQualifyingType();
}
@Override
public Map<TypeParameter, Type> initTypeArguments() {
Type type = type();
return type == null ? null : type.getTypeArguments();
}
@Override
public TypeDeclaration initDeclaration() {
Type type = type();
return type == null ? null : type.getDeclaration();
}
@Override
public Map<TypeParameter, SiteVariance> getVarianceOverrides() {
Type type = type();
return type == null ? null : type.getVarianceOverrides();
}
});
} else {
Tree.Parameter tp = tpl.getParameters().get(j);
Parameter rp = tp.getParameterModel();
rp.setDefaulted(p.isDefaulted());
rp.setDeclaration(method);
l.getParameters().add(rp);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.Parameter that) {
Parameter p = that.getParameterModel();
boolean oip = inParameter;
inParameter = true;
Parameter op = parameter;
parameter = p;
super.visit(that);
parameter = op;
inParameter = oip;
if (p != null && p.getModel() == declaration) {
specify();
}
}
Aggregations