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

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