[colobot] 206/377: Started docs of CBotStack; random refactorings

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 c72cfa234b96f1a71168e52d7fe55c470c5083b4
Author: krzys-h <krzys_h at interia.pl>
Date:   Fri Dec 25 19:48:31 2015 +0100

    Started docs of CBotStack; random refactorings
---
 src/CBot/CBotExternalCall.h          | 12 +++----
 src/CBot/CBotInstr/CBotCatch.cpp     |  2 +-
 src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 17 +++++----
 src/CBot/CBotStack.cpp               | 20 ++---------
 src/CBot/CBotStack.h                 | 67 +++++++++++++-----------------------
 src/CBot/CBotToken.h                 |  6 ++--
 6 files changed, 45 insertions(+), 79 deletions(-)

diff --git a/src/CBot/CBotExternalCall.h b/src/CBot/CBotExternalCall.h
index 071f6e9..e7171ca 100644
--- a/src/CBot/CBotExternalCall.h
+++ b/src/CBot/CBotExternalCall.h
@@ -56,9 +56,9 @@ public:
     /**
      * \brief Compile the function
      *
-     * \param "this" variable for class calls, nullptr for normal calls
-     * \param Arguments (only types!) passed to the function
-     * \param User pointer provided to CBotProgram::Compile()
+     * \param thisVar "this" variable for class calls, nullptr for normal calls
+     * \param args Arguments (only types!) passed to the function
+     * \param user User pointer provided to CBotProgram::Compile()
      */
     virtual CBotTypResult Compile(CBotVar* thisVar, CBotVar* args, void* user) = 0;
 
@@ -155,10 +155,10 @@ public:
      * This function sets an error in compilation stack in case of failure
      *
      * \param p Token representing the function name
-     * \param ppVars List of arguments (only types!)
      * \param thisVar "this" variable for class calls, nullptr for normal calls
+     * \param ppVars List of arguments (only types!)
      * \param pStack Compilation stack
-     * \return CBotTypResult representing the return type of the function (::CBotTypVar), or an error (::CBotError)
+     * \return CBotTypResult representing the return type of the function (::CBotType), or an error (::CBotError)
      */
     CBotTypResult CompileCall(CBotToken*& p, CBotVar* thisVar, CBotVar** ppVars, CBotCStack* pStack);
 
@@ -187,7 +187,7 @@ public:
      * \brief Restore execution status after loading saved state
      *
      * \param token Token representing the function name
