Skip to content

Commit fdce4be

Browse files
committed
documentation
1 parent d4031c3 commit fdce4be

9 files changed

+1163
-1121
lines changed

src/edu/mit/csail/sdg/alloy4compiler/translator/A4Solution.java

+1,099-1,091
Large diffs are not rendered by default.

src/edu/mit/csail/sdg/alloy4compiler/translator/A4SolutionReader.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
2+
* Electrum -- Copyright (c) 2014-present, Nuno Macedo
23
*
34
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
45
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
@@ -49,7 +50,10 @@
4950
import edu.mit.csail.sdg.alloy4compiler.ast.Sig.PrimSig;
5051
import edu.mit.csail.sdg.alloy4compiler.ast.Sig.SubsetSig;
5152

52-
/** This helper class contains helper routines for reading an A4Solution object from an XML file. */
53+
/** This helper class contains helper routines for reading an A4Solution object from an XML file.
54+
*
55+
* @modified: nmm
56+
* */
5357

5458
public final class A4SolutionReader {
5559

@@ -72,7 +76,7 @@ public final class A4SolutionReader {
7276
private final Map<String,Sig> id2sig = new LinkedHashMap<String,Sig>();
7377

7478
/** Stores the set of all sigs. */
75-
private final Set<Sig> allsigs = Util.asSet((Sig)UNIV, SIGINT, SEQIDX, STRING, NONE, TIME); //pt.uminho.haslab
79+
private final Set<Sig> allsigs = Util.asSet((Sig)UNIV, SIGINT, SEQIDX, STRING, NONE, TIME); //pt.uminho.haslab: time sigs
7680

7781
/** Mapes each expression we've seen to its TupleSet. */
7882
private final Map<Expr,TupleSet> expr2ts = new LinkedHashMap<Expr,TupleSet>();
@@ -138,7 +142,7 @@ private Sig parseSig(String id, int depth) throws IOException, Err {
138142
if (label.equals(SIGINT.label)) { id2sig.put(id, SIGINT); return SIGINT; }
139143
if (label.equals(SEQIDX.label)) { id2sig.put(id, SEQIDX); return SEQIDX; }
140144
if (label.equals(STRING.label)) { id2sig.put(id, STRING); return STRING; }
141-
if (label.equals(TIME.label)) { id2sig.put(id, TIME); return TIME; } // pt.uminho.haslab
145+
if (label.equals(TIME.label)) { id2sig.put(id, TIME); return TIME; } // pt.uminho.haslab: time sigs
142146
throw new IOException("Unknown builtin sig: "+label+" (id="+id+")");
143147
}
144148
if (depth > nmap.size()) throw new IOException("Sig "+label+" (id="+id+") is in a cyclic inheritance relationship.");

src/edu/mit/csail/sdg/alloy4compiler/translator/A4SolutionWriter.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
2+
* Electrum -- Copyright (c) 2015-present, Nuno Macedo
23
*
34
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
45
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
@@ -37,7 +38,10 @@
3738
import edu.mit.csail.sdg.alloy4compiler.ast.Sig.SubsetSig;
3839
import edu.mit.csail.sdg.alloy4compiler.ast.Type;
3940

40-
/** This helper class contains helper routines for writing an A4Solution object out as an XML file. */
41+
/** This helper class contains helper routines for writing an A4Solution object out as an XML file.
42+
*
43+
* @modified: nmm
44+
* */
4145

4246
public final class A4SolutionWriter {
4347

@@ -108,6 +112,7 @@ private boolean writeExpr(String prefix, Expr expr) throws Err {
108112
}
109113

110114
/** Write the given Sig. */
115+
// pt.uminho.haslab: extended with time sigs
111116
private A4TupleSet writesig(final Sig x) throws Err {
112117
A4TupleSet ts = null, ts2 = null;
113118
if (x==Sig.NONE) return null; // should not happen, but we test for it anyway
@@ -130,7 +135,7 @@ private A4TupleSet writesig(final Sig x) throws Err {
130135
if (x.isEnum!=null) out.print("\" enum=\"yes");
131136
out.print("\">\n");
132137
try {
133-
if (sol!=null && x!=Sig.UNIV && x!=Sig.SIGINT && x!=Sig.SEQIDX && x!=Sig.TIME) { // pt.uminho.haslab
138+
if (sol!=null && x!=Sig.UNIV && x!=Sig.SIGINT && x!=Sig.SEQIDX && x!=Sig.TIME) { // pt.uminho.haslab: time sigs
134139
ts = (A4TupleSet)(sol.eval(x));
135140
for(A4Tuple t: ts.minus(ts2)) Util.encodeXMLs(out, " <atom label=\"", t.atom(0), "\"/>\n");
136141
}
@@ -174,15 +179,16 @@ private void writeSkolem(ExprVar x) throws Err {
174179
}
175180

176181
/** If sol==null, write the list of Sigs as a Metamodel, else write the solution as an XML file. */
182+
// pt.uminho.haslab: extended with time scopes and sigs
177183
private A4SolutionWriter(A4Reporter rep, A4Solution sol, Iterable<Sig> sigs, int bitwidth, int maxseq, int time, int loop, String originalCommand, String originalFileName, PrintWriter out, Iterable<Func> extraSkolems) throws Err {
178184
this.rep = rep;
179185
this.out = out;
180186
this.sol = sol;
181187
for (Sig s:sigs) if (s instanceof PrimSig && ((PrimSig)s).parent==Sig.UNIV) toplevels.add((PrimSig)s);
182188
out.print("<instance bitwidth=\""); out.print(bitwidth);
183189
out.print("\" maxseq=\""); out.print(maxseq);
184-
out.print("\" time=\""); out.print(time); // pt.uminho.haslab
185-
out.print("\" loop=\""); out.print(loop); // pt.uminho.haslab
190+
out.print("\" time=\""); out.print(time); // pt.uminho.haslab: time scopes
191+
out.print("\" loop=\""); out.print(loop); // pt.uminho.haslab: time scopes
186192
out.print("\" command=\""); Util.encodeXML(out, originalCommand);
187193
out.print("\" filename=\""); Util.encodeXML(out, originalFileName);
188194
if (sol==null) out.print("\" metamodel=\"yes");
@@ -223,11 +229,12 @@ private A4SolutionWriter(A4Reporter rep, A4Solution sol, Iterable<Sig> sigs, int
223229
}
224230

225231
/** If this solution is a satisfiable solution, this method will write it out in XML format. */
232+
// pt.uminho.haslab: extended with time scopes and sigs
226233
static void writeInstance(A4Reporter rep, A4Solution sol, PrintWriter out, Iterable<Func> extraSkolems, Map<String,String> sources) throws Err {
227234
if (!sol.satisfiable()) throw new ErrorAPI("This solution is unsatisfiable.");
228235
try {
229236
Util.encodeXMLs(out, "<alloy builddate=\"", Version.buildDate(), "\">\n\n");
230-
new A4SolutionWriter(rep, sol, sol.getAllReachableSigs(), sol.getBitwidth(), sol.getMaxSeq(), sol.getTime(), sol.getLoop(), sol.getOriginalCommand(), sol.getOriginalFilename(), out, extraSkolems); // pt.uminho.haslab
237+
new A4SolutionWriter(rep, sol, sol.getAllReachableSigs(), sol.getBitwidth(), sol.getMaxSeq(), sol.getTime(), sol.getLoop(), sol.getOriginalCommand(), sol.getOriginalFilename(), out, extraSkolems); // pt.uminho.haslab: time scopes
231238
if (sources!=null) for(Map.Entry<String,String> e: sources.entrySet()) {
232239
Util.encodeXMLs(out, "\n<source filename=\"", e.getKey(), "\" content=\"", e.getValue(), "\"/>\n");
233240
}
@@ -239,9 +246,10 @@ static void writeInstance(A4Reporter rep, A4Solution sol, PrintWriter out, Itera
239246
}
240247

241248
/** Write the metamodel as &lt;instance&gt;..&lt;/instance&gt; in XML format. */
249+
// pt.uminho.haslab: extended with time scopes and sigs
242250
public static void writeMetamodel(ConstList<Sig> sigs, String originalFilename, PrintWriter out) throws Err {
243251
try {
244-
new A4SolutionWriter(null, null, sigs, 4, 4, 4, 4, "show metamodel", originalFilename, out, null); // pt.uminho.haslab
252+
new A4SolutionWriter(null, null, sigs, 4, 4, 4, 4, "show metamodel", originalFilename, out, null); // pt.uminho.haslab: time scopes
245253
} catch(Throwable ex) {
246254
if (ex instanceof Err) throw (Err)ex; else throw new ErrorFatal("Error writing the solution XML file.", ex);
247255
}

src/edu/mit/csail/sdg/alloy4compiler/translator/ScopeComputer.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
2+
* Electrum -- Copyrght (c) 2015-present, Nuno Macedo
23
*
34
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
45
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
@@ -70,6 +71,8 @@
7071
* <br> we will give an error message.
7172
*
7273
* <p> Please see ScopeComputer.java for the exact rules for deriving the missing scopes.
74+
*
75+
* @modified: nmm
7376
*/
7477

7578
final class ScopeComputer {
@@ -91,7 +94,7 @@ final class ScopeComputer {
9194
/** The number of STRING atoms to allocate; -1 if it was not specified. */
9295
private int maxstring = (-1);
9396

94-
private int time = (-1); // pt.uminho.haslab
97+
private int time = (-1); // pt.uminho.haslab: time scopes
9598

9699
/** The scope for each sig. */
97100
private final IdentityHashMap<PrimSig,Integer> sig2scope = new IdentityHashMap<PrimSig,Integer>();
@@ -110,7 +113,7 @@ public int sig2scope(Sig sig) {
110113
if (sig==SIGINT) return 1<<bitwidth;
111114
if (sig==SEQIDX) return maxseq;
112115
if (sig==STRING) return maxstring;
113-
if (sig==TIME) return time; // pt.uminho.haslab
116+
if (sig==TIME) return time; // pt.uminho.haslab: time scopes
114117
Integer y = sig2scope.get(sig);
115118
return (y==null) ? (-1) : y;
116119
}
@@ -129,7 +132,7 @@ private void sig2scope(Sig sig, int newValue) throws Err {
129132

130133
/** Returns whether the scope of a sig is exact or not. */
131134
public boolean isExact(Sig sig) {
132-
return sig==SIGINT || sig==SEQIDX || sig==STRING || sig==TIME || ((sig instanceof PrimSig) && exact.containsKey(sig)); // pt.uminho.haslab
135+
return sig==SIGINT || sig==SEQIDX || sig==STRING || sig==TIME || ((sig instanceof PrimSig) && exact.containsKey(sig)); // pt.uminho.haslab: time scopes
133136
}
134137

135138
/** Make the given sig "exact". */
@@ -271,6 +274,7 @@ private int computeLowerBound(final PrimSig sig) throws Err {
271274
//===========================================================================================================================//
272275

273276
/** Compute the scopes, based on the settings in the "cmd", then log messages to the reporter. */
277+
// pt.uminho.haslab: extended with time scopes
274278
private ScopeComputer(A4Reporter rep, Iterable<Sig> sigs, Command cmd) throws Err {
275279
this.rep = rep;
276280
this.cmd = cmd;
@@ -329,9 +333,9 @@ private ScopeComputer(A4Reporter rep, Iterable<Sig> sigs, Command cmd) throws Er
329333
for(Sig s:sigs) if (s.isTopLevel()) computeLowerBound((PrimSig)s);
330334
int max = max(), min = min();
331335
if (max >= min) for(int i=min; i<=max; i++) atoms.add(""+i);
332-
time = cmd.time; // pt.uminho.haslab
333-
sig2scope.put(TIME, time < 1 ? 0 : time); // pt.uminho.haslab
334-
if (time > 0) for(int i=0; i<time; i++) atoms.add("Time$"+i); // pt.uminho.haslab
336+
time = cmd.time; // pt.uminho.haslab: time scopes
337+
sig2scope.put(TIME, time < 1 ? 0 : time); // pt.uminho.haslab: time scopes
338+
if (time > 0) for(int i=0; i<time; i++) atoms.add("Time$"+i); // pt.uminho.haslab: time scopes
335339
}
336340

337341
/** Whether or not Int appears in the relation types found in these sigs */

src/edu/mit/csail/sdg/alloy4compiler/translator/TranslateAlloyToKodkod.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
2+
* Electrum -- Copyright (c) 2015-present, Nuno Macedo
23
*
34
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
45
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
@@ -75,7 +76,10 @@
7576
import edu.mit.csail.sdg.alloy4compiler.ast.Type;
7677
import edu.mit.csail.sdg.alloy4compiler.ast.VisitReturn;
7778

78-
/** Translate an Alloy AST into Kodkod AST then attempt to solve it using Kodkod. */
79+
/** Translate an Alloy AST into Kodkod AST then attempt to solve it using Kodkod.
80+
*
81+
* @modifed: nmm
82+
* */
7983

8084
public final class TranslateAlloyToKodkod extends VisitReturn<Object> {
8185

@@ -414,6 +418,7 @@ public static A4Solution execute_command (A4Reporter rep, Iterable<Sig> sigs, Co
414418
* <p> If the return value X is satisfiable, you can call X.next() to get the next satisfying solution X2;
415419
* and you can call X2.next() to get the next satisfying solution X3... until you get an unsatisfying solution.
416420
*/
421+
// pt.uminho.haslab: extended for timed iterations
417422
public static A4Solution execute_commandFromBook (A4Reporter rep, Iterable<Sig> sigs, Command cmd, A4Options opt) throws Err {
418423
if (rep==null) rep = A4Reporter.NOP;
419424
TranslateAlloyToKodkod tr = null;
@@ -599,10 +604,10 @@ private static Relation right(Expression x) {
599604
case MIN: return IntConstant.constant(min); //TODO
600605
case MAX: return IntConstant.constant(max); //TODO
601606
case NEXT: return A4Solution.KK_NEXT;
602-
case NEXTTIME: return A4Solution.KK_TIMENEXT; // pt.uminho.haslab
603-
case END: return A4Solution.KK_TIMEEND; // pt.uminho.haslab
604-
case LOOP: return A4Solution.KK_TIMELOOP; // pt.uminho.haslab
605-
case INIT: return A4Solution.KK_TIMEINIT; // pt.uminho.haslab
607+
case NEXTTIME: return A4Solution.KK_TIMENEXT; // pt.uminho.haslab: time relations (deprecated)
608+
case END: return A4Solution.KK_TIMEEND; // pt.uminho.haslab: time relations (deprecated)
609+
case LOOP: return A4Solution.KK_TIMELOOP; // pt.uminho.haslab: time relations (deprecated)
610+
case INIT: return A4Solution.KK_TIMEINIT; // pt.uminho.haslab: time relations (deprecated)
606611
case TRUE: return Formula.TRUE;
607612
case FALSE: return Formula.FALSE;
608613
case EMPTYNESS: return Expression.NONE;

src/edu/mit/csail/sdg/alloy4viz/AlloyType.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
2+
* Electrum -- Copyright (c) 2015-present, Nuno Macedo
23
*
34
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
45
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
@@ -20,6 +21,8 @@
2021
/** Immutable; represents an Alloy toplevel signature or an Alloy subsignature.
2122
*
2223
* <p><b>Thread Safety:</b> Can be called only by the AWT event thread.
24+
*
25+
* @modified: nmm
2326
*/
2427

2528
public final class AlloyType extends AlloyNodeElement {
@@ -40,7 +43,7 @@ public final class AlloyType extends AlloyNodeElement {
4043
public static final AlloyType SET=new AlloyType("set", false, false, false, false, false, false);
4144

4245

43-
public static final AlloyType TIME=new AlloyType("Time", false, false, true, false, false, false); // pt.uminho.haslab
46+
public static final AlloyType TIME=new AlloyType("Time", false, false, true, false, false, false); // pt.uminho.haslab: time types (deprecated)
4447

4548

4649
/** Constructs an AlloyType object with that name. */

src/edu/mit/csail/sdg/alloy4viz/StaticInstanceReader.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
2+
* Electrum -- Copyright (c) 2015-present, Nuno Macedo
23
*
34
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
45
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
@@ -94,7 +95,7 @@ private AlloyType makeType(String label, boolean isOne, boolean isAbstract, bool
9495

9596
/** Create a new AlloySet whose label is unambiguous with any existing one. */
9697
private AlloySet makeSet(String label, boolean isPrivate, boolean isMeta, AlloyType type) {
97-
while(label.equals(Sig.UNIV.label) || label.equals(Sig.SIGINT.label) || label.equals(Sig.SEQIDX.label) || label.equals(Sig.STRING.label) || label.equals(Sig.TIME.label)) label=label+"'"; // pt.uminho.haslab
98+
while(label.equals(Sig.UNIV.label) || label.equals(Sig.SIGINT.label) || label.equals(Sig.SEQIDX.label) || label.equals(Sig.STRING.label) || label.equals(Sig.TIME.label)) label=label+"'"; // pt.uminho.haslab: time sigs
9899
while(true) {
99100
AlloySet ans = new AlloySet(label, isPrivate, isMeta, type);
100101
if (!sets.contains(ans)) return ans;
@@ -104,7 +105,7 @@ private AlloySet makeSet(String label, boolean isPrivate, boolean isMeta, AlloyT
104105

105106
/** Create a new AlloyRelation whose label is unambiguous with any existing one. */
106107
private AlloyRelation makeRel(String label, boolean isPrivate, boolean isMeta, List<AlloyType> types) {
107-
while(label.equals(Sig.UNIV.label) || label.equals(Sig.SIGINT.label) || label.equals(Sig.SEQIDX.label) || label.equals(Sig.STRING.label) || label.equals(Sig.TIME.label)) label=label+"'"; // pt.uminho.haslab
108+
while(label.equals(Sig.UNIV.label) || label.equals(Sig.SIGINT.label) || label.equals(Sig.SEQIDX.label) || label.equals(Sig.STRING.label) || label.equals(Sig.TIME.label)) label=label+"'"; // pt.uminho.haslab: time sigs
108109
while(true) {
109110
AlloyRelation ans = new AlloyRelation(label, isPrivate, isMeta, types);
110111
if (!rels.containsKey(ans)) return ans;
@@ -212,6 +213,7 @@ private void setOrRel(A4Solution sol, String label, Expr expr, boolean isPrivate
212213
}
213214

214215
/** Parse the file into an AlloyInstance if possible. */
216+
// pt.uminho.haslab: extended with time sigs
215217
private StaticInstanceReader(XMLNode root) throws Err {
216218
XMLNode inst = null;
217219
for(XMLNode sub: root) if (sub.is("instance")) { inst=sub; break; }
@@ -224,7 +226,7 @@ private StaticInstanceReader(XMLNode root) throws Err {
224226
sig2type.put(Sig.SIGINT, AlloyType.INT);
225227
sig2type.put(Sig.SEQIDX, AlloyType.SEQINT);
226228
sig2type.put(Sig.STRING, AlloyType.STRING);
227-
sig2type.put(Sig.TIME, AlloyType.TIME); // pt.uminho.haslab
229+
sig2type.put(Sig.TIME, AlloyType.TIME); // pt.uminho.haslab: time sigs
228230
ts.put(AlloyType.SEQINT, AlloyType.INT);
229231
for(int i=sol.min(), max=sol.max(), maxseq=sol.getMaxSeq(); i<=max; i++) {
230232
AlloyAtom at = new AlloyAtom(i>=0 && i<maxseq ? AlloyType.SEQINT : AlloyType.INT, i, ""+i);
@@ -262,7 +264,7 @@ private StaticInstanceReader(XMLNode root) throws Err {
262264
AlloyAtom intAtom = sig2atom.get(Sig.SIGINT);
263265
AlloyAtom seqAtom = sig2atom.get(Sig.SEQIDX);
264266
AlloyAtom strAtom = sig2atom.get(Sig.STRING);
265-
AlloyAtom timAtom = sig2atom.get(Sig.TIME); // pt.uminho.haslab
267+
AlloyAtom timAtom = sig2atom.get(Sig.TIME); // pt.uminho.haslab: time sigs
266268
for(Set<AlloyTuple> t: rels.values()) for(AlloyTuple at: t) if (at.getAtoms().contains(univAtom)) { univAtom=null; break; }
267269
for(Set<AlloyTuple> t: rels.values()) for(AlloyTuple at: t) if (at.getAtoms().contains(intAtom)) { intAtom=null; break; }
268270
for(Set<AlloyTuple> t: rels.values()) for(AlloyTuple at: t) if (at.getAtoms().contains(seqAtom)) { seqAtom=null; break; }
@@ -282,7 +284,7 @@ private StaticInstanceReader(XMLNode root) throws Err {
282284
}
283285
atom2sets.remove(strAtom);
284286
}
285-
if (timAtom!=null) { // pt.uminho.haslab
287+
if (timAtom!=null) { // pt.uminho.haslab: time sigs
286288
for(Iterator<AlloyTuple> it=exts.iterator(); it.hasNext();) {
287289
AlloyTuple at=it.next();
288290
if (at.getStart()==timAtom || at.getEnd()==timAtom) it.remove();

0 commit comments

Comments
 (0)