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

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