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