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

Contents of /trunk/ascend/compiler/destroyinst.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2687 - (show annotations) (download) (as text)
Fri Mar 1 02:15:09 2013 UTC (10 years, 3 months ago) by jpye
File MIME type: text/x-csrc
File size: 19322 byte(s)
Moving reproducible version of bug 567 into models/test directory.
Valgrind test shows invalid memory access in RemoveRelation of data freed in DestroyInstanceParts.
1 /*
2 * Ascend Instance Tree Killing
3 * by Tom Epperly & Ben Allan
4 * 9/3/89
5 * Version: $Revision: 1.12 $
6 * Version control file: $RCSfile: destroyinst.c,v $
7 * Date last modified: $Date: 1997/07/18 12:28:50 $
8 * Last modified by: $Author: mthomas $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1996 Ben Allan
13 * based on instance.c
14 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
15 *
16 * The Ascend Language Interpreter is free software; you can redistribute
17 * it and/or modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of the
19 * License, or (at your option) any later version.
20 *
21 * The Ascend Language Interpreter is distributed in hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 #include <stdarg.h>
30 #include <ascend/general/platform.h>
31 #include <ascend/general/panic.h>
32 #include <ascend/general/ascMalloc.h>
33 #include <ascend/general/pool.h>
34 #include <ascend/general/list.h>
35 #include <ascend/general/dstring.h>
36
37 #include "symtab.h"
38 #include "functype.h"
39 #include "expr_types.h"
40 #include "instance_name.h"
41 #include "instance_io.h"
42 #include "child.h"
43 #include "type_desc.h"
44 #include "instmacro.h"
45 #include "instquery.h"
46 #include "instance_types.h"
47 #include "setinstval.h"
48 #include "linkinst.h"
49 #include "destroyinst.h"
50 #include "arrayinst.h"
51 #include "parentchild.h"
52 #include "atomvalue.h"
53 #include "atomsize.h"
54 #include "check.h"
55 #include "dump.h"
56 #include "find.h"
57 #include "type_desc.h"
58 #include "prototype.h"
59 #include "pending.h"
60 #include "rel_blackbox.h"
61 #include "vlist.h"
62 #include "relation.h"
63 #include "logical_relation.h"
64 #include "logrelation.h"
65 #include "relation_util.h"
66 #include "logrel_util.h"
67 #include "rel_common.h"
68 #include "case.h"
69 #include "when_util.h"
70 #include "universal.h"
71 #include "instance_types.h"
72 #include "cmpfunc.h"
73 #include "slvreq.h"
74
75
76 static void DeleteIPtr(struct Instance *i){
77 assert(i&&InterfacePtrDelete);
78 AssertMemory(i);
79 switch(i->t) {
80 case SIM_INST:
81 slvreq_sim_destroy_hooks(i);
82 (*InterfacePtrDelete)(i,SIM_INST(i)->interface_ptr);
83 SIM_INST(i)->interface_ptr = NULL;
84 return;
85 case MODEL_INST:
86 (*InterfacePtrDelete)(i,MOD_INST(i)->interface_ptr);
87 MOD_INST(i)->interface_ptr = NULL;
88 break;
89 case REAL_ATOM_INST:
90 (*InterfacePtrDelete)(i,RA_INST(i)->interface_ptr);
91 RA_INST(i)->interface_ptr = NULL;
92 break;
93 case BOOLEAN_ATOM_INST:
94 (*InterfacePtrDelete)(i,BA_INST(i)->interface_ptr);
95 BA_INST(i)->interface_ptr = NULL;
96 break;
97 case INTEGER_ATOM_INST:
98 (*InterfacePtrDelete)(i,IA_INST(i)->interface_ptr);
99 IA_INST(i)->interface_ptr = NULL;
100 break;
101 case SET_ATOM_INST:
102 (*InterfacePtrDelete)(i,SA_INST(i)->interface_ptr);
103 SA_INST(i)->interface_ptr = NULL;
104 break;
105 case SYMBOL_ATOM_INST:
106 (*InterfacePtrDelete)(i,SYMA_INST(i)->interface_ptr);
107 SYMA_INST(i)->interface_ptr = NULL;
108 break;
109 case REL_INST:
110 (*InterfacePtrDelete)(i,RELN_INST(i)->interface_ptr);
111 RELN_INST(i)->interface_ptr = NULL;
112 break;
113 case LREL_INST:
114 (*InterfacePtrDelete)(i,LRELN_INST(i)->interface_ptr);
115 LRELN_INST(i)->interface_ptr = NULL;
116 break;
117 case WHEN_INST:
118 (*InterfacePtrDelete)(i,W_INST(i)->interface_ptr);
119 W_INST(i)->interface_ptr = NULL;
120 break;
121 /* constants */
122 case INTEGER_CONSTANT_INST:
123 (*InterfacePtrDelete)(i,IC_INST(i)->interface_ptr);
124 IC_INST(i)->interface_ptr = NULL;
125 break;
126 case BOOLEAN_CONSTANT_INST:
127 (*InterfacePtrDelete)(i,BC_INST(i)->interface_ptr);
128 BC_INST(i)->interface_ptr = NULL;
129 break;
130 case SYMBOL_CONSTANT_INST:
131 (*InterfacePtrDelete)(i,SYMC_INST(i)->interface_ptr);
132 SYMC_INST(i)->interface_ptr = NULL;
133 break;
134 case DUMMY_INST:
135 (*InterfacePtrDelete)(i,D_INST(i)->interface_ptr);
136 D_INST(i)->interface_ptr = NULL;
137 break;
138 case REAL_CONSTANT_INST: /* fall through */
139 /* arrays */
140 case ARRAY_INT_INST: /* fall through */
141 case ARRAY_ENUM_INST: /* fall through */
142 /* fundies */
143 case REAL_INST: /* fall through */
144 case INTEGER_INST: /* fall through */
145 case BOOLEAN_INST: /* fall through */
146 case SET_INST: /* fall through */
147 case SYMBOL_INST: /* fall through */
148 break;
149 default:
150 ASC_PANIC("Unknown instance type passed to DeleteIPtr.\n");
151 }
152 }
153
154 /**
155 This never returns anything but 1 for DUMMY_INSTs.
156 @return true value if inst should be deleted; otherwise, return 0.
157 */
158 static int RemoveParentReferences(
159 struct Instance *inst, struct Instance *parent
160 ){
161 register unsigned long c,pos,length;
162 AssertMemory(inst);
163 if (parent!=NULL) {
164 AssertMemory(parent);
165 /* destroy link from inst to parent */
166 pos = SearchForParent(inst,parent);
167 if (pos != 0 || inst->t == DUMMY_INST) {
168 /* Because the dummy always 'adds' a parent,
169 * it must always delete it to keep the ref_count happy.
170 * Dummy knows of no parents, but knows
171 * exactly how many it doesn't have.
172 */
173 DeleteParent(inst,pos);
174 }
175 /* destroy link(s) from parent to inst */
176 while (0 != (pos = ChildIndex(parent,inst))) {
177 StoreChildPtr(parent,pos,NULL);
178 }
179 return (NumberParents(inst) == 0);
180 } else {
181 length = NumberParents(inst);
182 if (inst->t == DUMMY_INST) {
183 FPRINTF(ASCERR,
184 "The global dummy instance cannot be destroyed w/out parental consent\n");
185 FPRINTF(ASCERR, "You should not be seeing this message.\n");
186 return 0;
187 }
188 for(c=1;c<=length;c++) {
189 parent = InstanceParent(inst,c);
190 while (0 != (pos = ChildIndex(parent,inst))) {
191 StoreChildPtr(parent,pos,NULL);
192 }
193 }
194 return 1;
195 }
196 }
197
198 static void RemoveFromClique(struct Instance *inst){
199 register struct Instance *i,*hold;
200 AssertMemory(inst);
201 if ((hold=i=NextCliqueMember(inst))==inst)
202 return;
203 while (NextCliqueMember(i)!=inst)
204 i = NextCliqueMember(i);
205 switch(i->t) {
206 case MODEL_INST:
207 MOD_INST(i)->alike_ptr = hold;
208 break;
209 case REAL_CONSTANT_INST:
210 RC_INST(i)->alike_ptr = hold;
211 break;
212 case BOOLEAN_CONSTANT_INST:
213 BC_INST(i)->alike_ptr = hold;
214 break;
215 case INTEGER_CONSTANT_INST:
216 IC_INST(i)->alike_ptr = hold;
217 break;
218 case SYMBOL_CONSTANT_INST:
219 SYMC_INST(i)->alike_ptr = hold;
220 break;
221 case REAL_ATOM_INST:
222 RA_INST(i)->alike_ptr = hold;
223 break;
224 case BOOLEAN_ATOM_INST:
225 BA_INST(i)->alike_ptr = hold;
226 break;
227 case INTEGER_ATOM_INST:
228 IA_INST(i)->alike_ptr = hold;
229 break;
230 case SET_ATOM_INST:
231 SA_INST(i)->alike_ptr = hold;
232 break;
233 case SYMBOL_ATOM_INST:
234 SYMA_INST(i)->alike_ptr = hold;
235 break;
236 default:
237 Asc_Panic(2, "RemoveFromClique",
238 "Invalid instance in clique found in RemoveFromClique.\n");
239 }
240 }
241
242 static void DeleteArrayChild(struct ArrayChild *acp, struct Instance *parent){
243 if ((acp!=NULL)&&(acp->inst!=NULL)) {
244 AssertContainedMemory(acp,sizeof(struct ArrayChild));
245 DestroyInstance(acp->inst,parent);
246 }
247 }
248
249 /**
250 Take an ATOM and tell all the relations that know about it to
251 forget it, then destroy the list that identifies those relations.
252 After this, a real ATOM can be safely deleted if there are no models
253 refering to it.
254 */
255 static void RemoveRelationLinks(struct Instance *i, struct gl_list_t *list){
256 register unsigned long c,length;
257 assert(list!=NULL);
258 length = gl_length(list);
259 for(c=1;c<=length;c++) {
260 ChangeRelationPointers(INST(gl_fetch(list,c)),i,INST(NULL));
261 }
262 gl_destroy(list);
263 }
264
265
266 /**
267 Take a BOOLEAN ATOM, REL or LOGREL and tell all the logrelations that
268 know about them to forget them, then destroy the list that identifies
269 those logrelations.
270 After this, the ATOM, REL or LOGREL can be deleted if there are no
271 models or whens refering to it.
272 */
273 static
274 void RemoveLogRelLinks(struct Instance *i, struct gl_list_t *list)
275 {
276 register unsigned long c,length;
277 assert(list!=NULL);
278 length = gl_length(list);
279 for(c=1;c<=length;c++) {
280 ChangeLogRelPointers(INST(gl_fetch(list,c)),i,INST(NULL));
281 }
282 gl_destroy(list);
283 }
284
285
286 static
287 void RemoveWhenLinks(struct Instance *i, struct gl_list_t *list)
288 {
289 register unsigned long c,length;
290 assert(list!=NULL);
291 length = gl_length(list);
292 for(c=1;c<=length;c++) {
293 ChangeWhenPointers(INST(gl_fetch(list,c)),i,INST(NULL));
294 }
295 gl_destroy(list);
296 }
297
298 static void DestroyAtomChildren(
299 register struct Instance **i, register unsigned long int nc
300 ){
301 while(nc-- > 0){
302 AssertMemory(i);
303 AssertMemory(*i);
304 if ((*i)->t==SET_INST) {
305 if (S_INST(*i)->list!=NULL) {
306 DestroySet(S_INST(*i)->list);
307 }
308 }
309 i++; /* position pointer for next child */
310 }
311 }
312
313 /*
314 should only be called when there areno more references
315 to the object.
316 */
317 static void DestroyInstanceParts(struct Instance *i){
318 register unsigned long c,length;
319 register struct gl_list_t *l;
320 struct Instance *child;
321 AssertMemory(i);
322 switch(i->t) {
323 case SIM_INST:
324 child = InstanceChild(i,1); /* one child only */
325 DestroyInstance(child,i);
326 SIM_INST(i)->name = NULL; /* main symbol table owns the string */
327 SIM_INST(i)->extvars = NULL;
328 i->t = ERROR_INST;
329 DeleteTypeDesc(SIM_INST(i)->desc);
330 SIM_INST(i)->desc = NULL;
331 ascfree((char *)i);
332 return;
333 case MODEL_INST:
334 gl_destroy(MOD_INST(i)->parents);
335 MOD_INST(i)->parents = NULL;
336 MOD_INST(i)->alike_ptr = NULL;
337 if (MOD_INST(i)->whens!=NULL) {
338 RemoveWhenLinks(i,MOD_INST(i)->whens);
339 MOD_INST(i)->whens=NULL;
340 }
341 DestroyBList(MOD_INST(i)->executed);
342 MOD_INST(i)->executed = NULL;
343 /* destroy reference to children */
344 length = NumberChildren(i);
345 for(c=1;c<=length;c++) {
346 child = InstanceChild(i,c);
347 DestroyInstance(child,i);
348 }
349 i->t = ERROR_INST;
350 DeleteTypeDesc(MOD_INST(i)->desc);
351 MOD_INST(i)->desc = NULL;
352 gl_destroy(MOD_INST(i)->link_table);
353 ascfree((char *)i);
354 return;
355 case REAL_CONSTANT_INST:
356 /* continue delete the atom */
357 gl_destroy(RC_INST(i)->parents);
358 RC_INST(i)->parents = NULL;
359 DeleteTypeDesc(RC_INST(i)->desc);
360 RC_INST(i)->desc = NULL;
361 RC_INST(i)->alike_ptr = NULL;
362 /* children are automatically deleted by the following */
363 i->t = ERROR_INST;
364 ascfree((char *)i);
365 return;
366 case BOOLEAN_CONSTANT_INST:
367 gl_destroy(BC_INST(i)->parents);
368 BC_INST(i)->parents = NULL;
369 DeleteTypeDesc(BC_INST(i)->desc);
370 BC_INST(i)->desc = NULL;
371 BC_INST(i)->alike_ptr = NULL;
372 if (BC_INST(i)->whens!=NULL) {
373 RemoveWhenLinks(i,BC_INST(i)->whens);
374 BC_INST(i)->whens=NULL;
375 }
376 i->t = ERROR_INST;
377 ascfree((char *)i);
378 return;
379 case INTEGER_CONSTANT_INST:
380 gl_destroy(IC_INST(i)->parents);
381 IC_INST(i)->parents = NULL;
382 DeleteTypeDesc(IC_INST(i)->desc);
383 IC_INST(i)->desc = NULL;
384 IC_INST(i)->alike_ptr = NULL;
385 if (IC_INST(i)->whens!=NULL) {
386 RemoveWhenLinks(i,IC_INST(i)->whens);
387 IC_INST(i)->whens=NULL;
388 }
389 i->t = ERROR_INST;
390 ascfree((char *)i);
391 return;
392 case SYMBOL_CONSTANT_INST:
393 gl_destroy(SYMC_INST(i)->parents);
394 SYMC_INST(i)->parents = NULL;
395 DeleteTypeDesc(SYMC_INST(i)->desc);
396 SYMC_INST(i)->desc = NULL;
397 SYMC_INST(i)->alike_ptr = NULL;
398 SYMC_INST(i)->value = NULL;
399 if (SYMC_INST(i)->whens!=NULL) {
400 RemoveWhenLinks(i,SYMC_INST(i)->whens);
401 SYMC_INST(i)->whens=NULL;
402 }
403 i->t = ERROR_INST;
404 ascfree((char *)i);
405 return;
406 case REAL_ATOM_INST:
407 /* deallocate dynamic memory used by children */
408 DestroyAtomChildren(RA_CHILD(i,0),
409 ChildListLen(GetChildList(RA_INST(i)->desc)));
410 /* continue delete the atom */
411 gl_destroy(RA_INST(i)->parents);
412 RA_INST(i)->parents = NULL;
413 DeleteTypeDesc(RA_INST(i)->desc);
414 RA_INST(i)->desc = NULL;
415 RA_INST(i)->alike_ptr = NULL;
416 if (RA_INST(i)->relations!=NULL) {
417 RemoveRelationLinks(i,RA_INST(i)->relations);
418 RA_INST(i)->relations=NULL;
419 }
420 /* children are automatically deleted by the following */
421 i->t = ERROR_INST;
422 ascfree((char *)i);
423 return;
424 case BOOLEAN_ATOM_INST:
425 /* deallocate dynamic memory used by children */
426 DestroyAtomChildren(BA_CHILD(i,0),
427 ChildListLen(GetChildList(BA_INST(i)->desc)));
428 /* continue delete the atom */
429 gl_destroy(BA_INST(i)->parents);
430 BA_INST(i)->parents = NULL;
431 DeleteTypeDesc(BA_INST(i)->desc);
432 BA_INST(i)->desc = NULL;
433 BA_INST(i)->alike_ptr = NULL;
434 if (BA_INST(i)->logrelations!=NULL)
435 RemoveLogRelLinks(i,BA_INST(i)->logrelations);
436 if (BA_INST(i)->whens!=NULL) {
437 RemoveWhenLinks(i,BA_INST(i)->whens);
438 BA_INST(i)->whens=NULL;
439 }
440 i->t = ERROR_INST;
441 /* children are automatically deleted by the following */
442 ascfree((char *)i);
443 return;
444 case INTEGER_ATOM_INST:
445 /* deallocate dynamic memory used by children */
446 DestroyAtomChildren(IA_CHILD(i,0),
447 ChildListLen(GetChildList(IA_INST(i)->desc)));
448 /* continue delete the atom */
449 gl_destroy(IA_INST(i)->parents);
450 IA_INST(i)->parents = NULL;
451 DeleteTypeDesc(IA_INST(i)->desc);
452 IA_INST(i)->desc = NULL;
453 IA_INST(i)->alike_ptr = NULL;
454 if (IA_INST(i)->whens!=NULL) {
455 RemoveWhenLinks(i,IA_INST(i)->whens);
456 IA_INST(i)->whens=NULL;
457 }
458 i->t = ERROR_INST;
459 /* children are automatically deleted by the following */
460 ascfree((char *)i);
461 return;
462 case SET_ATOM_INST:
463 /* deallocate dynamic memory used by children */
464 DestroyAtomChildren(SA_CHILD(i,0),
465 ChildListLen(GetChildList(SA_INST(i)->desc)));
466 /* continue delete the atom */
467 gl_destroy(SA_INST(i)->parents);
468 SA_INST(i)->parents = NULL;
469 DeleteTypeDesc(SA_INST(i)->desc);
470 SA_INST(i)->desc = NULL;
471 SA_INST(i)->alike_ptr = NULL;
472 if (SA_INST(i)->list != NULL)
473 DestroySet(SA_INST(i)->list);
474 i->t = ERROR_INST;
475 ascfree((char *)i);
476 return;
477 case SYMBOL_ATOM_INST:
478 /* deallocate dynamic memory used by children */
479 DestroyAtomChildren(SYMA_CHILD(i,0),
480 ChildListLen(GetChildList(SYMA_INST(i)->desc)));
481 /* continue to delete the atom */
482 gl_destroy(SYMA_INST(i)->parents);
483 SYMA_INST(i)->parents = NULL;
484 DeleteTypeDesc(SYMA_INST(i)->desc);
485 SYMA_INST(i)->desc = NULL;
486 SYMA_INST(i)->alike_ptr = NULL;
487 if (SYMA_INST(i)->whens!=NULL) {
488 RemoveWhenLinks(i,SYMA_INST(i)->whens);
489 SYMA_INST(i)->whens = NULL;
490 }
491 SYMA_INST(i)->value = NULL;
492 i->t = ERROR_INST;
493 ascfree((char *)i);
494 return;
495 case REL_INST:
496 /* deallocate dynamic memory used by children */
497 DestroyAtomChildren(REL_CHILD(i,0),
498 ChildListLen(GetChildList(RELN_INST(i)->desc)));
499 /* continue deleting the relation */
500 DeleteTypeDesc(RELN_INST(i)->desc);
501 RELN_INST(i)->desc = NULL;
502 RELN_INST(i)->parent[0] = NULL;
503 RELN_INST(i)->parent[1] = NULL;
504 if (RELN_INST(i)->logrels!=NULL) {
505 RemoveLogRelLinks(i,RELN_INST(i)->logrels);
506 RELN_INST(i)->logrels=NULL;
507 }
508 if (RELN_INST(i)->whens!=NULL) {
509 RemoveWhenLinks(i,RELN_INST(i)->whens);
510 RELN_INST(i)->whens=NULL;
511 }
512 /* delete references of reals to this expression */
513 if (RELN_INST(i)->ptr != NULL){
514 /*CONSOLE_DEBUG("Destroying relation at %p",RELN_INST(i)->ptr);*/
515 DestroyRelation(RELN_INST(i)->ptr,i);
516 RELN_INST(i)->ptr = NULL;
517 }
518 /* after relation has been destroyed */
519 if(RELN_INST(i)->ptr != NULL){
520 ERROR_REPORTER_HERE(ASC_PROG_ERR,"Rel ptr not null where expected");
521 }
522 i->t = ERROR_INST;
523 ascfree((char *)i);
524 return;
525 case LREL_INST:
526 DestroyAtomChildren(LREL_CHILD(i,0),
527 ChildListLen(GetChildList(LRELN_INST(i)->desc)));
528 DeleteTypeDesc(LRELN_INST(i)->desc);
529 LRELN_INST(i)->desc = NULL;
530 LRELN_INST(i)->parent[0] = NULL;
531 LRELN_INST(i)->parent[1] = NULL;
532 if (LRELN_INST(i)->logrels!=NULL) {
533 RemoveLogRelLinks(i,LRELN_INST(i)->logrels);
534 LRELN_INST(i)->logrels=NULL;
535 }
536 if (LRELN_INST(i)->whens!=NULL) {
537 RemoveWhenLinks(i,LRELN_INST(i)->whens);
538 LRELN_INST(i)->whens=NULL;
539 }
540 if (LRELN_INST(i)->ptr != NULL){
541 DestroyLogRelation(LRELN_INST(i)->ptr,i);
542 LRELN_INST(i)->ptr = NULL;
543 }
544 LRELN_INST(i)->ptr = NULL;
545 i->t = ERROR_INST;
546 ascfree((char *)i);
547 return;
548 case WHEN_INST:
549 DeleteTypeDesc(W_INST(i)->desc);
550 W_INST(i)->desc = NULL;
551 W_INST(i)->parent[0] = NULL;
552 W_INST(i)->parent[1] = NULL;
553 if (W_INST(i)->whens!=NULL) {
554 RemoveWhenLinks(i,W_INST(i)->whens);
555 W_INST(i)->whens=NULL;
556 }
557 if (W_INST(i)->bvar!=NULL) {
558 DestroyWhenVarList(W_INST(i)->bvar,i);
559 W_INST(i)->bvar = NULL;
560 }
561 if (W_INST(i)->cases!=NULL) {
562 DestroyWhenCaseList(W_INST(i)->cases,i);
563 W_INST(i)->cases = NULL;
564 }
565 i->t = ERROR_INST;
566 ascfree((char *)i);
567 return;
568 case ARRAY_INT_INST:
569 case ARRAY_ENUM_INST:
570 DeleteTypeDesc(ARY_INST(i)->desc);
571 gl_destroy(ARY_INST(i)->parents);
572 ARY_INST(i)->parents = NULL;
573 l = ARY_INST(i)->children;
574 if (l!=NULL){
575 length = gl_length(l);
576 for (c=1; c <= length; c++) {
577 DeleteArrayChild((struct ArrayChild *)gl_fetch(l,c),i);
578 FREEPOOLAC(gl_fetch(l,c));
579 }
580 gl_destroy(l);
581 }
582 ARY_INST(i)->children = NULL;
583 i->t = ERROR_INST;
584 ascfree((char *)i);
585 return;
586 case REAL_INST:
587 i->t = ERROR_INST;
588 return;
589 case INTEGER_INST:
590 i->t = ERROR_INST;
591 return;
592 case BOOLEAN_INST:
593 i->t = ERROR_INST;
594 return;
595 case SET_INST:
596 if (S_INST(i)->list!=NULL)
597 DestroySet(S_INST(i)->list);
598 i->t = ERROR_INST;
599 return;
600 case SYMBOL_INST:
601 i->t = ERROR_INST;
602 return;
603 case DUMMY_INST:
604 /* no parts */
605 DeleteTypeDesc(D_INST(i)->desc);
606 i->t = ERROR_INST;
607 ascfree((char *)i);
608 return;
609 default:
610 Asc_Panic(2, "DeleteInstance",
611 "Unknown type of instance passed to DeleteInstance.\n");
612 }
613 }
614
615 void DestroyInstance(struct Instance *inst, struct Instance *parent){
616 struct TypeDescription *desc;
617 int delete;
618 if(inst==NULL) return;
619
620 if(InterfacePtrDelete!=NULL){
621 DeleteIPtr(inst);
622 }
623 delete = RemoveParentReferences(inst,parent);
624 if(delete){
625 if (inst->t != DUMMY_INST){
626 desc = InstanceTypeDesc(inst);
627 if(GetUniversalFlag(desc)){ /* universal is being deleted */
628 RemoveUniversalInstance(GetUniversalTable(),inst);
629 }
630 if(IsCompoundInstance(inst) &&
631 InstanceKind(inst) != SIM_INST &&
632 ((struct PendInstance *)(inst))->p != NULL
633 ){
634 RemoveInstance(inst);
635 }
636 /* remove PENDING or maybe not pending instance in destroy process. */
637 RemoveFromClique(inst);
638 DestroyInstanceParts(inst);
639 }else{
640 if(D_INST(inst)->ref_count<2){
641 desc = InstanceTypeDesc(inst);
642 if(GetUniversalFlag(desc)){ /* universal is being deleted */
643 RemoveUniversalInstance(GetUniversalTable(),inst);
644 }
645 /* dummy is never in cliques or pending */
646 DestroyInstanceParts(inst);
647 }
648 }
649 }
650 }
651

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