Changeset c227a2f in git


Ignore:
Timestamp:
Jun 6, 2011, 4:40:16 PM (13 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
f0910569263b99287146ba84e626f35f43980b56
Parents:
e3687463a6a7bf65d26001ae69082c0fdcfeb425
Message:
attribute handling

git-svn-id: file:///usr/local/Singular/svn/trunk@14260 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • Singular/attrib.cc

    re368746 rc227a2f  
    3737attr sattr::Copy()
    3838{
    39   omCheckAddrSize(this,sizeof(sattr));
    40   attr n=(attr)omAlloc0Bin(sattr_bin);
    41   n->atyp=atyp;
    42   if (name!=NULL) n->name=omStrDup(name);
    43   n->data=CopyA();
    44   if (next!=NULL)
    45   {
    46     n->next=next->Copy();
    47   }
    48   return n;
     39  if (this!=NULL)
     40  {
     41    omCheckAddrSize(this,sizeof(sattr));
     42    attr n=(attr)omAlloc0Bin(sattr_bin);
     43    n->atyp=atyp;
     44    if (name!=NULL) n->name=omStrDup(name);
     45    n->data=CopyA();
     46    if (next!=NULL)
     47    {
     48      n->next=next->Copy();
     49    }
     50    return n;
     51  }
     52  else
     53    return NULL;
    4954}
    5055
     
    9095  while (h!=NULL)
    9196  {
    92     if (0 == strcmp(s,h->name)) 
    93     { 
     97    if (0 == strcmp(s,h->name))
     98    {
    9499#ifdef TEST
    95100      //::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
     
    114119{
    115120  attr temp;
    116   if (root->e==NULL)
    117     temp = root->attribute->get(name);
    118   else
    119     temp = (root->LData())->attribute->get(name);
    120   if ((temp==NULL) && (root->rtyp==IDHDL))
    121   {
    122     idhdl h=(idhdl)root->data;
    123     temp=h->attribute->get(name);
    124   }
     121  attr a=*(root->Attribute());
     122  temp = a->get(name);
    125123  if (temp!=NULL)
    126124    return temp->data;
     
    140138void * atGet(leftv root,const char * name, int t)
    141139{
    142   attr temp = root->attribute->get(name);
    143   if ((temp==NULL) && (root->rtyp==IDHDL))
    144   {
    145     idhdl h=(idhdl)root->data;
    146     temp=h->attribute->get(name);
    147   }
     140  attr a=*(root->Attribute());
     141  attr temp = a->get(name);
    148142  if ((temp!=NULL) && (temp->atyp==t))
    149143    return temp->data;
     
    160154    && (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
    161155      WerrorS("cannot set ring-dependend objects at this type");
    162     else 
     156    else
    163157      root->attribute=root->attribute->set(name,data,typ);
    164158  }
     
    169163  if (root!=NULL)
    170164  {
    171     if (root->e!=NULL)
    172     {
    173       Werror("object must have a name for attrib %s",name);
    174     }
    175     else
    176     {
    177       int rt=root->Typ();
    178       if ((rt!=RING_CMD)
    179       && (rt!=QRING_CMD)
    180       && (!RingDependend(rt))&&(RingDependend(typ)))
    181         WerrorS("cannot set ring-dependend objects at this type");
    182       else 
    183       if (root->rtyp==IDHDL)
    184       {
    185         idhdl h=(idhdl)root->data;
    186         h->attribute=h->attribute->set(name,data,typ);
    187       }
    188       else
    189       {
    190         root->attribute=root->attribute->set(name,data,typ);
    191       }
     165    attr *a=root->Attribute();
     166    int rt=root->Typ();
     167    if ((rt!=RING_CMD)
     168    && (rt!=QRING_CMD)
     169    && (!RingDependend(rt))&&(RingDependend(typ)))
     170      WerrorS("cannot set ring-dependend objects at this type");
     171    else
     172    {
     173      *a=(*a)->set(name,data,typ);
    192174    }
    193175  }
     
    240222  root->attribute = NULL;
    241223}
    242 
    243 BOOLEAN atATTRIB1(leftv res,leftv a)
    244 {
    245   leftv v=a;
     224void at_KillAll(leftv root, const ring r)
     225{
     226  root->attribute->killAll(r);
     227  root->attribute = NULL;
     228}
     229
     230BOOLEAN atATTRIB1(leftv res,leftv v)
     231{
    246232  int t;
    247   attr at;
    248   if (a->e!=NULL)
    249   {
    250     v=a->LData();
    251     if (v==NULL) return TRUE;
    252   }
    253   at=v->attribute;
    254   if ((a->rtyp==IDHDL)&&(a->e==NULL))
    255   {
    256     at=IDATTR((idhdl)v->data);
    257   }
     233  attr *aa=(v->Attribute());
     234  if (aa==NULL)
     235  {
     236    WerrorS("this object cannot have attributes");
     237    return TRUE;
     238  }
     239  attr a=*aa;
    258240  BOOLEAN haveNoAttribute=TRUE;
    259   if (hasFlag(v,FLAG_STD))
    260   {
    261     PrintS("attr:isSB, type int\n");
    262     haveNoAttribute=FALSE;
    263   }
    264   if (hasFlag(v,FLAG_QRING))
    265   {
    266     PrintS("attr:qringNF, type int\n");
    267     haveNoAttribute=FALSE;
    268   }
    269   if (((t=v->Typ())==RING_CMD)||(t==QRING_CMD))
    270   {
    271     PrintS("attr:global, type int\n");
    272     haveNoAttribute=FALSE;
    273   }
    274   if (at!=NULL)                    at->Print();
    275   else  if(haveNoAttribute)        PrintS("no attributes\n");
     241  if (v->e==NULL)
     242  {
     243    if (hasFlag(v,FLAG_STD))
     244    {
     245      PrintS("attr:isSB, type int\n");
     246      haveNoAttribute=FALSE;
     247    }
     248    if (hasFlag(v,FLAG_QRING))
     249    {
     250      PrintS("attr:qringNF, type int\n");
     251      haveNoAttribute=FALSE;
     252    }
     253    if (((t=v->Typ())==RING_CMD)||(t==QRING_CMD))
     254    {
     255      PrintS("attr:global, type int\n");
     256      haveNoAttribute=FALSE;
     257    }
     258  }
     259  else
     260  {
     261    leftv at=v->LData();
     262    return atATTRIB1(res,at);
     263  }
     264  if (a!=NULL)                    a->Print();
     265  else  if(haveNoAttribute)       PrintS("no attributes\n");
    276266  return FALSE;
    277267}
    278 BOOLEAN atATTRIB2(leftv res,leftv a,leftv b)
     268BOOLEAN atATTRIB2(leftv res,leftv v,leftv b)
    279269{
    280270  char *name=(char *)b->Data();
    281271  int t;
    282   leftv v=a;
    283   if (a->e!=NULL)
    284   {
    285     v=a->LData();
    286     if (v==NULL) return TRUE;
    287   }
     272  leftv at=NULL;
     273  if (v->e!=NULL)
     274    at=v->LData();
    288275  if (strcmp(name,"isSB")==0)
    289276  {
    290277    res->rtyp=INT_CMD;
    291278    res->data=(void *)(long)hasFlag(v,FLAG_STD);
     279    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
    292280  }
    293281  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
     
    306294    res->rtyp=INT_CMD;
    307295    res->data=(void *)(long)hasFlag(v,FLAG_QRING);
     296    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
    308297  }
    309298#ifdef HAVE_SHIFTBBA
     
    317306  else
    318307  {
    319     attr at;
    320     if (v->rtyp==IDHDL)
    321       at=IDATTR((idhdl)v->data);
    322     else
    323       at=v->attribute;
    324     at=at->get(name);
    325     if (at!=NULL)
    326     {
    327       res->rtyp=at->atyp;
    328       res->data=at->CopyA();
     308    attr *aa=v->Attribute();
     309    if (aa==NULL)
     310    {
     311      WerrorS("this object cannot have attributes");
     312      return TRUE;
     313    }
     314    attr a=*aa;
     315    a=a->get(name);
     316    if (a!=NULL)
     317    {
     318      res->rtyp=a->atyp;
     319      res->data=a->CopyA();
    329320    }
    330321    else
     
    336327  return FALSE;
    337328}
    338 BOOLEAN atATTRIB3(leftv res,leftv a,leftv b,leftv c)
    339 {
    340   idhdl h=(idhdl)a->data;
     329BOOLEAN atATTRIB3(leftv res,leftv v,leftv b,leftv c)
     330{
     331  idhdl h=(idhdl)v->data;
    341332  int t;
    342   leftv v=a;
    343   if (a->e!=NULL)
    344   {
    345     v=a->LData();
     333  if (v->e!=NULL)
     334  {
     335    v=v->LData();
    346336    if (v==NULL) return TRUE;
    347337    h=NULL;
    348338  }
    349   if (a->rtyp!=IDHDL) h=NULL;
    350 
    351   attr *at=&(v->attribute);
    352   if (h!=NULL) at=&(IDATTR(h));
     339  else if (v->rtyp!=IDHDL) h=NULL;
     340
    353341  char *name=(char *)b->Data();
    354342  if (strcmp(name,"isSB")==0)
     
    428416BOOLEAN atKILLATTR1(leftv res,leftv a)
    429417{
     418  idhdl h=NULL;
     419  if ((a->rtyp==IDHDL)&&(a->e==NULL))
     420  {
     421    h=(idhdl)a->data;
     422    resetFlag((idhdl)a->data,FLAG_STD);
     423  }
     424  resetFlag(a,FLAG_STD);
     425  if (h->attribute!=NULL)
     426  {
     427    atKillAll(h);
     428    a->attribute=NULL;
     429  }
     430  else atKillAll(a);
     431  return FALSE;
     432}
     433BOOLEAN atKILLATTR2(leftv res,leftv a,leftv b)
     434{
    430435  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
    431436  {
     
    433438    return TRUE;
    434439  }
    435   resetFlag(a,FLAG_STD);
    436   resetFlag((idhdl)a->data,FLAG_STD);
    437   if (a->attribute!=NULL)
    438   {
    439     atKillAll((idhdl)a->data);
    440     a->attribute=NULL;
    441   }
    442   return FALSE;
    443 }
    444 BOOLEAN atKILLATTR2(leftv res,leftv a,leftv b)
    445 {
    446   if ((a->rtyp!=IDHDL)||(a->e!=NULL))
    447   {
    448     WerrorS("object must have a name");
    449     return TRUE;
    450   }
    451440  char *name=(char *)b->Data();
    452441  if (strcmp(name,"isSB")==0)
  • Singular/attrib.h

    re368746 rc227a2f  
    3939void atSet(leftv root,const char * name,void * data,int typ);
    4040void at_KillAll(idhdl root,const ring r);
     41void at_KillAll(leftv root,const ring r);
    4142#define atKillAll(H) at_KillAll(H,currRing)
    4243void at_Kill(idhdl root,const char * name,const ring r);
  • Singular/iparith.cc

    re368746 rc227a2f  
    30363036    assume( (r->orderedRes != NULL) || (r->res != NULL) ); // analog for hres...
    30373037
    3038  
    30393038  return FALSE;
    30403039}
     
    32643263  else /*IDEAL/MODULE*/
    32653264  {
     3265    attr *aa=u->Attribute();
    32663266    attr a=NULL;
    3267     if (u->attribute!=NULL) a=u->attribute->Copy();
     3267    if (aa!=NULL) a=(*aa)->Copy();
    32683268    jjSTD_1_ID(res,(ideal)u->CopyD(),r,(ideal)v->CopyD(),a);
    32693269  }
  • Singular/ipid.cc

    re368746 rc227a2f  
    372372  if (h->attribute!=NULL)
    373373  {
    374     h->attribute->killAll(r);
     374    //h->attribute->killAll(r); MEMORY LEAK!
    375375    h->attribute=NULL;
    376376  }
  • Singular/ipshell.cc

    re368746 rc227a2f  
    866866  l->m[0].rtyp=u->Typ();
    867867  l->m[0].data=u->Data();
    868   l->m[0].attribute=u->attribute;
     868  attr *a=u->Attribute();
     869  if (a!=NULL)
     870  l->m[0].attribute=*a;
    869871  sleftv tmp2;
    870872  memset(&tmp2,0,sizeof(tmp2));
  • Singular/lists.cc

    re368746 rc227a2f  
    9696  l->m[pos].data=v->CopyD();
    9797  l->m[pos].flag=v->flag;
    98   if (v->attribute!=NULL)
    99   {
    100     l->m[pos].attribute=v->attribute->Copy();
     98  attr *a=v->Attribute();
     99  if (a!=NULL)
     100  {
     101    l->m[pos].attribute=(*a)->Copy();
    101102  }
    102103  if (ul->m != NULL)
     
    167168      {
    168169        l->m[j]=ul->m[i];
    169         memset(&ul->m[i],0,sizeof(ul->m[i]));
     170        memset(&ul->m[i],0,sizeof(ul->m[i]));
    170171      }
    171172      else
  • Singular/subexpr.cc

    re368746 rc227a2f  
    324324      default:
    325325      {
    326         if (attribute!=NULL) attribute->killAll(r);
     326        attribute->killAll(r);
    327327      }
    328328    }
Note: See TracChangeset for help on using the changeset viewer.