1 |
/* |
2 |
* Atom Child Description List |
3 |
* by Tom Epperly |
4 |
* Version: $Revision: 1.10 $ |
5 |
* Version control file: $RCSfile: childinfo.h,v $ |
6 |
* Date last modified: $Date: 1998/02/05 16:35:41 $ |
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 |
* |
13 |
* The Ascend Language Interpreter is free software; you can redistribute |
14 |
* it and/or modify it under the terms of the GNU General Public License as |
15 |
* published by the Free Software Foundation; either version 2 of the |
16 |
* License, or (at your option) any later version. |
17 |
* |
18 |
* The Ascend Language Interpreter is distributed in hope that it will be |
19 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
21 |
* General Public License for more details. |
22 |
* |
23 |
* You should have received a copy of the GNU General Public License |
24 |
* along with the program; if not, write to the Free Software Foundation, |
25 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
26 |
* COPYING. |
27 |
* |
28 |
* These routines provide a list for storing descriptions of children of |
29 |
* atoms. |
30 |
*/ |
31 |
|
32 |
/** @file |
33 |
* Atom Child Description List. |
34 |
* <pre> |
35 |
* When #including childinfo.h, make sure these files are #included first: |
36 |
* #include "utilities/ascConfig.h" |
37 |
* #include "compiler.h" |
38 |
* #include "list.h" |
39 |
* #include "dimen.h" |
40 |
* #include "setinstval.h" |
41 |
* #include "instance_enum.h" |
42 |
* </pre> |
43 |
*/ |
44 |
|
45 |
#ifndef ASC_CHILDINFO_H |
46 |
#define ASC_CHILDINFO_H |
47 |
|
48 |
/** addtogroup compiler Compiler |
49 |
@{ |
50 |
*/ |
51 |
|
52 |
/** Atom child value for Real type. */ |
53 |
struct ChildDescR { |
54 |
double value; |
55 |
CONST dim_type *dims; |
56 |
}; |
57 |
|
58 |
/** Atom child value for Integer type. */ |
59 |
struct ChildDescI { |
60 |
long value; /**< always mutable */ |
61 |
}; |
62 |
|
63 |
/** Atom child value for Set type. */ |
64 |
struct ChildDescS{ |
65 |
struct set_t *slist; /**< set list */ |
66 |
unsigned is_int; /**< integer 1 or symbol 0 set */ |
67 |
}; |
68 |
|
69 |
/** Atom child value - union of all types. */ |
70 |
union ChildDescUnion { |
71 |
int bvalue; /**< boolean value */ |
72 |
struct ChildDescS s; /**< set information */ |
73 |
struct ChildDescI ivalue; /**< integer value */ |
74 |
struct ChildDescR rvalue; /**< real value */ |
75 |
symchar *svalue; /**< symbol value */ |
76 |
}; |
77 |
|
78 |
/** Atom child types. */ |
79 |
enum ChildDescT { |
80 |
bad_child, /**< invalid type. |
81 |
* This should never, ever, ever be seen except in childless |
82 |
* atoms who need a place holder. bad_child-ren are never |
83 |
* assigned and the UNION meaningless |
84 |
*/ |
85 |
real_child, /**< real type. */ |
86 |
integer_child, /**< integer type. */ |
87 |
boolean_child, /**< boolean type. */ |
88 |
set_child, /**< set type. */ |
89 |
symbol_child /**< symbol type. */ |
90 |
}; |
91 |
|
92 |
/** Atom child description. */ |
93 |
struct ChildDesc { |
94 |
enum ChildDescT t; /**< Child type. */ |
95 |
unsigned assigned; /**< Assigned flag = 0 or 1 */ |
96 |
union ChildDescUnion u; /**< Child value. */ |
97 |
}; |
98 |
|
99 |
#ifdef NDEBUG |
100 |
/** Initialize a child description structure (do nothing in release mode). */ |
101 |
#define ICDESC(x) |
102 |
/** Initialize a child description structure via a pointer (do nothing in release mode). */ |
103 |
#define ICDESCPTR(y) |
104 |
#else |
105 |
/** |
106 |
* Initialize a child description structure. |
107 |
* x must be a struct ChildDesc variable, NOT a pointer to same. |
108 |
* If you want to init a pointer contents, use ICDESCPTR(). |
109 |
*/ |
110 |
#define ICDESC(x) CDescInit(&(x)) |
111 |
/** |
112 |
* Initialize a child description structure via a pointer. |
113 |
* y must be a pointer to a struct ChildDesc variable. |
114 |
* If you want to init a ChildDesc variable directly, use ICDESC(). |
115 |
*/ |
116 |
#define ICDESCPTR(y) CDescInit(y) |
117 |
#endif |
118 |
|
119 |
extern void CDescInit(struct ChildDesc *c); |
120 |
/**< |
121 |
* <!-- CDescInit(c) --> |
122 |
* Initializes the contents of c to 0. |
123 |
* Do not call this function -- use ICDESC() or IDESCPTR() instead. |
124 |
*/ |
125 |
|
126 |
extern struct ChildDesc *CreateChildDescArray(unsigned long l); |
127 |
/**< |
128 |
* <!-- struct ChildDesc *CreateChildDescArray(l) --> |
129 |
* <!-- unsigned long l; --> |
130 |
* Allocate space for an array of length l. This will not initialize |
131 |
* the array in any special way. Use ICDESC() or ICDESCPTR() to initialize |
132 |
* the elements of the array. The array should be accessed using |
133 |
* AssignChildArrayElement() and GetChildArrayElement(). When finished |
134 |
* with the array, deallocate it using DestroyChildDescArray(). |
135 |
*/ |
136 |
|
137 |
extern struct ChildDesc *CreateEmptyChildDescArray(void); |
138 |
/**< |
139 |
* <!-- struct ChildDesc *CreateEmptyChildDescArray(); --> |
140 |
* Allocate space for an array of length 1. |
141 |
* The array element will be initialized as type bad_child (its value is |
142 |
* not initialized). The array should be accessed using |
143 |
* AssignChildArrayElement() and GetChildArrayElement(). When finished |
144 |
* with the array, deallocate it using DestroyChildDescArray(). |
145 |
*/ |
146 |
|
147 |
extern void DestroyChildDescArray(struct ChildDesc *c, |
148 |
unsigned long l); |
149 |
/**< |
150 |
* <!-- void DestroyChildDescArray(c,l) --> |
151 |
* <!-- struct ChildDesc *c; --> |
152 |
* <!-- unsigned long l; --> |
153 |
* This routine will deallocate the space for array c of length l. |
154 |
* Any elements of c which are sets will have all subelements |
155 |
* properly deallocated also. |
156 |
*/ |
157 |
|
158 |
#ifdef NDEBUG |
159 |
#define AssignChildArrayElement(a,n,e) (a)[(n)-1] = (e) |
160 |
#else |
161 |
#define AssignChildArrayElement(a,n,e) AssignChildArrayElementF((a),(n),(e)) |
162 |
#endif |
163 |
/**< |
164 |
* Set an element of a ChildDesc array. |
165 |
* @param a struct ChildDesc*, the array to modify. |
166 |
* @param n unsigned long, index of the element to set. |
167 |
* Should be between 1 and the length of "a" (never 0). |
168 |
* @param e struct ChildDesc, the value to which element n should be set. |
169 |
* @return No return value. |
170 |
* @see AssignChildArrayElementF() |
171 |
*/ |
172 |
extern void AssignChildArrayElementF(struct ChildDesc *a, |
173 |
unsigned long n, |
174 |
struct ChildDesc e); |
175 |
/**< |
176 |
* <!-- macro AssignChildArrayElement(a,n,e) --> |
177 |
* <!-- void AssignChildArrayElementF(a,n,e) --> |
178 |
* <!-- struct ChildDesc *a; --> |
179 |
* <!-- unsigned long n; --> |
180 |
* <!-- struct ChildDesc e; --> |
181 |
* <!-- --> |
182 |
* <!-- Set the n'th child's description to e. n should range from 1 --> |
183 |
* <!-- to the length of "a". n should never be zero. --> |
184 |
* Implementation function for AssignChildArrayElement(). |
185 |
* Do not use this function directly - use AssignChildArrayElement() instead. |
186 |
*/ |
187 |
|
188 |
#ifdef NDEBUG |
189 |
#define GetChildArrayElement(a,n) ((a)[n-1]) |
190 |
#else |
191 |
#define GetChildArrayElement(a,n) GetChildArrayElementF((a),(n)) |
192 |
#endif |
193 |
/**< |
194 |
* Get an element from a ChildDesc array. |
195 |
* @param a struct ChildDesc*, the array to query. |
196 |
* @param n unsigned long, index of the element to retrieve. |
197 |
* Should be between 1 and the length of "a" (never 0). |
198 |
* @return Returns a ChildDesc corresponding to element n. |
199 |
* @see GetChildArrayElementF() |
200 |
*/ |
201 |
extern struct ChildDesc GetChildArrayElementF(CONST struct ChildDesc *a, |
202 |
unsigned long n); |
203 |
/**< |
204 |
* <!-- macro GetChildArrayElement(a,n) --> |
205 |
* <!-- struct ChildDesc GetChildArrayElementF(a,n) --> |
206 |
* <!-- const struct ChildDesc *a; --> |
207 |
* <!-- unsigned long n; --> |
208 |
* <!-- Return the n'th child description from "a". n ranges from 1 --> |
209 |
* <!-- to the length of "a". --> |
210 |
* Implementation function for GetChildArrayElement(). |
211 |
* Do not use this function directly - use GetChildArrayElement() instead. |
212 |
*/ |
213 |
|
214 |
#ifdef NDEBUG |
215 |
#define ChildDescType(e) ((e).t) |
216 |
#else |
217 |
#define ChildDescType(e) ChildDescTypeF(e) |
218 |
#endif |
219 |
/**< |
220 |
* Return the type of e. |
221 |
* @param e struct ChildDesc, the ChildDesc to query. |
222 |
* @return Returns the ChildDescT of e. |
223 |
* @see ChildDescTypeF() |
224 |
*/ |
225 |
extern enum ChildDescT ChildDescTypeF(struct ChildDesc e); |
226 |
/**< |
227 |
* <!-- macro ChildDescType(e) --> |
228 |
* <!-- enum ChildDescT ChildDescF(e) --> |
229 |
* <!-- struct ChildDesc e; --> |
230 |
* <!-- Return the type of e. --> |
231 |
* Implementation function for ChildDescType(). |
232 |
* Do not use this function directly - use ChildDescType() instead. |
233 |
*/ |
234 |
|
235 |
#ifdef NDEBUG |
236 |
#define ValueAssigned(e) ((e).assigned) |
237 |
#else |
238 |
#define ValueAssigned(e) ValueAssignedF(e) |
239 |
#endif |
240 |
/**< |
241 |
* Test whether ChildDesc e has been assigned a value. |
242 |
* @param e struct ChildDesc, the ChildDesc to query. |
243 |
* @return Returns as an int a true value if e has been assigned a |
244 |
* value, a false value otherwise. |
245 |
* @see ValueAssignedF() |
246 |
*/ |
247 |
extern int ValueAssignedF(struct ChildDesc e); |
248 |
/**< |
249 |
* <!-- macro ValueAssigned(e) --> |
250 |
* <!-- int ValueAssignedF(e) --> |
251 |
* <!-- struct ChildDesc e; --> |
252 |
* <!-- Return a true value if e the child has been assigned a value. --> |
253 |
* <!-- Otherwise, returns a false value. --> |
254 |
* Implementation function for ValueAssigned(). |
255 |
* Do not use this function directly - use ValueAssigned() instead. |
256 |
*/ |
257 |
|
258 |
#ifdef NDEBUG |
259 |
#define IntegerDefault(e) ((e).u.ivalue.value) |
260 |
#else |
261 |
#define IntegerDefault(e) IntegerDefaultF(e) |
262 |
#endif |
263 |
/**< |
264 |
* Return the default value of integer ChildDesc e. The value is |
265 |
* meaningless if e is not an integer_child, or if ValueAssigned(e) |
266 |
* is not true. |
267 |
* @param e struct ChildDesc, the ChildDesc to query. |
268 |
* @return Returns as a long the default value of e. |
269 |
* @see IntegerDefaultF() |
270 |
*/ |
271 |
extern long IntegerDefaultF(struct ChildDesc e); |
272 |
/**< |
273 |
* <!-- macro IntegerDefault(e) --> |
274 |
* <!-- long IntegerDefaultF(e) --> |
275 |
* <!-- struct ChildDesc e; --> |
276 |
* <!-- Return the integer default value assuming that e is an integer_child --> |
277 |
* <!-- This value is meaningless if ValueAssigned(e) is not true. --> |
278 |
* Implementation function for IntegerDefault(). |
279 |
* Do not use this function directly - use IntegerDefault() instead. |
280 |
*/ |
281 |
|
282 |
#ifdef NDEBUG |
283 |
#define BooleanDefault(e) ((e).u.bvalue) |
284 |
#else |
285 |
#define BooleanDefault(e) BooleanDefaultF(e) |
286 |
#endif |
287 |
/**< |
288 |
* Return the default value of boolean ChildDesc e. The value is |
289 |
* meaningless if e is not an boolean_child, or if ValueAssigned(e) |
290 |
* is not true. |
291 |
* @param e struct ChildDesc, the ChildDesc to query. |
292 |
* @return Returns as an int the default value of e. |
293 |
* @see BooleanDefaultF() |
294 |
*/ |
295 |
extern int BooleanDefaultF(struct ChildDesc e); |
296 |
/**< |
297 |
* <!-- macro BooleanDefault(e) --> |
298 |
* <!-- int BooleanDefaultF(e) --> |
299 |
* <!-- struct ChildDesc e; --> |
300 |
* <!-- Return the boolean default value assuming that e is a boolean_child. --> |
301 |
* <!-- This value is meaningless if ValueAssigned(e) is not true. --> |
302 |
* Implementation function for BooleanDefault(). |
303 |
* Do not use this function directly - use BooleanDefault() instead. |
304 |
*/ |
305 |
|
306 |
#ifdef NDEBUG |
307 |
#define SetDefault(e) ((e).u.s.slist) |
308 |
#else |
309 |
#define SetDefault(e) SetDefaultF(e) |
310 |
#endif |
311 |
/**< |
312 |
* Return the default value of set ChildDesc e. The value is |
313 |
* meaningless if e is not an set_child, or if ValueAssigned(e) |
314 |
* is not true. |
315 |
* @param e struct ChildDesc, the ChildDesc to query. |
316 |
* @return Returns as a CONST struct set_t* the default value of e. |
317 |
* @see SetDefaultF() |
318 |
*/ |
319 |
extern CONST struct set_t *SetDefaultF(struct ChildDesc e); |
320 |
/**< |
321 |
* <!-- macro SetDefault(e) --> |
322 |
* <!-- const struct set_t *SetDefaultF(e) --> |
323 |
* <!-- struct ChildDesc e; --> |
324 |
* <!-- Return the set default value assuming that e is a set_child. --> |
325 |
* <!-- This value is meaningless if ValueAssigned(e) is not true. --> |
326 |
* Implementation function for SetDefault(). |
327 |
* Do not use this function directly - use SetDefault() instead. |
328 |
*/ |
329 |
|
330 |
#ifdef NDEBUG |
331 |
#define SetIsIntegerSet(e) ((e).u.s.is_int) |
332 |
#else |
333 |
#define SetIsIntegerSet(e) SetIsIntegerSetF(e) |
334 |
#endif |
335 |
/**< |
336 |
* Return the set type of e. The value is meaningless if e is not a |
337 |
* set_child, or if ValueAssigned(e) is not true. |
338 |
* @param e struct ChildDesc, the ChildDesc to query. |
339 |
* @return Returns an int: 0 for a symbol set, 1 for an integer set. |
340 |
* @see SetIsIntegerSetF() |
341 |
*/ |
342 |
extern int SetIsIntegerSetF(struct ChildDesc e); |
343 |
/**< |
344 |
* <!-- macro SetIsIntegerSet(e) --> |
345 |
* <!-- int SetIsIntegerSetF(e) --> |
346 |
* <!-- struct ChildDesc e; --> |
347 |
* <!-- Return the set type. 0 symbol and 1 integer. --> |
348 |
* Implementation function for SetIsIntegerSet(). |
349 |
* Do not use this function directly - use SetIsIntegerSet() instead. |
350 |
*/ |
351 |
|
352 |
#ifdef NDEBUG |
353 |
#define SymbolDefault(e) ((e).u.svalue) |
354 |
#else |
355 |
#define SymbolDefault(e) SymbolDefaultF(e) |
356 |
#endif |
357 |
/**< |
358 |
* Return the default value of symbol ChildDesc e. The value is |
359 |
* meaningless if e is not an symbol_child, or if ValueAssigned(e) |
360 |
* is not true. |
361 |
* @param e struct ChildDesc, the ChildDesc to query. |
362 |
* @return Returns as a symchar* the default value of e. |
363 |
* @see SymbolDefaultF() |
364 |
*/ |
365 |
extern symchar *SymbolDefaultF(struct ChildDesc e); |
366 |
/**< |
367 |
* <!-- macro SymbolDefault(e) --> |
368 |
* <!-- symchar *SymbolDefaultF(e) --> |
369 |
* <!-- struct ChildDesc e; --> |
370 |
* <!-- Return the symbol default value assuming that e is a symbol_child. --> |
371 |
* <!-- This value is meaningless is ValueAssigned(e) is not true. --> |
372 |
* Implementation function for SymbolDefault(). |
373 |
* Do not use this function directly - use SymbolDefault() instead. |
374 |
*/ |
375 |
|
376 |
#ifdef NDEBUG |
377 |
#define RealDefaultValue(e) ((e).u.rvalue.value) |
378 |
#else |
379 |
#define RealDefaultValue(e) RealDefaultValueF(e) |
380 |
#endif |
381 |
/**< |
382 |
* Return the default value of real ChildDesc e. The value is |
383 |
* meaningless if e is not an real_child, or if ValueAssigned(e) |
384 |
* is not true. |
385 |
* @param e struct ChildDesc, the ChildDesc to query. |
386 |
* @return Returns as a double the default value of e. |
387 |
* @see RealDefaultValueF() |
388 |
*/ |
389 |
extern double RealDefaultValueF(struct ChildDesc e); |
390 |
/**< |
391 |
* <!-- macro RealDefaultValue(e) --> |
392 |
* <!-- struct ChildDesc e; --> |
393 |
* <!-- Return the real default value assuming that e is a real_child. --> |
394 |
* <!-- This value is meaningless if ValueAssigned(e) is not true. --> |
395 |
* Implementation function for RealDefaultValue(). |
396 |
* Do not use this function directly - use RealDefaultValue() instead. |
397 |
*/ |
398 |
|
399 |
#ifdef NDEBUG |
400 |
#define RealDimensions(e) ((e).u.rvalue.dims) |
401 |
#else |
402 |
#define RealDimensions(e) RealDimensionsF(e) |
403 |
#endif |
404 |
/**< |
405 |
* Return the units pointer of real ChildDesc e. The value is |
406 |
* meaningless if e is not an real_child, or if ValueAssigned(e) |
407 |
* is not true. |
408 |
* @param e struct ChildDesc, the ChildDesc to query. |
409 |
* @return Returns as a CONST dim_type* the units pointer of e. |
410 |
* @see RealDimensionsF() |
411 |
*/ |
412 |
extern CONST dim_type *RealDimensionsF(struct ChildDesc e); |
413 |
/**< |
414 |
* <!-- macro RealDimensions(e) --> |
415 |
* <!-- struct ChildDesc e; --> |
416 |
* <!-- Return the units pointer assuming that e is a real_child. --> |
417 |
* <!-- This value is meaningless if ValueAssigned(e) is not true. --> |
418 |
* Implementation function for RealDimensions(). |
419 |
* Do not use this function directly - use RealDimensions() instead. |
420 |
*/ |
421 |
|
422 |
extern struct ChildDesc MakeRealDesc(int assigned, |
423 |
double v, |
424 |
CONST dim_type *dims); |
425 |
/**< |
426 |
* <!-- struct ChildDesc MakeRealDesc(assigned,v,dims); --> |
427 |
* <!-- int assigned; --> |
428 |
* <!-- double v; --> |
429 |
* <!-- const dim_type *dims; --> |
430 |
* Make a real child with default v, and dimensions dims. Those |
431 |
* values can be garbage if assigned is FALSE. |
432 |
*/ |
433 |
|
434 |
extern struct ChildDesc MakeIntegerDesc(int assigned, long i); |
435 |
/**< |
436 |
* <!-- struct ChildDesc MakeIntegerDesc(assigned,i) --> |
437 |
* <!-- int assigned; --> |
438 |
* <!-- long i; --> |
439 |
* Make an integer child with default value i. The value i is ignored if |
440 |
* assigned is false. |
441 |
*/ |
442 |
|
443 |
extern struct ChildDesc MakeBooleanDesc(int assigned, int b); |
444 |
/**< |
445 |
* <!-- struct ChildDesc MakeBooleanDesc(assigned,b) --> |
446 |
* <!-- int assigned,b; --> |
447 |
* Make a boolean child with default value b. The value b is ignored if |
448 |
* assigned is false. |
449 |
*/ |
450 |
|
451 |
extern struct ChildDesc MakeSetDesc(int assigned, int intset, struct set_t *s); |
452 |
/**< |
453 |
* <!-- struct ChildDesc MakeSetDesc(assigned,intset,s) --> |
454 |
* <!-- int assigned; --> |
455 |
* <!-- int intset; --> |
456 |
* <!-- struct gl_list_t *s; --> |
457 |
* Make a set child with default value s. The value of s is ignored if |
458 |
* assigned is false. |
459 |
*/ |
460 |
|
461 |
extern struct ChildDesc MakeSymbolDesc(int assigned, symchar *str); |
462 |
/**< |
463 |
* <!-- struct ChildDesc MakeSymbolDesc(assigned,str) --> |
464 |
* <!-- int assigned; --> |
465 |
* <!-- char *str; --> |
466 |
* Make a symbol child description with default value str. The value of |
467 |
* str is ignored if assigned is false. |
468 |
*/ |
469 |
|
470 |
/* @} */ |
471 |
|
472 |
#endif /* ASC_CHILDINFO_H */ |
473 |
|