My Project
Loading...
Searching...
No Matches
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 "misc/options.h"
12#include "misc/intvec.h"
13
14#include "polys/matpol.h"
15
16#include "kernel/polys.h"
17#include "kernel/ideals.h"
18
19#include "Singular/tok.h"
20#include "Singular/ipid.h"
21#include "Singular/ipshell.h"
22#include "Singular/attrib.h"
23
25
27{
28 omCheckAddrSize(this,sizeof(sattr));
29 ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
30 if (next!=NULL) next->Print();
31}
32
34{
35 assume (this!=NULL);
36
37 omCheckAddrSize(this,sizeof(sattr));
39 n->atyp=atyp;
40 if (name!=NULL) n->name=omStrDup(name);
41 n->data=CopyA();
42 if (next!=NULL)
43 {
44 n->next=next->Copy();
45 }
46 return n;
47}
48
49// in subexr.cc:
50//void * sattr::CopyA()
51//{
52// omCheckAddrSize(this,sizeof(sattr));
53// return s_internalCopy(atyp,data);
54//}
55
56static void attr_free(attr h, const ring r=currRing)
57{
58 if (h->name!=NULL)
59 {
60 omFree(h->name);
61 h->name=NULL;
62 }
63 if (h->data!=NULL) /*avoid assume failure */
64 {
65 s_internalDelete(h->atyp,h->data,r);
66 h->data=NULL;
67 }
68}
69
70attr sattr::set(char * s, void * d, int t)
71{
72 attr h = get(s);
73 attr result=this;
74 if (h!=NULL)
75 {
76 attr_free(h);
77 }
78 else
79 {
81 h->next = this;
82 result=h;
83 }
84 h->name = s;
85 h->data = d;
86 h->atyp = t;
87#ifdef TEST
88 //::Print("set attr >>%s<< of type %s\n",h->name, Tok2Cmdname(t));
89#endif
90 return result;
91}
92
93attr sattr::get(const char * s)
94{
95 attr h = this;
96 while (h!=NULL)
97 {
98 if (0 == strcmp(s,h->name))
99 {
100#ifdef TEST
101 //::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
102#endif
103 return h;
104 }
105 h = h->next;
106 }
107 return NULL;
108}
109
110#if 0
111void * atGet(idhdl root,const char * name)
112{
113 attr temp = root->attribute->get(name);
114 if (temp!=NULL)
115 return temp->data;
116 else
117 return NULL;
118}
119
120void * atGet(leftv root,const char * name)
121{
122 attr temp;
123 attr a=*(root->Attribute());
124 temp = a->get(name);
125 if (temp!=NULL)
126 return temp->data;
127 else
128 return NULL;
129}
130#endif
131
132void * atGet(idhdl root,const char * name, int t, void *defaultReturnValue)
133{
134 attr temp = root->attribute->get(name);
135 if ((temp!=NULL) && (temp->atyp==t))
136 return temp->data;
137 else
138 return defaultReturnValue;
139}
140
141void * atGet(leftv root,const char * name, int t)
142{
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 }
150 return NULL;
151}
152
153void atSet(idhdl root, char * name,void * data,int typ)
154{
155 if (root!=NULL)
156 {
157 if ((IDTYP(root)!=RING_CMD)
158 && (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
159 WerrorS("cannot set ring-dependend objects at this type");
160 else
161 root->attribute=root->attribute->set(name,data,typ);
162 }
163}
164
165void atSet(leftv root, char * name,void * data,int typ)
166{
167 if (root!=NULL)
168 {
169 attr *a=root->Attribute();
170 int rt=root->Typ();
171 if (a==NULL)
172 WerrorS("cannot set attributes of this object");
173 else if ((rt!=RING_CMD)
174 && (!RingDependend(rt))&&(RingDependend(typ)))
175 WerrorS("cannot set ring-dependend objects at this type");
176 else
177 {
178 *a=(*a)->set(name,data,typ);
179 }
180 }
181}
182
183void sattr::kill(const ring r)
184{
185 attr_free(this,r);
187}
188
189void sattr::killAll(const ring r)
190{
191 attr temp = this,temp1;
192
193 while (temp!=NULL)
194 {
195 temp1 = temp->next;
196 omCheckAddr(temp);
197 temp->kill(r);
198 temp = temp1;
199 }
200}
201
202void at_Kill(idhdl root,const char * name, const ring r)
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 }
218 temp->kill(r);
219 }
220}
221
222void at_KillAll(idhdl root, const ring r)
223{
224 root->attribute->killAll(r);
225 root->attribute = NULL;
226}
227
228void at_KillAll(leftv root, const ring r)
229{
230 root->attribute->killAll(r);
231 root->attribute = NULL;
232}
233
235{
236 attr *aa=(v->Attribute());
237 if (aa==NULL)
238 {
239 WerrorS("this object cannot have attributes");
240 return TRUE;
241 }
242 attr a=*aa;
243 BOOLEAN haveNoAttribute=TRUE;
244 if (v->e==NULL)
245 {
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 }
256 if (v->Typ()==RING_CMD)
257 {
258 PrintS("attr:cf_class, type int\n");
259 PrintS("attr:cf_class_Zp, type int\n");
260 PrintS("attr:cf_class_QQ, type int\n");
261 PrintS("attr:global, type int\n");
262 PrintS("attr:maxExp, type int\n");
263 PrintS("attr:ring_cf, type int\n");
264 #ifdef HAVE_SHIFTBBA
265 PrintS("attr:isLetterplaceRing, type int\n");
266 if (rIsLPRing((ring)v->Data()))
267 PrintS("attr:ncgenCount, type int\n");
268 #endif
269
270 haveNoAttribute=FALSE;
271 }
272 }
273 else
274 {
275 leftv at=v->LData();
276 return atATTRIB1(res,at);
277 }
278 if (a!=NULL) a->Print();
279 else if(haveNoAttribute) PrintS("no attributes\n");
280 return FALSE;
281}
283{
284 char *name=(char *)b->Data();
285 int t=v->Typ();
286 leftv at=NULL;
287 if (v->e!=NULL)
288 at=v->LData();
289 if (strcmp(name,"isSB")==0)
290 {
291 res->rtyp=INT_CMD;
292 res->data=(void *)(long)hasFlag(v,FLAG_STD);
293 if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
294 }
295 else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
296 {
297 res->rtyp=INT_CMD;
298 res->data=(void *)(((ideal)v->Data())->rank);
299 }
300 else if ((strcmp(name,"global")==0)
301 &&(/*v->Typ()*/t==RING_CMD))
302 {
303 res->rtyp=INT_CMD;
304 res->data=(void *)(((ring)v->Data())->OrdSgn==1);
305 }
306 else if ((strcmp(name,"maxExp")==0)
307 &&(/*v->Typ()*/t==RING_CMD))
308 {
309 res->rtyp=INT_CMD;
310 res->data=(void *)(long)(((ring)v->Data())->bitmask);
311 }
312 else if ((strcmp(name,"ring_cf")==0)
313 &&(/*v->Typ()*/t==RING_CMD))
314 {
315 res->rtyp=INT_CMD;
316 res->data=(void *)(long)(rField_is_Ring((ring)v->Data()));
317 }
318 else if ((strncmp(name,"cf_class",strlen("cf_class"))==0)
319 &&(/*v->Typ()*/t==RING_CMD))
320 {
321 res->rtyp=INT_CMD;
322 coeffs cf;
323 cf=((ring)v->Data())->cf;
324 if (strcmp(name,"cf_class_Zp")==0)
325 res->data=(void *)(long)(int)(cf->type==n_Zp);
326 else if (strcmp(name,"cf_class_QQ")==0)
327 res->data=(void *)(long)(int)(cf->type==n_Q);
328 else
329 res->data=(void *)(long)(int)cf->type;
330 }
331 else if (strcmp(name,"qringNF")==0)
332 {
333 res->rtyp=INT_CMD;
334 res->data=(void *)(long)hasFlag(v,FLAG_QRING);
335 if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
336 }
337#ifdef HAVE_SHIFTBBA
338 else if ((strcmp(name,"isLetterplaceRing")==0)
339 &&(/*v->Typ()*/t==RING_CMD))
340 {
341 res->rtyp=INT_CMD;
342 res->data=(void *)(long)(((ring)v->Data())->isLPring);
343 }
344 else if ((strcmp(name,"ncgenCount")==0)
345 &&(/*v->Typ()*/t==RING_CMD))
346 {
347 res->rtyp=INT_CMD;
348 res->data=(void *)(long)(((ring)v->Data())->LPncGenCount);
349 }
350#endif
351 else
352 {
353 attr *aa=v->Attribute();
354 if (aa==NULL)
355 {
356 WerrorS("this object cannot have attributes");
357 return TRUE;
358 }
359 attr a=*aa;
360 a=a->get(name);
361 if (a!=NULL)
362 {
363 res->rtyp=a->atyp;
364 res->data=a->CopyA();
365 }
366 else
367 {
368 res->rtyp=STRING_CMD;
369 res->data=omStrDup("");
370 }
371 }
372 return FALSE;
373}
375{
376 idhdl h=(idhdl)v->data;
377 if (v->e!=NULL)
378 {
379 v=v->LData();
380 if (v==NULL) return TRUE;
381 h=NULL;
382 }
383 else if (v->rtyp!=IDHDL) h=NULL;
384 int t=v->Typ();
385
386 char *name=(char *)b->Data();
387 if (strcmp(name,"isSB")==0)
388 {
389 if (c->Typ()!=INT_CMD)
390 {
391 WerrorS("attribute isSB must be int");
392 return TRUE;
393 }
394 if (((long)c->Data())!=0L)
395 {
396 if (h!=NULL) setFlag(h,FLAG_STD);
398 }
399 else
400 {
401 if (h!=NULL) resetFlag(h,FLAG_STD);
403 }
404 }
405 else if (strcmp(name,"qringNF")==0)
406 {
407 if (c->Typ()!=INT_CMD)
408 {
409 WerrorS("attribute qringNF must be int");
410 return TRUE;
411 }
412 if (((long)c->Data())!=0L)
413 {
414 if (h!=NULL) setFlag(h,FLAG_QRING);
416 }
417 else
418 {
419 if (h!=NULL) resetFlag(h,FLAG_QRING);
421 }
422 }
423 else if ((strcmp(name,"rank")==0)&&(/*v->Typ()*/t==MODUL_CMD))
424 {
425 if (c->Typ()!=INT_CMD)
426 {
427 WerrorS("attribute `rank` must be int");
428 return TRUE;
429 }
430 ideal I=(ideal)v->Data();
431 int rk=id_RankFreeModule(I,currRing);
432 I->rank=si_max(rk,(int)((long)c->Data()));
433 }
434 else if (((strcmp(name,"global")==0)
435 || (strncmp(name,"cf_class",strlen("cf_class"))==0)
436 || (strcmp(name,"ring_cf")==0)
437 || (strcmp(name,"maxExp")==0))
438 &&(/*v->Typ()*/t==RING_CMD))
439 {
440 Werror("can not set attribute `%s`",name);
441 return TRUE;
442 }
443#ifdef HAVE_SHIFTBBA
444 else if ((strcmp(name,"isLetterplaceRing")==0)
445 &&(/*v->Typ()*/t==RING_CMD))
446 {
447 if (c->Typ()==INT_CMD)
448 ((ring)v->Data())->isLPring=(int)(long)c->Data();
449 else
450 {
451 WerrorS("attribute `isLetterplaceRing` must be int");
452 return TRUE;
453 }
454 }
455 else if ((strcmp(name,"ncgenCount")==0)
456 &&(/*v->Typ()*/t==RING_CMD))
457 {
458 if (c->Typ()==INT_CMD)
459 ((ring)v->Data())->LPncGenCount=(int)(long)c->Data();
460 else
461 {
462 WerrorS("attribute `ncgenCount` must be int");
463 return TRUE;
464 }
465 }
466#endif
467 else
468 {
469 int typ=c->Typ();
470 if (h!=NULL) atSet(h,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
471 else atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
472 }
473 return FALSE;
474}
475
477{
478 idhdl h=NULL;
479 if ((a->rtyp==IDHDL)&&(a->e==NULL))
480 {
481 h=(idhdl)a->data;
483 }
485 if (h->attribute!=NULL)
486 {
487 atKillAll(h);
488 a->attribute=NULL;
489 }
490 else atKillAll(a);
491 return FALSE;
492}
494{
495 if ((a->rtyp!=IDHDL)||(a->e!=NULL))
496 {
497 WerrorS("object must have a name");
498 return TRUE;
499 }
500 char *name=(char *)b->Data();
501 if (strcmp(name,"isSB")==0)
502 {
505 }
506 else if (strcmp(name,"global")==0)
507 {
508 WerrorS("can not set attribut `global`");
509 return TRUE;
510 }
511 else
512 {
513 atKill((idhdl)a->data,name);
514 }
515 return FALSE;
516}
517
BOOLEAN atATTRIB3(leftv, leftv v, leftv b, leftv c)
Definition attrib.cc:374
STATIC_VAR omBin sattr_bin
Definition attrib.cc:24
BOOLEAN atKILLATTR2(leftv, leftv a, leftv b)
Definition attrib.cc:493
BOOLEAN atKILLATTR1(leftv, leftv a)
Definition attrib.cc:476
void at_KillAll(idhdl root, const ring r)
Definition attrib.cc:222
void at_Kill(idhdl root, const char *name, const ring r)
Definition attrib.cc:202
void atSet(idhdl root, char *name, void *data, int typ)
Definition attrib.cc:153
static void attr_free(attr h, const ring r=currRing)
Definition attrib.cc:56
BOOLEAN atATTRIB2(leftv res, leftv v, leftv b)
Definition attrib.cc:282
void * atGet(idhdl root, const char *name, int t, void *defaultReturnValue)
Definition attrib.cc:132
BOOLEAN atATTRIB1(leftv res, leftv v)
Definition attrib.cc:234
sattr * attr
Definition attrib.h:16
#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:125
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void * ADDRESS
Definition auxiliary.h:120
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
CanonicalForm cf
Definition cfModGcd.cc:4091
CanonicalForm b
Definition cfModGcd.cc:4111
attr attribute
Definition idrec.h:41
Definition attrib.h:21
void * data
Definition attrib.h:25
attr Copy()
Definition attrib.cc:33
attr get(const char *s)
Definition attrib.cc:93
void kill(const ring r)
Definition attrib.cc:183
void killAll(const ring r)
Definition attrib.cc:189
void * CopyA()
Definition subexpr.cc:2192
attr set(char *s, void *data, int t)
Definition attrib.cc:70
int atyp
Definition attrib.h:27
void Print()
Definition attrib.cc:26
char * name
Definition attrib.h:24
attr next
Definition attrib.h:26
void * CopyD(int t)
Definition subexpr.cc:714
int Typ()
Definition subexpr.cc:1048
int rtyp
Definition subexpr.h:91
void * Data()
Definition subexpr.cc:1192
void * data
Definition subexpr.h:88
attr * Attribute()
Definition subexpr.cc:1505
Subexpr e
Definition subexpr.h:105
attr attribute
Definition subexpr.h:89
@ n_Q
rational (GMP) numbers
Definition coeffs.h:30
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
return result
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
void WerrorS(const char *s)
Definition feFopen.cc:24
const char * Tok2Cmdname(int tok)
Definition gentable.cc:137
static int RingDependend(int t)
Definition gentable.cc:23
#define STATIC_VAR
Definition globaldefs.h:7
@ MODUL_CMD
Definition grammar.cc:288
@ RING_CMD
Definition grammar.cc:282
#define resetFlag(A, F)
Definition ipid.h:114
#define hasFlag(A, F)
Definition ipid.h:112
#define setFlag(A, F)
Definition ipid.h:113
#define FLAG_QRING
Definition ipid.h:108
#define IDTYP(a)
Definition ipid.h:119
#define FLAG_STD
Definition ipid.h:106
STATIC_VAR Poly * h
Definition janet.cc:971
#define assume(x)
Definition mod2.h:389
The main handler for Singular numbers which are suitable for Singular polynomials.
#define omStrDup(s)
#define omCheckAddr(addr)
#define omCheckAddrSize(addr, size)
#define omAlloc0Bin(bin)
#define omFree(addr)
#define omFreeBin(addr, bin)
#define omGetSpecBin(size)
Definition omBin.h:11
#define NULL
Definition omList.c:12
omBin_t * omBin
Definition omStructs.h:12
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
Compatibility 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 rIsLPRing(const ring r)
Definition ring.h:417
#define rField_is_Ring(R)
Definition ring.h:491
idrec * idhdl
Definition ring.h:22
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
sleftv * leftv
Definition structs.h:53
void s_internalDelete(const int t, void *d, const ring r)
Definition subexpr.cc:518
int name
New type name for int.
#define IDHDL
Definition tok.h:31
@ STRING_CMD
Definition tok.h:187
@ INT_CMD
Definition tok.h:96