Search in sources :

Example 96 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.InitializerParameter that) {
    super.visit(that);
    Parameter p = that.getParameterModel();
    if (p != null) {
        Declaration a = that.getScope().getDirectMember(p.getName(), null, false);
        if (a != null && a == declaration) {
            specify();
            hasParameter = true;
        }
    }
}
Also used : Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 97 with Parameter

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

the class TypeArgumentInference method inferTypeArgumentFromNamedArgs.

private Type inferTypeArgumentFromNamedArgs(TypeParameter tp, ParameterList parameters, Type qt, Tree.NamedArgumentList nal, Declaration invoked) {
    boolean findingUpperBounds = isEffectivelyContravariant(tp, invoked, specifiedParameters(nal, parameters), false);
    List<NamedArgument> namedArgs = nal.getNamedArguments();
    Set<Parameter> foundParameters = new HashSet<Parameter>();
    List<Type> inferredTypes = new ArrayList<Type>(namedArgs.size());
    for (Tree.NamedArgument arg : namedArgs) {
        inferTypeArgFromNamedArg(arg, tp, qt, parameters, findingUpperBounds, inferredTypes, invoked, foundParameters);
    }
    Parameter sp = getUnspecifiedParameter(null, parameters, foundParameters);
    if (sp != null) {
        Tree.SequencedArgument sarg = nal.getSequencedArgument();
        inferTypeArgFromSequencedArg(sarg, tp, sp, findingUpperBounds, inferredTypes, sarg);
    }
    return unionOrIntersection(findingUpperBounds, inferredTypes);
}
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) NamedArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.NamedArgument) ArrayList(java.util.ArrayList) 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) NamedArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.NamedArgument) HashSet(java.util.HashSet)

Example 98 with Parameter

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

the class TypeArgumentInference method inferFunctionRefTypeArgs.

/**
 * Infer type arguments for a direct function
 * ref (i.e. not a value ref with a type
 * constructor type) that occurs as an argument
 * to a callable parameter.
 */
private List<Type> inferFunctionRefTypeArgs(Tree.StaticMemberOrTypeExpression smte, Type receiverType, boolean secondList, Declaration reference, List<TypeParameter> typeParameters, TypedReference paramTypedRef, Declaration paramDec, Declaration parameterizedDec) {
    Reference arg = appliedReference(smte);
    Functional fun = (Functional) reference;
    List<ParameterList> apls = fun.getParameterLists();
    Functional pfun = (Functional) paramDec;
    List<ParameterList> ppls = pfun.getParameterLists();
    if (apls.isEmpty() || ppls.isEmpty()) {
        // TODO: to give a nicer error
        return null;
    } else {
        ParameterList aplf = apls.get(secondList ? 1 : 0);
        ParameterList pplf = ppls.get(0);
        List<Parameter> apl = aplf.getParameters();
        List<Parameter> ppl = pplf.getParameters();
        boolean[] specifiedParams = specifiedParameters(apl.size(), ppl.size());
        List<Type> inferredTypes = new ArrayList<Type>(typeParameters.size());
        for (TypeParameter tp : typeParameters) {
            boolean findUpperBounds = isEffectivelyContravariant(tp, reference, specifiedParams, secondList);
            Type it = inferFunctionRefTypeArg(smte, tp, typeParameters, paramTypedRef, parameterizedDec, arg, apl, ppl, findUpperBounds);
            inferredTypes.add(it);
        }
        return constrainInferredTypes(typeParameters, inferredTypes, receiverType, reference);
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) 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) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) ArrayList(java.util.ArrayList) 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)

Example 99 with Parameter

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

the class TypeArgumentInference method inferFunctionRefTypeArg.

/**
 * Infer the type arguments for a reference to a
 * generic function that occurs as a parameter in
 * an invocation. This implementation is used when
 * have a direct ref to the actual declaration.
 */
private Type inferFunctionRefTypeArg(Tree.StaticMemberOrTypeExpression smte, TypeParameter tp, List<TypeParameter> typeParams, TypedReference param, Declaration pd, Reference arg, List<Parameter> apl, List<Parameter> ppl, boolean findingUpperBounds) {
    List<Type> list = new ArrayList<Type>();
    // first look at the parameter types
    for (int i = 0; i < apl.size() && i < ppl.size(); i++) {
        Parameter ap = apl.get(i);
        Parameter pp = ppl.get(i);
        Type type = param.getTypedParameter(pp).getFullType();
        Type template = arg.getTypedParameter(ap).getFullType();
        Type it = inferTypeArg(tp, template, type, findingUpperBounds, smte);
        if (!(isTypeUnknown(it) || // it.involvesTypeParameters(typeParams) ||
        involvesTypeParams(pd, it))) {
            addToUnionOrIntersection(findingUpperBounds, list, it);
        }
    }
    // now look at the return type
    Type it = inferTypeArg(tp, arg.getType(), param.getType(), false, true, findingUpperBounds, new ArrayList<TypeParameter>(), smte);
    if (!(isTypeUnknown(it) || // it.involvesTypeParameters(typeParams) ||
    involvesTypeParams(pd, it))) {
        addToUnionOrIntersection(findingUpperBounds, list, it);
    }
    return unionOrIntersection(findingUpperBounds, list);
}
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) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) ArrayList(java.util.ArrayList) 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 100 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.PositionalArgumentList args, ParameterList parameters) {
    List<Parameter> params = parameters.getParameters();
    boolean[] specified = new boolean[params.size()];
    for (Tree.PositionalArgument arg : args.getPositionalArguments()) {
        Parameter p = arg.getParameter();
        if (p != null) {
            int loc = params.indexOf(p);
            if (loc >= 0) {
                specified[loc] = true;
            }
        }
    }
    return specified;
}
Also used : 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) 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