Package edu.mit.csail.sdg.alloy4

Examples of edu.mit.csail.sdg.alloy4.ErrorType


    /** {@inheritDoc} */
    @Override public Object visit(ExprConstant x) throws Err {
        switch(x.op) {
          case NUMBER:
             int n = x.num();
             if (n<min) throw new ErrorType(x.pos, "Current bitwidth is set to "+bitwidth+", thus this integer constant "+n+" is smaller than the minimum integer "+min);
             if (n>max) throw new ErrorType(x.pos, "Current bitwidth is set to "+bitwidth+", thus this integer constant "+n+" is bigger than the maximum integer "+max);
             return n;
          case FALSE: return Boolean.FALSE;
          case TRUE: return Boolean.TRUE;
          case MIN: return min;
          case MAX: return max;
View Full Code Here


   Expr (Pos pos, Pos closingBracket, boolean ambiguous, Type type, int mult, long weight, JoinableList<Err> errors) {
      this.pos = (pos==null ? Pos.UNKNOWN : pos);
      this.closingBracket = (closingBracket==null ? Pos.UNKNOWN : closingBracket);
      this.ambiguous      = ambiguous;
      if (errors==null) errors = emptyListOfErrors;
      if (type==EMPTY && errors.size()==0) errors = errors.make(new ErrorType(pos, "This expression failed to be typechecked"));
      this.mult   = (mult<0 || mult>2) ? 0 : mult;
      this.type   = (errors.size()>0 || type==null) ? EMPTY : type;
      this.weight = (weight>0) ? weight : 0;
      this.errors = errors;
   }
View Full Code Here

   /** Converts this into a "formula" if possible; otherwise, returns an Expr with a nonempty error list */
   public final Expr typecheck_as_formula() {
      if (!errors.isEmpty() || type.is_bool) return this;
      String msg = "This must be a formula expression.\nInstead, it has the following possible type(s):\n" + type;
      return NOOP.make(null, this, new ErrorType(span(), msg), 0);
   }
View Full Code Here

   /** Converts this into an "integer expression" if possible; otherwise, returns an Expr with a nonempty error list */
   public final Expr typecheck_as_int() {
      if (!errors.isEmpty() || type.is_int) return this;
      if (Type.SIGINT2INT && type.intersects(SIGINT.type)) return cast2int();
      String msg = "This must be an integer expression.\nInstead, it has the following possible type(s):\n"+type;
      return NOOP.make(null, this, new ErrorType(span(), msg), 0);
   }
View Full Code Here

   /** Converts this into a "set or relation" if possible; otherwise, returns an Expr with a nonempty error list */
   public final Expr typecheck_as_set() {
      if (!errors.isEmpty() || type.size()>0) return this;
      if (Type.INT2SIGINT && type.is_int) return cast2sigint();
      String msg = "This must be a set or relation.\nInstead, it has the following possible type(s):\n"+type;
      return NOOP.make(null, this, new ErrorType(span(), msg), 0);
   }
View Full Code Here

   /** Convenience method that generates a type error with "msg" as the message,
    * and includes the left and right bounding types in the message.
    */
   private static ErrorType error(Pos pos, String msg, Expr left, Expr right) {
      return new ErrorType(pos, msg+"\nLeft type = "+left.type+"\nRight type = "+right.type);
   }
View Full Code Here

        } else {
            newBody = newBody.typecheck_as_set();
            if (newBody.ambiguous) newBody = newBody.resolve_as_set(null);
            if (newBody.errors.size()>0) throw newBody.errors.pick();
            if (newBody.type.arity() != returnDecl.type.arity())
               throw new ErrorType(newBody.span(),
               "Function return type is "+returnDecl.type+",\nso the body must be a relation with arity "
               +returnDecl.type.arity()+".\nSo the body's type cannot be: "+newBody.type);
        }
        if (newBody.mult!=0) throw new ErrorSyntax(newBody.span(), "Multiplicity expression not allowed here.");
        this.body = newBody;
View Full Code Here

           "perhaps you used ( ) when you should have used [ ]\n");
        for(Expr x:choices) {
            pos = pos.merge(x.span());
            if (x instanceof ExprBadCall || x instanceof ExprBadJoin) sb.append('\n').append(x.errors.pick().msg);
        }
        return new ErrorType(pos, sb.toString());
    }
View Full Code Here

    //============================================================================================================//

    /** Construct an ExprChoice node. */
    public static Expr make(Pos pos, ConstList<Expr> choices, ConstList<String> reasons) {
        if (choices.size()==0) return new ExprBad(pos, "", new ErrorType(pos, "This expression failed to be typechecked."));
        if (choices.size()==1 && choices.get(0).errors.isEmpty()) return choices.get(0); // Shortcut
        Type type=EMPTY;
        boolean first=true;
        long weight=0;
        for(Expr x:choices) {
View Full Code Here

            txt="\nThis name cannot be resolved; its relevant type does not intersect with any of the following candidates:";
            re = reasons;
        }
        StringBuilder msg = new StringBuilder(txt);
        for(String r:re) msg.append('\n').append(r);
        return new ExprBad(pos, toString(), new ErrorType(pos, msg.toString()));
    }
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4.ErrorType

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.