[colobot] 109/377: Moving CBotClass functions into CBotClass.cpp. Moving gloable function used by CBotClass and CBotFunction into CBotUtils.cpp.

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:04 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 0a1b7da2a80aaaf1fe31174371da746ccde51a7e
Author: Grunaka <dev at romainbreton.fr>
Date:   Sun Nov 15 18:40:16 2015 +0100

    Moving CBotClass functions into CBotClass.cpp. Moving gloable function used by CBotClass and CBotFunction into CBotUtils.cpp.
---
 src/CBot/CBotClass.cpp              | 313 ++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotFunction.cpp | 370 +-----------------------------------
 src/CBot/CBotUtils.cpp              |  57 ++++++
 src/CBot/CBotUtils.h                |  17 ++
 4 files changed, 389 insertions(+), 368 deletions(-)

diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index f37d55c..d2d03e9 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -24,8 +24,13 @@
 #include "CBotInstr/CBotLeftExprVar.h"
 #include "CBotInstr/CBotTwoOpExpr.h"
 #include "CBotInstr/CBotFunction.h"
+#include "CBotInstr/CBotExpression.h"
+#include "CBotInstr/CBotListArray.h"
+#include "CBotInstr/CBotEmpty.h"
 
 #include "CBotCall.h"
+#include "CBotStack.h"
+#include "CBotUtils.h"
 
 // Local include
 
