Data Structures | Functions
newstruct.cc File Reference
#include <kernel/mod2.h>
#include <Singular/ipid.h>
#include <Singular/blackbox.h>
#include <Singular/lists.h>
#include <Singular/ipshell.h>
#include <Singular/newstruct.h>
#include <ctype.h>

Go to the source code of this file.

Data Structures

struct  newstruct_member
 
struct  newstruct_proc
 
struct  newstruct_desc
 

Functions

int newstruct_desc_size ()
 
char * newstruct_String (blackbox *b, void *d)
 
lists lCopy_newstruct (lists L)
 
void * newstruct_Copy (blackbox *, void *d)
 
BOOLEAN newstruct_Assign_user (int op, leftv l, leftv r)
 
void lClean_newstruct (lists l)
 
static BOOLEAN newstruct_Assign_same (leftv l, leftv r)
 
BOOLEAN newstruct_Op1 (int op, leftv res, leftv arg)
 
BOOLEAN newstruct_Assign (leftv l, leftv r)
 
BOOLEAN newstruct_Op2 (int op, leftv res, leftv a1, leftv a2)
 
BOOLEAN newstruct_OpM (int op, leftv res, leftv args)
 
void newstruct_destroy (blackbox *, void *d)
 
void * newstruct_Init (blackbox *b)
 
BOOLEAN newstruct_CheckAssign (blackbox *, leftv L, leftv R)
 
BOOLEAN newstruct_serialize (blackbox *b, void *d, si_link f)
 
BOOLEAN newstruct_deserialize (blackbox **, void **d, si_link f)
 
void newstruct_Print (blackbox *b, void *d)
 
void newstruct_setup (const char *n, newstruct_desc d)
 
static newstruct_desc scanNewstructFromString (const char *s, newstruct_desc res)
 
newstruct_desc newstructFromString (const char *s)
 
newstruct_desc newstructChildFromString (const char *parent, const char *s)
 
void newstructShow (newstruct_desc d)
 
BOOLEAN newstruct_set_proc (const char *bbname, const char *func, int args, procinfov pr)
 

Data Structure Documentation

◆ newstruct_member_s

struct newstruct_member_s

Definition at line 14 of file newstruct.cc.

Data Fields
char * name
newstruct_member next
int pos
int typ

◆ newstruct_proc_a

struct newstruct_proc_a

Definition at line 24 of file newstruct.cc.

Data Fields
int args
newstruct_proc next
procinfov p
int t

◆ newstruct_desc_s

struct newstruct_desc_s

Definition at line 32 of file newstruct.cc.

Data Fields
int id
newstruct_member member
newstruct_desc parent
newstruct_proc procs
int size

Function Documentation

◆ lClean_newstruct()

void lClean_newstruct ( lists  l)

Definition at line 204 of file newstruct.cc.

205 {
206  if (l->nr>=0)
207  {
208  int i;
209  ring r=NULL;
210  for(i=l->nr;i>=0;i--)
211  {
212  if ((i>0) && (l->m[i-1].rtyp==RING_CMD))
213  r=(ring)(l->m[i-1].data);
214  else
215  r=NULL;
216  l->m[i].CleanUp(r);
217  }
218  omFreeSize((ADDRESS)l->m, (l->nr+1)*sizeof(sleftv));
219  l->nr=-1;
220  }
222 }
sleftv * m
Definition: lists.h:45
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void * ADDRESS
Definition: auxiliary.h:115
void * data
Definition: subexpr.h:89
const ring r
Definition: syzextra.cc:208
int i
Definition: cfEzgcd.cc:123
int nr
Definition: lists.h:43
#define NULL
Definition: omList.c:10
int rtyp
Definition: subexpr.h:92
void CleanUp(ring r=currRing)
Definition: subexpr.cc:332
omBin slists_bin
Definition: lists.cc:23
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259

◆ lCopy_newstruct()

lists lCopy_newstruct ( lists  L)

Definition at line 120 of file newstruct.cc.

121 {
123  int n=L->nr;
124  ring save_ring=currRing;
125  N->Init(n+1);
126  for(;n>=0;n--)
127  {
128  if (RingDependend(L->m[n].rtyp)
129  ||((L->m[n].rtyp==LIST_CMD)&&lRingDependend((lists)L->m[n].data)))
130  {
131  assume((L->m[n-1].rtyp==RING_CMD) || (L->m[n-1].data==NULL));
132  if(L->m[n-1].data!=NULL)
133  {
134  if (L->m[n-1].data!=(void*)currRing)
135  rChangeCurrRing((ring)(L->m[n-1].data));
136  N->m[n].Copy(&L->m[n]);
137  }
138  else
139  {
140  N->m[n].rtyp=L->m[n].rtyp;
141  N->m[n].data=idrecDataInit(L->m[n].rtyp);
142  }
143  }
144  else if(L->m[n].rtyp==LIST_CMD)
145  {
146  N->m[n].rtyp=L->m[n].rtyp;
147  N->m[n].data=(void *)lCopy((lists)(L->m[n].data));
148  }
149  else if(L->m[n].rtyp>MAX_TOK)
150  {
151  N->m[n].rtyp=L->m[n].rtyp;
152  blackbox *b=getBlackboxStuff(N->m[n].rtyp);
153  N->m[n].data=(void *)b->blackbox_Copy(b,L->m[n].data);
154  }
155  else
156  N->m[n].Copy(&L->m[n]);
157  }
158  if (currRing!=save_ring) rChangeCurrRing(save_ring);
159  return N;
160 }
void * idrecDataInit(int t)
Definition: ipid.cc:131
sleftv * m
Definition: lists.h:45
Definition: lists.h:22
Definition: tok.h:213
void * data
Definition: subexpr.h:89
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
int RingDependend(int t)
Definition: gentable.cc:23
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
#define assume(x)
Definition: mod2.h:394
void Copy(leftv e)
Definition: subexpr.cc:688
lists lCopy(lists L)
Definition: lists.cc:32
void rChangeCurrRing(ring r)
Definition: polys.cc:12
INLINE_THIS void Init(int l=0)
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
int nr
Definition: lists.h:43
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146
int rtyp
Definition: subexpr.h:92
Definition: tok.h:117
omBin slists_bin
Definition: lists.cc:23
const poly b
Definition: syzextra.cc:213
BOOLEAN lRingDependend(lists L)
Definition: lists.cc:199
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16

