/[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 2688 by jpye, Mon Mar 4 08:11:49 2013 UTC revision 2689 by jpye, Mon Mar 4 11:28:19 2013 UTC
# Line 3393  static void DestroyTermSide(struct relat Line 3393  static void DestroyTermSide(struct relat
3393      @param l    list of variables (gl_list of struct Instance *)      @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      @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)  void DestroyVarList(struct gl_list_t *l, struct Instance *relinst){
 {  
3397    register struct Instance *ptr;    register struct Instance *ptr;
3398    register unsigned long c;    register unsigned long c;
3399    for(c=gl_length(l);c>=1;c--) {    for(c=gl_length(l);c>=1;c--){
3400      if (NULL != (ptr = (struct Instance *)gl_fetch(l,c))) {      if(NULL != (ptr = (struct Instance *)gl_fetch(l,c))){
3401        CONSOLE_DEBUG("Destroy var list");        //CONSOLE_DEBUG("Destroy var list");
3402        RemoveRelation(ptr,relinst);        RemoveRelation(ptr,relinst);
3403      }      }
3404    }    }
# Line 3414  void DestroyRelation(struct relation *re Line 3413  void DestroyRelation(struct relation *re
3413    if (--(RelationRefCount(rel))==0) {    if (--(RelationRefCount(rel))==0) {
3414      switch (GetInstanceRelationType(relinst)) {      switch (GetInstanceRelationType(relinst)) {
3415      case e_token:      case e_token:
3416        CONSOLE_DEBUG("Destroy token rel");        //CONSOLE_DEBUG("Destroy token rel");
3417        if (RTOKEN(rel).lhs!=NULL) {        if (RTOKEN(rel).lhs!=NULL) {
3418          ascfree(RTOKEN(rel).lhs);          ascfree(RTOKEN(rel).lhs);
3419        }        }
# Line 3426  void DestroyRelation(struct relation *re Line 3425  void DestroyRelation(struct relation *re
3425        }        }
3426        break;        break;
3427      case e_opcode:      case e_opcode:
3428        CONSOLE_DEBUG("Destroy opcode rel");        //CONSOLE_DEBUG("Destroy opcode rel");
3429        if (ROPCODE(rel).lhs) {        if (ROPCODE(rel).lhs) {
3430          ascfree((char *)ROPCODE(rel).lhs);          ascfree((char *)ROPCODE(rel).lhs);
3431        }        }
# Line 3438  void DestroyRelation(struct relation *re Line 3437  void DestroyRelation(struct relation *re
3437        }        }
3438        break;        break;
3439      case e_glassbox:      case e_glassbox:
3440        CONSOLE_DEBUG("Destroy glass rel");        //CONSOLE_DEBUG("Destroy glass rel");
3441        if (RGBOX(rel).args) {        if (RGBOX(rel).args) {
3442          ascfree((char *)(RGBOX(rel).args));          ascfree((char *)(RGBOX(rel).args));
3443        }        }
3444        break;        break;
3445      case e_blackbox:      case e_blackbox:
3446        CONSOLE_DEBUG("Destroy black rel");        //CONSOLE_DEBUG("Destroy black rel");
3447        if (RBBOX(rel).inputArgs) {        if (RBBOX(rel).inputArgs) {
3448          ascfree((void *)(RBBOX(rel).inputArgs));          ascfree((void *)(RBBOX(rel).inputArgs));
3449          RBBOX(rel).inputArgs = NULL;          RBBOX(rel).inputArgs = NULL;
# Line 3465  void DestroyRelation(struct relation *re Line 3464  void DestroyRelation(struct relation *re
3464      }      }
3465    }    }
3466    
3467      //CONSOLE_DEBUG("Running DestroyVarList on rel->vars for rel %p",rel);
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("...");    //CONSOLE_DEBUG("...");
3471  }  }
3472    
3473  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
# Line 3658  void RecomputeVarListPointers(struct Ins Line 3658  void RecomputeVarListPointers(struct Ins
3658  * 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
3659  *   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.
3660  */  */
3661  void ModifyTokenRelationPointers(struct Instance *relinst,  void ModifyTokenRelationPointers(struct Instance *relinst
3662                       struct relation *rel,      , struct relation *rel, CONST struct Instance *old
3663                       CONST struct Instance *old,      , CONST struct Instance *new
3664                       CONST struct Instance *new)  ){
 {  
3665    unsigned long pos,other;    unsigned long pos,other;
3666    
3667    (void)relinst;    /*  stop gcc whine about unused parameter  */    (void)relinst;    /*  stop gcc whine about unused parameter  */
3668    /* FIXME: ModifyTokenRelationPointers. we may have a problem here handling relation shared    /* FIXME: ModifyTokenRelationPointers. we may have a problem here handling relation shared
3669      merge/split operations and the sorted/unsorted assumption.    merge/split operations and the sorted/unsorted assumption. */
   */  
3670    
3671    assert(rel!=NULL);    assert(rel!=NULL);
3672    
3673    if (old==new) {    if(old==new){
3674      return;      return;
3675    }    }
3676    if (new!=NULL){    if(new!=NULL){
3677      pos = gl_search(rel->vars,old,(CmpFunc)CmpP);      pos = gl_search(rel->vars,old,(CmpFunc)CmpP);
3678      if (pos != 0) {      if(pos != 0){
3679        other = gl_search(rel->vars,new,(CmpFunc)CmpP);        other = gl_search(rel->vars,new,(CmpFunc)CmpP);
3680        if (other != 0L) {        if(other != 0L){
3681          if (RelationRefCount(rel) > 1) {          if(RelationRefCount(rel) > 1){
3682            /* must copy and split off a separate token string            /* must copy and split off a separate token string so as not to mess
3683             * so as not to mess up sharer's varlists.            up sharer's varlists. */
            */  
3684            RelationRefCount(rel)--; /* adjusts the shared data refcount */            RelationRefCount(rel)--; /* adjusts the shared data refcount */
3685            rel->share = CopyRelationShare(rel->share,e_token);            rel->share = CopyRelationShare(rel->share,e_token);
3686            RelationRefCount(rel) = 1; /* init the new copied data refcount */            RelationRefCount(rel) = 1; /* init the new copied data refcount */
3687          }          }
3688      gl_store(rel->vars,pos,(VOIDPTR)new);          gl_store(rel->vars,pos,(VOIDPTR)new);
3689      DeleteAndChange(rel,pos,other);     /* case 3 */          DeleteAndChange(rel,pos,other);     /* case 3 */
3690        } else {        }else{
3691      gl_store(rel->vars,pos,(char *)new);    /* case 2 */          gl_store(rel->vars,pos,(char *)new);    /* case 2 */
3692        }        }
3693      } else{                 /* case 1 */      }else{                  /* case 1 */
3694        FPRINTF(ASCERR,"Warning ModifyTokenRelationPointers arg not found.\n");        FPRINTF(ASCERR,"Warning ModifyTokenRelationPointers arg not found.\n");
3695        FPRINTF(ASCERR,"This shouldn't affect your usage at all.\n");        FPRINTF(ASCERR,"This shouldn't affect your usage at all.\n");
3696      }      }
3697    } else {                      /* case 4 */    }else{                        /* case 4 */
3698      pos = gl_search(rel->vars,old,(CmpFunc)CmpP);      pos = gl_search(rel->vars,old,(CmpFunc)CmpP);
3699      if (pos) {      if(pos){
3700        gl_store(rel->vars,pos,(VOIDPTR)new);        gl_store(rel->vars,pos,(VOIDPTR)new);
3701      }      }
3702    }    }
# Line 3818  void ModifyBlackBoxRelPointers(struct In Line 3815  void ModifyBlackBoxRelPointers(struct In
3815                     CONST struct Instance *old,                     CONST struct Instance *old,
3816                     CONST struct Instance *new                     CONST struct Instance *new
3817  ){  ){
3818      unsigned long len1,c1,len2,c2;      unsigned long pos;
3819      struct gl_list_t *branch, *extvars;      struct gl_list_t *branch, *extvars;
3820      struct Instance *arg;      struct Instance *arg;
3821    
3822      if(0==new)CONSOLE_DEBUG("Blackbox relation %p: clear reference to var 'old'=%p",relinst,old);      if(old==new)return;/* case 1 */
3823    
3824        if(0==new){/* case 4 */
3825            //CONSOLE_DEBUG("Blackbox relation %p: clear reference to var 'old'=%p",relinst,old);
3826            struct gl_list_t *vars = rel->vars;
3827            pos = gl_search(rel->vars, old, (CmpFunc)CmpP);
3828            if(pos){
3829                gl_store(rel->vars, pos, NULL);
3830            }
3831            return;
3832        }
3833        
3834        ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Unhandled case");
3835    
3836    #if 0
3837      /* FIXME: kirk never dealt with varlist rel->properly under merge. ModifyBlackBoxRelPointers      /* FIXME: kirk never dealt with varlist rel->properly under merge. ModifyBlackBoxRelPointers
3838      this gets used in interactive merge/refinement.      this gets used in interactive merge/refinement.
3839      This should have just gone away perhaps now that we don't store      This should have just gone away perhaps now that we don't store
# Line 3853  void ModifyBlackBoxRelPointers(struct In Line 3863  void ModifyBlackBoxRelPointers(struct In
3863      /* fix up inputs lookup table. */      /* fix up inputs lookup table. */
3864      UpdateInputArgsList(relinst,rel,(new==NULL));      UpdateInputArgsList(relinst,rel,(new==NULL));
3865      /* still need to fix up lhsvar index. */      /* still need to fix up lhsvar index. */
3866    #endif
3867  }  }
3868    
3869  /**  /**

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

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