My Project
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
blackbox.h File Reference
#include "kernel/mod2.h"
#include "kernel/structs.h"
#include "Singular/lists.h"
#include "Singular/links/silink.h"

Go to the source code of this file.

Data Structures

struct  blackbox
 
struct  blackbox_list
 struct for containing list of blackbox names and the number of them.
More...
 

Macros

#define BB_LIKE_LIST(B)   ((B)->properties &1)
 

Functions

void removeBlackboxStuff (const int rt)
 
BOOLEAN blackboxDefaultOp1 (int op, leftv l, leftv r)
 default procedure blackboxDefaultOp1, to be called as "default:" branch More...
 
BOOLEAN blackboxDefaultOp2 (int op, leftv l, leftv r1, leftv r2)
 default procedure blackboxDefaultOp2, to be called as "default:" branch More...
 
BOOLEAN blackboxDefaultOp3 (int op, leftv l, leftv r1, leftv r2, leftv r3)
 default procedure blackboxDefaultOp3, to be called as "default:" branch More...
 
BOOLEAN blackboxDefaultOpM (int op, leftv l, leftv r)
 default procedure blackboxDefaultOpM, to be called as "default:" branch More...
 
void blackbox_default_Print (blackbox *b, void *d)
 default procedure blackbox_default_Print: print the string More...
 
blackbox * getBlackboxStuff (const int t)
 return the structure to the type given by t More...
 
const char * getBlackboxName (const int t)
 return the name to the type given by t (r/o) More...
 
int blackboxIsCmd (const char *n, int &tok)
 used by scanner: returns ROOT_DECL for known types (and the type number in tok) More...
 
int setBlackboxStuff (blackbox *bb, const char *name)
 define a new type More...
 
void printBlackboxTypes ()
 list all defined type (for debugging) More...
 
struct blackbox_listgetBlackboxTypes ()
 return array of all define types. More...
 

Data Structure Documentation

◆ blackbox_list

struct blackbox_list

struct for containing list of blackbox names and the number of them.

Definition at line 84 of file blackbox.h.

Data Fields
int count
void ** list

Macro Definition Documentation

◆ BB_LIKE_LIST

#define BB_LIKE_LIST (   B)    ((B)->properties &1)

Definition at line 53 of file blackbox.h.

Function Documentation

◆ blackbox_default_Print()

void blackbox_default_Print ( blackbox *  b,
void *  d 
)

default procedure blackbox_default_Print: print the string

Definition at line 55 of file blackbox.cc.

56{
57 char *s=b->blackbox_String(b,d);
58 PrintS(s);
59 omFree(s);
60}
CanonicalForm b
Definition: cfModGcd.cc:4103
const CanonicalForm int s
Definition: facAbsFact.cc:51
#define omFree(addr)
Definition: omAllocDecl.h:261
void PrintS(const char *s)
Definition: reporter.cc:284

◆ blackboxDefaultOp1()

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

default procedure blackboxDefaultOp1, to be called as "default:" branch

Definition at line 78 of file blackbox.cc.

79{
80 if (op==TYPEOF_CMD)
81 {
82 l->data=omStrDup(getBlackboxName(r->Typ()));
83 l->rtyp=STRING_CMD;
84 return FALSE;
85 }
86 else if (op==NAMEOF_CMD)
87 {
88 if (r->name==NULL) l->data=omStrDup("");
89 else l->data=omStrDup(r->name);
90 l->rtyp=STRING_CMD;
91 return FALSE;
92 }
93
94 return TRUE;
95}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
const char * getBlackboxName(const int t)
return the name to the type given by t (r/o)
Definition: blackbox.cc:212
int l
Definition: cfEzgcd.cc:100
int Typ()
Definition: subexpr.cc:1019
const char * name
Definition: subexpr.h:87
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define NULL
Definition: omList.c:12
@ NAMEOF_CMD
Definition: tok.h:134
@ TYPEOF_CMD
Definition: tok.h:194
@ STRING_CMD
Definition: tok.h:185

◆ blackboxDefaultOp2()

BOOLEAN blackboxDefaultOp2 ( int  op,
leftv  l,
leftv  r1,
leftv  r2 
)

default procedure blackboxDefaultOp2, to be called as "default:" branch

Definition at line 97 of file blackbox.cc.

98{
99 return TRUE;
100}

◆ blackboxDefaultOp3()

BOOLEAN blackboxDefaultOp3 ( int  op,
leftv  l,
leftv  r1,
leftv  r2,
leftv  r3 
)

default procedure blackboxDefaultOp3, to be called as "default:" branch

Definition at line 102 of file blackbox.cc.

103{
104 return TRUE;
105}

◆ blackboxDefaultOpM()

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

default procedure blackboxDefaultOpM, to be called as "default:" branch

Definition at line 107 of file blackbox.cc.