◆ newstruct_Assign()

BOOLEAN newstruct_Assign ( leftv  l,
leftv  r 
)

Definition at line 278 of file newstruct.cc.

279 {
280  assume(l->Typ() > MAX_TOK);
281  if (l->Typ()==r->Typ())
282  {
283  return newstruct_Assign_same(l,r);
284  }
285  if (r->Typ()>MAX_TOK)
286  {
287  blackbox *rr=getBlackboxStuff(r->Typ());
288  if (l->Typ()!=r->Typ())
289  {
290  newstruct_desc rrn=(newstruct_desc)rr->data;
291 
292  if (rrn==NULL) // this is not a newstruct
293  {
294  Werror("custom type %s(%d) cannot be assigned to newstruct %s(%d)",
295  Tok2Cmdname(r->Typ()), r->Typ(), Tok2Cmdname(l->Typ()), l->Typ());
296  return TRUE;
297  }
298 
299  // try to find a parent newstruct:
300  newstruct_desc rrp=rrn->parent;
301  while ((rrp!=NULL)&&(rrp->id!=l->Typ())) rrp=rrp->parent;
302  if (rrp!=NULL)
303  {
304  if (l->rtyp==IDHDL)
305  {
306  IDTYP((idhdl)l->data)=r->Typ();
307  }
308  else
309  {
310  l->rtyp=r->Typ();
311  }
312  }
313  else // unrelated types - look for custom conversion
314  {
315  sleftv tmp;
316  if (! newstruct_Op1(l->Typ(), &tmp, r)) return newstruct_Assign(l, &tmp);
317  if(!newstruct_Assign_user(l->Typ(), &tmp, r)) return newstruct_Assign(l, &tmp);
318  }
319  }
320  if (l->Typ()==r->Typ())
321  {
322  return newstruct_Assign_same(l,r);
323  }
324  }
325  else
326  {
327  sleftv tmp;
328  if(!newstruct_Assign_user(l->Typ(), &tmp, r)) return newstruct_Assign(l, &tmp);
329  }
330  Werror("assign %s(%d) = %s(%d)",
331  Tok2Cmdname(l->Typ()),l->Typ(),Tok2Cmdname(r->Typ()),r->Typ());
332  return TRUE;
333 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
BOOLEAN newstruct_Op1(int op, leftv res, leftv arg)
Definition: newstruct.cc:246
if(0 > strat->sl)
Definition: myNF.cc:73
BOOLEAN newstruct_Assign_user(int op, leftv l, leftv r)
Definition: newstruct.cc:168
Definition: tok.h:213
#define TRUE
Definition: auxiliary.h:98
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:31
void * data
Definition: subexpr.h:89
#define IDTYP(a)
Definition: ipid.h:116
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:394
static BOOLEAN newstruct_Assign_same(leftv l, leftv r)
Definition: newstruct.cc:224
BOOLEAN newstruct_Assign(leftv l, leftv r)
Definition: newstruct.cc:278
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
int rtyp
Definition: subexpr.h:92
void Werror(const char *fmt,...)
Definition: reporter.cc:189
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16

◆ newstruct_Assign_same()

static BOOLEAN newstruct_Assign_same ( leftv  l,
leftv  r 
)
static

Definition at line 224 of file newstruct.cc.

225 {
226  assume(l->Typ() == r->Typ());
227  if (l->Data()!=NULL)
228  {
229  lists n1=(lists)l->Data();
230  lClean_newstruct(n1);
231  }
232  lists n2=(lists)r->Data();
233  n2=lCopy_newstruct(n2);
234  r->CleanUp();
235  if (l->rtyp==IDHDL)
236  {
237  IDDATA((idhdl)l->data)=(char *)n2;
238  }
239  else
240  {
241  l->data=(void *)n2;
242  }
243  return FALSE;
244 }
Definition: lists.h:22
#define FALSE
Definition: auxiliary.h:94
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:31
void * data
Definition: subexpr.h:89
#define assume(x)
Definition: mod2.h:394
lists lCopy_newstruct(lists L)
Definition: newstruct.cc:120
void lClean_newstruct(lists l)
Definition: newstruct.cc:204
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146
int rtyp
Definition: subexpr.h:92
void CleanUp(ring r=currRing)
Definition: subexpr.cc:332
void * Data()
Definition: subexpr.cc:1137
#define IDDATA(a)
Definition: ipid.h:123

◆ newstruct_Assign_user()

BOOLEAN newstruct_Assign_user ( int  op,
leftv  l,
leftv  r 
)

Definition at line 168 of file newstruct.cc.

169 {
170  blackbox *ll=getBlackboxStuff(op);
171  assume(ll->data != NULL);
172  newstruct_desc nt=(newstruct_desc)ll->data;
173  newstruct_proc p=nt->procs;
174 
175  while( (p!=NULL) && ((p->t!='=')||(p->args!=1)) ) p=p->next;
176 
177  if (p!=NULL)
178  {
179  BOOLEAN sl;
180  idrec hh;
181  memset(&hh,0,sizeof(hh));
182  hh.id=Tok2Cmdname(p->t);
183  hh.typ=PROC_CMD;
184  hh.data.pinf=p->p;
185  sleftv tmp;
186  memset(&tmp,0,sizeof(sleftv));
187  tmp.Copy(r);
188  sl = iiMake_proc(&hh, NULL, &tmp);
189  if (!sl)
190  {
191  if (iiRETURNEXPR.Typ() == op)
192  {
193  memcpy(l,&iiRETURNEXPR,sizeof(sleftv));
194  iiRETURNEXPR.Init();
195  return FALSE;
196  }
198  iiRETURNEXPR.Init();
199  }
200  }
201  return TRUE;
202 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
sleftv iiRETURNEXPR
Definition: iplib.cc:471
#define TRUE
Definition: auxiliary.h:98
void Init()
Definition: subexpr.h:108
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
#define assume(x)
Definition: mod2.h:394
void Copy(leftv e)
Definition: subexpr.cc:688
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
void CleanUp(ring r=currRing)
Definition: subexpr.cc:332
int typ
Definition: idrec.h:43
const char * id
Definition: idrec.h:39
int BOOLEAN
Definition: auxiliary.h:85
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
utypes data
Definition: idrec.h:40

◆ newstruct_CheckAssign()

BOOLEAN newstruct_CheckAssign ( blackbox *  ,
leftv  L,
leftv  R 
)

Definition at line 554 of file newstruct.cc.

555 {
556  int lt=L->Typ();
557  int rt=R->Typ();
558  if ((lt!=DEF_CMD)&&(lt!=rt))
559  {
560  const char *rt1=Tok2Cmdname(rt);
561  const char *lt1=Tok2Cmdname(lt);
562  if ((rt>0) && (lt>0)
563  && ((strcmp(rt1,Tok2Cmdname(0))==0)||(strcmp(lt1,Tok2Cmdname(0))==0)))
564  {
565  Werror("can not assign %s(%d) to member of type %s(%d)",
566  rt1,rt,lt1,lt);
567  }
568  else
569  {
570  Werror("can not assign %s to member of type %s",rt1,lt1);
571  }
572  return TRUE;
573  }
574  return FALSE;
575 }
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
int Typ()
Definition: subexpr.cc:995
Definition: tok.h:58
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ newstruct_Copy()

void* newstruct_Copy ( blackbox *  ,
void *  d 
)

Definition at line 161 of file newstruct.cc.

162 {
163  lists n1=(lists)d;
164  return (void*)lCopy_newstruct(n1);
165 }
Definition: lists.h:22
lists lCopy_newstruct(lists L)
Definition: newstruct.cc:120
slists * lists
Definition: mpr_numeric.h:146

◆ newstruct_desc_size()

int newstruct_desc_size ( )

Definition at line 41 of file newstruct.cc.

42 {
43  return sizeof(newstruct_desc_s);
44 }

◆ newstruct_deserialize()

BOOLEAN newstruct_deserialize ( blackbox **  ,
void **  d,
si_link  f 
)

Definition at line 640 of file newstruct.cc.

641 {
642  // newstruct is serialized as analog to a list,
643  // just read a list and take data,
644  // rtyp must be set correctly (to the blackbox id) by routine calling
645  // newstruct_deserialize
646  leftv l=f->m->Read(f); // int: length of list
647  int Ll=(int)(long)(l->data);
648  omFree(l);
650  L->Init(Ll+1);
651  for(int i=0;i<=Ll;i++)
652  {
653  l=f->m->Read(f);
654  memcpy(&(L->m[i]),l,sizeof(sleftv));
655  omFree(l);
656  }
657  //newstruct_desc n=(newstruct_desc)b->data;
658  //TODO: check compatibility of list l->data with description in n
659  *d=L;
660  return FALSE;
661 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
sleftv * m
Definition: lists.h:45
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
Definition: lists.h:22
#define FALSE
Definition: auxiliary.h:94
void * data
Definition: subexpr.h:89
#define omFree(addr)
Definition: omAllocDecl.h:261
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:123
INLINE_THIS void Init(int l=0)
slists * lists
Definition: mpr_numeric.h:146
omBin slists_bin
Definition: lists.cc:23
int l
Definition: cfEzgcd.cc:94

◆ newstruct_destroy()

void newstruct_destroy ( blackbox *  ,
void *  d 
)

Definition at line 528 of file newstruct.cc.

529 {
530  if (d!=NULL)
531  {
532  lists n=(lists)d;
533  lClean_newstruct(n);
534  }
535 }
Definition: lists.h:22
void lClean_newstruct(lists l)
Definition: newstruct.cc:204
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146

◆ newstruct_Init()

void* newstruct_Init ( blackbox *  b)

Definition at line 537 of file newstruct.cc.

538 {
539  newstruct_desc n=(newstruct_desc)b->data;
541  l->Init(n->size);
542  newstruct_member nm=n->member;
543  while (nm!=NULL)
544  {
545  l->m[nm->pos].rtyp=nm->typ;
546  if (RingDependend(nm->typ) ||(nm->typ==DEF_CMD)||(nm->typ==LIST_CMD))
547  l->m[nm->pos-1].rtyp=RING_CMD;
548  l->m[nm->pos].data=idrecDataInit(nm->typ);
549  nm=nm->next;
550  }
551  return l;
552 }
void * idrecDataInit(int t)
Definition: ipid.cc:131
Definition: lists.h:22
int RingDependend(int t)
Definition: gentable.cc:23
Definition: tok.h:58
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define NULL
Definition: omList.c:10
Definition: tok.h:117
omBin slists_bin
Definition: lists.cc:23
const poly b
Definition: syzextra.cc:213
int l
Definition: cfEzgcd.cc:94

◆ newstruct_Op1()

BOOLEAN newstruct_Op1 ( int  op,
leftv  res,
leftv  arg 
)

Definition at line 246 of file newstruct.cc.

247 {
248  // interpreter: arg is newstruct
249  blackbox *a=getBlackboxStuff(arg->Typ());
250  newstruct_desc nt=(newstruct_desc)a->data;
251  newstruct_proc p=nt->procs;
252 
253  while((p!=NULL) &&( (p->t!=op) || (p->args!=1) )) p=p->next;
254 
255  if (p!=NULL)
256  {
257  BOOLEAN sl;
258  sleftv tmp;
259  memset(&tmp,0,sizeof(sleftv));
260  tmp.Copy(arg);
261  idrec hh;
262  memset(&hh,0,sizeof(hh));
263  hh.id=Tok2Cmdname(p->t);
264  hh.typ=PROC_CMD;
265  hh.data.pinf=p->p;
266  sl=iiMake_proc(&hh,NULL,&tmp);
267  if (sl) return TRUE;
268  else
269  {
270  res->Copy(&iiRETURNEXPR);
271  iiRETURNEXPR.Init();
272  return FALSE;
273  }
274  }
275  return blackboxDefaultOp1(op,res,arg);
276 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
sleftv iiRETURNEXPR
Definition: iplib.cc:471
#define TRUE
Definition: auxiliary.h:98
void Init()
Definition: subexpr.h:108
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
void Copy(leftv e)
Definition: subexpr.cc:688
BOOLEAN blackboxDefaultOp1(int op, leftv l, leftv r)
default procedure blackboxDefaultOp1, to be called as "default:" branch
Definition: blackbox.cc:62
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
int typ
Definition: idrec.h:43
const char * id
Definition: idrec.h:39
int BOOLEAN
Definition: auxiliary.h:85
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
utypes data
Definition: idrec.h:40

◆ newstruct_Op2()

BOOLEAN newstruct_Op2 ( int  op,
leftv  res,
leftv  a1,
leftv  a2 
)

Definition at line 335 of file newstruct.cc.

336 {
337  // interpreter: a1 or a2 is newstruct
338  blackbox *a=getBlackboxStuff(a1->Typ());
339  newstruct_desc nt;
340  lists al=(lists)a1->Data();
341  if (a!=NULL)
342  {
343  nt=(newstruct_desc)a->data;
344  switch(op)
345  {
346  case '.':
347  {
348  if (a2->name!=NULL)
349  {
350  BOOLEAN search_ring=FALSE;
351  newstruct_member nm=nt->member;
352  while ((nm!=NULL)&&(strcmp(nm->name,a2->name)!=0)) nm=nm->next;
353  if ((nm==NULL) && (strncmp(a2->name,"r_",2)==0))
354  {
355  nm=nt->member;
356  while ((nm!=NULL)&&(strcmp(nm->name,a2->name+2)!=0)) nm=nm->next;
357  if ((nm!=NULL)&&(RingDependend(nm->typ)))
358  search_ring=TRUE;
359  else
360  nm=NULL;
361  }
362  if (nm==NULL)
363  {
364  Werror("member %s not found", a2->name);
365  return TRUE;
366  }
367  if (search_ring)
368  {
369  ring r;
370  res->rtyp=RING_CMD;
371  res->data=al->m[nm->pos-1].data;
372  r=(ring)res->data;
373  if (r==NULL)
374  {
375  res->data=(void *)currRing; r=currRing;
376  if (r!=NULL) r->ref++;
377  else WerrorS("ring of this member is not set and no basering found");
378  }
379  return r==NULL;
380  }
381  else if (RingDependend(nm->typ)
382  || (al->m[nm->pos].RingDependend()))
383  {
384  if (al->m[nm->pos].data==NULL)
385  {
386  // NULL belongs to any ring
387  ring r=(ring)al->m[nm->pos-1].data;
388  if (r!=NULL)
389  {
390  r->ref--;
391  al->m[nm->pos-1].data=NULL;
392  al->m[nm->pos-1].rtyp=DEF_CMD;
393  }
394  }
395  else
396  {
397  //Print("checking ring at pos %d for dat at pos %d\n",nm->pos-1,nm->pos);
398  if ((al->m[nm->pos-1].data!=(void *)currRing)
399  &&(al->m[nm->pos-1].data!=(void*)0L))
400  {
401  Werror("different ring %lx(data) - %lx(basering)",
402  (long unsigned)(al->m[nm->pos-1].data),(long unsigned)currRing);
403  Werror("name of basering: %s",IDID(currRingHdl));
405  idhdl hh=rFindHdl((ring)(al->m[nm->pos-1].data),NULL);
406  const char *nn="??";
407  if (hh!=NULL) nn=IDID(hh);
408  Werror("(possible) name of ring of data: %s",nn);
409  rWrite((ring)(al->m[nm->pos-1].data),TRUE);PrintLn();
410 
411  return TRUE;
412  }
413  }
414  if ((currRing!=NULL)&&(al->m[nm->pos-1].data==NULL))
415  {
416  // remember the ring, if not already set
417  al->m[nm->pos-1].data=(void *)currRing;
418  al->m[nm->pos-1].rtyp=RING_CMD;
419  currRing->ref++;
420  }
421  }
422  else if ((nm->typ==DEF_CMD)||(nm->typ==LIST_CMD))
423  {
424  if (al->m[nm->pos-1].data==NULL)
425  {
426  al->m[nm->pos-1].data=(void*)currRing;
427  if (currRing!=NULL) currRing->ref++;
428  }
429  }
430  Subexpr r=(Subexpr)omAlloc0Bin(sSubexpr_bin);
431  r->start = nm->pos+1;
432  memcpy(res,a1,sizeof(sleftv));
433  memset(a1,0,sizeof(sleftv));
434  if (res->e==NULL) res->e=r;
435  else
436  {
437  Subexpr sh=res->e;
438  while (sh->next != NULL) sh=sh->next;
439  sh->next=r;
440  }
441  return FALSE;
442  }
443  else
444  {
445  WerrorS("name expected");
446  return TRUE;
447  }
448  }
449  }
450  }
451  else
452  {
453  a=getBlackboxStuff(a2->Typ());
454  nt=(newstruct_desc)a->data;
455  al=(lists)a2->Data();
456  }
457  newstruct_proc p=nt->procs;
458  while((p!=NULL) && ( (p->t!=op) || (p->args!=2) )) p=p->next;
459  if (p!=NULL)
460  {
461  BOOLEAN sl;
462  sleftv tmp;
463  memset(&tmp,0,sizeof(sleftv));
464  tmp.Copy(a1);
465  tmp.next=(leftv)omAlloc0(sizeof(sleftv));
466  tmp.next->Copy(a2);
467  idrec hh;
468  memset(&hh,0,sizeof(hh));
469  hh.id=Tok2Cmdname(p->t);
470  hh.typ=PROC_CMD;
471  hh.data.pinf=p->p;
472  sl=iiMake_proc(&hh,NULL,&tmp);
473  if (sl) return TRUE;
474  else
475  {
476  res->Copy(&iiRETURNEXPR);
477  iiRETURNEXPR.Init();
478  return FALSE;
479  }
480  }
481  return blackboxDefaultOp2(op,res,a1,a2);
482 }
sleftv * m
Definition: lists.h:45
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
const poly a
Definition: syzextra.cc:212
void PrintLn()
Definition: reporter.cc:310
Subexpr e
Definition: subexpr.h:106
Definition: lists.h:22
if(0 > strat->sl)
Definition: myNF.cc:73
#define IDID(a)
Definition: ipid.h:119
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
sleftv iiRETURNEXPR
Definition: iplib.cc:471
#define TRUE
Definition: auxiliary.h:98
void Init()
Definition: subexpr.h:108
sleftv * leftv
Definition: structs.h:60
void WerrorS(const char *s)
Definition: feFopen.cc:24
BOOLEAN blackboxDefaultOp2(int, leftv, leftv, leftv)
default procedure blackboxDefaultOp2, to be called as "default:" branch
Definition: blackbox.cc:81
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
void * data
Definition: subexpr.h:89
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
int RingDependend(int t)
Definition: gentable.cc:23
const ring r
Definition: syzextra.cc:208
BOOLEAN RingDependend()
Definition: subexpr.cc:402
Definition: tok.h:58
const char * name
Definition: subexpr.h:88
omBin sSubexpr_bin
Definition: subexpr.cc:49
idhdl currRingHdl
Definition: ipid.cc:65
void Copy(leftv e)
Definition: subexpr.cc:688
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1594
void rWrite(ring r, BOOLEAN details)
Definition: ring.cc:236
leftv next
Definition: subexpr.h:87
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
int rtyp
Definition: subexpr.h:92
void * Data()
Definition: subexpr.cc:1137
int typ
Definition: idrec.h:43
Definition: tok.h:117
const char * id
Definition: idrec.h:39
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
utypes data
Definition: idrec.h:40

◆ newstruct_OpM()

BOOLEAN newstruct_OpM ( int  op,
leftv  res,
leftv  args 
)

Definition at line 485 of file newstruct.cc.

486 {
487  // interpreter: args->1. arg is newstruct
488  blackbox *a=getBlackboxStuff(args->Typ());
489  newstruct_desc nt=(newstruct_desc)a->data;
490  switch(op)
491  {
492  case STRING_CMD:
493  {
494  res->data=(void *)a->blackbox_String(a,args->Data());
495  res->rtyp=STRING_CMD;
496  return FALSE;
497  }
498  default:
499  break;
500  }
501  newstruct_proc p=nt->procs;
502 
503  while((p!=NULL) &&( (p->t!=op) || (p->args!=4) )) p=p->next;
504 
505  if (p!=NULL)
506  {
507  BOOLEAN sl;
508  sleftv tmp;
509  memset(&tmp,0,sizeof(sleftv));
510  tmp.Copy(args);
511  idrec hh;
512  memset(&hh,0,sizeof(hh));
513  hh.id=Tok2Cmdname(p->t);
514  hh.typ=PROC_CMD;
515  hh.data.pinf=p->p;
516  sl=iiMake_proc(&hh,NULL,&tmp);
517  if (sl) return TRUE;
518  else
519  {
520  res->Copy(&iiRETURNEXPR);
521  iiRETURNEXPR.Init();
522  return FALSE;
523  }
524  }
525  return blackboxDefaultOpM(op,res,args);
526 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
sleftv iiRETURNEXPR
Definition: iplib.cc:471
#define TRUE
Definition: auxiliary.h:98
void Init()
Definition: subexpr.h:108
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
void * data
Definition: subexpr.h:89
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
void Copy(leftv e)
Definition: subexpr.cc:688
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
BOOLEAN blackboxDefaultOpM(int op, leftv res, leftv args)
default procedure blackboxDefaultOpM, to be called as "default:" branch
Definition: blackbox.cc:91
int rtyp
Definition: subexpr.h:92
void * Data()
Definition: subexpr.cc:1137
int typ
Definition: idrec.h:43
const char * id
Definition: idrec.h:39
int BOOLEAN
Definition: auxiliary.h:85
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
utypes data
Definition: idrec.h:40

◆ newstruct_Print()

void newstruct_Print ( blackbox *  b,
void *  d 
)

Definition at line 663 of file newstruct.cc.

664 {
665  newstruct_desc dd=(newstruct_desc)b->data;
666  newstruct_proc p=dd->procs;
667  while((p!=NULL)&&(p->t!=PRINT_CMD))
668  p=p->next;
669  if (p!=NULL)
670  {
671  BOOLEAN sl;
672  sleftv tmp;
673  memset(&tmp,0,sizeof(tmp));
674  tmp.rtyp=dd->id;
675  tmp.data=(void*)newstruct_Copy(b,d);
676  idrec hh;
677  memset(&hh,0,sizeof(hh));
678  hh.id=Tok2Cmdname(p->t);
679  hh.typ=PROC_CMD;
680  hh.data.pinf=p->p;
681  sl=iiMake_proc(&hh,NULL,&tmp);
682  if (!sl)
683  {
684  if (iiRETURNEXPR.Typ()!=NONE) Warn("ignoring return value (%s)",Tok2Cmdname(iiRETURNEXPR.Typ()));
686  }
687  iiRETURNEXPR.Init();
688  }
689  else
691 }
void blackbox_default_Print(blackbox *b, void *d)
default procedure blackbox_default_Print: print the string
Definition: blackbox.cc:39
Definition: tok.h:154
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
return P p
Definition: myNF.cc:203
sleftv iiRETURNEXPR
Definition: iplib.cc:471
void Init()
Definition: subexpr.h:108
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
void * data
Definition: subexpr.h:89
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
void * newstruct_Copy(blackbox *, void *d)
Definition: newstruct.cc:161
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
int rtyp
Definition: subexpr.h:92
void CleanUp(ring r=currRing)
Definition: subexpr.cc:332
int typ
Definition: idrec.h:43
const char * id
Definition: idrec.h:39
int BOOLEAN
Definition: auxiliary.h:85
const poly b
Definition: syzextra.cc:213
#define NONE
Definition: tok.h:216
utypes data
Definition: idrec.h:40
#define Warn
Definition: emacs.cc:80

◆ newstruct_serialize()

BOOLEAN newstruct_serialize ( blackbox *  b,
void *  d,
si_link  f 
)

Definition at line 599 of file newstruct.cc.

600 {
601  newstruct_desc dd=(newstruct_desc)b->data;
602  sleftv l;
603  memset(&l,0,sizeof(l));
604  l.rtyp=STRING_CMD;
605  l.data=(void*)getBlackboxName(dd->id);
606  f->m->Write(f, &l);
607  lists ll=(lists)d;
608  int Ll=lSize(ll);
609  l.rtyp=INT_CMD;
610  l.data=(void*)(long)Ll;
611  f->m->Write(f, &l);
612  // set all entries corresponding to "real" mebers to 1 in rings
613  char *rings=(char*)omAlloc0(Ll+1);
614  newstruct_member elem=dd->member;
615  while (elem!=NULL)
616  {
617  rings[elem->pos]='\1';
618  elem=elem->next;
619  }
620  int i;
621  BOOLEAN ring_changed=FALSE;
622  ring save_ring=currRing;
623  for(i=0;i<=Ll;i++)
624  {
625  if (rings[i]=='\0') // ring entry for pos i+1
626  {
627  if (ll->m[i].data!=NULL)
628  {
629  ring_changed=TRUE;
630  f->m->SetRing(f,(ring)ll->m[i].data,TRUE);
631  }
632  }
633  f->m->Write(f,&(ll->m[i]));
634  }
635  if (ring_changed)
636  f->m->SetRing(f,save_ring,FALSE);
637  return FALSE;
638 }
sleftv * m
Definition: lists.h:45
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
Definition: tok.h:95
Definition: lists.h:22
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
void * data
Definition: subexpr.h:89
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:123
int lSize(lists L)
Definition: lists.cc:25
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146
const char * getBlackboxName(const int t)
return the name to the type given by t (r/o)
Definition: blackbox.cc:185
int BOOLEAN
Definition: auxiliary.h:85
const poly b
Definition: syzextra.cc:213
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94

◆ newstruct_set_proc()

BOOLEAN newstruct_set_proc ( const char *  bbname,
const char *  func,
int  args,
procinfov  pr 
)

Definition at line 850 of file newstruct.cc.

851 {
852  int id=0;
853  blackboxIsCmd(bbname,id);
854  if (id<MAX_TOK)
855  {
856  Werror(">>%s<< is not a newstruct type",bbname);
857  return TRUE;
858  }
859  blackbox *bb=getBlackboxStuff(id);
860  newstruct_desc desc=(newstruct_desc)bb->data;
861  newstruct_proc p=(newstruct_proc)omAlloc(sizeof(*p));
862  p->next=desc->procs; desc->procs=p;
863 
864  idhdl save_ring=currRingHdl;
865  currRingHdl=(idhdl)1; // fake ring detection
866 
867  int tt;
868  if(!(tt=IsCmd(func,p->t)))
869  {
870  int t;
871  if((t=iiOpsTwoChar(func))!=0)
872  {
873  p->t=t;
874  tt=CMD_2; /* ..,::, ==, <=, <>, >= !=i and +,-,*,/,%,.... */
875  if ((t==PLUSPLUS)
876  ||(t==MINUSMINUS)
877  ||(t=='='))
878  tt=CMD_1; /* ++,--,= */
879  else if (t=='(') /* proc call */
880  tt=CMD_M;
881  else if (t=='-') /* unary and binary - */
882  tt=CMD_12;
883  }
884  else
885  {
886  desc->procs=p->next;
887  omFreeSize(p,sizeof(*p));
888  Werror(">>%s<< is not a kernel command",func);
889  currRingHdl = save_ring;
890  return TRUE;
891  }
892  }
893  switch(tt)
894  {
895  // type conversions:
896  case BIGINTMAT_CMD:
897  case MATRIX_CMD:
898  case INTMAT_CMD:
899  case RING_CMD:
900  case RING_DECL:
901  case RING_DECL_LIST:
902  case ROOT_DECL:
903  case ROOT_DECL_LIST:
904  // operations:
905  case CMD_1:
906  if(args!=1) { Warn("args must be 1 in %s",my_yylinebuf);args=1;}
907  break;
908  case CMD_2:
909  if(args!=2) { Warn("args must be 2 in %s",my_yylinebuf);args=2;}
910  break;
911  case CMD_3:
912  if(args!=3) { Warn("args must be 3 in %s",my_yylinebuf);args=3;}
913  break;
914  case CMD_12:
915  if((args!=1)&&(args!=2)) { Werror("args must in 1 or 2 in %s",my_yylinebuf);}
916  break;
917  case CMD_13:
918  if((args!=1)&&(args!=3)) { Werror("args must in 1 or 3 in %s",my_yylinebuf);}
919  break;
920  case CMD_23:
921  if((args<2)||(args>3)) { Werror("args must in 2..3 in %s",my_yylinebuf);}
922  break;
923  case CMD_123:
924  if((args<1)||(args>3)) { Werror("args must in 1..3 in %s",my_yylinebuf);}
925  break;
926  case CMD_M:
927  if(args!=4) { Warn("args must be 4 in %s",my_yylinebuf);args=4;}
928  break;
929  default:
930  Werror("unknown token type %d in %s",tt,my_yylinebuf);
931  break;
932  }
933  currRingHdl = save_ring;
934  if (errorreported)
935  {
936  desc->procs=p->next;
937  omFreeSize(p,sizeof(*p));
938  return TRUE;
939  }
940  p->args=args;
941  p->p=pr; pr->ref++;
942  pr->is_static=0;
943  return FALSE;
944 }
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
Definition: tok.h:213
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define TRUE
Definition: auxiliary.h:98
short ref
Definition: subexpr.h:60
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: idrec.h:34
char my_yylinebuf[80]
Definition: febase.cc:48
idhdl currRingHdl
Definition: ipid.cc:65
idrec * idhdl
Definition: ring.h:18
short errorreported
Definition: feFopen.cc:23
char is_static
Definition: subexpr.h:61
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
Definition: blackbox.cc:191
int iiOpsTwoChar(const char *s)
Definition: ipshell.cc:119
void Werror(const char *fmt,...)
Definition: reporter.cc:189
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8628
#define Warn
Definition: emacs.cc:80

◆ newstruct_setup()

void newstruct_setup ( const char *  n,
newstruct_desc  d 
)

Definition at line 692 of file newstruct.cc.

693 {
694  blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
695  // all undefined entries will be set to default in setBlackboxStuff
696  // the default Print is quite useful,
697  // all other are simply error messages
698  b->blackbox_destroy=newstruct_destroy;
699  b->blackbox_String=newstruct_String;
700  b->blackbox_Print=newstruct_Print;//blackbox_default_Print;
701  b->blackbox_Init=newstruct_Init;
702  b->blackbox_Copy=newstruct_Copy;
703  b->blackbox_Assign=newstruct_Assign;
704  b->blackbox_Op1=newstruct_Op1;
705  b->blackbox_Op2=newstruct_Op2;
706  //b->blackbox_Op3=blackboxDefaultOp3;
707  b->blackbox_OpM=newstruct_OpM;
708  b->blackbox_CheckAssign=newstruct_CheckAssign;
709  b->blackbox_serialize=newstruct_serialize;
710  b->blackbox_deserialize=newstruct_deserialize;
711  b->data=d;
712  b->properties=1; // list_like
713  int rt=setBlackboxStuff(b,n);
714  d->id=rt;
715  //Print("create type %d (%s)\n",rt,n);
716 }
BOOLEAN newstruct_Op1(int op, leftv res, leftv arg)
Definition: newstruct.cc:246
void newstruct_destroy(blackbox *, void *d)
Definition: newstruct.cc:528
BOOLEAN newstruct_OpM(int op, leftv res, leftv args)
Definition: newstruct.cc:485
BOOLEAN newstruct_Op2(int op, leftv res, leftv a1, leftv a2)
Definition: newstruct.cc:335
void * newstruct_Init(blackbox *b)
Definition: newstruct.cc:537
BOOLEAN newstruct_serialize(blackbox *b, void *d, si_link f)
Definition: newstruct.cc:599
BOOLEAN newstruct_deserialize(blackbox **, void **d, si_link f)
Definition: newstruct.cc:640
BOOLEAN newstruct_Assign(leftv l, leftv r)
Definition: newstruct.cc:278
char * newstruct_String(blackbox *b, void *d)
Definition: newstruct.cc:46
void * newstruct_Copy(blackbox *, void *d)
Definition: newstruct.cc:161
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:126
const poly b
Definition: syzextra.cc:213
void newstruct_Print(blackbox *b, void *d)
Definition: newstruct.cc:663
#define omAlloc0(size)
Definition: omAllocDecl.h:211
BOOLEAN newstruct_CheckAssign(blackbox *, leftv L, leftv R)
Definition: newstruct.cc:554

◆ newstruct_String()

char* newstruct_String ( blackbox *  b,
void *  d 
)

Definition at line 46 of file newstruct.cc.

47 {
48  if (d==NULL) return omStrDup("oo");
49  else
50  {
51  newstruct_desc ad=(newstruct_desc)(b->data);
52 
53  newstruct_proc p=ad->procs;
54  while((p!=NULL)&&(p->t!=STRING_CMD))
55  p=p->next;
56 
57  if (p!=NULL)
58  {
59  BOOLEAN sl;
60  sleftv tmp;
61  memset(&tmp,0,sizeof(tmp));
62  tmp.rtyp=ad->id;
63  void * newstruct_Copy(blackbox*, void *); //forward declaration
64  tmp.data=(void*)newstruct_Copy(b,d);
65  idrec hh;
66  memset(&hh,0,sizeof(hh));
67  hh.id=Tok2Cmdname(p->t);
68  hh.typ=PROC_CMD;
69  hh.data.pinf=p->p;
70  sl=iiMake_proc(&hh,NULL,&tmp);
71 
72  if ((!sl)&& (iiRETURNEXPR.Typ() == STRING_CMD))
73  {
74  char *res = omStrDup((char*)iiRETURNEXPR.CopyD());
77  return res;
78  }
81  }
82 
83  lists l=(lists)d;
84  newstruct_member a=ad->member;
85  StringSetS("");
86  loop
87  {
88  StringAppendS(a->name);
89  StringAppendS("=");
90  if ((!RingDependend(a->typ))
91  || ((l->m[a->pos-1].data==(void *)currRing)
92  && (currRing!=NULL)))
93  {
94  if (l->m[a->pos].rtyp==LIST_CMD)
95  {
96  StringAppendS("<list>");
97  }
98  else
99  {
100  char *tmp2=omStrDup(l->m[a->pos].String());
101  if ((strlen(tmp2)>80)||(strchr(tmp2,'\n')!=NULL))
102  {
103  StringAppendS("<");
104  StringAppendS(Tok2Cmdname(l->m[a->pos].rtyp));
105  StringAppendS(">");
106  }
107  else StringAppendS(tmp2);
108  omFree(tmp2);
109  }
110  }
111  else StringAppendS("??");
112  if (a->next==NULL) break;
113  StringAppendS("\n");
114  if(errorreported) break;
115  a=a->next;
116  }
117  return StringEndS();
118  }
119 }
sleftv * m
Definition: lists.h:45
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
const poly a
Definition: syzextra.cc:212
Definition: lists.h:22
loop
Definition: myNF.cc:98
return P p
Definition: myNF.cc:203
sleftv iiRETURNEXPR
Definition: iplib.cc:471
void Init()
Definition: subexpr.h:108
char * StringEndS()
Definition: reporter.cc:151
int Typ()
Definition: subexpr.cc:995
Definition: idrec.h:34
char * String(void *d=NULL, BOOLEAN typed=FALSE, int dim=1)
Called for conversion to string (used by string(..), write(..),..)
Definition: subexpr.cc:751
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:10
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
int RingDependend(int t)
Definition: gentable.cc:23
#define omFree(addr)
Definition: omAllocDecl.h:261
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
CFList tmp2
Definition: facFqBivar.cc:70
short errorreported
Definition: feFopen.cc:23
void * newstruct_Copy(blackbox *, void *d)
Definition: newstruct.cc:161
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
int rtyp
Definition: subexpr.h:92
void CleanUp(ring r=currRing)
Definition: subexpr.cc:332
int typ
Definition: idrec.h:43
Definition: tok.h:117
const char * id
Definition: idrec.h:39
int BOOLEAN
Definition: auxiliary.h:85
const poly b
Definition: syzextra.cc:213
void * CopyD(int t)
Definition: subexpr.cc:707
int l
Definition: cfEzgcd.cc:94
utypes data
Definition: idrec.h:40
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ newstructChildFromString()

newstruct_desc newstructChildFromString ( const char *  parent,
const char *  s 
)

Definition at line 803 of file newstruct.cc.

804 {
805  // find parent:
806  int parent_id=0;
807  blackboxIsCmd(parent,parent_id);
808  if (parent_id<MAX_TOK)
809  {
810  Werror(">>%s< not found",parent);
811  return NULL;
812  }
813  blackbox *parent_bb=getBlackboxStuff(parent_id);
814  // check for the correct type:
815  if (parent_bb->blackbox_destroy!=newstruct_destroy)
816  {
817  Werror(">>%s< is not a user defined type",parent);
818  return NULL;
819  }
820  // setup for scanNewstructFromString:
821  newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
822  newstruct_desc parent_desc=(newstruct_desc)parent_bb->data;
823  res->size=parent_desc->size;
824  res->member=parent_desc->member;
825  res->parent=parent_desc;
826 
827  return scanNewstructFromString(s,res);
828 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void newstruct_destroy(blackbox *, void *d)
Definition: newstruct.cc:528
Definition: tok.h:213
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
static newstruct_desc scanNewstructFromString(const char *s, newstruct_desc res)
Definition: newstruct.cc:718
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
Definition: blackbox.cc:191
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16

◆ newstructFromString()

newstruct_desc newstructFromString ( const char *  s)

Definition at line 796 of file newstruct.cc.

797 {
798  newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
799  res->size=0;
800 
801  return scanNewstructFromString(s,res);
802 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
poly res
Definition: myNF.cc:322
static newstruct_desc scanNewstructFromString(const char *s, newstruct_desc res)
Definition: newstruct.cc:718
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ newstructShow()

void newstructShow ( newstruct_desc  d)

Definition at line 830 of file newstruct.cc.

831 {
832  newstruct_member elem;
833  Print("id: %d\n",d->id);
834  elem=d->member;
835  while (elem!=NULL)
836  {
837  Print(">>%s<< at pos %d, type %d (%s)\n",elem->name,elem->pos,elem->typ,Tok2Cmdname(elem->typ));
838  if (RingDependend(elem->typ)|| (elem->typ==DEF_CMD) ||(elem->typ==LIST_CMD))
839  Print(">>r_%s<< at pos %d, shadow ring\n",elem->name,elem->pos-1);
840  elem=elem->next;
841  }
842  newstruct_proc p=d->procs;
843  while (p!=NULL)
844  {
845  Print("op:%d(%s) with %d args -> %s\n",p->t,iiTwoOps(p->t),p->args,p->p->procname);
846  p=p->next;
847  }
848 }
#define Print
Definition: emacs.cc:83
return P p
Definition: myNF.cc:203
int RingDependend(int t)
Definition: gentable.cc:23
const char * iiTwoOps(int t)
Definition: gentable.cc:253
Definition: tok.h:58
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
Definition: tok.h:117

◆ scanNewstructFromString()

static newstruct_desc scanNewstructFromString ( const char *  s,
newstruct_desc  res 
)
static

Definition at line 718 of file newstruct.cc.

719 {
720  char *ss=omStrDup(s);
721  char *p=ss;
722  char *start;
723  int t;
724  char c;
725  newstruct_member elem;
726 
727  idhdl save_ring=currRingHdl;
728  currRingHdl=(idhdl)1; // fake ring detection
729  loop
730  {
731  // read type:
732  while ((*p!='\0') && (*p<=' ')) p++;
733  start=p;
734  while (isalnum(*p)) p++;
735  *p='\0';
736  IsCmd(start,t);
737  if (t==0)
738  {
739  Werror("unknown type `%s`",start);
740  omFree(ss);
741  omFree(res);
742  currRingHdl=save_ring;
743  return NULL;
744  }
745  if (t==QRING_CMD) t=RING_CMD;
746  else if (RingDependend(t) || (t==DEF_CMD)||(t==LIST_CMD))
747  res->size++; // one additional field for the ring (before the data)
748  //Print("found type %s at real-pos %d",start,res->size);
749  elem=(newstruct_member)omAlloc0(sizeof(*elem));
750  // read name:
751  p++;
752  while ((*p!='\0') && (*p<=' ')) p++;
753  start=p;
754  while (isalnum(*p)) p++;
755  c=*p;
756  *p='\0';
757  elem->typ=t;
758  elem->pos=res->size;
759  if ((*start=='\0') /*empty name*/||(isdigit(*start)))
760  {
761  WerrorS("illegal/empty name for element");
762  goto error_in_newstruct_def;
763  }
764  elem->name=omStrDup(start);
765  //Print(" name:%s\n",start);
766  elem->next=res->member;
767  res->member=elem;
768  res->size++;
769 
770  // next ?
771  *p=c;
772  while ((*p!='\0') && (*p<=' ')) p++;
773  if (*p!=',')
774  {
775  if (*p!='\0')
776  {
777  Werror("unknown character in newstruct:>>%s<<",p);
778  goto error_in_newstruct_def;
779  }
780  break; // end-of-list
781  }
782  p++;
783  }
784  omFree(ss);
785  currRingHdl=save_ring;
786  //Print("new type with %d elements\n",res->size);
787  //newstructShow(res);
788  return res;
789 error_in_newstruct_def:
790  omFree(elem);
791  omFree(ss);
792  omFree(res);
793  currRingHdl=save_ring;
794  return NULL;
795 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
loop
Definition: myNF.cc:98
return P p
Definition: myNF.cc:203
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: idrec.h:34
poly res
Definition: myNF.cc:322
int RingDependend(int t)
Definition: gentable.cc:23
Definition: tok.h:58
#define omFree(addr)
Definition: omAllocDecl.h:261
idhdl currRingHdl
Definition: ipid.cc:65
idrec * idhdl
Definition: ring.h:18
#define NULL
Definition: omList.c:10
Definition: tok.h:117
Definition: tok.h:157
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8628
#define omStrDup(s)
Definition: omAllocDecl.h:263