Search in sources :

Example 56 with Parameter

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;
}
Also used : NamedArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.NamedArgument) 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) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 57 with Parameter

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));
        }
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) 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)

Example 58 with Parameter

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);
    }
}
Also used : Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 59 with Parameter

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);
        }
    }
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Example 60 with Parameter

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

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