/[ascend]/trunk/ascend/compiler/exprio.c
ViewVC logotype

Contents of /trunk/ascend/compiler/exprio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2781 - (show annotations) (download) (as text)
Fri Jun 20 05:12:07 2014 UTC (3 years, 11 months ago) by jpye
File MIME type: text/x-csrc
File size: 9409 byte(s)
remove RCS comments per warnings from clang 3.4
1 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *//* @file
18 Expression Output Routines
19 *//*
20 by Tom Epperly
21 Last in CVS: $Revision: 1.14 $ $Date: 1998/04/10 23:25:42 $ $Author: ballan $
22 */
23
24 #include <ascend/general/platform.h>
25 #include <ascend/general/panic.h>
26 #include <ascend/general/ascMalloc.h>
27 #include <ascend/general/dstring.h>
28
29 #include "functype.h"
30 #include "expr_types.h"
31 #include "func.h"
32 #include "instance_enum.h"
33 #include <ascend/general/list.h>
34 #include "extfunc.h"
35 #include "exprs.h"
36 #include "exprio.h"
37 #include "nameio.h"
38 #include "setio.h"
39
40 CONST char *ExprEnumName(CONST enum Expr_enum t)
41 {
42 switch (t) {
43 case e_nop:
44 return "e_nop";
45 case e_undefined:
46 return "e_undefined";
47 case e_glassbox:
48 return "e_glassbox";
49 case e_blackbox:
50 return "e_blackbox";
51 case e_opcode:
52 return "e_opcode";
53 case e_token:
54 return "e_token";
55 case e_zero:
56 return "e_zero";
57 case e_real:
58 return "e_real";
59 case e_int:
60 return "e_int";
61 case e_var:
62 return "e_var";
63 case e_uminus:
64 return "e_uminus";
65 case e_func:
66 return "e_func";
67 case e_plus:
68 return "e_plus";
69 case e_minus:
70 return "e_minus";
71 case e_times:
72 return "e_times";
73 case e_divide:
74 return "e_divide";
75 case e_power:
76 return "e_power";
77 case e_ipower:
78 return "e_ipower";
79 case e_notequal:
80 return "e_notequal";
81 case e_equal:
82 return "e_equal";
83 case e_less:
84 return "e_less";
85 case e_greater:
86 return "e_greater";
87 case e_lesseq:
88 return "e_lesseq";
89 case e_greatereq:
90 return "e_greatereq";
91 case e_maximize:
92 return "e_maximize";
93 case e_minimize:
94 return "e_minimize";
95 case e_boolean:
96 return "e_boolean";
97 case e_or:
98 return "e_or";
99 case e_and:
100 return "e_and";
101 case e_not:
102 return "e_not";
103 case e_subexpr:
104 return "e_subexpr";
105 case e_const:
106 return "e_const";
107 case e_par:
108 return "e_par";
109 case e_sum:
110 return "e_sum";
111 case e_prod:
112 return "e_prod";
113 case e_symbol:
114 return "e_symbol";
115 case e_set:
116 return "e_set";
117 case e_in:
118 return "e_in";
119 case e_st:
120 return "e_st";
121 case e_card:
122 return "e_card";
123 case e_choice:
124 return "e_choice";
125 case e_union:
126 return "e_union";
127 case e_inter:
128 return "e_inter";
129 case e_qstring:
130 return "e_qstring";
131 default:
132 return "UNKNOWN_TYPE";
133 }
134 }
135
136 void WriteExprNode(FILE *f, CONST struct Expr *e)
137 {
138 AssertMemory(e);
139 switch(ExprType(e)) {
140 case e_uminus:
141 PUTC('-',f);
142 break;
143 case e_plus:
144 PUTC('+',f);
145 break;
146 case e_minus:
147 PUTC('-',f);
148 break;
149 case e_times:
150 PUTC('*',f);
151 break;
152 case e_divide:
153 PUTC('/',f);
154 break;
155 case e_power:
156 PUTC('^',f);
157 break;
158 case e_boolean:
159 switch (ExprBValue(e)) {
160 case 0:
161 FPRINTF(f,"FALSE");
162 break;
163 case 2:
164 FPRINTF(f,"ANY");
165 break;
166 default:
167 FPRINTF(f,"TRUE");
168 break;
169 }
170 break;
171 case e_and:
172 FPRINTF(f,"AND");
173 break;
174 case e_or:
175 FPRINTF(f,"OR");
176 break;
177 case e_not:
178 FPRINTF(f,"NOT");
179 break;
180 case e_equal:
181 PUTC('=',f);
182 break;
183 case e_notequal:
184 FPRINTF(f,"<>");
185 break;
186 case e_boolean_eq:
187 FPRINTF(f,"==");
188 break;
189 case e_boolean_neq:
190 FPRINTF(f,"!=");
191 break;
192 case e_less:
193 PUTC('<',f);
194 break;
195 case e_greater:
196 PUTC('>',f);
197 break;
198 case e_lesseq:
199 FPRINTF(f,"<=");
200 break;
201 case e_greatereq:
202 FPRINTF(f,">=");
203 break;
204 case e_st:
205 PUTC('|',f);
206 break;
207 case e_in:
208 FPRINTF(f,"IN");
209 break;
210 case e_var:
211 WriteName(f,ExprName(e));
212 break;
213 case e_int:
214 FPRINTF(f,"%ld",ExprIValue(e));
215 break;
216 case e_zero:
217 FPRINTF(f,"0");
218 break;
219 case e_real:
220 FPRINTF(f,"%g",ExprRValue(e));
221 break;
222 case e_set:
223 PUTC('[',f);
224 WriteSet(f,ExprSValue(e));
225 PUTC(']',f);
226 break;
227 case e_symbol:
228 FPRINTF(f,"'%s'",SCP(ExprSymValue(e)));
229 break;
230 case e_qstring:
231 FPRINTF(f,"\"%s\"",ExprQStrValue(e));
232 break;
233 case e_card:
234 FPRINTF(f,"CARD[");
235 WriteSet(f,ExprBuiltinSet(e));
236 PUTC(']',f);
237 break;
238 case e_choice:
239 FPRINTF(f,"CHOICE[");
240 WriteSet(f,ExprBuiltinSet(e));
241 PUTC(']',f);
242 break;
243 case e_sum:
244 FPRINTF(f,"SUM[");
245 WriteSet(f,ExprBuiltinSet(e));
246 PUTC(']',f);
247 break;
248 case e_prod:
249 FPRINTF(f,"PROD[");
250 WriteSet(f,ExprBuiltinSet(e));
251 PUTC(']',f);
252 break;
253 case e_union:
254 FPRINTF(f,"UNION[");
255 WriteSet(f,ExprBuiltinSet(e));
256 PUTC(']',f);
257 break;
258 case e_inter:
259 FPRINTF(f,"INTERSECTION[");
260 WriteSet(f,ExprBuiltinSet(e));
261 PUTC(']',f);
262 break;
263 case e_minimize:
264 FPRINTF(f,"MINIMIZE");
265 break;
266 case e_maximize:
267 FPRINTF(f,"MAXIMIZE");
268 break;
269 case e_func:
270 FPRINTF(f,FuncName(ExprFunc(e)));
271 break;
272 case e_satisfied:
273 FPRINTF(f,"SATISFIED(");
274 WriteName(f,SatisfiedExprName(e));
275 if (SatisfiedExprRValue(e)!=DBL_MAX){
276 FPRINTF(f,",");
277 FPRINTF(f,"%g",SatisfiedExprRValue(e));
278 }
279 PUTC(')',f);
280 break;
281 default:
282 FPRINTF(f,"<term>");
283 break;
284 }
285 }
286
287
288 void WriteExpr(FILE *f, CONST struct Expr *e)
289 {
290 while (e!=NULL) {
291 AssertMemory(e);
292 WriteExprNode(f,e);
293 e = NextExpr(e);
294 if (e!=NULL) {
295 PUTC(' ',f);
296 }
297 }
298 return;
299 }
300
301 /*
302 * A ridiculous piece of code to convert an expr back into
303 * a string. This version is in postfix, as it was read in.
304 * The temporary buffer is used to collect known small strings
305 * which then get appended to the dynamic string. These cases
306 * break rather than return. The longer strings get appended
307 * immeadiately, and return.
308 */
309 void WriteExprNode2Str(Asc_DString *dstring, CONST struct Expr *e)
310 {
311 char tmp[64];
312
313 AssertMemory(e);
314 switch(ExprType(e)) {
315 case e_uminus:
316 strcpy(tmp,"-");
317 break;
318 case e_plus:
319 strcpy(tmp,"+");
320 break;
321 case e_minus:
322 strcpy(tmp,"-");
323 break;
324 case e_times:
325 strcpy(tmp,"*");
326 break;
327 case e_divide:
328 strcpy(tmp,"/");
329 break;
330 case e_power:
331 strcpy(tmp,"^");
332 break;
333 case e_ipower:
334 strcpy(tmp,"^");
335 break;
336 case e_boolean:
337 ExprBValue(e) ? strcpy(tmp,"TRUE") : strcpy(tmp,"FALSE");
338 break;
339 case e_and:
340 strcpy(tmp,"AND");
341 break;
342 case e_or:
343 strcpy(tmp,"OR");
344 break;
345 case e_not:
346 strcpy(tmp,"NOT");
347 break;
348 case e_equal:
349 strcpy(tmp,"=");
350 break;
351 case e_notequal:
352 strcpy(tmp,"<>");
353 break;
354 case e_less:
355 strcpy(tmp,"<");
356 break;
357 case e_greater:
358 strcpy(tmp,">");
359 break;
360 case e_lesseq:
361 strcpy(tmp,"<=");
362 break;
363 case e_greatereq:
364 strcpy(tmp,">=");
365 break;
366 case e_st:
367 strcpy(tmp,"/");
368 break;
369 case e_in:
370 strcpy(tmp,"IN");
371 break;
372 case e_var:
373 WriteName2Str(dstring,ExprName(e));
374 return;
375 case e_int:
376 sprintf(tmp,"%ld",ExprIValue(e));
377 break;
378 case e_zero:
379 sprintf(tmp,"0");
380 break;
381 case e_real:
382 sprintf(tmp,"%g",ExprRValue(e));
383 break;
384 case e_set:
385 Asc_DStringAppend(dstring,"[",-1);
386 WriteSet2Str(dstring,ExprSValue(e));
387 Asc_DStringAppend(dstring,"]",-1);
388 return;
389 case e_symbol:
390 sprintf(tmp,"'%s'",SCP(ExprSymValue(e)));
391 break;
392 case e_qstring:
393 sprintf(tmp,"\"%s\"",ExprQStrValue(e));
394 break;
395 case e_card:
396 Asc_DStringAppend(dstring,"CARD[",-1);
397 WriteSet2Str(dstring,ExprBuiltinSet(e));
398 Asc_DStringAppend(dstring,"]",-1);
399 return;
400 case e_choice:
401 Asc_DStringAppend(dstring,"CHOICE[",-1);
402 WriteSet2Str(dstring,ExprBuiltinSet(e));
403 Asc_DStringAppend(dstring,"]",-1);
404 return;
405 case e_sum:
406 Asc_DStringAppend(dstring,"SUM[",-1);
407 WriteSet2Str(dstring,ExprBuiltinSet(e));
408 Asc_DStringAppend(dstring,"]",-1);
409 return;
410 case e_prod:
411 Asc_DStringAppend(dstring,"PROD[",-1);
412 WriteSet2Str(dstring,ExprBuiltinSet(e));
413 Asc_DStringAppend(dstring,"]",-1);
414 return;
415 case e_union:
416 Asc_DStringAppend(dstring,"UNION[",-1);
417 WriteSet2Str(dstring,ExprBuiltinSet(e));
418 Asc_DStringAppend(dstring,"]",-1);
419 return;
420 case e_inter:
421 Asc_DStringAppend(dstring,"INTERSECTION[",-1);
422 WriteSet2Str(dstring,ExprBuiltinSet(e));
423 Asc_DStringAppend(dstring,"]",-1);
424 return;
425 case e_minimize:
426 strcpy(tmp,"MINIMIZE");
427 break;
428 case e_maximize:
429 strcpy(tmp,"MAXIMIZE");
430 break;
431 case e_func:
432 strcpy(tmp,FuncName(ExprFunc(e)));
433 break;
434 default:
435 strcpy(tmp,"<term>");
436 break;
437 }
438 Asc_DStringAppend(dstring,tmp,-1);
439 }
440
441 void WriteExpr2Str(Asc_DString *dstring, CONST struct Expr *e)
442 {
443 while (e!=NULL) {
444 AssertMemory(e);
445 WriteExprNode2Str(dstring,e);
446 e = NextExpr(e);
447 if (e!=NULL) {
448 Asc_DStringAppend(dstring," ",-1);
449 }
450 }
451 return;
452 }
453
454
455
456
457
458
459
460
461

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22