[colobot] 93/377: Moving CBotClassInst class in its own header and source files.

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit bbf2e48802082ff0fbd336b2f5a5eeb4200f818c
Author: Grunaka <dev at romainbreton.fr>
Date:   Wed Nov 11 22:36:18 2015 +0100

    Moving CBotClassInst class in its own header and source files.
---
 src/CBot/CBot.cpp                                  |   2 +
 src/CBot/CBot.h                                    |  20 -
 src/CBot/CBotClass.cpp                             | 411 -----------------
 .../{CBotClass.cpp => CBotInstr/CBotClassInst.cpp} | 490 +--------------------
 src/CBot/CBotInstr/CBotClassInst.h                 |  85 ++++
 src/CBot/CMakeLists.txt                            |   1 +
 6 files changed, 99 insertions(+), 910 deletions(-)

diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index 7ad12b3..9e4716e 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -61,6 +61,8 @@
 #include "CBotInstr/CBotExpression.h"
 #include "CBotInstr/CBotIndexExpr.h"
 #include "CBotInstr/CBotFieldExpr.h"
+#include "CBotInstr/CBotClassInst.h"
+
 
 // Local include
 
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 1b038cb..a045dc3 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -617,26 +617,6 @@ public:
     void        RestoreState(CBotStack* &pj, bool bMain) override;
 };
 
-// definition of an element of any class
-
-class CBotClassInst : public CBotInstr
-{
-private:
-    CBotInstr*    m_var;                // variable to initialise
-    CBotClass*    m_pClass;            // reference to the class
-    CBotInstr*    m_Parameters;        // parameters to be evaluated for the contructor
-    CBotInstr*    m_expr;                // a value to put, if there is
-    bool        m_hasParams;        // has it parameters?
-    long        m_nMethodeIdent;
-
-public:
-                CBotClassInst();
-                ~CBotClassInst();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr);
-    bool        Execute(CBotStack* &pj) override;
-    void        RestoreState(CBotStack* &pj, bool bMain) override;
-};
 
 #define    MAX(a,b)    ((a>b) ? a : b)
 
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 11f93a1..f98eaaa 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -463,417 +463,6 @@ bool CBotClass::RestoreStaticState(FILE* pf)
     return true;
 }
 
