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

Diff of /trunk/base/generic/compiler/relation.c

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

revision 708 by johnpye, Tue Jun 27 05:49:11 2006 UTC revision 709 by johnpye, Wed Jun 28 16:28:57 2006 UTC
# Line 241  void InitRelInstantiator(void) { Line 241  void InitRelInstantiator(void) {
241                "ERROR: InitRelInstantiator unable to allocate pool.\n");                "ERROR: InitRelInstantiator unable to allocate pool.\n");
242    }    }
243    g_term_ptrs.buf = (struct relation_term **)    g_term_ptrs.buf = (struct relation_term **)
244      asccalloc(TPBUF_INITSIZE,sizeof(union RelationTermUnion *));      ASC_NEW_ARRAY_CLEAR(union RelationTermUnion *,TPBUF_INITSIZE);
245    /* don't let the above cast fool you about what's in the array */    /* don't let the above cast fool you about what's in the array */
246    if (g_term_ptrs.buf == NULL) {    if (g_term_ptrs.buf == NULL) {
247      Asc_Panic(2, "InitRelInstantiator",      Asc_Panic(2, "InitRelInstantiator",
# Line 250  void InitRelInstantiator(void) { Line 250  void InitRelInstantiator(void) {
250    g_term_ptrs.len = 0;    g_term_ptrs.len = 0;
251    g_term_ptrs.cap = TPBUF_INITSIZE;    g_term_ptrs.cap = TPBUF_INITSIZE;
252    g_term_ptrs.termstackcap = 200;    g_term_ptrs.termstackcap = 200;
253    g_term_ptrs.termstack =    g_term_ptrs.termstack = ASC_NEW_ARRAY(unsigned long,200);
     (unsigned long *)ascmalloc((sizeof(unsigned long)*200));  
254    if (g_term_ptrs.termstack == NULL) {    if (g_term_ptrs.termstack == NULL) {
255      Asc_Panic(2, "InitRelInstantiator",      Asc_Panic(2, "InitRelInstantiator",
256                "ERROR: InitRelInstantiator unable to allocate memory.\n");                "ERROR: InitRelInstantiator unable to allocate memory.\n");
# Line 1888  static int ConvertTermBuf(struct relatio Line 1887  static int ConvertTermBuf(struct relatio
1887    
1888    len = SimplifyTermBuf(g_simplify_relations,g_term_ptrs.buf,g_term_ptrs.len);    len = SimplifyTermBuf(g_simplify_relations,g_term_ptrs.buf,g_term_ptrs.len);
1889    if (len < 1) return 0;    if (len < 1) return 0;
1890    arr = (union RelationTermUnion *)    arr = ASC_NEW_ARRAY(union RelationTermUnion,len);
     ascmalloc(len*sizeof(union RelationTermUnion));  
1891    if (arr==NULL) {    if (arr==NULL) {
1892      FPRINTF(ASCERR,"Create Token Relation: Insufficient memory :-(.\n");      FPRINTF(ASCERR,"Create Token Relation: Insufficient memory :-(.\n");
1893      return 0;      return 0;
# Line 2032  static struct relation_term *CreateDiffT Line 2030  static struct relation_term *CreateDiffT
2030      PTINIT(term);      PTINIT(term);
2031      term->t = e_diff;      term->t = e_diff;
2032      /* NOT YET IMPLEMENTED */      /* NOT YET IMPLEMENTED */
2033        Asc_Panic(2,__FUNCTION__,"not yet implemented");
2034  }  }
2035    
2036  /** create a term from the pool */  /** create a term from the pool */
# Line 2043  static struct relation_term *CreateNaryT Line 2042  static struct relation_term *CreateNaryT
2042    assert(term!=NULL);    assert(term!=NULL);
2043    PTINIT(term);    PTINIT(term);
2044    term->t = e_func;    term->t = e_func;
2045    N_TERM(term) -> fptr = f;    N_TERM(term)->fptr = f;
2046    N_TERM(term) -> args = NULL;    N_TERM(term)->args = NULL;
2047    return term;    return term;
2048  }  }
2049  #endif  /* THIS_IS_AN_UNUSED_FUNCTION */  #endif  /* THIS_IS_AN_UNUSED_FUNCTION */
2050    
2051    
2052  /**  /**
2053   * This function create and *must* create the memory      This function creates and *must* create the memory
2054   * for the structure and for the union that the structure      for the structure and for the union that the structure
2055   * points to. Too much code depends on the pre-existent      points to.
2056   * of a properly initialized union.  
2057   * If copyunion is crs_NOUNION, the share ptr is init to NULL and user      Too much code depends on the pre-existence of a properly initialized union.
2058   * must set refcount,relop after the allocate a UNION or whatever.  
2059   * If copyunion is crs_NEWUNION, share ptr is allocated and configured.      If copyunion is crs_NOUNION, the share ptr is init to NULL and user
2060   *      must set refcount,relop after the allocate a UNION or whatever.
2061   */      If copyunion is crs_NEWUNION, share ptr is allocated and configured.
2062    */
2063  struct relation *CreateRelationStructure(enum Expr_enum relop,int copyunion)  struct relation *CreateRelationStructure(enum Expr_enum relop,int copyunion)
2064  {  {
2065    struct relation *newrelation;    struct relation *newrelation;
2066    
2067    newrelation = (struct relation *)ascmalloc(sizeof(struct relation));    newrelation = ASC_NEW(struct relation);
2068    assert(newrelation!=NULL);    assert(newrelation!=NULL);
2069      CONSOLE_DEBUG("Created 'struct relation' at %p",newrelation);
2070    
2071    newrelation->residual = DBL_MAX;    newrelation->residual = DBL_MAX;
2072    newrelation->multiplier = DBL_MAX;    newrelation->multiplier = DBL_MAX;
# Line 2075  struct relation *CreateRelationStructure Line 2076  struct relation *CreateRelationStructure
2076    newrelation->d =(dim_type *)WildDimension();    newrelation->d =(dim_type *)WildDimension();
2077    
2078    if (copyunion) {    if (copyunion) {
2079      newrelation->share =      newrelation->share = ASC_NEW(union RelationUnion);
         (union RelationUnion *)ascmalloc(sizeof(union RelationUnion));  
2080      assert(newrelation->share!=NULL);      assert(newrelation->share!=NULL);
2081      RelationRefCount(newrelation) = 0;      RelationRefCount(newrelation) = 0;
2082      RelRelop(newrelation) = relop;      RelRelop(newrelation) = relop;
# Line 2100  struct relation *CreateRelationStructure Line 2100  struct relation *CreateRelationStructure
2100    
2101    
2102  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
2103   * EXTERNAL CALL PROCESSING    EXTERNAL CALL PROCESSING
2104   *  */
2105    
2106  /** @note  /** @file "relation.h"
2107        @note
2108      A special note on external relations      A special note on external relations
2109    
2110      External relations behave like relations but they also behave like      External relations behave like relations but they also behave like
# Line 2145  struct relation *CreateBlackBoxRelation( Line 2146  struct relation *CreateBlackBoxRelation(
2146    len = n_inputs + 1; /* an extra for the output variable. */    len = n_inputs + 1; /* an extra for the output variable. */
2147    
2148    /*    /*
2149      Add the input vars, making sure that their incidence      Create 'newlist' which is a uniquified list of inputs plus the 'subject'
2150      is unique, and adjusting the indexing appropriately      Instance (output variable). Keep track of which instances in 'newlist'
2151      on the integer args array.      correspond to which original blackbox argument by building up the 'args'
2152        list at the same time.
2153    */    */
   
2154    args = ASC_NEW_ARRAY_CLEAR(int,len+1);    args = ASC_NEW_ARRAY_CLEAR(int,len+1);
2155      newlist = gl_create(len); /* list of Instance objects */
   newlist = gl_create(len);  
2156    
2157    for (c=1;c<=n_inputs;c++) {    for (c=1;c<=n_inputs;c++) {
2158      var = (struct Instance *)gl_fetch(inputs,c);      var = (struct Instance *)gl_fetch(inputs,c);
# Line 2167  struct relation *CreateBlackBoxRelation( Line 2167  struct relation *CreateBlackBoxRelation(
2167      }      }
2168    }    }
2169    
2170    /* add the subject */    /*
2171        Add the 'subject' instance to the end of the newlist. For a black box,
2172        I think that this means the output  variable. -- JP
2173      */
2174    pos = gl_search(newlist,subject,(CmpFunc)CmpP);    pos = gl_search(newlist,subject,(CmpFunc)CmpP);
2175    if (pos) {    if (pos) {
2176      FPRINTF(ASCERR,"An input and output variable are the same !!\n");      FPRINTF(ASCERR,"An input and output variable are the same !!\n");
# Line 2177  struct relation *CreateBlackBoxRelation( Line 2180  struct relation *CreateBlackBoxRelation(
2180      *args++ = (int)gl_length(newlist);      *args++ = (int)gl_length(newlist);
2181      AddRelation(var,relinst);      AddRelation(var,relinst);
2182    }    }
2183    *args = 0; /* terminate */  
2184      /* Add a zero to terminate the 'args' list. */
2185      *args = 0;
2186    
2187    /*    /*
2188      Create the BlackBox relation structure. This requires      Create the BlackBox relation structure. This requires
# Line 2219  struct relation *CreateGlassBoxRelation( Line 2224  struct relation *CreateGlassBoxRelation(
2224     * the args list indexing.     * the args list indexing.
2225     */     */
2226    if (len) {    if (len) {
2227      tmp = args = (int *)asccalloc((int)(len+1), sizeof(int));      tmp = args = ASC_NEW_ARRAY_CLEAR(int,len+1);
2228      newlist = gl_create(len);      newlist = gl_create(len);
2229    
2230      for (c=1;c<=len;c++) {      for (c=1;c<=len;c++) {
# Line 4037  static union RelationTermUnion Line 4042  static union RelationTermUnion
4042    long int delta;    long int delta;
4043    
4044    if (!old || !len) return NULL;    if (!old || !len) return NULL;
4045    arr = (union RelationTermUnion *)    arr = ASC_NEW_ARRAY(union RelationTermUnion,len);
     ascmalloc(len*sizeof(union RelationTermUnion));  
4046    if (arr==NULL) {    if (arr==NULL) {
4047      FPRINTF(ASCERR,"CopyTokenRelation: Insufficient memory :-(.\n");      FPRINTF(ASCERR,"CopyTokenRelation: Insufficient memory :-(.\n");
4048      return NULL;      return NULL;
# Line 4312  struct relation *CopyRelationToModify(CO Line 4316  struct relation *CopyRelationToModify(CO
4316      return result;      return result;
4317    case e_opcode:    case e_opcode:
4318      Asc_Panic(2, NULL, "Opcode relation copying not yet supported\n");      Asc_Panic(2, NULL, "Opcode relation copying not yet supported\n");
4319      exit(2);/* Needed to keep gcc from whining */      
4320      break;      break;
4321    case e_glassbox:    case e_glassbox:
4322      result = CreateGlassBoxRelation(dest_inst, RGBOX(src).efunc,      result = CreateGlassBoxRelation(dest_inst, RGBOX(src).efunc,
# Line 4321  struct relation *CopyRelationToModify(CO Line 4325  struct relation *CopyRelationToModify(CO
4325      return result;      return result;
4326    case e_blackbox:    case e_blackbox:
4327      Asc_Panic(2, NULL, "Blackbox relation copying not yet supported\n");      Asc_Panic(2, NULL, "Blackbox relation copying not yet supported\n");
4328      exit(2);/* Needed to keep gcc from whining */      
4329      break;      break;
4330    default:    default:
4331      Asc_Panic(2, NULL, "unknown relation type in CopyRelationToModify\n");      Asc_Panic(2, NULL, "unknown relation type in CopyRelationToModify\n");
4332      exit(2);/* Needed to keep gcc from whining */      
4333      break;      break;
4334    }    }
4335  }  }

Legend:
Removed from v.708  
changed lines
  Added in v.709

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