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

Annotation of /trunk/ascend/compiler/instquery.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2183 - (hide annotations) (download) (as text)
Tue May 4 13:38:42 2010 UTC (9 years, 6 months ago) by jpye
File MIME type: text/x-csrc
File size: 21997 byte(s)
Merging slvreq functionality into trunk.
1 aw0a 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 jpye 2018 #include <ascend/utilities/ascConfig.h>
33     #include <ascend/utilities/ascMalloc.h>
34     #include <ascend/utilities/ascPanic.h>
35     #include <ascend/general/list.h>
36     #include <ascend/general/pool.h>
37     #include <ascend/general/dstring.h>
38 johnpye 1210
39 johnpye 399 #include "bit.h"
40     #include "symtab.h"
41     #include "functype.h"
42 johnpye 669 #include "expr_types.h"
43 johnpye 399 #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 johnpye 908 #include "rel_blackbox.h"
54     #include "vlist.h"
55 johnpye 399 #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 aw0a 1 /* new */
66 johnpye 399 #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 aw0a 1
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 jpye 1695 enum inst_t InstanceKindF(CONST struct Instance *i){
85 aw0a 1 if (i==NULL || (i->t & IERRINST))
86     return (ERROR_INST);
87     return i->t;
88     }
89    
90    
91 jpye 1695 unsigned long InstanceDepth(CONST struct Instance *i){
92 aw0a 1 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 jpye 1695 unsigned long InstanceShortDepth(CONST struct Instance *i){
105 aw0a 1 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 jpye 1695 void SetNextCliqueMember(struct Instance *i, struct Instance *next){
126 aw0a 1 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 jpye 1695 ASC_PANIC("Relations can only be ALIKE with themselves.");
167 aw0a 1 case LREL_INST:
168     Asc_Panic(2, NULL,
169 jpye 1695 "Logical Relations can only be ALIKE with themselves.");
170 aw0a 1 case WHEN_INST:
171 jpye 1695 ASC_PANIC("WHEN's can only be ALIKE with themselves.");
172 aw0a 1 case SIM_INST:
173 jpye 1695 ASC_PANIC("Simulations can only be ALIKE with themselves.");
174 aw0a 1 case ARRAY_INT_INST:
175     case ARRAY_ENUM_INST:
176 jpye 1695 ASC_PANIC("Arrays can only be ALIKE with themselves.");
177 aw0a 1 /* fundamentals */
178     case REAL_INST:
179     case INTEGER_INST:
180     case BOOLEAN_INST:
181     case SET_INST:
182     case SYMBOL_INST:
183 jpye 1695 ASC_PANIC("Fundamental reals cannot be made ARE_ALIKE.");
184 aw0a 1 case DUMMY_INST:
185 jpye 1695 ASC_PANIC("UNSELECTED instances cannot be made ARE_ALIKE.");
186 aw0a 1 default:
187 jpye 1695 ASC_PANIC("Illegal atom passed to SetNextCliqueMember.");
188 aw0a 1 }
189     }
190    
191 jpye 1372 struct Instance *NextCliqueMember(CONST struct Instance *i){
192 aw0a 1 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 jpye 1695 ASC_PANIC("Invalid arguments to NextCliqueMember.");
236 johnpye 709
237 aw0a 1 }
238     }
239    
240 jpye 1695 VOIDPTR GetInterfacePtr(CONST struct Instance *i){
241 aw0a 1 if (i == NULL) {
242 jpye 1695 ASC_PANIC("NULL instance passed to GetInterfacePtr.");
243 aw0a 1 }
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 johnpye 1197 /* FPRINTF(ASCERR,"Instance type does not possess an GetInterfacePtr."); */
272     break;
273 aw0a 1 default:
274 johnpye 1197 ASC_PANIC("Undefined instance type %d passed to GetInterfacePtr",i->t);
275     }
276 aw0a 1 return NULL;
277     }
278    
279 jpye 1695 void SetInterfacePtr(struct Instance *i, VOIDPTR c){
280 aw0a 1 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 johnpye 1197 FPRINTF(ASCERR,"Instance type does not possess an InterfacePtr.");
332     return;
333 aw0a 1 default:
334 jpye 1695 ASC_PANIC("Undefined instance type passed to InterfacePtr.");
335 aw0a 1 }
336     }
337    
338 jpye 1695 unsigned int GetAnonFlags(CONST struct Instance *i){
339 aw0a 1 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 jpye 1695 ASC_PANIC("Incorrect type in GetAnonFlags"); /*NOTREACHED*/
377 johnpye 709
378 aw0a 1 }
379     }
380    
381 jpye 1695 void SetAnonFlags(struct Instance *i,unsigned int flags){
382 aw0a 1 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 jpye 1695 ASC_PANIC("Incorrect atom type in SetAnonFlags.");
427 aw0a 1 }
428     }
429    
430 jpye 1695 symchar *GetSimulationName(struct Instance *i){
431 aw0a 1 assert(i&&InstanceKind(i)==SIM_INST);
432     if (!(i&&InstanceKind(i)==SIM_INST)) {
433 jpye 1695 FPRINTF(ASCERR,"GetSimulationName called on non-simulation.");
434 aw0a 1 }
435     return SIM_INST(i)->name;
436     }
437    
438     static
439 jpye 1695 void CollectSimulationInstances(struct Instance *i,struct gl_list_t *sims){
440 aw0a 1 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 jpye 1695 struct gl_list_t *FindSimulationAncestors(struct Instance *i){
452 aw0a 1 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 jpye 1695 struct Instance *GetSimulationRoot(struct Instance *i){
463 aw0a 1 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 jpye 2183 struct Instance *FindSimulationInstance(struct Instance *i){
470     struct gl_list_t *sims;
471     sims = FindSimulationAncestors(i);
472     if(gl_length(sims)!=1){
473     CONSOLE_DEBUG("Instance does not have just one SIM_INST ancestor");
474     return NULL;
475     }
476     struct Instance *sim;
477     sim = gl_fetch(sims,1);
478     gl_destroy(sims);
479     return sim;
480     }
481 aw0a 1
482 jpye 2183
483 aw0a 1 /* Returns the number of bytes spent on a particular instance
484     * Does not count relation guts, dimens, strings, or set_t *
485     * as these are all potentially shared.
486     */
487 jpye 1695 unsigned long InstanceSize(CONST struct Instance *i){
488 aw0a 1 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 jpye 1695 ASC_PANIC("Invalid argument to InstanceSize.");
600 johnpye 709
601 aw0a 1 }
602     }
603    
604 jpye 1695 int IntegerSetInstance(CONST struct Instance *i){
605 aw0a 1 AssertMemory(i);
606     switch(i->t) {
607     case SET_ATOM_INST:
608     return SA_INST(i)->int_set;
609     case SET_INST:
610     return S_INST(i)->int_set;
611     default:
612 jpye 1695 ASC_PANIC("IntegerSetInstance called with non-set argument.");
613 johnpye 709
614 aw0a 1 }
615     }
616    
617    
618 jpye 1695 struct TypeDescription *InstanceTypeDesc(CONST struct Instance *i){
619 aw0a 1 assert(i!=NULL);
620     AssertMemory(i);
621     switch(i->t) {
622     case SIM_INST:
623     return SIM_INST(i)->desc; /* SIM_INST -- same as root for the time */
624     case MODEL_INST:
625     return MOD_INST(i)->desc;
626     case DUMMY_INST:
627     return D_INST(i)->desc;
628     case REAL_ATOM_INST:
629     return RA_INST(i)->desc;
630     case BOOLEAN_ATOM_INST:
631     return BA_INST(i)->desc;
632     case INTEGER_ATOM_INST:
633     return IA_INST(i)->desc;
634     case SET_ATOM_INST:
635     return SA_INST(i)->desc;
636     case SYMBOL_ATOM_INST:
637     return SYMA_INST(i)->desc;
638     case REAL_CONSTANT_INST:
639     return RC_INST(i)->desc;
640     case BOOLEAN_CONSTANT_INST:
641     return BC_INST(i)->desc;
642     case INTEGER_CONSTANT_INST:
643     return IC_INST(i)->desc;
644     case SYMBOL_CONSTANT_INST:
645     return SYMC_INST(i)->desc;
646     case REL_INST:
647     return RELN_INST(i)->desc;
648     case LREL_INST:
649     return LRELN_INST(i)->desc;
650     case WHEN_INST:
651     return W_INST(i)->desc;
652     case ARRAY_INT_INST:
653     case ARRAY_ENUM_INST:
654     return ARY_INST(i)->desc;
655     case REAL_INST:
656     case INTEGER_INST:
657     case BOOLEAN_INST:
658     case SET_INST:
659     case SYMBOL_INST:
660     return NULL;
661     default:
662 jpye 1695 ASC_PANIC("Unknown instance type (i->t=%d)!",i->t);
663 johnpye 709
664 aw0a 1 }
665     }
666    
667 jpye 1695 unsigned long InstanceIndirected(CONST struct Instance *i){
668 aw0a 1 assert(i!=NULL);
669     if (InstanceKind(i) & IARR) {
670     return ARY_INST(i)->indirected;
671     }
672     return LONG_MAX;
673     }
674    
675 jpye 1695 symchar *InstanceType(register CONST struct Instance *i){
676 aw0a 1 AssertMemory(i);
677     switch(i->t) {
678     case SIM_INST: /* Not sure -- return the type of root */
679     return GetName(SIM_INST(i)->desc);
680     case MODEL_INST:
681     return GetName(MOD_INST(i)->desc);
682     case DUMMY_INST:
683     return GetName(D_INST(i)->desc);
684     case REAL_CONSTANT_INST:
685     return GetName(RC_INST(i)->desc);
686     case BOOLEAN_CONSTANT_INST:
687     return GetName(BC_INST(i)->desc);
688     case INTEGER_CONSTANT_INST:
689     return GetName(IC_INST(i)->desc);
690     case SYMBOL_CONSTANT_INST:
691     return GetName(SYMC_INST(i)->desc);
692     case REAL_ATOM_INST:
693     return GetName(RA_INST(i)->desc);
694     case BOOLEAN_ATOM_INST:
695     return GetName(BA_INST(i)->desc);
696     case INTEGER_ATOM_INST:
697     return GetName(IA_INST(i)->desc);
698     case SET_ATOM_INST:
699     return GetName(SA_INST(i)->desc);
700     case SYMBOL_ATOM_INST:
701     return GetName(SYMA_INST(i)->desc);
702     case REL_INST:
703     return GetName(FindRelationType());
704     case LREL_INST:
705     return GetName(FindLogRelType());
706     case WHEN_INST:
707     return GetName(FindWhenType());
708     case ARRAY_INT_INST:
709     case ARRAY_ENUM_INST: /* the following addsymbol calls suck */
710     return AddSymbol("");
711     case REAL_INST:
712     return GetBaseTypeName(real_type);
713     case INTEGER_INST:
714     return GetBaseTypeName(integer_type);
715     case BOOLEAN_INST:
716     return GetBaseTypeName(boolean_type);
717     case SET_INST:
718     return GetBaseTypeName(set_type);
719     case SYMBOL_INST:
720     return GetBaseTypeName(symbol_type);
721     default:
722 jpye 1695 ASC_PANIC("InstanceType called on invalid instance.");
723 johnpye 709
724 aw0a 1 }
725     }
726    
727    
728 jpye 1695 struct BitList *InstanceBitList(CONST struct Instance *i){
729 aw0a 1 AssertMemory(i);
730     switch(i->t) {
731     case MODEL_INST:
732     return MOD_INST(i)->executed;
733     case REAL_ATOM_INST:
734     case BOOLEAN_ATOM_INST:
735     case INTEGER_ATOM_INST:
736     case SET_ATOM_INST:
737     case SYMBOL_ATOM_INST:
738     case REL_INST:
739     case LREL_INST:
740     case WHEN_INST:
741     case ARRAY_INT_INST:
742     case ARRAY_ENUM_INST:
743     case REAL_CONSTANT_INST:
744     case INTEGER_CONSTANT_INST:
745     case BOOLEAN_CONSTANT_INST:
746     case SYMBOL_CONSTANT_INST:
747     case REAL_INST:
748     case INTEGER_INST:
749     case BOOLEAN_INST:
750     case SET_INST:
751     case SYMBOL_INST:
752     case DUMMY_INST:
753     return NULL;
754     default:
755 jpye 1695 ASC_PANIC("Unknown instance type passed to InstanceBitList.");
756 johnpye 709
757 aw0a 1 }
758     }
759    

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