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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2687 by jpye, Fri Mar 1 02:15:09 2013 UTC revision 2688 by jpye, Mon Mar 4 08:11:49 2013 UTC
# Line 160  static int RemoveParentReferences( Line 160  static int RemoveParentReferences(
160  ){  ){
161    register unsigned long c,pos,length;    register unsigned long c,pos,length;
162    AssertMemory(inst);    AssertMemory(inst);
163    if (parent!=NULL) {    if(parent!=NULL){
164      AssertMemory(parent);      AssertMemory(parent);
165      /* destroy link from inst to parent */      /* destroy link from inst to parent */
166      pos = SearchForParent(inst,parent);      pos = SearchForParent(inst,parent);
167      if (pos != 0 || inst->t == DUMMY_INST) {      if(pos != 0 || inst->t == DUMMY_INST){
168        /* Because the dummy always 'adds' a parent,        /* Because the dummy always 'adds' a parent, it must always delete it to
169         * it must always delete it to keep the ref_count happy.        keep the ref_count happy. Dummy knows of no parents, but knows exactly
170         * Dummy knows of no parents, but knows        how many it doesn't have. */
        * exactly how many it doesn't have.  
        */  
171        DeleteParent(inst,pos);        DeleteParent(inst,pos);
172      }      }
173      /* destroy link(s) from parent to inst */      /* destroy link(s) from parent to inst */
174      while (0 != (pos = ChildIndex(parent,inst))) {      while(0 != (pos = ChildIndex(parent,inst))){
175        StoreChildPtr(parent,pos,NULL);        StoreChildPtr(parent,pos,NULL);
176      }      }
177      return (NumberParents(inst) == 0);      return (NumberParents(inst) == 0);
178    } else {    }else{
179      length = NumberParents(inst);      length = NumberParents(inst);
180      if (inst->t == DUMMY_INST) {      if(inst->t == DUMMY_INST){
181        FPRINTF(ASCERR,        FPRINTF(ASCERR,
182   "The global dummy instance cannot be destroyed w/out parental consent\n");          "The global dummy instance cannot be destroyed w/out parental consent\n"
183          );
184        FPRINTF(ASCERR, "You should not be seeing this message.\n");        FPRINTF(ASCERR, "You should not be seeing this message.\n");
185        return 0;        return 0;
186      }      }
187      for(c=1;c<=length;c++) {      for(c=1;c<=length;c++) {
188        parent = InstanceParent(inst,c);        parent = InstanceParent(inst,c);
189        while (0 != (pos = ChildIndex(parent,inst))) {        while(0 != (pos = ChildIndex(parent,inst))){
190      StoreChildPtr(parent,pos,NULL);          StoreChildPtr(parent,pos,NULL);
191        }        }
192      }      }
193      return  1;      return  1;
# Line 252  static void DeleteArrayChild(struct Arra Line 251  static void DeleteArrayChild(struct Arra
251      After this, a real ATOM can be safely deleted if there are no models      After this, a real ATOM can be safely deleted if there are no models
252      refering to it.      refering to it.
253  */  */
254  static void RemoveRelationLinks(struct Instance *i, struct gl_list_t *list){  static void RemoveRelationLinks(struct Instance *i){
255      struct gl_list_t *list = RA_INST(i)->relations;
256      if(NULL==list)return;
257    register unsigned long c,length;    register unsigned long c,length;
258    assert(list!=NULL);    assert(list!=NULL);
259    length = gl_length(list);    length = gl_length(list);
260    for(c=1;c<=length;c++) {    for(c=1;c<=length;c++) {
261        CONSOLE_DEBUG("Var %p: remove links to this var in relation %p",i, INST(gl_fetch(list,c)));
262      ChangeRelationPointers(INST(gl_fetch(list,c)),i,INST(NULL));      ChangeRelationPointers(INST(gl_fetch(list,c)),i,INST(NULL));
263    }    }
264    gl_destroy(list);    gl_destroy(list);
265      RA_INST(i)->relations = NULL;
266  }  }
267    
268    
# Line 404  static void DestroyInstanceParts(struct Line 407  static void DestroyInstanceParts(struct
407      ascfree((char *)i);      ascfree((char *)i);
408      return;      return;
409    case REAL_ATOM_INST:    case REAL_ATOM_INST:
410        CONSOLE_DEBUG("Removing parts of var %p",i);
411      /* deallocate dynamic memory used by children */      /* deallocate dynamic memory used by children */
412      DestroyAtomChildren(RA_CHILD(i,0),      DestroyAtomChildren(RA_CHILD(i,0),ChildListLen(GetChildList(RA_INST(i)->desc)));
             ChildListLen(GetChildList(RA_INST(i)->desc)));  
413      /* continue delete the atom */      /* continue delete the atom */
414      gl_destroy(RA_INST(i)->parents);      gl_destroy(RA_INST(i)->parents);
415      RA_INST(i)->parents = NULL;      RA_INST(i)->parents = NULL;
416      DeleteTypeDesc(RA_INST(i)->desc);      DeleteTypeDesc(RA_INST(i)->desc);
417      RA_INST(i)->desc = NULL;      RA_INST(i)->desc = NULL;
418      RA_INST(i)->alike_ptr = NULL;      RA_INST(i)->alike_ptr = NULL;
419      if (RA_INST(i)->relations!=NULL) {      RemoveRelationLinks(i);
420        RemoveRelationLinks(i,RA_INST(i)->relations);      /* children are automatically deleted by the following  ----  EH??? how does that work? -JP */
       RA_INST(i)->relations=NULL;  
     }  
     /* children are automatically deleted by the following */  
421      i->t = ERROR_INST;      i->t = ERROR_INST;
422      ascfree((char *)i);      ascfree((char *)i);
423      return;      return;
# Line 493  static void DestroyInstanceParts(struct Line 493  static void DestroyInstanceParts(struct
493      ascfree((char *)i);      ascfree((char *)i);
494      return;      return;
495    case REL_INST:    case REL_INST:
496        CONSOLE_DEBUG("Removing parts of rel %p",i);
497      /* deallocate dynamic memory used by children */      /* deallocate dynamic memory used by children */
498      DestroyAtomChildren(REL_CHILD(i,0),      DestroyAtomChildren(REL_CHILD(i,0),
499              ChildListLen(GetChildList(RELN_INST(i)->desc)));      ChildListLen(GetChildList(RELN_INST(i)->desc)));
500      /* continue deleting the relation */      /* continue deleting the relation */
501      DeleteTypeDesc(RELN_INST(i)->desc);      DeleteTypeDesc(RELN_INST(i)->desc);
502      RELN_INST(i)->desc = NULL;      RELN_INST(i)->desc = NULL;
# Line 510  static void DestroyInstanceParts(struct Line 511  static void DestroyInstanceParts(struct
511        RELN_INST(i)->whens=NULL;        RELN_INST(i)->whens=NULL;
512      }      }
513      /* delete references of reals to this expression */      /* delete references of reals to this expression */
514      if (RELN_INST(i)->ptr != NULL){      if(RELN_INST(i)->ptr != NULL){
515        /*CONSOLE_DEBUG("Destroying relation at %p",RELN_INST(i)->ptr);*/        CONSOLE_DEBUG("Destroying links to relation %p",i);
516        DestroyRelation(RELN_INST(i)->ptr,i);        DestroyRelation(RELN_INST(i)->ptr,i);
517        RELN_INST(i)->ptr = NULL;        RELN_INST(i)->ptr = NULL;
518      }      }
# Line 631  void DestroyInstance(struct Instance *in Line 632  void DestroyInstance(struct Instance *in
632            InstanceKind(inst) != SIM_INST &&            InstanceKind(inst) != SIM_INST &&
633            ((struct PendInstance *)(inst))->p != NULL            ((struct PendInstance *)(inst))->p != NULL
634        ){        ){
635            // remove instance from the pending list, if such exists
636          RemoveInstance(inst);          RemoveInstance(inst);
637        }        }
638        /* remove PENDING or maybe not pending instance in destroy process. */        /* remove PENDING or maybe not pending instance in destroy process. */

Legend:
Removed from v.2687  
changed lines
  Added in v.2688

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