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