source: git/Singular/attrib.cc @ 7f5789

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