/[ascend]/trunk/base/generic/compiler/exprs.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/exprs.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 669 - (show annotations) (download) (as text)
Wed Jun 21 07:00:45 2006 UTC (13 years, 8 months ago) by johnpye
File MIME type: text/x-chdr
File size: 13931 byte(s)
Merged changes from DAE branch (revisions 702 to 819) back into trunk.
This adds the Integration API to the ASCEND solver (in base/generic).
Also provides pre-alpha support for 'IDA' from the SUNDIALS suite, a DAE solver.
Many other minor code clean-ups, including adoption of new 'ASC_NEW' and friends (to replace 'ascmalloc')
Added some very sketchy stuff providing 'DIFF(...)' syntax, although it is anticipated that this will be removed.
1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//**
20 @file
21 Expression Module
22
23 Requires:
24 #include "utilities/ascConfig.h"
25 #include "fractions.h"
26 #include "compiler.h"
27 #include "dimen.h"
28 #include "expr_types.h"
29 *//*
30 by Tom Epperly
31 Last in CVS: $Revision: 1.11 $ $Date: 1998/02/05 16:36:00 $ $Author: ballan $
32 */
33
34 #ifndef ASC_EXPRS_H
35 #define ASC_EXPRS_H
36
37 extern struct Expr *CreateVarExpr(struct Name *n);
38 /**<
39 * Create a name type expr node.
40 */
41
42 extern struct Expr *CreateDiffExpr(struct Name *n);
43 /**<
44 Create a time-derivative-of-a-single-variable node. Currently just returns
45 the same as 0.0 (a real-valued expression with wildcard dimensions)
46 */
47
48 extern void InitVarExpr(struct Expr *e, CONST struct Name *n);
49 /**<
50 * Given an empty expr node, initialize it to contain the name.
51 * Generally this is only used to init a temporary expr node
52 * that you want to be able to destroy later (or forget later)
53 * without destroying the contents -- in this case name.
54 * How you create and destroy e is your business. using stack space
55 * is suggested.<br><br>
56 *
57 * The problem with creating a varexpr with a name you want to keep
58 * after the node dies is that the name is destroyed when the node is.
59 */
60
61 extern struct Expr *CreateOpExpr(enum Expr_enum t);
62 /**<
63 * Create an operator node.
64 */
65
66 extern struct Expr *CreateSatisfiedExpr(struct Name *n,
67 double tol,
68 CONST dim_type *dims);
69 /**<
70 * Create an satisfied operator node.
71 */
72
73 extern struct Expr *CreateFuncExpr(CONST struct Func *f);
74 /**<
75 * Create a function node.
76 */
77
78 extern struct Expr *CreateIntExpr(long i);
79 /**<
80 * Create an integer node.
81 */
82
83 extern struct Expr *CreateRealExpr(double r, CONST dim_type *dims);
84 /**<
85 * Create a real node with value r and dimensions "dims".
86 */
87
88 extern struct Expr *CreateTrueExpr(void);
89 /**<
90 * Create a boolean node with value TRUE.
91 */
92
93 extern struct Expr *CreateFalseExpr(void);
94 /**<
95 * Create a boolean node with value FALSE.
96 */
97
98 extern struct Expr *CreateAnyExpr(void);
99 /**<
100 * Create a boolean node with undefined value. b_value will be 2.
101 */
102
103 extern struct Expr *CreateSetExpr(struct Set *set);
104 /**<
105 * Create a set node.
106 */
107
108 extern struct Expr *CreateSymbolExpr(symchar *sym);
109 /**<
110 * Create a symbol node.
111 */
112
113 extern struct Expr *CreateQStringExpr(CONST char *qstring);
114 /**<
115 * Create a string node. The difference is that string may contain
116 * anything and are quoted as "qstring is string", whereas symbols
117 * are of the form 'symbol' and may have content restrictions.
118 */
119
120 extern struct Expr *CreateBuiltin(enum Expr_enum t, struct Set *set);
121 /**<
122 * Create a node for SUM, PROD, UNION, etc....
123 */
124
125 extern void LinkExprs(struct Expr *cur, struct Expr *next);
126 /**<
127 * Link cur to next.
128 */
129
130 extern unsigned long ExprListLength(CONST struct Expr *e);
131 /**<
132 * Traverse list to the end to find the length.
133 * Sometimes one would like to know the length a priori.
134 */
135
136 #ifdef NDEBUG
137 #define NextExpr(e) ((e)->next)
138 #else
139 #define NextExpr(e) NextExprF(e)
140 #endif
141 /**<
142 * Return the expr node linked to e.
143 * @param e <code>CONST struct Expr*</code>, the expr to query.
144 * @return Returns the linked node as type <code>struct Expr*</code>.
145 * @see NextExprF()
146 */
147 extern struct Expr *NextExprF(CONST struct Expr *e);
148 /**<
149 * Return the expr node linked to e.
150 * Implementation function for NextExpr(). Do not use this function
151 * directly - use NextExpr() instead.
152 */
153
154 #ifdef NDEBUG
155 #define ExprType(e) ((e)->t)
156 #else
157 #define ExprType(e) ExprTypeF(e)
158 #endif
159 /**<
160 * Return the type of e.
161 * @param e <code>CONST struct Expr*</code>, the expr to query.
162 * @return Returns the type as a <code>enum Expr_enum</code>.
163 * @see ExprTypeF()
164 */
165 extern enum Expr_enum ExprTypeF(CONST struct Expr *e);
166 /**<
167 * Return the type of e.
168 * Implementation function for ExprType(). Do not use this function
169 * directly - use ExprType() instead.
170 */
171
172 #ifdef NDEBUG
173 #define ExprName(e) ((e)->v.nptr)
174 #else
175 #define ExprName(e) ExprNameF(e)
176 #endif
177 /**<
178 * Return the name field of a var type expr node.
179 * @param e <code>CONST struct Expr*</code>, the expr to query.
180 * @return Returns the name as a <code>CONST struct Name*</code>.
181 * @see ExprNameF()
182 */
183 extern CONST struct Name *ExprNameF(CONST struct Expr *e);
184 /**<
185 * Return the name field of a var type expr node.
186 * Implementation function for ExprName(). Do not use this function
187 * directly - use ExprName() instead.
188 */
189
190 #ifdef NDEBUG
191 #define ExprFunc(e) ((e)->v.fptr)
192 #else
193 #define ExprFunc(e) ExprFuncF(e)
194 #endif
195 /**<
196 * Return the func field of a function type expr node.
197 * @param e <code>CONST struct Expr*</code>, the expr to query.
198 * @return Returns the func as a <code>CONST struct Func*</code>.
199 * @see ExprFuncF()
200 */
201 extern CONST struct Func *ExprFuncF(CONST struct Expr *e);
202 /**<
203 * Return the func field of a function type expr node.
204 * Implementation function for ExprFunc(). Do not use this function
205 * directly - use ExprFunc() instead.
206 */
207
208 #ifdef NDEBUG
209 #define ExprIValue(e) ((e)->v.ivalue)
210 #else
211 #define ExprIValue(e) ExprIValueF(e)
212 #endif
213 /**<
214 * Return the integer value of a integer type expr node.
215 * @param e <code>CONST struct Expr*</code>, the expr to query.
216 * @return Returns the value as a <code>long</code>.
217 * @see ExprIValueF()
218 */
219 extern long ExprIValueF(CONST struct Expr *e);
220 /**<
221 * Return the integer value of a integer type expr node.
222 * Implementation function for ExprIValue(). Do not use this function
223 * directly - use ExprIValue() instead.
224 */
225
226 #ifdef NDEBUG
227 #define ExprRValue(e) ((e)->v.r.rvalue)
228 #else
229 #define ExprRValue(e) ExprRValueF(e)
230 #endif
231 /**<
232 * Return the real value of a real type expr node.
233 * @param e <code>CONST struct Expr*</code>, the expr to query.
234 * @return Returns the value as a <code>double</code>.
235 * @see ExprRValueF()
236 */
237 extern double ExprRValueF(CONST struct Expr *e);
238 /**<
239 * Return the real value of a real type expr node.
240 * Implementation function for ExprRValue(). Do not use this function
241 * directly - use ExprRValue() instead.
242 */
243
244 #ifdef NDEBUG
245 #define ExprRDimensions(e) ((e)->v.r.dimensions)
246 #else
247 #define ExprRDimensions(e) ExprRDimensionsF(e)
248 #endif
249 /**<
250 * Return the dimensions of a real type expr node.
251 * @param e <code>CONST struct Expr*</code>, the expr to query.
252 * @return Returns the value as a <code>CONST dim_type*</code>.
253 * @see ExprRDimensionsF()
254 */
255 extern CONST dim_type *ExprRDimensionsF(CONST struct Expr *e);
256 /**<
257 * Return the dimensions of a real type expr node.
258 * Implementation function for ExprRDimensions(). Do not use this function
259 * directly - use ExprRDimensions() instead.
260 */
261
262 #ifdef NDEBUG
263 #define SatisfiedExprName(e) ((e)->v.se.sen)
264 #else
265 #define SatisfiedExprName(e) SatisfiedExprNameF(e)
266 #endif
267 /**<
268 * Return the name field of a var type satisfied expr node.
269 * @param e <code>CONST struct Expr*</code>, the expr to query.
270 * @return Returns the name as a <code>CONST struct Name*</code>.
271 * @see SatisfiedExprNameF()
272 */
273 extern CONST struct Name *SatisfiedExprNameF(CONST struct Expr *e);
274 /**<
275 * Return the name field of a var type satisfied expr node.
276 * Implementation function for SatisfiedExprName(). Do not use this function
277 * directly - use SatisfiedExprName() instead.
278 */
279
280 #ifdef NDEBUG
281 #define SatisfiedExprRValue(e) ((e)->v.se.ser.rvalue)
282 #else
283 #define SatisfiedExprRValue(e) SatisfiedExprRValueF(e)
284 #endif
285 /**<
286 * Return the real value of a real type satisfied expr node.
287 * @param e <code>CONST struct Expr*</code>, the expr to query.
288 * @return Returns the value as a <code>double</code>.
289 * @see SatisfiedExprRValueF()
290 */
291 extern double SatisfiedExprRValueF(CONST struct Expr *e);
292 /**<
293 * Return the real value of a real type satisfied expr node.
294 * Implementation function for SatisfiedExprRValue(). Do not use this function
295 * directly - use SatisfiedExprRValue() instead.
296 */
297
298 #ifdef NDEBUG
299 #define SatisfiedExprRDimensions(e) ((e)->v.se.ser.dimensions)
300 #else
301 #define SatisfiedExprRDimensions(e) SatisfiedExprRDimensionsF(e)
302 #endif
303 /**<
304 * Return the dimensions of a real type satisfied expr node.
305 * @param e <code>CONST struct Expr*</code>, the expr to query.
306 * @return Returns the dimension as a <code>CONST dim_type*</code>.
307 * @see SatisfiedExprRDimensionsF()
308 */
309 extern CONST dim_type *SatisfiedExprRDimensionsF(CONST struct Expr *e);
310 /**<
311 * Return the dimensions of a real type satisfied expr node.
312 * Implementation function for SatisfiedExprRDimensions(). Do not use this function
313 * directly - use SatisfiedExprRDimensions() instead.
314 */
315
316 #ifdef NDEBUG
317 #define ExprBValue(e) ((e)->v.bvalue)
318 #else
319 #define ExprBValue(e) ExprBValueF(e)
320 #endif
321 /**<
322 * Return the boolean value of a boolean type satisfied expr node.
323 * Returns 1 if e is TRUE, 0 if e is FALSE, 2 if e is ANY.
324 * @param e <code>CONST struct Expr*</code>, the expr to query.
325 * @return Returns the value as an <code>int</code>.
326 * @see ExprBValueF()
327 */
328 extern int ExprBValueF(CONST struct Expr *e);
329 /**<
330 * Return 1 if e is TRUE, 0 if e is FALSE, 2 if e is ANY.
331 * Implementation function for ExprBValue(). Do not use this function
332 * directly - use ExprBValue() instead.
333 */
334
335 #ifdef NDEBUG
336 #define ExprSValue(e) ((e)->v.s)
337 #else
338 #define ExprSValue(e) ExprSValueF(e)
339 #endif
340 /**<
341 * Return the set value of a set node type.
342 * @param e <code>CONST struct Expr*</code>, the expr to query.
343 * @return Returns the value as an <code>struct Set*</code>.
344 * @see ExprSValueF()
345 */
346 extern struct Set *ExprSValueF(CONST struct Expr *e);
347 /**<
348 * Return the set value of a set node type.
349 * Implementation function for ExprSValue(). Do not use this function
350 * directly - use ExprSValue() instead.
351 */
352
353 #ifdef NDEBUG
354 #define ExprSymValue(e) ((e)->v.sym_ptr)
355 #else
356 #define ExprSymValue(e) ExprSymValueF(e)
357 #endif
358 /**<
359 * Return the symbol pointer value from a symbol node type.
360 * @param e <code>CONST struct Expr*</code>, the expr to query.
361 * @return Returns the value as an <code>symchar*</code>.
362 * @see ExprSymValueF()
363 */
364 extern symchar *ExprSymValueF(CONST struct Expr *e);
365 /**<
366 * Return the symbol pointer value from a symbol node type.
367 * Implementation function for ExprSymValue(). Do not use this function
368 * directly - use ExprSymValue() instead.
369 */
370
371 #ifdef NDEBUG
372 #define ExprQStrValue(e) ((e)->v.sym_ptr)
373 #else
374 #define ExprQStrValue(e) ExprQStrValueF(e)
375 #endif
376 /**<
377 * Return the string pointer value from a string node type.
378 * The difference between a string and a symbol, is that the former
379 * may contain whitespace. The type is called e_qstring
380 * @param e <code>CONST struct Expr*</code>, the expr to query.
381 * @return Returns the value as an <code>CONST char*</code>.
382 * @see ExprQStrValueF()
383 */
384 extern CONST char *ExprQStrValueF(CONST struct Expr *e);
385 /**<
386 * Return the string pointer value from a string node type.
387 * The difference between a string and a symbol, is that the former
388 * may contain whitespace. The type is called e_qstring
389 * Implementation function for ExprQStrValue(). Do not use this function
390 * directly - use ExprQStrValue() instead.
391 */
392
393 #ifdef NDEBUG
394 #define ExprBuiltinSet(e) ((e)->v.s)
395 #else
396 #define ExprBuiltinSet(e) ExprBuiltinSetF(e)
397 #endif
398 /**<
399 * Return the set argument for one of the builtin operations.
400 * SUM, PROD, CARD, etc..
401 * @param e <code>CONST struct Expr*</code>, the expr to query.
402 * @return Returns the set as an <code>CONST struct Set*</code>.
403 * @see ExprBuiltinSetF()
404 */
405 extern CONST struct Set *ExprBuiltinSetF(CONST struct Expr *e);
406 /**<
407 * Return the set argument for one of the builtin operations.
408 * SUM, PROD, CARD, etc.
409 * Implementation function for ExprBuiltinSet(). Do not use this function
410 * directly - use ExprBuiltinSet() instead.
411 */
412
413 extern struct Expr *CopyExprList(CONST struct Expr *e);
414 /**<
415 * Make and return a copy of e.
416 */
417
418 extern void DestroyExprList(struct Expr *e);
419 /**<
420 * Deallocate all the memory associated with e.
421 * Handles NULL input gracefully.
422 */
423
424 extern struct Expr *JoinExprLists(struct Expr *e1, struct Expr *e2);
425 /**<
426 * Append list e2 to the end of e1. This returns e1, unless e1
427 * is NULL in which case it returns e2.
428 */
429
430 extern int ExprsEqual(CONST struct Expr *e1, CONST struct Expr *e2);
431 /**<
432 * Return TRUE if and only if e1 and e2 are structurally equivalent.
433 */
434
435 extern int CompareExprs(CONST struct Expr *e1, CONST struct Expr *e2);
436 /**<
437 * Compares2 expressions.
438 * Return -1, 0, 1 as e1 is < == > e2.
439 * Expressions being complicated things, this is not easily
440 * explained. The expressions are being compared in the
441 * absence of an instance context, so we're looking for
442 * structural differences.
443 * The NULL Expr > all Expr.
444 */
445
446 extern void exprs_init_pool(void);
447 /**<
448 * Starts memory recycle. do not call twice before stopping recycle.
449 */
450
451 extern void exprs_destroy_pool(void);
452 /**<
453 * Stops memory recycle. do not call while ANY Expr are outstanding.
454 */
455
456 extern void exprs_report_pool(void);
457 /**<
458 * Write the pool report to ASCERR for the exprs pool.
459 */
460
461 #endif /* ASC_EXPRS_H */
462

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