Package edu.mit.csail.sdg.alloy4

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


           allsigs.add(s);
           choices.add(s);
           for(Field f:s.getFields()) choices.add(f);
       }
       // find <instance>..</instance>
       if (!xml.is("alloy")) throw new ErrorSyntax("The XML file's root node must be <alloy> or <instance>.");
       XMLNode inst = null;
       for(XMLNode sub: xml) if (sub.is("instance")) { inst=sub; break; }
       if (inst==null) throw new ErrorSyntax("The XML file must contain an <instance> element.");
       // set up the basic values of the A4Solution object
       final int bitwidth = Integer.parseInt(inst.getAttribute("bitwidth"));
       final int maxseq = Integer.parseInt(inst.getAttribute("maxseq"));
       final int max = (1<<(bitwidth-1))-1, min = 0-(1<<(bitwidth-1));
       if (bitwidth>=1 && bitwidth<=30) for(int i=min; i<=max; i++) { atoms.add(Integer.toString(i)); }
View Full Code Here


        this.isPred = (returnDecl==null);
        if (returnDecl==null) returnDecl = ExprConstant.FALSE;
        if (returnDecl.mult==0 && returnDecl.type.arity()==1) returnDecl = ExprUnary.Op.ONEOF.make(null, returnDecl);
        this.returnDecl = returnDecl;
        this.body = body;
        if (body.mult!=0) throw new ErrorSyntax(body.span(), "Multiplicity expression not allowed here.");
        this.decls = ConstList.make(decls);
        for(int n=count(), i=0; i<n; i++)
          for(int j=i+1; j<n; j++)
            if (get(i)==get(j))
              throw new ErrorSyntax(get(j).span(),
                "The same variable cannot appear more than once in a predicate/function's parameter list.");
        for(Decl d: this.decls) if (d.expr!=null && d.expr.hasCall())
           throw new ErrorSyntax(d.expr.span(), "Parameter declaration cannot contain predicate/function calls.");
        if (returnDecl.hasCall())
           throw new ErrorSyntax(returnDecl.span(), "Return type declaration cannot contain predicate/function calls.");
    }
View Full Code Here

            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

        boolean ambiguous = false;
        JoinableList<Err> errs = emptyListOfErrors;
        TempList<Expr> newargs = new TempList<Expr>(args.size());
        if (args.size() != fun.count()) {
            errs = errs.make(
              new ErrorSyntax(pos, ""+fun+" has "+fun.count()+" parameters but is called with "+args.size()+" arguments."));
        }
        for(int i=0; i<args.size(); i++) {
            final int a = (i<fun.count()) ? fun.get(i).type.arity() : 0;
            final Expr x = args.get(i).typecheck_as_set();
            ambiguous = ambiguous || x.ambiguous;
            errs = errs.make(x.errors);
            weight = weight + x.weight;
            if (x.mult!=0) errs = errs.make(new ErrorSyntax(x.span(), "Multiplicity expression not allowed here."));
            if (a>0 && x.errors.isEmpty() && !x.type.hasArity(a))
              errs = errs.make(new ErrorType(x.span(), "This should have arity "+a+" but instead its possible type(s) are "+x.type));
            newargs.add(x);
        }
        Type t=Type.FORMULA;
View Full Code Here

            Type ans = x.sub.accept(this);
            env.remove(x.var);
            return ans;
        }
        @Override public Type visit(ExprCall x) throws Err {
            throw new ErrorSyntax(x.span(), "Return type declaration cannot contain predicate/function calls.");
        }