108{
109 if (op==LIST_CMD)
110 {
111 res->rtyp=LIST_CMD;
112 BOOLEAN bo=jjLIST_PL(res,args);
113 args->CleanUp();
114 return bo;
115 }
116 else if(op==STRING_CMD)
117 {
118 blackbox *b=getBlackboxStuff(args->Typ());
119 res->data=b->blackbox_String(b,args->Data());
120 res->rtyp=STRING_CMD;
121 args=args->next;
122 if(args!=NULL)
123 {
124 sleftv res2;
125 int ret=iiExprArithM(&res2,args,op);
126 if (ret) return TRUE;
127 char *s2=(char*)omAlloc(strlen((char*)res->data)+strlen((char*)res2.data)+1);
128 sprintf(s2,"%s%s",(char*)res->data,(char*)res2.data);
129 omFree(res2.data);
130 omFree(res->data);
131 res->data=s2;
132 }
133 return FALSE;
134 }
135 return TRUE;
136}
int BOOLEAN
Definition: auxiliary.h:87
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:17
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
void * data
Definition: subexpr.h:88
CanonicalForm res
Definition: facAbsFact.cc:60
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition: iparith.cc:9414
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition: iparith.cc:7998
#define omAlloc(size)
Definition: omAllocDecl.h:210
@ LIST_CMD
Definition: tok.h:118

◆ blackboxIsCmd()

int blackboxIsCmd ( const char *  n,
int &  tok 
)

used by scanner: returns ROOT_DECL for known types (and the type number in tok)

Definition at line 218 of file blackbox.cc.

219{
220 for(int i=blackboxTableCnt-1;i>=0;i--)
221 {
222 if(strcmp(n,blackboxName[i])==0)
223 {
224#ifdef BLACKBOX_DEVEL
225 Print("blackboxIsCmd: found bb:%s:%d (table:%d)\n",n,i+BLACKBOX_OFFSET,i);
226#endif
227 tok=i+BLACKBOX_OFFSET;
228 return ROOT_DECL;
229 }
230 }
231 tok=0;
232 return 0;
233}
static GLOBAL_VAR char * blackboxName[MAX_BB_TYPES]
Definition: blackbox.cc:14
static GLOBAL_VAR int blackboxTableCnt
Definition: blackbox.cc:15
#define BLACKBOX_OFFSET
Definition: blackbox.cc:16
int i
Definition: cfEzgcd.cc:132
#define Print
Definition: emacs.cc:80
@ ROOT_DECL
Definition: grammar.cc:319

◆ getBlackboxName()

const char * getBlackboxName ( const int  t)

return the name to the type given by t (r/o)

Definition at line 212 of file blackbox.cc.

213{
215 if (b!=NULL) return b;
216 else return "";
217}

◆ getBlackboxStuff()

blackbox * getBlackboxStuff ( const int  t)

return the structure to the type given by t

Definition at line 17 of file blackbox.cc.

18{
19 if (t>MAX_TOK) /*MAX_TOK+1 is BLACKBOX_OFFSET*/
21 else
22 return NULL;
23}
static GLOBAL_VAR blackbox * blackboxTable[MAX_BB_TYPES]
Definition: blackbox.cc:13
@ MAX_TOK
Definition: tok.h:218

◆ getBlackboxTypes()

struct blackbox_list * getBlackboxTypes ( )

return array of all define types.

Definition at line 244 of file blackbox.cc.

245{
246 int i = 0;
247 void **l = (void **)omalloc0(blackboxTableCnt * sizeof(void *));
248 struct blackbox_list *list_struct = (struct blackbox_list *) omAlloc0(sizeof(struct blackbox_list));
249 list_struct->count = blackboxTableCnt;
250 list_struct->list = l;
251
252 for (i = blackboxTableCnt-1; i >= 0 ;i--)
253 {
254 if (blackboxName[i]!=NULL) {
255 l[i] = (void *)omStrDup(blackboxName[i]);
256 //Print("type %d: %s\n",i,blackboxName[i]);
257 } else {
258 l[i] = NULL;
259 }
260 }
261 return list_struct;
262}
void ** list
Definition: blackbox.h:86
struct for containing list of blackbox names and the number of them.
Definition: blackbox.h:84
#define omalloc0(size)
Definition: omAllocDecl.h:229
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ printBlackboxTypes()

void printBlackboxTypes ( )

list all defined type (for debugging)

Definition at line 235 of file blackbox.cc.

236{
237 for(int i=blackboxTableCnt-1;i>=0;i--)
238 {
239 if (blackboxName[i]!=NULL)
240 Print("type %d: %s\n",i,blackboxName[i]);
241 }
242}

◆ removeBlackboxStuff()

void removeBlackboxStuff ( const int  rt)

Definition at line 205 of file blackbox.cc.

◆ setBlackboxStuff()

int setBlackboxStuff ( blackbox *  bb,
const char *  name 
)

