Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.ProducedType


    }

    private void validateEnumeratedSupertypeArguments(Node that, TypeDeclaration d,
            ProducedType supertype) {
        for (TypeParameter p: supertype.getDeclaration().getTypeParameters()) {
            ProducedType arg = supertype.getTypeArguments().get(p); //the type argument that the declaration (indirectly) passes to the enumerated supertype
            if (arg!=null) {
                validateEnumeratedSupertypeArgument(that, d, supertype, p, arg);
            }
        }
    }
View Full Code Here


            }
        }
        else if (p.isContravariant()) {
            List<ProducedType> sts = p.getSatisfiedTypes();
            //TODO: do I need to do type arg substitution here??
            ProducedType ub = formIntersection(sts);
            if (!(arg.isExactly(ub))) {
                that.addError("argument to contravariant type parameter of enumerated supertype must be a type parameter or '" +
                        typeNamesAsIntersection(sts, unit) + "': " +
                        typeDescription(p, unit));
            }
View Full Code Here

            super.visit(that);
        }
        finally {
            declarationLiteral = false;
        }
        ProducedType t;
        TypeDeclaration d;
        Tree.StaticType type = that.getType();
        Tree.BaseMemberExpression oe = that.getObjectExpression();
        Node errorNode;
    if (type != null) {
          t = type.getTypeModel();
          d = t.getDeclaration();
          errorNode = type;
        }
    else if (oe != null ) {
          t = oe.getTypeModel();
          d = t.getDeclaration();
          if (!d.isAnonymous()) {
            oe.addError("must be a reference to an anonymous class");
          }
          errorNode = oe;
        }
    else {
        errorNode = that;
            ClassOrInterface classOrInterface =
                    getContainingClassOrInterface(that.getScope());
        if (that instanceof Tree.ClassLiteral ||
            that instanceof Tree.InterfaceLiteral) {
            d = classOrInterface;
            if (d==null) {
                errorNode.addError("no containing type");
                return; //EARLY EXIT!!
            }
            else {
                t = classOrInterface.getType();
            }
        }
        else {
            errorNode.addError("missing type reference");
            return; //EARLY EXIT!!
        }
    }
        // FIXME: should we disallow type parameters in there?
        if (t!=null) {
            that.setDeclaration(d);
            that.setWantsDeclaration(true);
            if (that instanceof Tree.ClassLiteral) {
                if (!(d instanceof Class)) {
                    if (d != null) {
                        errorNode.addError("referenced declaration is not a class" +
                                getDeclarationReferenceSuggestion(d));
                    }
                }
                that.setTypeModel(unit.getClassDeclarationType());
            }
            else if (that instanceof Tree.InterfaceLiteral) {
                if (!(d instanceof Interface)) {
                    if (d!=null) {
                        errorNode.addError("referenced declaration is not an interface" +
                                getDeclarationReferenceSuggestion(d));
                    }
                }
                that.setTypeModel(unit.getInterfaceDeclarationType());
            }
            else if (that instanceof Tree.AliasLiteral) {
                if (!(d instanceof TypeAlias)) {
                    errorNode.addError("referenced declaration is not a type alias" +
                            getDeclarationReferenceSuggestion(d));
                }
                that.setTypeModel(unit.getAliasDeclarationType());
            }
            else if (that instanceof Tree.TypeParameterLiteral) {
                if (!(d instanceof TypeParameter)) {
                    errorNode.addError("referenced declaration is not a type parameter" +
                            getDeclarationReferenceSuggestion(d));
                }
                that.setTypeModel(unit.getTypeParameterDeclarationType());
            }
            else if (d != null) {
                that.setWantsDeclaration(false);
                t = t.resolveAliases();
                //checkNonlocalType(that.getType(), t.getDeclaration());
                if (d instanceof Class) {
//                    checkNonlocal(that, t.getDeclaration());
                    if (((Class) d).isAbstraction()) {
                        errorNode.addError("class constructor is overloaded");
View Full Code Here

            declarationLiteral = false;
        }
        Tree.Identifier id = that.getIdentifier();
        if (id!=null) {
            String name = name(id);
            ProducedType qt = null;
            TypeDeclaration qtd = null;
            Tree.StaticType type = that.getType();
            Tree.BaseMemberExpression oe = that.getObjectExpression();
      if (type != null) {
              qt = type.getTypeModel();
              qtd = qt.getDeclaration();
            }
      else if (oe != null) {
              qt = oe.getTypeModel();
              qtd = qt.getDeclaration();
              if (!qtd.isAnonymous()) {
                oe.addError("must be a reference to an anonymous class");
              }
            }
            if (qt != null) {
              qt = qt.resolveAliases();
              if (qtd instanceof UnknownType) {
                // let it go, we already logged an error for the missing type
                return;
              }
              //checkNonlocalType(that.getType(), qtd);
View Full Code Here

        }
        return "";
    }

    private void setMetamodelType(Tree.MemberLiteral that, Declaration result) {
        ProducedType outerType;
        if (result.isClassOrInterfaceMember()) {
            outerType = that.getType()==null ?
                    that.getScope().getDeclaringType(result) :
                    that.getType().getTypeModel();           
        }
        else {
            outerType = null;
        }
        if (result instanceof Method) {
            Method method = (Method) result;
            if (method.isAbstraction()) {
                that.addError("method is overloaded");
            }
            else {
                Tree.TypeArgumentList tal = that.getTypeArgumentList();
                if (explicitTypeArguments(method, tal)) {
                    List<ProducedType> ta = getTypeArguments(tal,
                        getTypeParameters(method), outerType);
                    if (tal != null) {
                        tal.setTypeModels(ta);
                    }
                    if (acceptsTypeArguments(outerType, method, ta, tal, that, false)) {
                        ProducedTypedReference pr = outerType==null ?
                                method.getProducedTypedReference(null, ta) :
                                    outerType.getTypedMember(method, ta);
                                that.setTarget(pr);
                                that.setTypeModel(unit.getFunctionMetatype(pr));
                    }
                }
                else {
View Full Code Here

        }
    }
   
    private void visitArithmeticAssignOperator(Tree.BinaryOperatorExpression that,
            TypeDeclaration type) {
        ProducedType lhst = leftType(that);
        ProducedType rhst = rightType(that);
        if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
            //hardcoded implicit type conversion Integer->Float
            TypeDeclaration fd = unit.getFloatDeclaration();
            TypeDeclaration id = unit.getIntegerDeclaration();
            if (rhst.getDeclaration().inherits(id) &&
                lhst.getDeclaration().inherits(fd)) {
                rhst = fd.getType();
            }
            ProducedType nt = checkSupertype(lhst, type, that.getLeftTerm(),
                    that instanceof Tree.AddAssignOp ?
                            "operand expression must be of summable type" :
                            "operand expression must be of numeric type");
            that.setTypeModel(lhst);
            if (nt!=null) {
                ProducedType t = nt.getTypeArgumentList().get(0);
                //that.setTypeModel(t); //stef requests lhst to make it easier on backend
                checkAssignable(rhst, t, that,
                        that instanceof Tree.AddAssignOp ?
                                "right operand must be of compatible summable type" :
                                "right operand must be of compatible numeric type");
View Full Code Here

        }
    }
   
    private void visitSetOperator(Tree.BitwiseOp that) {
        //TypeDeclaration sd = unit.getSetDeclaration();
        ProducedType lhst = leftType(that);
        ProducedType rhst = rightType(that);
        if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
            checkAssignable(lhst, unit.getSetType(unit.getType(unit.getObjectDeclaration())),
                    that.getLeftTerm(), "set operand expression must be a set");
            checkAssignable(lhst, unit.getSetType(unit.getType(unit.getObjectDeclaration())),
                    that.getRightTerm(), "set operand expression must be a set");
            ProducedType lhset = unit.getSetElementType(lhst);
            ProducedType rhset = unit.getSetElementType(rhst);
            ProducedType et;
            if (that instanceof Tree.IntersectionOp) {
                et = intersectionType(rhset, lhset, unit);
            }
            else if (that instanceof Tree.ComplementOp) {
                et = lhset;
View Full Code Here

        }
    }

    private void visitSetAssignmentOperator(Tree.BitwiseAssignmentOp that) {
        //TypeDeclaration sd = unit.getSetDeclaration();
        ProducedType lhst = leftType(that);
        ProducedType rhst = rightType(that);
        if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
            checkAssignable(lhst, unit.getSetType(unit.getType(unit.getObjectDeclaration())),
                    that.getLeftTerm(), "set operand expression must be a set");
            checkAssignable(lhst, unit.getSetType(unit.getType(unit.getObjectDeclaration())),
                    that.getRightTerm(), "set operand expression must be a set");
            ProducedType lhset = unit.getSetElementType(lhst);
            ProducedType rhset = unit.getSetElementType(rhst);
            if (that instanceof Tree.UnionAssignOp) {
                checkAssignable(rhset, lhset, that.getRightTerm(),
                        "resulting set element type must be assignable to to declared set element type");
            }           
            that.setTypeModel(unit.getSetType(lhset)); //in theory, we could make this narrower
View Full Code Here

            that.setTypeModel(unit.getSetType(lhset)); //in theory, we could make this narrower
        }
    }

    private void visitLogicalOperator(Tree.BinaryOperatorExpression that) {
        ProducedType bt = unit.getType(unit.getBooleanDeclaration());
        ProducedType lt = leftType(that);
        ProducedType rt = rightType(that);
        if (!isTypeUnknown(rt) && !isTypeUnknown(lt)) {
            checkAssignable(lt, bt, that,
                    "logical operand expression must be a boolean value");
            checkAssignable(rt, bt, that,
                    "logical operand expression must be a boolean value");
View Full Code Here

        }
        that.setTypeModel(bt);
    }

    private void visitDefaultOperator(Tree.DefaultOp that) {
        ProducedType lhst = leftType(that);
        ProducedType rhst = rightType(that);
        if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
            checkOptional(lhst, that.getLeftTerm(), that.getLeftTerm());
            List<ProducedType> list = new ArrayList<ProducedType>(2);
            addToUnion(list, unit.denotableType(rhst));
            addToUnion(list, unit.getDefiniteType(unit.denotableType(lhst)));
            UnionType ut = new UnionType(unit);
            ut.setCaseTypes(list);
            ProducedType rt = ut.getType();
            that.setTypeModel(rt);
            /*that.setTypeModel(rhst);
            ProducedType ot;
            if (isOptionalType(rhst)) {
                ot = rhst;
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.ProducedType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.