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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations) (download) (as text)
Sat Nov 13 16:45:56 2004 UTC (15 years, 10 months ago) by aw0a
File MIME type: text/x-csrc
File size: 25604 byte(s)
moving things to base/generic
1 /*
2 * Ascend Instance Tree Type Implementation
3 * by Tom Epperly
4 * 9/3/89
5 * Version: $Revision: 1.10 $
6 * Version control file: $RCSfile: mathinst.c,v $
7 * Date last modified: $Date: 1998/05/06 17:33:36 $
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 #include <stdarg.h>
31 #include "utilities/ascConfig.h"
32 #include "utilities/ascMalloc.h"
33 #include "utilities/ascPanic.h"
34 #include "general/pool.h"
35 #include "general/list.h"
36 #include "general/dstring.h"
37 #include "compiler/compiler.h"
38 #include "compiler/bit.h"
39 #include "compiler/symtab.h"
40 #include "compiler/fractions.h"
41 #include "compiler/dimen.h"
42 #include "compiler/functype.h"
43 #include "compiler/types.h"
44 #include "compiler/child.h"
45 #include "compiler/type_desc.h"
46 #include "compiler/instance_enum.h"
47 #include "compiler/instance_name.h"
48 #include "compiler/instance_io.h"
49 #include "compiler/instmacro.h"
50 #include "compiler/extinst.h"
51 #include "compiler/instquery.h"
52 #include "compiler/instance_types.h"
53 #include "compiler/linkinst.h"
54 #include "compiler/destroyinst.h"
55 #include "compiler/createinst.h"
56 #include "compiler/refineinst.h"
57 #include "compiler/atomvalue.h"
58 #include "compiler/atomsize.h"
59 #include "compiler/check.h"
60 #include "compiler/dump.h"
61 #include "compiler/childinfo.h"
62 #include "compiler/prototype.h"
63 #include "compiler/pending.h"
64 #include "compiler/find.h"
65 #include "compiler/relation_type.h"
66 #include "compiler/relation.h"
67 #include "compiler/logical_relation.h"
68 #include "compiler/logrelation.h"
69 #include "compiler/relation_util.h"
70 #include "compiler/logrel_util.h"
71 #include "compiler/rel_common.h"
72 #include "compiler/case.h"
73 #include "compiler/when_util.h"
74 #include "compiler/universal.h"
75 #include "compiler/cmpfunc.h"
76 #include "compiler/tmpnum.h"
77 #include "compiler/mathinst.h"
78
79 #ifndef lint
80 static CONST char MathInstModuleID[] = "$Id: mathinst.c,v 1.10 1998/05/06 17:33:36 ballan Exp $";
81 #endif
82
83 enum Expr_enum GetInstanceRelationType(CONST struct Instance *i)
84 {
85 AssertMemory(i);
86 if (i->t == REL_INST) {
87 return RELN_INST(i)->type; /* the implementation kind */
88 } else {
89 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceRelationType.\n");
90 exit(2);/* Needed to keep gcc from whining */
91 }
92 }
93
94 CONST struct relation *GetInstanceRelationOnly(CONST struct Instance *i)
95 {
96 AssertMemory(i);
97 if (i->t == REL_INST) {
98 return RELN_INST(i)->ptr;
99 } else {
100 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceRelationOnly.\n");
101 exit(2);/* Needed to keep gcc from whining */
102 }
103 }
104
105 CONST struct relation *GetInstanceRelation(CONST struct Instance *i,
106 enum Expr_enum *type)
107 {
108 AssertMemory(i);
109 if (i->t == REL_INST) {
110 *type = RELN_INST(i)->type;
111 return RELN_INST(i)->ptr;
112 } else {
113 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceRelation.\n");
114 exit(2);/* Needed to keep gcc from whining */
115 }
116 }
117
118 struct relation *GetInstanceRelToModify(struct Instance *i,
119 enum Expr_enum *type)
120 {
121 AssertMemory(i);
122 if (i->t == REL_INST) {
123 *type = RELN_INST(i)->type;
124 return RELN_INST(i)->ptr;
125 } else {
126 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceRelToModify.\n");
127 exit(2);/* Needed to keep gcc from whining */
128 }
129 }
130
131
132 CONST struct logrelation *GetInstanceLogRel(CONST struct Instance *i)
133 {
134 AssertMemory(i);
135 if (i->t == LREL_INST) {
136 return LRELN_INST(i)->ptr;
137 } else {
138 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceLogRel.\n");
139 exit(2);/* Needed to keep gcc from whining */
140 }
141 }
142
143 struct logrelation *GetInstanceLogRelToModify(struct Instance *i)
144 {
145 AssertMemory(i);
146 if (i->t == LREL_INST) {
147 return LRELN_INST(i)->ptr;
148 } else {
149 Asc_Panic(2, NULL,"Incorrect type passed to GetInstanceLogRelToModify.\n");
150 exit(2);/* Needed to keep gcc from whining */
151 }
152 }
153 CONST struct logrelation *GetInstanceLogRelOnly(CONST struct Instance *i)
154 {
155 AssertMemory(i);
156 if (InstanceKind(i) == LREL_INST) {
157 return LRELN_INST(i)->ptr;
158 } else {
159 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceLogRelOnly.\n");
160 exit(2);/* Needed to keep gcc from whining */
161 }
162 }
163
164 /*
165 * l = GetInstanceOperands(i);
166 * Returns list of vars/models/equations in a mathematical relationship.
167 * May want to include the models/relations from the cases of a when.
168 */
169 struct gl_list_t *GetInstanceOperands(CONST struct Instance *i)
170 {
171 CONST struct gl_list_t *list = NULL;
172 CONST struct gl_list_t *list2 = NULL;
173 struct gl_list_t *result = NULL;
174 unsigned long c,len;
175 CONST struct relation *rel;
176 CONST struct logrelation *lrel;
177 void *p;
178
179 if (i == NULL) {
180 return NULL;
181 }
182 switch (InstanceKind(i)) {
183 case REL_INST:
184 rel = GetInstanceRelationOnly(i);
185 if (rel != NULL) {
186 list = RelationVarList(rel);
187 }
188 break;
189 case LREL_INST:
190 lrel = GetInstanceLogRel(i);
191 if (lrel != NULL) {
192 list = LogRelBoolVarList(lrel);
193 list2 = LogRelSatRelList(lrel);
194 }
195 break;
196 case WHEN_INST:
197 list = GetInstanceWhenVars(i);
198 break;
199 default:
200 return NULL;
201 }
202 len = 0;
203 len += (list != NULL) ? gl_length(list) : 0;
204 len += (list2 != NULL) ? gl_length(list2) : 0;
205 result = gl_create(len);
206 if (list != NULL) {
207 for (c=1; c <= len; c++) {
208 p = gl_fetch(list,c);
209 if (p!=NULL) {
210 gl_append_ptr(result,p);
211 }
212 }
213 }
214 if (list2 != NULL) {
215 for (c=1; c <= len; c++) {
216 p = gl_fetch(list2,c);
217 if (p!=NULL) {
218 gl_append_ptr(result,p);
219 }
220 }
221 }
222 return result;
223 }
224
225 struct gl_list_t *GetInstanceWhenVars(CONST struct Instance *i)
226 {
227 AssertMemory(i);
228 if (i->t == WHEN_INST) {
229 return W_INST(i)->bvar;
230 } else {
231 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceWhenVars.\n");
232 exit(2);/* Needed to keep gcc from whining */
233 }
234 }
235
236
237 struct gl_list_t *GetInstanceWhenCases(CONST struct Instance *i)
238 {
239 AssertMemory(i);
240 if (i->t == WHEN_INST) {
241 return W_INST(i)->cases;
242 } else {
243 Asc_Panic(2, NULL,"Incorrect type passed to GetInstanceWhenCases.\n");
244 exit(2);/* Needed to keep gcc from whining */
245 }
246 }
247
248
249 struct gl_list_t *GetInstanceWhens(CONST struct Instance *i)
250 {
251 AssertMemory(i);
252 switch(i->t) {
253 case BOOLEAN_ATOM_INST:
254 return BA_INST(i)->whens;
255 case INTEGER_ATOM_INST:
256 return IA_INST(i)->whens;
257 case SYMBOL_ATOM_INST:
258 return SYMA_INST(i)->whens;
259 case BOOLEAN_CONSTANT_INST:
260 return BC_INST(i)->whens;
261 case INTEGER_CONSTANT_INST:
262 return IC_INST(i)->whens;
263 case SYMBOL_CONSTANT_INST:
264 return SYMC_INST(i)->whens;
265 case MODEL_INST:
266 return MOD_INST(i)->whens;
267 case REL_INST:
268 return RELN_INST(i)->whens;
269 case LREL_INST:
270 return LRELN_INST(i)->whens;
271 case WHEN_INST:
272 return W_INST(i)->whens;
273 default:
274 Asc_Panic(2, NULL, "Incorrect type passed to GetInstanceWhens.\n");
275 exit(2);/* Needed to keep gcc from whining */
276 }
277 }
278
279 void SetWhenVarList(struct Instance *i,struct gl_list_t *whenvars)
280 {
281 AssertMemory(i);
282 if (i->t == WHEN_INST) {
283 W_INST(i)->bvar = whenvars;
284 } else {
285 Asc_Panic(2, NULL, "Incorrect type passed to SetWhenVarList.\n");
286 }
287 }
288
289 void SetWhenCases(struct Instance *i,struct gl_list_t *whencases)
290 {
291 AssertMemory(i);
292 if (i->t == WHEN_INST) {
293 W_INST(i)->cases = whencases;
294 } else {
295 Asc_Panic(2, NULL, "Incorrect type passed to SetWhenCases.\n");
296 }
297 }
298
299
300 /*
301 * This is a tricky function. If we are attempting to set
302 * a new relation, and if the i->ptr is not NULL, i.e. a
303 * relation structure was already assigned, we must *not* force
304 * the assignment, and destroy the old relation. Unfortunately
305 * at this stage, we would have to back up todo undo the
306 * AddRelations etc. So we punt.
307 */
308 void SetInstanceRelation(struct Instance *i, struct relation *rel,
309 enum Expr_enum type)
310 {
311 AssertMemory(i);
312 if (i->t==REL_INST) {
313 if (RELN_INST(i)->ptr==NULL) {
314 RELN_INST(i)->ptr = rel;
315 RELN_INST(i)->type = type;
316 } else {
317 Asc_Panic(2, NULL, "Attempt to reassign RelationPointer.\n");
318 }
319 } else {
320 Asc_Panic(2, NULL, "Incorrect type passed to SetInstanceRelation.\n");
321 }
322 }
323
324
325 void SetInstanceLogRel(struct Instance *i, struct logrelation *lrel)
326 {
327 AssertMemory(i);
328 if (i->t==LREL_INST) {
329 if (LRELN_INST(i)->ptr==NULL) {
330 LRELN_INST(i)->ptr = lrel;
331 } else {
332 Asc_Panic(2, NULL, "Attempt to reassign Logical Relation Pointer.\n");
333 }
334 } else {
335 Asc_Panic(2, NULL, "Incorrect type passed to SetInstanceLogRel.\n");
336 }
337 }
338
339 /*********************************************************************\
340 Relation list stuff
341 \*********************************************************************/
342
343 unsigned long RelationsCount(CONST struct Instance *i)
344 {
345 assert(i!=NULL);
346 AssertMemory(i);
347 switch(i->t) {
348 case REAL_ATOM_INST:
349 if (RA_INST(i)->relations!=NULL) {
350 return gl_length(RA_INST(i)->relations);
351 } else {
352 return 0;
353 }
354 default:
355 Asc_Panic(2, NULL, "RelationsCount called with inappropriate argument.\n");
356 exit(2);/* Needed to keep gcc from whining */
357 }
358 }
359
360 struct Instance *RelationsForAtom(CONST struct Instance *i,
361 unsigned long int c)
362 {
363 assert((i!=NULL)&&(c>0)&&(c<=RelationsCount(i)));
364 AssertMemory(i);
365 switch(i->t){
366 case REAL_ATOM_INST:
367 if (RA_INST(i)->relations!=NULL) {
368 return INST(gl_fetch(RA_INST(i)->relations,c));
369 } else {
370 Asc_Panic(2, NULL, "c out of bounds in RelationsForAtom.\n");
371 }
372 break;
373 default:
374 Asc_Panic(2, NULL,
375 "RelationsForAtom called with inappropriate argument.\n");
376 break;
377 }
378 exit(2);/* NOT REACHED. Needed to keep gcc from whining */
379 }
380
381 void AddRelation(struct Instance *i, struct Instance *reln)
382 {
383 unsigned long len;
384 assert(i&&reln&&(reln->t==REL_INST));
385 AssertMemory(i);
386 switch(i->t){
387 case REAL_ATOM_INST:
388 if (RA_INST(i)->relations==NULL) {
389 RA_INST(i)->relations = gl_create(AVG_RELATIONS);
390 }
391 len = gl_length(RA_INST(i)->relations);
392 if (gl_search(RA_INST(i)->relations,(char*)reln,(CmpFunc)CmpRelations)==0){
393 gl_append_ptr(RA_INST(i)->relations,(VOIDPTR)reln);
394 }
395 break;
396 default:
397 Asc_Panic(2, NULL, "AddRelation called with inappropriate argument.\n");
398 }
399 }
400
401 void RemoveRelation(struct Instance *i, struct Instance *reln)
402 {
403 register unsigned long c;
404 assert(i&&reln&&(reln->t==REL_INST));
405 AssertMemory(i);
406 switch(i->t) {
407 case REAL_ATOM_INST:
408 if (RA_INST(i)->relations==NULL) {
409 return;
410 }
411 c = gl_search(RA_INST(i)->relations,(char *)reln,(CmpFunc)CmpRelations);
412 if (c>0) {
413 gl_delete(RA_INST(i)->relations,c,0);
414 }
415 break;
416 default:
417 Asc_Panic(2, NULL, "Bad argument to RemoveRelation.\n");
418 }
419 }
420
421
422 /*********************************************************************\
423 Logical Relation list stuff
424 \*********************************************************************/
425
426 unsigned long LogRelationsCount(CONST struct Instance *i)
427 {
428 assert(i!=NULL);
429 AssertMemory(i);
430 switch(i->t) {
431 case BOOLEAN_ATOM_INST:
432 if (BA_INST(i)->logrelations!=NULL) {
433 return gl_length(BA_INST(i)->logrelations);
434 } else {
435 return 0;
436 }
437 case REL_INST:
438 if (RELN_INST(i)->logrels!=NULL) {
439 return gl_length(RELN_INST(i)->logrels);
440 } else {
441 return 0;
442 }
443 case LREL_INST:
444 if (LRELN_INST(i)->logrels!=NULL) {
445 return gl_length(LRELN_INST(i)->logrels);
446 } else {
447 return 0;
448 }
449 default:
450 Asc_Panic(2, "LogRelationsCount",
451 "LogRelationsCount called with inappropriate argument.\n");
452 exit(2);/* Needed to keep gcc from whining */
453 }
454 }
455
456 struct Instance *LogRelationsForInstance(CONST struct Instance *i,
457 unsigned long int c)
458 {
459 assert((i!=NULL)&&(c>0)&&(c<=LogRelationsCount(i)));
460 AssertMemory(i);
461 switch(i->t){
462 case BOOLEAN_ATOM_INST:
463 if (BA_INST(i)->logrelations!=NULL) {
464 return INST(gl_fetch(BA_INST(i)->logrelations,c));
465 } else {
466 Asc_Panic(2, NULL, "c out of bounds in LogRelationsForInstance.\n");
467 }
468 case REL_INST:
469 if (RELN_INST(i)->logrels!=NULL) {
470 return INST(gl_fetch(RELN_INST(i)->logrels,c));
471 } else {
472 Asc_Panic(2, NULL, "c out of bounds in LogRelationsForInstance.\n");
473 }
474 case LREL_INST:
475 if (LRELN_INST(i)->logrels!=NULL) {
476 return INST(gl_fetch(LRELN_INST(i)->logrels,c));
477 } else {
478 Asc_Panic(2, NULL, "c out of bounds in LogRelationsForInstance.\n");
479 }
480 default:
481 Asc_Panic(2, NULL,
482 "LogRelationsForInstance called with inappropriate argument.\n");
483 }
484 exit(2);/* NOT REACHED. Needed to keep gcc from whining */
485 }
486
487 void AddLogRel(struct Instance *i, struct Instance *lreln)
488 {
489 unsigned long len;
490 assert(i&&lreln&&(lreln->t==LREL_INST));
491 AssertMemory(i);
492 switch(i->t){
493 case BOOLEAN_ATOM_INST:
494 if (BA_INST(i)->logrelations==NULL) {
495 BA_INST(i)->logrelations = gl_create(AVG_LOGRELS);
496 }
497 len = gl_length(BA_INST(i)->logrelations);
498 if (gl_search(BA_INST(i)->logrelations,
499 (char *)lreln,(CmpFunc)CmpLogRelations)==0) {
500 gl_append_ptr(BA_INST(i)->logrelations,(VOIDPTR)lreln);
501 }
502 break;
503 case REL_INST:
504 if (RELN_INST(i)->logrels==NULL) {
505 RELN_INST(i)->logrels = gl_create(AVG_LOGRELS);
506 }
507 len = gl_length(RELN_INST(i)->logrels);
508 if (gl_search(RELN_INST(i)->logrels,
509 (char *)lreln,(CmpFunc)CmpLogRelations)==0) {
510 gl_append_ptr(RELN_INST(i)->logrels,(VOIDPTR)lreln);
511 }
512 break;
513 case LREL_INST:
514 if (LRELN_INST(i)->logrels==NULL) {
515 LRELN_INST(i)->logrels = gl_create(AVG_LOGRELS);
516 }
517 len = gl_length(LRELN_INST(i)->logrels);
518 if (gl_search(LRELN_INST(i)->logrels,
519 (char *)lreln,(CmpFunc)CmpLogRelations)==0) {
520 gl_append_ptr(LRELN_INST(i)->logrels,(VOIDPTR)lreln);
521 }
522 break;
523 default:
524 Asc_Panic(2, NULL, "AddLogRel called with inappropriate argument.\n");
525 }
526 }
527
528 void RemoveLogRel(struct Instance *i, struct Instance *lreln)
529 {
530 register unsigned long c;
531 assert(i&&lreln&&(lreln->t==LREL_INST));
532 AssertMemory(i);
533 switch(i->t) {
534 case BOOLEAN_ATOM_INST:
535 if (BA_INST(i)->logrelations==NULL) {
536 return;
537 }
538 c = gl_search(BA_INST(i)->logrelations,
539 (char *)lreln,(CmpFunc)CmpLogRelations);
540 if (c>0) {
541 gl_delete(BA_INST(i)->logrelations,c,0);
542 }
543 break;
544 case REL_INST:
545 if (RELN_INST(i)->logrels==NULL) {
546 return;
547 }
548 c = gl_search(RELN_INST(i)->logrels,
549 (char *)lreln,(CmpFunc)CmpLogRelations);
550 if (c>0) {
551 gl_delete(RELN_INST(i)->logrels,c,0);
552 }
553 break;
554 case LREL_INST:
555 if (LRELN_INST(i)->logrels==NULL) {
556 return;
557 }
558 c = gl_search(LRELN_INST(i)->logrels,
559 (char *)lreln,(CmpFunc)CmpLogRelations);
560 if (c>0) {
561 gl_delete(LRELN_INST(i)->logrels,c,0);
562 }
563 break;
564 default:
565 Asc_Panic(2, NULL, "Bad argument to RemoveLogRel.\n");
566 }
567 }
568
569 /*********************************************************************\
570 When list stuff
571 \*********************************************************************/
572
573 unsigned long WhensCount(struct Instance *i)
574 {
575 assert(i!=NULL);
576 AssertMemory(i);
577 switch(i->t) {
578 case BOOLEAN_ATOM_INST:
579 if (BA_INST(i)->whens!=NULL) {
580 return gl_length(BA_INST(i)->whens);
581 } else {
582 return 0;
583 }
584 case INTEGER_ATOM_INST:
585 if (IA_INST(i)->whens!=NULL) {
586 return gl_length(IA_INST(i)->whens);
587 } else {
588 return 0;
589 }
590 case SYMBOL_ATOM_INST:
591 if (SYMA_INST(i)->whens!=NULL) {
592 return gl_length(SYMA_INST(i)->whens);
593 } else {
594 return 0;
595 }
596 case BOOLEAN_CONSTANT_INST:
597 if (BC_INST(i)->whens!=NULL) {
598 return gl_length(BC_INST(i)->whens);
599 } else {
600 return 0;
601 }
602 case INTEGER_CONSTANT_INST:
603 if (IC_INST(i)->whens!=NULL) {
604 return gl_length(IC_INST(i)->whens);
605 } else {
606 return 0;
607 }
608 case SYMBOL_CONSTANT_INST:
609 if (SYMC_INST(i)->whens!=NULL) {
610 return gl_length(SYMC_INST(i)->whens);
611 } else {
612 return 0;
613 }
614 case MODEL_INST:
615 if (MOD_INST(i)->whens!=NULL) {
616 return gl_length(MOD_INST(i)->whens);
617 } else {
618 return 0;
619 }
620 case REL_INST:
621 if (RELN_INST(i)->whens!=NULL) {
622 return gl_length(RELN_INST(i)->whens);
623 } else {
624 return 0;
625 }
626 case LREL_INST:
627 if (LRELN_INST(i)->whens!=NULL) {
628 return gl_length(LRELN_INST(i)->whens);
629 } else {
630 return 0;
631 }
632 case WHEN_INST:
633 if (W_INST(i)->whens!=NULL) {
634 return gl_length(W_INST(i)->whens);
635 } else {
636 return 0;
637 }
638 default:
639 Asc_Panic(2, NULL, "WhensCount called with inappropriate argument.\n");
640 exit(2);/* Needed to keep gcc from whining */
641
642 }
643 }
644
645
646 struct Instance *WhensForInstance(struct Instance *i,
647 unsigned long int c)
648 {
649 assert((i!=NULL)&&(c>0)&&(c<=WhensCount(i)));
650 AssertMemory(i);
651 switch(i->t) {
652 case BOOLEAN_ATOM_INST:
653 if (BA_INST(i)->whens!=NULL)
654 return INST(gl_fetch(BA_INST(i)->whens,c));
655 else{
656 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
657 }
658 case INTEGER_ATOM_INST:
659 if (IA_INST(i)->whens!=NULL) {
660 return INST(gl_fetch(IA_INST(i)->whens,c));
661 } else {
662 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
663 }
664 case SYMBOL_ATOM_INST:
665 if (SYMA_INST(i)->whens!=NULL) {
666 return INST(gl_fetch(SYMA_INST(i)->whens,c));
667 } else {
668 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
669 }
670 case BOOLEAN_CONSTANT_INST:
671 if (BC_INST(i)->whens!=NULL) {
672 return INST(gl_fetch(BC_INST(i)->whens,c));
673 } else {
674 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
675 }
676 case INTEGER_CONSTANT_INST:
677 if (IC_INST(i)->whens!=NULL) {
678 return INST(gl_fetch(IC_INST(i)->whens,c));
679 } else {
680 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
681 }
682 case SYMBOL_CONSTANT_INST:
683 if (SYMC_INST(i)->whens!=NULL) {
684 return INST(gl_fetch(SYMC_INST(i)->whens,c));
685 } else {
686 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
687 }
688 case MODEL_INST:
689 if (MOD_INST(i)->whens!=NULL) {
690 return INST(gl_fetch(MOD_INST(i)->whens,c));
691 } else {
692 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
693 }
694 case REL_INST:
695 if (RELN_INST(i)->whens!=NULL) {
696 return INST(gl_fetch(RELN_INST(i)->whens,c));
697 } else {
698 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
699 }
700 case LREL_INST:
701 if (LRELN_INST(i)->whens!=NULL) {
702 return INST(gl_fetch(LRELN_INST(i)->whens,c));
703 } else {
704 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
705 }
706 case WHEN_INST:
707 if (W_INST(i)->whens!=NULL) {
708 return INST(gl_fetch(W_INST(i)->whens,c));
709 } else {
710 Asc_Panic(2, NULL, "c out of bounds in WhensForInstance.\n");
711 }
712 default:
713 Asc_Panic(2, "WhensForInstance",
714 "WhensForInstance called with inappropriate argument.\n");
715 }
716 exit(2);/* NOT REACHED. Needed to keep gcc from whining */
717 }
718
719
720 void AddWhen(struct Instance *i, struct Instance *when)
721 {
722 unsigned long len;
723 assert(i&&when&&(when->t==WHEN_INST));
724 AssertMemory(i);
725 switch(i->t){
726 case BOOLEAN_ATOM_INST:
727 if (BA_INST(i)->whens==NULL)
728 BA_INST(i)->whens = gl_create(AVG_WHEN);
729 len = gl_length(BA_INST(i)->whens);
730 if (gl_search(BA_INST(i)->whens,
731 (char *)when,(CmpFunc)CmpWhens)==0)
732 gl_append_ptr(BA_INST(i)->whens,(VOIDPTR)when);
733 break;
734 case INTEGER_ATOM_INST:
735 if (IA_INST(i)->whens==NULL)
736 IA_INST(i)->whens = gl_create(AVG_WHEN);
737 len = gl_length(IA_INST(i)->whens);
738 if (gl_search(IA_INST(i)->whens,
739 (char *)when,(CmpFunc)CmpWhens)==0)
740 gl_append_ptr(IA_INST(i)->whens,(VOIDPTR)when);
741 break;
742 case SYMBOL_ATOM_INST:
743 if (SYMA_INST(i)->whens==NULL)
744 SYMA_INST(i)->whens = gl_create(AVG_WHEN);
745 len = gl_length(SYMA_INST(i)->whens);
746 if (gl_search(SYMA_INST(i)->whens,
747 (char *)when,(CmpFunc)CmpWhens)==0)
748 gl_append_ptr(SYMA_INST(i)->whens,(VOIDPTR)when);
749 break;
750 case BOOLEAN_CONSTANT_INST:
751 if (BC_INST(i)->whens==NULL)
752 BC_INST(i)->whens = gl_create(AVG_WHEN);
753 len = gl_length(BC_INST(i)->whens);
754 if (gl_search(BC_INST(i)->whens,
755 (char *)when,(CmpFunc)CmpWhens)==0)
756 gl_append_ptr(BC_INST(i)->whens,(VOIDPTR)when);
757 break;
758 case INTEGER_CONSTANT_INST:
759 if (IC_INST(i)->whens==NULL)
760 IC_INST(i)->whens = gl_create(AVG_WHEN);
761 len = gl_length(IC_INST(i)->whens);
762 if (gl_search(IC_INST(i)->whens,
763 (char *)when,(CmpFunc)CmpWhens)==0)
764 gl_append_ptr(IC_INST(i)->whens,(VOIDPTR)when);
765 break;
766 case SYMBOL_CONSTANT_INST:
767 if (SYMC_INST(i)->whens==NULL)
768 SYMC_INST(i)->whens = gl_create(AVG_WHEN);
769 len = gl_length(SYMC_INST(i)->whens);
770 if (gl_search(SYMC_INST(i)->whens,
771 (char *)when,(CmpFunc)CmpWhens)==0)
772 gl_append_ptr(SYMC_INST(i)->whens,(VOIDPTR)when);
773 break;
774 case MODEL_INST:
775 if (MOD_INST(i)->whens==NULL)
776 MOD_INST(i)->whens = gl_create(AVG_WHEN);
777 len = gl_length(MOD_INST(i)->whens);
778 if (gl_search(MOD_INST(i)->whens,
779 (char *)when,(CmpFunc)CmpWhens)==0)
780 gl_append_ptr(MOD_INST(i)->whens,(VOIDPTR)when);
781 break;
782 case REL_INST:
783 if (RELN_INST(i)->whens==NULL)
784 RELN_INST(i)->whens = gl_create(AVG_WHEN);
785 len = gl_length(RELN_INST(i)->whens);
786 if (gl_search(RELN_INST(i)->whens,
787 (char *)when,(CmpFunc)CmpWhens)==0)
788 gl_append_ptr(RELN_INST(i)->whens,(VOIDPTR)when);
789 break;
790 case LREL_INST:
791 if (LRELN_INST(i)->whens==NULL)
792 LRELN_INST(i)->whens = gl_create(AVG_WHEN);
793 len = gl_length(LRELN_INST(i)->whens);
794 if (gl_search(LRELN_INST(i)->whens,
795 (char *)when,(CmpFunc)CmpWhens)==0)
796 gl_append_ptr(LRELN_INST(i)->whens,(VOIDPTR)when);
797 break;
798 case WHEN_INST:
799 if (W_INST(i)->whens==NULL)
800 W_INST(i)->whens = gl_create(AVG_WHEN);
801 len = gl_length(W_INST(i)->whens);
802 if (gl_search(W_INST(i)->whens,
803 (char *)when,(CmpFunc)CmpWhens)==0)
804 gl_append_ptr(W_INST(i)->whens,(VOIDPTR)when);
805 break;
806 default:
807 Asc_Panic(2, NULL, "AddWhen called with inappropriate argument.\n");
808 }
809 }
810
811 void RemoveWhen(struct Instance *i, struct Instance *when)
812 {
813 register unsigned long c;
814 assert(i&&when&&(when->t==WHEN_INST));
815 AssertMemory(i);
816 switch(i->t) {
817 case BOOLEAN_ATOM_INST:
818 if (BA_INST(i)->whens==NULL) return;
819 c = gl_search(BA_INST(i)->whens,
820 (char *)when,(CmpFunc)CmpWhens);
821 if (c>0) gl_delete(BA_INST(i)->whens,c,0);
822 break;
823 case INTEGER_ATOM_INST:
824 if (IA_INST(i)->whens==NULL) return;
825 c = gl_search(IA_INST(i)->whens,
826 (char *)when,(CmpFunc)CmpWhens);
827 if (c>0) gl_delete(IA_INST(i)->whens,c,0);
828 break;
829 case SYMBOL_ATOM_INST:
830 if (SYMA_INST(i)->whens==NULL) return;
831 c = gl_search(SYMA_INST(i)->whens,
832 (char *)when,(CmpFunc)CmpWhens);
833 if (c>0) gl_delete(SYMA_INST(i)->whens,c,0);
834 break;
835 case BOOLEAN_CONSTANT_INST:
836 if (BC_INST(i)->whens==NULL) return;
837 c = gl_search(BC_INST(i)->whens,
838 (char *)when,(CmpFunc)CmpWhens);
839 if (c>0) gl_delete(BC_INST(i)->whens,c,0);
840 break;
841 case INTEGER_CONSTANT_INST:
842 if (IC_INST(i)->whens==NULL) return;
843 c = gl_search(IC_INST(i)->whens,
844 (char *)when,(CmpFunc)CmpWhens);
845 if (c>0) gl_delete(IC_INST(i)->whens,c,0);
846 break;
847 case SYMBOL_CONSTANT_INST:
848 if (SYMC_INST(i)->whens==NULL) return;
849 c = gl_search(SYMC_INST(i)->whens,
850 (char *)when,(CmpFunc)CmpWhens);
851 if (c>0) gl_delete(SYMC_INST(i)->whens,c,0);
852 break;
853 case MODEL_INST:
854 if (MOD_INST(i)->whens==NULL) return;
855 c = gl_search(MOD_INST(i)->whens,
856 (char *)when,(CmpFunc)CmpWhens);
857 if (c>0) gl_delete(MOD_INST(i)->whens,c,0);
858 break;
859 case REL_INST:
860 if (RELN_INST(i)->whens==NULL) return;
861 c = gl_search(RELN_INST(i)->whens,
862 (char *)when,(CmpFunc)CmpWhens);
863 if (c>0) gl_delete(RELN_INST(i)->whens,c,0);
864 break;
865 case LREL_INST:
866 if (LRELN_INST(i)->whens==NULL) return;
867 c = gl_search(LRELN_INST(i)->whens,
868 (char *)when,(CmpFunc)CmpWhens);
869 if (c>0) gl_delete(LRELN_INST(i)->whens,c,0);
870 break;
871 case WHEN_INST:
872 if (W_INST(i)->whens==NULL) return;
873 c = gl_search(W_INST(i)->whens,
874 (char *)when,(CmpFunc)CmpWhens);
875 if (c>0) gl_delete(W_INST(i)->whens,c,0);
876 break;
877 default:
878 Asc_Panic(2, NULL, "Bad argument to RemoveWhen.\n");
879 /*NOTREACHED*/
880 }
881 }
882
883

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