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

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


    private void checkSelfTypes(Tree.StaticType that, TypeDeclaration td, ProducedType type) {
        if (!(td instanceof TypeParameter)) { //TODO: is this really ok?!
            List<TypeParameter> params = type.getDeclaration().getTypeParameters();
            List<ProducedType> args = type.getTypeArgumentList();
            for (int i=0; i<params.size(); i++) {
                TypeParameter param = params.get(i);
                if ( param.isSelfType() && args.size()>i ) {
                    ProducedType arg = args.get(i);
                    if (arg==null) arg = new UnknownType(unit).getType();
                    TypeDeclaration std = param.getSelfTypedDeclaration();
                    ProducedType at;
                    TypeDeclaration mtd;
                    if (param.getContainer().equals(std)) {
                        at = td.getType();
                        mtd = td;
                    }
                    else {
                        //TODO: lots wrong here?
                        mtd = (TypeDeclaration) td.getMember(std.getName(), null, false);
                        at = mtd==null ? null : mtd.getType();
                    }
                    if (at!=null && !at.isSubtypeOf(arg) &&
                            !(mtd.getSelfType()!=null &&
                                mtd.getSelfType().isExactly(arg))) {
                        String help;
                        TypeDeclaration ad = arg.getDeclaration();
                        if (ad instanceof TypeParameter &&
                                ((TypeParameter) ad).getDeclaration().equals(td)) {
                            help = " (try making " + ad.getName() + " a self type of " + td.getName() + ")";
                        }
                        else if (ad instanceof Interface) {
                            help = " (try making " + td.getName() + " satisfy " + ad.getName() + ")";
                        }
                        else if (ad instanceof Class && td instanceof Class) {
                            help = " (try making " + td.getName() + " extend " + ad.getName() + ")";
                        }
                        else {
                            help = "";
                        }
                        that.addError("type argument does not satisfy self type constraint on type parameter '" +
                                param.getName() + "' of '" + type.getDeclaration().getName(unit) + "': '" +
                                arg.getProducedTypeName(unit) + "' is not a supertype or self type of '" +
                                td.getName(unit) + "'" + help);
                    }
                }
            }
View Full Code Here


    private void validateEnumeratedSupertypeArgument(Node that, TypeDeclaration d,
            ProducedType supertype, TypeParameter p, ProducedType arg) {
        TypeDeclaration td = arg.getDeclaration();
        if (td instanceof TypeParameter) {
            TypeParameter tp = (TypeParameter) td;
            if (tp.getDeclaration().equals(d)) { //the argument is a type parameter of the declaration
                //check that the variance of the argument type parameter is
                //the same as the type parameter of the enumerated supertype
                if (p.isCovariant() && !tp.isCovariant()) {
                    that.addError("argument to covariant type parameter of enumerated supertype must be covariant: " +
                            typeDescription(p, unit));
                }
                if (p.isContravariant() && !tp.isContravariant()) {
                    that.addError("argument to contravariant type parameter of enumerated supertype must be contravariant: " +
                            typeDescription(p, unit));
                }
            }
            else {
View Full Code Here

*/
public class DefaultTypeArgVisitor extends Visitor {
   
    @Override
    public void visit(Tree.TypeParameterDeclaration that) {
        TypeParameter tpd = that.getDeclarationModel();
        ProducedType dta = tpd.getDefaultTypeArgument();
        if (dta!=null && dta.containsDeclaration(tpd.getDeclaration())) {
            tpd.setDefaultTypeArgument(null);
        }
        super.visit(that);
    }
View Full Code Here

        contravariant = !contravariant;
    }
       
    @Override public void visit(Tree.TypeConstraint that) {
        super.visit(that);
        TypeParameter dec = that.getDeclarationModel();
        if (dec!=null) {
            parameterizedDeclaration = dec.getDeclaration();
            flip();
            if (that.getSatisfiedTypes()!=null) {
                for (Tree.Type type: that.getSatisfiedTypes().getTypes()) {
                    check(type, false, null);
                }
View Full Code Here

                    }
                }
            }
            for (int i=typeArguments.size();
                i<typeParameters.size(); i++) {
                TypeParameter tp = typeParameters.get(i);
              ProducedType dta = tp.getDefaultTypeArgument();
              if (dta==null ||
                      //necessary to prevent stack overflow
                      //for illegal recursively-defined
                      //default type argument
                      dta.containsDeclaration(tp.getDeclaration())) {
                break;
              }
              else {
                  ProducedType da = dta.substitute(typeArgMap);
                typeArguments.add(da);
View Full Code Here

      if (max==0) {
        return emptyList();
      }
    List<ProducedType> typeArgs = new ArrayList<ProducedType>(max);
    for (int i=0; i<max; i++) {
          TypeParameter refinedTypeParam = refinedTypeParams.get(i);
          TypeParameter refiningTypeParam = refiningTypeParams.get(i);
          ProducedType refinedProducedType = refinedTypeParam.getType();
            Map<TypeParameter, ProducedType> args = ci.getType()
                    .getSupertype((TypeDeclaration)refined.getContainer())
                    .getTypeArguments();
          for (ProducedType t: refiningTypeParam.getSatisfiedTypes()) {
              ProducedType bound =
                  t.substitute(singletonMap(refiningTypeParam, refinedProducedType));
              //for every type constraint of the refining member, there must
              //be at least one type constraint of the refined member which
              //is assignable to it, guaranteeing that the intersection of
              //the refined member bounds is assignable to the intersection
              //of the refining member bounds
              //TODO: would it be better to just form the intersections and
              //      test assignability directly (the error messages might
              //      not be as helpful, but it might be less restrictive)
              boolean ok = false;
              for (ProducedType st: refinedTypeParam.getSatisfiedTypes()) {
                  if (st.substitute(args).isSubtypeOf(bound)) {
                      ok = true;
                  }
              }
              if (!ok) {
                  that.addError("member type parameter '" + refiningTypeParam.getName() +
                          "' has upper bound which refined member type parameter '" +
                          refinedTypeParam.getName() + "' of " + message(refined) +
                          " does not satisfy: '" + t.getProducedTypeName(that.getUnit()) + "'");
              }
          }
            for (ProducedType st: refinedTypeParam.getSatisfiedTypes()) {
                boolean ok = false;
                for (ProducedType t: refiningTypeParam.getSatisfiedTypes()) {
                    ProducedType bound =
                            t.substitute(singletonMap(refiningTypeParam, refinedProducedType));
                    if (st.substitute(args).isSubtypeOf(bound)) {
                        ok = true;
                    }
                }
                if (!ok) {
                    that.addUnsupportedError("refined member type parameter " +
                            refinedTypeParam.getName() + " of " + message(refined) +
                            " with upper bound which member type parameter " + refiningTypeParam.getName() +
                            " does not satisfy not yet supported: '" + st.getProducedTypeName(that.getUnit()) + "'");
                }
            }
          typeArgs.add(refinedProducedType);
      }
View Full Code Here

                }
                return name.toString();
            }
            else if (pt.getDeclaration() instanceof TypeParameter) {
                StringBuilder name = new StringBuilder();
                TypeParameter tp = (TypeParameter) pt.getDeclaration();

                if (printTypeParameterDetail() && tp.isContravariant()) {
                    name.append("in ");
                }
                if (printTypeParameterDetail() && tp.isCovariant()) {
                    name.append("out ");
                }

                name.append(getSimpleProducedTypeName(pt, unit));

                if (printTypeParameterDetail() && tp.isDefaulted()) {
                    ProducedType dta = tp.getDefaultTypeArgument();
                    if (dta == null) {
                        name.append("=");
                    }
                    else {
                        name.append(" = ")
View Full Code Here

                !args.isEmpty()) {
            ptn.append(lt());
            boolean first = true;
            for (int i=0; i<args.size()&&i<params.size(); i++) {
                ProducedType t = args.get(i);
                TypeParameter p = params.get(i);
                if (first) {
                    first = false;
                }
                else {
                    ptn.append(",");
                }
                if (t==null) {
                    ptn.append("unknown");
                }
                else {
                    if (!p.isCovariant() && pt.isCovariant(p)) {
                        ptn.append("out ");
                    }
                    if (!p.isContravariant() && pt.isContravariant(p)) {
                        ptn.append("in ");
                    }
                    ptn.append(getProducedTypeName(t, unit));
                }
            }
View Full Code Here

   
    @Override
    public void visit(Tree.TypeParameterDeclaration that) {
        Tree.TypeSpecifier ts = that.getTypeSpecifier();
        Tree.TypeVariance tv = that.getTypeVariance();
        TypeParameter p = new TypeParameter();
        defaultExtendedToAnything(p);
        p.setDeclaration(declaration);
        p.setDefaulted(ts!=null);
        if (tv!=null) {
            String v = tv.getText();
            p.setCovariant("out".equals(v));
            p.setContravariant("in".equals(v));
        }
        that.setDeclarationModel(p);
        visitDeclaration(that, p);
        super.visit(that);
        if (ts!=null) {
            Tree.StaticType type = ts.getType();
            if (type!=null) {
                p.setDefaultTypeArgument(type.getTypeModel());
            }
        }
    }
View Full Code Here

    }

    @Override
    public void visit(Tree.TypeConstraint that) {
        String name = name(that.getIdentifier());
        TypeParameter p = (TypeParameter) scope.getDirectMember(name, null, false);
        that.setDeclarationModel(p);
        if (p==null) {
            that.addError("no matching type parameter for constraint: '" +
                    name + "'");
            p = new TypeParameter();
            p.setDeclaration(declaration);
            that.setDeclarationModel(p);
            visitDeclaration(that, p);
        }
        else {
          if (p.isConstrained()) {
            that.addError("duplicate constraint list for type parameter: '" +
                name + "'");
          }
          p.setConstrained(true);
        }
       
        Scope o = enterScope(p);
        super.visit(that);
        exitScope(o);
       
        if ( that.getAbstractedType()!=null ) {
            that.addUnsupportedError("lower bound type constraints are not yet supported");
        }
        /*if ( that.getCaseTypes()!=null ) {
            that.addWarning("enumerated type constraints are not yet supported");
        }*/
        if ( that.getParameterList()!=null ) {
            that.addUnsupportedError("parameter bounds are not yet supported");
            that.getParameterList().getModel().setFirst(true);
            p.addParameterList(that.getParameterList().getModel());
        }
    }
View Full Code Here

TOP

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

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.