-
-/////////////////////////////////////////////////////////////////////
-
-CBotClassInst::CBotClassInst()
-{
-    m_next          = nullptr;
-    m_var           = nullptr;
-    m_Parameters    = nullptr;
-    m_expr          = nullptr;
-    m_hasParams     = false;
-    m_nMethodeIdent = 0;
-    name = "CBotClassInst";
-}
-
-CBotClassInst::~CBotClassInst()
-{
-    delete m_var;
-//  delete m_next;          // done by the destructor of the base class ~CBotInstr()
-}
-
-// definition of pointer (s) to an object
-// style
-// CPoint A, B ;
-
-CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass)
-{
-    // seeks the corresponding classes
-    if ( pClass == nullptr )
-    {
-        pStack->SetStartError(p->GetStart());
-        pClass = CBotClass::Find(p);
-        if ( pClass == nullptr )
-        {
-            // not found? is bizare
-            pStack->SetError(TX_NOCLASS, p);
-            return nullptr;
-        }
-        p = p->GetNext();
-    }
-
-    bool        bIntrinsic = pClass->IsIntrinsic();
-    CBotTypResult type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer, pClass );
-    CBotClassInst*  inst = static_cast<CBotClassInst*>(CompileArray(p, pStack, type));
-    if ( inst != nullptr || !pStack->IsOk() ) return inst;
-
-    CBotCStack* pStk = pStack->TokenStack();
-
-    inst = new CBotClassInst();
-    /// TODO Need to be revised and fixed after adding unit tests
-    CBotToken token(pClass->GetName(), CBotString(), p->GetStart(), p->GetEnd());
-    inst->SetToken(&token);
-    CBotToken*  vartoken = p;
-
-    if ( nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
-    {
-        (static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = type;
-        if (pStk->CheckVarLocal(vartoken))                  // redefinition of the variable
-        {
-            pStk->SetStartError(vartoken->GetStart());
-            pStk->SetError(TX_REDEFVAR, vartoken->GetEnd());
-            goto error;
-        }
-
-        if (IsOfType(p,  ID_OPBRK))                         // with any clues?
-        {
-            delete inst;                                    // is not type CBotInt
-            p = vartoken;                                   // returns to the variable name
-
-            // compiles declaration an array
-
-            inst = static_cast<CBotClassInst*>(CBotInstArray::Compile( p, pStk, type ));
-
-            if (!pStk->IsOk() )
-            {
-                pStk->SetError(TX_CLBRK, p->GetStart());
-                goto error;
-            }
-            goto suite;         // no assignment, variable already created
-        }
-
-
-        CBotVar*    var;
-        var = CBotVar::Create(vartoken->GetString(), type); // creates the instance
-//      var->SetClass(pClass);
-        var->SetUniqNum(
-            (static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
-                                                            // its attribute a unique number
-        pStack->AddVar(var);                                // placed on the stack
-
-        // look if there are parameters
-        inst->m_hasParams = (p->GetType() == ID_OPENPAR);
-
-        CBotVar*    ppVars[1000];
-        inst->m_Parameters = CompileParams(p, pStk, ppVars);
-        if ( !pStk->IsOk() ) goto error;
-
-        // if there are parameters, is the equivalent to the stament "new"
-        // CPoint A ( 0, 0 ) is equivalent to
-        // CPoint A = new CPoint( 0, 0 )
-
-//      if ( nullptr != inst->m_Parameters )
-        if ( inst->m_hasParams )
-        {
-            // the constructor is there?
-//          CBotString  noname;
-            CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent);
-            delete pStk->TokenStack();                          // releases the supplement stack
-            int typ = r.GetType();
-
-            if (typ == TX_UNDEFCALL)
-            {
-                // si le constructeur n'existe pas
-                if (inst->m_Parameters != nullptr)                 // with parameters
-                {
-                    pStk->SetError(TX_NOCONST, vartoken);
-                    goto error;
-                }
-                typ = 0;
-            }
-
-            if (typ>20)
-            {
-                pStk->SetError(typ, vartoken->GetEnd());
-                goto error;
-            }
-
-        }
-
-        if (IsOfType(p,  ID_ASS))                           // with a assignment?
-        {
-            if (inst->m_hasParams)
-            {
-                pStk->SetError(TX_ENDOF, p->GetStart());
-                goto error;
-            }
-
-            if ( nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
-            {
-                goto error;
-            }
-            CBotClass* result = pStk->GetClass();
-            if ( !pStk->GetTypResult(1).Eq(CBotTypNullPointer) &&
-               ( !pStk->GetTypResult(1).Eq(CBotTypPointer) ||
-                 ( result != nullptr && !pClass->IsChildOf(result) )))     // type compatible ?
-            {
-                pStk->SetError(TX_BADTYPE, p->GetStart());
-                goto error;
-            }
-//          if ( !bIntrinsic ) var->SetPointer(pStk->GetVar()->GetPointer());
-            if ( !bIntrinsic )
-            {
-                // does not use the result on the stack, to impose the class
-                CBotVar* pvar = CBotVar::Create("", pClass);
-                var->SetPointer( pvar );                    // variable already declared instance pointer
-                delete pvar;                                // removes the second pointer
-            }
-            var->SetInit(CBotVar::InitType::DEF);                         // marks the pointer as init
-        }
-        else if (inst->m_hasParams)
-        {
-            // creates the object on the "job" (\TODO "tas")
-            // with a pointer to the object
-            if ( !bIntrinsic )
-            {
-                CBotVar* pvar = CBotVar::Create("", pClass);
-                var->SetPointer( pvar );                    // variable already declared instance pointer
-                delete pvar;                                // removes the second pointer
-            }
-            var->SetInit(CBotVar::InitType::IS_POINTER);                            // marks the pointer as init
-        }
-suite:
-        if (IsOfType(p,  ID_COMMA))                         // several chained definitions
-        {
-            if ( nullptr != ( inst->m_next = CBotClassInst::Compile(p, pStk, pClass) ))    // compiles the following
-            {
-                return pStack->Return(inst, pStk);
-            }
-        }
-
-        if (IsOfType(p,  ID_SEP))                           // complete instruction
-        {
-            return pStack->Return(inst, pStk);
-        }
-
-        pStk->SetError(TX_ENDOF, p->GetStart());
-    }
-
-error:
-    delete inst;
-    return pStack->Return(nullptr, pStk);
-}
-
-// declaration of the instance of a class, for example:
-//  CPoint A, B;
-
-bool CBotClassInst::Execute(CBotStack* &pj)
-{
-    CBotVar*    pThis = nullptr;
-
-    CBotStack*  pile = pj->AddStack(this);//essential for SetState()
-//  if ( pile == EOX ) return true;
-
-    CBotToken*  pt = &m_token;
-    CBotClass*  pClass = CBotClass::Find(pt);
-
-    bool bIntrincic = pClass->IsIntrinsic();
-
-    // creates the variable of type pointer to the object
-
-    if ( pile->GetState()==0)
-    {
-        CBotString  name = m_var->m_token.GetString();
-        if ( bIntrincic )
-        {
-            pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass ));
-        }
-        else
-        {
-            pThis = CBotVar::Create(name, CBotTypResult( CBotTypPointer, pClass ));
-        }
-
-        pThis->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent); // its attribute as unique number
-        pile->AddVar(pThis);                                    // place on the stack
-        pile->IncState();
-    }
-
-    if ( pThis == nullptr ) pThis = pile->FindVar((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent);
-
-    if ( pile->GetState()<3)
-    {
-        // ss there an assignment or parameters (contructor)
-
-//      CBotVarClass* pInstance = nullptr;
-
-        if ( m_expr != nullptr )
-        {
-            // evaluates the expression for the assignment
-            if (!m_expr->Execute(pile)) return false;
-
-            if ( bIntrincic )
-            {
-                CBotVar*    pv = pile->GetVar();
-                if ( pv == nullptr || pv->GetPointer() == nullptr )
-                {
-                    pile->SetError(TX_NULLPT, &m_token);
-                    return pj->Return(pile);
-                }
-                pThis->Copy(pile->GetVar(), false);
-            }
-            else
-            {
-                CBotVarClass* pInstance;
-                pInstance = (static_cast<CBotVarPointer*>(pile->GetVar()))->GetPointer();    // value for the assignment
-                pThis->SetPointer(pInstance);
-            }
-            pThis->SetInit(CBotVar::InitType::DEF);
-        }
-
-        else if ( m_hasParams )
-        {
-            // evaluates the constructor of an instance
-
-            if ( !bIntrincic && pile->GetState() == 1)
-            {
-                CBotToken*  pt = &m_token;
-                CBotClass* pClass = CBotClass::Find(pt);
-
-                // creates an instance of the requested class
-
-                CBotVarClass* pInstance;
-                pInstance = static_cast<CBotVarClass*>(CBotVar::Create("", pClass));
-                pThis->SetPointer(pInstance);
-                delete pInstance;
-
-                pile->IncState();
-            }
-
-            CBotVar*    ppVars[1000];
-            CBotStack*  pile2 = pile;
-
-            int     i = 0;
-
-            CBotInstr*  p = m_Parameters;
-            // evaluates the parameters
-            // and places the values ​​on the stack
-            // to (can) be interrupted (broken) at any time
-
-            if ( p != nullptr) while ( true )
-            {
-                pile2 = pile2->AddStack();                      // place on the stack for the results
-                if ( pile2->GetState() == 0 )
-                {
-                    if (!p->Execute(pile2)) return false;       // interrupted here?
-                    pile2->SetState(1);
-                }
-                ppVars[i++] = pile2->GetVar();
-                p = p->GetNext();
-                if ( p == nullptr) break;
-            }
-            ppVars[i] = nullptr;
-
-            // creates a variable for the result
-            CBotVar*    pResult = nullptr;     // constructor still void
-
-            if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(),
-                                         pThis, ppVars,
-                                         pResult, pile2, GetToken())) return false; // interrupt
-
-            pThis->SetInit(CBotVar::InitType::DEF);
-            pThis->ConstructorSet();        // indicates that the constructor has been called
-            pile->Return(pile2);                                // releases a piece of stack
-
-//          pInstance = pThis->GetPointer();
-
-        }
-
-//      if ( !bIntrincic ) pThis->SetPointer(pInstance);        // a pointer to the instance
-
-        pile->SetState(3);                                  // finished this part
-    }
-
-    if ( pile->IfStep() ) return false;
-
-    if ( m_next2b != nullptr &&
-        !m_next2b->Execute(pile)) return false;             // other (s) definition (s)
-
-    return pj->Return( pile );                              // transmits below (further)
-}
-
-
-
-void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
-{
-    CBotVar*    pThis = nullptr;
-
-    CBotStack*  pile = pj;
-    if ( bMain ) pile = pj->RestoreStack(this);
-    if ( pile == nullptr ) return;
-
-    // creates the variable of type pointer to the object
-    {
-        CBotString  name = m_var->m_token.GetString();
-        pThis = pile->FindVar(name);
-        pThis->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent); // its attribute a unique number
-    }
-
-    CBotToken*  pt = &m_token;
-    CBotClass*  pClass = CBotClass::Find(pt);
-    bool bIntrincic = pClass->IsIntrinsic();
-
-    if ( bMain && pile->GetState()<3)
-    {
-        // is there an assignment or parameters (constructor)
-
-//      CBotVarClass* pInstance = nullptr;
-
-        if ( m_expr != nullptr )
-        {
-            // evaluates the expression for the assignment
-            m_expr->RestoreState(pile, bMain);
-            return;
-        }
-
-        else if ( m_hasParams )
-        {
-            // evaluates the constructor of an instance
-
-            if ( !bIntrincic && pile->GetState() == 1)
-            {
-                return;
-            }
-
-            CBotVar*    ppVars[1000];
-            CBotStack*  pile2 = pile;
-
-            int     i = 0;
-
-            CBotInstr*  p = m_Parameters;
-            // evaluates the parameters
-            // and the values an the stack
-            // for the ability to be interrupted at any time (\TODO pour pouvoir être interrompu n'importe quand)
-
-            if ( p != nullptr) while ( true )
-            {
-                pile2 = pile2->RestoreStack();                      // place on the stack for the results
-                if ( pile2 == nullptr ) return;
-
-                if ( pile2->GetState() == 0 )
-                {
-                    p->RestoreState(pile2, bMain);      // interrupted here?
-                    return;
-                }
-                ppVars[i++] = pile2->GetVar();
-                p = p->GetNext();
-                if ( p == nullptr) break;
-            }
-            ppVars[i] = nullptr;
-
-            // creates a variable for the result
-//            CBotVar*    pResult = nullptr;     // constructor still void
-
-            pClass->RestoreMethode(m_nMethodeIdent, pClass->GetName(), pThis, ppVars, pile2);
-            return;
-        }
-    }
-
-    if ( m_next2b != nullptr )
-         m_next2b->RestoreState(pile, bMain);                   // other(s) definition(s)
-}
-
-
 // test if a procedure name is already defined somewhere
 
 bool CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp
