Changeset f2749c in git


Ignore:
Timestamp:
Apr 2, 2019, 1:24:01 PM (5 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
d20e96946730123ff9fe475bded1ae950d09590d
Parents:
befd80dcf6854e395b3758a678e1384360f63f4b
Message:
add idrec::get_level, opt. ggetid, idrec::get
Location:
Singular
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Singular/idrec.h

    rbefd80d rf2749c  
    4949  idrec() { memset(this,0,sizeof(*this)); }
    5050  idhdl get(const char * s, int lev);
     51  idhdl get_level(const char * s, int lev);
    5152  idhdl set(const char * s, int lev, int t/*typ*/, BOOLEAN init=TRUE);
    5253  char * String(BOOLEAN typed = FALSE);
  • Singular/ipid.cc

    rbefd80d rf2749c  
    9999  }
    100100  return found;
     101}
     102
     103idhdl idrec::get_level(const char * s, int level)
     104{
     105  assume(s!=NULL);
     106  assume((level>=0) && (level<=1000)); //not really, but if it isnt in that bounds..
     107  idhdl h = this;
     108  int l;
     109  const char *id_;
     110  unsigned long i=iiS2I(s);
     111  int less4=(i < (1L<<((SIZEOF_LONG-1)*8)));
     112  while (h!=NULL)
     113  {
     114    omCheckAddr((ADDRESS)IDID(h));
     115    l=IDLEV(h);
     116    if ((l==level)&&(i==h->id_i))
     117    {
     118      id_=IDID(h);
     119      if (less4 || (0 == strcmp(s+SIZEOF_LONG,id_+SIZEOF_LONG)))
     120      {
     121        return h;
     122      }
     123    }
     124    h = IDNEXT(h);
     125  }
     126  return NULL;
    101127}
    102128
     
    266292  }
    267293  // is it already defined in root ?
    268   if ((h=(*root)->get(s,lev))!=NULL)
    269   {
    270     if (IDLEV(h)==lev)
     294  if ((h=(*root)->get_level(s,lev))!=NULL)
     295  {
     296    if ((IDTYP(h) == t)||(t==DEF_CMD))
     297    {
     298      if (IDTYP(h)==PACKAGE_CMD)
     299      {
     300        if (strcmp(s,"Top")==0)
     301        {
     302          goto errlabel;
     303        }
     304        else return h;
     305      }
     306      else
     307      {
     308        if (BVERBOSE(V_REDEFINE))
     309        {
     310          const char *f=VoiceName();
     311          if (strcmp(f,"STDIN")==0)
     312            Warn("redefining %s (%s)",s,my_yylinebuf);
     313          else
     314            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
     315        }
     316        if (s==IDID(h)) IDID(h)=NULL;
     317        killhdl2(h,root,currRing);
     318      }
     319    }
     320    else
     321      goto errlabel;
     322  }
     323  // is it already defined in currRing->idroot ?
     324  else if (search && (currRing!=NULL)&&((*root) != currRing->idroot))
     325  {
     326    if ((h=currRing->idroot->get_level(s,lev))!=NULL)
    271327    {
    272328      if ((IDTYP(h) == t)||(t==DEF_CMD))
    273329      {
    274         if (IDTYP(h)==PACKAGE_CMD)
     330        if (BVERBOSE(V_REDEFINE))
    275331        {
    276           if (strcmp(s,"Top")==0)
    277           {
    278             goto errlabel;
    279           }
    280           else return h;
     332          const char *f=VoiceName();
     333          if (strcmp(f,"STDIN")==0)
     334            Warn("redefining %s (%s)",s,my_yylinebuf);
     335          else
     336            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
    281337        }
    282         else
    283         {
    284           if (BVERBOSE(V_REDEFINE))
    285           {
    286             const char *f=VoiceName();
    287             if (strcmp(f,"STDIN")==0)
    288               Warn("redefining %s (%s)",s,my_yylinebuf);
    289             else
    290               Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
    291           }
    292           if (s==IDID(h)) IDID(h)=NULL;
    293           killhdl2(h,root,currRing);
    294         }
     338        if (s==IDID(h)) IDID(h)=NULL;
     339        killhdl2(h,&currRing->idroot,currRing);
    295340      }
    296341      else
     
    298343    }
    299344  }
    300   // is it already defined in currRing->idroot ?
    301   else if (search && (currRing!=NULL)&&((*root) != currRing->idroot))
    302   {
    303     if ((h=currRing->idroot->get(s,lev))!=NULL)
    304     {
    305       if (IDLEV(h)==lev)
    306       {
    307         if ((IDTYP(h) == t)||(t==DEF_CMD))
    308         {
    309           if (BVERBOSE(V_REDEFINE))
    310           {
    311             const char *f=VoiceName();
    312             if (strcmp(f,"STDIN")==0)
    313               Warn("redefining %s (%s)",s,my_yylinebuf);
    314             else
    315               Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
    316           }
    317           if (s==IDID(h)) IDID(h)=NULL;
    318           killhdl2(h,&currRing->idroot,currRing);
    319         }
    320         else
    321           goto errlabel;
    322       }
    323     }
    324   }
    325345  // is it already defined in idroot ?
    326346  else if (search && (*root != IDROOT))
    327347  {
    328     if ((h=IDROOT->get(s,lev))!=NULL)
    329     {
    330       if (IDLEV(h)==lev)
    331       {
    332         if ((IDTYP(h) == t)||(t==DEF_CMD))
     348    if ((h=IDROOT->get_level(s,lev))!=NULL)
     349    {
     350      if ((IDTYP(h) == t)||(t==DEF_CMD))
     351      {
     352        if (BVERBOSE(V_REDEFINE))
    333353        {
    334           if (BVERBOSE(V_REDEFINE))
    335           {
    336             const char *f=VoiceName();
    337             if (strcmp(f,"STDIN")==0)
    338               Warn("redefining %s (%s)",s,my_yylinebuf);
    339             else
    340               Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
    341           }
    342           if (s==IDID(h)) IDID(h)=NULL;
    343           killhdl2(h,&IDROOT,NULL);
     354          const char *f=VoiceName();
     355          if (strcmp(f,"STDIN")==0)
     356            Warn("redefining %s (%s)",s,my_yylinebuf);
     357          else
     358            Warn("redefining %s (%s) %s:%d",s,my_yylinebuf,f, yylineno);
    344359        }
    345         else
    346           goto errlabel;
    347       }
     360        if (s==IDID(h)) IDID(h)=NULL;
     361        killhdl2(h,&IDROOT,NULL);
     362      }
     363      else
     364        goto errlabel;
    348365    }
    349366  }
     
    527544idhdl ggetid(const char *n)
    528545{
    529   idhdl h = IDROOT->get(n,myynest);
    530   if ((h!=NULL)&&(IDLEV(h)==myynest)) return h;
    531546  if (currRing!=NULL)
    532547  {
    533548    idhdl h2 = currRing->idroot->get(n,myynest);
     549    if ((h2!=NULL)&&(IDLEV(h2)==myynest)) return h2;
     550    idhdl h = IDROOT->get(n,myynest);
     551    if (h!=NULL) return h;
    534552    if (h2!=NULL) return h2;
    535553  }
    536   if (h!=NULL) return h;
     554  else
     555  {
     556    idhdl h = IDROOT->get(n,myynest);
     557    if (h!=NULL) return h;
     558  }
    537559  if (basePack!=currPack)
    538560    return basePack->idroot->get(n,myynest);
Note: See TracChangeset for help on using the changeset viewer.