View Full Code Here

        Type commonArity = null;
        for(int i=0; i<args.size(); i++) {
            Expr a = (op==Op.AND || op==Op.OR) ? args.get(i).typecheck_as_formula() : args.get(i).typecheck_as_set();
            ambiguous = ambiguous || a.ambiguous;
            weight = weight + a.weight;
            if (a.mult != 0) errs = errs.make(new ErrorSyntax(a.span(), "Multiplicity expression not allowed here."));
            if (!a.errors.isEmpty()) errs = errs.make(a.errors); else if (commonArity==null) commonArity = a.type; else commonArity = commonArity.pickCommonArity(a.type);
            if (op==Op.AND) addAND(newargs, a); else if (op==Op.OR) addOR(newargs, a); else newargs.add(a);
        }
        if (op==Op.TOTALORDER) {
           if (newargs.size()!=3) {
              errs = errs.make(new ErrorSyntax(pos, "The builtin pred/totalOrder[] predicate must be called with exactly three arguments."));
           } else if (errs.isEmpty()) {
              if (!newargs.get(0).type.hasArity(1)) errs = errs.make(new ErrorType(pos, "The first argument to pred/totalOrder must be unary."));
              if (!newargs.get(1).type.hasArity(1)) errs = errs.make(new ErrorType(pos, "The second argument to pred/totalOrder must be unary."));
              if (!newargs.get(2).type.hasArity(2)) errs = errs.make(new ErrorType(pos, "The third argument to pred/totalOrder must be binary."));
           }
        }
        if (op==Op.DISJOINT) {
           if (newargs.size()<2) errs = errs.make(new ErrorSyntax(pos, "The builtin disjoint[] predicate must be called with at least two arguments."));
           if (commonArity==EMPTY) errs = errs.make(new ErrorType(pos, "The builtin predicate disjoint[] cannot be used among expressions of different arities."));
        }
        return new ExprList(pos, closingBracket, op, ambiguous, newargs.makeConst(), weight, errs);
    }
View Full Code Here

     * @param left - the then-clause
     * @param right - the else-clause
     */
    public static Expr make(Pos pos, Expr cond, Expr left, Expr right) {
        JoinableList<Err> errs = emptyListOfErrors;
        if (cond.mult != 0) errs = errs.make(new ErrorSyntax(cond.span(), "Multiplicity expression not allowed here."));
        if (left.mult != 0) errs = errs.make(new ErrorSyntax(left.span(), "Multiplicity expression not allowed here."));
        if (right.mult != 0) errs = errs.make(new ErrorSyntax(right.span(), "Multiplicity expression not allowed here."));
        Type c=EMPTY;
        while(left.errors.isEmpty() && right.errors.isEmpty()) {
            Type a=left.type, b=right.type;
            c = a.unionWithCommonArity(b);
            if (a.is_int && b.is_int) c=Type.makeInt(c);
View Full Code Here

           if (y.op==ExprUnary.Op.ONEreturn ExprUnary.Op.ONEOF.make(y.pos, y.sub);
        }
        return x;
    }
    private void nod(ExprVar name) throws Err {
        if (name.label.indexOf('$')>=0) throw new ErrorSyntax(name.pos, "The name cannot contain the '$' symbol.");
    }
View Full Code Here

    }
    private void nod(ExprVar name) throws Err {
        if (name.label.indexOf('$')>=0) throw new ErrorSyntax(name.pos, "The name cannot contain the '$' symbol.");
    }
    private void nod(List<ExprVar> names) throws Err {
        if (names!=null) for(ExprVar n:names) if (n!=null && n.label.indexOf('$')>=0) throw new ErrorSyntax(n.pos, "The name cannot contain the '$' symbol.");
    }
View Full Code Here

        Pos p = o.pos.merge(n!=null ? n.span() : e.span());
        for(int i=s.size()-1; i>=0; i--) {
          Sig j=s.get(i).sig;  int k=s.get(i).startingScope;
          p=p.merge(j.pos);
          if (j.label.equals("univ")) { overall=k; s.remove(i); continue; }
          if (j.label.equals("int"))  { if (bitwidth>=0) throw new ErrorSyntax(j.pos, "The bitwidth cannot be specified more than once."); bitwidth=k; s.remove(i); continue; }
          if (j.label.equals("seq"))  { if (maxseq>=0) throw new ErrorSyntax(j.pos, "The maximum sequence length cannot be specified more than once."); maxseq=k; s.remove(i); continue; }
        }
        if (n!=null)
          parser.alloymodule.addCommand(follow, p, n.label, o.label.equals("c"), overall, bitwidth, maxseq, expects, s, x);
        else
          parser.alloymodule.addCommand(follow, p, e,       o.label.equals("c"), overall, bitwidth, maxseq, expects, s, x);
View Full Code Here

TOP

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

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.