similarity index 56%
copy from src/CBot/CBotClass.cpp
copy to src/CBot/CBotInstr/CBotClassInst.cpp
index 11f93a1..cf835df 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotInstr/CBotClassInst.cpp
@@ -17,455 +17,17 @@
  * along with this program. If not, see http://gnu.org/licenses
  */
 
-/////////////////////////////////////////////////////////////////////
-// Management of variables of class type
-//
+// Modules inlcude
+#include "CBotClassInst.h"
+#include "CBotLeftExprVar.h"
+#include "CBotTwoOpExpr.h"
 
-#include "CBot.h"
-#include "CBotInstr/CBotNew.h"
-#include "CBotInstr/CBotLeftExprVar.h"
-#include "CBotInstr/CBotTwoOpExpr.h"
+// Local include
 
-CBotClass* CBotClass::m_ExClass = nullptr;
+// Global include
 
-CBotClass::CBotClass(const char* name, CBotClass* pPapa, bool bIntrinsic)
-{
-    m_pParent   = pPapa;
-    m_name      = name;
-    m_pVar      = nullptr;
-    m_next      = nullptr;
-    m_pCalls    = nullptr;
-    m_pMethod   = nullptr;
-    m_rMaj      = nullptr;
-    m_IsDef     = true;
-    m_bIntrinsic= bIntrinsic;
-    m_cptLock   = 0;
-    m_cptOne    = 0;
-    m_nbVar     = m_pParent == nullptr ? 0 : m_pParent->m_nbVar;
-
-    for ( int j= 0; j< 5 ; j++ )
-    {
-        m_ProgInLock[j] = nullptr;
-    }
-
-
-    // is located alone in the list
-    if (m_ExClass) m_ExClass->m_ExPrev = this;
-    m_ExNext  = m_ExClass;
-    m_ExPrev  = nullptr;
-    m_ExClass = this;
-
-}
-
-CBotClass::~CBotClass()
-{
-    // removes the list of class
-    if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext;
-    else m_ExClass = m_ExNext;
-
-    if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev;
-    m_ExPrev = nullptr;
-    m_ExNext = nullptr;
-
-    delete  m_pVar;
-    delete  m_pCalls;
-    delete  m_pMethod;
-
-    delete  m_next;         // releases all of them on this level
-}
-
-CBotClass* CBotClass::Create(const char* name, CBotClass* parent, bool intrinsic)
-{
-    return new CBotClass(name, parent, intrinsic);
-}
-
-void CBotClass::Free()
-{
-    while ( m_ExClass != nullptr )
-    {
-        delete m_ExClass;
-    }
-}
-
-void CBotClass::Purge()
-{
-    if ( this == nullptr ) return;
-
-    delete      m_pVar;
-    m_pVar      = nullptr;
-    delete      m_pCalls;
-    m_pCalls    = nullptr;
-    delete      m_pMethod;
-    m_pMethod   = nullptr;
-    m_IsDef     = false;
-
-    m_nbVar     = m_pParent == nullptr ? 0 : m_pParent->m_nbVar;
-
-    m_next->Purge();
-    m_next = nullptr;          // no longer belongs to this chain
-}
-
-bool CBotClass::Lock(CBotProgram* p)
-{
-    int i = m_cptLock++;
-
-    if ( i == 0 )
-    {
-        m_cptOne = 1;
-        m_ProgInLock[0] = p;
-        return true;
-    }
-    if ( p == m_ProgInLock[0] )
-    {
-        m_cptOne++;
-        m_cptLock--;                                // has already been counted
-        return true;
-    }
-
-    for ( int j = 1 ; j <= i ; j++)
-    {
-        if ( p == m_ProgInLock[j] )
-        {
-            m_cptLock--;
-            return false;   // already pending
-        }
-    }
-
-    if ( i < 5 )    // max 5 in query
-    {
-        m_ProgInLock[i] = p;                        // located in a queue
-    }
-    else
-        m_cptLock--;
-
-    return false;
-}
-
-void CBotClass::Unlock()
-{
-    if ( --m_cptOne > 0 ) return ;
-
-    int i = --m_cptLock;
-    if ( i<0 )
-    {
-        m_cptLock = 0;
-        return;
-    }
-
-    for ( int j= 0; j< i ; j++ )
-    {
-        m_ProgInLock[j] = m_ProgInLock[j+1];
-    }
-    m_ProgInLock[i] = nullptr;
-}
-
-void CBotClass::FreeLock(CBotProgram* p)
-{
-    CBotClass* pClass = m_ExClass;
-
-    while ( pClass != nullptr )
-    {
-        if ( p == pClass->m_ProgInLock[0] )
-        {
-            pClass->m_cptLock -= pClass->m_cptOne;
-            pClass->m_cptOne = 0;
-        }
-
-        for ( int j = 1; j < 5 ; j++ )
-            if ( p == pClass->m_ProgInLock[j] )
-                pClass->m_cptLock--;
-
-        pClass = pClass->m_ExNext;
-    }
-}
-
-
-
-bool CBotClass::AddItem(CBotString name, CBotTypResult type, int mPrivate)
-{
-    CBotToken   token(name, CBotString());
-    CBotClass*  pClass = type.GetClass();
-
-    CBotVar*    pVar = CBotVar::Create( name, type );
-/// pVar->SetUniqNum(CBotVar::NextUniqNum());
-    pVar->SetPrivate( mPrivate );
-
-    if ( pClass != nullptr )
-    {
-//      pVar->SetClass(pClass);
-        if ( type.Eq(CBotTypClass) )
-        {
-            // adds a new statement for the object initialization
-            pVar->m_InitExpr = new CBotNew() ;
-            CBotToken nom( pClass->GetName() );
-            pVar->m_InitExpr->SetToken(&nom);
-        }
-    }
-    return AddItem( pVar );
-}
-
-
-bool CBotClass::AddItem(CBotVar* pVar)
-{
-    pVar->SetUniqNum(++m_nbVar);
-
-    if ( m_pVar == nullptr ) m_pVar = pVar;
-    else m_pVar->AddNext(pVar);
-
-    return true;
-}
-
-void CBotClass::AddNext(CBotClass* pClass)
-{
-    CBotClass*      p = this;
-    while (p->m_next != nullptr) p = p->m_next;
-
-    p->m_next = pClass;
-}
-
-CBotString  CBotClass::GetName()
-{
-    return m_name;
-}
-
-CBotClass*  CBotClass::GetParent()
-{
-    if ( this == nullptr ) return nullptr;
-    return m_pParent;
-}
-
-bool  CBotClass::IsChildOf(CBotClass* pClass)
-{
-    CBotClass* p = this;
-    while ( p != nullptr )
-    {
-        if ( p == pClass ) return true;
-        p = p->m_pParent;
-    }
-    return false;
-}
-
-
-CBotVar* CBotClass::GetVar()
-{
-    return  m_pVar;
-}
-
-CBotVar* CBotClass::GetItem(const char* name)
-{
-    CBotVar*    p = m_pVar;
-
-    while ( p != nullptr )
-    {
-        if ( p->GetName() == name ) return p;
-        p = p->GetNext();
-    }
-    if ( m_pParent != nullptr ) return m_pParent->GetItem(name);
-    return nullptr;
-}
-
-CBotVar* CBotClass::GetItemRef(int nIdent)
-{
-    CBotVar*    p = m_pVar;
-
-    while ( p != nullptr )
-    {
-        if ( p->GetUniqNum() == nIdent ) return p;
-        p = p->GetNext();
-    }
-    if ( m_pParent != nullptr ) return m_pParent->GetItemRef(nIdent);
-    return nullptr;
-}
-
-bool CBotClass::IsIntrinsic()
-{
-    return  m_bIntrinsic;
-}
-
-CBotClass* CBotClass::Find(CBotToken* &pToken)
-{
-    return Find(pToken->GetString());
-}
-
-CBotClass* CBotClass::Find(const char* name)
-{
-    CBotClass*  p = m_ExClass;
-
-    while ( p != nullptr )
-    {
-        if ( p->GetName() == name ) return p;
-        p = p->m_ExNext;
-    }
-
-    return nullptr;
-}
-
-bool CBotClass::AddFunction(const char* name,
-                                bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
-                                CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar))
-{
-    // stores pointers to the two functions
-    CBotCallMethode*    p = m_pCalls;
-    CBotCallMethode*    pp = nullptr;
-
-    while ( p != nullptr )
-    {
-        if ( name == p->GetName() )
-        {
-            if ( pp == nullptr ) m_pCalls = p->m_next;
-            else              pp->m_next = p->m_next;
-            delete p;
-            break;
-        }
-        pp = p;
-        p = p->m_next;
-    }
-
-    p = new CBotCallMethode(name, rExec, rCompile);
-
-    if (m_pCalls == nullptr) m_pCalls = p;
-    else    m_pCalls->AddNext(p);               // added to the list
-
-    return true;
-}
-
-bool CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) )
-{
-    m_rMaj = rMaj;
-    return true;
-}
-
-// compiles a method associated with an instance of class
-// the method can be declared by the user or AddFunction
-
-CBotTypResult CBotClass::CompileMethode(const char* name,
-                                        CBotVar* pThis, CBotVar** ppParams,
-                                        CBotCStack* pStack, long& nIdent)
-{
-    nIdent = 0; // forget the previous one if necessary
-
-    // find the methods declared by AddFunction
-
-    CBotTypResult r = m_pCalls->CompileCall(name, pThis, ppParams, pStack, nIdent);
-    if ( r.GetType() >= 0) return r;
-
-    // find the methods declared by user
-
-    r = m_pMethod->CompileCall(name, ppParams, nIdent);
-    if ( r.Eq(TX_UNDEFCALL) && m_pParent != nullptr )
-        return m_pParent->m_pMethod->CompileCall(name, ppParams, nIdent);
-    return r;
-}
-
-// executes a method
-
-bool CBotClass::ExecuteMethode(long& nIdent, const char* name,
-                               CBotVar* pThis, CBotVar** ppParams,
-                               CBotVar* &pResult, CBotStack* &pStack,
-                               CBotToken* pToken)
-{
-    int ret = m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken);
-    if (ret>=0) return ret;
-
-    ret = m_pMethod->DoCall(nIdent, name, pThis, ppParams, pStack, pToken, this);
-    if (ret >= 0) return ret;
-
-    if (m_pParent != nullptr)
-    {
-        ret = m_pParent->m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken);
-        if (ret >= 0) return ret;
-        ret = m_pParent->m_pMethod->DoCall(nIdent, name, pThis, ppParams, pStack, pToken, m_pParent);
-    }
-    return ret;
-}
-
-// restored the execution stack
-
-void CBotClass::RestoreMethode(long& nIdent, const char* name, CBotVar* pThis,
-                               CBotVar** ppParams, CBotStack* &pStack)
-{
-    m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this);
-}
-
-
-
-
-bool CBotClass::SaveStaticState(FILE* pf)
-{
-    if (!WriteWord( pf, CBOTVERSION*2)) return false;
-
-    // saves the state of static variables in classes
-    CBotClass*  p = m_ExClass;
-
-    while ( p != nullptr )
-    {
-        if (!WriteWord( pf, 1)) return false;
-        // save the name of the class
-        if (!WriteString( pf, p->GetName() )) return false;
-
-        CBotVar*    pv = p->GetVar();
-        while( pv != nullptr )
-        {
-            if ( pv->IsStatic() )
-            {
-                if (!WriteWord( pf, 1)) return false;
-                if (!WriteString( pf, pv->GetName() )) return false;
-
-                if ( !pv->Save0State(pf)) return false;             // common header
-                if ( !pv->Save1State(pf) ) return false;                // saves as the child class
-                if ( !WriteWord( pf, 0)) return false;
-            }
-            pv = pv->GetNext();
-        }
-
-        if (!WriteWord( pf, 0)) return false;
-        p = p->m_ExNext;
-    }
-
-    if (!WriteWord( pf, 0)) return false;
-    return true;
-}
-
-bool CBotClass::RestoreStaticState(FILE* pf)
-{
-    CBotString      ClassName, VarName;
-    CBotClass*      pClass;
-    unsigned short  w;
-
-    if (!ReadWord( pf, w )) return false;
-    if ( w != CBOTVERSION*2 ) return false;
-
-    while (true)
-    {
-        if (!ReadWord( pf, w )) return false;
-        if ( w == 0 ) return true;
-
-        if (!ReadString( pf, ClassName )) return false;
-        pClass = Find(ClassName);
-
-        while (true)
-        {
-            if (!ReadWord( pf, w )) return false;
-            if ( w == 0 ) break;
-
-            CBotVar*    pVar = nullptr;
-            CBotVar*    pv = nullptr;
-
-            if (!ReadString( pf, VarName )) return false;
-            if ( pClass != nullptr ) pVar = pClass->GetItem(VarName);
-
-            if (!CBotVar::RestoreState(pf, pv)) return false;   // the temp variable
-
-            if ( pVar != nullptr ) pVar->Copy(pv);
-            delete pv;
-        }
-    }
-    return true;
-}
-
-
-/////////////////////////////////////////////////////////////////////
 
