Package edu.mit.csail.sdg.alloy4compiler.ast

Examples of edu.mit.csail.sdg.alloy4compiler.ast.Expr


final class ConvToConjunction extends VisitReturn<Expr> {

    /** {@inheritDoc} */
    @Override public Expr visit(ExprBinary x) throws Err {
        if (x.op == ExprBinary.Op.AND) {
            Expr a = visitThis(x.left);
            Expr b = visitThis(x.right);
            return a.and(b);
        }
        return x;
    }
View Full Code Here


    }

    /** {@inheritDoc} */
    @Override public Expr visit(ExprQt x) throws Err {
        if (x.op == ExprQt.Op.ALL) {
            Expr s = x.sub.deNOP();
            if (s instanceof ExprBinary && ((ExprBinary)s).op==ExprBinary.Op.AND) {
                Expr a = visitThis(x.op.make(Pos.UNKNOWN, Pos.UNKNOWN, x.decls, ((ExprBinary)s).left));
                Expr b = visitThis(x.op.make(Pos.UNKNOWN, Pos.UNKNOWN, x.decls, ((ExprBinary)s).right));
                return a.and(b);
            }
        }
        return x;
    }
View Full Code Here

    @Override public Expr visit(ExprUnary x) throws Err {
        if (x.op == ExprUnary.Op.NOOP) {
            return visitThis(x.sub);
        }
        if (x.op == ExprUnary.Op.NOT) {
            Expr s = x.sub.deNOP();
            if (s instanceof ExprBinary && ((ExprBinary)s).op==ExprBinary.Op.OR) {
                Expr a = visitThis(((ExprBinary)s).left.not());
                Expr b = visitThis(((ExprBinary)s).right.not());
                return a.and(b);
            }
        }
        return x;
    }
View Full Code Here

    /** Write the bitwidth, maxseq, set of all atoms, and map of all sig/field/var into the given file. */
    private void write(BufferedOutputStream out) throws IOException {
        write(out, "maxseq = " + maxseq + ("\n" + "bitwidth = ") + bitwidth + "\n");
        for(Map.Entry<Expr,SimTupleset> entry: sfs.entrySet()) {
            Expr e = entry.getKey();
            if (e instanceof Sig) write(out, "sig " + ((Sig)e).label + " = ");
            else if (e instanceof Field) write(out, "field " + ((Field)e).sig.label + " " + ((Field)e).label + " = ");
            else if (e instanceof ExprVar) write(out, "var " + ((ExprVar)e).label + " = ");
            else continue;
            entry.getValue().write(out);
View Full Code Here

        throw new ErrorFatal(x.span(), "This should have been a set or a relation.\nInstead it is "+y);
    }

    /** {@inheritDoc} */
    @Override public Object visit(ExprBinary x) throws Err {
        Expr a=x.left, b=x.right;
        switch(x.op) {
          case ARROW: case ANY_ARROW_LONE: case ANY_ARROW_ONE: case ANY_ARROW_SOME:
          case LONE_ARROW_ANY: case LONE_ARROW_LONE: case LONE_ARROW_ONE: case LONE_ARROW_SOME:
          case ONE_ARROW_ANY: case ONE_ARROW_LONE: case ONE_ARROW_ONE: case ONE_ARROW_SOME:
          case SOME_ARROW_ANY: case SOME_ARROW_LONE: case SOME_ARROW_ONE: case SOME_ARROW_SOME:
View Full Code Here

    @Override public Object visit(ExprCall x) throws Err {
        final Func f = x.fun;
        final int n = f.count();
        final Object candidate = n==0 ? cacheForConstants.get(f) : null;
        if (candidate!=null) return candidate;
        final Expr body = f.getBody();
        if (body.type().arity()<0 || body.type().arity()!=f.returnDecl.type().arity()) throw new ErrorType(body.span(), "Function return value not fully resolved.");
        for(Func ff:current_function) if (ff==f) throw new ErrorSyntax(x.span(), ""+f+" cannot call itself recursively!");
        Env<ExprVar,Object> newenv = new Env<ExprVar,Object>();
        List<SimTupleset> list = new ArrayList<SimTupleset>(x.args.size());
        for(int i=0; i<n; i++) { SimTupleset ts = cset(x.args.get(i)); newenv.put(f.get(i), ts);  list.add(ts); }
        final SimCallback cb = callbacks.get(f);
View Full Code Here

    /** {@inheritDoc} */
    @Override public SimTupleset visit(Field x) throws Err {
        if (x.defined) {
            final ExprVar v = (ExprVar)(x.sig.decl.get());
            final Expr b = x.decl().expr;
            final Env<ExprVar,Object> oldenv = env;
            env = new Env<ExprVar,Object>();
            if (!b.hasVar(v)) { SimTupleset ans=cset(x.sig).product(cset(b)); env=oldenv; return ans; }
            SimTupleset ans = SimTupleset.EMPTY;
            for(SimTuple a: visit(x.sig)) {
                SimTupleset left = SimTupleset.make(a);
                env.put(v, left);
                SimTupleset right = cset(b);
View Full Code Here

    /** Helper method for enumerating all possibilties for a quantification-expression. */
    private int enumerate(final TempList<SimTuple> store, int sum, final ExprQt x, final Expr body, final int i) throws Err { // if op is ALL NO SOME ONE LONE then it always returns 0 1 2
       final int n = x.count();
       final ExprVar v = x.get(i);
       final Expr bound = x.getBound(i);
       final SimTupleset e = cset(bound);
       final Iterator<SimTupleset> it;
       switch(bound.mult()) {
         case LONEOF: it = e.loneOf(); break;
         case ONEOF:  it = e.oneOf()break;
         case SOMEOF: it = e.someOf(); break;
         default:     it = e.setOf();
       }
View Full Code Here

       return sum;
    }

    /** {@inheritDoc} */
    @Override public Object visit(ExprQt x) throws Err {
        Expr xx = x.desugar();
        if (xx instanceof ExprQt) x = (ExprQt)xx; else return visitThis(xx);
        if (x.op == ExprQt.Op.COMPREHENSION) {
           TempList<SimTuple> ans = new TempList<SimTuple>();
           enumerate(ans, 0, x, x.sub, 0);
           return SimTupleset.make(ans.makeConst());
View Full Code Here

           if (b.isSame(Sig.SEQIDX)) { Integer i = a.get(0).toInt(null); return i!=null && i>=0 && i<maxseq; }
           if (b.isSame(Sig.SIGINT)) { Integer i = a.get(0).toInt(null); return i!=null; }
           if (b.isSame(Sig.STRING)) { String at = a.get(0).toString(); return at.length()>0 && (at.charAt(0)=='\"'); }
        }
        if (b instanceof ExprBinary && ((ExprBinary)b).op==ExprBinary.Op.ARROW) {
           Expr left = ((ExprBinary)b).left, right = ((ExprBinary)b).right;
           int ll = left.type().arity(), rr = right.type().arity();
           if (ll <= rr) return isIn(a.head(ll), left) && isIn(a.tail(rr), right);
           return isIn(a.tail(rr), right) && isIn(a.head(ll), left);
        }
        if (b instanceof ExprBinary && ((ExprBinary)b).op==ExprBinary.Op.PLUS) {
           return isIn(a, ((ExprBinary)b).left) || isIn(a, ((ExprBinary)b).right);
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4compiler.ast.Expr

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.