|
| 1 | +/* |
| 2 | + These classes are used only during parsing because |
| 3 | + we do not know what order items within a state will be parsed in. |
| 4 | +*/ |
| 5 | + |
| 6 | +package ca.uwaterloo.watform.dashast; |
| 7 | + |
| 8 | +import java.util.Collections; |
| 9 | + |
| 10 | +import ca.uwaterloo.watform.alloyast.Pos; |
| 11 | +import ca.uwaterloo.watform.alloyast.expr.AlloyExpr; |
| 12 | +import ca.uwaterloo.watform.dashast.DashStrings; |
| 13 | +//import ca.uwaterloo.watform.alloyasthelper.ExprHelper; |
| 14 | +// use this one, rather than regular Alloy Expr .toString |
| 15 | +// so we can control the printing of the parameters in DashRefs |
| 16 | +//import ca.uwaterloo.watform.alloyasthelper.ExprToString; |
| 17 | + |
| 18 | + |
| 19 | +public abstract class DashExpr extends Dash { |
| 20 | + |
| 21 | + public AlloyExpr exp; |
| 22 | + public Pos pos; |
| 23 | + |
| 24 | + public DashExpr(Pos p, AlloyExpr e) { |
| 25 | + assert(e != null); |
| 26 | + this.pos = p; |
| 27 | + this.exp = e; |
| 28 | + } |
| 29 | + public String toString(String name, Integer i) { |
| 30 | + String s = new String(); |
| 31 | + s += DashStrings.indent(i) + name + " {\n"; |
| 32 | + |
| 33 | + // Alloy seems to put a NOOP on the front of the expression |
| 34 | + //Expr e = exp; |
| 35 | + //while (ExprHelper.isExprNoop(e)) { |
| 36 | + // e = ExprHelper.getSub(e); |
| 37 | + //} |
| 38 | + |
| 39 | + // we don't want to translateExpr here b/c that includes s and s' in the output expression |
| 40 | + |
| 41 | + /* |
| 42 | + if (ExprHelper.isExprAndList(e)) { |
| 43 | +
|
| 44 | + // Drop the "AND[p1,p2 ]" and print p1 and p2 on separate lines |
| 45 | + for (Expr a: ExprHelper.getExprListArgs(e)) { |
| 46 | + // have to call a new ExprToString each time b/c on exprToString call closes it |
| 47 | + ep = new ExprToString(true); // true b/c withinDash printing expression |
| 48 | + s += DashStrings.indent(i+1) + ep.exprToString(a) + "\n"; |
| 49 | + } |
| 50 | + } else { |
| 51 | + ep = new ExprToString(true); // true -> b/c withinDash printing expression |
| 52 | + */ |
| 53 | + //NADTODO pass toString an Int parameter for indentation |
| 54 | + s += exp.toString() + "\n"; |
| 55 | + //} |
| 56 | + s += DashStrings.indent(i) + "}\n"; |
| 57 | + return s; |
| 58 | + } |
| 59 | + public AlloyExpr getExp() { |
| 60 | + return exp; |
| 61 | + } |
| 62 | +} |
0 commit comments