Changeset 0e767dc in tol


Ignore:
Timestamp:
Jul 3, 2012, 9:33:03 PM (14 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
8e7b274
Parents:
0d63276
Message:

Fixes #1558 in 3.2
Fixes #1559 in 3.2
Fixes #1560 in 3.2

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

Location:
tol
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • tol/OIS/oisloader.cpp

    r0d63276 r0e767dc  
    510510      mbr->isStatic_ = isStatic!=0;
    511511      mbr->isGood_ = true;
    512       mbr->BuildMethod();
    513       mbr->BuildStatic();
     512      mbr->BuildAll();
    514513    }
    515514    else
    … …  
    842841    else if(mode==BCLASSMODE)
    843842    {
    844       BClass* cls = BClass::PredeclareClass(name);
     843      BClass* cls = BClass::PredeclareClassIfNeeded(name);
    845844      Ensure(cls);
    846845      Ensure(Read(*cls,object_));
    … …  
    10411040              ERead(className, set_);
    10421041            //Std(BText("\nBOisLoader::ReadNextObject Predeclared Class ")+className);
    1043               BClass::PredeclareClass(className);
     1042              BClass::PredeclareClassIfNeeded(className);
    10441043            }
    10451044          }
    … …  
    10901089              ERead(className, set_);
    10911090            //Std(BText("\nBOisLoader::ReadNextObject Predeclared Class ")+className);
    1092               BClass::PredeclareClass(className);
     1091              BClass::PredeclareClassIfNeeded(className);
    10931092            }
    10941093          }
    … …  
    11551154          ERead(offset, object_);
    11561155          set_->SetPos(offset);
     1156          BGrammar::IncLevel();
    11571157          if(control_.oisEngine_.oisVersion_>="02.15")
    11581158          {
    … …  
    11641164              ERead(className, set_);
    11651165            //Std(BText("\nBOisLoader::ReadNextObject Predeclared Class ")+className);
    1166               BClass::PredeclareClass(className);
     1166              BClass::PredeclareClassIfNeeded(className);
    11671167            }
    11681168          }
    … …  
    12051205              BText className;
    12061206              ERead(className, set_);
    1207               BClass::PredeclareClass(className);
     1207              BClass::PredeclareClassIfNeeded(className);
    12081208            }
    12091209          }
    … …  
    12241224          BSyntaxObject* r=NULL;
    12251225          x.Set().PrepareStore(s);
    1226           BGrammar::IncLevel();
    12271226          for(n=1; n<=s; n++)
    12281227          {
  • tol/btol/bgrammar/class.cpp

    r0d63276 r0e767dc  
    6666  isStatic_    (false),
    6767  static_      (NULL),
    68   description_ ("")
     68  description_ (""),
     69  type_        (NULL),
     70  class_       (NULL),
     71  struct_      (NULL)
    6972{
    7073}
    … …  
    8588  isStatic_    (false),
    8689  static_      (NULL),
    87   description_ ("")
     90  description_ (""),
     91  type_        (NULL),
     92  class_       (NULL),
     93  struct_      (NULL)
    8894{
    8995  Copy(mbr);
    9096}
     97
     98
     99//--------------------------------------------------------------------
     100  void CleanLeftAndRightChar(BText& expression, char begin, char end)
     101//--------------------------------------------------------------------
     102{
     103  int fst = 0;
     104  int lst = expression.Length()-1;
     105  while(expression[fst]==begin) { fst++; }
     106  while(expression[lst]==end  ) { lst--; }
     107  expression = expression.SubString(fst,lst);
     108}
     109
     110
    91111//--------------------------------------------------------------------
    92112BMember::BMember(BMemberOwner* parent, List* branch)
    … …  
    104124  isStatic_    (false),
    105125  static_      (NULL),
    106   description_ ("")
     126  description_ (""),
     127  type_        (NULL),
     128  class_       (NULL),
     129  struct_      (NULL)
    107130{
    108131  List* cdr;
    … …  
    159182      else if(expression[0]=='{')
    160183      {
    161         expression = expression.SubString(1,expression.Length()-2);
     184        CleanLeftAndRightChar(expression,'{','}');
    162185      }
    163186      int posEq = expression.Find("=");
    … …  
    265288        {
    266289          name_ = simpleDec.SubString(p0+1,p1-1);
     290          CleanLeftAndRightChar(name_,'{','}');
    267291        }
    268292      }
    269293    }
    270294    //Cleaning open and close parenthesis
    271     if(declaration_[0]=='{')
    272     {
    273       declaration_=declaration_.SubString(1,declaration_.Length()-2);
    274     }
     295    CleanLeftAndRightChar(declaration_,'{','}');
    275296  }
    276297  //Checking mandatory information: name and declaration.
    … …  
    293314            I2(" of Class ", " de Class ")+parent->getFullName());
    294315  }
    295   if(parent->OwnerType()==BMemberOwner::BCLASS)
    296   {
    297     BuildMethod();
    298     BuildStatic();
    299   }
     316  BuildAll();
    300317}
    301318
    … …  
    360377  isStatic_     = mbr.isStatic_;
    361378  static_       = mbr.static_;
     379  type_         = mbr.type_;
     380  class_        = mbr.class_;
     381  struct_       = mbr.struct_;
    362382  if(method_) { method_->IncNRefs(); }
    363383  if(static_) { static_->IncNRefs(); }
    … …  
    483503  }
    484504}
     505
     506//--------------------------------------------------------------------
     507  int BMember::BuildType()
     508//! Builds type information
     509//--------------------------------------------------------------------
     510{
     511  if(isMethod_) { type_ = GraCode(); }
     512  else
     513  {
     514    BText typeDec = declaration_+" ";
     515    typeDec.Replace(BText(" ")+name_+" ","");
     516    typeDec.Compact();
     517    class_ = FindClass(typeDec,-1);
     518    if(class_) { type_ = GraNameBlock(); }
     519    else
     520    {
     521      struct_ = FindStruct(typeDec);
     522      if(struct_) { type_ = GraSet(); }
     523      else
     524      {
     525        type_ = BGrammar::FindByName(typeDec,false);
     526        if(!type_)
     527        {
     528          isGood_ = false;
     529          Error(I2("Unknown type declaration of member ",
     530                   "Tipo descponocido en declaración de miembro ")+
     531          BParser::Unparse(branch_,"","\n")+
     532          I2(" of Class ", " de Class ")+parent_->getFullName() );
     533          return(-1);
     534        }
     535      }
     536    }
     537  }
     538  return(0);
     539}
     540
     541//--------------------------------------------------------------------
     542  int BMember::BuildAll()
     543//--------------------------------------------------------------------
     544{
     545  if(parent_->OwnerType()==BMemberOwner::BCLASS)
     546  {
     547    BuildMethod();
     548    BuildStatic();
     549  }
     550  BuildType();
     551  return(0);
     552}
     553
    485554//--------------------------------------------------------------------
    486555  bool BMember::HasDefVal() const
    … …  
    747816  if(!parent) { return(false); }
    748817  if(this==parent) { return(true); }
    749   return(InheritesFrom(parent->getFullNameRef()));
     818  BClassByNameHash::const_iterator iterA;
     819  BClassByNameHash& ah = *ascentHash_;
     820  for(iterA=ah.begin(); iterA!=ah.end(); iterA++)
     821  {
     822    if(iterA->second==parent) { return(true); }
     823  }
     824  return(false);
     825//return(InheritesFrom(parent->getFullNameRef()));
    750826//return(InheritesFrom(parent->Name()));
    751827}
    … …  
    819895{
    820896  if(!isGood_) { return(false); }
    821   const BText& dec  = newMember->declaration_;
     897  const BText* dec  = &(newMember->declaration_);
    822898  const BText& name = newMember->name_;
    823   assert(name.HasName()&& dec.HasName());
     899  assert(name.HasName()&& dec->HasName());
    824900
    825901  if(OwnerType()==BCLASS)
    … …  
    847923  BMbrNum* mbrNum = FindMbrNum(name);
    848924  BMember* member = (mbrNum)?mbrNum->member_:NULL;
     925  if(member)
     926  {
     927    if(member->type_ == newMember->type_)
     928    {
     929      if( ((member->type_==GraSet())&&member->struct_&&(member->struct_==newMember->struct_))
     930          ||
     931          ((member->type_==GraNameBlock())&&member->class_&&(member->class_==newMember->class_)) )
     932      {
     933        dec = &(member->declaration_);
     934      }
     935    }
     936  }
    849937  //Searches for existant member with same declaration but no default value
    850   BMember* mbrDec = FindDecMember(dec);
     938  BMember* mbrDec = FindDecMember(*dec);
    851939  //Searches for existant member with same declaration and with default value
    852   BMember* mbrDef = FindDefMember(dec);
     940  BMember* mbrDef = FindDefMember(*dec);
     941
    853942  bool isMethod = newMember->isMethod_;
    854943  if(!member)
    … …  
    858947    (*memberHash_)[name] = newMbrNum;
    859948    //It's also added to correspondent map hashed by declaration
    860     if(hasDefVal) { (*mbrDefHash_)[dec] = newMember; }
    861     else          { (*mbrDecHash_)[dec] = newMember; }
     949    if(hasDefVal) { (*mbrDefHash_)[*dec] = newMember; }
     950    else          { (*mbrDecHash_)[*dec] = newMember; }
    862951    if(isMethod && !hasDefVal) { notImplementedMethods_++; }
    863952  }
    … …  
    895984      memberHash_->erase(name);
    896985      assert(!FindMember(name));
    897       mbrDefHash_->erase(dec);
    898       assert(!FindDefMember(dec));
     986      mbrDefHash_->erase(*dec);
     987      assert(!FindDefMember(*dec));
    899988      (*memberHash_)[name] = newMbrNum;
    900       (*mbrDefHash_)[dec ] = newMember;
     989      (*mbrDefHash_)[*dec] = newMember;
    901990      newMember->firstParent_ = mbrDef->firstParent_;
    902991    }
    … …  
    907996      memberHash_->erase(name);
    908997      assert(!FindMember(name));
    909       mbrDecHash_->erase(dec);
    910       assert(!FindDecMember(dec));
    911       (*memberHash_)[name]= newMbrNum;
    912       (*mbrDefHash_)[dec] = newMember;
     998      mbrDecHash_->erase(*dec);
     999      assert(!FindDecMember(*dec));
     1000      (*memberHash_)[name] = newMbrNum;
     1001      (*mbrDefHash_)[*dec] = newMember;
    9131002      if(isMethod)
    9141003      {
    … …  
    9531042  " \n  class:"+Name()+
    9541043  " \n  member name:"+name+
    955   " \n  member declaration:"+dec+"\n");
     1044  " \n  member declaration:"+*dec+"\n");
    9561045*/
    9571046  return(ok);
    … …  
    11931282  __destroy(NULL)
    11941283{
     1284  if(name=="@BsrMaster")
     1285    printf("");
    11951286  CreateMemberHashes();
    11961287  CreateParentHashes();
    … …  
    16651756
    16661757//--------------------------------------------------------------------
    1667   BClass* BClass::PredeclareClass(
     1758static BClass* FindClassInNameBlock(
     1759  const BText& name,
     1760  BUserNameBlock*& unb )
     1761//--------------------------------------------------------------------
     1762{
     1763  BClass* cls = NULL;
     1764  BSyntaxObject* obj;
     1765  int pos = name.Find("::",0);
     1766  if(pos>=0)
     1767  {
     1768    BText prefix;
     1769    BText suffix;
     1770    prefix = name.SubString(0,pos-1);
     1771    suffix  = name.SubString(pos+2,name.Length());
     1772    if(!unb)
     1773    {
     1774      obj = GraNameBlock()->FindOperand(prefix,false);
     1775      if(obj && obj->Grammar()==GraNameBlock())
     1776      {
     1777        unb = (BUserNameBlock*)obj;
     1778      }
     1779    }
     1780    else
     1781    {
     1782      BNameBlock& nb = unb->Contens();
     1783      obj = nb.Member(prefix);
     1784      if(obj && obj->Grammar()==GraNameBlock())
     1785      {
     1786        unb = (BUserNameBlock*)obj;
     1787      }
     1788      else
     1789      {
     1790        unb = NULL;
     1791      }
     1792    }
     1793    if(unb)
     1794    {
     1795      cls = FindClassInNameBlock(suffix, unb);         
     1796    }
     1797  }
     1798  else if(unb)
     1799  {
     1800    BNameBlock& nb = unb->Contens();
     1801    obj = nb.Member(name);
     1802    if(obj && obj->Mode()==BCLASSMODE)
     1803    {
     1804      cls = (BClass*)obj;
     1805    }
     1806  }
     1807  return(cls);
     1808}
     1809
     1810
     1811//--------------------------------------------------------------------
     1812static BClass* FindNonMemberClass(const BText& name, int defined)
     1813
     1814/*! Searches a user class wich name is name and returns it.
     1815 *  If itsn't exists returns NIL.
     1816 */
     1817//--------------------------------------------------------------------
     1818{
     1819  BClass* cls = BStackManager::FindClass(name);
     1820  if(!cls)
     1821  {
     1822    BObjClassify oc(GraAnything(),BCLASSMODE);
     1823    cls= (BClass*)BGrammar::SymbolTable().Search(oc, name);
     1824  }
     1825  return(cls);
     1826}
     1827
     1828//--------------------------------------------------------------------
     1829BClass* FindClass(const BText& name, int defined)
     1830
     1831/*! Searches a user class wich name is name and returns it.
     1832 *  If itsn't exists returns NIL.
     1833 */
     1834//--------------------------------------------------------------------
     1835{
     1836  BSyntaxObject* result = NULL;
     1837  BUserNameBlock* unb = NULL;
     1838  BClass* cls = FindClassInNameBlock(name, unb);
     1839  if(!cls && BNameBlock::Current())
     1840  {
     1841    result = BNameBlock::Current()->Member(name);
     1842    if(result && (result->Mode()==BCLASSMODE))
     1843    {
     1844      cls = (BClass*)result;
     1845    }
     1846  }
     1847  if(!cls)
     1848  {
     1849    cls = BStackManager::FindClass(name);
     1850  }
     1851  if(!cls)
     1852  {
     1853    result = BNameBlock::LocalMember(name);
     1854    if(result && (result->Mode()==BCLASSMODE))
     1855    {
     1856      cls = (BClass*)result;
     1857    }
     1858  }
     1859  if(!cls)
     1860  {
     1861    BObjClassify oc(GraAnything(),BCLASSMODE);
     1862    cls= (BClass*)BGrammar::SymbolTable().Search(oc, name);
     1863  }
     1864  if(!cls)
     1865  {
     1866    result = BNameBlock::UsingMember(name);
     1867    if(result && (result->Mode()==BCLASSMODE))
     1868    {
     1869      cls = (BClass*)result;
     1870    }
     1871  }
     1872  if(cls && (defined>=0) && (cls->isDefined_!=(defined!=0)))
     1873  {
     1874    cls = NULL;
     1875  }
     1876  return(cls);
     1877}
     1878
     1879//--------------------------------------------------------------------
     1880  BClass* BClass::GetClassIfExist(const BText& name)
     1881//--------------------------------------------------------------------
     1882{
     1883  if(name=="@BsrMaster")
     1884    printf("");
     1885  BClass* old = NULL;
     1886  if(name.HasName())
     1887  {
     1888    BUserNameBlock* bnbP = BNameBlock::Building();
     1889    if(bnbP)
     1890    {
     1891      old = BStackManager::FindClass(name);
     1892      if(old && (old->Level()!=BGrammar::Level()))
     1893      {
     1894        old = NULL;
     1895      }
     1896    }
     1897    else
     1898    {
     1899      old = FindClass(name,-1);
     1900    } 
     1901  }
     1902  return(old);
     1903}
     1904
     1905//--------------------------------------------------------------------
     1906  BClass* BClass::PredeclareClassIfNeeded(const BText& name)
     1907//--------------------------------------------------------------------
     1908{
     1909  BClass* class_ = BClass::GetClassIfExist(name);
     1910  if(!class_)
     1911  {
     1912    class_ = new BClass(name);
     1913  }
     1914  return(class_);
     1915};
     1916
     1917
     1918//--------------------------------------------------------------------
     1919  BClass* BClass::PredeclareNewClass(
    16681920     const BText& name,
    16691921     BClass*& old,
    … …  
    16711923//--------------------------------------------------------------------
    16721924{
    1673   old = NULL;
     1925  old = BClass::GetClassIfExist(name);
    16741926  BClass* class_ = NULL;
    1675   if(name.HasName())
    1676   {
    1677     old = FindClass(name,-1);
    1678     //Checking existent class with the same name
    1679     if(old && old->isDefined_)
    1680     {
    1681       ok = false;
    1682       Error(BText("Class '") + name +
    1683         I2("' is already defined as ",
    1684            "' ya fue definida como \"") + old->Dump() + "\"\n");
    1685     }
    1686     else if(old)
    1687     {
    1688       class_ = old;
    1689     }
    1690     else
    1691     {
    1692       class_ = new BClass(name);
    1693     }
     1927  //Checking existent class with the same name
     1928  if(old && old->isDefined_)
     1929  {
     1930    ok = false;
     1931    Error(BText("Class '") + name +
     1932      I2("' is already defined as ",
     1933         "' ya fue definida como \"") + old->Dump() + "\"\n");
     1934  }
     1935  else if(old)
     1936  {
     1937    class_ = old;
     1938  }
     1939  else
     1940  {
     1941    class_ = new BClass(name);
    16941942  }
    16951943  return(class_);
    … …  
    16971945
    16981946//--------------------------------------------------------------------
    1699   BClass* BClass::PredeclareClass(const BText& name)
    1700 //--------------------------------------------------------------------
    1701 {
    1702   BClass* old;
     1947  BClass* BClass::PredeclareNewClass(const BText& name)
     1948//--------------------------------------------------------------------
     1949{
     1950  BClass* class_;
    17031951  bool ok;
    1704   return(PredeclareClass(name, old, ok));
     1952  return(PredeclareNewClass(name, class_, ok));
    17051953};
    17061954
    … …  
    17331981    {
    17341982      name = tok->Name();
    1735       class_ = PredeclareClass(name, old, ok);
     1983      class_ = PredeclareNewClass(name, old, ok);
    17361984      ok = (class_!=NULL);
    17371985      memberLst=NULL;
    … …  
    17421990      tok = (BToken*)((List*)(cdr->car()))->car();
    17431991      name = tok->Name();
    1744       class_ = PredeclareClass(name, old, ok);
     1992      class_ = PredeclareNewClass(name, old, ok);
    17451993      ok = (class_!=NULL);
    17461994      cdr = cdr->cdr();
    … …  
    18242072      //Class without inheriting clause
    18252073      name = tok->Name();
    1826       class_ = PredeclareClass(name, old, ok);
     2074      class_ = PredeclareNewClass(name, old, ok);
    18272075      ok = (class_!=NULL);
    18282076      memberLst = cdr;
    … …  
    18692117}
    18702118
    1871 //--------------------------------------------------------------------
    1872 static BClass* FindClassInNameBlock(
    1873   const BText& name,
    1874   BUserNameBlock*& unb )
    1875 //--------------------------------------------------------------------
    1876 {
    1877   BClass* cls = NULL;
    1878   BSyntaxObject* obj;
    1879   int pos = name.Find("::",0);
    1880   if(pos>=0)
    1881   {
    1882     BText prefix;
    1883     BText suffix;
    1884     prefix = name.SubString(0,pos-1);
    1885     suffix  = name.SubString(pos+2,name.Length());
    1886     if(!unb)
    1887     {
    1888       obj = GraNameBlock()->FindOperand(prefix,false);
    1889       if(obj && obj->Grammar()==GraNameBlock())
    1890       {
    1891         unb = (BUserNameBlock*)obj;
    1892       }
    1893     }
    1894     else
    1895     {
    1896       BNameBlock& nb = unb->Contens();
    1897       obj = nb.Member(prefix);
    1898       if(obj && obj->Grammar()==GraNameBlock())
    1899       {
    1900         unb = (BUserNameBlock*)obj;
    1901       }
    1902       else
    1903       {
    1904         unb = NULL;
    1905       }
    1906     }
    1907     if(unb)
    1908     {
    1909       cls = FindClassInNameBlock(suffix, unb);         
    1910     }
    1911   }
    1912   else if(unb)
    1913   {
    1914     BNameBlock& nb = unb->Contens();
    1915     obj = nb.Member(name);
    1916     if(obj && obj->Mode()==BCLASSMODE)
    1917     {
    1918       cls = (BClass*)obj;
    1919     }
    1920   }
    1921   return(cls);
    1922 }
    1923 
    1924 //--------------------------------------------------------------------
    1925 BClass* FindClass(const BText& name, int defined)
    1926 
    1927 /*! Searches a user class wich name is name and returns it.
    1928  *  If itsn't exists returns NIL.
    1929  */
    1930 //--------------------------------------------------------------------
    1931 {
    1932   BSyntaxObject* result = NULL;
    1933   BUserNameBlock* unb = NULL;
    1934   BClass* cls = FindClassInNameBlock(name, unb);
    1935   if(!cls && BNameBlock::Current())
    1936   {
    1937     result = BNameBlock::Current()->Member(name);
    1938     if(result && (result->Mode()==BCLASSMODE))
    1939     {
    1940       cls = (BClass*)result;
    1941     }
    1942   }
    1943   if(!cls)
    1944   {
    1945     cls = BStackManager::FindClass(name);
    1946   }
    1947   if(!cls)
    1948   {
    1949     result = BNameBlock::LocalMember(name);
    1950     if(result && (result->Mode()==BCLASSMODE))
    1951     {
    1952       cls = (BClass*)result;
    1953     }
    1954   }
    1955   if(!cls)
    1956   {
    1957     BObjClassify oc(GraAnything(),BCLASSMODE);
    1958     cls= (BClass*)BGrammar::SymbolTable().Search(oc, name);
    1959   }
    1960   if(!cls)
    1961   {
    1962     result = BNameBlock::UsingMember(name);
    1963     if(result && (result->Mode()==BCLASSMODE))
    1964     {
    1965       cls = (BClass*)result;
    1966     }
    1967   }
    1968   if(cls && (defined>=0) && (cls->isDefined_!=(defined!=0)))
    1969   {
    1970     cls = NULL;
    1971   }
    1972   return(cls);
    1973 }
    19742119
    19752120//--------------------------------------------------------------------
  • tol/btol/bgrammar/oprimp.cpp

    r0d63276 r0e767dc  
    13541354          {
    13551355            BNameBlock& nb = ((BUserNameBlock*)var)->Contens();
     1356            if(cls->Name()=="@BsrMaster")
     1357              printf("");
    13561358                        if(!nb.IsInstanceOf(cls))
    13571359            {
    13581360                                BText bText = BParser::Unparse(b);
     1361              BText but = "";
     1362              if(nb.Class())
     1363              {
     1364                but = I2(" but it's an instance of ",
     1365                         " sino de " )+nb.Class()->FullName();
     1366              }
     1367              else
     1368              {
     1369                but = I2(" nor any other class.",
     1370                         " ni de ninguna otra clase.");
     1371              }
    13591372                                Error(bText + I2(" is not a NameBlock instance of ",
    13601373                                                             " no es un NameBlock instancia de ") +
    1361                                       cls->FullName());
     1374                                      cls->FullName()+but);
    13621375                                DESTROY(var);
    13631376                        }
    … …  
    15991612    BStruct*  str  = NIL;
    16001613    BClass*   cls  = NIL;
     1614    structs_ [n] = NIL;
     1615    classes_ [n] = NIL;
    16011616    bool carIsList = dec->car()->IsListClass();
    16021617    List* decLst = carIsList?Tree::treNode((List*) dec):(List*)dec;
    … …  
    16141629      structs_ [n] = str;
    16151630      classes_ [n] = cls;
     1631      if(str) { str->IncNRefs(); }
     1632      if(cls) { cls->IncNRefs(); }
    16161633      dec = dec->cdr();
    16171634    }
    … …  
    18751892  declare_     = "";
    18761893  define_      = "";
     1894  for(int n = 0; n<maxArg_; n++)
     1895  {
     1896    if(classes_[n]) { classes_[n]->DecNRefs(); }
     1897    if(structs_[n]) { structs_[n]->DecNRefs(); }
     1898  }
    18771899}
    18781900
  • tol/btol/bgrammar/spfuninst.cpp

    r0d63276 r0e767dc  
    137137                   int numParam)
    138138   
    139 /*! Returns true if the number of branch in a tree is correct
     139/*! Returns true if the number and types of branches in a tree is correct
    140140 */
    141141//--------------------------------------------------------------------
    … …  
    143143  BList* lst = NIL;
    144144  BList* aux = NIL;
    145   BInt n = BSpecialFunction::NumBranches(tre);
    146   if(numParam)
    147   {
    148     for(BInt i=0; i<n; i++)
    149     {
    150       BInt j = Minimum(i, numParam-1);
    151       BGrammar* gra = graParam[j];
    152       assert(gra);
    153       List* branch = Branch(tre,i+1);
    154       assert(branch);
    155       BSyntaxObject* arg = gra->EvaluateTree(branch);
    156       if(arg)
    157       {
    158         LstFastAppend(lst,aux,arg);
    159       }
    160       else
    161       {
    162         Error(BParser::Unparse(branch)+
    163               I2(BText(" is not a ") + gra->Name() + " object.",
    164               BText(" no es un objeto de tipo ") + gra->Name()));
    165         DESTROY(lst);
    166         break;
    167       }
     145  BInt n = numParam;
     146  for(BInt i=0; i<n; i++)
     147  {
     148    BInt j = Minimum(i, numParam-1);
     149    BGrammar* gra = graParam[j];
     150    assert(gra);
     151    List* branch = Branch(tre,i+1);
     152    assert(branch);
     153    BSyntaxObject* arg = gra->EvaluateTree(branch);
     154    if(arg && ((gra==GraAnything()) || (arg->Grammar()==gra)))
     155    {
     156      LstFastAppend(lst,aux,arg);
     157    }
     158    else
     159    {
     160      Error(BParser::Unparse(branch)+
     161            I2(BText(" is not a ") + gra->Name() + " object.",
     162            BText(" no es un objeto de tipo ") + gra->Name()));
     163      DESTROY(lst);
     164      return;
    168165    }
    169166  }
    … …  
    519516{
    520517  static BText _name_ = "Group";
    521   static BGrammar* graParam[2] =
     518  static BGrammar* graParam[3] =
    522519  {
    523520    GraText(),
    524     GraSet()
     521    GraSet(),
     522    GraAnything()
    525523  };
    526   BSet args; BSpecialFunction::GetArg(args, tre, graParam, 2);
    527524  BSyntaxObject* result = NIL;
    528   BSyntaxObject* uTxt  = NIL;
    529   BSyntaxObject* uSet  = NIL;
    530   if(gra==GraAnything())
    531   {
    532     Error(I2("Cannot eval Group returning an object of type Anything.",
    533              "No se puede evaluar Group para devolver un objeto de tipo Anything."));
    534   }
    535   else
    536   {
    537     if(args.Card()>=2)
    538     {
    539             uTxt = args[1];
    540             uSet = args[2];
    541      
    542             if(uTxt && uSet)
    543             {
     525
     526  BInt nb = BSpecialFunction::NumBranches(tre);
     527  BSet args;
     528  if(BSpecialFunction::TestNumArg(_name_, 2, nb, 3))
     529  { 
     530    BSpecialFunction::GetArg(args, tre, graParam, nb);
     531  }
     532  if(args.Card()==nb)
     533  {
     534    BSyntaxObject* uTxt  = NIL;
     535    BSyntaxObject* uSet  = NIL;
     536    if(gra==GraAnything())
     537    {
     538      Error(I2("Cannot eval Group returning an object of type Anything.",
     539               "No se puede evaluar Group para devolver un objeto de tipo Anything."));
     540    }
     541    else
     542    {
     543      uTxt = args[1];
     544      uSet = args[2];
     545      if(uTxt && uSet)
     546      {
    544547        BSet& set = Set(uSet);
    545               BText txt = uTxt->Dump();
    546                                 txt = txt.SubString(1,txt.Length()-2);
    547               BStandardOperator* ope = (BStandardOperator*)gra->FindOperator(txt);
    548               if(ope)
    549               {
    550                       if(set.Card()==0)
     548        BText txt  = uTxt->Dump();
     549        txt = txt.SubString(1,txt.Length()-2);
     550        BStandardOperator* ope = (BStandardOperator*)gra->FindOperator(txt);
     551        if(ope)
     552        {
     553          if(set.Card()==0)
    551554          {
    552             if(args.Card()==3)
     555            if(nb==3)
    553556            {
    554                     result = args[3];
     557              if(gra==args[3]->Grammar()) { result = gra->New("",args[3]); }
     558              else
     559              {
     560                Error(I2("Group default value type should be ",
     561                         "El valor por defecto de Group debería ser de tipo ")+gra->Name()+
     562                      I2(" instead of "," en lugar de ")+args[3]->Grammar()->Name());
     563              }
    555564            }
    556565            else
    … …  
    558567              Error(I2("Cannot evaluate Group over empty set without "
    559568                       "a default value.",
    560                                                "No sepuede evaluar Group sobre un conjunto vacío "
     569                       "No se puede evaluar Group sobre un conjunto vacío "
    561570                       "sin valor por defecto."));
    562571            }
    … …  
    564573          else 
    565574          {
    566                         BBool ok = BTRUE;
     575            BBool ok = BTRUE;
    567576            BGrammar* g;
    568                         for(BInt n=1; ok&&(n<=set.Card()); n++)
     577            for(BInt n=1; ok&&(n<=set.Card()); n++)
    569578            {
    570579              g = set[n]->Grammar();
    571                                 if((gra!=GraAnything()) &&
    572                                    !(ok = (g==gra)))
     580              if((gra!=GraAnything()) &&
     581                 !(ok = (g==gra)))
    573582              {
    574                                   Error(I2("An element for Group function is not an"
    575                                                  " object of type ",
    576                                                  "Algún elemento para la funcion Group no"
     583                Error(I2("An element for Group function is not an"
     584                         " object of type ",
     585                         "Algún elemento para la funcion Group no"
    577586                         " es un objeto de tipo ")+ gra->Name()+":\n"+
    578587                         set[n]->LexInfo());
    579                                 }
    580                         }
    581                         if(ok)
     588              }
     589            }
     590            if(ok)
    582591            {
    583                                 if(set.Card()==1)
     592              if(set.Card()==1)
    584593              {
    585                                   result = gra->New("",set[1]);
     594                result = gra->New("",set[1]);
    586595              //result = set[1];
    587                                 }
     596              }
    588597              else
    589598              {
    … …  
    591600                BList* arg = Set(args[2]).ToReversedList();
    592601              //Std(BText("\nGroup(")+uTxt->Dump()+",[["+set.Name()+"]])");
    593                                   result = ope->Evaluator(arg);
    594                                 }
    595                         }
    596                       }
    597               }
    598               else
    599               {
    600                       Error(BText("Group : ") +txt +
    601                             I2(" is not a " + gra->Name() + " operator.",
    602                                   " no es un operador de tipo " + gra->Name()));
    603               }
    604             }
     602                result = ope->Evaluator(arg);
     603              }
     604            }
     605          }
     606        }
     607        else
     608        {
     609          Error(BText("Group : ") +txt +
     610                I2(" is not a " + gra->Name() + " operator.",
     611                " no es un operador de tipo " + gra->Name()));
     612        }
     613      }
    605614    }
    606615  }
    … …  
    19982007          unb = (BUserNameBlock*)result;
    19992008        }
    2000         if(!unb || (unb->Contens().Class()!=cls))
     2009        const BClass* unbCls = (!unb)?NULL:unb->Contens().Class();
     2010        if(!unb || !unbCls->InheritesFrom(cls))
    20012011        {
    20022012          errMsg = I2("It was expected an instance of Class ",
  • tol/btol/bgrammar/tol_bclass.h

    r0d63276 r0e767dc  
    3434class TOL_API BMemberOwner;
    3535class TOL_API BClass;
     36class TOL_API BStruct;
    3637struct TOL_API BMbrNum;
    3738
    … …  
    6364  int      position_; //Appearing order
    6465};
     66
    6567
    6668//--------------------------------------------------------------------
    … …  
    8385  BSyntaxObject* static_;       //!< Store for Class static member or method
    8486  BText          description_;  //!< Store for Class member description
     87  BGrammar*      type_;
     88  BStruct*       struct_;
     89  BClass*        class_;
    8590 public:
    8691  // Constructors and destructors: bgrammar\class.cpp
    … …  
    102107  int BuildMethod();
    103108  int BuildStatic();
     109  int BuildType();
     110  int BuildAll();
    104111        BText   Dump () const;
    105112  void PutDescription(const BText& desc);
    … …  
    246253  bool DestroyInstance(BNameBlock* instance);
    247254  //! Evaluates a parsed tree with a Class declaration
    248   static BClass* PredeclareClass(const BText&name, BClass*&old, bool &ok);
    249   static BClass* PredeclareClass(const BText&name);
     255  static BClass* GetClassIfExist(const BText& name);
     256  static BClass* PredeclareClassIfNeeded(const BText& name);
     257  static BClass* PredeclareNewClass(const BText&name, BClass*&old, bool &ok);
     258  static BClass* PredeclareNewClass(const BText&name);
    250259  static BSyntaxObject* Evaluate(const List* tree);
    251260  BSyntaxObject* FindMethod(const BText& memberName, bool fullAccess) const;
Note: See TracChangeset for help on using the changeset viewer.