-     * \param "this" variable for class calls, nullptr for normal calls
+     * \param thisVar "this" variable for class calls, nullptr for normal calls
      * \param ppVar List of arguments
      * \param pStack Runtime stack
      * \return false on failure (e.g. function doesn't exist)
diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp
index 2388a0c..7d4f32c 100644
--- a/src/CBot/CBotInstr/CBotCatch.cpp
+++ b/src/CBot/CBotInstr/CBotCatch.cpp
@@ -103,7 +103,7 @@ bool CBotCatch :: TestCatch(CBotStack* &pile, int val)
 {
     if ( !m_Cond->Execute(pile) ) return false;
 
-    if ( val > 0 || pile->GetType() != CBotTypBoolean )
+    if ( val > 0 || pile->GetVar() == nullptr || pile->GetVar()->GetType() != CBotTypBoolean )
     {
         CBotVar* var = CBotVar::Create("", CBotTypBoolean);
         var->SetValInt( pile->GetVal() == val );
diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
index e2727f0..2e3ec4e 100644
--- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
+++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
@@ -36,8 +36,6 @@
 // Global include
 #include <cassert>
 
-#define    MAX(a,b)    ((a>b) ? a : b)
-
 ////////////////////////////////////////////////////////////////////////////////
 CBotTwoOpExpr::CBotTwoOpExpr()
 {
@@ -200,7 +198,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
             type2 = pStk->GetTypResult();                       // what kind of results?
 
             // what kind of result?
-            int TypeRes = MAX( type1.GetType(3), type2.GetType(3) );
+            int TypeRes = std::max( type1.GetType(3), type2.GetType(3) );
             if ( TypeOp == ID_ADD && type1.Eq(CBotTypString) )
             {
                 TypeRes = CBotTypString;
@@ -253,7 +251,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
                     }
 
                     if ( TypeRes != CBotTypString )
-                        TypeRes = MAX(type1.GetType(), type2.GetType());
+                        TypeRes = std::max(type1.GetType(), type2.GetType());
                     inst = i;
                 }
 
@@ -344,15 +342,16 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
         pStk2->IncState();
     }
 
-    CBotTypResult       type1 = pStk1->GetTypResult();      // what kind of results?
-    CBotTypResult       type2 = pStk2->GetTypResult();
+    assert(pStk1->GetVar() != nullptr && pStk2->GetVar() != nullptr);
+    CBotTypResult       type1 = pStk1->GetVar()->GetTypResult();      // what kind of results?
+    CBotTypResult       type2 = pStk2->GetVar()->GetTypResult();
 
     CBotStack* pStk3 = pStk2->AddStack(this);               // adds an item to the stack
     if ( pStk3->IfStep() ) return false;                    // shows the operation if step by step
 
     // creates a temporary variable to put the result
     // what kind of result?
-    int TypeRes = MAX(type1.GetType(), type2.GetType());
+    int TypeRes = std::max(type1.GetType(), type2.GetType());
 
     if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) )
     {
@@ -374,14 +373,14 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
         TypeRes = CBotTypBoolean;
         break;
     case ID_DIV:
-        TypeRes = MAX(TypeRes, CBotTypFloat);
+        TypeRes = std::max(TypeRes, static_cast<int>(CBotTypFloat));
     }
 
     // creates a variable for the result
     CBotVar*    result = CBotVar::Create("", TypeRes);
 
     // creates a variable to perform the calculation in the appropriate type
