1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: ipid.cc,v 1.68 2003-07-25 14:04:09 levandov Exp $ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT: identfier handling |
---|
8 | */ |
---|
9 | |
---|
10 | #include <string.h> |
---|
11 | |
---|
12 | #include "mod2.h" |
---|
13 | #include "static.h" |
---|
14 | #include "omalloc.h" |
---|
15 | #include "tok.h" |
---|
16 | #include "ipshell.h" |
---|
17 | #include "intvec.h" |
---|
18 | #include "febase.h" |
---|
19 | #include "numbers.h" |
---|
20 | #include "polys.h" |
---|
21 | #include "ring.h" |
---|
22 | #include "ideals.h" |
---|
23 | #include "matpol.h" |
---|
24 | #include "lists.h" |
---|
25 | #include "attrib.h" |
---|
26 | #include "silink.h" |
---|
27 | #include "syz.h" |
---|
28 | #include "ipid.h" |
---|
29 | |
---|
30 | #ifdef HAVE_DYNAMIC_LOADING |
---|
31 | #include "mod_raw.h" |
---|
32 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
33 | |
---|
34 | omBin sip_command_bin = omGetSpecBin(sizeof(sip_command)); |
---|
35 | omBin ip_command_bin = omGetSpecBin(sizeof(ip_command)); |
---|
36 | omBin sip_package_bin = omGetSpecBin(sizeof(sip_package)); |
---|
37 | omBin ip_package_bin = omGetSpecBin(sizeof(ip_package)); |
---|
38 | omBin idrec_bin = omGetSpecBin(sizeof(idrec)); |
---|
39 | |
---|
40 | proclevel *procstack=NULL; |
---|
41 | #define TEST |
---|
42 | idhdl idroot = NULL; |
---|
43 | |
---|
44 | #ifdef HAVE_NS |
---|
45 | idhdl currPackHdl = NULL; |
---|
46 | idhdl basePackHdl = NULL; |
---|
47 | package currPack =NULL; |
---|
48 | package basePack =NULL; |
---|
49 | #endif /* HAVE_NS */ |
---|
50 | idhdl currRingHdl = NULL; |
---|
51 | ring currRing = NULL; |
---|
52 | ideal currQuotient = NULL; |
---|
53 | char* iiNoName="_"; |
---|
54 | |
---|
55 | void paCleanUp(package pack); |
---|
56 | |
---|
57 | /*0 implementation*/ |
---|
58 | |
---|
59 | idhdl idrec::get(const char * s, int lev) |
---|
60 | { |
---|
61 | assume(s!=NULL); |
---|
62 | assume((lev>=0) && (lev<1000)); //not really, but if it isnt in that bounds.. |
---|
63 | idhdl h = this; |
---|
64 | idhdl found=NULL; |
---|
65 | int l; |
---|
66 | char *id; |
---|
67 | if (s[1]=='\0') |
---|
68 | { |
---|
69 | while (h!=NULL) |
---|
70 | { |
---|
71 | omCheckAddr(IDID(h)); |
---|
72 | // ============================================================= |
---|
73 | #if 0 |
---|
74 | // timings: ratchwum: 515 s, wilde13: 373 s, nepomuck: 267 s, lukas 863 s |
---|
75 | id=IDID(h); |
---|
76 | l=IDLEV(h); |
---|
77 | if ((l==0) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1))) |
---|
78 | { |
---|
79 | found=h; |
---|
80 | } |
---|
81 | else if ((l==lev) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1))) |
---|
82 | { |
---|
83 | return h; |
---|
84 | } |
---|
85 | #endif |
---|
86 | // ============================================================= |
---|
87 | #if 0 |
---|
88 | // timings: ratchwum: 515 s, wilde13: 398 s, nepomuck: 269 s, lukas 834 s |
---|
89 | id=IDID(h); |
---|
90 | if (*(short *)s==*(short *)id) |
---|
91 | { |
---|
92 | l=IDLEV(h); |
---|
93 | if ((l==0) && (0 == strcmp(s+1,id+1))) |
---|
94 | { |
---|
95 | found=h; |
---|
96 | } |
---|
97 | else if ((l==lev) && (0 == strcmp(s+1,id+1))) |
---|
98 | { |
---|
99 | return h; |
---|
100 | } |
---|
101 | } |
---|
102 | #endif |
---|
103 | // ============================================================= |
---|
104 | #if 1 |
---|
105 | // timings: ratchwum: 501 s, wilde13: 357 s, nepomuck: 267 s, lukas 816 s |
---|
106 | // timings bug4: ratchwum: s, wilde13: s, nepomuck: 379.74 s, lukas s |
---|
107 | l=IDLEV(h); |
---|
108 | if ((l==0)||(l==lev)) |
---|
109 | { |
---|
110 | id=IDID(h); |
---|
111 | if (*(short *)s==*(short *)id) |
---|
112 | { |
---|
113 | if (0 == strcmp(s+1,id+1)) |
---|
114 | { |
---|
115 | if (l==lev) return h; |
---|
116 | found=h; |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|
120 | #endif |
---|
121 | // ============================================================= |
---|
122 | #if 0 |
---|
123 | // timings: ratchwum: s, wilde13: s, nepomuck: s, lukas s |
---|
124 | // timings bug4: ratchwum: s, wilde13: s, nepomuck: s, lukas s |
---|
125 | l=IDLEV(h); |
---|
126 | if ((l==0)||(l==lev)) |
---|
127 | { |
---|
128 | id=IDID(h); |
---|
129 | if (*(short *)s==*(short *)id) |
---|
130 | { |
---|
131 | if (l==lev) return h; |
---|
132 | found=h; |
---|
133 | } |
---|
134 | } |
---|
135 | #endif |
---|
136 | // ============================================================= |
---|
137 | h = IDNEXT(h); |
---|
138 | } |
---|
139 | } |
---|
140 | else |
---|
141 | { |
---|
142 | while (h!=NULL) |
---|
143 | { |
---|
144 | omCheckAddr(IDID(h)); |
---|
145 | // ============================================================= |
---|
146 | #if 0 |
---|
147 | // timings: ratchwum: 515 s, wilde13: 373 s, nepomuck: 267 s, lukas 863 s |
---|
148 | id=IDID(h); |
---|
149 | l=IDLEV(h); |
---|
150 | if ((l==0) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1))) |
---|
151 | { |
---|
152 | found=h; |
---|
153 | } |
---|
154 | else if ((l==lev) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1))) |
---|
155 | { |
---|
156 | return h; |
---|
157 | } |
---|
158 | #endif |
---|
159 | // ============================================================= |
---|
160 | #if 0 |
---|
161 | // timings: ratchwum: 515 s, wilde13: 398 s, nepomuck: 269 s, lukas 834 s |
---|
162 | id=IDID(h); |
---|
163 | if (*(short *)s==*(short *)id) |
---|
164 | { |
---|
165 | l=IDLEV(h); |
---|
166 | if ((l==0) && (0 == strcmp(s+1,id+1))) |
---|
167 | { |
---|
168 | found=h; |
---|
169 | } |
---|
170 | else if ((l==lev) && (0 == strcmp(s+1,id+1))) |
---|
171 | { |
---|
172 | return h; |
---|
173 | } |
---|
174 | } |
---|
175 | #endif |
---|
176 | // ============================================================= |
---|
177 | #if 0 |
---|
178 | // timings: ratchwum: 501 s, wilde13: 357 s, nepomuck: 267 s, lukas 816 s |
---|
179 | // timings bug4: ratchwum: s, wilde13: s, nepomuck: 379.74 s, lukas s |
---|
180 | l=IDLEV(h); |
---|
181 | if ((l==0)||(l==lev)) |
---|
182 | { |
---|
183 | id=IDID(h); |
---|
184 | if (*(short *)s==*(short *)id) |
---|
185 | { |
---|
186 | if (0 == strcmp(s+1,id+1)) |
---|
187 | { |
---|
188 | if (l==lev) return h; |
---|
189 | found=h; |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | #endif |
---|
194 | // ============================================================= |
---|
195 | #if 1 |
---|
196 | // timings: ratchwum: s, wilde13: s, nepomuck: s, lukas s |
---|
197 | // timings bug4: ratchwum: s, wilde13: s, nepomuck: s, lukas s |
---|
198 | l=IDLEV(h); |
---|
199 | if ((l==0)||(l==lev)) |
---|
200 | { |
---|
201 | id=IDID(h); |
---|
202 | if (*(short *)s==*(short *)id) |
---|
203 | { |
---|
204 | if (0 == strcmp(s+2,id+2)) |
---|
205 | { |
---|
206 | if (l==lev) return h; |
---|
207 | found=h; |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | #endif |
---|
212 | // ============================================================= |
---|
213 | h = IDNEXT(h); |
---|
214 | } |
---|
215 | } |
---|
216 | return found; |
---|
217 | } |
---|
218 | |
---|
219 | //idrec::~idrec() |
---|
220 | //{ |
---|
221 | // if (id!=NULL) |
---|
222 | // { |
---|
223 | // omFree((ADDRESS)id); |
---|
224 | // id=NULL; |
---|
225 | // } |
---|
226 | // /* much more !! */ |
---|
227 | //} |
---|
228 | |
---|
229 | idhdl idrec::set(char * s, int lev, idtyp t, BOOLEAN init) |
---|
230 | { |
---|
231 | //printf("define %s, %x, lev: %d, typ: %d\n", s,s,lev,t); |
---|
232 | idhdl h = (idrec *)omAlloc0Bin(idrec_bin); |
---|
233 | int len = 0; |
---|
234 | IDID(h) = s; |
---|
235 | IDTYP(h) = t; |
---|
236 | IDLEV(h) = lev; |
---|
237 | IDNEXT(h) = this; |
---|
238 | if (init) |
---|
239 | { |
---|
240 | switch (t) |
---|
241 | { |
---|
242 | //the type with init routines: |
---|
243 | case INTVEC_CMD: |
---|
244 | case INTMAT_CMD: |
---|
245 | IDINTVEC(h) = new intvec(); |
---|
246 | break; |
---|
247 | case NUMBER_CMD: |
---|
248 | IDNUMBER(h) = nInit(0); |
---|
249 | break; |
---|
250 | case IDEAL_CMD: |
---|
251 | case MODUL_CMD: |
---|
252 | IDFLAG(h) = Sy_bit(FLAG_STD); |
---|
253 | case MATRIX_CMD: |
---|
254 | IDIDEAL(h) = idInit(1,1); |
---|
255 | break; |
---|
256 | case MAP_CMD: |
---|
257 | IDIDEAL(h) = idInit(1,1); |
---|
258 | IDMAP(h)->preimage = omStrDup(IDID(currRingHdl)); |
---|
259 | break; |
---|
260 | case STRING_CMD: |
---|
261 | IDSTRING(h) = omStrDup(""); |
---|
262 | break; |
---|
263 | case LIST_CMD: |
---|
264 | IDLIST(h)=(lists)omAllocBin(slists_bin); |
---|
265 | IDLIST(h)->Init(); |
---|
266 | break; |
---|
267 | case LINK_CMD: |
---|
268 | IDLINK(h)=(si_link) omAlloc0Bin(sip_link_bin); |
---|
269 | break; |
---|
270 | case RING_CMD: |
---|
271 | case QRING_CMD: |
---|
272 | IDRING(h) = (ring) omAlloc0Bin(sip_sring_bin); |
---|
273 | break; |
---|
274 | case PACKAGE_CMD: |
---|
275 | IDPACKAGE(h) = (package) omAlloc0Bin(sip_package_bin); |
---|
276 | break; |
---|
277 | case PROC_CMD: |
---|
278 | IDPROC(h) = (procinfo*) omAlloc0Bin(procinfo_bin); |
---|
279 | break; |
---|
280 | //the types with the standard init: set the struct to zero |
---|
281 | case RESOLUTION_CMD: |
---|
282 | len=sizeof(ssyStrategy); |
---|
283 | break; |
---|
284 | //other types: without init (int,script,poly,def,package) |
---|
285 | } |
---|
286 | if (len!=0) |
---|
287 | { |
---|
288 | IDSTRING(h) = (char *)omAlloc0(len); |
---|
289 | } |
---|
290 | // additional settings:-------------------------------------- |
---|
291 | #if 0 |
---|
292 | // this leads to a memory leak |
---|
293 | if (t == QRING_CMD) |
---|
294 | { |
---|
295 | // IDRING(h)=rCopy(currRing); |
---|
296 | /* QRING_CMD is ring dep => currRing !=NULL */ |
---|
297 | } |
---|
298 | else |
---|
299 | #endif |
---|
300 | if (t == PROC_CMD) |
---|
301 | { |
---|
302 | IDPROC(h)->language=LANG_NONE; |
---|
303 | } |
---|
304 | else if (t == PACKAGE_CMD) |
---|
305 | { |
---|
306 | IDPACKAGE(h)->language=LANG_NONE; |
---|
307 | IDPACKAGE(h)->loaded = FALSE; |
---|
308 | } |
---|
309 | } |
---|
310 | // -------------------------------------------------------- |
---|
311 | return h; |
---|
312 | } |
---|
313 | |
---|
314 | char * idrec::String() |
---|
315 | { |
---|
316 | sleftv tmp; |
---|
317 | memset(&tmp,0,sizeof(sleftv)); |
---|
318 | tmp.rtyp=IDTYP(this); |
---|
319 | tmp.data=IDDATA(this); |
---|
320 | tmp.name=IDID(this); |
---|
321 | return tmp.String(); |
---|
322 | } |
---|
323 | |
---|
324 | //#define KAI |
---|
325 | idhdl enterid(char * s, int lev, idtyp t, idhdl* root, BOOLEAN init) |
---|
326 | { |
---|
327 | idhdl h; |
---|
328 | s=omStrDup(s); |
---|
329 | // is it already defined in root ? |
---|
330 | if ((h=(*root)->get(s,lev))!=NULL) |
---|
331 | { |
---|
332 | if (IDLEV(h)==lev) |
---|
333 | { |
---|
334 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
335 | { |
---|
336 | if ((IDTYP(h)==PACKAGE_CMD) |
---|
337 | && (strcmp(s,"Top")==0)) |
---|
338 | { |
---|
339 | goto errlabel; |
---|
340 | } |
---|
341 | if (BVERBOSE(V_REDEFINE)) |
---|
342 | Warn("redefining %s **",s); |
---|
343 | if (s==IDID(h)) IDID(h)=NULL; |
---|
344 | killhdl2(h,root,currRing); |
---|
345 | } |
---|
346 | else |
---|
347 | goto errlabel; |
---|
348 | } |
---|
349 | } |
---|
350 | // is it already defined in idroot ? |
---|
351 | else if (*root != IDROOT) |
---|
352 | { |
---|
353 | if ((h=IDROOT->get(s,lev))!=NULL) |
---|
354 | { |
---|
355 | if (IDLEV(h)==lev) |
---|
356 | { |
---|
357 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
358 | { |
---|
359 | if (BVERBOSE(V_REDEFINE)) |
---|
360 | Warn("redefining %s **",s); |
---|
361 | if (s==IDID(h)) IDID(h)=NULL; |
---|
362 | killhdl2(h,&IDROOT,NULL); |
---|
363 | } |
---|
364 | else |
---|
365 | goto errlabel; |
---|
366 | } |
---|
367 | } |
---|
368 | } |
---|
369 | // is it already defined in currRing->idroot ? |
---|
370 | else if ((currRing!=NULL)&&((*root) != currRing->idroot)) |
---|
371 | { |
---|
372 | if ((h=currRing->idroot->get(s,lev))!=NULL) |
---|
373 | { |
---|
374 | if (IDLEV(h)==lev) |
---|
375 | { |
---|
376 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
377 | { |
---|
378 | if (BVERBOSE(V_REDEFINE)) |
---|
379 | Warn("redefining %s **",s); |
---|
380 | IDID(h)=NULL; |
---|
381 | killhdl2(h,&currRing->idroot,currRing); |
---|
382 | } |
---|
383 | else |
---|
384 | goto errlabel; |
---|
385 | } |
---|
386 | } |
---|
387 | } |
---|
388 | *root = (*root)->set(s, lev, t, init); |
---|
389 | #ifdef HAVE_NS |
---|
390 | checkall(); |
---|
391 | #endif |
---|
392 | return *root; |
---|
393 | |
---|
394 | errlabel: |
---|
395 | //Werror("identifier `%s` in use(lev h=%d,typ=%d,t=%d, curr=%d)",s,IDLEV(h),IDTYP(h),t,lev); |
---|
396 | Werror("identifier `%s` in use",s); |
---|
397 | #ifdef HAVE_NS |
---|
398 | //listall(); |
---|
399 | #endif |
---|
400 | omFree(s); |
---|
401 | return NULL; |
---|
402 | } |
---|
403 | |
---|
404 | void killid(char * id, idhdl * ih) |
---|
405 | { |
---|
406 | if (id!=NULL) |
---|
407 | { |
---|
408 | idhdl h = (*ih)->get(id,myynest); |
---|
409 | |
---|
410 | // id not found in global list, is it defined in current ring ? |
---|
411 | if (h==NULL) |
---|
412 | { |
---|
413 | if ((currRing!=NULL) && (*ih != (currRing->idroot))) |
---|
414 | { |
---|
415 | h = currRing->idroot->get(id,myynest); |
---|
416 | if (h!=NULL) |
---|
417 | { |
---|
418 | killhdl2(h,&(currRing->idroot),currRing); |
---|
419 | return; |
---|
420 | } |
---|
421 | } |
---|
422 | Werror("`%s` is not defined",id); |
---|
423 | return; |
---|
424 | } |
---|
425 | killhdl2(h,ih,currRing); |
---|
426 | } |
---|
427 | else |
---|
428 | Werror("kill what ?"); |
---|
429 | } |
---|
430 | |
---|
431 | void killhdl(idhdl h) |
---|
432 | { |
---|
433 | int t=IDTYP(h); |
---|
434 | if ((BEGIN_RING<t) && (t<END_RING) && (t!=QRING_CMD)) |
---|
435 | killhdl2(h,&currRing->idroot,currRing); |
---|
436 | else |
---|
437 | { |
---|
438 | #ifdef HAVE_NS |
---|
439 | if(t==PACKAGE_CMD) |
---|
440 | { |
---|
441 | killhdl2(h,&(basePack->idroot),NULL); |
---|
442 | } |
---|
443 | else |
---|
444 | { |
---|
445 | idhdl s=currPack->idroot; |
---|
446 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
447 | if (s!=NULL) |
---|
448 | killhdl2(h,&(currPack->idroot),NULL); |
---|
449 | else if (basePack!=currPack) |
---|
450 | { |
---|
451 | idhdl s=basePack->idroot; |
---|
452 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
453 | if (s!=NULL) |
---|
454 | killhdl2(h,&(basePack->idroot),currRing); |
---|
455 | else |
---|
456 | killhdl2(h,&(currRing->idroot),currRing); |
---|
457 | } |
---|
458 | } |
---|
459 | #else /* HAVE_NS */ |
---|
460 | { |
---|
461 | idhdl s=IDROOT; |
---|
462 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
463 | if (s==NULL) killhdl2(h,&(currRing->idroot),currRing); |
---|
464 | else killhdl2(h,&IDROOT,currRing); |
---|
465 | } |
---|
466 | #endif /* HAVE_NS */ |
---|
467 | } |
---|
468 | } |
---|
469 | |
---|
470 | #ifdef HAVE_NS |
---|
471 | void killhdl(idhdl h, package proot) |
---|
472 | { |
---|
473 | int t=IDTYP(h); |
---|
474 | if ((BEGIN_RING<t) && (t<END_RING) && (t!=QRING_CMD)) |
---|
475 | killhdl2(h,&currRing->idroot,currRing); |
---|
476 | else |
---|
477 | { |
---|
478 | if(t==PACKAGE_CMD) |
---|
479 | { |
---|
480 | killhdl2(h,&(basePack->idroot),NULL); |
---|
481 | } |
---|
482 | else |
---|
483 | { |
---|
484 | idhdl s=proot->idroot; |
---|
485 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
486 | if (s!=NULL) |
---|
487 | killhdl2(h,&(proot->idroot),NULL); |
---|
488 | else if (basePack!=proot) |
---|
489 | { |
---|
490 | idhdl s=basePack->idroot; |
---|
491 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
492 | if (s!=NULL) |
---|
493 | killhdl2(h,&(basePack->idroot),currRing); |
---|
494 | else |
---|
495 | killhdl2(h,&(currRing->idroot),currRing); |
---|
496 | } |
---|
497 | } |
---|
498 | } |
---|
499 | } |
---|
500 | #endif /* HAVE_NS */ |
---|
501 | |
---|
502 | void killhdl2(idhdl h, idhdl * ih, ring r) |
---|
503 | { |
---|
504 | //printf("kill %s, id %x, typ %d lev: %d\n",IDID(h),(int)IDID(h),IDTYP(h),IDLEV(h)); |
---|
505 | idhdl hh; |
---|
506 | |
---|
507 | if (h->attribute!=NULL) |
---|
508 | { |
---|
509 | atKillAll(h); |
---|
510 | //h->attribute=NULL; |
---|
511 | } |
---|
512 | if ((IDTYP(h) == PACKAGE_CMD) && (strcmp(IDID(h),"Top")==0)) |
---|
513 | { |
---|
514 | WarnS("can not kill `Top`"); |
---|
515 | return; |
---|
516 | } |
---|
517 | // ring / qring -------------------------------------------------------- |
---|
518 | if ((IDTYP(h) == RING_CMD) || (IDTYP(h) == QRING_CMD)) |
---|
519 | { |
---|
520 | // any objects defined for this ring ? |
---|
521 | // Hmm ... why only for rings and not for qrings?? |
---|
522 | // if (((IDTYP(h)==RING_CMD) && (IDRING(h)->ref<=0)) |
---|
523 | if ((IDRING(h)->ref<=0) && (IDRING(h)->idroot!=NULL)) |
---|
524 | { |
---|
525 | idhdl * hd = &IDRING(h)->idroot; |
---|
526 | idhdl hdh = IDNEXT(*hd); |
---|
527 | idhdl temp; |
---|
528 | if (IDRING(h)==currRing) //we are not killing the base ring, so switch |
---|
529 | { |
---|
530 | // we are killing the basering, so: make sure that |
---|
531 | // sLastPrinted is killed before this ring is destroyed |
---|
532 | if (((sLastPrinted.rtyp>BEGIN_RING) && (sLastPrinted.rtyp<END_RING)) |
---|
533 | || ((sLastPrinted.rtyp==LIST_CMD)&&(lRingDependend((lists)sLastPrinted.data)))) |
---|
534 | { |
---|
535 | sLastPrinted.CleanUp(); |
---|
536 | } |
---|
537 | } |
---|
538 | while (hdh!=NULL) |
---|
539 | { |
---|
540 | temp = IDNEXT(hdh); |
---|
541 | killhdl2(hdh,&(IDRING(h)->idroot),IDRING(h)); |
---|
542 | hdh = temp; |
---|
543 | } |
---|
544 | killhdl2(*hd,hd,IDRING(h)); |
---|
545 | } |
---|
546 | rKill(h); |
---|
547 | } |
---|
548 | #ifdef HAVE_NS |
---|
549 | // package ------------------------------------------------------------- |
---|
550 | else if (IDTYP(h) == PACKAGE_CMD) |
---|
551 | { |
---|
552 | // any objects defined for this package ? |
---|
553 | if ((IDPACKAGE(h)->ref<=0) && (IDPACKAGE(h)->idroot!=NULL)) |
---|
554 | { |
---|
555 | if (currPack==IDPACKAGE(h)) |
---|
556 | { |
---|
557 | currPack=basePack; |
---|
558 | currPackHdl=NULL; |
---|
559 | } |
---|
560 | idhdl * hd = &IDRING(h)->idroot; |
---|
561 | idhdl hdh = IDNEXT(*hd); |
---|
562 | idhdl temp; |
---|
563 | while (hdh!=NULL) |
---|
564 | { |
---|
565 | temp = IDNEXT(hdh); |
---|
566 | killhdl2(hdh,&(IDPACKAGE(h)->idroot),NULL); |
---|
567 | hdh = temp; |
---|
568 | } |
---|
569 | killhdl2(*hd,hd,NULL); |
---|
570 | } |
---|
571 | paKill(IDPACKAGE(h)); |
---|
572 | if (currPackHdl==h) currPackHdl=packFindHdl(currPack); |
---|
573 | iiCheckPack(currPack); |
---|
574 | } |
---|
575 | #endif /* HAVE_NS */ |
---|
576 | // poly / vector ------------------------------------------------------- |
---|
577 | else if ((IDTYP(h) == POLY_CMD) || (IDTYP(h) == VECTOR_CMD)) |
---|
578 | { |
---|
579 | assume(r!=NULL); |
---|
580 | p_Delete(&IDPOLY(h),r); |
---|
581 | } |
---|
582 | // ideal / module/ matrix / map ---------------------------------------- |
---|
583 | else if ((IDTYP(h) == IDEAL_CMD) |
---|
584 | || (IDTYP(h) == MODUL_CMD) |
---|
585 | || (IDTYP(h) == MATRIX_CMD) |
---|
586 | || (IDTYP(h) == MAP_CMD)) |
---|
587 | { |
---|
588 | assume(r!=NULL); |
---|
589 | ideal iid = IDIDEAL(h); |
---|
590 | if (IDTYP(h) == MAP_CMD) |
---|
591 | { |
---|
592 | map im = IDMAP(h); |
---|
593 | omFree((ADDRESS)im->preimage); |
---|
594 | } |
---|
595 | id_Delete(&iid,r); |
---|
596 | } |
---|
597 | // string ------------------------------------------------------------- |
---|
598 | else if (IDTYP(h) == STRING_CMD) |
---|
599 | { |
---|
600 | omFree((ADDRESS)IDSTRING(h)); |
---|
601 | //IDSTRING(h)=NULL; |
---|
602 | } |
---|
603 | // proc --------------------------------------------------------------- |
---|
604 | else if (IDTYP(h) == PROC_CMD) |
---|
605 | { |
---|
606 | if (piKill(IDPROC(h))) return; |
---|
607 | } |
---|
608 | // number ------------------------------------------------------------- |
---|
609 | else if (IDTYP(h) == NUMBER_CMD) |
---|
610 | { |
---|
611 | assume(r!=NULL); |
---|
612 | n_Delete(&IDNUMBER(h),r); |
---|
613 | } |
---|
614 | // intvec / intmat --------------------------------------------------- |
---|
615 | else if ((IDTYP(h) == INTVEC_CMD)||(IDTYP(h) == INTMAT_CMD)) |
---|
616 | { |
---|
617 | delete IDINTVEC(h); |
---|
618 | } |
---|
619 | // list ------------------------------------------------------------- |
---|
620 | else if (IDTYP(h)==LIST_CMD) |
---|
621 | { |
---|
622 | IDLIST(h)->Clean(r); |
---|
623 | //omFreeSize((ADDRESS)IDLIST(h)->m, (IDLIST(h)->nr+1)*sizeof(sleftv)); |
---|
624 | //omFreeBin((ADDRESS)IDLIST(h), slists_bin); |
---|
625 | } |
---|
626 | // link ------------------------------------------------------------- |
---|
627 | else if (IDTYP(h)==LINK_CMD) |
---|
628 | { |
---|
629 | slKill(IDLINK(h)); |
---|
630 | } |
---|
631 | else if(IDTYP(h)==RESOLUTION_CMD) |
---|
632 | { |
---|
633 | assume(r!=NULL); |
---|
634 | if (IDDATA(h)!=NULL) |
---|
635 | syKillComputation((syStrategy)IDDATA(h),r); |
---|
636 | } |
---|
637 | #ifdef TEST |
---|
638 | else if ((IDTYP(h)!= INT_CMD)&&(IDTYP(h)!=DEF_CMD) && (IDTYP(h)!=NONE)) |
---|
639 | Warn("unknown type to kill: %s(%d)",Tok2Cmdname(IDTYP(h)),IDTYP(h)); |
---|
640 | #endif |
---|
641 | |
---|
642 | // general ------------------------------------------------------------- |
---|
643 | // now dechain it and delete idrec |
---|
644 | #ifdef KAI |
---|
645 | if(h->next != NULL) |
---|
646 | Print("=======>%s(%x) -> %s<====\n", IDID(h), IDID(h), IDID(h->next)); |
---|
647 | else |
---|
648 | Print("=======>%s(%x)<====\n", IDID(h), IDID(h)); |
---|
649 | #endif |
---|
650 | |
---|
651 | if (IDID(h)) // OB: ????? |
---|
652 | omFree((ADDRESS)IDID(h)); |
---|
653 | IDID(h)=NULL; |
---|
654 | if (h == (*ih)) |
---|
655 | { |
---|
656 | // h is at the beginning of the list |
---|
657 | *ih = IDNEXT(h) /* ==*ih */; |
---|
658 | } |
---|
659 | else |
---|
660 | { |
---|
661 | // h is somethere in the list: |
---|
662 | hh = *ih; |
---|
663 | loop |
---|
664 | { |
---|
665 | if (hh==NULL) |
---|
666 | { |
---|
667 | PrintS(">>?<< not found for kill\n"); |
---|
668 | return; |
---|
669 | } |
---|
670 | idhdl hhh = IDNEXT(hh); |
---|
671 | if (hhh == h) |
---|
672 | { |
---|
673 | IDNEXT(hh) = IDNEXT(hhh); |
---|
674 | break; |
---|
675 | } |
---|
676 | hh = hhh; |
---|
677 | } |
---|
678 | } |
---|
679 | omFreeBin((ADDRESS)h, idrec_bin); |
---|
680 | } |
---|
681 | |
---|
682 | idhdl ggetid(const char *n, BOOLEAN local, idhdl *packhdl) |
---|
683 | { |
---|
684 | idhdl h = IDROOT->get(n,myynest); |
---|
685 | idhdl h2=NULL; |
---|
686 | *packhdl = NULL; |
---|
687 | if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest))) |
---|
688 | { |
---|
689 | h2 = currRing->idroot->get(n,myynest); |
---|
690 | } |
---|
691 | if (h2==NULL) return h; |
---|
692 | return h2; |
---|
693 | } |
---|
694 | |
---|
695 | idhdl ggetid(const char *n, BOOLEAN local) |
---|
696 | { |
---|
697 | idhdl h = IDROOT->get(n,myynest); |
---|
698 | if ((h!=NULL)&&(IDLEV(h)==myynest)) return h; |
---|
699 | idhdl h2=NULL; |
---|
700 | if (currRing!=NULL) |
---|
701 | { |
---|
702 | h2 = currRing->idroot->get(n,myynest); |
---|
703 | } |
---|
704 | if (h2!=NULL) return h2; |
---|
705 | if (h!=NULL) return h; |
---|
706 | #ifdef HAVE_NS |
---|
707 | if (basePack!=currPack) |
---|
708 | return basePack->idroot->get(n,myynest); |
---|
709 | #endif |
---|
710 | return NULL; |
---|
711 | } |
---|
712 | |
---|
713 | void ipListFlag(idhdl h) |
---|
714 | { |
---|
715 | if (hasFlag(h,FLAG_STD)) PrintS(" (SB)"); |
---|
716 | #ifdef HAVE_PLURAL |
---|
717 | if (hasFlag(h,FLAG_TWOSTD)) PrintS(" (2SB)"); |
---|
718 | #endif |
---|
719 | } |
---|
720 | |
---|
721 | lists ipNameList(idhdl root) |
---|
722 | { |
---|
723 | idhdl h=root; |
---|
724 | /* compute the length */ |
---|
725 | int l=0; |
---|
726 | while (h!=NULL) { l++; h=IDNEXT(h); } |
---|
727 | /* allocate list */ |
---|
728 | lists L=(lists)omAllocBin(slists_bin); |
---|
729 | L->Init(l); |
---|
730 | /* copy names */ |
---|
731 | h=root; |
---|
732 | l=0; |
---|
733 | while (h!=NULL) |
---|
734 | { |
---|
735 | /* list is initialized with 0 => no need to clear anything */ |
---|
736 | L->m[l].rtyp=STRING_CMD; |
---|
737 | L->m[l].data=omStrDup(IDID(h)); |
---|
738 | l++; |
---|
739 | h=IDNEXT(h); |
---|
740 | } |
---|
741 | return L; |
---|
742 | } |
---|
743 | |
---|
744 | /* |
---|
745 | * move 'tomove' from root1 list to root2 list |
---|
746 | */ |
---|
747 | static int ipSwapId(idhdl tomove, idhdl &root1, idhdl &root2) |
---|
748 | { |
---|
749 | idhdl h; |
---|
750 | /* search 'tomove' in root2 : if found -> do nothing */ |
---|
751 | h=root2; |
---|
752 | while ((h!=NULL) && (h!=tomove)) h=IDNEXT(h); |
---|
753 | if (h!=NULL) return FALSE; /*okay */ |
---|
754 | /* search predecessor of h in root1, remove 'tomove' */ |
---|
755 | h=root1; |
---|
756 | if (tomove==h) |
---|
757 | { |
---|
758 | root1=IDNEXT(h); |
---|
759 | } |
---|
760 | else |
---|
761 | { |
---|
762 | while ((h!=NULL) && (IDNEXT(h)!=tomove)) h=IDNEXT(h); |
---|
763 | if (h==NULL) return TRUE; /* not in the list root1 -> do nothing */ |
---|
764 | IDNEXT(h)=IDNEXT(tomove); |
---|
765 | } |
---|
766 | /* add to root2 list */ |
---|
767 | IDNEXT(tomove)=root2; |
---|
768 | root2=tomove; |
---|
769 | return FALSE; |
---|
770 | } |
---|
771 | |
---|
772 | void ipMoveId(idhdl tomove) |
---|
773 | { |
---|
774 | if ((currRing!=NULL)&&(tomove!=NULL)) |
---|
775 | { |
---|
776 | if (((QRING_CMD!=IDTYP(tomove)) && RingDependend(IDTYP(tomove))) |
---|
777 | || ((IDTYP(tomove)==LIST_CMD) && (lRingDependend(IDLIST(tomove))))) |
---|
778 | { |
---|
779 | /*move 'tomove' to ring id's*/ |
---|
780 | #ifdef HAVE_NS |
---|
781 | if (ipSwapId(tomove,IDROOT,currRing->idroot)) |
---|
782 | ipSwapId(tomove,basePack->idroot,currRing->idroot); |
---|
783 | #else |
---|
784 | ipSwapId(tomove,IDROOT,currRing->idroot); |
---|
785 | #endif |
---|
786 | } |
---|
787 | else |
---|
788 | { |
---|
789 | /*move 'tomove' to global id's*/ |
---|
790 | ipSwapId(tomove,currRing->idroot,IDROOT); |
---|
791 | } |
---|
792 | } |
---|
793 | } |
---|
794 | |
---|
795 | char * piProcinfo(procinfov pi, char *request) |
---|
796 | { |
---|
797 | if(pi == NULL) return "empty proc"; |
---|
798 | else if (strcmp(request, "libname") == 0) return pi->libname; |
---|
799 | else if (strcmp(request, "procname") == 0) return pi->procname; |
---|
800 | else if (strcmp(request, "type") == 0) |
---|
801 | { |
---|
802 | switch (pi->language) |
---|
803 | { |
---|
804 | case LANG_SINGULAR: return "singular"; break; |
---|
805 | case LANG_C: return "object"; break; |
---|
806 | case LANG_NONE: return "none"; break; |
---|
807 | default: return "unknow language"; |
---|
808 | } |
---|
809 | } |
---|
810 | else if (strcmp(request, "ref") == 0) |
---|
811 | { |
---|
812 | char p[8]; |
---|
813 | sprintf(p, "%d", pi->ref); |
---|
814 | return omStrDup(p); // MEMORY-LEAK |
---|
815 | } |
---|
816 | return "??"; |
---|
817 | } |
---|
818 | |
---|
819 | void piCleanUp(procinfov pi) |
---|
820 | { |
---|
821 | (pi->ref)--; |
---|
822 | if (pi->ref <= 0) |
---|
823 | { |
---|
824 | if (pi->libname != NULL) // OB: ???? |
---|
825 | omFree((ADDRESS)pi->libname); |
---|
826 | if (pi->procname != NULL) // OB: ???? |
---|
827 | omFree((ADDRESS)pi->procname); |
---|
828 | |
---|
829 | if( pi->language == LANG_SINGULAR) |
---|
830 | { |
---|
831 | if (pi->data.s.body != NULL) // OB: ???? |
---|
832 | omFree((ADDRESS)pi->data.s.body); |
---|
833 | } |
---|
834 | if( pi->language == LANG_C) |
---|
835 | { |
---|
836 | } |
---|
837 | memset((void *) pi, 0, sizeof(procinfo)); |
---|
838 | pi->language=LANG_NONE; |
---|
839 | } |
---|
840 | } |
---|
841 | |
---|
842 | BOOLEAN piKill(procinfov pi) |
---|
843 | { |
---|
844 | Voice *p=currentVoice; |
---|
845 | while (p!=NULL) |
---|
846 | { |
---|
847 | if (p->pi==pi && pi->ref <= 1) |
---|
848 | { |
---|
849 | Warn("`%s` in use, can not be killed",pi->procname); |
---|
850 | return TRUE; |
---|
851 | } |
---|
852 | p=p->next; |
---|
853 | } |
---|
854 | piCleanUp(pi); |
---|
855 | if (pi->ref <= 0) |
---|
856 | omFreeBin((ADDRESS)pi, procinfo_bin); |
---|
857 | return FALSE; |
---|
858 | } |
---|
859 | |
---|
860 | void paCleanUp(package pack) |
---|
861 | { |
---|
862 | (pack->ref)--; |
---|
863 | if (pack->ref < 0) |
---|
864 | { |
---|
865 | #ifndef HAVE_STATIC |
---|
866 | if( pack->language == LANG_C) |
---|
867 | { |
---|
868 | Print("//dlclose(%s)\n",pack->libname); |
---|
869 | #ifdef HAVE_DYNAMIC_LOADING |
---|
870 | dynl_close (pack->handle); |
---|
871 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
872 | } |
---|
873 | #endif /* HAVE_STATIC */ |
---|
874 | omfree((ADDRESS)pack->libname); |
---|
875 | memset((void *) pack, 0, sizeof(sip_package)); |
---|
876 | pack->language=LANG_NONE; |
---|
877 | } |
---|
878 | } |
---|
879 | |
---|
880 | char *idhdl2id(idhdl pck, idhdl h) |
---|
881 | { |
---|
882 | char *name = (char *)omAlloc(strlen(pck->id) + strlen(h->id) + 3); |
---|
883 | sprintf(name, "%s::%s", pck->id, h->id); |
---|
884 | return(name); |
---|
885 | } |
---|
886 | |
---|
887 | void iiname2hdl(const char *name, idhdl *pck, idhdl *h) |
---|
888 | { |
---|
889 | const char *q = strchr(name, ':'); |
---|
890 | char *p, *i; |
---|
891 | |
---|
892 | if(q==NULL) |
---|
893 | { |
---|
894 | p = omStrDup(""); |
---|
895 | i = (char *)omAlloc(strlen(name)+1); |
---|
896 | *i = '\0'; |
---|
897 | sscanf(name, "%s", i); |
---|
898 | } |
---|
899 | else { |
---|
900 | if( *(q+1) != ':') return; |
---|
901 | i = (char *)omAlloc(strlen(name)+1); |
---|
902 | *i = '\0'; |
---|
903 | if(name == q) |
---|
904 | { |
---|
905 | p = omStrDup(""); |
---|
906 | sscanf(name, "::%s", i); |
---|
907 | } |
---|
908 | else |
---|
909 | { |
---|
910 | p = (char *)omAlloc(strlen(name)+1); |
---|
911 | sscanf(name, "%[^:]::%s", p, i); |
---|
912 | } |
---|
913 | } |
---|
914 | //printf("Package: '%s'\n", p); |
---|
915 | //printf("Id Rec : '%s'\n", i); |
---|
916 | omFree(p); |
---|
917 | omFree(i); |
---|
918 | } |
---|
919 | |
---|
920 | #if 0 |
---|
921 | char *getnamelev() |
---|
922 | { |
---|
923 | char buf[256]; |
---|
924 | sprintf(buf, "(%s:%d)", namespaceroot->name,namespaceroot->lev); |
---|
925 | return(buf); |
---|
926 | } |
---|
927 | // warning: address of local variable `buf' returned |
---|
928 | #endif |
---|
929 | |
---|
930 | void proclevel::push(char *n) |
---|
931 | { |
---|
932 | //Print("push %s\n",n); |
---|
933 | proclevel *p=(proclevel*)omAlloc0(sizeof(proclevel)); |
---|
934 | p->cRing=currRing; |
---|
935 | p->cRingHdl=currRingHdl; |
---|
936 | p->name=n; |
---|
937 | #ifdef HAVE_NS |
---|
938 | p->cPackHdl=currPackHdl; |
---|
939 | p->cPack=currPack; |
---|
940 | #endif |
---|
941 | p->next=this; |
---|
942 | procstack=p; |
---|
943 | } |
---|
944 | void proclevel::pop() |
---|
945 | { |
---|
946 | //Print("pop %s\n",name); |
---|
947 | //if (currRing!=::currRing) PrintS("currRing wrong\n");; |
---|
948 | //::currRing=this->currRing; |
---|
949 | //if (r==NULL) Print("set ring to NULL at lev %d(%s)\n",myynest,name); |
---|
950 | //::currRingHdl=this->currRingHdl; |
---|
951 | //if((::currRingHdl==NULL)||(IDRING(::currRingHdl)!=(::currRing))) |
---|
952 | // ::currRingHdl=rFindHdl(::currRing,NULL,NULL); |
---|
953 | #ifdef HAVE_NS |
---|
954 | //Print("restore pack=%s,1.obj=%s\n",IDID(currPackHdl),IDID(currPack->idroot)); |
---|
955 | currPackHdl=this->cPackHdl; |
---|
956 | currPack=this->cPack; |
---|
957 | iiCheckPack(currPack); |
---|
958 | #endif |
---|
959 | proclevel *p=this; |
---|
960 | procstack=next; |
---|
961 | omFreeSize(p,sizeof(proclevel)); |
---|
962 | } |
---|
963 | |
---|
964 | #ifdef HAVE_NS |
---|
965 | idhdl packFindHdl(package r) |
---|
966 | { |
---|
967 | idhdl h=basePack->idroot; |
---|
968 | while (h!=NULL) |
---|
969 | { |
---|
970 | if ((IDTYP(h)==PACKAGE_CMD) |
---|
971 | && (IDPACKAGE(h)==r)) |
---|
972 | return h; |
---|
973 | h=IDNEXT(h); |
---|
974 | } |
---|
975 | return NULL; |
---|
976 | } |
---|
977 | #endif |
---|