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

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

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

revision 2687 by jpye, Wed Dec 12 12:39:25 2012 UTC revision 2688 by jpye, Mon Mar 4 08:11:49 2013 UTC
# Line 3388  static void DestroyTermSide(struct relat Line 3388  static void DestroyTermSide(struct relat
3388    temp->length=0L;    temp->length=0L;
3389  }  }
3390    
3391  void DestroyVarList(struct gl_list_t *l, struct Instance *inst)  /**
3392        From a list of variables, remove all references to relation 'inst'.
3393        @param l    list of variables (gl_list of struct Instance *)
3394        @param inst relation instance to be removed from the relations list belonging to each variable
3395    */
3396    void DestroyVarList(struct gl_list_t *l, struct Instance *relinst)
3397  {  {
3398    register struct Instance *ptr;    register struct Instance *ptr;
3399    register unsigned long c;    register unsigned long c;
3400    for(c=gl_length(l);c>=1;c--) {    for(c=gl_length(l);c>=1;c--) {
3401      if (NULL != (ptr = (struct Instance *)gl_fetch(l,c))) {      if (NULL != (ptr = (struct Instance *)gl_fetch(l,c))) {
3402        RemoveRelation(ptr,inst);        CONSOLE_DEBUG("Destroy var list");
3403          RemoveRelation(ptr,relinst);
3404      }      }
3405    }    }
3406    gl_destroy(l);    gl_destroy(l);
# Line 3408  void DestroyRelation(struct relation *re Line 3414  void DestroyRelation(struct relation *re
3414    if (--(RelationRefCount(rel))==0) {    if (--(RelationRefCount(rel))==0) {
3415      switch (GetInstanceRelationType(relinst)) {      switch (GetInstanceRelationType(relinst)) {
3416      case e_token:      case e_token:
3417          CONSOLE_DEBUG("Destroy token rel");
3418        if (RTOKEN(rel).lhs!=NULL) {        if (RTOKEN(rel).lhs!=NULL) {
3419          ascfree(RTOKEN(rel).lhs);          ascfree(RTOKEN(rel).lhs);
3420        }        }
# Line 3419  void DestroyRelation(struct relation *re Line 3426  void DestroyRelation(struct relation *re
3426        }        }
3427        break;        break;
3428      case e_opcode:      case e_opcode:
3429          CONSOLE_DEBUG("Destroy opcode rel");
3430        if (ROPCODE(rel).lhs) {        if (ROPCODE(rel).lhs) {
3431          ascfree((char *)ROPCODE(rel).lhs);          ascfree((char *)ROPCODE(rel).lhs);
3432        }        }
# Line 3430  void DestroyRelation(struct relation *re Line 3438  void DestroyRelation(struct relation *re
3438        }        }
3439        break;        break;
3440      case e_glassbox:      case e_glassbox:
3441          CONSOLE_DEBUG("Destroy glass rel");
3442        if (RGBOX(rel).args) {        if (RGBOX(rel).args) {
3443          ascfree((char *)(RGBOX(rel).args));          ascfree((char *)(RGBOX(rel).args));
3444        }        }
3445        break;        break;
3446      case e_blackbox:      case e_blackbox:
3447          CONSOLE_DEBUG("Destroy black rel");
3448        if (RBBOX(rel).inputArgs) {        if (RBBOX(rel).inputArgs) {
3449          ascfree((void *)(RBBOX(rel).inputArgs));          ascfree((void *)(RBBOX(rel).inputArgs));
3450          RBBOX(rel).inputArgs = NULL;          RBBOX(rel).inputArgs = NULL;
# Line 3457  void DestroyRelation(struct relation *re Line 3467  void DestroyRelation(struct relation *re
3467    
3468    if (rel->vars) DestroyVarList(rel->vars,relinst);    if (rel->vars) DestroyVarList(rel->vars,relinst);
3469    ascfree((char *)rel);    ascfree((char *)rel);
3470      CONSOLE_DEBUG("...");
3471  }  }
3472    
3473  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
# Line 3777  static void UpdateInputArgsList(struct I Line 3788  static void UpdateInputArgsList(struct I
3788  }  }
3789    
3790    
3791  /*  /**
3792      This procedure should change all references of "old" in relation      This procedure should change all references of "old" in relation
3793      instance rel to "new.      instance rel to "new.
3794      Remember:      Remember:
# Line 3787  static void UpdateInputArgsList(struct I Line 3798  static void UpdateInputArgsList(struct I
3798    
3799      If the varlist length is changed, we must rebuild the      If the varlist length is changed, we must rebuild the
3800      indexing array.      indexing array.
3801  * @param relinst the relation instance.      @param relinst the relation instance.
3802  * @param rel the relation structure, which must be from a blackbox relation.      @param rel the relation structure, which must be from a blackbox relation.
3803  * @param new the variable instance being used to replace old.      @param new the variable instance being used to replace old.
3804  * 5 cases:  
3805  * 0-    no-op; old and new are the same already; do nothing.      Five cases that need to be dealt with here:
3806  * 1-    notfound; old is not in the varlist; do nothing.      0-  no-op; old and new are the same already; do nothing.
3807  * 2-    replace; old is found and new is not in list. overwrite old. ref count?      1-  notfound; old is not in the varlist; do nothing.
3808  *       bbox arg indexing remains the same.      2-  replace; old is found and new is not in list. overwrite old. ref count?
3809  * 3-    merge; old and new are both in varlist, which shrinks varlist. This          bbox arg indexing remains the same.
3810  *   will break the indexing, which is part of the shared RelationUnion,      3-  merge; old and new are both in varlist, which shrinks varlist. This
3811  *   and we will need to copy.          will break the indexing, which is part of the shared RelationUnion,
3812  *          and we will need to copy.
3813  * 4-    null; new is NULL, in which case we just overwrite first instance of      4-  null; new is NULL, in which case we just overwrite first instance of
3814  *   old in the list with null. This is probably incorrect in refcount terms.          old in the list with null. This is probably incorrect in refcount terms.
3815  */  */
3816  void ModifyBlackBoxRelPointers(struct Instance *relinst,  void ModifyBlackBoxRelPointers(struct Instance *relinst,
3817                     struct relation *rel,                     struct relation *rel,
# Line 3811  void ModifyBlackBoxRelPointers(struct In Line 3822  void ModifyBlackBoxRelPointers(struct In
3822      struct gl_list_t *branch, *extvars;      struct gl_list_t *branch, *extvars;
3823      struct Instance *arg;      struct Instance *arg;
3824    
3825    /* FIXME: kirk never dealt with varlist rel->properly under merge. ModifyBlackBoxRelPointers      if(0==new)CONSOLE_DEBUG("Blackbox relation %p: clear reference to var 'old'=%p",relinst,old);
 this gets used in interactive merge/refinement.  
 This should have just gone away perhaps now that we don't store  
 instance pointers anywhere except the varlist. maybe we must reindex,though.  
  */  
   
   assert(rel!=NULL);  
   if (old==new) return;  
   extvars = RelationBlackBoxArgNames(rel);  
   if (extvars==NULL) return;  
3826    
3827    len1 = gl_length(extvars);      /* FIXME: kirk never dealt with varlist rel->properly under merge. ModifyBlackBoxRelPointers
3828    if (!len1) return;      this gets used in interactive merge/refinement.
3829    for (c1=1;c1<=len1;c1++){ /* find all occurrences and change them */      This should have just gone away perhaps now that we don't store
3830      branch = (struct gl_list_t *)gl_fetch(extvars,c1);      instance pointers anywhere except the varlist. maybe we must reindex,though. */
3831      if (branch){  
3832        len2 = gl_length(branch);      assert(rel!=NULL);
3833        for (c2=1;c2<=len2;c2++){      if(old==new)return;/* case 1 */
3834      arg = (struct Instance *)gl_fetch(branch,c2);  
3835      if (arg==old) {      extvars = RelationBlackBoxArgNames(rel);
3836        gl_store(branch,c2,(VOIDPTR)new);      if(extvars==NULL)return;
3837          }  
3838        }      len1 = gl_length(extvars);
3839      }      if(!len1)return;
3840    }      for(c1=1;c1<=len1;c1++){ /* find all occurrences and change them */
3841    /* fix up inputs lookup table. */          branch = (struct gl_list_t *)gl_fetch(extvars,c1);
3842    UpdateInputArgsList(relinst,rel,(new==NULL));          if(branch){
3843    /* still need to fix up lhsvar index. */              len2 = gl_length(branch);
3844                for(c2=1;c2<=len2;c2++){
3845                    arg = (struct Instance *)gl_fetch(branch,c2);
3846                    if(arg==old) {
3847                        CONSOLE_DEBUG("Rewriting reference to %p to be %p",c2,new);
3848                        gl_store(branch,c2,(VOIDPTR)new);
3849                    }
3850                }
3851            }
3852        }
3853        /* fix up inputs lookup table. */
3854        UpdateInputArgsList(relinst,rel,(new==NULL));
3855        /* still need to fix up lhsvar index. */
3856  }  }
3857    
3858  /**  /**

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

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