[colobot] 207/377: More CBotStack docs

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:17 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 9b3b701785f4639402ebd9ed2b59483e109cb76f
Author: krzys-h <krzys_h at interia.pl>
Date:   Fri Dec 25 20:47:30 2015 +0100

    More CBotStack docs
---
 src/CBot/CBotCallMethode.h              |   2 -
 src/CBot/CBotClass.h                    |   1 +
 src/CBot/CBotInstr/CBotFor.cpp          |   2 +-
 src/CBot/CBotInstr/CBotFunction.cpp     |  20 ++--
 src/CBot/CBotInstr/CBotInstrMethode.cpp |   4 +-
 src/CBot/CBotInstr/CBotListInstr.cpp    |   2 +-
 src/CBot/CBotStack.cpp                  |  61 +++-------
 src/CBot/CBotStack.h                    | 206 ++++++++++++++++++++++++++------
 8 files changed, 200 insertions(+), 98 deletions(-)

diff --git a/src/CBot/CBotCallMethode.h b/src/CBot/CBotCallMethode.h
index 85d9985..17fab20 100644
--- a/src/CBot/CBotCallMethode.h
+++ b/src/CBot/CBotCallMethode.h
@@ -57,7 +57,6 @@ public:
      * \param pThis
      * \param ppVars
      * \param pStack
