Search in sources :

Example 51 with Type

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

the class TypePrinter method abbreviateEntry.

public static boolean abbreviateEntry(Type pt) {
    if (pt.isEntry() && pt.getTypeArgumentList().size() == 2) {
        Unit unit = pt.getDeclaration().getUnit();
        Type kt = unit.getKeyType(pt);
        Type vt = unit.getValueType(pt);
        return kt != null && vt != null && !kt.isEntry() && !vt.isEntry();
    /*&&
                    kt.isPrimitiveAbbreviatedType() && 
                    vt.isPrimitiveAbbreviatedType();*/
    } else {
        return false;
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 52 with Type

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

the class ExpressionVisitor method accountForIntermediateRefinements.

private Reference accountForIntermediateRefinements(Tree.SpecifierStatement that, FunctionOrValue refinedMethodOrValue, FunctionOrValue methodOrValue, ClassOrInterface refiningType, List<Declaration> interveningRefinements) {
    // accumulate an intersection of the types of
    // everything it refines
    List<Type> refinedTypes = new ArrayList<Type>();
    // don't check this one here because it is
    // separately checked in visit(SpecifierStatement)
    Reference refinedProducedReference = getRefinedMemberReference(refinedMethodOrValue, refiningType);
    Map<TypeParameter, Type> substs = substitutions(refinedMethodOrValue, methodOrValue);
    Type refinedType = refinedProducedReference.getType().substitute(substs, null);
    boolean allHaveNulls = hasNullReturnValues(refinedType, refinedMethodOrValue);
    intersectReturnType(refinedTypes, refinedType);
    for (Declaration intervening : interveningRefinements) {
        if (intervening instanceof FunctionOrValue && // factors here as well?
        !refinedMethodOrValue.equals(intervening)) {
            FunctionOrValue refinement = (FunctionOrValue) intervening;
            Reference refinedMember = getRefinedMemberReference(refinement, refiningType);
            Map<TypeParameter, Type> subs = substitutions(refinement, methodOrValue);
            Type type = refinedMember.getType().substitute(subs, null);
            allHaveNulls = allHaveNulls && hasNullReturnValues(type, refinement);
            intersectReturnType(refinedTypes, type);
            checkIntermediateRefinement(that, refinement, refinedMember);
        }
    }
    Type it = canonicalIntersection(refinedTypes, unit);
    if (allHaveNulls && !unit.isOptionalType(it)) {
        methodOrValue.setUncheckedNullType(true);
        Tree.Term lhs = that.getBaseMemberExpression();
        // TODO: this is pretty ugly, think of something better!
        lhs.setTypeModel(unit.getOptionalType(lhs.getTypeModel()));
    }
    methodOrValue.setType(it);
    return refinedProducedReference;
}
Also used : 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) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) ArrayList(java.util.ArrayList) 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) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 53 with Type

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

the class ExpressionVisitor method setMetamodelType.

private void setMetamodelType(Tree.MemberLiteral that, Declaration result) {
    Type outerType;
    if (result.isClassOrInterfaceMember()) {
        Tree.StaticType type = that.getType();
        outerType = type == null ? that.getScope().getDeclaringType(result) : type.getTypeModel();
    } else {
        outerType = null;
    }
    boolean constructor = isConstructor(result);
    if (result instanceof Function) {
        Function method = (Function) result;
        if (method.isAbstraction()) {
            that.addError("method is overloaded");
        } else {
            Tree.TypeArgumentList tal = that.getTypeArgumentList();
            if (explicitTypeArguments(method, tal)) {
                List<Type> typeArgs = getTypeArguments(tal, outerType, method.getTypeParameters());
                if (tal != null) {
                    tal.setTypeModels(typeArgs);
                }
                if (acceptsTypeArguments(method, outerType, typeArgs, tal, that) || true) {
                    TypedReference pr = outerType == null ? method.appliedTypedReference(null, typeArgs) : outerType.getTypedMember(method, typeArgs);
                    that.setTarget(pr);
                    Type metatype = constructor ? unit.getConstructorMetatype(pr) : unit.getFunctionMetatype(pr);
                    that.setTypeModel(metatype);
                }
            } else {
                that.addError("missing type arguments to generic declaration: '" + method.getName(unit) + "'");
            }
        }
    } else if (result instanceof Value) {
        Value value = (Value) result;
        if (that.getTypeArgumentList() != null) {
            that.addError("does not accept type arguments: '" + result.getName(unit) + "' is a value");
        } else {
            TypedReference reference = value.appliedTypedReference(outerType, NO_TYPE_ARGS);
            that.setTarget(reference);
            Type metatype = constructor ? unit.getValueConstructorMetatype(reference) : unit.getValueMetatype(reference);
            that.setTypeModel(metatype);
        }
    }
}
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) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 54 with Type

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

the class ExpressionVisitor method inferParameterTypesIndirectly.

/**
 * Infer parameter types of anonymous function arguments
 * in an indirect invocation with positional arguments.
 */
private boolean[] inferParameterTypesIndirectly(Tree.PositionalArgumentList pal, Type type, boolean error) {
    List<Tree.PositionalArgument> args = pal.getPositionalArguments();
    int argCount = args.size();
    boolean[] delayed = new boolean[argCount];
    if (unit.isCallableType(type)) {
        List<Type> paramTypes = unit.getCallableArgumentTypes(type);
        int paramsSize = paramTypes.size();
        for (int i = 0; i < paramsSize && i < argCount; i++) {
            Type paramType = paramTypes.get(i);
            paramType = callableFromUnion(paramType);
            Tree.PositionalArgument arg = args.get(i);
            if (arg instanceof Tree.ListedArgument && unit.isCallableType(paramType)) {
                Tree.ListedArgument la = (Tree.ListedArgument) arg;
                Tree.Expression e = la.getExpression();
                if (e != null) {
                    Tree.Term term = unwrapExpressionUntilTerm(e.getTerm());
                    if (term instanceof Tree.FunctionArgument) {
                        Tree.FunctionArgument fa = (Tree.FunctionArgument) term;
                        delayed[i] = !inferParameterTypesFromCallableType(paramType, null, fa, error);
                    } else if (term instanceof Tree.StaticMemberOrTypeExpression) {
                        Tree.StaticMemberOrTypeExpression smte = (Tree.StaticMemberOrTypeExpression) term;
                        smte.setParameterType(paramType);
                    }
                }
            }
        }
    }
    return delayed;
}
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) 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) 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 55 with Type

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

the class ExpressionVisitor method checkComprehensionIndirectArgument.

private void checkComprehensionIndirectArgument(Tree.Comprehension c, Type paramType, boolean atLeastOne) {
    Tree.InitialComprehensionClause icc = c.getInitialComprehensionClause();
    if (icc.getPossiblyEmpty() && atLeastOne) {
        c.addError("variadic parameter is required but comprehension is possibly empty");
    }
    Type at = c.getTypeModel();
    Type set = paramType == null ? null : unit.getIteratedType(paramType);
    if (!isTypeUnknown(at) && !isTypeUnknown(set)) {
        checkAssignable(at, set, c, "argument must be assignable to variadic parameter");
    }
}
Also used : 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) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Aggregations

Type (org.eclipse.ceylon.model.typechecker.model.Type)692 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)270 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)263 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)244 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)225 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)207 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)182 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)176 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)176 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)169 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)153 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)130 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)125 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)114 ArrayList (java.util.ArrayList)106 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)100 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)96 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)95 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)94 Class (org.eclipse.ceylon.model.typechecker.model.Class)87