-    TypeRes = MAX(type1.GetType(), type2.GetType());
+    TypeRes = std::max(type1.GetType(), type2.GetType());
 
     if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) )
     {
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 0e56def..319371d 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -319,20 +319,6 @@ CBotError CBotStack::GetError(int& start, int& end)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int CBotStack::GetType(CBotVar::GetTypeMode mode)
-{
-    if (m_var == nullptr) return -1;
-    return m_var->GetType(mode);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotStack::GetTypResult(CBotVar::GetTypeMode mode)
-{
-    if (m_var == nullptr) return -1;
-    return m_var->GetTypResult(mode);
-}
-
-////////////////////////////////////////////////////////////////////////////////
 CBotVar* CBotStack::FindVar(CBotToken*& pToken, bool bUpdate)
 {
     CBotStack*    p = this;
@@ -408,9 +394,9 @@ CBotVar* CBotStack::FindVar(CBotToken& pToken, bool bUpdate)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate)
+CBotVar* CBotStack::CopyVar(CBotToken& pToken, bool bUpdate)
 {
-    CBotVar*    pVar = FindVar(Token, bUpdate);
+    CBotVar*    pVar = FindVar(pToken, bUpdate);
 
     if ( pVar == nullptr) return nullptr;
 
@@ -557,7 +543,7 @@ void CBotStack::AddVar(CBotVar* pVar)
 
     if ( p == nullptr ) return;
 
-///    p->m_bDontDelete = bDontDelete;
+//    p->m_bDontDelete = bDontDelete;
 
     CBotVar**    pp = &p->m_listVar;
     while ( *pp != nullptr ) pp = &(*pp)->m_next;
diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h
index 10873c9..e8773b2 100644
--- a/src/CBot/CBotStack.h
+++ b/src/CBot/CBotStack.h
@@ -43,12 +43,12 @@ public:
     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
 
     /**
-     * \brief AllocateStack Allocate the stack
+     * \brief Allocate the stack
      * \return pointer to created stack
      */
     static CBotStack* AllocateStack();
 
-    /** \brief Delete Remove current stack */
+    /** \brief Remove the current stack */
     void Delete();
 
     CBotStack() = delete;
@@ -81,69 +81,50 @@ public:
     void Reset();
 
     /**
-     * \brief GetType Get the type of value on the stack.
-     * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
-     * \return Type number.
+     * \brief Adds a local variable
+     * \param var Variable to be added
      */
-    int GetType(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
+    void AddVar(CBotVar* var);
 
     /**
-     * \brief Getes the type of complete value on the stack.
-     * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
-     * \return  Type of an element.
-     */
-    CBotTypResult GetTypResult(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
-
-    /**
-     * \brief Adds a local variable.
-     * \param [in] p Variable to be added.
-     */
-    void AddVar(CBotVar* p);
-
-    /**
-     * \brief Fetch a variable by its token.
-     * \brief This may be a composite variable
-     * \param [in] pToken Token upon which search is performed
-     * \param [in] bUpdate Not used. Probably need to be removed
-     * \param [in] bModif Not used. Probably need to be removed
-     * \return Found variable
+     * \brief Fetch a variable by its token
+     * \param pToken Token upon which search is performed
+     * \param bUpdate true to automatically call update function for classes, see CBotClass::AddUpdateFunc()
+     * \return Found variable, nullptr if not found
      */
     CBotVar* FindVar(CBotToken*& pToken, bool bUpdate);
 
     /**
-     * \brief Fetch a variable by its token.
-     * \brief This may be a composite variable
-     * \param [in] pToken Token upon which search is performed
-     * \param [in] bUpdate Not used. Probably need to be removed
-     * \param [in] bModif Not used. Probably need to be removed
-     * \return Found variable
+     * \copydoc FindVar(CBotToken*&, bool)
      */
     CBotVar* FindVar(CBotToken& pToken, bool bUpdate);
 
     /**
      * \brief Fetch variable by its name
-     * \param [in] name Name of variable to find
-     * \return Found variable
+     * \param name Name of variable to find
+     * \return Found variable, nullptr if not found
      */
     CBotVar* FindVar(const std::string& name);
 
     /**
-     * \brief Fetch a variable on the stack according to its identification number
-     * \brief This is faster than comparing names
-     * \param [in] ident Identifier of a variable
-     * \param [in] bUpdate Not used. Probably need to be removed
-     * \param [in] bModif Not used. Probably need to be removed
-     * \return Found variable
+     * \brief Fetch a variable on the stack according to its unique identifier
+     *
+     * This is faster than comparing names
+     *
+     * \param ident Unique identifier of a variable
+     * \param bUpdate true to automatically call update function for classes, see CBotClass::AddUpdateFunc()
+     * \return Found variable, nullptr if not found
      */
     CBotVar* FindVar(long ident, bool bUpdate);
 
     /**
-     * \brief Find variable by its token and returns a copy of it.
-     * \param Token Token upon which search is performed
-     * \param bUpdate Not used.
+     * \brief Find variable by its token and returns a copy of it
+     *
+     * \param pToken Token upon which search is performed
+     * \param bUpdate true to automatically call update function for classes, see CBotClass::AddUpdateFunc()
      * \return Found variable, nullptr if not found
      */
-    CBotVar*        CopyVar(CBotToken& Token, bool bUpdate = false);
+    CBotVar*        CopyVar(CBotToken& pToken, bool bUpdate = false);
 
 
     CBotStack*        AddStack(CBotInstr* instr = nullptr, UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE);    // extends the stack
diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h
index cb3c6a9..22f9bd0 100644
--- a/src/CBot/CBotToken.h
+++ b/src/CBot/CBotToken.h
@@ -88,7 +88,7 @@ public:
     /**
      * \brief Constructor
      *
-     * \param token The string this token represents
+     * \param text The string this token represents
      * \param sep All separators that appeared after this token
      * \param start Beginning location in the source code of this token
      * \param end Ending location in the source code of this token
@@ -121,7 +121,7 @@ public:
 
     /**
      * \brief Set the token string
-     * \param The new string to set
+     * \param name The new string to set
      */
     void SetString(const std::string& name);
 
@@ -144,7 +144,7 @@ public:
 
     /**
      * \brief Get the keyword id
-     * \return The keyword id, see ::CBotTokenId
+     * \return The keyword id, see ::TokenId
      */
     long GetKeywordId();
 

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