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

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