@@ -519,3 +524,311 @@ bool CBotClass::CheckCall(CBotToken* &pToken,
 
     return false;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
+{
+    if ( !IsOfType(p, ID_PUBLIC) )
+    {
+        pStack->SetError(TX_NOPUBLIC, p);
+        return nullptr;
+    }
+
+    if ( !IsOfType(p, ID_CLASS) ) return nullptr;
+
+    CBotString name = p->GetString();
+
+    CBotClass* pOld = CBotClass::Find(name);
+    if ( pOld != nullptr && pOld->m_IsDef )
+    {
+        pStack->SetError( TX_REDEFCLASS, p );
+        return nullptr;
+    }
+
+    // a name of the class is there?
+    if (IsOfType(p, TokenTypVar))
+    {
+        CBotClass* pPapa = nullptr;
+        if ( IsOfType( p, ID_EXTENDS ) )
+        {
+            CBotString name = p->GetString();
+            pPapa = CBotClass::Find(name);
+
+            if (!IsOfType(p, TokenTypVar) || pPapa == nullptr )
+            {
+                pStack->SetError( TX_NOCLASS, p );
+                return nullptr;
+            }
+        }
+        CBotClass* classe = (pOld == nullptr) ? new CBotClass(name, pPapa) : pOld;
+        classe->Purge();                            // emptythe old definitions
+        classe->m_IsDef = false;                    // current definition
+
+        if ( !IsOfType( p, ID_OPBLK) )
+        {
+            pStack->SetError(TX_OPENBLK, p);
+            return nullptr;
+        }
+
+        while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) )
+        {
+            classe->CompileDefItem(p, pStack, false);
+        }
+
+        if (pStack->IsOk()) return classe;
+    }
+    pStack->SetError(TX_ENDOF, p);
+    return nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
+{
+    bool    bStatic = false;
+    int     mProtect = PR_PUBLIC;
+    bool    bSynchro = false;
+
+    while (IsOfType(p, ID_SEP)) ;
+
+    CBotTypResult   type( -1 );
+
+    if ( IsOfType(p, ID_SYNCHO) ) bSynchro = true;
+    CBotToken*      pBase = p;
+
+    if ( IsOfType(p, ID_STATIC) ) bStatic = true;
+    if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC;
+    if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE;
+    if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT;
+    if ( IsOfType(p, ID_STATIC) ) bStatic = true;
+
+//  CBotClass* pClass = nullptr;
+    type = TypeParam(p, pStack);        // type of the result
+
+    if ( type.Eq(-1) )
+    {
+        pStack->SetError(TX_NOTYP, p);
+        return false;
+    }
+
+    while (pStack->IsOk())
+    {
+        CBotToken*  pp = p;
+        IsOfType(p, ID_NOT);    // skips ~ eventual (destructor)
+
+        if (IsOfType(p, TokenTypVar))
+        {
+            CBotInstr* limites = nullptr;
+            while ( IsOfType( p, ID_OPBRK ) )   // a table?
+            {
+                CBotInstr* i = nullptr;
+
+                if ( p->GetType() != ID_CLBRK )
+                    i = CBotExpression::Compile( p, pStack );           // expression for the value
+                else
+                    i = new CBotEmpty();                            // special if not a formula
+
+                type = CBotTypResult(CBotTypArrayPointer, type);
+
+                if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) )
+                {
+                    pStack->SetError(TX_CLBRK, p->GetStart());
+                    return false;
+                }
+
+/*              CBotVar* pv = pStack->GetVar();
+                if ( pv->GetType()>= CBotTypBoolean )
+                {
+                    pStack->SetError(TX_BADTYPE, p->GetStart());
+                    return false;
+                }*/
+
+                if (limites == nullptr) limites = i;
+                else limites->AddNext3(i);
+            }
+
+            if ( p->GetType() == ID_OPENPAR )
+            {
+                if ( !bSecond )
+                {
+                    p = pBase;
+                    CBotFunction* f =
+                    CBotFunction::Compile1(p, pStack, this);
+
+                    if ( f == nullptr ) return false;
+
+                    if (m_pMethod == nullptr) m_pMethod = f;
+                    else m_pMethod->AddNext(f);
+                }
+                else
+                {
+                    // return a method precompiled in pass 1
+                    CBotFunction*   pf = m_pMethod;
+                    CBotFunction*   prev = nullptr;
+                    while ( pf != nullptr )
+                    {
+                        if (pf->GetName() == pp->GetString()) break;
+                        prev = pf;
+                        pf = pf->Next();
+                    }
+
+                    bool bConstructor = (pp->GetString() == GetName());
+                    CBotCStack* pile = pStack->TokenStack(nullptr, true);
+
+                    // make "this" known
+                    CBotToken TokenThis(CBotString("this"), CBotString());
+                    CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) );
+                    pThis->SetUniqNum(-2);
+                    pile->AddVar(pThis);
+
+                    if ( m_pParent )
+                    {
+                        // makes "super" known
+                        CBotToken TokenSuper(CBotString("super"), CBotString());
+                        CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) );
+                        pThis->SetUniqNum(-3);
+                        pile->AddVar(pThis);
+                    }
+
+//                  int num = 1;
+                    CBotClass*  my = this;
+                    while (my != nullptr)
+                    {
+                        // places a copy of variables of a class (this) on a stack
+                        CBotVar* pv = my->m_pVar;
+                        while (pv != nullptr)
+                        {
+                            CBotVar* pcopy = CBotVar::Create(pv);
+                            CBotVar::InitType initType = CBotVar::InitType::UNDEF;
+                            if (!bConstructor || pv->IsStatic())
+                                initType = CBotVar::InitType::DEF;
+                            pcopy->SetInit(initType);
+                            pcopy->SetUniqNum(pv->GetUniqNum());
+                            pile->AddVar(pcopy);
+                            pv = pv->GetNext();
+                        }
+                        my = my->m_pParent;
+                    }
+
+                    // compiles a method
+                    p = pBase;
+                    CBotFunction* f =
+                    CBotFunction::Compile(p, pile, nullptr/*, false*/);
+
+                    if ( f != nullptr )
+                    {
+                        f->m_pProg = pStack->GetBotCall();
+                        f->m_bSynchro = bSynchro;
+                        // replaces the element in the chain
+                        f->m_next = pf->m_next;
+                        pf->m_next = nullptr;
+                        delete pf;
+                        if (prev == nullptr) m_pMethod = f;
+                        else prev->m_next = f;
+                    }
+                    pStack->Return(nullptr, pile);
+                }
+
+                return pStack->IsOk();
+            }
+
+            // definition of an element
+            if (type.Eq(0))
+            {
+                pStack->SetError(TX_ENDOF, p);
+                return false;
+            }
+
+            CBotInstr* i = nullptr;
+            if ( IsOfType(p, ID_ASS ) )
+            {
+                if ( type.Eq(CBotTypArrayPointer) )
+                {
+                    i = CBotListArray::Compile(p, pStack, type.GetTypElem());
+                }
+                else
+                {
+                    // it has an assignmet to calculate
+                    i = CBotTwoOpExpr::Compile(p, pStack);
+                }
+                if ( !pStack->IsOk() ) return false;
+            }
+
+
+            if ( !bSecond )
+            {
+                CBotVar*    pv = CBotVar::Create(pp->GetString(), type);
+                pv -> SetStatic( bStatic );
+                pv -> SetPrivate( mProtect );
+
+                AddItem( pv );
+
+                pv->m_InitExpr = i;
+                pv->m_LimExpr = limites;
+
+
+                if ( pv->IsStatic() && pv->m_InitExpr != nullptr )
+                {
+                    CBotStack* pile = CBotStack::FirstStack();              // independent stack
+                    while(pile->IsOk() && !pv->m_InitExpr->Execute(pile));  // evaluates the expression without timer
+                    pv->SetVal( pile->GetVar() ) ;
+                    pile->Delete();
+                }
+            }
+            else
+                delete i;
+
+            if ( IsOfType(p, ID_COMMA) ) continue;
+            if ( IsOfType(p, ID_SEP) ) break;
+        }
+        pStack->SetError(TX_ENDOF, p);
+    }
+    return pStack->IsOk();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+    if ( !IsOfType(p, ID_PUBLIC) ) return nullptr;
+    if ( !IsOfType(p, ID_CLASS) ) return nullptr;
+
+    CBotString name = p->GetString();
+
+    // a name for the class is there?
+    if (IsOfType(p, TokenTypVar))
+    {
+        // the class was created by Compile1
+        CBotClass* pOld = CBotClass::Find(name);
+
+        if ( IsOfType( p, ID_EXTENDS ) )
+        {
+            // TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h
+            CBotString name = p->GetString();
+            CBotClass* pPapa = CBotClass::Find(name);
+
+            if (!IsOfType(p, TokenTypVar) || pPapa == nullptr)
+            {
+                pStack->SetError( TX_NOCLASS, p );
+                return nullptr;
+            }
+            pOld->m_pParent = pPapa;
+        }
+        else
+        {
+            if (pOld != nullptr)
+            {
+                pOld->m_pParent = nullptr;
+            }
+        }
+        IsOfType( p, ID_OPBLK); // necessarily
+
+        while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) )
+        {
+            pOld->CompileDefItem(p, pStack, true);
+        }
+
+        pOld->m_IsDef = true;           // complete definition
+        if (pStack->IsOk()) return pOld;
+    }
+    pStack->SetError(TX_ENDOF, p);
+    return nullptr;
+}
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 61428da..94df0e7 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -32,6 +32,8 @@
 #include "CBotStack.h"
 #include "CBotClass.h"
 
