1 |
aw0a |
1 |
/* |
2 |
|
|
* BrowLogRel_io.c |
3 |
|
|
* by Kirk Abbott and Ben Allan |
4 |
|
|
* Created: 1/94 |
5 |
|
|
* Version: $Revision: 1.11 $ |
6 |
|
|
* Version control file: $RCSfile: BrowLogRel_io.c,v $ |
7 |
|
|
* Date last modified: $Date: 2003/08/23 18:43:04 $ |
8 |
|
|
* Last modified by: $Author: ballan $ |
9 |
|
|
* |
10 |
|
|
* This file is part of the ASCEND Tcl/Tk interface |
11 |
|
|
* |
12 |
|
|
* Copyright 1997, Carnegie Mellon University |
13 |
|
|
* |
14 |
|
|
* The ASCEND Tcl/Tk interface is free software; you can redistribute |
15 |
|
|
* it and/or modify it under the terms of the GNU General Public License as |
16 |
|
|
* published by the Free Software Foundation; either version 2 of the |
17 |
|
|
* License, or (at your option) any later version. |
18 |
|
|
* |
19 |
|
|
* The ASCEND Tcl/Tk interface is distributed in hope that it will be |
20 |
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 |
|
|
* General Public License for more details. |
23 |
|
|
* |
24 |
|
|
* You should have received a copy of the GNU General Public License |
25 |
|
|
* along with the program; if not, write to the Free Software Foundation, |
26 |
|
|
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
27 |
|
|
* COPYING. COPYING is found in ../compiler. |
28 |
|
|
*/ |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/* |
32 |
|
|
* Browser Logical Relation Output Routines |
33 |
|
|
*/ |
34 |
|
|
|
35 |
|
|
#include "tcl.h" |
36 |
|
|
#include "utilities/ascConfig.h" |
37 |
|
|
#include "utilities/ascMalloc.h" |
38 |
|
|
#include "general/list.h" |
39 |
|
|
#include "general/dstring.h" |
40 |
|
|
#include "compiler/compiler.h" |
41 |
|
|
#include "compiler/fractions.h" |
42 |
|
|
#include "compiler/dimen.h" |
43 |
|
|
#include "compiler/types.h" |
44 |
|
|
#include "compiler/exprs.h" |
45 |
|
|
#include "compiler/instance.h" |
46 |
|
|
#include "compiler/instance_enum.h" |
47 |
|
|
#include "compiler/symtab.h" |
48 |
|
|
#include "compiler/instance_io.h" |
49 |
|
|
#include "compiler/instquery.h" |
50 |
|
|
#include "compiler/visitinst.h" |
51 |
|
|
#include "compiler/mathinst.h" |
52 |
|
|
#include "compiler/extfunc.h" |
53 |
|
|
#include "compiler/find.h" |
54 |
|
|
#include "compiler/functype.h" |
55 |
|
|
#include "compiler/safe.h" |
56 |
|
|
#include "compiler/func.h" |
57 |
|
|
#include "compiler/extcall.h" |
58 |
|
|
#include "compiler/logical_relation.h" |
59 |
|
|
#include "compiler/logrelation.h" |
60 |
|
|
#include "compiler/logrel_util.h" |
61 |
|
|
#include "compiler/logrel_io.h" |
62 |
|
|
#include "compiler/instance_name.h" |
63 |
|
|
#include "solver/slv_types.h" |
64 |
|
|
#include "interface/HelpProc.h" |
65 |
|
|
#include "interface/BrowserProc.h" |
66 |
|
|
#include "interface/BrowLogRel_io.h" |
67 |
|
|
#include "interface/Qlfdid.h" |
68 |
|
|
#include "interface/BrowserQuery.h" |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
#ifndef lint |
72 |
|
|
static CONST char BrowLogRelIOID[] = "$Id: BrowLogRel_io.c,v 1.11 2003/08/23 18:43:04 ballan Exp $"; |
73 |
|
|
#endif |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
/**************************************************************************/ |
77 |
|
|
|
78 |
|
|
static struct gl_list_t *g_brow_lrellist = NULL; |
79 |
|
|
static struct gl_list_t *g_brow_condlrellist = NULL; |
80 |
|
|
|
81 |
|
|
/**************************************************************************/ |
82 |
|
|
|
83 |
|
|
/* Get a list of pointers to logical relations and |
84 |
|
|
* a list of pointer to conditional logical relations |
85 |
|
|
*/ |
86 |
|
|
|
87 |
|
|
static |
88 |
|
|
void BrowGetLogRelations(struct Instance *i) |
89 |
|
|
{ |
90 |
|
|
CONST struct logrelation *lrel; |
91 |
|
|
|
92 |
|
|
if (i) { |
93 |
|
|
switch(InstanceKind(i)) { |
94 |
|
|
case LREL_INST: |
95 |
|
|
lrel = GetInstanceLogRelOnly(i); |
96 |
|
|
if (!LogRelIsCond(lrel)) { |
97 |
|
|
gl_append_ptr(g_brow_lrellist,i); |
98 |
|
|
} else { /* conditional */ |
99 |
|
|
gl_append_ptr(g_brow_condlrellist,i); |
100 |
|
|
} |
101 |
|
|
break; |
102 |
|
|
default: |
103 |
|
|
break; |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
|
109 |
|
|
/* This functions sends to the interpreter the list of logical relations |
110 |
|
|
* and then the list of conditional ligcal relations if required |
111 |
|
|
*/ |
112 |
|
|
|
113 |
|
|
int Asc_BrowWriteLogRelListCmd(ClientData cdata,Tcl_Interp *interp, |
114 |
|
|
int argc, CONST84 char *argv[]) |
115 |
|
|
{ |
116 |
|
|
struct Instance *i, *lrel_inst; |
117 |
|
|
unsigned long len, c; |
118 |
|
|
int save=0; |
119 |
|
|
|
120 |
|
|
(void)cdata; /* stop gcc whine about unused parameter */ |
121 |
|
|
|
122 |
|
|
if (( argc < 2 ) || ( argc > 3 )) { |
123 |
|
|
Tcl_AppendResult(interp,"wrong # args : ", |
124 |
|
|
"Usage \"bgetlogrels\" ?cur?search? save",(char *)NULL); |
125 |
|
|
return TCL_ERROR; |
126 |
|
|
} |
127 |
|
|
if (strncmp(argv[1],"current",3)==0) { |
128 |
|
|
i = g_curinst; |
129 |
|
|
} else { |
130 |
|
|
if (strncmp(argv[1],"search",3)==0) { |
131 |
|
|
i = g_search_inst; |
132 |
|
|
} else { |
133 |
|
|
Tcl_SetResult(interp, "invalid args to \"bgetlogrels\"", TCL_STATIC); |
134 |
|
|
return TCL_ERROR; |
135 |
|
|
} |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
if (argc==3) { |
139 |
|
|
if (strncmp(argv[2],"save",4)==0) { |
140 |
|
|
save = 1; |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
if (!i) { |
145 |
|
|
return TCL_ERROR; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
if (!g_brow_lrellist) { |
149 |
|
|
g_brow_lrellist = gl_create(40L); |
150 |
|
|
} |
151 |
|
|
if (!g_brow_condlrellist) { |
152 |
|
|
g_brow_condlrellist = gl_create(40L); |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
VisitInstanceTree(i,BrowGetLogRelations,0,0); |
156 |
|
|
|
157 |
|
|
/* Logical Relation */ |
158 |
|
|
len = gl_length(g_brow_lrellist); |
159 |
|
|
for (c=1;c<=len;c++) { |
160 |
|
|
char *tmp; |
161 |
|
|
lrel_inst = (struct Instance *)gl_fetch(g_brow_lrellist,c); |
162 |
|
|
Tcl_AppendResult(interp,"{",(char *)NULL); |
163 |
|
|
tmp = WriteLogRelToString(lrel_inst,NULL); |
164 |
|
|
Tcl_AppendResult(interp,tmp,(char *)NULL); |
165 |
|
|
ascfree(tmp); |
166 |
|
|
Tcl_AppendResult(interp,"} ",(char *)NULL); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
/* Conditional Logical Relation if the case */ |
170 |
|
|
len = gl_length(g_brow_condlrellist); |
171 |
|
|
if (len) { |
172 |
|
|
Tcl_AppendResult(interp,"{The following LogRels are Conditional: } ", |
173 |
|
|
(char *)NULL); |
174 |
|
|
for (c=1;c<=len;c++) { |
175 |
|
|
char *tmp; |
176 |
|
|
lrel_inst = (struct Instance *)gl_fetch(g_brow_condlrellist,c); |
177 |
|
|
Tcl_AppendResult(interp,"{",(char *)NULL); |
178 |
|
|
tmp = WriteLogRelToString(lrel_inst,NULL); |
179 |
|
|
Tcl_AppendResult(interp,tmp,(char *)NULL); |
180 |
|
|
ascfree(tmp); |
181 |
|
|
Tcl_AppendResult(interp,"} ",(char *)NULL); |
182 |
|
|
} |
183 |
|
|
} |
184 |
|
|
if (!save) { |
185 |
|
|
gl_destroy(g_brow_lrellist); |
186 |
|
|
g_brow_lrellist=NULL; |
187 |
|
|
gl_destroy(g_brow_condlrellist); |
188 |
|
|
g_brow_condlrellist=NULL; |
189 |
|
|
} |
190 |
|
|
return TCL_OK; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
|
194 |
|
|
/* This function is particular for conditional logical relations */ |
195 |
|
|
|
196 |
|
|
int Asc_BrowWriteCondLogRelListCmd(ClientData cdata,Tcl_Interp *interp, |
197 |
|
|
int argc, CONST84 char *argv[]) |
198 |
|
|
{ |
199 |
|
|
struct Instance *i, *lrel_inst; |
200 |
|
|
unsigned long len, c; |
201 |
|
|
int save=0; |
202 |
|
|
|
203 |
|
|
(void)cdata; /* stop gcc whine about unused parameter */ |
204 |
|
|
|
205 |
|
|
if (( argc < 2 ) || ( argc > 3 )) { |
206 |
|
|
Tcl_AppendResult(interp,"wrong # args : ", |
207 |
|
|
"Usage \"bgetcondlogrels\" ?cur?search? save",(char *)NULL); |
208 |
|
|
return TCL_ERROR; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
if (strncmp(argv[1],"current",3)==0) { |
212 |
|
|
i = g_curinst; |
213 |
|
|
} else { |
214 |
|
|
if (strncmp(argv[1],"search",3)==0) { |
215 |
|
|
i = g_search_inst; |
216 |
|
|
} else { |
217 |
|
|
Tcl_SetResult(interp, "invalid args to \"bgetcondlogrels\"", TCL_STATIC); |
218 |
|
|
return TCL_ERROR; |
219 |
|
|
} |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
if (argc==3) { |
223 |
|
|
if (strncmp(argv[2],"save",4)==0) { |
224 |
|
|
save = 1; |
225 |
|
|
} |
226 |
|
|
} |
227 |
|
|
if (!i) { |
228 |
|
|
return TCL_ERROR; |
229 |
|
|
} |
230 |
|
|
|
231 |
|
|
if (!g_brow_lrellist) { |
232 |
|
|
g_brow_lrellist = gl_create(40L); |
233 |
|
|
} |
234 |
|
|
if (!g_brow_condlrellist) { |
235 |
|
|
g_brow_condlrellist = gl_create(40L); |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
VisitInstanceTree(i,BrowGetLogRelations,0,0); |
239 |
|
|
|
240 |
|
|
len = gl_length(g_brow_condlrellist); |
241 |
|
|
if (len) { |
242 |
|
|
for (c=1;c<=len;c++) { |
243 |
|
|
char *tmp; |
244 |
|
|
lrel_inst = (struct Instance *)gl_fetch(g_brow_condlrellist,c); |
245 |
|
|
Tcl_AppendResult(interp,"{",(char *)NULL); |
246 |
|
|
tmp = WriteLogRelToString(lrel_inst,NULL); |
247 |
|
|
Tcl_AppendResult(interp,tmp,(char *)NULL); |
248 |
|
|
ascfree(tmp); |
249 |
|
|
Tcl_AppendResult(interp,"} ",(char *)NULL); |
250 |
|
|
} |
251 |
|
|
} |
252 |
|
|
if (!save) { |
253 |
|
|
gl_destroy(g_brow_lrellist); |
254 |
|
|
g_brow_lrellist=NULL; |
255 |
|
|
gl_destroy(g_brow_condlrellist); |
256 |
|
|
g_brow_condlrellist=NULL; |
257 |
|
|
} |
258 |
|
|
return TCL_OK; |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
/* For postfix representation */ |
265 |
|
|
|
266 |
|
|
int Asc_BrowWriteLogRelListPostfixCmd(ClientData cdata,Tcl_Interp *interp, |
267 |
|
|
int argc, CONST84 char *argv[]) |
268 |
|
|
{ |
269 |
|
|
struct Instance *i, *lrel_inst; |
270 |
|
|
unsigned long len, c; |
271 |
|
|
int save=0; |
272 |
|
|
|
273 |
|
|
(void)cdata; /* stop gcc whine about unused parameter */ |
274 |
|
|
|
275 |
|
|
if (( argc < 2 ) || ( argc > 3 )) { |
276 |
|
|
Tcl_AppendResult(interp,"wrong # args : ", |
277 |
|
|
"Usage \"bgetlogrelspf\" ?cur?search? save",(char *)NULL); |
278 |
|
|
return TCL_ERROR; |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
if (strncmp(argv[1],"current",3)==0) { |
282 |
|
|
i = g_curinst; |
283 |
|
|
} else { |
284 |
|
|
if (strncmp(argv[1],"search",3)==0) { |
285 |
|
|
i = g_search_inst; |
286 |
|
|
} else { |
287 |
|
|
Tcl_SetResult(interp, "invalid args to \"bgetlogrelspf\"", TCL_STATIC); |
288 |
|
|
return TCL_ERROR; |
289 |
|
|
} |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
if (argc==3) { |
293 |
|
|
if (strncmp(argv[2],"save",4)==0) { |
294 |
|
|
save = 1; |
295 |
|
|
} |
296 |
|
|
} |
297 |
|
|
|
298 |
|
|
if (!i) { |
299 |
|
|
return TCL_ERROR; |
300 |
|
|
} |
301 |
|
|
|
302 |
|
|
|
303 |
|
|
if (!g_brow_lrellist) { |
304 |
|
|
g_brow_lrellist = gl_create(40L); |
305 |
|
|
} |
306 |
|
|
if (!g_brow_condlrellist) { |
307 |
|
|
g_brow_condlrellist = gl_create(40L); |
308 |
|
|
} |
309 |
|
|
|
310 |
|
|
VisitInstanceTree(i,BrowGetLogRelations,0,0); |
311 |
|
|
|
312 |
|
|
len = gl_length(g_brow_lrellist); |
313 |
|
|
for (c=1;c<=len;c++) { |
314 |
|
|
char *tmp; |
315 |
|
|
lrel_inst = (struct Instance *)gl_fetch(g_brow_lrellist,c); |
316 |
|
|
Tcl_AppendResult(interp,"{",(char *)NULL); |
317 |
|
|
tmp = WriteLogRelPostfixToString(lrel_inst,NULL); |
318 |
|
|
Tcl_AppendResult(interp,tmp,(char *)NULL); |
319 |
|
|
ascfree(tmp); |
320 |
|
|
Tcl_AppendResult(interp,"} ",(char *)NULL); |
321 |
|
|
} |
322 |
|
|
if (!save) { |
323 |
|
|
gl_destroy(g_brow_lrellist); |
324 |
|
|
g_brow_lrellist=NULL; |
325 |
|
|
gl_destroy(g_brow_condlrellist); |
326 |
|
|
g_brow_condlrellist=NULL; |
327 |
|
|
} |
328 |
|
|
return TCL_OK; |
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
|
332 |
|
|
/* Get a list of logical relations involving the current |
333 |
|
|
* boolean instance |
334 |
|
|
*/ |
335 |
|
|
|
336 |
|
|
int Asc_BrowWriteLogRelsForAtomCmd(ClientData cdata,Tcl_Interp *interp, |
337 |
|
|
int argc, CONST84 char *argv[]) |
338 |
|
|
{ |
339 |
|
|
CONST struct logrelation *lrel; |
340 |
|
|
struct Instance *i, *lrel_inst; |
341 |
|
|
unsigned long nlrels, c; |
342 |
|
|
|
343 |
|
|
(void)cdata; /* stop gcc whine about unused parameter */ |
344 |
|
|
|
345 |
|
|
if ( argc != 2 ) { |
346 |
|
|
Tcl_AppendResult(interp,"wrong # args : ", |
347 |
|
|
"Usage :__brow_lrelsforatom ?cur?search?",(char *)NULL); |
348 |
|
|
return TCL_ERROR; |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
if (strncmp(argv[1],"current",3)==0) { |
352 |
|
|
i = g_curinst; |
353 |
|
|
} else { |
354 |
|
|
if (strncmp(argv[1],"search",3)==0) { |
355 |
|
|
i = g_search_inst; |
356 |
|
|
} else { |
357 |
|
|
Tcl_SetResult(interp, "invalid args to \"__brow_lrelsforatom\"", |
358 |
|
|
TCL_STATIC); |
359 |
|
|
return TCL_ERROR; |
360 |
|
|
} |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
if (!i) { |
364 |
|
|
return TCL_ERROR; |
365 |
|
|
} |
366 |
|
|
|
367 |
|
|
if ( (InstanceKind(i)!= BOOLEAN_ATOM_INST ) && |
368 |
|
|
(InstanceKind(i)!= BOOLEAN_CONSTANT_INST ) ) { |
369 |
|
|
Tcl_AppendResult(interp,"Only boolean atoms are allowed", |
370 |
|
|
"in logical relations",(char *)NULL); |
371 |
|
|
return TCL_ERROR; |
372 |
|
|
} |
373 |
|
|
|
374 |
|
|
nlrels = LogRelationsCount(i); |
375 |
|
|
for (c=1;c<=nlrels;c++) { |
376 |
|
|
char *tmp; |
377 |
|
|
lrel_inst = LogRelationsForInstance(i,c); |
378 |
|
|
lrel = GetInstanceLogRelOnly(lrel_inst); |
379 |
|
|
Tcl_AppendResult(interp,"{",(char *)NULL); |
380 |
|
|
tmp = WriteLogRelToString(lrel_inst,NULL); |
381 |
|
|
Tcl_AppendResult(interp,tmp,(char *)NULL); |
382 |
|
|
ascfree(tmp); |
383 |
|
|
if (LogRelIsCond(lrel)) { |
384 |
|
|
Tcl_AppendResult(interp," Conditional Logical Relation",(char *)NULL); |
385 |
|
|
} |
386 |
|
|
Tcl_AppendResult(interp,"} ",(char *)NULL); |
387 |
|
|
} |
388 |
|
|
return TCL_OK; |
389 |
|
|
} |
390 |
|
|
|
391 |
|
|
|