attrib.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 /*
6 * ABSTRACT: attributes to leftv and idhdl
7 */
8 
9 #include <kernel/mod2.h>
10 
11 #include <omalloc/omalloc.h>
12 
13 #include <misc/options.h>
14 #include <misc/intvec.h>
15 
16 #include <polys/matpol.h>
17 
18 #include <kernel/polys.h>
19 #include <kernel/ideals.h>
20 
21 #include <Singular/tok.h>
22 #include <Singular/ipid.h>
23 #include <Singular/ipshell.h>
24 #include <Singular/attrib.h>
25 
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <unistd.h>
31 
32 static omBin sattr_bin = omGetSpecBin(sizeof(sattr));
33 
35 {
36  omCheckAddrSize(this,sizeof(sattr));
37  ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
38  if (next!=NULL) next->Print();
39 }
40 
42 {
43  assume (this!=NULL);
44 
45  omCheckAddrSize(this,sizeof(sattr));
47  n->atyp=atyp;
48  if (name!=NULL) n->name=omStrDup(name);
49  n->data=CopyA();
50  if (next!=NULL)
51  {
52  n->next=next->Copy();
53  }
54  return n;
55 }
56 
57 // in subexr.cc:
58 //void * sattr::CopyA()
59 //{
60 // omCheckAddrSize(this,sizeof(sattr));
61 // return s_internalCopy(atyp,data);
62 //}
63 
64 static void attr_free(attr h, const ring r=currRing)
65 {
66  if (h->data!=NULL) /*avoid assume failure */
67  {
68  s_internalDelete(h->atyp,h->data,r);
69  h->data=NULL;
70  }
71 }
72 
73 attr sattr::set(const char * s, void * d, int t)
74 {
75  attr h = get(s);
76  attr result=this;
77  if (h!=NULL)
78  {
79  attr_free(h);
80  }
81  else
82  {
84  h->next = this;
85  result=h;
86  }
87  h->name = s;
88  h->data = d;
89  h->atyp = t;
90 #ifdef TEST
91  //::Print("set attr >>%s<< of type %s\n",h->name, Tok2Cmdname(t));
92 #endif
93  return result;
94 }
95 
96 attr sattr::get(const char * s)
97 {
98  attr h = this;
99  while (h!=NULL)
100  {
101  if (0 == strcmp(s,h->name))
102  {
103 #ifdef TEST
104  //::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
105 #endif
106  return h;
107  }
108  h = h->next;
109  }
110  return NULL;
111 }
112 
113 #if 0
114 void * atGet(idhdl root,const char * name)
115 {
116  attr temp = root->attribute->get(name);
117  if (temp!=NULL)
118  return temp->data;
119  else
120  return NULL;
121 }
122 
123 void * atGet(leftv root,const char * name)
124 {
125  attr temp;
126  attr a=*(root->Attribute());
127  temp = a->get(name);
128  if (temp!=NULL)
129  return temp->data;
130  else
131  return NULL;
132 }
133 #endif
134 
135 void * atGet(idhdl root,const char * name, int t, void *defaultReturnValue)
136 {
137  attr temp = root->attribute->get(name);
138  if ((temp!=NULL) && (temp->atyp==t))
139  return temp->data;
140  else
141  return defaultReturnValue;
142 }
143 
144 void * atGet(leftv root,const char * name, int t)
145 {
146  attr *a=(root->Attribute());
147  if (a!=NULL)
148  {
149  attr temp = (*a)->get(name);
150  if ((temp!=NULL) && (temp->atyp==t))
151  return temp->data;
152  }
153  return NULL;
154 }
155 
156 void atSet(idhdl root,const char * name,void * data,int typ)
157 {
158  if (root!=NULL)
159  {
160  if ((IDTYP(root)!=RING_CMD)
161  && (IDTYP(root)!=QRING_CMD)
162  && (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
163  WerrorS("cannot set ring-dependend objects at this type");
164  else
165  root->attribute=root->attribute->set(name,data,typ);
166  }
167 }
168 
169 void atSet(leftv root,const char * name,void * data,int typ)
170 {
171  if (root!=NULL)
172  {
173  attr *a=root->Attribute();
174  int rt=root->Typ();
175  if (a==NULL)
176  WerrorS("cannot set attributes of this object");
177  else if ((rt!=RING_CMD)
178  && (rt!=QRING_CMD)
179  && (!RingDependend(rt))&&(RingDependend(typ)))
180  WerrorS("cannot set ring-dependend objects at this type");
181  else
182  {
183  *a=(*a)->set(name,data,typ);
184  }
185  }
186 }
187 
188 void sattr::kill(const ring r)
189 {
190  attr_free(this,r);
191  omFree((ADDRESS)name);
192  name=NULL;
193  omFreeBin((ADDRESS)this, sattr_bin);
194 }
195 
196 void sattr::killAll(const ring r)
197 {
198  attr temp = this,temp1;
199 
200  while (temp!=NULL)
201  {
202  temp1 = temp->next;
203  omCheckAddr(temp);
204  temp->kill(r);
205  temp = temp1;
206  }
207 }
208 
209 void at_Kill(idhdl root,const char * name, const ring r)
210 {
211  attr temp = root->attribute->get(name);
212  if (temp!=NULL)
213  {
214  attr N = temp->next;
215  attr temp1 = root->attribute;
216  if (temp1==temp)
217  {
218  root->attribute = N;
219  }
220  else
221  {
222  while (temp1->next!=temp) temp1 = temp1->next;
223  temp1->next = N;
224  }
225  temp->kill(r);
226  }
227 }
228 
229 void at_KillAll(idhdl root, const ring r)
230 {
231  root->attribute->killAll(r);
232  root->attribute = NULL;
233 }
234 
235 void at_KillAll(leftv root, const ring r)
236 {
237  root->attribute->killAll(r);
238  root->attribute = NULL;
239 }
240 
242 {
243  int t;
244  attr *aa=(v->Attribute());
245  if (aa==NULL)
246  {
247  WerrorS("this object cannot have attributes");
248  return TRUE;
249  }
250  attr a=*aa;
251  BOOLEAN haveNoAttribute=TRUE;
252  if (v->e==NULL)
253  {
254  if (hasFlag(v,FLAG_STD))
255  {
256  PrintS("attr:isSB, type int\n");
257  haveNoAttribute=FALSE;
258  }
259  if (hasFlag(v,FLAG_QRING))
260  {
261  PrintS("attr:qringNF, type int\n");
262  haveNoAttribute=FALSE;
263  }
264  if (((t=v->Typ())==RING_CMD)||(t==QRING_CMD))
265  {
266  PrintS("attr:global, type int\n");
267  PrintS("attr:maxExp, type int\n");
268  PrintS("attr:ring_cf, type int\n");
269  #ifdef HAVE_SHIFTBBA
270  PrintS("attr:isLPring, type int\n");
271  #endif
272 
273  haveNoAttribute=FALSE;
274  }
275  }
276  else
277  {
278  leftv at=v->LData();
279  return atATTRIB1(res,at);
280  }
281  if (a!=NULL) a->Print();
282  else if(haveNoAttribute) PrintS("no attributes\n");
283  return FALSE;
284 }
286 {
287  char *name=(char *)b->Data();
288  int t;
289  leftv at=NULL;
290  if (v->e!=NULL)
291  at=v->LData();
292  if (strcmp(name,"isSB")==0)
293  {
294  res->rtyp=INT_CMD;
295  res->data=(void *)(long)hasFlag(v,FLAG_STD);
296  if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
297  }
298  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
299  {
300  res->rtyp=INT_CMD;
301  res->data=(void *)(((ideal)v->Data())->rank);
302  }
303  else if ((strcmp(name,"global")==0)
304  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
305  {
306  res->rtyp=INT_CMD;
307  res->data=(void *)(((ring)v->Data())->OrdSgn==1);
308  }
309  else if ((strcmp(name,"maxExp")==0)
310  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
311  {
312  res->rtyp=INT_CMD;
313  res->data=(void *)(long)(((ring)v->Data())->bitmask/2);
314  }
315  else if ((strcmp(name,"ring_cf")==0)
316  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
317  {
318  res->rtyp=INT_CMD;
319  res->data=(void *)(long)(rField_is_Ring((ring)v->Data()));
320  }
321  else if (strcmp(name,"qringNF")==0)
322  {
323  res->rtyp=INT_CMD;
324  res->data=(void *)(long)hasFlag(v,FLAG_QRING);
325  if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
326  }
327 #ifdef HAVE_SHIFTBBA
328  else if ((strcmp(name,"isLPring")==0)
329  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
330  {
331  res->rtyp=INT_CMD;
332  res->data=(void *)(long)(((ring)v->Data())->isLPring);
333  }
334 #endif
335  else
336  {
337  attr *aa=v->Attribute();
338  if (aa==NULL)
339  {
340  WerrorS("this object cannot have attributes");
341  return TRUE;
342  }
343  attr a=*aa;
344  a=a->get(name);
345  if (a!=NULL)
346  {
347  res->rtyp=a->atyp;
348  res->data=a->CopyA();
349  }
350  else
351  {
352  res->rtyp=STRING_CMD;
353  res->data=omStrDup("");
354  }
355  }
356  return FALSE;
357 }
359 {
360  idhdl h=(idhdl)v->data;
361  int t;
362  if (v->e!=NULL)
363  {
364  v=v->LData();
365  if (v==NULL) return TRUE;
366  h=NULL;
367  }
368  else if (v->rtyp!=IDHDL) h=NULL;
369 
370  char *name=(char *)b->Data();
371  if (strcmp(name,"isSB")==0)
372  {
373  if (c->Typ()!=INT_CMD)
374  {
375  WerrorS("attribute isSB must be int");
376  return TRUE;
377  }
378  if (((long)c->Data())!=0L)
379  {
380  if (h!=NULL) setFlag(h,FLAG_STD);
381  setFlag(v,FLAG_STD);
382  }
383  else
384  {
385  if (h!=NULL) resetFlag(h,FLAG_STD);
386  resetFlag(v,FLAG_STD);
387  }
388  }
389  else if (strcmp(name,"qringNF")==0)
390  {
391  if (c->Typ()!=INT_CMD)
392  {
393  WerrorS("attribute qringNF must be int");
394  return TRUE;
395  }
396  if (((long)c->Data())!=0L)
397  {
398  if (h!=NULL) setFlag(h,FLAG_QRING);
399  setFlag(v,FLAG_QRING);
400  }
401  else
402  {
403  if (h!=NULL) resetFlag(h,FLAG_QRING);
405  }
406  }
407  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
408  {
409  if (c->Typ()!=INT_CMD)
410  {
411  WerrorS("attribute `rank` must be int");
412  return TRUE;
413  }
414  ideal I=(ideal)v->Data();
415  int rk=id_RankFreeModule(I,currRing);
416  I->rank=si_max(rk,(int)((long)c->Data()));
417  }
418  else if (((strcmp(name,"global")==0)
419  || (strcmp(name,"ring_cf")==0)
420  || (strcmp(name,"maxExp")==0))
421  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
422  {
423  Werror("can not set attribute `%s`",name);
424  return TRUE;
425  }
426 #ifdef HAVE_SHIFTBBA
427  else if ((strcmp(name,"isLPring")==0)
428  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
429  {
430  if (c->Typ()==INT_CMD)
431  ((ring)v->Data())->isLPring=(int)(long)c->Data();
432  else
433  {
434  WerrorS("attribute `isLPring` must be int");
435  return TRUE;
436  }
437  }
438 #endif
439  else
440  {
441  int typ=c->Typ();
442  if (h!=NULL) atSet(h,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
443  else atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
444  }
445  return FALSE;
446 }
447 
449 {
450  idhdl h=NULL;
451  if ((a->rtyp==IDHDL)&&(a->e==NULL))
452  {
453  h=(idhdl)a->data;
455  }
456  resetFlag(a,FLAG_STD);
457  if (h->attribute!=NULL)
458  {
459  atKillAll(h);
460  a->attribute=NULL;
461  }
462  else atKillAll(a);
463  return FALSE;
464 }
466 {
467  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
468  {
469  WerrorS("object must have a name");
470  return TRUE;
471  }
472  char *name=(char *)b->Data();
473  if (strcmp(name,"isSB")==0)
474  {
475  resetFlag(a,FLAG_STD);
477  }
478  else if (strcmp(name,"global")==0)
479  {
480  WerrorS("can not set attribut `global`");
481  return TRUE;
482  }
483  else
484  {
485  atKill((idhdl)a->data,name);
486  }
487  return FALSE;
488 }
489 
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
void atSet(idhdl root, const char *name, void *data, int typ)
Definition: attrib.cc:156
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
const poly a
Definition: syzextra.cc:212
omBin_t * omBin
Definition: omStructs.h:12
Definition: tok.h:98
void killAll(const ring r)
Definition: attrib.cc:196
attr set(const char *s, void *data, int t)
Definition: attrib.cc:73
Definition: attrib.h:15
void Print()
Definition: attrib.cc:34
Subexpr e
Definition: subexpr.h:106
if(0 > strat->sl)
Definition: myNF.cc:73
#define FALSE
Definition: auxiliary.h:140
Compatiblity layer for legacy polynomial operations (over currRing)
attr * Attribute()
Definition: subexpr.cc:1373
void * data
Definition: attrib.h:20
void at_KillAll(idhdl root, const ring r)
Definition: attrib.cc:229
#define TRUE
Definition: auxiliary.h:144
void * ADDRESS
Definition: auxiliary.h:161
void WerrorS(const char *s)
Definition: feFopen.cc:24
BOOLEAN atKILLATTR2(leftv, leftv a, leftv b)
Definition: attrib.cc:465
BOOLEAN atKILLATTR1(leftv, leftv a)
Definition: attrib.cc:448
int Typ()
Definition: subexpr.cc:976
void kill(const ring r)
Definition: attrib.cc:188
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:35
BOOLEAN atATTRIB2(leftv res, leftv v, leftv b)
Definition: attrib.cc:285
void at_Kill(idhdl root, const char *name, const ring r)
Definition: attrib.cc:209
void * data
Definition: subexpr.h:89
poly res
Definition: myNF.cc:322
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
#define IDTYP(a)
Definition: ipid.h:118
void * CopyA()
Definition: subexpr.cc:1938
sattr * attr
Definition: attrib.h:13
int RingDependend(int t)
Definition: gentable.cc:23
const ring r
Definition: syzextra.cc:208
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
BOOLEAN atATTRIB3(leftv, leftv v, leftv b, leftv c)
Definition: attrib.cc:358
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:405
void s_internalDelete(const int t, void *d, const ring r)
Definition: subexpr.cc:478
#define setFlag(A, F)
Definition: ipid.h:112
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
idrec * idhdl
Definition: ring.h:18
#define FLAG_QRING
Definition: ipid.h:110
void PrintS(const char *s)
Definition: reporter.cc:294
#define atKill(H, A)
Definition: attrib.h:44
#define FLAG_STD
Definition: ipid.h:108
BOOLEAN atATTRIB1(leftv res, leftv v)
Definition: attrib.cc:241
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define omGetSpecBin(size)
Definition: omBin.h:11
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define atKillAll(H)
Definition: attrib.h:42
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition: attrib.cc:135
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:434
#define NULL
Definition: omList.c:10
attr attribute
Definition: idrec.h:41
static omBin sattr_bin
Definition: attrib.cc:32
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
#define hasFlag(A, F)
Definition: ipid.h:111
attr next
Definition: attrib.h:21
int rtyp
Definition: subexpr.h:92
void * Data()
Definition: subexpr.cc:1118
attr Copy()
Definition: attrib.cc:41
attr attribute
Definition: subexpr.h:90
const char * name
Definition: attrib.h:19
attr get(const char *s)
Definition: attrib.cc:96
Definition: tok.h:159
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
#define resetFlag(A, F)
Definition: ipid.h:113
static void attr_free(attr h, const ring r=currRing)
Definition: attrib.cc:64
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:131
const poly b
Definition: syzextra.cc:213
leftv LData()
Definition: subexpr.cc:1387
void Werror(const char *fmt,...)
Definition: reporter.cc:199
void * CopyD(int t)
Definition: subexpr.cc:676
int atyp
Definition: attrib.h:22
return result
Definition: facAbsBiFact.cc:76
#define omStrDup(s)
Definition: omAllocDecl.h:263