+#include "CBotUtils.h"
+
 // Local include
 
 // Global include
@@ -138,59 +140,6 @@ bool CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CBotTypResult   ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type)
-{
-    while ( IsOfType( p, ID_OPBRK ) )
-    {
-        if ( !IsOfType( p, ID_CLBRK ) )
-        {
-            pile->SetError(TX_CLBRK, p->GetStart());
-            return CBotTypResult( -1 );
-        }
-        type = CBotTypResult( CBotTypArrayPointer, type );
-    }
-    return type;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotTypResult   TypeParam(CBotToken* &p, CBotCStack* pile)
-{
-    CBotClass*  pClass = nullptr;
-
-    switch (p->GetType())
-    {
-    case ID_INT:
-        p = p->GetNext();
-        return ArrayType(p, pile, CBotTypResult( CBotTypInt ));
-    case ID_FLOAT:
-        p = p->GetNext();
-        return ArrayType(p, pile, CBotTypResult( CBotTypFloat ));
-    case ID_BOOLEAN:
-    case ID_BOOL:
-        p = p->GetNext();
-        return ArrayType(p, pile, CBotTypResult( CBotTypBoolean ));
-    case ID_STRING:
-        p = p->GetNext();
-        return ArrayType(p, pile, CBotTypResult( CBotTypString ));
-    case ID_VOID:
-        p = p->GetNext();
-        return CBotTypResult( 0 );
-
-    case TokenTypVar:
-        pClass = CBotClass::Find(p);
-        if ( pClass != nullptr)
-        {
-            p = p->GetNext();
-            return ArrayType(p, pile,
-                             pClass->IsIntrinsic() ?
-                             CBotTypResult( CBotTypIntrinsic, pClass ) :
-                             CBotTypResult( CBotTypPointer,   pClass ) );
-        }
-    }
-    return CBotTypResult( -1 );
-}
-
-////////////////////////////////////////////////////////////////////////////////
 CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* finput, bool bLocal)
 {
     CBotToken*      pp;
@@ -1122,318 +1071,3 @@ CBotString CBotDefParam::GetParamString()
     param += m_token.GetString();
     return param;
 }
