1
1
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
2
+ * Electrum -- Copyright (c) 2015-present, Nuno Macedo
2
3
*
3
4
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
4
5
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
37
38
import edu .mit .csail .sdg .alloy4compiler .ast .Sig .SubsetSig ;
38
39
import edu .mit .csail .sdg .alloy4compiler .ast .Type ;
39
40
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
+ * */
41
45
42
46
public final class A4SolutionWriter {
43
47
@@ -108,6 +112,7 @@ private boolean writeExpr(String prefix, Expr expr) throws Err {
108
112
}
109
113
110
114
/** Write the given Sig. */
115
+ // pt.uminho.haslab: extended with time sigs
111
116
private A4TupleSet writesig (final Sig x ) throws Err {
112
117
A4TupleSet ts = null , ts2 = null ;
113
118
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 {
130
135
if (x .isEnum !=null ) out .print ("\" enum=\" yes" );
131
136
out .print ("\" >\n " );
132
137
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
134
139
ts = (A4TupleSet )(sol .eval (x ));
135
140
for (A4Tuple t : ts .minus (ts2 )) Util .encodeXMLs (out , " <atom label=\" " , t .atom (0 ), "\" />\n " );
136
141
}
@@ -174,15 +179,16 @@ private void writeSkolem(ExprVar x) throws Err {
174
179
}
175
180
176
181
/** 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
177
183
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 {
178
184
this .rep = rep ;
179
185
this .out = out ;
180
186
this .sol = sol ;
181
187
for (Sig s :sigs ) if (s instanceof PrimSig && ((PrimSig )s ).parent ==Sig .UNIV ) toplevels .add ((PrimSig )s );
182
188
out .print ("<instance bitwidth=\" " ); out .print (bitwidth );
183
189
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
186
192
out .print ("\" command=\" " ); Util .encodeXML (out , originalCommand );
187
193
out .print ("\" filename=\" " ); Util .encodeXML (out , originalFileName );
188
194
if (sol ==null ) out .print ("\" metamodel=\" yes" );
@@ -223,11 +229,12 @@ private A4SolutionWriter(A4Reporter rep, A4Solution sol, Iterable<Sig> sigs, int
223
229
}
224
230
225
231
/** 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
226
233
static void writeInstance (A4Reporter rep , A4Solution sol , PrintWriter out , Iterable <Func > extraSkolems , Map <String ,String > sources ) throws Err {
227
234
if (!sol .satisfiable ()) throw new ErrorAPI ("This solution is unsatisfiable." );
228
235
try {
229
236
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
231
238
if (sources !=null ) for (Map .Entry <String ,String > e : sources .entrySet ()) {
232
239
Util .encodeXMLs (out , "\n <source filename=\" " , e .getKey (), "\" content=\" " , e .getValue (), "\" />\n " );
233
240
}
@@ -239,9 +246,10 @@ static void writeInstance(A4Reporter rep, A4Solution sol, PrintWriter out, Itera
239
246
}
240
247
241
248
/** Write the metamodel as <instance>..</instance> in XML format. */
249
+ // pt.uminho.haslab: extended with time scopes and sigs
242
250
public static void writeMetamodel (ConstList <Sig > sigs , String originalFilename , PrintWriter out ) throws Err {
243
251
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
245
253
} catch (Throwable ex ) {
246
254
if (ex instanceof Err ) throw (Err )ex ; else throw new ErrorFatal ("Error writing the solution XML file." , ex );
247
255
}
0 commit comments