Changeset 6e30ee1 in tol


Ignore:
Timestamp:
Jan 23, 2009, 11:35:13 AM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
1f5af94
Parents:
3ac3a3f
Message:

New methods to make a list of selected members in plain (SelectMembers) and recursive (SelectMembersDeep) modes

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@453 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol/btol/bgrammar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/bgrammar/nameblock.cpp

    r3ac3a3f r6e30ee1  
    107107//--------------------------------------------------------------------
    108108{
     109  static BText currentFullName = "";
    109110  const BText& name = BEqualOperator::CreatingName();
    110111//Std(BText("BNameBlock::EvaluateTree:\n")+BParser::treWrite((List*)tre,"  "));
    111112  BBool hasName = name.HasName();
    112113  BText fullName = name;
    113   if(BNameBlock::current_ && hasName)
    114   {
    115     fullName = BNameBlock::current_->Name()+"::"+name;
    116   }
     114  BText oldFullName = currentFullName;
     115  if(hasName)
     116  {
     117    if(currentFullName.HasName())
     118    {
     119      fullName = currentFullName+"::"+name;
     120    }
     121    currentFullName = fullName;
     122  }
     123  BUserNameBlock* ns_result = NULL;
    117124  BSyntaxObject* result = NULL;
    118125  int level = BGrammar::Level();
    … …  
    138145          I2("Current NameBlock is ",
    139146             "El NameBlock en curso es ")+BNameBlock::current_->Name()));
    140     return(NULL);
    141   }
    142 //const BNameBlock* oldNameBlock = BNameBlock::current_;
    143   BUserNameBlock* ns_result = new BGraContensP<BNameBlock>(new BNameBlock);
    144   BNameBlock& newNameBlock  = ns_result->Contens();
    145   newNameBlock.PutName(fullName);
    146 //BNameBlock::current_ = &newNameBlock;
    147   int oldErr = (int)TOLErrorNumber().Value();
    148   BGrammar::IncLevel();
    149   int stackPos = BGrammar::StackSize();
    150   BSyntaxObject* set_result = GraSet()->EvaluateTree(tre);
    151   BGrammar::DestroyStackUntil(stackPos, set_result);
    152   BGrammar::DecLevel();
    153   int numErr = (int)TOLErrorNumber().Value()-oldErr;
    154   if(!set_result || (set_result->Grammar()!=GraSet()))
    155   {
    156     DESTROY(set_result);
    157     DESTROY(ns_result);
    158   }
    159   if(set_result)
    160   {
    161     BUserSet* uSet = USet(set_result);
    162     if(!newNameBlock.Fill(uSet->Contens()))
     147  }
     148  else
     149  {
     150  //const BNameBlock* oldNameBlock = BNameBlock::current_;
     151    ns_result = new BGraContensP<BNameBlock>(new BNameBlock);
     152    BNameBlock& newNameBlock  = ns_result->Contens();
     153    newNameBlock.PutName(fullName);
     154  //BNameBlock::current_ = &newNameBlock;
     155    int oldErr = (int)TOLErrorNumber().Value();
     156    BGrammar::IncLevel();
     157    int stackPos = BGrammar::StackSize();
     158    BSyntaxObject* set_result = GraSet()->EvaluateTree(tre);
     159    BGrammar::DestroyStackUntil(stackPos, set_result);
     160    BGrammar::DecLevel();
     161    int numErr = (int)TOLErrorNumber().Value()-oldErr;
     162    if(!set_result || (set_result->Grammar()!=GraSet()))
    163163    {
    164164      DESTROY(set_result);
    165165      DESTROY(ns_result);
    166166    }
    167   }
    168 //BNameBlock::current_ = oldNameBlock;
    169   if(!set_result)
    170   {
    171     Error(I2("Cannot build NameBlock ",
    172              "No se puede contruir el NameBlock  ")+name);
    173     bool assigned = (ns_result && (ns_result->IsAssigned()==1));
    174     if(assigned) { DESTROY(ns_result); }
    175   }
    176   else
    177   {
    178     if(numErr)
    179     {
    180       Warning(BText("NameBlock ")+name+" "+
    181               I2("has been built with",
    182                  "se ha construido con") + " "+numErr+" "+
    183               I2("errors.","errores."));
    184     }
    185     DESTROY(set_result);
    186   }
     167    if(set_result)
     168    {
     169      BUserSet* uSet = USet(set_result);
     170      if(!newNameBlock.Fill(uSet->Contens()))
     171      {
     172        DESTROY(set_result);
     173        DESTROY(ns_result);
     174      }
     175    }
     176  //BNameBlock::current_ = oldNameBlock;
     177    if(!set_result)
     178    {
     179      Error(I2("Cannot build NameBlock ",
     180               "No se puede contruir el NameBlock  ")+name);
     181      bool assigned = (ns_result && (ns_result->IsAssigned()==1));
     182      if(assigned) { DESTROY(ns_result); }
     183    }
     184    else
     185    {
     186      if(numErr)
     187      {
     188        Warning(BText("NameBlock ")+name+" "+
     189                I2("has been built with",
     190                   "se ha construido con") + " "+numErr+" "+
     191                I2("errors.","errores."));
     192      }
     193      DESTROY(set_result);
     194    }
     195  }
     196  currentFullName = oldFullName;
    187197  return(ns_result);
    188198}
    … …  
    444454  }
    445455}
     456
     457//--------------------------------------------------------------------
     458  BList* BNameBlock::SelectMembers(BList* lst, const BObjClassify&  oc)
     459//--------------------------------------------------------------------
     460{
     461//Std(BText("\n")+"BNameBlock::SelectMembers Exploring NameBlock "+Name());
     462  BSyntaxObject* obj;
     463  BObjByNameHash::const_iterator iter;
     464//Std(BText("\n")+" Seaching for "+GetModeName(oc.mode_)+" "+oc.grammar_->Name());
     465  for(iter=public_.begin(); iter!=public_.end(); iter++)
     466  {
     467    obj = iter->second;
     468    if((oc.mode_==BUSERFUNMODE) &&
     469       (obj->Mode()==BOBJECTMODE) &&
     470       (obj->Grammar()==GraCode()))
     471    {
     472      BUserCode* uc = (BUserCode*)obj;
     473      obj = uc->Contens().Operator();
     474    }
     475    bool match = (obj->Grammar()==oc.grammar_) && (obj->Mode()==oc.mode_);
     476    if(match)
     477    {
     478    //Std(BText("\n")+"  "+GetModeName(obj->Mode())+" "+obj->Grammar()->Name()+" "+obj->Name()+" matches? "+int(match));
     479      lst = Cons(obj,lst);
     480    }
     481  }
     482  return(lst);
     483}
     484
     485//--------------------------------------------------------------------
     486  BList* BNameBlock::SelectMembersDeep(BList* lst, const BObjClassify&  oc)
     487//--------------------------------------------------------------------
     488{
     489//Std(BText("\n")+"BNameBlock::SelectMembersDeep Exploring NameBlock "+Name());
     490  lst = SelectMembers(lst, oc);
     491  BSyntaxObject* obj;
     492  BObjByNameHash::const_iterator iter;
     493  for(iter=public_.begin(); iter!=public_.end(); iter++)
     494  {
     495    obj = iter->second;
     496    if((obj->Grammar()==GraNameBlock()) && (obj->Mode()==BOBJECTMODE))
     497    {
     498      BUserNameBlock* unb = (BUserNameBlock*)obj;
     499      lst = unb->Contens().SelectMembersDeep(lst, oc);
     500    }
     501  }
     502  return(lst);
     503}
     504
    446505
    447506//--------------------------------------------------------------------
  • tol/btol/bgrammar/tol_bnameblock.h

    r3ac3a3f r6e30ee1  
    131131  BSyntaxObject* PublicMember (const BText& memberName) const;
    132132  BSyntaxObject* PrivateMember(const BText& memberName) const;
     133  BList* SelectMembers(BList* lst, const BObjClassify&  oc);
     134  BList* SelectMembersDeep(BList* lst, const BObjClassify&  oc);
    133135
    134136  DeclareClassNewDelete(BNameBlock);
Note: See TracChangeset for help on using the changeset viewer.