-
-//////////////////////////////////////////////////////////////////////////////
-// statement of user classes
-
-// pre-compile a new class
-// analysis is complete except the body of routines
-
-////////////////////////////////////////////////////////////////////////////////
-CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
-{
-    if ( !IsOfType(p, ID_PUBLIC) )
-    {
-        pStack->SetError(TX_NOPUBLIC, p);
-        return nullptr;
-    }
-
-    if ( !IsOfType(p, ID_CLASS) ) return nullptr;
-
-    CBotString name = p->GetString();
-
-    CBotClass* pOld = CBotClass::Find(name);
-    if ( pOld != nullptr && pOld->m_IsDef )
-    {
-        pStack->SetError( TX_REDEFCLASS, p );
-        return nullptr;
-    }
-
-    // a name of the class is there?
-    if (IsOfType(p, TokenTypVar))
-    {
-        CBotClass* pPapa = nullptr;
-        if ( IsOfType( p, ID_EXTENDS ) )
-        {
-            CBotString name = p->GetString();
-            pPapa = CBotClass::Find(name);
-
-            if (!IsOfType(p, TokenTypVar) || pPapa == nullptr )
-            {
-                pStack->SetError( TX_NOCLASS, p );
-                return nullptr;
-            }
-        }
-        CBotClass* classe = (pOld == nullptr) ? new CBotClass(name, pPapa) : pOld;
-        classe->Purge();                            // emptythe old definitions
-        classe->m_IsDef = false;                    // current definition
-
-        if ( !IsOfType( p, ID_OPBLK) )
-        {
-            pStack->SetError(TX_OPENBLK, p);
-            return nullptr;
-        }
-
-        while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) )
-        {
-            classe->CompileDefItem(p, pStack, false);
-        }
-
-        if (pStack->IsOk()) return classe;
-    }
-    pStack->SetError(TX_ENDOF, p);
-    return nullptr;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
-{
-    bool    bStatic = false;
-    int     mProtect = PR_PUBLIC;
-    bool    bSynchro = false;
-
-    while (IsOfType(p, ID_SEP)) ;
-
-    CBotTypResult   type( -1 );
-
-    if ( IsOfType(p, ID_SYNCHO) ) bSynchro = true;
-    CBotToken*      pBase = p;
-
-    if ( IsOfType(p, ID_STATIC) ) bStatic = true;
-    if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC;
-    if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE;
-    if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT;
-    if ( IsOfType(p, ID_STATIC) ) bStatic = true;
-
-//  CBotClass* pClass = nullptr;
-    type = TypeParam(p, pStack);        // type of the result
-
-    if ( type.Eq(-1) )
-    {
-        pStack->SetError(TX_NOTYP, p);
-        return false;
-    }
-
-    while (pStack->IsOk())
-    {
-        CBotToken*  pp = p;
-        IsOfType(p, ID_NOT);    // skips ~ eventual (destructor)
-
-        if (IsOfType(p, TokenTypVar))
-        {
-            CBotInstr* limites = nullptr;
-            while ( IsOfType( p, ID_OPBRK ) )   // a table?
-            {
-                CBotInstr* i = nullptr;
-
-                if ( p->GetType() != ID_CLBRK )
-                    i = CBotExpression::Compile( p, pStack );           // expression for the value
-                else
-                    i = new CBotEmpty();                            // special if not a formula
-
-                type = CBotTypResult(CBotTypArrayPointer, type);
-
-                if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) )
-                {
-                    pStack->SetError(TX_CLBRK, p->GetStart());
-                    return false;
-                }
-
-/*              CBotVar* pv = pStack->GetVar();
-                if ( pv->GetType()>= CBotTypBoolean )
-                {
-                    pStack->SetError(TX_BADTYPE, p->GetStart());
-                    return false;
-                }*/
-
-                if (limites == nullptr) limites = i;
-                else limites->AddNext3(i);
-            }
-
-            if ( p->GetType() == ID_OPENPAR )
-            {
-                if ( !bSecond )
-                {
-                    p = pBase;
-                    CBotFunction* f =
-                    CBotFunction::Compile1(p, pStack, this);
-
-                    if ( f == nullptr ) return false;
-
-                    if (m_pMethod == nullptr) m_pMethod = f;
-                    else m_pMethod->AddNext(f);
-                }
-                else
-                {
-                    // return a method precompiled in pass 1
-                    CBotFunction*   pf = m_pMethod;
-                    CBotFunction*   prev = nullptr;
-                    while ( pf != nullptr )
-                    {
-                        if (pf->GetName() == pp->GetString()) break;
-                        prev = pf;
-                        pf = pf->Next();
-                    }
-
-                    bool bConstructor = (pp->GetString() == GetName());
-                    CBotCStack* pile = pStack->TokenStack(nullptr, true);
-
-                    // make "this" known
-                    CBotToken TokenThis(CBotString("this"), CBotString());
-                    CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) );
-                    pThis->SetUniqNum(-2);
-                    pile->AddVar(pThis);
-
-                    if ( m_pParent )
-                    {
-                        // makes "super" known
-                        CBotToken TokenSuper(CBotString("super"), CBotString());
-                        CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) );
-                        pThis->SetUniqNum(-3);
-                        pile->AddVar(pThis);
-                    }
-
-//                  int num = 1;
-                    CBotClass*  my = this;
-                    while (my != nullptr)
-                    {
-                        // places a copy of variables of a class (this) on a stack
-                        CBotVar* pv = my->m_pVar;
-                        while (pv != nullptr)
-                        {
-                            CBotVar* pcopy = CBotVar::Create(pv);
-                            CBotVar::InitType initType = CBotVar::InitType::UNDEF;
-                            if (!bConstructor || pv->IsStatic())
-                                initType = CBotVar::InitType::DEF;
-                            pcopy->SetInit(initType);
-                            pcopy->SetUniqNum(pv->GetUniqNum());
-                            pile->AddVar(pcopy);
-                            pv = pv->GetNext();
-                        }
-                        my = my->m_pParent;
-                    }
-
-                    // compiles a method
-                    p = pBase;
-                    CBotFunction* f =
-                    CBotFunction::Compile(p, pile, nullptr/*, false*/);
-
-                    if ( f != nullptr )
-                    {
-                        f->m_pProg = pStack->GetBotCall();
-                        f->m_bSynchro = bSynchro;
-                        // replaces the element in the chain
-                        f->m_next = pf->m_next;
-                        pf->m_next = nullptr;
-                        delete pf;
-                        if (prev == nullptr) m_pMethod = f;
-                        else prev->m_next = f;
-                    }
-                    pStack->Return(nullptr, pile);
-                }
-
-                return pStack->IsOk();
-            }
-
-            // definition of an element
-            if (type.Eq(0))
-            {
-                pStack->SetError(TX_ENDOF, p);
-                return false;
-            }
-
-            CBotInstr* i = nullptr;
-            if ( IsOfType(p, ID_ASS ) )
-            {
-                if ( type.Eq(CBotTypArrayPointer) )
-                {
-                    i = CBotListArray::Compile(p, pStack, type.GetTypElem());
-                }
-                else
-                {
-                    // it has an assignmet to calculate
-                    i = CBotTwoOpExpr::Compile(p, pStack);
-                }
-                if ( !pStack->IsOk() ) return false;
-            }
-
-
-            if ( !bSecond )
-            {
-                CBotVar*    pv = CBotVar::Create(pp->GetString(), type);
-                pv -> SetStatic( bStatic );
-                pv -> SetPrivate( mProtect );
-
-                AddItem( pv );
-
-                pv->m_InitExpr = i;
-                pv->m_LimExpr = limites;
-
-
-                if ( pv->IsStatic() && pv->m_InitExpr != nullptr )
-                {
-                    CBotStack* pile = CBotStack::FirstStack();              // independent stack
-                    while(pile->IsOk() && !pv->m_InitExpr->Execute(pile));  // evaluates the expression without timer
-                    pv->SetVal( pile->GetVar() ) ;
-                    pile->Delete();
-                }
-            }
-            else
-                delete i;
-
-            if ( IsOfType(p, ID_COMMA) ) continue;
-            if ( IsOfType(p, ID_SEP) ) break;
-        }
-        pStack->SetError(TX_ENDOF, p);
-    }
-    return pStack->IsOk();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack)
-{
-    if ( !IsOfType(p, ID_PUBLIC) ) return nullptr;
-    if ( !IsOfType(p, ID_CLASS) ) return nullptr;
-
-    CBotString name = p->GetString();
-
-    // a name for the class is there?
-    if (IsOfType(p, TokenTypVar))
-    {
-        // the class was created by Compile1
-        CBotClass* pOld = CBotClass::Find(name);
-
-        if ( IsOfType( p, ID_EXTENDS ) )
-        {
-            // TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h
-            CBotString name = p->GetString();
-            CBotClass* pPapa = CBotClass::Find(name);
-
-            if (!IsOfType(p, TokenTypVar) || pPapa == nullptr)
-            {
-                pStack->SetError( TX_NOCLASS, p );
-                return nullptr;
-            }
-            pOld->m_pParent = pPapa;
-        }
-        else
-        {
-            if (pOld != nullptr)
-            {
-                pOld->m_pParent = nullptr;
-            }
-        }
-        IsOfType( p, ID_OPBLK); // necessarily
-
-        while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) )
-        {
-            pOld->CompileDefItem(p, pStack, true);
-        }
-
-        pOld->m_IsDef = true;           // complete definition
-        if (pStack->IsOk()) return pOld;
-    }
-    pStack->SetError(TX_ENDOF, p);
-    return nullptr;
-}
-
diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp
index 5aba61c..bb2b940 100644
--- a/src/CBot/CBotUtils.cpp
+++ b/src/CBot/CBotUtils.cpp
@@ -20,6 +20,10 @@
 // Modules inlcude
 #include "CBotUtils.h"
 
