Changeset a32a175 in tol


Ignore:
Timestamp:
Dec 23, 2009, 10:58:33 AM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
4725fcb
Parents:
6a80a46
Message:

Fixes #824

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

Location:
tol/btol/bgrammar
Files:
3 edited

Legend:

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

    r6a80a46 ra32a175  
    3737#include <tol/tol_bcodgra.h>
    3838#include <tol/tol_btxtgra.h>
     39#include <tol/tol_bdatgra.h>
    3940
    4041
    … …  
    291292//--------------------------------------------------------------------
    292293{
     294  static BText __destroyDec = "Real __destroy(Real void)";
    293295  if(!isStatic_ && !method_ && isMethod_ && definition_.HasName())
    294296  {
    … …  
    304306      method_->IncNRefs();
    305307      method_->PutMethod();
     308      bool isDestroy = method_->Name()=="__destroy";
     309      if(isDestroy)
     310      {
     311        if(Compact(declaration_)==__destroyDec)
     312        {
     313          cls->PutDestroy(method_);
     314        }
     315        else
     316        {
     317          Error(I2("Wrong declaration of destroyer method of Class ",
     318                   "Declaración errónea del método destructor de Class ")+
     319                parent_->getName()+
     320                "\n"+declaration_+"\n"+
     321                I2(" should be ", " debería ser ")+__destroyDec+
     322                "\n"+__destroyDec+"\n");
     323        } 
     324      }
    306325      BUserCode* uCode = UCode(method_);
    307326      uCode->Contens().Operator()->PutMethod();
    … …  
    314333               "Sintaxis incorrecta en declaración de método ")+
    315334            BParser::Unparse(branch_,"","\n")+
    316             I2(" of Class ", "de Class ")+parent_->getName());
     335            I2(" of Class ", " de Class ")+parent_->getName());
    317336      return(0);
    318337    }
    … …  
    10001019: BSyntaxObject(),
    10011020  BMemberOwner(),
    1002   isDefined_(false)
     1021  isDefined_(false),
     1022  __destroy(NULL)
    10031023{
    10041024  CreateMemberHashes();
    … …  
    10221042  //Remove symbol from language searchers
    10231043  BGrammar::DelObject(this);
     1044}
     1045
     1046//--------------------------------------------------------------------
     1047  void BClass::PutDestroy(BSyntaxObject* destroy)
     1048//--------------------------------------------------------------------
     1049{
     1050  if(!__destroy) { __destroy = destroy; }
    10241051}
    10251052
    … …  
    14381465}
    14391466
     1467//--------------------------------------------------------------------
     1468  bool BClass::DestroyInstance(BNameBlock* instance)
     1469//--------------------------------------------------------------------
     1470{
     1471  BClassByNameHash::const_iterator iterC;
     1472  BClassByNameHash& par = *(parentHash_);
     1473  bool ok = true;
     1474  for(iterC=par.begin(); iterC!=par.end(); iterC++)
     1475  {
     1476    BClass* parent = iterC->second;
     1477    ok &= parent->DestroyInstance(instance);
     1478  }
     1479  if(__destroy)
     1480  {
     1481    BUserFunCode* ufc= (BUserFunCode*)__destroy;
     1482    BUserFunction* dstryr = (BUserFunction*)ufc->Contens().Operator();
     1483    BList* args = NCons(new BContensDat(0.0));
     1484    const BNameBlock* old = dstryr->NameBlock();
     1485    dstryr->PutNameBlock(instance);
     1486    BSyntaxObject* result = dstryr->Evaluator(args);
     1487    if(!result) { ok = false; }
     1488    else { ok = (bool)Real(result); }
     1489    dstryr->PutNameBlock(old);
     1490    DESTROY(result);
     1491  }
     1492  return(ok);
     1493}
  • tol/btol/bgrammar/nameblock.cpp

    r6a80a46 ra32a175  
    168168{
    169169  int n;
     170  if(class_)
     171  {
     172    class_->DestroyInstance(this);
     173    class_->DecNRefs();
     174    DESTROY(class_);
     175  }
    170176  owner_ = NULL;
    171177  for(n=1; n<=set_.Card(); n++)
    … …  
    177183  set_.Delete();
    178184  father_ = NULL;
    179   if(class_)
    180   {
    181     class_->DecNRefs();
    182     DESTROY(class_);
    183   }
    184185  if(requiredPackages_)
    185186  {
    … …  
    187188    requiredPackages_ = NULL;
    188189  }
    189 
    190190}
    191191
  • tol/btol/bgrammar/tol_bclass.h

    r6a80a46 ra32a175  
    185185  static const BClass* currentClassBuildingInstance_;
    186186  static const BClass* currentStatic_;
     187  BSyntaxObject* __destroy;
    187188  // Constructors and destructors: bgrammar\class.cpp
    188189  BClass(const BText& name);
    … …  
    200201
    201202  bool CheckAutoDoc();
    202 
     203  void PutDestroy(BSyntaxObject* destroy);
     204  bool DestroyInstance(BNameBlock* instance);
    203205  //! Evaluates a parsed tree with a Class declaration
    204206  static BClass* PredeclareClass(const BText&name, BClass*&old, bool &ok);
Note: See TracChangeset for help on using the changeset viewer.