+////////////////////////////////////////////////////////////////////////////////
 CBotClassInst::CBotClassInst()
 {
     m_next          = nullptr;
@@ -477,16 +39,13 @@ CBotClassInst::CBotClassInst()
     name = "CBotClassInst";
 }
 
+////////////////////////////////////////////////////////////////////////////////
 CBotClassInst::~CBotClassInst()
 {
     delete m_var;
-//  delete m_next;          // done by the destructor of the base class ~CBotInstr()
 }
 
-// definition of pointer (s) to an object
-// style
-// CPoint A, B ;
-
+////////////////////////////////////////////////////////////////////////////////
 CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass)
 {
     // seeks the corresponding classes
@@ -655,9 +214,7 @@ error:
     return pStack->Return(nullptr, pStk);
 }
 
-// declaration of the instance of a class, for example:
-//  CPoint A, B;
-
+////////////////////////////////////////////////////////////////////////////////
 bool CBotClassInst::Execute(CBotStack* &pj)
 {
     CBotVar*    pThis = nullptr;
@@ -792,8 +349,7 @@ bool CBotClassInst::Execute(CBotStack* &pj)
     return pj->Return( pile );                              // transmits below (further)
 }
 
-
-
+////////////////////////////////////////////////////////////////////////////////
 void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
 {
     CBotVar*    pThis = nullptr;
@@ -872,27 +428,3 @@ void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
     if ( m_next2b != nullptr )
          m_next2b->RestoreState(pile, bMain);                   // other(s) definition(s)
 }
