Search in sources :

Example 91 with Parameter

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++;
                    }
                }
            }
        }
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.getUnspecifiedParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getMatchingParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint)

Example 92 with Parameter

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);
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) AnalyzerUtil.getUnspecifiedParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getMatchingParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 93 with Parameter

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");
            }
        }
    }
}
Also used : PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint) TreeUtil.isInstantiationExpression(org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.isInstantiationExpression) TreeUtil.isEffectivelyBaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.isEffectivelyBaseMemberExpression) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getUnspecifiedParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getMatchingParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument)

Example 94 with Parameter

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);
    }
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.erasedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.erasedType) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 95 with Parameter

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();
    }
}
Also used : Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter)

Aggregations

Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)160 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)123 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)71 Type (org.eclipse.ceylon.model.typechecker.model.Type)71 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)57 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)48 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)45 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)45 Function (org.eclipse.ceylon.model.typechecker.model.Function)43 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)42 Value (org.eclipse.ceylon.model.typechecker.model.Value)42 ArrayList (java.util.ArrayList)38 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)30 AnalyzerUtil.getMatchingParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter)27 AnalyzerUtil.getUnspecifiedParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter)27 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)27 Class (org.eclipse.ceylon.model.typechecker.model.Class)23 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)21 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)19 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)19