Functions
newstruct.h File Reference

Go to the source code of this file.

Functions

void newstruct_setup (const char *name, newstruct_desc d)
 
int newstruct_desc_size ()
 
newstruct_desc newstructFromString (const char *s)
 
newstruct_desc newstructChildFromString (const char *p, const char *s)
 
BOOLEAN newstruct_set_proc (const char *name, const char *func, int args, procinfov p)
 
void newstructShow (newstruct_desc d)
 

Function Documentation

int newstruct_desc_size ( )

Definition at line 41 of file newstruct.cc.

42 {
43  return sizeof(newstruct_desc_s);
44 }
BOOLEAN newstruct_set_proc ( const char *  name,
const char *  func,
int  args,
procinfov  p 
)

Definition at line 849 of file newstruct.cc.

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

Definition at line 802 of file newstruct.cc.

803 {
804  // find parent:
805  int parent_id=0;
806  blackboxIsCmd(parent,parent_id);
807  if (parent_id<MAX_TOK)
808  {
809  Werror(">>%s< not found",parent);
810  return NULL;
811  }
812  blackbox *parent_bb=getBlackboxStuff(parent_id);
813  // check for the correct type:
814  if (parent_bb->blackbox_destroy!=newstruct_destroy)
815  {
816  Werror(">>%s< is not a user defined type",parent);
817  return NULL;
818  }
819  // setup for scanNewstructFromString:
820  newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
821  newstruct_desc parent_desc=(newstruct_desc)parent_bb->data;
822  res->size=parent_desc->size;
823  res->member=parent_desc->member;
824  res->parent=parent_desc;
825 
826  return scanNewstructFromString(s,res);
827 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void newstruct_destroy(blackbox *, void *d)
Definition: newstruct.cc:528
Definition: tok.h:217
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:193
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define omAlloc0(size)
Definition: omAllocDecl.h:211
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:20
newstruct_desc newstructFromString ( const char *  s)

Definition at line 795 of file newstruct.cc.

796 {
797  newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
798  res->size=0;
799 
800  return scanNewstructFromString(s,res);
801 }
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
void newstructShow ( newstruct_desc  d)

Definition at line 829 of file newstruct.cc.

830 {
831  newstruct_member elem;
832  Print("id: %d\n",d->id);
833  elem=d->member;
834  while (elem!=NULL)
835  {
836  Print(">>%s<< at pos %d, type %d (%s)\n",elem->name,elem->pos,elem->typ,Tok2Cmdname(elem->typ));
837  if (RingDependend(elem->typ)|| (elem->typ==DEF_CMD) ||(elem->typ==LIST_CMD))
838  Print(">>r_%s<< at pos %d, shadow ring\n",elem->name,elem->pos-1);
839  elem=elem->next;
840  }
841  newstruct_proc p=d->procs;
842  while (p!=NULL)
843  {
844  Print("op:%d(%s) with %d args -> %s\n",p->t,iiTwoOps(p->t),p->args,p->p->procname);
845  p=p->next;
846  }
847 }
#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:252
Definition: tok.h:61
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
Definition: tok.h:120