-     * \param nIdent
      * \return
      */
     CBotTypResult CompileCall(const std::string& name, CBotVar* pThis, CBotVar** ppVars,
@@ -65,7 +64,6 @@ public:
 
     /*!
      * \brief DoCall
-     * \param nIdent
      * \param name
      * \param pThis
      * \param ppVars
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index 6233de3..152849a 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -350,6 +350,7 @@ public:
 
     /*!
      * \brief CheckCall Test if a procedure name is already defined somewhere.
+     * \param program
      * \param pToken
      * \param pParam
      * \return
diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp
index 2b93a17..bc13636 100644
--- a/src/CBot/CBotInstr/CBotFor.cpp
+++ b/src/CBot/CBotInstr/CBotFor.cpp
@@ -115,7 +115,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
 ////////////////////////////////////////////////////////////////////////////////
 bool CBotFor :: Execute(CBotStack* &pj)
 {
-    CBotStack* pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE);     // adds an item to the stack (variables locales)
+    CBotStack* pile = pj->AddStack(this, CBotStack::IsBlock::BLOCK);     // adds an item to the stack (variables locales)
                                                     // or find in case of recovery
 //  if ( pile == EOX ) return true;
 
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 6a5a914..c83484a 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -335,7 +335,7 @@ bad:
 ////////////////////////////////////////////////////////////////////////////////
 bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
 {
-    CBotStack*  pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_2);               // one end of stack local to this function
+    CBotStack*  pile = pj->AddStack(this, CBotStack::IsBlock::FUNCTION);               // one end of stack local to this function
 //  if ( pile == EOX ) return true;
 
     pile->SetProgram(m_pProg);                              // bases for routines
@@ -397,7 +397,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
 
     pile->SetProgram(m_pProg);                          // bases for routines
 
-    if ( pile->GetBlock() != CBotStack::UnknownEnumBlock::UNKNOWN_2 )
+    if ( pile->GetBlock() != CBotStack::IsBlock::FUNCTION)
     {
         CBotStack*  pile2 = pile->RestoreStack(nullptr);       // one end of stack local to this function
         if ( pile2 == nullptr ) return;
@@ -600,14 +600,14 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
 
     if ( pt != nullptr )
     {
-        CBotStack*  pStk1 = pStack->AddStack(pt, CBotStack::UnknownEnumBlock::UNKNOWN_2);    // to put "this"
+        CBotStack*  pStk1 = pStack->AddStack(pt, CBotStack::IsBlock::FUNCTION);    // to put "this"
 //      if ( pStk1 == EOX ) return true;
 
         pStk1->SetProgram(pt->m_pProg);                 // it may have changed module
 
         if ( pStk1->IfStep() ) return false;
 
-        CBotStack*  pStk3 = pStk1->AddStack(nullptr, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE);    // parameters
+        CBotStack*  pStk3 = pStk1->AddStack(nullptr, CBotStack::IsBlock::BLOCK);    // parameters
 
         // preparing parameters on the stack
 
@@ -682,7 +682,7 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar**
 
         pStk1->SetProgram(pt->m_pProg);                 // it may have changed module
 
-        if ( pStk1->GetBlock() != CBotStack::UnknownEnumBlock::UNKNOWN_2 )
+        if ( pStk1->GetBlock() != CBotStack::IsBlock::FUNCTION)
         {
             CBotStack* pStk2 = pStk1->RestoreStack(nullptr); // used more
             if ( pStk2 == nullptr ) return;
@@ -725,7 +725,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis,
                          CBotToken* pToken, CBotClass* pClass)
 {
     CBotTypResult   type;
-    CBotProgram*    pProgCurrent = pStack->GetBotCall();
+    CBotProgram*    pProgCurrent = pStack->GetProgram();
 
     CBotFunction*   pt = FindLocalOrPublic(nIdent, name, ppVars, type, false);
 
@@ -733,11 +733,11 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis,
     {
 //      DEBUG( "CBotFunction::DoCall" + pt->GetName(), 0, pStack);
 
-        CBotStack*  pStk = pStack->AddStack(pt, CBotStack::UnknownEnumBlock::UNKNOWN_2);
+        CBotStack*  pStk = pStack->AddStack(pt, CBotStack::IsBlock::FUNCTION);
 //      if ( pStk == EOX ) return true;
 
         pStk->SetProgram(pt->m_pProg);                  // it may have changed module
-        CBotStack*  pStk3 = pStk->AddStack(nullptr, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // to set parameters passed
+        CBotStack*  pStk3 = pStk->AddStack(nullptr, CBotStack::IsBlock::BLOCK); // to set parameters passed
 
         // preparing parameters on the stack
 
@@ -767,7 +767,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis,
         {
             if ( pt->m_bSynchro )
             {
-                CBotProgram* pProgBase = pStk->GetBotCall(true);
+                CBotProgram* pProgBase = pStk->GetProgram(true);
                 if ( !pClass->Lock(pProgBase) ) return false;       // expected to power \TODO attend de pouvoir
             }
             pStk->IncState();
@@ -826,7 +826,7 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* p
         if ( pStk->GetState() > 1 &&                        // latching is effective?
              pt->m_bSynchro )
             {
-                CBotProgram* pProgBase = pStk->GetBotCall(true);
+                CBotProgram* pProgBase = pStk->GetProgram(true);
                 pClass->Lock(pProgBase);                    // locks the class
             }
 
diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp
index f8493bc..98c1f5b 100644
--- a/src/CBot/CBotInstr/CBotInstrMethode.cpp
+++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp
@@ -106,7 +106,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
 bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend)
 {
     CBotVar*    ppVars[1000];
-    CBotStack*    pile1 = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE);     // a place for the copy of This
+    CBotStack*    pile1 = pj->AddStack(this, CBotStack::IsBlock::BLOCK);     // a place for the copy of This
 
     if (pVar->GetPointer() == nullptr)
     {
@@ -221,7 +221,7 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
 bool CBotInstrMethode::Execute(CBotStack* &pj)
 {
     CBotVar*    ppVars[1000];
-    CBotStack*    pile1 = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE);        // place for the copy of This
+    CBotStack*    pile1 = pj->AddStack(this, CBotStack::IsBlock::BLOCK);        // place for the copy of This
 
     if (pile1->IfStep()) return false;
 
diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp
index 7958dae..3e1ab7d 100644
--- a/src/CBot/CBotInstr/CBotListInstr.cpp
+++ b/src/CBot/CBotInstr/CBotListInstr.cpp
@@ -80,7 +80,7 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal
 bool CBotListInstr::Execute(CBotStack* &pj)
 {
 
-    CBotStack*    pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE);                //needed for SetState()
+    CBotStack*    pile = pj->AddStack(this, CBotStack::IsBlock::BLOCK);                //needed for SetState()
     if (pile->StackOver() ) return pj->Return( pile);
 
 
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 319371d..7308e70 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -58,7 +58,7 @@ CBotStack* CBotStack::AllocateStack()
     // completely empty
     memset(p, 0, size);
 
-    p-> m_bBlock = UnknownEnumBlock::UNKNOWN_TRUE ;
+    p-> m_bBlock = IsBlock::BLOCK;
     m_timer = m_initimer;                // sets the timer at the beginning
 
     CBotStack* pp = p;
@@ -107,7 +107,7 @@ void CBotStack::Delete()
 
 // routine improved
 ////////////////////////////////////////////////////////////////////////////////
-CBotStack* CBotStack::AddStack(CBotInstr* instr, UnknownEnumBlock bBlock)
+CBotStack* CBotStack::AddStack(CBotInstr* instr, IsBlock bBlock)
 {
     if (m_next != nullptr)
     {
@@ -129,12 +129,12 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, UnknownEnumBlock bBlock)
     p->m_prev         = this;
     p->m_state         = 0;
     p->m_call         = nullptr;
-    p->m_bFunc         = IsFunctionParam::FALSE;
+    p->m_bFunc         = IsFunction::NO;
     return    p;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotStack* CBotStack::AddStackEOX(CBotExternalCall* instr, UnknownEnumBlock bBlock)
+CBotStack* CBotStack::AddStackEOX(CBotExternalCall* instr, IsBlock bBlock)
 {
     if (m_next != nullptr)
     {
@@ -147,12 +147,12 @@ CBotStack* CBotStack::AddStackEOX(CBotExternalCall* instr, UnknownEnumBlock bBlo
     }
     CBotStack*    p = AddStack(nullptr, bBlock);
     p->m_call = instr;
-    p->m_bFunc = IsFunctionParam::UNKNOWN_EOX_SPECIAL;    // special
+    p->m_bFunc = IsFunction::EXTERNAL_CALL;    // special
     return    p;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotStack* CBotStack::AddStack2(UnknownEnumBlock bBlock)
+CBotStack* CBotStack::AddStack2(IsBlock bBlock)
 {
     if (m_next2 != nullptr)
     {
@@ -176,7 +176,7 @@ CBotStack* CBotStack::AddStack2(UnknownEnumBlock bBlock)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotStack::UnknownEnumBlock CBotStack::GetBlock()
+CBotStack::IsBlock CBotStack::GetBlock()
 {
     return    m_bBlock;
 }
@@ -193,7 +193,7 @@ bool CBotStack::Return(CBotStack* pfils)
     m_next->Delete();m_next = nullptr;                // releases the stack above
     m_next2->Delete();m_next2 = nullptr;            // also the second stack (catch)
 
-    return (m_error == 0);                        // interrupted if error
+    return IsOk();                        // interrupted if error
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -205,7 +205,7 @@ bool CBotStack::ReturnKeep(CBotStack* pfils)
     m_var = pfils->m_var;                        // result transmitted
     pfils->m_var = nullptr;                        // not to destroy the variable
 
-    return (m_error == 0);                        // interrupted if error
+    return IsOk();                        // interrupted if error
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -311,14 +311,6 @@ bool CBotStack::GetRetVar(bool bRet)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotError CBotStack::GetError(int& start, int& end)
-{
-    start = m_start;
-    end      = m_end;
-    return m_error;
-}
-
-////////////////////////////////////////////////////////////////////////////////
 CBotVar* CBotStack::FindVar(CBotToken*& pToken, bool bUpdate)
 {
     CBotStack*    p = this;
@@ -510,23 +502,6 @@ CBotVar* CBotStack::GetVar()
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotStack::GetPtVar()
-{
-    CBotVar*    p = m_var;
-    m_var = nullptr;                // therefore will not be destroyed
-    return p;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotStack::GetCopyVar()
-{
-    if (m_var == nullptr) return nullptr;
-    CBotVar*    v = CBotVar::Create("", m_var->GetType());
-    v->Copy( m_var );
-    return v;
-}
-
-////////////////////////////////////////////////////////////////////////////////
 long CBotStack::GetVal()
 {
     if (m_var == nullptr) return 0;
@@ -539,7 +514,7 @@ void CBotStack::AddVar(CBotVar* pVar)
     CBotStack*    p = this;
 
     // returns to the father element
-    while (p != nullptr && p->m_bBlock == UnknownEnumBlock::UNKNOWN_FALSE) p = p->m_prev;
+    while (p != nullptr && p->m_bBlock == IsBlock::INSTRUCTION) p = p->m_prev;
 
     if ( p == nullptr ) return;
 
@@ -555,11 +530,11 @@ void CBotStack::AddVar(CBotVar* pVar)
 void CBotStack::SetProgram(CBotProgram* p)
 {
     m_prog  = p;
-    m_bFunc = IsFunctionParam::TRUE;
+    m_bFunc = IsFunction::TRUE;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotProgram*  CBotStack::GetBotCall(bool bFirst)
+CBotProgram*  CBotStack::GetProgram(bool bFirst)
 {
     if ( ! bFirst )    return m_prog;
     CBotStack*    p = this;
@@ -645,7 +620,7 @@ void CBotStack::GetRunPos(std::string& FunctionName, int& start, int& end)
     while (p->m_next != nullptr)
     {
         if ( p->m_instr != nullptr ) instr = p->m_instr;
-        if ( p->m_bFunc == IsFunctionParam::TRUE && p->m_instr != nullptr ) funct = p->m_instr;
+        if ( p->m_bFunc == IsFunction::TRUE && p->m_instr != nullptr ) funct = p->m_instr;
         if ( p->m_next->m_prog != prog ) break ;
 
         if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ;
@@ -653,7 +628,7 @@ void CBotStack::GetRunPos(std::string& FunctionName, int& start, int& end)
     }
 
     if ( p->m_instr != nullptr ) instr = p->m_instr;
-    if ( p->m_bFunc == IsFunctionParam::TRUE && p->m_instr != nullptr ) funct = p->m_instr;
+    if ( p->m_bFunc == IsFunction::TRUE && p->m_instr != nullptr ) funct = p->m_instr;
 
     if ( funct == nullptr ) return;
 
@@ -687,13 +662,13 @@ CBotVar* CBotStack::GetStackVars(std::string& FunctionName, int level)
 
 
     // descends upon the elements of block
-    while ( p != nullptr && p->m_bBlock == UnknownEnumBlock::UNKNOWN_FALSE ) p = p->m_prev;
+    while ( p != nullptr && p->m_bBlock == IsBlock::INSTRUCTION) p = p->m_prev;
     // Now p is on the beggining of the top block (with local variables)
 
     while ( p != nullptr && level++ < 0 )
     {
         p = p->m_prev;
-        while ( p != nullptr && p->m_bBlock == UnknownEnumBlock::UNKNOWN_FALSE ) p = p->m_prev;
+        while ( p != nullptr && p->m_bBlock == IsBlock::INSTRUCTION) p = p->m_prev;
     }
     // Now p is on the block "level"
 
@@ -703,7 +678,7 @@ CBotVar* CBotStack::GetStackVars(std::string& FunctionName, int level)
     CBotStack* pp = p;
     while ( pp != nullptr )
     {
-        if ( pp->m_bFunc == IsFunctionParam::TRUE) break;
+        if ( pp->m_bFunc == IsFunction::TRUE) break;
         pp = pp->m_prev;
     }
 
@@ -762,7 +737,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
     }
 
     if (!ReadWord(pf, w)) return false;            // is a local block
-    pStack->m_bBlock = static_cast<UnknownEnumBlock>(w);
+    pStack->m_bBlock = static_cast<IsBlock>(w);
 
     if (!ReadWord(pf, w)) return false;            // in what state ?
     pStack->SetState(static_cast<short>(w));                    // in a good state
diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h
index e8773b2..3131a65 100644
--- a/src/CBot/CBotStack.h
+++ b/src/CBot/CBotStack.h
@@ -35,12 +35,18 @@ class CBotToken;
 
 /**
  * \brief The execution stack
+ *
+ * \nosubgrouping
  */
 class CBotStack
 {
 public:
-    enum class UnknownEnumBlock : unsigned short { UNKNOWN_FALSE = 0, UNKNOWN_TRUE = 1, UNKNOWN_2 = 2 }; // TODO: figure out what these mean ~krzys_h
-    enum class IsFunctionParam : unsigned short { FALSE = 0, TRUE = 1, UNKNOWN_EOX_SPECIAL = 2 }; // TODO: just guessing the meaning of values, should be verified ~krzys_h
+    enum class IsBlock : unsigned short { INSTRUCTION = 0, BLOCK = 1, FUNCTION = 2 }; // TODO: figure out what these mean ~krzys_h
+    enum class IsFunction : unsigned short { NO = 0, TRUE = 1, EXTERNAL_CALL = 2 }; // TODO: just guessing the meaning of values, should be verified ~krzys_h
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    //! \name Stack memory management
+    //@{
 
     /**
      * \brief Allocate the stack
@@ -60,26 +66,54 @@ public:
      */
     bool StackOver();
 
+    //@}
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /** \name Error management
+     *
+     * Be careful - errors are stored in static variables!
+     * \todo Refactor that
+     */
+    //@{
+
     /**
      * \brief Get last error
      * \param[out] start Starting position in code of the error
      * \param[out] end Ending position in code of the error
      * \return Error number
      */
-    CBotError GetError(int& start, int& end);
+    CBotError GetError(int& start, int& end) { start = m_start; end = m_end; return m_error; }
 
     /**
      * \brief Get last error
      * \return Error number
      * \see GetError(int&, int&) for error position in code
      */
-    CBotError GetError();
+    CBotError GetError() { return m_error; }
+
+    /**
+     * \brief Check if there was an error
+     * \return false if an error occured
+     * \see GetError()
+     */
+    bool IsOk()
+    {
+        return m_error == CBotNoErr;
+    }
+
+    //@}
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
     /**
      * \brief Reset the stack - resets the error and timer
      */
     void Reset();
 
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    //! \name Local variables
+    //@{
+
     /**
      * \brief Adds a local variable
      * \param var Variable to be added
@@ -126,46 +160,158 @@ public:
      */
     CBotVar*        CopyVar(CBotToken& pToken, bool bUpdate = false);
 
+    //@}
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /** \name Child stacks
+     *
+     * When you enter a new code block or instruction, child stack is created
+     * for managing everything that happens inside that block / instruction.
+     */
+    //@{
 
-    CBotStack*        AddStack(CBotInstr* instr = nullptr, UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE);    // extends the stack
-    CBotStack*        AddStackEOX(CBotExternalCall* instr = nullptr, UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE);    // extends the stack
+    /**
+     * \brief Creates or gets the primary child stack
+     *
+     * If the stack already exists, it is returned.
+     * Otherwise, a new stack is created.
+     *
+     * \todo Document params
+     * \returns New stack element
+     */
+    CBotStack*        AddStack(CBotInstr* instr = nullptr, IsBlock bBlock = IsBlock::INSTRUCTION);
+
+    /**
+     * \brief Creates or gets the secondary child stack
+     * \todo What is it used for?
+     *
+     * If the stack already exists, it is returned.
+     * Otherwise, a new stack is created.
+     *
+     * \see AddStack()
+     * \return New stack element
+     */
+    CBotStack*        AddStack2(IsBlock bBlock = IsBlock::INSTRUCTION);
+
+    /**
+     * \brief Adds special EOX stack marker
+     *
+     * \todo What is this thing?
+     * Used by external calls
+     *
+     * \todo Document params & return
+     */
+    CBotStack*        AddStackEOX(CBotExternalCall* instr = nullptr, IsBlock bBlock = IsBlock::INSTRUCTION);
+
+    /**
+     * \brief Restore CBotInstr pointer after loading stack from file
+     * \todo Check what this does exactly
+     */
     CBotStack*        RestoreStack(CBotInstr* instr = nullptr);
+    /**
+     * \brief Restores CBotExternalCall in the EOX marker after loading stack from file
+     * \todo Check what this does exactly
+     */
     CBotStack*        RestoreStackEOX(CBotExternalCall* instr = nullptr);
 
-    CBotStack*        AddStack2(UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE);                        // extends the stack
-    bool            Return(CBotStack* pFils);                            // transmits the result over
-    bool            ReturnKeep(CBotStack* pFils);                        // transmits the result without reducing the stack
+    /**
+     * \brief Return to this point - copy the result from given stack, and destroy all child stacks from here
+     *
+     * \todo Better description
+     *
+     * \param pFils Stack to copy result from
+     * \return IsOk()
+     */
+    bool            Return(CBotStack* pFils);
+    /**
+     * \brief Like Return() but doesn't destroy the stacks
+     *
+     * \param pFils Stack to copy result from
+     * \return IsOk()
+     */
+    bool            ReturnKeep(CBotStack* pFils);
+
+    /**
+     * \todo Document
+     * in case of eventual break
+     */
     bool            BreakReturn(CBotStack* pfils, const std::string& name = nullptr);
-                                                                        // in case of eventual break
+    /**
+     * \todo Document
+     * or "continue"
+     */
     bool            IfContinue(int state, const std::string& name);
-                                                                        // or "continue"
 
-    bool            IsOk();
+    //@}
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /** \name Preserving execution status
+     *
+     * A "state" is a number that determines how much of CBotInstr::Execute() has been already executed.
+     * When CBotInstr::Execute() is called, it continues execution from the point it finished at.
+     * See various CBotInstr::Execute() implementations for details.
+     *
+     * Call CBotStack::Execute() to resume execution of the interrupted instruction
+     *
+     * \todo More detailed docs on functions
+     */
+    //@{
 
     bool            SetState(int n, int lim = -10);                        // select a state
-    int             GetState();                                            // in what state am I?
+    int             GetState() { return m_state; }                         // in what state am I?
     bool            IncState(int lim = -10);                            // passes to the next state
     bool            IfStep();                                            // do step by step
     bool            Execute();
 
-    void            SetVar( CBotVar* var );
+    //@}
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    // \name Result variable
+
+    //@{
+
+    /**
+     * \brief Set the result variable
+     * \todo CBotStack takes over the ownership - use std::unique_ptr here
+     * \param var Result variable to set
+     */
+    void            SetVar(CBotVar* var);
+    /**
+     * \brief Set the result variable to copy of given variable
+     * \param var Variable to copy as result
+     */
     void            SetCopyVar( CBotVar* var );
+    /**
+     * \brief Return result variable
+     * \return Variable set with SetVar() or SetCopyVar()
+     */
     CBotVar*        GetVar();
-    CBotVar*        GetCopyVar();
-    CBotVar*        GetPtVar();
+    /**
+     * \todo Document
+     */
     bool            GetRetVar(bool bRet);
+    /**
+     * \brief Return the result variable as int
+     * \deprecated Please use GetVar()->GetValInt() instead
+     * \todo Remove
+     * \return GetVar()->GetValInt(), or 0 if GetVar() == nullptr
+     */
     long            GetVal();
 
+    //@}
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
     void            SetError(CBotError n, CBotToken* token = nullptr);
     void            SetPosError(CBotToken* token);
     void            ResetError(CBotError n, int start, int end);
     void            SetBreak(int val, const std::string& name);
 
     void            SetProgram(CBotProgram* p);
-    CBotProgram*    GetBotCall(bool bFirst = false);
+    CBotProgram* GetProgram(bool bFirst = false);
     void            SetUserPtr(void* user);
     void*           GetUserPtr();
-    UnknownEnumBlock GetBlock();
+    IsBlock GetBlock();
 
 
     bool            ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype);
@@ -174,8 +320,7 @@ public:
     bool            SaveState(FILE* pf);
     bool            RestoreState(FILE* pf, CBotStack* &pStack);
 
-    static
-    void            SetTimer(int n);
+    static void     SetTimer(int n);
 
     void            GetRunPos(std::string& FunctionName, int& start, int& end);
     CBotVar*        GetStackVars(std::string& FunctionName, int level);
@@ -197,7 +342,7 @@ private:
     CBotVar*        m_var;                        // result of the operations
     CBotVar*        m_listVar;                    // variables declared at this level
 
-    UnknownEnumBlock m_bBlock;                    // is part of a block (variables are local to this block)
+    IsBlock m_bBlock;                    // is part of a block (variables are local to this block)
     bool            m_bOver;                    // stack limits?
 //    bool            m_bDontDelete;                // special, not to destroy the variable during delete
     CBotProgram*    m_prog;                        // user-defined functions
@@ -212,24 +357,7 @@ private:
     void*            m_pUser;
 
     CBotInstr*        m_instr;                    // the corresponding instruction
-    IsFunctionParam  m_bFunc;                    // an input of a function?
+    IsFunction m_bFunc;                    // an input of a function?
     CBotExternalCall*        m_call;                        // recovery point in a extern call
     friend class    CBotTry;
 };
-
-// inline routinees must be declared in file.h
-
-inline bool CBotStack::IsOk()
-{
-    return (m_error == 0);
-}
-
-inline int CBotStack::GetState()
-{
-    return m_state;
-}
-
-inline CBotError CBotStack::GetError()
-{
-    return m_error;
-}

-- 
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