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

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