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