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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 355 - (show annotations) (download) (as text)
Mon Mar 6 03:11:28 2006 UTC (14 years, 4 months ago) by johnpye
File MIME type: text/x-chdr
File size: 45277 byte(s)
In PyGTK 'modules' list, you can now see non-parameterised types in bold.
1 /*
2 * Atom description structure data type
3 * by Tom Epperly
4 * 9/3/89
5 * Version: $Revision: 1.37 $
6 * Version control file: $RCSfile: type_desc.h,v $
7 * Date last modified: $Date: 1998/05/18 16:36:52 $
8 * Last modified by: $Author: ballan $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
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 along
25 * with the program; if not, write to the Free Software Foundation, Inc., 675
26 * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
27 */
28
29 /** @file
30 * Atom description structure data type.
31 * <pre>
32 * When #including type_desc.h, make sure these files are #included first:
33 * #include <stdio.h>
34 * #include "utilities/ascConfig.h"
35 * #include "compiler/fractions.h"
36 * #include "compiler/compiler.h"
37 * #include "compiler/dimen.h"
38 * #include "compiler/child.h"
39 * #include "compiler/list.h"
40 * #include "compiler/module.h"
41 * #include "compiler/childinfo.h"
42 * #include "compiler/slist.h"
43 * </pre>
44 */
45
46 #ifndef ASC_TYPE_DESC_H
47 #define ASC_TYPE_DESC_H
48
49 /**
50 * Bad pointer for a patently bogus type definition when needed.
51 * This token is an illegal address for any type definition,
52 * (illegal for alignment reasons) which we can use to denote
53 * the UNIVERSAL root MODEL which does not exist as a real
54 * type description in the library.
55 */
56 #define ILLEGAL_DEFINITION ((struct TypeDescription *)0xF0F0F0F7)
57
58 /* some bit patterns to make basetype checking faster, etc. */
59 #define REAL_KIND 0x1
60 #define INT_KIND 0x2
61 #define BOOL_KIND 0x4
62 #define SYM_KIND 0x8
63 #define SET_KIND 0x10
64 #define ATOM_KIND 0x20
65 #define CONSTANT_KIND 0x40
66 #define COMPOUND_KIND 0x80
67 #define EQN_KIND 0x8000
68 #define DUMB_KIND 0x10000
69 #define ERROR_KIND ~(REAL_KIND|INT_KIND|BOOL_KIND|SYM_KIND|SET_KIND| \
70 ATOM_KIND|CONSTANT_KIND|COMPOUND_KIND|0x100| \
71 0x200|0x400|0x1000|0x2000|0x4000|EQN_KIND|DUMB_KIND)
72 #define SIMPLE_KINDS \
73 ( REAL_KIND | INT_KIND | BOOL_KIND | SYM_KIND | SET_KIND | EQN_KIND )
74
75 /** (t & ERROR_KIND) ==> bogus type, there may be other bogus types as well.)*/
76 enum type_kind {
77 /* complex base types */
78 model_type = COMPOUND_KIND | 0x100,
79 array_type = COMPOUND_KIND | 0x200,
80 patch_type = COMPOUND_KIND | 0x400,
81 /* list_type? COMPOUND_KIND | 0x800, */
82 /* oddly structured base types */
83 relation_type = EQN_KIND | 0x1000,
84 logrel_type = EQN_KIND | 0x2000,
85 when_type = EQN_KIND | 0x4000,
86 /* simply structured base types */
87 real_type = ATOM_KIND | REAL_KIND,
88 integer_type = ATOM_KIND | INT_KIND,
89 boolean_type = ATOM_KIND | BOOL_KIND,
90 symbol_type = ATOM_KIND | SYM_KIND,
91 set_type = ATOM_KIND | SET_KIND,
92 /* list_type = ATOM_KIND | SET_KIND */
93 /* baa: eventually become a variable ordered set */
94
95 /* very simply structured base types */
96 real_constant_type = CONSTANT_KIND | REAL_KIND,
97 integer_constant_type = CONSTANT_KIND | INT_KIND,
98 boolean_constant_type = CONSTANT_KIND | BOOL_KIND,
99 symbol_constant_type = CONSTANT_KIND | SYM_KIND,
100 /* set atoms should be down here */
101 /* dummy type */
102 dummy_type = DUMB_KIND
103 };
104
105 struct ConstantTypeDesc {
106 unsigned long byte_length; /**< byte length of an instance */
107 union {
108 double defreal; /**< default value for real instances */
109 long definteger; /**< default value for integer instances */
110 symchar *defsymbol; /**< default value for symbol instances */
111 unsigned defboolean; /**< default value for boolean instances */
112 } u; /**< union of default values */
113 unsigned defaulted; /**< 0 -> ignore default value and units
114 1 -> don't ignore them */
115 CONST dim_type *dimp; /**< dimensions of instance */
116 /* no stinking child list */
117 };
118
119 struct AtomTypeDesc {
120 unsigned long byte_length; /**< byte length of an instance */
121 struct ChildDesc *childinfo;/**< description of children */
122 unsigned defaulted; /**< 0 -> ignore default value and units
123 1 -> don't ignore them */
124 double defval; /**< default value for real instances */
125 union {
126 double defval; /**< default value for real instances */
127 long defint; /**< default value for integer instances */
128 symchar *defsym; /**< default value for symbol instances */
129 unsigned defbool; /**< default value for boolean instances */
130 } u; /**< union of default values */
131 CONST dim_type *dimp; /**< dimensions of instance */
132 };
133
134 /**
135 * IndexType has been modified to store a key, and a string
136 * representation of the set of indices. As it stands the set
137 * of indices is of very little utility. For example, if we had
138 * foo[1,2,3,4] IS_A thing; then what would be saved is
139 * 1,2,3,4. -- which is useful
140 * Likewise
141 * foo[fooset - [thingset]] IS_A thing; we would have
142 * fooset thingset - -- which is not very useful.
143 * So we now save a string representation of the set.<br><br>
144 *
145 * The above statement about sets could only have been made
146 * by someone with no real clue about the instantiate process.
147 * Both representations are critical to have, and since they
148 * are cheap, we will have both.
149 * The string IS a string from the symbol table.
150 */
151 struct IndexType {
152 struct Set *set; /**< the original set */
153 symchar *sptr; /**< a string representation of the set */
154 unsigned int_index; /**< 0 this index is an enumerate one,
155 1 this index is an integer one */
156 };
157
158 struct ArrayDesc {
159 struct gl_list_t *indices; /**< a list of IndexTypes */
160 struct TypeDescription *desc; /**< the type of the array/common superclass*/
161 /* the following 4 need to be made bit flags.
162 * At present, this overuse of ints does not dominate the
163 * union cost at the end of the typedescription struct, so
164 * we have no incentive to do the fiddling with bits.
165 */
166 int isintset; /**< in case the type of the array is a set */
167 int isrelation; /**< TRUE in case of an array of relations */
168 int islogrel; /**< TRUE in case of array of logical relation */
169 int iswhen; /**< TRUE in case of array of WHEN */
170 };
171
172 /** ModelArgs is a structure in preparation for parameterized types */
173 struct ModelArgs {
174 struct StatementList *declarations;
175 /**< list of the statements in the parameter list */
176 struct StatementList *absorbed;
177 /**< list of IS_A statements and their matching assignments
178 * removed in refinements.
179 */
180 struct StatementList *reductions;
181 /**< list of assignments from the REFINES x(reductions)
182 * these statements are not directly used in instantiation.
183 * duplicates (references) end up in the absorbed list.
184 * this list is kept to enable printing types properly.
185 */
186 struct StatementList *wheres;
187 /**< list of statements placing additional structural requirements
188 * on the arguments passed by reference. (WBTS's)
189 * these statements used for configuration checking in instantiation.
190 */
191 /* struct gl_list_t *argdata;
192 * list of final values, etc if needed. (not yet in use)
193 */
194 unsigned int argcnt;
195 /**< number of args required in an IS_A of this type. */
196 };
197
198 /** Type definition data structure. */
199 struct TypeDescription {
200 symchar *name; /**< type name */
201 enum type_kind t; /**< base type of the type */
202 short universal; /**< TRUE universal type, FALSE non-universal */
203 unsigned short flags; /**< various boolean flags */
204 struct TypeDescription *refines; /**< the type it refines or NULL */
205 struct module_t *mod; /**< module where it is defined */
206 ChildListPtr children; /**< list of children. Never NULL for models */
207 struct gl_list_t *init; /**< initialization procedures */
208 struct StatementList *stats; /**< statements */
209 struct gl_list_t *refiners; /**< list of types that refine this. alpha */
210 unsigned long ref_count; /**< count includes instances, other types */
211 long int parseid; /**< n as in 'nth definition made' */
212 union {
213 struct ArrayDesc array; /**< description of array things */
214 struct AtomTypeDesc atom; /**< atom description stuff */
215 struct ConstantTypeDesc constant; /**< constant description stuff */
216 struct ModelArgs modarg; /**< parameter list stuff */
217 } u; /**< union of description stuff */
218 };
219
220 #define MAKEARRAYNAMES 1
221 /**<
222 * If MAKEARRAYNAMES != 0 we will make up names for arrays
223 * so clients that want everything to have a name are happy.
224 * Note that virtually NOTHING works anymore if MAKEARRAYNAMES
225 * is 0.
226 */
227
228 #ifdef NDEBUG
229 #define GetChildList(d) ((d)->children)
230 #else
231 #define GetChildList(d) GetChildListF(d)
232 #endif
233 /**<
234 * Return the childlist field of d.
235 * @param d CONST struct TypeDescription*, type to query.
236 * @return The childlist field as a ChildListPtr.
237 * @see GetChildListF()
238 */
239 extern ChildListPtr GetChildListF(CONST struct TypeDescription *d);
240 /**<
241 * Returns the childlist field of d.
242 * Implementation function for GetChildList() (debug mode).
243 * Do not call this function directly - use GetChildList() instead.
244 */
245
246 #ifdef NDEBUG
247 #define GetBaseType(d) ((d)->t)
248 #else
249 #define GetBaseType(d) GetBaseTypeF(d)
250 #endif
251 /**<
252 * Return the base type of a type description.
253 * @param d CONST struct TypeDescription*, type to query.
254 * @return The base type as an enum type_kind.
255 * @see GetBaseTypeF()
256 */
257 extern enum type_kind GetBaseTypeF(CONST struct TypeDescription *d);
258 /**<
259 * Implementation function for GetBaseType() (debug mode).
260 * Do not call this function directly - use GetBaseType() instead.
261 */
262
263 #define BaseTypeIsReal(d) ((d)->t & REAL_KIND)
264 /**< Returns TRUE (int) if basetype of TypeDescription *d is real valued. */
265 #define BaseTypeIsInteger(d) ((d)->t & INT_KIND)
266 /**< Returns TRUE (int) if basetype of TypeDescription *d is integer valued. */
267 #define BaseTypeIsBoolean(d) ((d)->t & BOOL_KIND)
268 /**< Returns TRUE (int) if basetype of TypeDescription *d is truth valued. */
269 #define BaseTypeIsSymbol(d) ((d)->t & SYM_KIND)
270 /**< Returns TRUE (int) if basetype of TypeDescription *d is char * valued. */
271 #define BaseTypeIsSet(d) ((d)->t & SET_KIND)
272 /**< Returns TRUE (int) if basetype of TypeDescription *d is a set of anything. */
273 #define BaseTypeIsAtomic(d) ((d)->t & ATOM_KIND)
274 /**< Returns TRUE (int) if basetype of TypeDescription *d is among the atoms. */
275 #define BaseTypeIsConstant(d) ((d)->t & CONSTANT_KIND)
276 /**< Returns TRUE (int) if basetype of TypeDescription *d is among the constants. */
277 #define BaseTypeIsCompound(d) ((d)->t & COMPOUND_KIND)
278 /**<
279 * Returns TRUE (int) if basetype of TypeDescription *d is among the compound types.
280 * Note that several types are not simple or compound --
281 * we can't really make up our minds whether relations/whens/etc are
282 * simple or compound. In general simple means having a scalar(set)
283 * value. Relations have several values (satisfaction, residual,etc)
284 * and so are not considered simple. Obviously arrays and models are
285 * compound.
286 */
287 #define BaseTypeIsEquation(d) ((d)->t & EQN_KIND)
288 /**< Returns TRUE (int) if basetype of TypeDescription *d is among the equation types. */
289 #define BaseTypeIsSimple(d) ((d)->t & SIMPLE_KINDS)
290 /**<
291 * Returns TRUE (int) if basetype of TypeDescription *d is among the simple types.
292 * Note that several types are not simple or compound --
293 * we can't really make up our minds whether relations/whens/etc are
294 * simple or compound. In general simple means having a scalar(set)
295 * value. Relations have several values (satisfaction, residual,etc)
296 * and so are not considered simple. Obviously arrays and models are
297 * compound.
298 */
299
300 #ifdef NDEBUG
301 #define GetStatementList(d) ((d)->stats)
302 #else
303 #define GetStatementList(d) GetStatementListF(d)
304 #endif
305 /**<
306 * Returns the statement list for models and atoms. In the case of
307 * models this will never return NULL. In some cases of atoms, this may
308 * return NULL which indicates that the instance doesn't have any
309 * pending statements.
310 * A nonNULL list may, however, be an empty list.
311 * @param d CONST struct TypeDescription*, the type description to query.
312 * @return The statement list as a CONST struct StatementList*.
313 * @see GetStatementListF()
314 */
315 extern CONST struct StatementList
316 *GetStatementListF(CONST struct TypeDescription *d);
317 /**<
318 * Implementation function for GetStatementList() (debug mode).
319 * Do not call this function directly - use GetStatementList() instead.
320 */
321
322 #ifdef NDEBUG
323 #define GetInitializationList(d) ((d)->init)
324 #else
325 #define GetInitializationList(d) GetInitializationListF(d)
326 #endif
327 /**<
328 * Returns the list of initialization procedures.
329 * @param d CONST struct TypeDescription*, the type description to query.
330 * @return The list as a CONST struct gl_list_t*.
331 * @see GetInitializationListF()
332 */
333 extern struct gl_list_t
334 *GetInitializationListF(CONST struct TypeDescription *d);
335 /**<
336 * Implementation function for GetInitializationList() (debug mode).
337 * Do not call this function directly - use GetInitializationList() instead.
338 */
339
340 /* the following two functions make it much easier to debug methods
341 * interactively without reconstructing complex objects.
342 * Since methods are fully interpretted at run time, this is not an
343 * unreasonable thing to do.
344 * It might be a good idea to procedure lock methods in types
345 * found in files *.a4l.
346 */
347
348 extern int AddMethods(struct TypeDescription *d,
349 struct gl_list_t *pl,
350 int err);
351 /**<
352 * Inserts new methods into a type and all its refinements.
353 * pl should contain (struct InitProcedure *) to the methods to
354 * add to d. The methods named in pl must not conflict with any
355 * method in d or its refinements. If err != 0, rejects pl.<br><br>
356 *
357 * If return is 1, caller is responsible for pl, OTHERWISE we manage it
358 * from here on. If caller supplied d == ILLEGAL_DEFINITION, the caller
359 * can unconditionally forget pl.
360 *
361 * @param d The type to which the methods in pl should be added.
362 * @param pl A gl_list_t of (struct InitProcedure *) to add to d.
363 * @param err If non-zero, pl is rejected and no methods are added.
364 * @return Returns 0 if successful, 1 if not.
365 */
366
367 extern int ReplaceMethods(struct TypeDescription *d,
368 struct gl_list_t *pl,
369 int err);
370 /**<
371 * Replaces listed methods in a type and all its refinements that do not
372 * themselves redefine the methods. The methods in pl must exist in d or
373 * else an error condition is returned. Methods not named in pl but found
374 * in d or its refinements are left undisturbed. If err != 0, rejects pl.<br><br>
375 *
376 * If return is 1, caller is responsible for pl, OTHERWISE we manage it
377 * from here on.
378 *
379 * @param d The type to which the methods in pl should be replaced.
380 * @param pl A gl_list_t of (struct InitProcedure *) to replace in.
381 * @param err If non-zero, pl is rejected and no methods are replaced.
382 * @return Returns 0 if successful, 1 if not.
383 */
384
385 #ifdef NDEBUG
386 #define CopyTypeDesc(d) ((d)->ref_count++)
387 #else
388 #define CopyTypeDesc(d) CopyTypeDescF(d)
389 #endif
390 /**<
391 * Increment the reference count.
392 * @param d CONST struct TypeDescription*, the type description to query.
393 * @return No return value.
394 * @see CopyTypeDescF()
395 */
396 extern void CopyTypeDescF(struct TypeDescription *d);
397 /**<
398 * Implementation function for CopyTypeDesc() (debug mode).
399 * Do not call this function directly - use CopyTypeDesc() instead.
400 */
401
402 extern void DeleteTypeDesc(struct TypeDescription *d);
403 /**<
404 * Decrement the reference count. Eventually, this should delete it
405 * when ref_count == 0. Note to myself: Remember that array type
406 * descriptions need to be removed from a list too.
407 */
408
409 extern void DeleteNewTypeDesc(struct TypeDescription *d);
410 /**<
411 * Checks that the type has a refcount of 1 before passing it on to
412 * DeleteTypeDesc. This is (or should be) the case when deleting
413 * types that are newly parsed but not yet in the type library.
414 * Essentially, this is a one-client (AddType) function.
415 */
416
417 #ifdef NDEBUG
418 #define GetByteSize(d) ((unsigned)(d)->u.atom.byte_length)
419 #else
420 #define GetByteSize(d) GetByteSizeF(d)
421 #endif
422 /**<
423 * Return the byte size of an atom type description.
424 * @param d CONST struct TypeDescription*, the type description to query.
425 * @return The size as an unsigned.
426 * @see GetByteSizeF()
427 */
428 extern unsigned GetByteSizeF(CONST struct TypeDescription *d);
429 /**<
430 * Implementation function for GetByteSize() (debug mode).
431 * Do not call this function directly - use GetByteSize() instead.
432 */
433
434 #ifdef NDEBUG
435 #define GetChildDesc(d) ((d)->u.atom.childinfo)
436 #else
437 #define GetChildDesc(d) GetChildDescF(d)
438 #endif
439 /**<
440 * Return the child description field of an atom type description.
441 * @param d CONST struct TypeDescription*, the type description to query.
442 * @return The child description field as a CONST struct ChildDesc*.
443 * @see GetChildDescF()
444 */
445 extern CONST struct ChildDesc *GetChildDescF(CONST struct TypeDescription *d);
446 /**<
447 * Implementation function for GetChildDesc() (debug mode).
448 * Do not call this function directly - use GetChildDesc() instead.
449 */
450
451 #ifdef NDEBUG
452 #define GetUniversalFlag(d) ((d)->universal)
453 #else
454 #define GetUniversalFlag(d) GetUniversalFlagF(d)
455 #endif
456 /**<
457 * Return the universal flag of a type definition
458 * Gets a short all to itself for no apparent reason.
459 * @param d CONST struct TypeDescription*, the type description to query.
460 * @return The flag as an int.
461 * @see GetUniversalFlagF()
462 */
463 extern int GetUniversalFlagF(CONST struct TypeDescription *d);
464 /**<
465 * Implementation function for GetUniversalFlag() (debug mode).
466 * Do not call this function directly - use GetUniversalFlag() instead.
467 */
468
469 #ifdef NDEBUG
470 #define GetTypeFlags(d) ((d)->flags)
471 #else
472 #define GetTypeFlags(d) GetTypeFlagsF(d)
473 #endif
474 /**<
475 * Return the type flags of a type definition
476 * There are a number of flags we might want in various bit positions.
477 * @param d CONST struct TypeDescription*, the type description to query.
478 * @return The flags as an unsigned short.
479 * @see GetTypeFlagsF()
480 */
481 extern unsigned short GetTypeFlagsF(CONST struct TypeDescription *d);
482 /**<
483 * Implementation function for GetTypeFlags() (debug mode).
484 * Do not call this function directly - use GetTypeFlags() instead.
485 */
486
487 #define TYPECONTAINSDEFAULTS 0x1
488 #define TYPECONTAINSPARINSTS 0x2
489 /**<
490 * We can add more, up to the minimum number of bits we expect a short
491 * to have under any C compiler.
492 * Universal really should be under this protocol.
493 */
494 #define TYPESHOW 0x100
495 /**< For browsing purposes */
496
497 #ifdef NDEBUG
498 #define TypeHasDefaultStatements(d) (GetTypeFlags(d)&TYPECONTAINSDEFAULTS)
499 #else
500 #define TypeHasDefaultStatements(d) TypeHasDefaultStatementsF(d)
501 #endif
502 /**<
503 * Tells if the statement list of a type has any default ( := ) statements.
504 * Returns 0 if not.
505 * This does not refer to the DEFAULT keyword in atoms.
506 * @param d CONST struct TypeDescription*, the type description to query.
507 * @return An unsigned.
508 * @see TypeHasDefaultStatementsF()
509 */
510 extern unsigned TypeHasDefaultStatementsF(CONST struct TypeDescription *d);
511 /**<
512 * Implementation function for TypeHasDefaultStatements() (debug mode).
513 * Do not call this function directly - use TypeHasDefaultStatements() instead.
514 */
515
516 #ifdef NDEBUG
517 #define TypeHasParameterizedInsts(d) (GetTypeFlags(d)&TYPECONTAINSPARINSTS)
518 #else
519 #define TypeHasParameterizedInsts(d) TypeHasParameterizedInstsF(d)
520 #endif
521 /**<
522 * Tells if the statement lists of a type involve parameters in any way.
523 * A type that has parameters, or has children that have parameters or
524 * recursively so returns nonzero result (TYPECONTAINSPARINSTS).
525 * Returns 0 if not.
526 * This does not refer to the DEFAULT keyword in atoms.
527 * @param d CONST struct TypeDescription*, the type description to query.
528 * @return An unsigned.
529 * @see TypeHasParameterizedInstsF()
530 */
531 extern unsigned TypeHasParameterizedInstsF(CONST struct TypeDescription *d);
532 /**<
533 * Implementation function for TypeHasParameterizedInsts() (debug mode).
534 * Do not call this function directly - use TypeHasParameterizedInsts() instead.
535 */
536
537 #define AtomDefaulted(d) ((d)->u.atom.defaulted)
538 /**<
539 * Returns TRUE if the atom has a default value; otherwise returns FALSE.
540 */
541
542 #define ConstantDefaulted(d) ((d)->u.constant.defaulted)
543 /**<
544 * Returns TRUE if the Constant has a default value; otherwise returns FALSE.
545 */
546
547 #define GetIntDefault(d) ((d)->u.atom.u.defint)
548 /**< Returns the long default value of TypeDescription *d. */
549 #define GetSymDefault(d) ((d)->u.atom.u.defsym)
550 /**< Returns the symchar* default value of TypeDescription *d. */
551 #ifdef NDEBUG
552 #define GetRealDefault(d) ((d)->u.atom.u.defval)
553 #else
554 #define GetRealDefault(d) GetRealDefaultF((d),__FILE__,__LINE__)
555 #endif
556 /**< Returns the double default value of TypeDescription *d. */
557 #ifdef NDEBUG
558 #define GetBoolDefault(d) ((d)->u.atom.u.defbool)
559 #else
560 #define GetBoolDefault(d) GetBoolDefaultF((d),__FILE__,__LINE__)
561 #endif
562 /**< Returns the unsigned default value of TypeDescription *d. */
563 extern double GetRealDefaultF(CONST struct TypeDescription *d,
564 CONST char *f, CONST int l);
565 /**<
566 * Implementation function for GetRealDefault() (debug mode).
567 * Do not call this function directly - use GetRealDefault() instead.
568 */
569
570 extern unsigned GetBoolDefaultF(CONST struct TypeDescription *d,
571 CONST char *f, CONST int l);
572 /**<
573 * Implementation function for GetBoolDefault() (debug mode).
574 * Do not call this function directly - use GetBoolDefault() instead.
575 */
576
577 #define GetConstantDefReal(d) ((d)->u.constant.u.defreal)
578 /**< Returns the double default value of constant TypeDescription *d. */
579 #define GetConstantDefInteger(d) ((d)->u.constant.u.definteger)
580 /**< Returns the long default value of constant TypeDescription *d. */
581 #define GetConstantDefBoolean(d) ((d)->u.constant.u.defboolean)
582 /**< Returns the short default value of constant TypeDescription *d. */
583 #define GetConstantDefSymbol(d) ((d)->u.constant.u.defsymbol)
584 /**< Returns the symchar* default value of constant TypeDescription *d. */
585
586 #ifdef NDEBUG
587 #define GetRealDimens(d) ((d)->u.atom.dimp)
588 #else
589 #define GetRealDimens(d) GetRealDimensF((d),__FILE__,__LINE__)
590 #endif
591 /**<
592 * Returns the dimensions of the atom.
593 * If atoms is not numeric, return value is uncertain.
594 * Will not work on constants.
595 * @param d CONST struct TypeDescription*, the type description to query.
596 * @return The dimensions as a CONST dim_type*.
597 * @see GetRealDimensF()
598 */
599 extern CONST dim_type *GetRealDimensF(CONST struct TypeDescription *d,
600 CONST char *f, CONST int l);
601 /**<
602 * Implementation function for GetRealDimens() (debug mode).
603 * Do not call this function directly - use GetRealDimens() instead.
604 */
605
606 #ifdef NDEBUG
607 #define GetConstantDimens(d) ((d)->u.constant.dimp)
608 #else
609 #define GetConstantDimens(d) GetConstantDimensF((d),__FILE__,__LINE__)
610 #endif
611 /**<
612 * Returns the dimensions of the constant.
613 * All constants have dimensionality. nonreal constants have the
614 * dim for DIMENSIONLESS. nonconstants and unassigned real constants
615 * will return WildDimension().
616 * @param d CONST struct TypeDescription*, the type description to query.
617 * @return The dimensions as a CONST dim_type*.
618 * @see GetConstantDimensF()
619 */
620 extern CONST dim_type *GetConstantDimensF(CONST struct TypeDescription *d,
621 CONST char *f, CONST int l);
622 /**<
623 * Implementation function for GetConstantDimens() (debug mode).
624 * Do not call this function directly - use GetConstantDimens() instead.
625 */
626
627 #ifdef NDEBUG
628 #define GetName(d) ((d)->name)
629 #else
630 #define GetName(d) GetNameF(d)
631 #endif
632 /**<
633 * Returns the name of the type that this structure defines.
634 * @param d CONST struct TypeDescription*, the type description to query.
635 * @return The name as a symchar*.
636 * @see GetNameF()
637 */
638 extern symchar *GetNameF(CONST struct TypeDescription *d);
639 /**<
640 * Implementation function for GetName() (debug mode).
641 * Do not call this function directly - use GetName() instead.
642 */
643
644 #define GetParseId(d) ((d)->parseid)
645 /**<
646 * Returns the parseid of type d.
647 *
648 * @param d The type to query (TypeDescription *).
649 * @return The parseid of d as a long int.
650 */
651
652 #define GetRefinement(d) ((d)->refines)
653 /**<
654 * Returns the refinement of type d, or NULL if none.
655 *
656 * @param d The type to query (TypeDescription *).
657 * @return The refinement of d as a TypeDescription *.
658 */
659
660 #define GetRefiners(d) ((d)->refiners)
661 /**<
662 * Returns a list of refiners of type d, or NULL if none.
663 *
664 * @param d The type to query (TypeDescription *).
665 * @return The refiners of d as a gl_list of TypeDescription *.
666 */
667
668 extern struct gl_list_t *GetAncestorNames(CONST struct TypeDescription *d);
669 /**<
670 * Return the names of ancestors of type d given.
671 * If none, list may be empty. The list is of symchar *.
672 * The caller should destroy the list but not its contents.
673 *
674 * @param d The type to query.
675 * @return Pointer to a gl_list_t containing the names of the ancestors of d.
676 */
677
678 #define GetModelParameterList(d) ((d)->u.modarg.declarations)
679 /**<
680 * Return the statements (forward declarations that constitute the
681 * parameter list for d. The statement list returned will contain
682 * willbes (possibly with value), and isas.
683 * Any attempt to use the type d in a RHS must fill in all the
684 * statements on this list with appropriate instances.
685 *
686 * @param d The type to query (TypeDescription *).
687 * @return The parameter list of d as a struct StatementList *.
688 */
689
690 #define GetModelParameterCount(d) ((d)->u.modarg.argcnt)
691 /**<
692 * Returns the number of arguments required when IS_A'ing a MODEL type.
693 * Any attempt to use the type d in a RHS must fill in this many slots.
694 *
695 * @param d The type to query (TypeDescription *).
696 * @return The count as an unsigned int.
697 */
698
699 #define GetModelAbsorbedParameters(d) ((d)->u.modarg.absorbed)
700 /**<
701 * Return the list of ISAs and CASGNs that absorbed them.
702 * May return NULL.
703 *
704 * @param d The type to query (TypeDescription *).
705 * @return The list as a struct StatementList *.
706 */
707
708 #define GetModelParameterReductions(d) ((d)->u.modarg.reductions)
709 /**<
710 * Return the list of statements that absorb parameter isas in the
711 * statement of this MODEL. Used for display purposes primarily.
712 *
713 * @param d The type to query (TypeDescription *).
714 * @return The list as a struct StatementList *.
715 */
716
717 #define GetModelParameterWheres(d) ((d)->u.modarg.wheres)
718 /**<
719 * Return the list of statements that restrict the structure of
720 * WILL_BE passed arguments in this MODEL.
721 * Used for instantiation-time checks.
722 *
723 * @param d The type to query (TypeDescription *).
724 * @return The list as a struct StatementList *.
725 */
726
727 #define GetModelParameterValues(d) ((d)->u.modarg.argdata)
728 /**<
729 * NOT IMPLEMENTED.
730 * Returns the list of values that match the ParameterLists.
731 * Possibly this is a redundancy.
732 *
733 * @param d The type to query (TypeDescription *).
734 * @return The list as a gl_list_t *.
735 */
736
737 #define GetArrayBaseType(d) ((d)->u.array.desc)
738 /**<
739 * Returns the base type of the array type description.
740 *
741 * @param d The type to query (TypeDescription *).
742 * @return The base type as a TypeDescription *.
743 */
744
745 #define GetArrayBaseIsRelation(d) ((d)->u.array.isrelation)
746 /**<
747 * Returns TRUE if the array is an array of relations.
748 *
749 * @param d The type to query (TypeDescription *).
750 * @return An int indicating whether d is an array of relations.
751 */
752
753 #define GetArrayBaseIsLogRel(d) ((d)->u.array.islogrel)
754 /**<
755 * Returns TRUE if the array is an array of logical relations.
756 *
757 * @param d The type to query (TypeDescription *).
758 * @return An int indicating whether d is an array of logical relations.
759 */
760
761 #define GetArrayBaseIsWhen(d) ((d)->u.array.iswhen)
762 /**<
763 * Returns TRUE if the array is an array of WHEN's.
764 *
765 * @param d The type to query (TypeDescription *).
766 * @return An int indicating whether d is an array of WHENs.
767 */
768
769 #define GetArrayBaseIsInt(d) ((d)->u.array.isintset)
770 /**<
771 * Returns TRUE if the array is a set.
772 * This is only meaningful when the base type is a refinement of
773 * set, but it is always available. Its value is inconsequential
774 * when the base type is not a set.
775 *
776 * @param d The type to query (TypeDescription *).
777 * @return An int indicating whether d is a set.
778 */
779
780 #define GetArrayIndexList(d) ((d)->u.array.indices)
781 /**<
782 * Returns a list of the indices of an array.
783 *
784 * @param d The type to query (TypeDescription *).
785 * @return A l_list_t * containing the indices of d.
786 */
787
788 #define GetModule(d) ((d)->mod)
789 /**<
790 * Returns the module in which type d is defined.
791 *
792 * @param d The type to query (TypeDescription *).
793 * @return The module associated with d as a module_t *.
794 */
795
796 #define GetPatchOriginal(d) ((d)->refines)
797 /**<
798 * Returns the original type of the TypeDescription being patched.
799 * NULL must be treated as an error, as a patch is meaningless without
800 * the original type. Internally it uses the same slot as refines.
801 *
802 * @param d The type to query (TypeDescription *).
803 * @return The original type of d as a TypeDescription *.
804 */
805
806 extern struct IndexType *CreateIndexType(struct Set *set, int int_index);
807 /**<
808 * Creates an IndexType. The set becomes the property of the index.
809 *
810 * @param set The set to use for the new IndexType.
811 * @param int_index Flag for whether set is enumerated (0) or int (non-zero).
812 * @return The new IndexType.
813 */
814
815 extern struct IndexType *CreateDummyIndexType(int int_index);
816 /**<
817 * Returns the dummy IndexType for int (int_index != 0) or for enum
818 * (int_index == 0). There is exactly one of each and you should not
819 * do anything with it except destroy it.
820 *
821 * @param int_index Flag for whether to return dummy for enum (0)
822 * or int (non-zero).
823 * @return The dummy IndexType of the specified kind.
824 */
825
826 extern struct IndexType *CreateIndexTypeFromStr(char *str, int int_index);
827 /**<
828 * Creates an IndexType from a string. We do NOT keep the
829 * string given; we keep the symbol table's version of the string.
830 * This operator is exceedingly redundant and should not be used.
831 *
832 * @param str The string to use to create the new IndexType.
833 * @param int_index Flag for whether the set is enumerated (0) or int (non-zero).
834 * @return The new IndexType.
835 */
836
837 extern void DestroyIndexType(struct IndexType *ind);
838 /**<
839 * Deallocates this structure and its internals. The string is
840 * assumed NOT to belong to the main symbol table, and thus freed.
841 *
842 * @param ind The IndexType to destroy.
843 */
844
845 #define GetIndexType(p) ((p)->int_index)
846 /**<
847 * Returns the kind flag for IndexType *p.
848 *
849 * @param p The type to query (IndexType *).
850 * @return The kind flag for p as an unsigned (0 => enum, 1 => int).
851 */
852
853 #define GetIndexSet(p) ((p)->set)
854 /**<
855 * Returns the set associated with IndexType *p.
856 * Note this may return NULL in odd circumstances.
857 *
858 * @param p The type to query (IndexType *).
859 * @return The set associated with p as a Set *.
860 */
861
862 #define GetIndexSetStr(p) ((p)->sptr)
863 /**<
864 * Returns the string associated with IndexType *p.
865 * Note this may return NULL in odd circumstances.
866 *
867 * @param p The type to query (IndexType *).
868 * @return The set string associated with p as a symchar *.
869 */
870
871 extern struct TypeDescription
872 *CreateModelTypeDesc(symchar *name,
873 struct TypeDescription *rdesc,
874 struct module_t *mod,
875 ChildListPtr cl,
876 struct gl_list_t *pl,
877 struct StatementList *sl,
878 int univ,
879 struct StatementList *psl,
880 struct StatementList *rsl,
881 struct StatementList *tsl,
882 struct StatementList *vsl);
883 /**<
884 * Creates a Model TypeDescription structure with the parameters given.
885 * sl, psl, rsl, wsl should NEVER be NULL, though they may be empty lists.
886 * tsl may be NULL.
887 *
888 * @param name Name of the type.
889 * @param rdesc Type that it refines or NULL.
890 * @param mod Module it is defined in.
891 * @param cl List of the type's child names.
892 * @param pl List of initialization procedures.
893 * @param sl List of declarative statements.
894 * @param univ TRUE universal FALSE non-universal.
895 * @param psl List of parameter statements.
896 * @param rsl List of parameter reducing statements.
897 * @param tsl List of reduced statements.
898 * @param vsl List of parameter constraint statements.
899 * @return A pointer to the new TypeDescription structure.
900 */
901
902 extern struct TypeDescription *CreateDummyTypeDesc(symchar *name);
903 /**<
904 * Creates the universal dummy type for unselected instances.
905 *
906 * @param name The name for the dummy type.
907 * @return A pointer to the new dummy TypeDescription structure.
908 */
909
910 extern struct TypeDescription
911 *CreateConstantTypeDesc(symchar *name,
912 enum type_kind t,
913 struct TypeDescription *rdesc,
914 struct module_t *mod,
915 unsigned long bytesize,
916 int defaulted,
917 double rval,
918 CONST dim_type *dim,
919 long ival,
920 symchar *sval,
921 int univ);
922 /**<
923 * Create a Constant TypeDescription structure with the parameters given.
924 *
925 * @param name Name of type.
926 * @param t Base type of Const(real_constant_type,etc).
927 * @param rdesc Type description what it refines.
928 * @param mod Module where the type is defined.
929 * @param bytesize Size of an instance in bytes.
930 * @param defaulted TRUE indicates default value was assigned.
931 * @param rval Default value for real atoms.
932 * @param dim Dimensions of default value.
933 * @param ival Default value for int/bool constants.
934 * @param sval Default value for symbol constants.
935 * @param univ TRUE universal FALSE non-universal.
936 * @return A pointer to the new TypeDescription structure.
937 */
938
939 extern struct TypeDescription
940 *CreateAtomTypeDesc(symchar *name,
941 enum type_kind t,
942 struct TypeDescription *rdesc,
943 struct module_t *mod,
944 ChildListPtr childl,
945 struct gl_list_t *procl,
946 struct StatementList *statl,
947 unsigned long bytesize,
948 struct ChildDesc *childd,
949 int defaulted,
950 double dval,
951 CONST dim_type *ddim,
952 int univ,
953 long ival,
954 symchar *sval);
955 /**<
956 * Creates an Atom TypeDescription structure with the parameters given.
957 *
958 * @param name Name of type.
959 * @param t Base type of atom (real_type, boolean_type, etc.)
960 * @param rdesc Type description what it refines.
961 * @param mod Module where the type is defined.
962 * @param childl List of children names.
963 * @param procl List of initialization procedures.
964 * @param statl List of declarative statements.
965 * @param bytesize Size of an instance in bytes.
966 * @param childd Description of the atom's children.
967 * @param defaulted Valid only for real atoms. TRUE indicates default value assigned.
968 * @param dval Default value for real atoms.
969 * @param ddim Dimensions of default value.
970 * @param univ TRUE universal FALSE non-universal.
971 * @param ival Defalut value for integer/boolean atoms.
972 * @param sval Default value for symbol atoms.
973 * @return A pointer to the new TypeDescription structure.
974 */
975
976 extern struct TypeDescription
977 *CreateRelationTypeDesc(struct module_t *mod,
978 ChildListPtr clist,
979 struct gl_list_t *plist,
980 struct StatementList *statl,
981 unsigned long bytesize,
982 struct ChildDesc *childd);
983 /**<
984 * Creates a Relation TypeDescription structure with the parameters given.
985 *
986 * @param mod The module where it is definde.
987 * @param clist The list of children names.
988 * @param plist The list of initialization procedures.
989 * @param statl The list of declarative statements.
990 * @param bytesize The byte length.
991 * @param childd The description of the children.
992 * @return A pointer to the new TypeDescription structure.
993 */
994
995 extern struct TypeDescription
996 *CreateLogRelTypeDesc(struct module_t *mod,
997 ChildListPtr clist,
998 struct gl_list_t *plist,
999 struct StatementList *statl,
1000 unsigned long bytesize,
1001 struct ChildDesc *childd);
1002 /**<
1003 * Creates a Logical Relation TypeDescription structure with the parameters given.
1004 *
1005 * @param mod The module where it is defined.
1006 * @param clist The list of children names.
1007 * @param plist The list of initialization procedures.
1008 * @param statl The list of declarative statements.
1009 * @param bytesize The byte length.
1010 * @param childd The description of the children.
1011 * @return A pointer to the new TypeDescription structure.
1012 */
1013
1014 extern struct TypeDescription
1015 *CreateWhenTypeDesc(struct module_t *mod,
1016 struct gl_list_t *pl,
1017 struct StatementList *sl);
1018 /**<
1019 * Creates a When TypeDescription structure with the parameters given.
1020 *
1021 * @param mod The module where it is defined.
1022 * @param pl The list of initialization procedures.
1023 * @param sl The list of declarative statements.
1024 * @return A pointer to the new TypeDescription structure.
1025 */
1026
1027 extern struct TypeDescription
1028 *CreateArrayTypeDesc(struct module_t *mod,
1029 struct TypeDescription *desc,
1030 int isintset,
1031 int isrel,
1032 int islogrel,
1033 int iswhen,
1034 struct gl_list_t *indices);
1035 /**<
1036 * Creates an Array TypeDescription structure with the parameters given.
1037 *
1038 * @param mod The module of the statement where the array is instanced.
1039 * @param desc The type description of the base type.
1040 * @param isintset Used only when "desc" is a refinement of set.
1041 * @param isrel TRUE only when it is an array of relations.
1042 * @param islogrel TRUE only when it is an array of logical relations.
1043 * @param iswhen TRUE only when it is an array of WHEN's.
1044 * @param indices A list of IndexType's this describes each array index.
1045 * @return A pointer to the new TypeDescription structure.
1046 */
1047
1048 /* Patches */
1049
1050 extern struct TypeDescription
1051 *CreatePatchTypeDesc(symchar *name,
1052 struct TypeDescription *rdesc,
1053 struct module_t *mod,
1054 struct gl_list_t *pl,
1055 struct StatementList *sl);
1056 /**<
1057 * Creates a Patch TypeDescription structure with the parameters given.
1058 *
1059 * Patches are constructs which are not strictly part of the main
1060 * language. They have been developed to enable automatic generation
1061 * of code from an ASCEND instance whilst maintaing proper scope,
1062 * and naming etc..., without having to generate entire copies of the
1063 * type libraries, which may differ in just a few key ways.
1064 * They do just what they say: given an original type description
1065 * (mandatory), patch it with the new statements and intializations.
1066 * The patch does *not* change the original type; it will be applied
1067 * at the time of instantiation. Otherwise patches look just like
1068 * other types.<br><br>
1069 *
1070 * Patch files need some strong sanity checking to be implemented.
1071 *
1072 * @param name The name of the patch.
1073 * @param rdesc The type description of the type being patched.
1074 * @param mod The module that the patch was defined in.
1075 * @param pl List of procedural statements.
1076 * @param sl List of declarative statements.
1077 * @return A pointer to the new TypeDescription structure.
1078 */
1079
1080 extern struct TypeDescription *MoreRefined(CONST struct TypeDescription *desc1,
1081 CONST struct TypeDescription *desc2);
1082 /**<
1083 * Returns the more refined of desc1 or desc2, or
1084 * NULL if they are unconformable.
1085 */
1086
1087 extern CONST struct TypeDescription
1088 *GreatestCommonAncestor(CONST struct TypeDescription *desc1,
1089 CONST struct TypeDescription *desc2);
1090 /**<
1091 * Returns the most refined common ancestor type of desc1,desc2.
1092 * If either of desc1 or desc2 directly REFINES the other, then
1093 * the return value will be the less refined of the two types.
1094 * Returns NULL if unconformable.<br><br>
1095 *
1096 * Due to malloc/free calls, this is not the cheapest call to make.
1097 * If you need it for a time critical test, then you need to redo
1098 * the implementation of internal functions Create/DestroyAncestor
1099 * to reuse memory.
1100 */
1101
1102 extern int TypesAreEquivalent(CONST struct TypeDescription *desc1,
1103 CONST struct TypeDescription *desc2);
1104 /**<
1105 * Returns 1 if types appear to be equivalent semantically.
1106 * This means comparing statment lists, methods, and so forth.
1107 * Uses, among others, CompareStatementLists CompareStatement,
1108 * and CompareProcedureLists, which is broken in a FALSE negative way.
1109 * Array and patch types are never equivalent.
1110 */
1111
1112 extern void DifferentVersionCheck(CONST struct TypeDescription *desc1,
1113 CONST struct TypeDescription *desc2);
1114 /**<
1115 * Checks that desc1 and desc2 are unconformable.
1116 * It is assumed that desc1 and desc2 are unconformable. This routine
1117 * tries to check if they are unconformable because of different versions
1118 * of the types in their type hierarchy. This can happen if one of these
1119 * type descriptions is based on an edited version of the type.<br><br>
1120 *
1121 * It reports its findings to standard error.
1122 */
1123
1124 extern struct TypeDescription *GetStatTypeDesc(CONST struct Statement *s);
1125 /**<
1126 * Returns the type field of an IS_A, WILL_BE, or IS_REFINED_TO statement
1127 * converted into a TypeDescription. Note that in some cases the result
1128 * may be NULL -- and the user should check. sets and arrays do not
1129 * return a proper type this way -- if you consider proper to be an
1130 * array type description or a set description of the relevant base type.
1131 * This should also not be used on statements defining children
1132 * of atoms because children of atoms do not have TypeDescriptions.
1133 * It must be passed one of these types of statement.
1134 * Other statements will return NULL or crash.
1135 * Given all the caveats, this is a darn handy operator.
1136 *
1137 * @param s The statement to evaluate.
1138 * @return The type field of the statement, which may be NULL.
1139 */
1140
1141 extern void WriteArrayTypeList(FILE *fp);
1142 /**<
1143 * Writes the internal (implicit) array types to file fp.
1144 * This is a debugging function. The information written isn't likely
1145 * to be very meaningful. It relies on internal variables, so we
1146 * can't put it in type_descio.c.
1147 */
1148
1149 #ifdef NDEBUG
1150 #define TypeShow(d) (GetTypeFlags(d)&TYPESHOW)
1151 #else
1152 #define TypeShow(d) TypeShowF(d)
1153 #endif
1154 /**<
1155 * Tells if the type description should be shown or not.
1156 * Returns 1 is the type is going to be shown. Returns 0 if not.
1157 * @param d The type description to query (CONST struct TypeDescription*).
1158 * @return The result as an unsigned.
1159 * @see TypeShowF()
1160 */
1161 extern unsigned TypeShowF(CONST struct TypeDescription *d);
1162 /**<
1163 * Implementation function for TypeShow() (debug mode).
1164 * Do not call this function directly - use TypeShow() instead.
1165 */
1166
1167 extern void SetTypeShowBit(struct TypeDescription *d, int value);
1168 /**<
1169 * Sets the bit TYPESHOW. This bit is for browsing purposes.
1170 * It will tell is the user wants to view the instances of a specific type.
1171 * The value of the bit will be selected in the Library window.
1172 *
1173 * @param d The type to modify.
1174 * @param value Flag for whether to set (non-zero) or clear (0) the show bit.
1175 */
1176
1177 #endif /* ASC_TYPE_DESC_H */
1178

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