My Project  debian-1:4.1.2-p1+ds-2
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 42 of file newstruct.cc.

43 {
44  return sizeof(newstruct_desc_s);
45 }

◆ newstruct_set_proc()

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

Definition at line 863 of file newstruct.cc.

864 {
865  int id=0;
866  blackboxIsCmd(bbname,id);
867  if (id<MAX_TOK)
868  {
869  Werror(">>%s<< is not a newstruct type",bbname);
870  return TRUE;
871  }
872  blackbox *bb=getBlackboxStuff(id);
873  newstruct_desc desc=(newstruct_desc)bb->data;
874  newstruct_proc p=(newstruct_proc)omAlloc(sizeof(*p));
875  p->next=desc->procs; desc->procs=p;
876 
877  idhdl save_ring=currRingHdl;
878  currRingHdl=(idhdl)1; // fake ring detection
879 
880  int tt;
881  if(!(tt=IsCmd(func,p->t)))
882  {
883  int t;
884  if((t=iiOpsTwoChar(func))!=0)
885  {
886  p->t=t;
887  tt=CMD_2; /* ..,::, ==, <=, <>, >= !=i and +,-,*,/,%,.... */
888  if ((t==PLUSPLUS)
889  ||(t==MINUSMINUS)
890  ||(t=='='))
891  tt=CMD_1; /* ++,--,= */
892  else if (t=='(') /* proc call */
893  tt=CMD_M;
894  else if (t=='-') /* unary and binary - */
895  tt=CMD_12;
896  }
897  else
898  {
899  desc->procs=p->next;
900  omFreeSize(p,sizeof(*p));
901  Werror(">>%s<< is not a kernel command",func);
902  currRingHdl = save_ring;
903  return TRUE;
904  }
905  }
906  switch(tt)
907  {
908  // type conversions:
909  case BIGINTMAT_CMD:
910  case MATRIX_CMD:
911  case INTMAT_CMD:
912  case RING_CMD:
913  case RING_DECL:
914  case ROOT_DECL:
915  // operations:
916  case CMD_1:
917  if(args!=1) { Warn("args must be 1 for %s in %s",func,my_yylinebuf);args=1;}
918  break;
919  case CMD_2:
920  if(args!=2) { Warn("args must be 2 in %s",my_yylinebuf);args=2;}
921  break;
922  case CMD_3:
923  if(args!=3) { Warn("args must be 3 in %s",my_yylinebuf);args=3;}
924  break;
925  case CMD_12:
926  if((args!=1)&&(args!=2)) { Werror("args must in 1 or 2 in %s",my_yylinebuf);}
927  break;
928  case CMD_13:
929  if((args!=1)&&(args!=3)) { Werror("args must in 1 or 3 in %s",my_yylinebuf);}
930  break;
931  case CMD_23:
932  if((args<2)||(args>3)) { Werror("args must in 2..3 in %s",my_yylinebuf);}
933  break;
934  case CMD_123:
935  if((args<1)||(args>3)) { Werror("args must in 1..3 in %s",my_yylinebuf);}
936  break;
937  case RING_DECL_LIST:
938  case ROOT_DECL_LIST:
939  case CMD_M:
940  break;
941  default:
942  Werror("unknown token type %d in %s",tt,my_yylinebuf);
943  break;
944  }
945  currRingHdl = save_ring;
946  if (errorreported)
947  {
948  desc->procs=p->next;
949  omFreeSize(p,sizeof(*p));
950  return TRUE;
951  }
952  p->args=args;
953  p->p=pr; pr->ref++;
954  pr->is_static=0;
955  return FALSE;
956 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16
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:201
int p
Definition: cfModGcd.cc:4019
Definition: idrec.h:35
#define Warn
Definition: emacs.cc:77
VAR short errorreported
Definition: feFopen.cc:23
VAR char my_yylinebuf[80]
Definition: febase.cc:43
@ CMD_1
Definition: grammar.cc:311
@ PLUSPLUS
Definition: grammar.cc:274
@ MINUSMINUS
Definition: grammar.cc:271
@ CMD_23
Definition: grammar.cc:316
@ CMD_2
Definition: grammar.cc:312
@ MATRIX_CMD
Definition: grammar.cc:286
@ RING_DECL
Definition: grammar.cc:321
@ RING_DECL_LIST
Definition: grammar.cc:322
@ BIGINTMAT_CMD
Definition: grammar.cc:278
@ CMD_3
Definition: grammar.cc:313
@ ROOT_DECL
Definition: grammar.cc:319
@ INTMAT_CMD
Definition: grammar.cc:279
@ ROOT_DECL_LIST
Definition: grammar.cc:320
@ CMD_123
Definition: grammar.cc:317
@ CMD_12
Definition: grammar.cc:314
@ CMD_13
Definition: grammar.cc:315
@ CMD_M
Definition: grammar.cc:318
@ RING_CMD
Definition: grammar.cc:281
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:9007
VAR idhdl currRingHdl
Definition: ipid.cc:59
int iiOpsTwoChar(const char *s)
Definition: ipshell.cc:117
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
void Werror(const char *fmt,...)
Definition: reporter.cc:189
idrec * idhdl
Definition: ring.h:21
@ MAX_TOK
Definition: tok.h:217

◆ newstruct_setup()

void newstruct_setup ( const char *  name,
newstruct_desc  d 
)

Definition at line 705 of file newstruct.cc.

706 {
707  blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
708  // all undefined entries will be set to default in setBlackboxStuff
709  // the default Print is quite useful,
710  // all other are simply error messages
711  b->blackbox_destroy=newstruct_destroy;
712  b->blackbox_String=newstruct_String;
713  b->blackbox_Print=newstruct_Print;//blackbox_default_Print;
714  b->blackbox_Init=newstruct_Init;
715  b->blackbox_Copy=newstruct_Copy;
716  b->blackbox_Assign=newstruct_Assign;
717  b->blackbox_Op1=newstruct_Op1;
718  b->blackbox_Op2=newstruct_Op2;
719  //b->blackbox_Op3=blackboxDefaultOp3;
720  b->blackbox_OpM=newstruct_OpM;
721  b->blackbox_CheckAssign=newstruct_CheckAssign;
722  b->blackbox_serialize=newstruct_serialize;
723  b->blackbox_deserialize=newstruct_deserialize;
724  b->data=d;
725  b->properties=1; // list_like
726  int rt=setBlackboxStuff(b,n);
727  d->id=rt;
728  //Print("create type %d (%s)\n",rt,n);
729 }
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:126
CanonicalForm b
Definition: cfModGcd.cc:4044
void * newstruct_Copy(blackbox *, void *d)
Definition: newstruct.cc:164
BOOLEAN newstruct_Op2(int op, leftv res, leftv a1, leftv a2)
Definition: newstruct.cc:334
char * newstruct_String(blackbox *b, void *d)
Definition: newstruct.cc:47
BOOLEAN newstruct_deserialize(blackbox **, void **d, si_link f)
Definition: newstruct.cc:653
void newstruct_destroy(blackbox *, void *d)
Definition: newstruct.cc:536
BOOLEAN newstruct_Op1(int op, leftv res, leftv arg)
Definition: newstruct.cc:249
BOOLEAN newstruct_Assign(leftv l, leftv r)
Definition: newstruct.cc:277
BOOLEAN newstruct_serialize(blackbox *b, void *d, si_link f)
Definition: newstruct.cc:611
BOOLEAN newstruct_OpM(int op, leftv res, leftv args)
Definition: newstruct.cc:495
BOOLEAN newstruct_CheckAssign(blackbox *, leftv L, leftv R)
Definition: newstruct.cc:566
void newstruct_Print(blackbox *b, void *d)
Definition: newstruct.cc:676
void * newstruct_Init(blackbox *b)
Definition: newstruct.cc:545
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ newstructChildFromString()

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

Definition at line 816 of file newstruct.cc.

817 {
818  // find parent:
819  int parent_id=0;
820  blackboxIsCmd(parent,parent_id);
821  if (parent_id<MAX_TOK)
822  {
823  Werror(">>%s< not found",parent);
824  return NULL;
825  }
826  blackbox *parent_bb=getBlackboxStuff(parent_id);
827  // check for the correct type:
828  if (parent_bb->blackbox_destroy!=newstruct_destroy)
829  {
830  Werror(">>%s< is not a user defined type",parent);
831  return NULL;
832  }
833  // setup for scanNewstructFromString:
834  newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
835  newstruct_desc parent_desc=(newstruct_desc)parent_bb->data;
836  res->size=parent_desc->size;
837  res->member=parent_desc->member;
838  res->parent=parent_desc;
839 
840  return scanNewstructFromString(s,res);
841 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
CanonicalForm res
Definition: facAbsFact.cc:64
static newstruct_desc scanNewstructFromString(const char *s, newstruct_desc res)
Definition: newstruct.cc:731
#define NULL
Definition: omList.c:12

◆ newstructFromString()

newstruct_desc newstructFromString ( const char *  s)

Definition at line 809 of file newstruct.cc.

810 {
811  newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
812  res->size=0;
813 
814  return scanNewstructFromString(s,res);
815 }

◆ newstructShow()

void newstructShow ( newstruct_desc  d)

Definition at line 843 of file newstruct.cc.

844 {
845  newstruct_member elem;
846  Print("id: %d\n",d->id);
847  elem=d->member;
848  while (elem!=NULL)
849  {
850  Print(">>%s<< at pos %d, type %d (%s)\n",elem->name,elem->pos,elem->typ,Tok2Cmdname(elem->typ));
851  if (RingDependend(elem->typ)|| (elem->typ==DEF_CMD) ||(elem->typ==LIST_CMD))
852  Print(">>r_%s<< at pos %d, shadow ring\n",elem->name,elem->pos-1);
853  elem=elem->next;
854  }
855  newstruct_proc p=d->procs;
856  while (p!=NULL)
857  {
858  Print("op:%d(%s) with %d args -> %s\n",p->t,iiTwoOps(p->t),p->args,p->p->procname);
859  p=p->next;
860  }
861 }
#define Print
Definition: emacs.cc:80
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
int RingDependend(int t)
Definition: gentable.cc:28
const char * iiTwoOps(int t)
Definition: gentable.cc:261
@ LIST_CMD
Definition: tok.h:118
@ DEF_CMD
Definition: tok.h:58