/[ascend]/trunk/base/generic/compiler/instquery.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/instquery.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1372 - (show annotations) (download) (as text)
Fri Mar 30 11:01:20 2007 UTC (17 years, 3 months ago) by jpye
File MIME type: text/x-csrc
File size: 21705 byte(s)
Added some tests that pick up two bugs in the current implementation of default_self
1 /*
2 * Ascend Instance Tree Type Implementation
3 * by Tom Epperly
4 * 9/3/89
5 * Version: $Revision: 1.19 $
6 * Version control file: $RCSfile: instquery.c,v $
7 * Date last modified: $Date: 1998/06/23 13:44:33 $
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
25 * along with the program; if not, write to the Free Software Foundation,
26 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
27 * COPYING.
28 *
29 */
30
31 #include <stdarg.h>
32 #include <utilities/ascConfig.h>
33 #include <utilities/ascMalloc.h>
34 #include <utilities/ascPanic.h>
35 #include <general/list.h>
36 #include <general/pool.h>
37 #include <general/dstring.h>
38
39 #include "bit.h"
40 #include "symtab.h"
41 #include "functype.h"
42 #include "expr_types.h"
43 #include "instance_name.h"
44 #include "instance_io.h"
45 #include "check.h"
46 #include "dump.h"
47 #include "child.h"
48 #include "type_desc.h"
49 #include "type_descio.h"
50 #include "prototype.h"
51 #include "pending.h"
52 #include "find.h"
53 #include "rel_blackbox.h"
54 #include "vlist.h"
55 #include "relation.h"
56 #include "logical_relation.h"
57 #include "logrelation.h"
58 #include "relation_util.h"
59 #include "logrel_util.h"
60 #include "rel_common.h"
61 #include "case.h"
62 #include "when_util.h"
63 #include "universal.h"
64 #include "instance_types.h"
65 /* new */
66 #include "atomsize.h"
67 #include "atomvalue.h"
68 #include "cmpfunc.h"
69 #include "instmacro.h"
70 #include "parentchild.h"
71 #include "module.h"
72 #include "library.h"
73 #include "visitinst.h"
74 #include "instquery.h"
75
76 /**** GLOBAL VARIABLE SECTION ****/
77
78 void (*InterfacePtrATS)() = NULL;
79 void (*InterfacePtrDelete)() = NULL;
80 void (*InterfaceNotify)() = NULL;
81
82 /**** END GLOBAL VARIABLE SECTION ****/
83
84 enum inst_t InstanceKindF(CONST struct Instance *i)
85 {
86 if (i==NULL || (i->t & IERRINST))
87 return (ERROR_INST);
88 return i->t;
89 }
90
91
92 unsigned long InstanceDepth(CONST struct Instance *i)
93 {
94 register unsigned long c,result=0,d;
95 register CONST struct Instance *parent;
96 if (i==NULL) return 0;
97 AssertMemory(i);
98 for(c=NumberParents(i);c>0;c--){
99 parent = InstanceParent(i,c);
100 AssertMemory(parent);
101 if ((d=InstanceDepth(parent))>result) result = d;
102 }
103 return result+1;
104 }
105
106 unsigned long InstanceShortDepth(CONST struct Instance *i)
107 {
108 register unsigned long c,result=UINT_MAX,d;
109 register CONST struct Instance *parent;
110 if (i==NULL) return 0;
111 AssertMemory(i);
112 if (NumberParents(i)==0) return 1;
113 for(c=NumberParents(i);c>0;c--){
114 parent = InstanceParent(i,c);
115 AssertMemory(parent);
116 if ((d=InstanceShortDepth(parent))<result) result = d;
117 }
118 return result+1;
119 }
120
121 /*********************************************************************\
122 SetNextCliqueMember(i,ptr)
123 sets i->alike_ptr to ptr for types that have alike_ptrs.
124 exits on types that don't or bad input.
125 Instantiator use only!
126 \*********************************************************************/
127
128 void SetNextCliqueMember(struct Instance *i, struct Instance *next)
129 {
130 AssertMemory(i);
131 switch(i->t) {
132 case MODEL_INST:
133 MOD_INST(i)->alike_ptr = next;
134 break;
135 /* constants */
136 case REAL_CONSTANT_INST:
137 RC_INST(i)->alike_ptr = next;
138 break;
139 case BOOLEAN_CONSTANT_INST:
140 BC_INST(i)->alike_ptr = next;
141 break;
142 case INTEGER_CONSTANT_INST:
143 IC_INST(i)->alike_ptr = next;
144 break;
145 case SET_ATOM_INST: /* should be a set constant */
146 SA_INST(i)->alike_ptr = next;
147 break;
148 case SYMBOL_CONSTANT_INST:
149 SYMC_INST(i)->alike_ptr = next;
150 break;
151 /* atoms */
152 case REAL_ATOM_INST:
153 RA_INST(i)->alike_ptr = next;
154 break;
155 case BOOLEAN_ATOM_INST:
156 BA_INST(i)->alike_ptr = next;
157 break;
158 case INTEGER_ATOM_INST:
159 IA_INST(i)->alike_ptr = next;
160 break;
161 /* should be a list atom inst
162 case SET_ATOM_INST:
163 SA_INST(i)->alike_ptr = next;
164 break;
165 */
166 case SYMBOL_ATOM_INST:
167 SYMA_INST(i)->alike_ptr = next;
168 break;
169 case REL_INST:
170 ASC_PANIC("Relations can only be ALIKE with themselves.\n");
171 case LREL_INST:
172 Asc_Panic(2, NULL,
173 "Logical Relations can only be ALIKE with themselves.\n");
174 case WHEN_INST:
175 ASC_PANIC("WHEN's can only be ALIKE with themselves.\n");
176 case SIM_INST:
177 ASC_PANIC("Simulations can only be ALIKE with themselves.\n");
178 case ARRAY_INT_INST:
179 case ARRAY_ENUM_INST:
180 ASC_PANIC("Arrays can only be ALIKE with themselves.\n");
181 /* fundamentals */
182 case REAL_INST:
183 case INTEGER_INST:
184 case BOOLEAN_INST:
185 case SET_INST:
186 case SYMBOL_INST:
187 ASC_PANIC("Fundamental reals cannot be made ARE_ALIKE.\n");
188 case DUMMY_INST:
189 ASC_PANIC("UNSELECTED instances cannot be made ARE_ALIKE.\n");
190 default:
191 ASC_PANIC("Illegal atom passed to SetNextCliqueMember.\n");
192 }
193 }
194
195 struct Instance *NextCliqueMember(CONST struct Instance *i){
196 AssertMemory(i);
197 switch(i->t) {
198 case MODEL_INST:
199 return MOD_INST(i)->alike_ptr;
200 /* constants */
201 case REAL_CONSTANT_INST:
202 return RC_INST(i)->alike_ptr;
203 case BOOLEAN_CONSTANT_INST:
204 return BC_INST(i)->alike_ptr;
205 case INTEGER_CONSTANT_INST:
206 return IC_INST(i)->alike_ptr;
207 case SET_ATOM_INST:
208 return SA_INST(i)->alike_ptr;
209 case SYMBOL_CONSTANT_INST:
210 return SYMC_INST(i)->alike_ptr;
211 /* atoms */
212 case REAL_ATOM_INST:
213 return RA_INST(i)->alike_ptr;
214 case BOOLEAN_ATOM_INST:
215 return BA_INST(i)->alike_ptr;
216 case INTEGER_ATOM_INST:
217 return IA_INST(i)->alike_ptr;
218 /* should be list atom
219 case SET_ATOM_INST:
220 return SA_INST(i)->alike_ptr;
221 */
222 case SYMBOL_ATOM_INST:
223 return SYMA_INST(i)->alike_ptr;
224 case REL_INST:
225 case LREL_INST:
226 case WHEN_INST:
227 case ARRAY_INT_INST:
228 case ARRAY_ENUM_INST:
229 /* fundies */
230 case REAL_INST:
231 case INTEGER_INST:
232 case BOOLEAN_INST:
233 case SET_INST:
234 case SYMBOL_INST:
235 case SIM_INST:
236 case DUMMY_INST:
237 return (struct Instance *)i;
238 default:
239 ASC_PANIC("Invalid arguments to NextCliqueMember.\n");
240
241 }
242 }
243
244 VOIDPTR GetInterfacePtr(CONST struct Instance *i)
245 {
246 if (i == NULL) {
247 ASC_PANIC("NULL instance passed to GetInterfacePtr.\n");
248 }
249 AssertMemory(i);
250 switch(i->t) {
251 case DUMMY_INST: return D_INST(i)->interface_ptr;
252 case MODEL_INST: return MOD_INST(i)->interface_ptr;
253 case ARRAY_INT_INST: /* fall through */
254 case ARRAY_ENUM_INST:
255 return ARY_INST(i)->interface_ptr;
256 case REAL_ATOM_INST: return RA_INST(i)->interface_ptr;
257 case BOOLEAN_ATOM_INST: return BA_INST(i)->interface_ptr;
258 case INTEGER_ATOM_INST: return IA_INST(i)->interface_ptr;
259 case SET_ATOM_INST: return SA_INST(i)->interface_ptr;
260 case SYMBOL_ATOM_INST: return SYMA_INST(i)->interface_ptr;
261 case REL_INST: return RELN_INST(i)->interface_ptr;
262 case LREL_INST: return LRELN_INST(i)->interface_ptr;
263 case WHEN_INST: return W_INST(i)->interface_ptr;
264 case SIM_INST: return SIM_INST(i)->interface_ptr;
265 /* constants */
266 case INTEGER_CONSTANT_INST: /* fall through */
267 case BOOLEAN_CONSTANT_INST: /* fall through */
268 case SYMBOL_CONSTANT_INST: /* fall through */
269 case REAL_CONSTANT_INST: return CI_INST(i)->interface_ptr;
270 /* fundies */
271 case REAL_INST: /* fall through */
272 case INTEGER_INST: /* fall through */
273 case BOOLEAN_INST: /* fall through */
274 case SET_INST: /* fall through */
275 case SYMBOL_INST: /* fall through */
276 /* FPRINTF(ASCERR,"Instance type does not possess an GetInterfacePtr."); */
277 break;
278 default:
279 ASC_PANIC("Undefined instance type %d passed to GetInterfacePtr",i->t);
280 }
281 return NULL;
282 }
283
284 void SetInterfacePtr(struct Instance *i, VOIDPTR c)
285 {
286 AssertMemory(i);
287 switch(i->t) {
288 case DUMMY_INST:
289 D_INST(i)->interface_ptr=c;
290 break;
291 case MODEL_INST:
292 MOD_INST(i)->interface_ptr=c;
293 break;
294 case ARRAY_INT_INST: /* FALL THROUGH */
295 case ARRAY_ENUM_INST:
296 ARY_INST(i)->interface_ptr=c;
297 break;
298 case REAL_ATOM_INST:
299 RA_INST(i)->interface_ptr=c;
300 break;
301 case BOOLEAN_ATOM_INST:
302 BA_INST(i)->interface_ptr=c;
303 break;
304 case INTEGER_ATOM_INST:
305 IA_INST(i)->interface_ptr=c;
306 break;
307 case SET_ATOM_INST:
308 SA_INST(i)->interface_ptr=c;
309 break;
310 case SYMBOL_ATOM_INST:
311 SYMA_INST(i)->interface_ptr=c;
312 break;
313 case REL_INST:
314 RELN_INST(i)->interface_ptr=c;
315 break;
316 case LREL_INST:
317 LRELN_INST(i)->interface_ptr=c;
318 break;
319 case WHEN_INST:
320 W_INST(i)->interface_ptr=c;
321 break;
322 case SIM_INST:
323 SIM_INST(i)->interface_ptr=c;
324 break;
325 /* constants */
326 case INTEGER_CONSTANT_INST: /* fall through */
327 case BOOLEAN_CONSTANT_INST: /* fall through */
328 case SYMBOL_CONSTANT_INST: /* fall through */
329 case REAL_CONSTANT_INST:
330 CI_INST(i)->interface_ptr=c;
331 break;
332 case REAL_INST: /* fall through */
333 case INTEGER_INST: /* fall through */
334 case BOOLEAN_INST: /* fall through */
335 case SET_INST: /* fall through */
336 case SYMBOL_INST: /* fall through */
337 FPRINTF(ASCERR,"Instance type does not possess an InterfacePtr.");
338 return;
339 default:
340 ASC_PANIC("Undefined instance type passed to InterfacePtr.\n");
341 }
342 }
343
344 unsigned int GetAnonFlags(CONST struct Instance *i)
345 {
346 AssertMemory(i);
347 switch(i->t) {
348 case SIM_INST:
349 return SIM_INST(i)->anon_flags;
350 case DUMMY_INST:
351 return D_INST(i)->anon_flags;
352 case MODEL_INST:
353 return MOD_INST(i)->anon_flags;
354 case REAL_ATOM_INST: /* fall through */
355 case BOOLEAN_ATOM_INST: /* fall through */
356 case INTEGER_ATOM_INST: /* fall through */
357 case SET_ATOM_INST: /* fall through */
358 case SYMBOL_ATOM_INST:
359 return CA_INST(i)->anon_flags;
360 case REL_INST:
361 return RELN_INST(i)->anon_flags;
362 case LREL_INST:
363 return LRELN_INST(i)->anon_flags;
364 case WHEN_INST:
365 return W_INST(i)->anon_flags;
366 case ARRAY_INT_INST:
367 case ARRAY_ENUM_INST:
368 return ARY_INST(i)->anon_flags;
369 /* constants */
370 case REAL_CONSTANT_INST: /* fall through */
371 case INTEGER_CONSTANT_INST: /* fall through */
372 case BOOLEAN_CONSTANT_INST: /* fall through */
373 case SYMBOL_CONSTANT_INST: /* fall through */
374 return CI_INST(i)->anon_flags;
375 /* fundies */
376 case REAL_INST: /* fall through */
377 case INTEGER_INST: /* fall through */
378 case BOOLEAN_INST: /* fall through */
379 case SET_INST: /* fall through */
380 case SYMBOL_INST: /* fall through */
381 return 0;
382 default:
383 ASC_PANIC("Incorrect type in GetAnonFlags\n"); /*NOTREACHED*/
384
385 }
386 }
387
388 void SetAnonFlags(struct Instance *i,unsigned int flags)
389 {
390 AssertMemory(i);
391 switch (i->t) {
392 case SIM_INST:
393 SIM_INST(i)->anon_flags = flags;
394 case DUMMY_INST:
395 D_INST(i)->anon_flags = flags;
396 break;
397 case MODEL_INST:
398 MOD_INST(i)->anon_flags = flags;
399 break;
400 case REAL_ATOM_INST: /* fall through */
401 case BOOLEAN_ATOM_INST: /* fall through */
402 case INTEGER_ATOM_INST: /* fall through */
403 case SET_ATOM_INST: /* fall through */
404 case SYMBOL_ATOM_INST:
405 CA_INST(i)->anon_flags = flags;
406 break;
407 case REL_INST:
408 RELN_INST(i)->anon_flags = flags;
409 break;
410 case LREL_INST:
411 LRELN_INST(i)->anon_flags = flags;
412 break;
413 case WHEN_INST:
414 W_INST(i)->anon_flags = flags;
415 break;
416 case ARRAY_INT_INST:
417 case ARRAY_ENUM_INST:
418 ARY_INST(i)->anon_flags = flags;
419 break;
420 /* constants */
421 case REAL_CONSTANT_INST: /* fall through */
422 case INTEGER_CONSTANT_INST: /* fall through */
423 case BOOLEAN_CONSTANT_INST: /* fall through */
424 case SYMBOL_CONSTANT_INST:
425 CI_INST(i)->anon_flags = flags;
426 /* fundies */
427 case REAL_INST: /* fall through */
428 case INTEGER_INST: /* fall through */
429 case BOOLEAN_INST: /* fall through */
430 case SET_INST: /* fall through */
431 case SYMBOL_INST: /* fall through */
432 break;
433 default:
434 ASC_PANIC("Incorrect atom type in SetAnonFlags.\n");
435 }
436 }
437
438 symchar *GetSimulationName(struct Instance *i)
439 {
440 assert(i&&InstanceKind(i)==SIM_INST);
441 if (!(i&&InstanceKind(i)==SIM_INST)) {
442 FPRINTF(ASCERR,"GetSimulationName called on non-simulation.\n");
443 }
444 return SIM_INST(i)->name;
445 }
446
447 static
448 void CollectSimulationInstances(struct Instance *i,struct gl_list_t *sims)
449 {
450 unsigned len;
451 assert(i!=NULL && sims != NULL);
452 if (InstanceKind(i) == MODEL_INST) {
453 for (len = NumberParents(i); len > 0 ; len--) {
454 if (InstanceKind(InstanceParent(i,len)) == SIM_INST) {
455 gl_append_ptr(sims,(VOIDPTR)InstanceParent(i,len));
456 }
457 }
458 }
459 }
460
461 struct gl_list_t *FindSimulationAncestors(struct Instance *i)
462 {
463 struct gl_list_t *sims;
464 if (i==NULL) {
465 return NULL;
466 }
467 sims = gl_create(7);
468 SilentVisitInstanceRootsTwo(i,(VisitTwoProc)CollectSimulationInstances,
469 0,(VOIDPTR)sims);
470 return sims;
471 }
472
473 struct Instance *GetSimulationRoot(struct Instance *i)
474 {
475 struct Instance **child_adr;
476 assert(i&&InstanceKind(i)==SIM_INST);
477 child_adr = SIM_CHILD(i,0);
478 return *child_adr;
479 }
480
481
482 /* Returns the number of bytes spent on a particular instance
483 * Does not count relation guts, dimens, strings, or set_t *
484 * as these are all potentially shared.
485 */
486 unsigned long InstanceSize(CONST struct Instance *i)
487 {
488 unsigned long len;
489
490 assert(i!=NULL);
491 AssertMemory(i);
492 len = 0;
493 if (i== NULL ||IsFundamentalInstance(i)) {
494 return len;
495 }
496 /* no bytes for fundamentals, nulls */
497 if (IsConstantInstance(i)) {
498 len += ConstantByteLength(InstanceKind(i));
499 }
500 switch(i->t) {
501 case SIM_INST: /* list is a pointer in the structure */
502 len += sizeof(struct SimulationInstance);
503 return len;
504 case DUMMY_INST:
505 len += sizeof(struct GlobalDummyInstance);
506 return len;
507 case MODEL_INST:
508 len += 2*sizeof(struct gl_list_t);
509 len += sizeof(struct ModelInstance);
510 len += BitListBytes(MOD_INST(i)->executed);
511 len += gl_capacity(MOD_INST(i)->whens) * sizeof(void *);
512 len += gl_capacity(MOD_INST(i)->parents)*sizeof(void *);
513 len += ChildListLen(GetChildList(MOD_INST(i)->desc))*
514 sizeof(struct Instance *);
515 return len;
516 case REAL_CONSTANT_INST:
517 len += sizeof(struct gl_list_t);
518 len += gl_capacity(RC_INST(i)->parents) * sizeof(void *);
519 return len;
520 case BOOLEAN_CONSTANT_INST:
521 len += 2*sizeof(struct gl_list_t);
522 len += gl_capacity(BC_INST(i)->parents) * sizeof(void *);
523 len += gl_capacity(BC_INST(i)->whens) * sizeof(void *);
524 return len;
525 case INTEGER_CONSTANT_INST:
526 len += 2*sizeof(struct gl_list_t);
527 len += gl_capacity(IC_INST(i)->parents) * sizeof(void *);
528 len += gl_capacity(IC_INST(i)->whens) * sizeof(void *);
529 return len;
530 case SYMBOL_CONSTANT_INST:
531 len += 2*sizeof(struct gl_list_t);
532 len += gl_capacity(SYMC_INST(i)->parents) * sizeof(void *);
533 len += gl_capacity(SYMC_INST(i)->whens) * sizeof(void *);
534 return len;
535 case REAL_ATOM_INST:
536 len += GetByteSize(InstanceTypeDesc(i));
537 len += 2*sizeof(struct gl_list_t);
538 len += (gl_capacity(RA_INST(i)->parents) +
539 gl_capacity(RA_INST(i)->relations)) * sizeof(void *);
540 return len;
541 case BOOLEAN_ATOM_INST:
542 len += 3 * sizeof(struct gl_list_t);
543 len += gl_capacity(BA_INST(i)->logrelations) * sizeof(void *);
544 len += gl_capacity(BA_INST(i)->whens) * sizeof(void *);
545 len += GetByteSize(InstanceTypeDesc(i));
546 len += gl_capacity(((struct CommonAtomInstance *)(i))->parents)
547 * sizeof(void *);
548 return len;
549 case INTEGER_ATOM_INST:
550 len += 2 * sizeof(struct gl_list_t);
551 len += gl_capacity(IA_INST(i)->whens) * sizeof(void *);
552 len += GetByteSize(InstanceTypeDesc(i));
553 len += gl_capacity(((struct CommonAtomInstance *)(i))->parents)
554 * sizeof(void *);
555 return len;
556 case SYMBOL_ATOM_INST:
557 len += 2 *sizeof(struct gl_list_t);
558 len += GetByteSize(InstanceTypeDesc(i));
559 len += gl_capacity(SYMA_INST(i)->whens) * sizeof(void *);
560 len += gl_capacity(((struct CommonAtomInstance *)(i))->parents)
561 * sizeof(void *);
562 return len;
563 case SET_ATOM_INST:
564 len += sizeof(struct gl_list_t);
565 len += GetByteSize(InstanceTypeDesc(i));
566 len += gl_capacity(((struct CommonAtomInstance *)(i))->parents)
567 * sizeof(void *);
568 return len;
569 case REL_INST:
570 len += 2*sizeof(struct gl_list_t);
571 len += gl_capacity(RELN_INST(i)->whens) * sizeof(void *);
572 len += gl_capacity(RELN_INST(i)->logrels) * sizeof(void *);
573 len += GetByteSize(InstanceTypeDesc(i));
574 return len;
575 case LREL_INST:
576 len += 2*sizeof(struct gl_list_t);
577 len += gl_capacity(LRELN_INST(i)->whens) * sizeof(void *);
578 len += gl_capacity(LRELN_INST(i)->logrels) * sizeof(void *);
579 len += GetByteSize(InstanceTypeDesc(i));
580 return len;
581 case WHEN_INST:
582 len += 3*sizeof(struct gl_list_t);
583 len += gl_capacity(W_INST(i)->bvar) * sizeof(void *);
584 len += gl_capacity(W_INST(i)->cases) * sizeof(void *);
585 len += gl_capacity(W_INST(i)->whens) * sizeof(void *);
586 len += GetByteSize(InstanceTypeDesc(i));
587 return len;
588 case ARRAY_INT_INST:
589 case ARRAY_ENUM_INST:
590 len += sizeof(struct ArrayInstance);
591 len += 2*sizeof(struct gl_list_t);
592 len += gl_capacity(ARY_INST(i)->children);
593 len += gl_capacity(ARY_INST(i)->parents);
594 if (ARY_INST(i)->children!= NULL) {
595 len += gl_length(ARY_INST(i)->children)*sizeof(struct ArrayChild);
596 }
597 return len;
598 default:
599 ASC_PANIC("Invalid argument to InstanceSize.\n");
600
601 }
602 }
603
604 int IntegerSetInstance(CONST struct Instance *i)
605 {
606 AssertMemory(i);
607 switch(i->t) {
608 case SET_ATOM_INST:
609 return SA_INST(i)->int_set;
610 case SET_INST:
611 return S_INST(i)->int_set;
612 default:
613 ASC_PANIC("IntegerSetInstance called with non-set argument.\n");
614
615 }
616 }
617
618
619 struct TypeDescription *InstanceTypeDesc(CONST struct Instance *i)
620 {
621 assert(i!=NULL);
622 AssertMemory(i);
623 switch(i->t) {
624 case SIM_INST:
625 return SIM_INST(i)->desc; /* SIM_INST -- same as root for the time */
626 case MODEL_INST:
627 return MOD_INST(i)->desc;
628 case DUMMY_INST:
629 return D_INST(i)->desc;
630 case REAL_ATOM_INST:
631 return RA_INST(i)->desc;
632 case BOOLEAN_ATOM_INST:
633 return BA_INST(i)->desc;
634 case INTEGER_ATOM_INST:
635 return IA_INST(i)->desc;
636 case SET_ATOM_INST:
637 return SA_INST(i)->desc;
638 case SYMBOL_ATOM_INST:
639 return SYMA_INST(i)->desc;
640 case REAL_CONSTANT_INST:
641 return RC_INST(i)->desc;
642 case BOOLEAN_CONSTANT_INST:
643 return BC_INST(i)->desc;
644 case INTEGER_CONSTANT_INST:
645 return IC_INST(i)->desc;
646 case SYMBOL_CONSTANT_INST:
647 return SYMC_INST(i)->desc;
648 case REL_INST:
649 return RELN_INST(i)->desc;
650 case LREL_INST:
651 return LRELN_INST(i)->desc;
652 case WHEN_INST:
653 return W_INST(i)->desc;
654 case ARRAY_INT_INST:
655 case ARRAY_ENUM_INST:
656 return ARY_INST(i)->desc;
657 case REAL_INST:
658 case INTEGER_INST:
659 case BOOLEAN_INST:
660 case SET_INST:
661 case SYMBOL_INST:
662 return NULL;
663 default:
664 ASC_PANIC("Unknown instance type passed to InstanceTypeDesc.\n");
665
666 }
667 }
668
669 unsigned long InstanceIndirected(CONST struct Instance *i)
670 {
671 assert(i!=NULL);
672 if (InstanceKind(i) & IARR) {
673 return ARY_INST(i)->indirected;
674 }
675 return LONG_MAX;
676 }
677
678 symchar *InstanceType(register CONST struct Instance *i)
679 {
680 AssertMemory(i);
681 switch(i->t) {
682 case SIM_INST: /* Not sure -- return the type of root */
683 return GetName(SIM_INST(i)->desc);
684 case MODEL_INST:
685 return GetName(MOD_INST(i)->desc);
686 case DUMMY_INST:
687 return GetName(D_INST(i)->desc);
688 case REAL_CONSTANT_INST:
689 return GetName(RC_INST(i)->desc);
690 case BOOLEAN_CONSTANT_INST:
691 return GetName(BC_INST(i)->desc);
692 case INTEGER_CONSTANT_INST:
693 return GetName(IC_INST(i)->desc);
694 case SYMBOL_CONSTANT_INST:
695 return GetName(SYMC_INST(i)->desc);
696 case REAL_ATOM_INST:
697 return GetName(RA_INST(i)->desc);
698 case BOOLEAN_ATOM_INST:
699 return GetName(BA_INST(i)->desc);
700 case INTEGER_ATOM_INST:
701 return GetName(IA_INST(i)->desc);
702 case SET_ATOM_INST:
703 return GetName(SA_INST(i)->desc);
704 case SYMBOL_ATOM_INST:
705 return GetName(SYMA_INST(i)->desc);
706 case REL_INST:
707 return GetName(FindRelationType());
708 case LREL_INST:
709 return GetName(FindLogRelType());
710 case WHEN_INST:
711 return GetName(FindWhenType());
712 case ARRAY_INT_INST:
713 case ARRAY_ENUM_INST: /* the following addsymbol calls suck */
714 return AddSymbol("");
715 case REAL_INST:
716 return GetBaseTypeName(real_type);
717 case INTEGER_INST:
718 return GetBaseTypeName(integer_type);
719 case BOOLEAN_INST:
720 return GetBaseTypeName(boolean_type);
721 case SET_INST:
722 return GetBaseTypeName(set_type);
723 case SYMBOL_INST:
724 return GetBaseTypeName(symbol_type);
725 default:
726 ASC_PANIC("InstanceType called on invalid instance.\n");
727
728 }
729 }
730
731
732 struct BitList *InstanceBitList(CONST struct Instance *i)
733 {
734 AssertMemory(i);
735 switch(i->t) {
736 case MODEL_INST:
737 return MOD_INST(i)->executed;
738 case REAL_ATOM_INST:
739 case BOOLEAN_ATOM_INST:
740 case INTEGER_ATOM_INST:
741 case SET_ATOM_INST:
742 case SYMBOL_ATOM_INST:
743 case REL_INST:
744 case LREL_INST:
745 case WHEN_INST:
746 case ARRAY_INT_INST:
747 case ARRAY_ENUM_INST:
748 case REAL_CONSTANT_INST:
749 case INTEGER_CONSTANT_INST:
750 case BOOLEAN_CONSTANT_INST:
751 case SYMBOL_CONSTANT_INST:
752 case REAL_INST:
753 case INTEGER_INST:
754 case BOOLEAN_INST:
755 case SET_INST:
756 case SYMBOL_INST:
757 case DUMMY_INST:
758 return NULL;
759 default:
760 ASC_PANIC("Unknown instance type passed to InstanceBitList.\n");
761
762 }
763 }
764

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