source: git/Singular/attrib.cc

spielwiese
Last change on this file was c2b991, checked in by Hans Schoenemann <hannes@…>, 4 years ago
fix: attrib ncgenCount only for LP rings
  • Property mode set to 100644
File size: 10.3 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[74f19d]4
[0e1846]5/*
[e2f1c7]6* ABSTRACT: attributes to leftv and idhdl
[0e1846]7*/
8
[b5dd9b]9#include "kernel/mod2.h"
[fd1b1be]10
[b5dd9b]11#include "misc/options.h"
12#include "misc/intvec.h"
[fd1b1be]13
[b5dd9b]14#include "polys/matpol.h"
[fd1b1be]15
[b5dd9b]16#include "kernel/polys.h"
17#include "kernel/ideals.h"
[fd1b1be]18
[b5dd9b]19#include "Singular/tok.h"
20#include "Singular/ipid.h"
21#include "Singular/ipshell.h"
22#include "Singular/attrib.h"
[c232af]23
[a3f0fea]24STATIC_VAR omBin sattr_bin = omGetSpecBin(sizeof(sattr));
[0e1846]25
26void sattr::Print()
27{
[c232af]28  omCheckAddrSize(this,sizeof(sattr));
[0e1846]29  ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
30  if (next!=NULL) next->Print();
31}
32
33attr sattr::Copy()
34{
[bb2fb6]35  assume (this!=NULL);
36
37  omCheckAddrSize(this,sizeof(sattr));
38  attr n=(attr)omAlloc0Bin(sattr_bin);
39  n->atyp=atyp;
40  if (name!=NULL) n->name=omStrDup(name);
41  n->data=CopyA();
42  if (next!=NULL)
[c227a2f]43  {
[bb2fb6]44    n->next=next->Copy();
[75f460]45  }
[bb2fb6]46  return n;
[0e1846]47}
48
[f71681]49// in subexr.cc:
50//void * sattr::CopyA()
51//{
52//  omCheckAddrSize(this,sizeof(sattr));
53//  return s_internalCopy(atyp,data);
54//}
[0e1846]55
[3aa622a]56static void attr_free(attr h, const ring r=currRing)
57{
[0762d19]58  if (h->name!=NULL)
59  {
60    omFree(h->name);
61    h->name=NULL;
62  }
[bcb8f3]63  if (h->data!=NULL) /*avoid assume failure */
64  {
65    s_internalDelete(h->atyp,h->data,r);
66    h->data=NULL;
67  }
[3aa622a]68}
69
[f93ebb]70attr sattr::set(char * s, void * d, int t)
[0e1846]71{
72  attr h = get(s);
[3aa622a]73  attr result=this;
[0e1846]74  if (h!=NULL)
75  {
[3aa622a]76    attr_free(h);
[0e1846]77  }
78  else
79  {
[3aa622a]80    h = (attr)omAlloc0Bin(sattr_bin);
81    h->next = this;
82    result=h;
[0e1846]83  }
[3aa622a]84  h->name = s;
[5f4463]85  h->data = d;
[0e1846]86  h->atyp = t;
[35b6ca]87#ifdef TEST
[57c64ff]88  //::Print("set attr >>%s<< of type %s\n",h->name, Tok2Cmdname(t));
[35b6ca]89#endif
[3aa622a]90  return  result;
[0e1846]91}
92
[85e68dd]93attr sattr::get(const char * s)
[0e1846]94{
95  attr h = this;
96  while (h!=NULL)
97  {
[c227a2f]98    if (0 == strcmp(s,h->name))
99    {
[35b6ca]100#ifdef TEST
[57c64ff]101      //::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
[35b6ca]102#endif
103      return h;
104    }
[0e1846]105    h = h->next;
106  }
107  return NULL;
108}
109
[f4b7ce8]110#if 0
[85e68dd]111void * atGet(idhdl root,const char * name)
[0e1846]112{
113  attr temp = root->attribute->get(name);
114  if (temp!=NULL)
115    return temp->data;
116  else
117    return NULL;
118}
119
[85e68dd]120void * atGet(leftv root,const char * name)
[0e1846]121{
[71df1a]122  attr temp;
[c227a2f]123  attr a=*(root->Attribute());
124  temp = a->get(name);
[0e1846]125  if (temp!=NULL)
126    return temp->data;
127  else
128    return NULL;
129}
[f4b7ce8]130#endif
[0e1846]131
[599813]132void * atGet(idhdl root,const char * name, int t, void *defaultReturnValue)
[242d8f]133{
134  attr temp = root->attribute->get(name);
135  if ((temp!=NULL) && (temp->atyp==t))
136    return temp->data;
137  else
[599813]138    return defaultReturnValue;
[242d8f]139}
140
[85e68dd]141void * atGet(leftv root,const char * name, int t)
[242d8f]142{
[541bc12]143  attr *a=(root->Attribute());
144  if (a!=NULL)
145  {
146    attr temp = (*a)->get(name);
147    if ((temp!=NULL) && (temp->atyp==t))
148      return temp->data;
149  }
[8200469]150  return NULL;
[242d8f]151}
152
[f93ebb]153void atSet(idhdl root, char * name,void * data,int typ)
[0e1846]154{
155  if (root!=NULL)
156  {
[c4dab4]157    if ((IDTYP(root)!=RING_CMD)
158    && (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
159      WerrorS("cannot set ring-dependend objects at this type");
[c227a2f]160    else
[c4dab4]161      root->attribute=root->attribute->set(name,data,typ);
[0e1846]162  }
163}
164
[f93ebb]165void atSet(leftv root, char * name,void * data,int typ)
[0e1846]166{
167  if (root!=NULL)
168  {
[c227a2f]169    attr *a=root->Attribute();
170    int rt=root->Typ();
[c244a95]171    if (a==NULL)
172      WerrorS("cannot set attributes of this object");
173    else if ((rt!=RING_CMD)
[c227a2f]174    && (!RingDependend(rt))&&(RingDependend(typ)))
175      WerrorS("cannot set ring-dependend objects at this type");
[0e1846]176    else
177    {
[c227a2f]178      *a=(*a)->set(name,data,typ);
[0e1846]179    }
180  }
181}
182
[2dbaba4]183void sattr::kill(const ring r)
[0e1846]184{
[35b6ca]185  attr_free(this,r);
[c232af]186  omFreeBin((ADDRESS)this, sattr_bin);
[0e1846]187}
188
[2dbaba4]189void sattr::killAll(const ring r)
[0e1846]190{
191  attr temp = this,temp1;
192
193  while (temp!=NULL)
194  {
195    temp1 = temp->next;
[c4dab4]196    omCheckAddr(temp);
[2dbaba4]197    temp->kill(r);
[0e1846]198    temp = temp1;
199  }
200}
201
[2dbaba4]202void at_Kill(idhdl root,const char * name, const ring r)
[0e1846]203{
204  attr temp = root->attribute->get(name);
205  if (temp!=NULL)
206  {
207    attr N = temp->next;
208    attr temp1 = root->attribute;
209    if (temp1==temp)
210    {
211      root->attribute = N;
212    }
213    else
214    {
215      while (temp1->next!=temp) temp1 = temp1->next;
216      temp1->next = N;
217    }
[2dbaba4]218    temp->kill(r);
[0e1846]219  }
220}
221
[2dbaba4]222void at_KillAll(idhdl root, const ring r)
[0e1846]223{
[2dbaba4]224  root->attribute->killAll(r);
[0e1846]225  root->attribute = NULL;
226}
[f4b7ce8]227
[c227a2f]228void at_KillAll(leftv root, const ring r)
229{
230  root->attribute->killAll(r);
231  root->attribute = NULL;
232}
[0e1846]233
[c227a2f]234BOOLEAN atATTRIB1(leftv res,leftv v)
[0e1846]235{
[c227a2f]236  attr *aa=(v->Attribute());
237  if (aa==NULL)
[0e1846]238  {
[c227a2f]239    WerrorS("this object cannot have attributes");
240    return TRUE;
[6c22988]241  }
[c227a2f]242  attr a=*aa;
[3aa622a]243  BOOLEAN haveNoAttribute=TRUE;
[c227a2f]244  if (v->e==NULL)
[6c4db17]245  {
[c227a2f]246    if (hasFlag(v,FLAG_STD))
247    {
248      PrintS("attr:isSB, type int\n");
249      haveNoAttribute=FALSE;
250    }
251    if (hasFlag(v,FLAG_QRING))
252    {
253      PrintS("attr:qringNF, type int\n");
254      haveNoAttribute=FALSE;
255    }
[d2fc5c5]256    if (v->Typ()==RING_CMD)
[c227a2f]257    {
[7b347b2]258      PrintS("attr:cf_class, type int\n");
[c227a2f]259      PrintS("attr:global, type int\n");
[47c27b]260      PrintS("attr:maxExp, type int\n");
261      PrintS("attr:ring_cf, type int\n");
262      #ifdef HAVE_SHIFTBBA
[86abd82]263      PrintS("attr:isLetterplaceRing, type int\n");
[c2b991]264      if (rIsLPRing((ring)v->Data()))
265        PrintS("attr:ncgenCount, type int\n");
[47c27b]266      #endif
267
[c227a2f]268      haveNoAttribute=FALSE;
269    }
[6c4db17]270  }
[c227a2f]271  else
[242d8f]272  {
[c227a2f]273    leftv at=v->LData();
274    return atATTRIB1(res,at);
[0e1846]275  }
[c227a2f]276  if (a!=NULL)                    a->Print();
277  else  if(haveNoAttribute)       PrintS("no attributes\n");
[0e1846]278  return FALSE;
279}
[c227a2f]280BOOLEAN atATTRIB2(leftv res,leftv v,leftv b)
[0e1846]281{
282  char *name=(char *)b->Data();
[d2fc5c5]283  int t=v->Typ();
[c227a2f]284  leftv at=NULL;
285  if (v->e!=NULL)
286    at=v->LData();
[0e1846]287  if (strcmp(name,"isSB")==0)
288  {
289    res->rtyp=INT_CMD;
[09bbf5]290    res->data=(void *)(long)hasFlag(v,FLAG_STD);
[c227a2f]291    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
[0e1846]292  }
[d2fc5c5]293  else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
[0e1846]294  {
295    res->rtyp=INT_CMD;
296    res->data=(void *)(((ideal)v->Data())->rank);
297  }
[242d8f]298  else if ((strcmp(name,"global")==0)
[d2fc5c5]299  &&(/*v->Typ()*/t==RING_CMD))
[242d8f]300  {
301    res->rtyp=INT_CMD;
302    res->data=(void *)(((ring)v->Data())->OrdSgn==1);
303  }
[47c27b]304  else if ((strcmp(name,"maxExp")==0)
[d2fc5c5]305  &&(/*v->Typ()*/t==RING_CMD))
[47c27b]306  {
307    res->rtyp=INT_CMD;
[0362ae]308    res->data=(void *)(long)(((ring)v->Data())->bitmask);
[47c27b]309  }
[1433ab]310  else if ((strcmp(name,"ring_cf")==0)
[d2fc5c5]311  &&(/*v->Typ()*/t==RING_CMD))
[1433ab]312  {
313    res->rtyp=INT_CMD;
[4bb0d7]314    res->data=(void *)(long)(rField_is_Ring((ring)v->Data()));
[1433ab]315  }
[7b347b2]316  else if ((strcmp(name,"cf_class")==0)
[d2fc5c5]317  &&(/*v->Typ()*/t==RING_CMD))
[7b347b2]318  {
319    res->rtyp=INT_CMD;
320    coeffs cf;
321    if (t==RING_CMD) cf=((ring)v->Data())->cf;
322    else             cf=(coeffs)v->Data();
323    res->data=(void *)(long)(cf->type);
324  }
[6c4db17]325  else if (strcmp(name,"qringNF")==0)
326  {
327    res->rtyp=INT_CMD;
328    res->data=(void *)(long)hasFlag(v,FLAG_QRING);
[c227a2f]329    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
[6c4db17]330  }
[b27003e]331#ifdef HAVE_SHIFTBBA
[86abd82]332  else if ((strcmp(name,"isLetterplaceRing")==0)
[d2fc5c5]333  &&(/*v->Typ()*/t==RING_CMD))
[b27003e]334  {
335    res->rtyp=INT_CMD;
[3ea5d2f]336    res->data=(void *)(long)(((ring)v->Data())->isLPring);
[b27003e]337  }
[7f5789]338  else if ((strcmp(name,"ncgenCount")==0)
339  &&(/*v->Typ()*/t==RING_CMD))
340  {
341    res->rtyp=INT_CMD;
342    res->data=(void *)(long)(((ring)v->Data())->LPncGenCount);
343  }
[b27003e]344#endif
[0e1846]345  else
346  {
[c227a2f]347    attr *aa=v->Attribute();
348    if (aa==NULL)
349    {
350      WerrorS("this object cannot have attributes");
351      return TRUE;
352    }
353    attr a=*aa;
354    a=a->get(name);
355    if (a!=NULL)
[0e1846]356    {
[c227a2f]357      res->rtyp=a->atyp;
358      res->data=a->CopyA();
[0e1846]359    }
360    else
361    {
362      res->rtyp=STRING_CMD;
[c232af]363      res->data=omStrDup("");
[0e1846]364    }
365  }
366  return FALSE;
367}
[2e4ec14]368BOOLEAN atATTRIB3(leftv /*res*/,leftv v,leftv b,leftv c)
[0e1846]369{
[c227a2f]370  idhdl h=(idhdl)v->data;
371  if (v->e!=NULL)
[0e1846]372  {
[c227a2f]373    v=v->LData();
[0e1846]374    if (v==NULL) return TRUE;
375    h=NULL;
376  }
[c227a2f]377  else if (v->rtyp!=IDHDL) h=NULL;
[d2fc5c5]378  int t=v->Typ();
[6c22988]379
[0e1846]380  char *name=(char *)b->Data();
381  if (strcmp(name,"isSB")==0)
382  {
383    if (c->Typ()!=INT_CMD)
384    {
[b27003e]385      WerrorS("attribute isSB must be int");
[0e1846]386      return TRUE;
387    }
[7447d8]388    if (((long)c->Data())!=0L)
[0e1846]389    {
390      if (h!=NULL) setFlag(h,FLAG_STD);
391      setFlag(v,FLAG_STD);
392    }
393    else
394    {
395      if (h!=NULL) resetFlag(h,FLAG_STD);
396      resetFlag(v,FLAG_STD);
397    }
398  }
[6c4db17]399  else if (strcmp(name,"qringNF")==0)
400  {
401    if (c->Typ()!=INT_CMD)
402    {
403      WerrorS("attribute qringNF must be int");
404      return TRUE;
405    }
406    if (((long)c->Data())!=0L)
407    {
408      if (h!=NULL) setFlag(h,FLAG_QRING);
409      setFlag(v,FLAG_QRING);
410    }
411    else
412    {
413      if (h!=NULL) resetFlag(h,FLAG_QRING);
414      resetFlag(v,FLAG_QRING);
415    }
416  }
[d2fc5c5]417  else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
[0e1846]418  {
419    if (c->Typ()!=INT_CMD)
420    {
[b27003e]421      WerrorS("attribute `rank` must be int");
[0e1846]422      return TRUE;
423    }
424    ideal I=(ideal)v->Data();
[eeff3a]425    int rk=id_RankFreeModule(I,currRing);
426    I->rank=si_max(rk,(int)((long)c->Data()));
[0e1846]427  }
[47c27b]428  else if (((strcmp(name,"global")==0)
[7b347b2]429    || (strcmp(name,"cf_class")==0)
[47c27b]430    || (strcmp(name,"ring_cf")==0)
431    || (strcmp(name,"maxExp")==0))
[d2fc5c5]432  &&(/*v->Typ()*/t==RING_CMD))
[242d8f]433  {
[47c27b]434    Werror("can not set attribute `%s`",name);
[242d8f]435    return TRUE;
436  }
[b27003e]437#ifdef HAVE_SHIFTBBA
[86abd82]438  else if ((strcmp(name,"isLetterplaceRing")==0)
[d2fc5c5]439  &&(/*v->Typ()*/t==RING_CMD))
[b27003e]440  {
441    if (c->Typ()==INT_CMD)
442      ((ring)v->Data())->isLPring=(int)(long)c->Data();
443    else
444    {
[86abd82]445      WerrorS("attribute `isLetterplaceRing` must be int");
[7f5789]446      return TRUE;
447    }
448  }
449  else if ((strcmp(name,"ncgenCount")==0)
450  &&(/*v->Typ()*/t==RING_CMD))
451  {
452    if (c->Typ()==INT_CMD)
453      ((ring)v->Data())->LPncGenCount=(int)(long)c->Data();
454    else
455    {
456      WerrorS("attribute `ncgenCount` must be int");
[b27003e]457      return TRUE;
458    }
459  }
460#endif
[0e1846]461  else
462  {
[2166ad3]463    int typ=c->Typ();
[6c22988]464    if (h!=NULL) atSet(h,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
465    else         atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
[0e1846]466  }
467  return FALSE;
468}
469
[2e4ec14]470BOOLEAN atKILLATTR1(leftv /*res*/,leftv a)
[0e1846]471{
[c227a2f]472  idhdl h=NULL;
473  if ((a->rtyp==IDHDL)&&(a->e==NULL))
[0e1846]474  {
[c227a2f]475    h=(idhdl)a->data;
476    resetFlag((idhdl)a->data,FLAG_STD);
[0e1846]477  }
478  resetFlag(a,FLAG_STD);
[c227a2f]479  if (h->attribute!=NULL)
[0e1846]480  {
[c227a2f]481    atKillAll(h);
[0e1846]482    a->attribute=NULL;
483  }
[c227a2f]484  else atKillAll(a);
[0e1846]485  return FALSE;
486}
[2e4ec14]487BOOLEAN atKILLATTR2(leftv /*res*/,leftv a,leftv b)
[0e1846]488{
489  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
490  {
[da97958]491    WerrorS("object must have a name");
[0e1846]492    return TRUE;
493  }
494  char *name=(char *)b->Data();
495  if (strcmp(name,"isSB")==0)
496  {
497    resetFlag(a,FLAG_STD);
498    resetFlag((idhdl)a->data,FLAG_STD);
499  }
[242d8f]500  else if (strcmp(name,"global")==0)
501  {
502    WerrorS("can not set attribut `global`");
503    return TRUE;
504  }
[0e1846]505  else
506  {
507    atKill((idhdl)a->data,name);
508  }
509  return FALSE;
510}
[3aa622a]511
Note: See TracBrowser for help on using the repository browser.