My Project
Loading...
Searching...
No Matches
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 857 of file newstruct.cc.

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

◆ newstruct_setup()

void newstruct_setup ( const char * name,
newstruct_desc d )

Definition at line 699 of file newstruct.cc.

700{
701 blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
702 // all undefined entries will be set to default in setBlackboxStuff
703 // the default Print is quite useful,
704 // all other are simply error messages
705 b->blackbox_destroy=newstruct_destroy;
706 b->blackbox_String=newstruct_String;
707 b->blackbox_Print=newstruct_Print;//blackbox_default_Print;
708 b->blackbox_Init=newstruct_Init;
709 b->blackbox_Copy=newstruct_Copy;
710 b->blackbox_Assign=newstruct_Assign;
711 b->blackbox_Op1=newstruct_Op1;
712 b->blackbox_Op2=newstruct_Op2;
713 //b->blackbox_Op3=blackboxDefaultOp3;
714 b->blackbox_OpM=newstruct_OpM;
715 b->blackbox_CheckAssign=newstruct_CheckAssign;
716 b->blackbox_serialize=newstruct_serialize;
717 b->blackbox_deserialize=newstruct_deserialize;
718 b->data=d;
719 b->properties=1; // list_like
720 int rt=setBlackboxStuff(b,n);
721 d->id=rt;
722 //Print("create type %d (%s)\n",rt,n);
723}
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition blackbox.cc:143
CanonicalForm b
Definition cfModGcd.cc:4111
BOOLEAN newstruct_Op2(int op, leftv res, leftv a1, leftv a2)
Definition newstruct.cc:344
BOOLEAN newstruct_deserialize(blackbox **, void **d, si_link f)
Definition newstruct.cc:644
void newstruct_destroy(blackbox *, void *d)
Definition newstruct.cc:527
char * newstruct_String(blackbox *b, void *d)
Definition newstruct.cc:50
BOOLEAN newstruct_Op1(int op, leftv res, leftv arg)
Definition newstruct.cc:259
BOOLEAN newstruct_Assign(leftv l, leftv r)
Definition newstruct.cc:287
BOOLEAN newstruct_serialize(blackbox *b, void *d, si_link f)
Definition newstruct.cc:602
void * newstruct_Copy(blackbox *, void *d)
Definition newstruct.cc:175
void * newstruct_Init(blackbox *b)
Definition newstruct.cc:536
BOOLEAN newstruct_OpM(int op, leftv res, leftv args)
Definition newstruct.cc:486
BOOLEAN newstruct_CheckAssign(blackbox *, leftv L, leftv R)
Definition newstruct.cc:557
void newstruct_Print(blackbox *b, void *d)
Definition newstruct.cc:670
#define omAlloc0(size)

◆ newstructChildFromString()

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

Definition at line 810 of file newstruct.cc.

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

◆ newstructFromString()

newstruct_desc newstructFromString ( const char * s)

Definition at line 803 of file newstruct.cc.

804{
805 newstruct_desc res=(newstruct_desc)omAlloc0(sizeof(*res));
806 res->size=0;
807
809}

◆ newstructShow()

void newstructShow ( newstruct_desc d)

Definition at line 837 of file newstruct.cc.

838{
839 newstruct_member elem;
840 Print("id: %d\n",d->id);
841 elem=d->member;
842 while (elem!=NULL)
843 {
844 Print(">>%s<< at pos %d, type %d (%s)\n",elem->name,elem->pos,elem->typ,Tok2Cmdname(elem->typ));
845 if (NeedShadowRing(elem->typ))
846 Print(">>r_%s<< at pos %d, shadow ring\n",elem->name,elem->pos-1);
847 elem=elem->next;
848 }
849 newstruct_proc p=d->procs;
850 while (p!=NULL)
851 {
852 Print("op:%d(%s) with %d args -> %s\n",p->t,iiTwoOps(p->t),p->args,p->p->procname);
853 p=p->next;
854 }
855}
#define Print
Definition emacs.cc:80
const char * iiTwoOps(int t)
Definition gentable.cc:258
const char * Tok2Cmdname(int tok)
Definition gentable.cc:137
static int NeedShadowRing(int t)
Definition newstruct.cc:46