diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index d528d1f7..1c8b4379 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -73,6 +73,7 @@ #include "CBotInstr/CBotInt.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 98d3f9ce..e42d1851 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -52,82 +52,6 @@ class CBotIf; // if (...) {...} else {...} class CBotDefParam; // paramerer list of a function - - - -//////////////////////////////////////////////////////////////////////// -// Management of the stack of compilation -//////////////////////////////////////////////////////////////////////// - - -class CBotCStack -{ -private: - CBotCStack* m_next; - CBotCStack* m_prev; - - static int m_error; - static int m_end; - int m_start; - - CBotVar* m_var; // result of the operations - - bool m_bBlock; // is part of a block (variables are local to this block) - CBotVar* m_listVar; - - static - CBotProgram* m_prog; // list of compiled functions - static - CBotTypResult m_retTyp; -// static -// CBotToken* m_retClass; - -public: - CBotCStack(CBotCStack* ppapa); - ~CBotCStack(); - - bool IsOk(); - int GetError(); - int GetError(int& start, int& end); - // gives error number - - void SetType(CBotTypResult& type);// determines the type - CBotTypResult GetTypResult(int mode = 0); // gives the type of value on the stack - int GetType(int mode = 0); // gives the type of value on the stack - CBotClass* GetClass(); // gives the class of the value on the stack - - void AddVar(CBotVar* p); // adds a local variable - CBotVar* FindVar(CBotToken* &p); // finds a variable - CBotVar* FindVar(CBotToken& Token); - bool CheckVarLocal(CBotToken* &pToken); - CBotVar* CopyVar(CBotToken& Token); // finds and makes a copy - - CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false); - CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmits the result upper - CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmits the result upper - - void SetVar( CBotVar* var ); - void SetCopyVar( CBotVar* var ); - CBotVar* GetVar(); - - void SetStartError(int pos); - void SetError(int n, int pos); - void SetError(int n, CBotToken* p); - void ResetError(int n, int start, int end); - - void SetRetType(CBotTypResult& type); - CBotTypResult GetRetType(); - -// void SetBotCall(CBotFunction* &pFunc); - void SetBotCall(CBotProgram* p); - CBotProgram* GetBotCall(); - CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent); - bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam); - - bool NextToken(CBotToken* &p); -}; - - extern bool SaveVar(FILE* pf, CBotVar* pVar); diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp new file mode 100644 index 00000000..6d9b820e --- /dev/null +++ b/src/CBot/CBotCStack.cpp @@ -0,0 +1,405 @@ +/* + * 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 + */ + + +// Modules inlcude +#include "CBotCStack.h" + +#include "CBotToken.h" +#include "CBotCall.h" + +#include "CBotVar/CBotVar.h" + +#include "CBotInstr/CBotFunction.h" + +// Local include + +// Global include + + + +//////////////////////////////////////////////////////////////////////////////// +CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable +int CBotCStack::m_error = 0; +int CBotCStack::m_end = 0; +CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0); + +//////////////////////////////////////////////////////////////////////////////// +CBotCStack::CBotCStack(CBotCStack* ppapa) +{ + m_next = nullptr; + m_prev = ppapa; + + if (ppapa == nullptr) + { + m_error = 0; + m_start = 0; + m_end = 0; + m_bBlock = true; + } + else + { + m_start = ppapa->m_start; + m_bBlock = false; + } + + m_listVar = nullptr; + m_var = nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCStack::~CBotCStack() +{ + if (m_next != nullptr) delete m_next; + if (m_prev != nullptr) m_prev->m_next = nullptr; // removes chain + + delete m_var; + delete m_listVar; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) +{ + if (m_next != nullptr) return m_next; // include on an existing stack + + CBotCStack* p = new CBotCStack(this); + m_next = p; // channel element + p->m_bBlock = bBlock; + + if (pToken != nullptr) p->SetStartError(pToken->GetStart()); + + return p; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) +{ + if ( pfils == this ) return inst; + + if (m_var != nullptr) delete m_var; // value replaced? + m_var = pfils->m_var; // result transmitted + pfils->m_var = nullptr; // not to destroy the variable + + if (m_error) + { + m_start = pfils->m_start; // retrieves the position of the error + m_end = pfils->m_end; + } + + delete pfils; + return inst; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) +{ + if (m_var != nullptr) delete m_var; // value replaced? + m_var = pfils->m_var; // result transmitted + pfils->m_var = nullptr; // not to destroy the variable + + if (m_error) + { + m_start = pfils->m_start; // retrieves the position of the error + m_end = pfils->m_end; + } + + delete pfils; + return inst; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCStack::GetError(int& start, int& end) +{ + start = m_start; + end = m_end; + return m_error; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCStack::GetError() +{ + return m_error; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCStack::GetTypResult(int mode) +{ + if (m_var == nullptr) + return CBotTypResult(99); + return m_var->GetTypResult(mode); +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCStack::GetType(int mode) +{ + if (m_var == nullptr) + return 99; + return m_var->GetType(mode); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotCStack::GetClass() +{ + if ( m_var == nullptr ) + return nullptr; + if ( m_var->GetType(1) != CBotTypPointer ) return nullptr; + + return m_var->GetClass(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetType(CBotTypResult& type) +{ + if (m_var == nullptr) return; + m_var->SetType( type ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::FindVar(CBotToken* &pToken) +{ + CBotCStack* p = this; + CBotString name = pToken->GetString(); + + while (p != nullptr) + { + CBotVar* pp = p->m_listVar; + while ( pp != nullptr) + { + if (name == pp->GetName()) + { + return pp; + } + pp = pp->m_next; + } + p = p->m_prev; + } + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::FindVar(CBotToken& Token) +{ + CBotToken* pt = &Token; + return FindVar(pt); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::CopyVar(CBotToken& Token) +{ + CBotVar* pVar = FindVar( Token ); + + if ( pVar == nullptr) return nullptr; + + CBotVar* pCopy = CBotVar::Create( "", pVar->GetType() ); + pCopy->Copy(pVar); + return pCopy; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::IsOk() +{ + return (m_error == 0); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetStartError( int pos ) +{ + if ( m_error != 0) return; // does not change existing error + m_start = pos; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetError(int n, int pos) +{ + if ( n!= 0 && m_error != 0) return; // does not change existing error + m_error = n; + m_end = pos; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetError(int n, CBotToken* p) +{ + if (m_error) return; // does not change existing error + m_error = n; + m_start = p->GetStart(); + m_end = p->GetEnd(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::ResetError(int n, int start, int end) +{ + m_error = n; + m_start = start; + m_end = end; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::NextToken(CBotToken* &p) +{ + CBotToken* pp = p; + + p = p->GetNext(); + if (p!=nullptr) return true; + + SetError(TX_ENDOF, pp->GetEnd()); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetBotCall(CBotProgram* p) +{ + m_prog = p; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotProgram* CBotCStack::GetBotCall() +{ + return m_prog; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetRetType(CBotTypResult& type) +{ + m_retTyp = type; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCStack::GetRetType() +{ + return m_retTyp; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetVar( CBotVar* var ) +{ + if (m_var) delete m_var; // replacement of a variable + m_var = var; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetCopyVar( CBotVar* var ) +{ + if (m_var) delete m_var; // replacement of a variable + + if ( var == nullptr ) return; + m_var = CBotVar::Create("", var->GetTypResult(2)); + m_var->Copy( var ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::GetVar() +{ + return m_var; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::AddVar(CBotVar* pVar) +{ + CBotCStack* p = this; + + // returns to the father element + while (p != nullptr && p->m_bBlock == 0) p = p->m_prev; + + if ( p == nullptr ) return; + + CBotVar** pp = &p->m_listVar; + while ( *pp != nullptr ) pp = &(*pp)->m_next; + + *pp = pVar; // added after + +#ifdef _DEBUG + if ( pVar->GetUniqNum() == 0 ) assert(0); +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::CheckVarLocal(CBotToken* &pToken) +{ + CBotCStack* p = this; + CBotString name = pToken->GetString(); + + while (p != nullptr) + { + CBotVar* pp = p->m_listVar; + while ( pp != nullptr) + { + if (name == pp->GetName()) + return true; + pp = pp->m_next; + } + if ( p->m_bBlock ) return false; + p = p->m_prev; + } + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent) +{ + nIdent = 0; + CBotTypResult val(-1); + + val = CBotCall::CompileCall(p, ppVars, this, nIdent); + if (val.GetType() < 0) + { + val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent); + if ( val.GetType() < 0 ) + { + // pVar = nullptr; // the error is not on a particular parameter + SetError( -val.GetType(), p ); + val.SetType(-val.GetType()); + return val; + } + } + return val; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) +{ + CBotString name = pToken->GetString(); + + if ( CBotCall::CheckCall(name) ) return true; + + CBotFunction* pp = m_prog->GetFunctions(); + while ( pp != nullptr ) + { + if ( pToken->GetString() == pp->GetName() ) + { + // are parameters exactly the same? + if ( pp->CheckParam( pParam ) ) + return true; + } + pp = pp->Next(); + } + + pp = CBotFunction::m_listPublic; + while ( pp != nullptr ) + { + if ( pToken->GetString() == pp->GetName() ) + { + // are parameters exactly the same? + if ( pp->CheckParam( pParam ) ) + return true; + } + pp = pp->m_nextpublic; + } + + return false; +} diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h new file mode 100644 index 00000000..28e9e886 --- /dev/null +++ b/src/CBot/CBotCStack.h @@ -0,0 +1,267 @@ +/* + * 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 "CBotDll.h" + +#include "CBotProgram.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotCStack class Management of the stack of compilation. + */ +class CBotCStack +{ +public: + + /*! + * \brief CBotCStack + * \param ppapa + */ + CBotCStack(CBotCStack* ppapa); + + /*! + * \brief CBotCStack Destructor. + */ + ~CBotCStack(); + + /*! + * \brief IsOk + * \return + */ + bool IsOk(); + + /*! + * \brief GetError + * \return + */ + int GetError(); + + /*! + * \brief GetError Gives error number + * \param start + * \param end + * \return + */ + int GetError(int& start, int& end); + + /*! + * \brief SetType Set the type of instruction on the stack. + * \param type + */ + void SetType(CBotTypResult& type); + + /*! + * \brief GetTypResult Gives the type of value on the stack. Type of + * instruction on the stack. + * \param mode + * \return + */ + CBotTypResult GetTypResult(int mode = 0); + + /*! + * \brief GetType Gives the type of value on the stack. + * \param mode + * \return + */ + int GetType(int mode = 0); + + /*! + * \brief GetClass Gives the class of the value on the stack. + * \return + */ + CBotClass* GetClass(); + + /*! + * \brief AddVar Adds a local variable. + * \param p + */ + void AddVar(CBotVar* p); + + /*! + * \brief FindVar Finds a variable. Seeks a variable on the stack the token + * may be a result of TokenTypVar (object of a class) or a pointer in the + * source. + * \param p + * \return + */ + CBotVar* FindVar(CBotToken* &p); + + /*! + * \brief FindVar + * \param Token + * \return + */ + CBotVar* FindVar(CBotToken& Token); + + /*! + * \brief CheckVarLocal Test whether a variable is already defined locally. + * \param pToken + * \return + */ + bool CheckVarLocal(CBotToken* &pToken); + + /*! + * \brief CopyVar Finds and makes a copy. + * \param Token + * \return + */ + CBotVar* CopyVar(CBotToken& Token); + + /*! + * \brief TokenStack Used only at compile. + * \param pToken + * \param bBlock + * \return + */ + CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false); + + /*! + * \brief Return Transmits the result upper. + * \param p + * \param pParent + * \return + */ + CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); + + /*! + * \brief ReturnFunc Transmits the result upper. + * \param p + * \param pParent + * \return + */ + CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); + + /*! + * \brief SetVar + * \param var + */ + void SetVar( CBotVar* var ); + + /*! + * \brief SetCopyVar Puts on the stack a copy of a variable. + * \param var + */ + void SetCopyVar( CBotVar* var ); + + /*! + * \brief GetVar + * \return + */ + CBotVar* GetVar(); + + /*! + * \brief SetStartError + * \param pos + */ + void SetStartError(int pos); + + /*! + * \brief SetError + * \param n + * \param pos + */ + void SetError(int n, int pos); + + /*! + * \brief SetError + * \param n + * \param p + */ + void SetError(int n, CBotToken* p); + + /*! + * \brief ResetError + * \param n + * \param start + * \param end + */ + void ResetError(int n, int start, int end); + + /*! + * \brief SetRetType + * \param type + */ + void SetRetType(CBotTypResult& type); + + /*! + * \brief GetRetType + * \return + */ + CBotTypResult GetRetType(); + + /*! + * \brief SetBotCall + * \param p + */ + void SetBotCall(CBotProgram* p); + + /*! + * \brief GetBotCall + * \return + */ + CBotProgram* GetBotCall(); + + /*! + * \brief CompileCall + * \param p + * \param ppVars + * \param nIdent + * \return + */ + CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent); + + /*! + * \brief CheckCall Test if a procedure name is already defined somewhere. + * \param pToken + * \param pParam + * \return + */ + bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam); + + /*! + * \brief NextToken + * \param p + * \return + */ + bool NextToken(CBotToken* &p); + +private: + CBotCStack* m_next; + CBotCStack* m_prev; + + static int m_error; + static int m_end; + int m_start; + + //! Result of the operations. + CBotVar* m_var; + //! Is part of a block (variables are local to this block). + bool m_bBlock; + CBotVar* m_listVar; + //! List of compiled functions. + static CBotProgram* m_prog; + static CBotTypResult m_retTyp; +}; diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index 75beb6fb..ee853d8a 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -22,11 +22,12 @@ #include "CBotToken.h" #include "CBotStack.h" - +#include "CBotCStack.h" #include "CBotUtils.h" #include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp index 2bcc41c8..da915dfb 100644 --- a/src/CBot/CBotCallMethode.cpp +++ b/src/CBot/CBotCallMethode.cpp @@ -22,6 +22,7 @@ #include "CBotUtils.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 9e20d667..94a05346 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -30,6 +30,7 @@ #include "CBotCall.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotUtils.h" #include "CBotCallMethode.h" diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp index 601e5676..9af6043f 100644 --- a/src/CBot/CBotDefParam.cpp +++ b/src/CBot/CBotDefParam.cpp @@ -23,6 +23,7 @@ #include "CBot.h" #include "CBotUtils.h" +#include "CBotCStack.h" #include "CBotVar/CBotVarClass.h" diff --git a/src/CBot/CBotInstr/CBotBlock.cpp b/src/CBot/CBotInstr/CBotBlock.cpp index ed87b53b..ba2b5ce5 100644 --- a/src/CBot/CBotInstr/CBotBlock.cpp +++ b/src/CBot/CBotInstr/CBotBlock.cpp @@ -19,6 +19,8 @@ // Modules inlcude #include "CBotBlock.h" + +#include "CBotCStack.h" #include "CBotListInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp index 2815c8ed..db6b36bd 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.cpp +++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp @@ -21,6 +21,8 @@ #include "CBotBoolExpr.h" #include "CBotTwoOpExpr.h" +#include "CBotCStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp index ea0103e5..64c4d3d3 100644 --- a/src/CBot/CBotInstr/CBotBoolean.cpp +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -24,6 +24,7 @@ #include "CBotInstArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp index 5879f0f8..9d4100cb 100644 --- a/src/CBot/CBotInstr/CBotBreak.cpp +++ b/src/CBot/CBotInstr/CBotBreak.cpp @@ -21,6 +21,7 @@ #include "CBotBreak.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp index f188f8ed..3ae5b706 100644 --- a/src/CBot/CBotInstr/CBotCase.cpp +++ b/src/CBot/CBotInstr/CBotCase.cpp @@ -22,6 +22,7 @@ #include "CBotExprNum.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index fdbc1d45..26f7d17d 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -23,6 +23,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index 8426422b..5d2e0a66 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -24,6 +24,7 @@ #include "CBotInstArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVarPointer.h" diff --git a/src/CBot/CBotInstr/CBotCondition.cpp b/src/CBot/CBotInstr/CBotCondition.cpp index d87c451b..453e26c8 100644 --- a/src/CBot/CBotInstr/CBotCondition.cpp +++ b/src/CBot/CBotInstr/CBotCondition.cpp @@ -21,6 +21,8 @@ #include "CBotCondition.h" #include "CBotBoolExpr.h" +#include "CBotCStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp index 9cfeddb3..c24baff5 100644 --- a/src/CBot/CBotInstr/CBotDo.cpp +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -23,6 +23,7 @@ #include "CBotCondition.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp index 60923754..1f93b89a 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.cpp +++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp @@ -21,6 +21,7 @@ #include "CBotExprAlpha.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp index ebefa6dd..3df5095f 100644 --- a/src/CBot/CBotInstr/CBotExprBool.cpp +++ b/src/CBot/CBotInstr/CBotExprBool.cpp @@ -21,6 +21,7 @@ #include "CBotExprBool.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp index 6082c0e1..65dbd780 100644 --- a/src/CBot/CBotInstr/CBotExprNum.cpp +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -21,6 +21,7 @@ #include "CBotExprNum.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp index 4732eda1..31056bb3 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.cpp +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -22,6 +22,7 @@ #include "CBotParExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 344ce85c..ee4a748e 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -25,6 +25,7 @@ #include "CBotFieldExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVarArray.h" diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index bdf096a5..b6b97837 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -22,6 +22,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index bad06d93..7c4ff58c 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -21,6 +21,7 @@ #include "CBotFieldExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVarClass.h" diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp index 1a721458..df69b07f 100644 --- a/src/CBot/CBotInstr/CBotFloat.cpp +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -24,6 +24,7 @@ #include "CBotInstArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index 7cbca510..2a97b86b 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -24,6 +24,7 @@ #include "CBotBoolExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 6700fab7..d325020e 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -30,6 +30,7 @@ #include "CBotInstr/CBotListArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotDefParam.h" #include "CBotUtils.h" diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp index 3c348111..6feefc41 100644 --- a/src/CBot/CBotInstr/CBotIString.cpp +++ b/src/CBot/CBotInstr/CBotIString.cpp @@ -23,6 +23,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotIf.cpp b/src/CBot/CBotInstr/CBotIf.cpp index b0cdbc88..1075f65f 100644 --- a/src/CBot/CBotInstr/CBotIf.cpp +++ b/src/CBot/CBotInstr/CBotIf.cpp @@ -23,6 +23,7 @@ #include "CBotInstr/CBotCondition.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp index 2bc37f1e..471089c3 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.cpp +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -21,6 +21,7 @@ #include "CBotIndexExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVarArray.h" diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp index f53cb65e..7d2a441e 100644 --- a/src/CBot/CBotInstr/CBotInstArray.cpp +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -26,6 +26,7 @@ #include "CBotEmpty.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotDefines.h" diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index c2c33b0f..ca21b87d 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index dabcd463..46adf723 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -21,6 +21,7 @@ #include "CBotInstrMethode.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp index 1649de55..7ea8cbf6 100644 --- a/src/CBot/CBotInstr/CBotInt.cpp +++ b/src/CBot/CBotInstr/CBotInt.cpp @@ -25,6 +25,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 468854a9..e09a2263 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -24,6 +24,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVarArray.h" diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index d0c3482b..18af17c7 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -21,6 +21,7 @@ #include "CBotLeftExprVar.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 682505b7..6ac0d6a0 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -24,6 +24,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index afa5f877..670f3fb5 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -26,6 +26,7 @@ #include "CBotInt.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp index fde2103c..576012b8 100644 --- a/src/CBot/CBotInstr/CBotListInstr.cpp +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -22,6 +22,7 @@ #include "CBotBlock.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 094e5a08..6f7d8605 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -21,6 +21,7 @@ #include "CBotNew.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp index fc34b513..21b40d18 100644 --- a/src/CBot/CBotInstr/CBotParExpr.cpp +++ b/src/CBot/CBotInstr/CBotParExpr.cpp @@ -34,6 +34,8 @@ #include "CBotVar/CBotVar.h" +#include "CBotCStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index 3837b26c..70c849d2 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index 0a527d2f..ef53fd77 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -26,6 +26,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp index c02f2214..4fc8cddd 100644 --- a/src/CBot/CBotInstr/CBotThrow.cpp +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp index 2ac2ae64..d3aecf85 100644 --- a/src/CBot/CBotInstr/CBotTry.cpp +++ b/src/CBot/CBotInstr/CBotTry.cpp @@ -22,6 +22,7 @@ #include "CBotBlock.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 4ad5ad03..ab5bc653 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -24,6 +24,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp index bfc2061f..eb38aea1 100644 --- a/src/CBot/CBotInstr/CBotWhile.cpp +++ b/src/CBot/CBotInstr/CBotWhile.cpp @@ -23,6 +23,7 @@ #include "CBotCondition.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 44eaca50..4e3f2c49 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -22,6 +22,7 @@ #include "CBotCall.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotUtils.h" diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 87aa0bb2..91f91a93 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -1133,392 +1133,3 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) } return true; } - - - - -//////////////////////////////////////////////////////////////////////////// -// management of the compile stack -//////////////////////////////////////////////////////////////////////////// - -CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable -int CBotCStack::m_error = 0; -int CBotCStack::m_end = 0; -CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0); -//CBotToken* CBotCStack::m_retClass= nullptr; - -//////////////////////////////////////////////////////////////////////////////// -CBotCStack::CBotCStack(CBotCStack* ppapa) -{ - m_next = nullptr; - m_prev = ppapa; - - if (ppapa == nullptr) - { - m_error = 0; - m_start = 0; - m_end = 0; - m_bBlock = true; - } - else - { - m_start = ppapa->m_start; - m_bBlock = false; - } - - m_listVar = nullptr; - m_var = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -// destructor -CBotCStack::~CBotCStack() -{ - if (m_next != nullptr) delete m_next; - if (m_prev != nullptr) m_prev->m_next = nullptr; // removes chain - - delete m_var; - delete m_listVar; -} - -//////////////////////////////////////////////////////////////////////////////// -// used only at compile -CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) -{ - if (m_next != nullptr) return m_next; // include on an existing stack - - CBotCStack* p = new CBotCStack(this); - m_next = p; // channel element - p->m_bBlock = bBlock; - - if (pToken != nullptr) p->SetStartError(pToken->GetStart()); - - return p; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) -{ - if ( pfils == this ) return inst; - - if (m_var != nullptr) delete m_var; // value replaced? - m_var = pfils->m_var; // result transmitted - pfils->m_var = nullptr; // not to destroy the variable - - if (m_error) - { - m_start = pfils->m_start; // retrieves the position of the error - m_end = pfils->m_end; - } - - delete pfils; - return inst; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) -{ - if (m_var != nullptr) delete m_var; // value replaced? - m_var = pfils->m_var; // result transmitted - pfils->m_var = nullptr; // not to destroy the variable - - if (m_error) - { - m_start = pfils->m_start; // retrieves the position of the error - m_end = pfils->m_end; - } - - delete pfils; - return inst; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotCStack::GetError(int& start, int& end) -{ - start = m_start; - end = m_end; - return m_error; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotCStack::GetError() -{ - return m_error; -} - -//////////////////////////////////////////////////////////////////////////////// -// type of instruction on the stack -CBotTypResult CBotCStack::GetTypResult(int mode) -{ - if (m_var == nullptr) - return CBotTypResult(99); - return m_var->GetTypResult(mode); -} - -//////////////////////////////////////////////////////////////////////////////// -// type of instruction on the stack -int CBotCStack::GetType(int mode) -{ - if (m_var == nullptr) - return 99; - return m_var->GetType(mode); -} - -//////////////////////////////////////////////////////////////////////////////// -// pointer on the stack is in what class? -CBotClass* CBotCStack::GetClass() -{ - if ( m_var == nullptr ) - return nullptr; - if ( m_var->GetType(1) != CBotTypPointer ) return nullptr; - - return m_var->GetClass(); -} - -//////////////////////////////////////////////////////////////////////////////// -// type of instruction on the stack -void CBotCStack::SetType(CBotTypResult& type) -{ - if (m_var == nullptr) return; - m_var->SetType( type ); -} - -// seeks a variable on the stack -// the token may be a result of TokenTypVar (object of a class) -// or a pointer in the source -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::FindVar(CBotToken* &pToken) -{ - CBotCStack* p = this; - CBotString name = pToken->GetString(); - - while (p != nullptr) - { - CBotVar* pp = p->m_listVar; - while ( pp != nullptr) - { - if (name == pp->GetName()) - { - return pp; - } - pp = pp->m_next; - } - p = p->m_prev; - } - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::FindVar(CBotToken& Token) -{ - CBotToken* pt = &Token; - return FindVar(pt); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::CopyVar(CBotToken& Token) -{ - CBotVar* pVar = FindVar( Token ); - - if ( pVar == nullptr) return nullptr; - - CBotVar* pCopy = CBotVar::Create( "", pVar->GetType() ); - pCopy->Copy(pVar); - return pCopy; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::IsOk() -{ - return (m_error == 0); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetStartError( int pos ) -{ - if ( m_error != 0) return; // does not change existing error - m_start = pos; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetError(int n, int pos) -{ - if ( n!= 0 && m_error != 0) return; // does not change existing error - m_error = n; - m_end = pos; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetError(int n, CBotToken* p) -{ - if (m_error) return; // does not change existing error - m_error = n; - m_start = p->GetStart(); - m_end = p->GetEnd(); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::ResetError(int n, int start, int end) -{ - m_error = n; - m_start = start; - m_end = end; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::NextToken(CBotToken* &p) -{ - CBotToken* pp = p; - - p = p->GetNext(); - if (p!=nullptr) return true; - - SetError(TX_ENDOF, pp->GetEnd()); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetBotCall(CBotProgram* p) -{ - m_prog = p; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotProgram* CBotCStack::GetBotCall() -{ - return m_prog; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetRetType(CBotTypResult& type) -{ - m_retTyp = type; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotCStack::GetRetType() -{ - return m_retTyp; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetVar( CBotVar* var ) -{ - if (m_var) delete m_var; // replacement of a variable - m_var = var; -} - -//////////////////////////////////////////////////////////////////////////////// -// puts on the stack a copy of a variable -void CBotCStack::SetCopyVar( CBotVar* var ) -{ - if (m_var) delete m_var; // replacement of a variable - - if ( var == nullptr ) return; - m_var = CBotVar::Create("", var->GetTypResult(2)); - m_var->Copy( var ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::GetVar() -{ - return m_var; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::AddVar(CBotVar* pVar) -{ - CBotCStack* p = this; - - // returns to the father element - while (p != nullptr && p->m_bBlock == 0) p = p->m_prev; - - if ( p == nullptr ) return; - - CBotVar** pp = &p->m_listVar; - while ( *pp != nullptr ) pp = &(*pp)->m_next; - - *pp = pVar; // added after - -#ifdef _DEBUG - if ( pVar->GetUniqNum() == 0 ) assert(0); -#endif -} - -// test whether a variable is already defined locally -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::CheckVarLocal(CBotToken* &pToken) -{ - CBotCStack* p = this; - CBotString name = pToken->GetString(); - - while (p != nullptr) - { - CBotVar* pp = p->m_listVar; - while ( pp != nullptr) - { - if (name == pp->GetName()) - return true; - pp = pp->m_next; - } - if ( p->m_bBlock ) return false; - p = p->m_prev; - } - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent) -{ - nIdent = 0; - CBotTypResult val(-1); - - val = CBotCall::CompileCall(p, ppVars, this, nIdent); - if (val.GetType() < 0) - { - val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent); - if ( val.GetType() < 0 ) - { - // pVar = nullptr; // the error is not on a particular parameter - SetError( -val.GetType(), p ); - val.SetType(-val.GetType()); - return val; - } - } - return val; -} - -// test if a procedure name is already defined somewhere -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) -{ - CBotString name = pToken->GetString(); - - if ( CBotCall::CheckCall(name) ) return true; - - CBotFunction* pp = m_prog->GetFunctions(); - while ( pp != nullptr ) - { - if ( pToken->GetString() == pp->GetName() ) - { - // are parameters exactly the same? - if ( pp->CheckParam( pParam ) ) - return true; - } - pp = pp->Next(); - } - - pp = CBotFunction::m_listPublic; - while ( pp != nullptr ) - { - if ( pToken->GetString() == pp->GetName() ) - { - // are parameters exactly the same? - if ( pp->CheckParam( pParam ) ) - return true; - } - pp = pp->m_nextpublic; - } - - return false; -} diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index b5f9c235..2df62cc2 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -23,6 +23,7 @@ #include "CBotToken.h" #include "CBotClass.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 87303c44..e69beaea 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -3,6 +3,7 @@ set(SOURCES CBotClass.cpp CBotProgram.cpp CBotStack.cpp + CBotCStack.cpp CBotString.cpp CBotToken.cpp CBotCall.cpp