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

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