Search in sources :

Example 36 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class ParameterNameParser method parseMpl.

public void parseMpl(String input, Type type, Function method) {
    lexer.setup(input);
    this.unit = method.getUnit();
    ArrayList<ParameterList> lists = new ArrayList<>();
    lists.add(parseNameList(type, method));
    while (lexer.lookingAt(LEFT_PAREN)) {
        // mpl
        type = loader.getSimpleCallableReturnType(type);
        lists.add(parseNameList(type, method));
    }
    for (ParameterList parameterList : lists) {
        method.addParameterList(parameterList);
    }
    method.setType(loader.getSimpleCallableReturnType(type));
    if (!lexer.lookingAt(EOI)) {
        throw new ParameterNameParserException("Expected end of input" + System.lineSeparator() + input);
    }
}
Also used : ArrayList(java.util.ArrayList) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList)

Example 37 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class ParameterNameParser method parseNameList.

private ParameterList parseNameList(Type type, Function method) {
    ParameterList pl = new ParameterList();
    List<Parameter> parameters = pl.getParameters();
    // startParameterList();
    lexer.eat(LEFT_PAREN);
    if (!lexer.lookingAt(RIGHT_PAREN)) {
        Iterator<Type> ct = loader.getSimpleCallableArgumentTypes(type).iterator();
        if (!ct.hasNext()) {
            throw new ParameterNameParserException("Too few parameter types");
        }
        parameters.add(parseName(ct.next(), method));
        // addParameter()
        while (lexer.lookingAt(COMMA)) {
            lexer.eat();
            if (!ct.hasNext()) {
                throw new ParameterNameParserException("Too few parameter types");
            }
            parameters.add(parseName(ct.next(), method));
        }
        if (ct.hasNext()) {
            throw new ParameterNameParserException("Too many parameter types");
        }
    }
    lexer.eat(RIGHT_PAREN);
    // endParameterList();
    return pl;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter)

Example 38 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class ExpressionVisitor method inferrableAnyway.

private static boolean inferrableAnyway(Declaration dec) {
    if (dec != null && dec.isParameterized() && dec instanceof Functional) {
        Functional fd = (Functional) dec;
        ParameterList list = fd.getFirstParameterList();
        return list != null && list.getParameters().isEmpty();
    } else {
        return false;
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList)

Example 39 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class ExpressionVisitor method inferParameterTypesFromCallableParameter.

private boolean inferParameterTypesFromCallableParameter(Reference pr, Parameter param, Tree.FunctionArgument anon, boolean error) {
    boolean result = true;
    Declaration declaration = param.getDeclaration();
    Functional fun = (Functional) param.getModel();
    List<ParameterList> fpls = fun.getParameterLists();
    List<Tree.ParameterList> apls = anon.getParameterLists();
    if (!fpls.isEmpty() && !apls.isEmpty()) {
        List<Parameter> fps = fpls.get(0).getParameters();
        List<Tree.Parameter> aps = apls.get(0).getParameters();
        for (int j = 0; j < fps.size() && j < aps.size(); j++) {
            Parameter fp = fps.get(j);
            Tree.Parameter ap = aps.get(j);
            if (isInferrableParameter(ap)) {
                result = result & createInferredParameter(anon, declaration, ap, ap.getParameterModel(), pr.getTypedParameter(fp).getType(), fp.getModel(), error);
            }
        }
    }
    return result;
}
Also used : 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) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) 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) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint)

Example 40 with ParameterList

use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.

the class ExpressionVisitor method inferrableParameters.

/**
 * Get the parameters of a callable parameter, or, if
 * the given parameter is a value parameter of type
 * X(Y), a single faked parameter with the name 'it'.
 */
private List<Parameter> inferrableParameters(Parameter param) {
    FunctionOrValue model = param.getModel();
    if (model instanceof Function) {
        Function fun = (Function) model;
        ParameterList fpl = fun.getFirstParameterList();
        return fpl == null ? null : fpl.getParameters();
    } else if (model instanceof Value) {
        Type type = param.getType();
        if (type != null) {
            Type callable = intersectionType(type.resolveAliases(), appliedType(unit.getCallableDeclaration(), unit.getAnythingType(), unit.getNothingType()), unit);
            if (callable.isCallable()) {
                Type tup = unit.getCallableTuple(callable);
                int min = unit.getTupleMinimumLength(tup);
                int max = unit.getTupleMaximumLength(tup);
                if (min == 1 || max == 1) {
                    Parameter p = new Parameter();
                    p.setName("it");
                    return Collections.<Parameter>singletonList(p);
                } else if (min == 0) {
                    return Collections.<Parameter>emptyList();
                }
            }
        }
        return null;
    } else {
        return null;
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) 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) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) 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) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)69 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)47 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)25 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)24 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)24 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)23 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)22 Function (org.eclipse.ceylon.model.typechecker.model.Function)21 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)20 Value (org.eclipse.ceylon.model.typechecker.model.Value)20 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)19 ArrayList (java.util.ArrayList)16 AnalyzerUtil.getMatchingParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter)12 AnalyzerUtil.getUnspecifiedParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter)12 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)12 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)12 Class (org.eclipse.ceylon.model.typechecker.model.Class)11 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)10 HashMap (java.util.HashMap)9