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

§ newstruct_desc_size()

int newstruct_desc_size ( )

Definition at line 41 of file newstruct.cc.

42 {
43  return sizeof(newstruct_desc_s);
44 }

§ newstruct_set_proc()

BOOLEAN newstruct_set_proc ( const char *  name,
const char *  func,
int  args,
procinfov  p 
)

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:97
return P p
Definition: myNF.cc:203
Definition: tok.h:213
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define TRUE
Definition: auxiliary.h:101
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
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:189
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:8830
#define Warn
Definition: emacs.cc:80

§ newstruct_setup()

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:124
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

§ newstructChildFromString()

newstruct_desc newstructChildFromString ( const char *  p,
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:189
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:252
Definition: tok.h:57
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:128
Definition: tok.h:116