-
-
-// test if a procedure name is already defined somewhere
-
-bool CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
-{
-    CBotString  name = pToken->GetString();
-
-    if ( CBotCall::CheckCall(name) ) return true;
-
-    CBotFunction*   pp = m_pMethod;
-    while ( pp != nullptr )
-    {
-        if ( pToken->GetString() == pp->GetName() )
-        {
-            // are their parameters exactly the same?
-            if ( pp->CheckParam( pParam ) )
-                return true;
-        }
-        pp = pp->Next();
-    }
-
-    return false;
-}
diff --git a/src/CBot/CBotInstr/CBotClassInst.h b/src/CBot/CBotInstr/CBotClassInst.h
new file mode 100644
index 0000000..370a46c
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotClassInst.h
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsitec.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+// Modules inlcude
+#include "CBot.h"
+
+// Local include
+
+// Global include
+
+/*!
+ * \brief The CBotClassInst class Definition of an element of any class.
+ */
+class CBotClassInst : public CBotInstr
+{
+
+public:
+
+    /*!
+     * \brief CBotClassInst
+     */
+    CBotClassInst();
+
+    /*!
+     * \brief ~CBotClassInst
+     */
+    ~CBotClassInst();
+
+    /*!
+     * \brief Compile Definition of pointer (s) to an object style CPoint A, B ;
+     * \param p
+     * \param pStack
+     * \param pClass
+     * \return
+     */
+    static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr);
+
+    /*!
+     * \brief Execute Declaration of the instance of a class, for example:
+     * CPoint A, B;
+     * \param pj
+     * \return
+     */
+    bool Execute(CBotStack* &pj) override;
+
+    /*!
+     * \brief RestoreState
+     * \param pj
+     * \param bMain
+     */
+    void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+
+    //! Variable to initialise.
+    CBotInstr* m_var;
+    //! Reference to the class.
+    CBotClass* m_pClass;
+    //! Parameters to be evaluated for the contructor.
+    CBotInstr* m_Parameters;
+    //! A value to put, if there is.
+    CBotInstr* m_expr;
+    //! Has it parameters.
+    bool m_hasParams;
+    long m_nMethodeIdent;
+
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index e94bf82..7142723 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -42,6 +42,7 @@ set(SOURCES
     CBotInstr/CBotFieldExpr.cpp
     CBotInstr/CBotLeftExpr.cpp
     CBotInstr/CBotCondition.cpp
+    CBotInstr/CBotClassInst.cpp
 )
 
 # Includes

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list