define a new type

Definition at line 142 of file blackbox.cc.

143{
144 int where = -1;
145 for (int i=0;i<MAX_BB_TYPES;i++)
146 {
147 if (blackboxTable[i]!=NULL && strcmp(blackboxName[i],n)==0) {
148 where = i;
149 break;
150 }
151 }
152 if (where < 0) {
154 {
155 // second try, find empty slot from removed bb:
156 for (int i=0;i<MAX_BB_TYPES;i++)
157 {
158 if (blackboxTable[i]==NULL) { where=i; break; }
159 }
160 }
161 else
162 {
163 where=blackboxTableCnt;
165 }
166 }
167 if (where==-1)
168 {
169 WerrorS("too many bb types defined");
170 return 0;
171 }
172 else
173 {
174 // check for alreday defined bb:
175 for (int i=0;i<MAX_BB_TYPES;i++)
176 {
177 if ((blackboxName[i]!=NULL) && (strcmp(blackboxName[i],n)==0))
178 {
179 Warn("not redefining blackbox type %s (%d)",n,i+BLACKBOX_OFFSET);
180 return 0;
181 }
182 }
183 blackboxTable[where]=bb;
184 blackboxName[where]=omStrDup(n);
185#ifdef BLACKBOX_DEVEL
186 Print("setBlackboxStuff: define bb:name=%s:rt=%d (table:cnt=%d)\n",blackboxName[where],where+BLACKBOX_OFFSET,where);
187#endif
188 if (bb->blackbox_destroy==NULL) bb->blackbox_destroy=blackbox_default_destroy;
189 if (bb->blackbox_String==NULL) bb->blackbox_String=blackbox_default_String;
190 if (bb->blackbox_Print==NULL) bb->blackbox_Print=blackbox_default_Print;
191 if (bb->blackbox_Init==NULL) bb->blackbox_Init=blackbox_default_Init;
192 if (bb->blackbox_Copy==NULL) bb->blackbox_Copy=blackbox_default_Copy;
193 if (bb->blackbox_Assign==NULL) bb->blackbox_Assign=blackbox_default_Assign;
194 if (bb->blackbox_Op1==NULL) bb->blackbox_Op1=blackboxDefaultOp1;
195 if (bb->blackbox_Op2==NULL) bb->blackbox_Op2=blackboxDefaultOp2;
196 if (bb->blackbox_Op3==NULL) bb->blackbox_Op3=blackboxDefaultOp3;
197 if (bb->blackbox_OpM==NULL) bb->blackbox_OpM=blackboxDefaultOpM;
198 if (bb->blackbox_CheckAssign==NULL) bb->blackbox_CheckAssign=blackbox_default_Check;
199 if (bb->blackbox_serialize==NULL) bb->blackbox_serialize=blackbox_default_serialize;
200 if (bb->blackbox_deserialize==NULL) bb->blackbox_deserialize=blackbox_default_deserialize;
201 return where+BLACKBOX_OFFSET;
202 }
203}
BOOLEAN blackboxDefaultOp2(int, leftv, leftv, leftv)
default procedure blackboxDefaultOp2, to be called as "default:" branch
Definition: blackbox.cc:97
void * blackbox_default_Copy(blackbox *, void *)
Definition: blackbox.cc:35
char * blackbox_default_String(blackbox *, void *)
Definition: blackbox.cc:30
BOOLEAN blackbox_default_serialize(blackbox *, void *, si_link)
Definition: blackbox.cc:66
BOOLEAN blackboxDefaultOp3(int, leftv, leftv, leftv, leftv)
default procedure blackboxDefaultOp3, to be called as "default:" branch
Definition: blackbox.cc:102
BOOLEAN blackbox_default_Check(blackbox *, leftv, leftv)
Definition: blackbox.cc:138
BOOLEAN blackbox_default_Assign(leftv l, leftv r)
Definition: blackbox.cc:40
void blackbox_default_Print(blackbox *b, void *d)
default procedure blackbox_default_Print: print the string
Definition: blackbox.cc:55
void * blackbox_default_Init(blackbox *)
Definition: blackbox.cc:61
BOOLEAN blackbox_default_deserialize(blackbox **, void **, si_link)
Definition: blackbox.cc:72
void blackbox_default_destroy(blackbox *, void *)
Definition: blackbox.cc:26
BOOLEAN blackboxDefaultOpM(int op, leftv res, leftv args)
default procedure blackboxDefaultOpM, to be called as "default:" branch
Definition: blackbox.cc:107
BOOLEAN blackboxDefaultOp1(int op, leftv l, leftv r)
default procedure blackboxDefaultOp1, to be called as "default:" branch
Definition: blackbox.cc:78
#define MAX_BB_TYPES
Definition: blackbox.cc:10
#define Warn
Definition: emacs.cc:77
void WerrorS(const char *s)
Definition: feFopen.cc:24