+#include "CBotToken.h"
+#include "CBotClass.h"
+#include "CBotStack.h"
+
 // Local include
 
 // Global include
@@ -48,3 +52,56 @@ CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal)
     }
     return pVar;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile)
+{
+    CBotClass*  pClass = nullptr;
+
+    switch (p->GetType())
+    {
+    case ID_INT:
+        p = p->GetNext();
+        return ArrayType(p, pile, CBotTypResult( CBotTypInt ));
+    case ID_FLOAT:
+        p = p->GetNext();
+        return ArrayType(p, pile, CBotTypResult( CBotTypFloat ));
+    case ID_BOOLEAN:
+    case ID_BOOL:
+        p = p->GetNext();
+        return ArrayType(p, pile, CBotTypResult( CBotTypBoolean ));
+    case ID_STRING:
+        p = p->GetNext();
+        return ArrayType(p, pile, CBotTypResult( CBotTypString ));
+    case ID_VOID:
+        p = p->GetNext();
+        return CBotTypResult( 0 );
+
+    case TokenTypVar:
+        pClass = CBotClass::Find(p);
+        if ( pClass != nullptr)
+        {
+            p = p->GetNext();
+            return ArrayType(p, pile,
+                             pClass->IsIntrinsic() ?
+                             CBotTypResult( CBotTypIntrinsic, pClass ) :
+                             CBotTypResult( CBotTypPointer,   pClass ) );
+        }
+    }
+    return CBotTypResult( -1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type)
+{
+    while ( IsOfType( p, ID_OPBRK ) )
+    {
+        if ( !IsOfType( p, ID_CLBRK ) )
+        {
+            pile->SetError(TX_CLBRK, p->GetStart());
+            return CBotTypResult( -1 );
+        }
+        type = CBotTypResult( CBotTypArrayPointer, type );
+    }
+    return type;
+}
diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h
index df8bb55..9d452d8 100644
--- a/src/CBot/CBotUtils.h
+++ b/src/CBot/CBotUtils.h
@@ -34,3 +34,20 @@
  * \return
  */
 CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal=false);
+
+/*!
+ * \brief TypeParam
+ * \param p
+ * \param pile
+ * \return
+ */
+CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile);
+
+/*!
+ * \brief ArrayType
+ * \param p
+ * \param pile
+ * \param type
+ * \return
+ */
+CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type);

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