Skip to content

Commit 335172c

Browse files
committed
added dashast
1 parent b275606 commit 335172c

19 files changed

Lines changed: 770 additions & 0 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import ca.uwaterloo.watform.alloyast.Pos;
4+
5+
public abstract class Dash {
6+
// methods that all of Dash AST should have
7+
8+
/**
9+
* The filename, line, and column position in the original Alloy model file
10+
* (cannot be null).
11+
*/
12+
public Pos pos;
13+
14+
public final Pos getPos() {
15+
return pos;
16+
}
17+
public abstract String toString(Integer indent);
18+
19+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import java.util.List;
4+
import java.util.StringJoiner;
5+
import java.util.Collections;
6+
7+
import ca.uwaterloo.watform.alloyast.Pos;
8+
import ca.uwaterloo.watform.dashast.DashStrings;
9+
10+
public class DashBufferDecls extends Dash {
11+
/**
12+
* The filename, line, and column position in the original Alloy model file
13+
* (cannot be null).
14+
*/
15+
16+
private List<String> names;
17+
private String element;
18+
private DashStrings.IntEnvKind kind;
19+
private Integer startIndex;
20+
private Integer endIndex;
21+
22+
public DashBufferDecls(Pos pos, List<String> n, String element, DashStrings.IntEnvKind k, int startIndex, int endIndex) {
23+
assert (n != null && element != null);
24+
this.pos = pos;
25+
this.names = n;
26+
this.element = element;
27+
this.kind = k;
28+
this.startIndex = startIndex;
29+
this.endIndex = endIndex;
30+
}
31+
32+
33+
public String toString(Integer i) {
34+
// indices are hidden
35+
String s = new String("");
36+
if (kind == DashStrings.IntEnvKind.ENV) {
37+
s += DashStrings.envName + " ";
38+
}
39+
StringJoiner sj = new StringJoiner(",\n");
40+
names.forEach(n -> sj.add(n));
41+
s += sj.toString() + ":" + DashStrings.bufName + "[" + element + "]\n";
42+
return DashStrings.indent(i)+s;
43+
}
44+
public List<String> getNames() {
45+
return names;
46+
}
47+
public String getElement() {
48+
return element;
49+
}
50+
public DashStrings.IntEnvKind getKind() {
51+
return kind;
52+
}
53+
public int getStartIndex() {
54+
return startIndex;
55+
}
56+
public int getEndIndex() {
57+
return endIndex;
58+
}
59+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import java.util.Collections;
4+
5+
import ca.uwaterloo.watform.alloyast.Pos;
6+
import ca.uwaterloo.watform.alloyast.expr.AlloyExpr;
7+
import ca.uwaterloo.watform.dashast.DashStrings;
8+
9+
public class DashDo extends DashExpr {
10+
11+
public DashDo(Pos pos,AlloyExpr a) {
12+
super(pos,a);
13+
}
14+
public String toString(Integer i) {
15+
return super.toString(DashStrings.doName, i);
16+
}
17+
public AlloyExpr getDo() {
18+
return super.getExp();
19+
}
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import ca.uwaterloo.watform.alloyast.Pos;
4+
import ca.uwaterloo.watform.alloyast.expr.AlloyExpr;
5+
6+
import ca.uwaterloo.watform.dashast.DashStrings;
7+
8+
public class DashEntered extends DashExpr {
9+
10+
public DashEntered(Pos p, AlloyExpr e) {
11+
super(p,e);
12+
}
13+
public String toString(Integer indent) {
14+
return super.toString(DashStrings.enterName, indent);
15+
}
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import java.util.List;
4+
import java.util.StringJoiner;
5+
import java.util.Collections;
6+
7+
import ca.uwaterloo.watform.alloyast.Pos;
8+
import ca.uwaterloo.watform.dashast.DashStrings;
9+
10+
public class DashEventDecls extends Dash {
11+
12+
private List<String> names;
13+
private DashStrings.IntEnvKind kind;
14+
15+
public DashEventDecls(Pos pos, List<String> n, DashStrings.IntEnvKind kind) {
16+
assert(n != null);
17+
this.pos = pos;
18+
this.names = n;
19+
this.kind = kind;
20+
}
21+
22+
public String toString(Integer i) {
23+
String s = new String("");
24+
if (kind == DashStrings.IntEnvKind.ENV) {
25+
s += DashStrings.envName + " ";
26+
}
27+
StringJoiner sj = new StringJoiner(",\n");
28+
names.forEach(n -> sj.add(n));
29+
s += DashStrings.eventName + " " + sj.toString() +" {}\n";
30+
return DashStrings.indent(i) + s;
31+
}
32+
public List<String> getNames() {
33+
return names;
34+
}
35+
public DashStrings.IntEnvKind getKind() {
36+
return kind;
37+
}
38+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import ca.uwaterloo.watform.alloyast.Pos;
4+
import ca.uwaterloo.watform.alloyast.expr.AlloyExpr;
5+
6+
import ca.uwaterloo.watform.dashast.DashStrings;
7+
8+
public class DashExited extends DashExpr {
9+
10+
public DashExited(Pos p, AlloyExpr e) {
11+
super(p,e);
12+
}
13+
14+
public String toString(Integer indent) {
15+
return super.toString(DashStrings.exitName, indent);
16+
}
17+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import java.util.List;
4+
import java.util.Collections;
5+
6+
import ca.uwaterloo.watform.alloyast.Pos;
7+
import ca.uwaterloo.watform.alloyast.expr.AlloyExpr;
8+
import ca.uwaterloo.watform.dashast.DashStrings;
9+
10+
public class DashFrom extends DashExpr {
11+
12+
public DashFrom(Pos pos, AlloyExpr d) {
13+
super(pos,d);
14+
}
15+
public String toString(Integer i) {
16+
return super.toString(DashStrings.fromName, i);
17+
}
18+
public AlloyExpr getSrc() {
19+
return super.getExp();
20+
}
21+
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import java.util.List;
4+
import java.util.Collections;
5+
6+
import ca.uwaterloo.watform.alloyast.Pos;
7+
import ca.uwaterloo.watform.alloyast.expr.AlloyExpr;
8+
import ca.uwaterloo.watform.dashast.DashStrings;
9+
10+
public class DashGoto extends DashExpr {
11+
12+
public DashGoto(Pos pos, AlloyExpr d) {
13+
super(pos,d);
14+
}
15+
public String toString(Integer i) {
16+
return super.toString(DashStrings.gotoName, i);
17+
}
18+
public AlloyExpr getDest() {
19+
return super.getExp();
20+
}
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ca.uwaterloo.watform.dashast;
2+
3+
import ca.uwaterloo.watform.dashast.DashStrings;
4+
import ca.uwaterloo.watform.alloyast.Pos;
5+
import ca.uwaterloo.watform.alloyast.expr.AlloyExpr;
6+
7+
public class DashInit extends DashExpr {
8+
9+
public DashInit(Pos p, AlloyExpr e) {
10+
super(p,e);
11+
}
12+
public String toString(Integer i) {
13+
return super.toString(DashStrings.initName, i);
14+
}
15+
}

0 commit comments

Comments
 (0)