Search in sources :

Example 21 with Reference

use of org.eclipse.ceylon.model.typechecker.model.Reference 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)

Example 22 with Reference

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

the class PrintVisitor method print.

private void print(Node node) {
    print(node.getText());
    print(" [" + node.getNodeType() + "]");
    if (node.getToken() != null) {
        print(" (" + node.getLocation() + ")");
    }
    if (node instanceof Tree.Term) {
        Type type = ((Tree.Term) node).getTypeModel();
        if (type != null) {
            print(" : " + type.asString() + "");
        }
    }
    if (node instanceof Tree.ComprehensionClause) {
        Type type = ((Tree.ComprehensionClause) node).getTypeModel();
        if (type != null) {
            print(" : " + type.asString() + "");
        }
    }
    if (node instanceof Tree.Type) {
        Type type = ((Tree.Type) node).getTypeModel();
        if (type != null) {
            print(" : " + type.asString() + "");
        }
    }
    if (node instanceof Tree.TypeArguments) {
        List<Type> types = ((Tree.TypeArguments) node).getTypeModels();
        if (types != null && !types.isEmpty()) {
            print(" : <");
            int i = 0;
            for (Type pt : types) {
                if (pt != null) {
                    print(pt.asString());
                }
                if (++i != types.size()) {
                    print(", ");
                }
            }
            print(">");
        }
    }
    if (node instanceof Tree.MemberOrTypeExpression) {
        Reference t = ((Tree.MemberOrTypeExpression) node).getTarget();
        Declaration d = ((Tree.MemberOrTypeExpression) node).getDeclaration();
        if (t != null) {
            print(" : " + t.asString() + "");
        }
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.Outer) {
        Declaration d = ((Tree.Outer) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.SelfExpression) {
        Declaration d = ((Tree.SelfExpression) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.Declaration) {
        Declaration d = ((Tree.Declaration) node).getDeclarationModel();
        if (d != null) {
            if (d.isCaptured() || d.isJsCaptured()) {
                print("[captured]");
            }
            print(" : " + d);
            Declaration rd = d.getRefinedDeclaration();
            if (rd != null && !rd.equals(d)) {
                Declaration container = (Declaration) rd.getContainer();
                print(" (refines " + container.getName() + "." + rd.getName() + ")");
            }
        }
    }
    if (node instanceof Tree.SpecifierStatement) {
        Declaration d = ((Tree.SpecifierStatement) node).getDeclaration();
        if (d != null) {
            print(" : " + d);
        }
        if (((Tree.SpecifierStatement) node).getRefinement()) {
            Declaration rd = d.getRefinedDeclaration();
            if (rd != null && !rd.equals(d)) {
                Declaration container = (Declaration) rd.getContainer();
                print(" (refines " + container.getName() + "." + rd.getName() + ")");
            }
        }
    }
    if (node instanceof Tree.SimpleType) {
        Declaration d = ((Tree.SimpleType) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.ImportMemberOrType) {
        Declaration d = ((Tree.ImportMemberOrType) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.Return) {
        Declaration d = ((Tree.Return) node).getDeclaration();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.PositionalArgument) {
        Parameter p = ((Tree.PositionalArgument) node).getParameter();
        if (p != null) {
            print(" : " + p);
        }
    }
    if (node instanceof Tree.NamedArgument) {
        Parameter p = ((Tree.NamedArgument) node).getParameter();
        if (p != null) {
            print(" : " + p);
        }
    }
    if (node instanceof Tree.SequencedArgument) {
        Parameter p = ((Tree.SequencedArgument) node).getParameter();
        if (p != null) {
            print(" : " + p);
        }
    }
    if (!node.getErrors().isEmpty()) {
        String icon = " [!]";
        for (Message e : node.getErrors()) {
            if (!(e instanceof UsageWarning)) {
                icon = " [X]";
            }
        }
        print(icon + node.getErrors());
    }
}
Also used : Message(org.eclipse.ceylon.compiler.typechecker.tree.Message) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Type(org.eclipse.ceylon.model.typechecker.model.Type) UsageWarning(org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 23 with Reference

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

the class ClassImpl method getDispatch.

ConstructorDispatch<Type, Arguments> getDispatch() {
    if (!initialized) {
        synchronized (this) {
            if (!initialized) {
                checkConstructor();
                Reference reference;
                if (!hasConstructors() && !hasEnumerated()) {
                    reference = producedType;
                } else {
                    reference = ((org.eclipse.ceylon.model.typechecker.model.Class) declaration.declaration).getDefaultConstructor().appliedReference(producedType, null);
                }
                this.dispatch = new ConstructorDispatch<Type, Arguments>(reference, this, null, ((Class) producedType.getDeclaration()).getFirstParameterList().getParameters(), instance);
                this.initialized = true;
            }
        }
    }
    return dispatch;
}
Also used : Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 24 with Reference

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

the class ClassOrInterfaceImpl method addInterfaceIfCompatible.

@SuppressWarnings({ "hiding" })
private <Container, Type> void addInterfaceIfCompatible(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, ArrayList<ceylon.language.meta.model.MemberInterface<? super Container, ? extends Type>> members, InterfaceDeclarationImpl decl, org.eclipse.ceylon.model.typechecker.model.Type qualifyingType, ClassOrInterfaceImpl<Container> containerMetamodel, org.eclipse.ceylon.model.typechecker.model.Type reifiedType) {
    // now the types
    Reference producedReference = decl.declaration.appliedReference(qualifyingType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
    org.eclipse.ceylon.model.typechecker.model.Type type = producedReference.getType();
    if (!type.isSubtypeOf(reifiedType))
        return;
    // it's compatible!
    members.add(decl.<Container, Type>memberInterfaceApply($reifiedContainer, $reifiedType, containerMetamodel));
}
Also used : Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)

Example 25 with Reference

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

the class ClassOrInterfaceImpl method addAttributeIfCompatible.

private <Container, Get, Set> void addAttributeIfCompatible(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, ArrayList<ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>> members, ValueDeclarationImpl decl, org.eclipse.ceylon.model.typechecker.model.Type qualifyingType, ceylon.language.meta.model.Type<Container> qualifyingMetamodel, org.eclipse.ceylon.model.typechecker.model.Type reifiedGet, org.eclipse.ceylon.model.typechecker.model.Type reifiedSet) {
    // now the types
    Reference producedReference = decl.declaration.appliedReference(qualifyingType, NO_TYPE_ARGS);
    org.eclipse.ceylon.model.typechecker.model.Type type = producedReference.getType();
    if (!type.isSubtypeOf(reifiedGet))
        return;
    org.eclipse.ceylon.model.typechecker.model.Type setType = decl.getVariable() ? type : decl.declaration.getUnit().getNothingType();
    if (!reifiedSet.isSubtypeOf(setType))
        return;
    // it's compatible!
    members.add(decl.<Container, Get, Set>memberApply($reifiedContainer, $reifiedGet, $reifiedSet, qualifyingMetamodel));
}
Also used : Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)

Aggregations

Reference (org.eclipse.ceylon.model.typechecker.model.Reference)42 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)28 Type (org.eclipse.ceylon.model.typechecker.model.Type)25 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)22 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)21 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)20 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)20 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)17 Function (org.eclipse.ceylon.model.typechecker.model.Function)13 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)12 ArrayList (java.util.ArrayList)11 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)11 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)11 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)10 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)10 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)10 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)9 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)9 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)8 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)8