Moving CBotCStack class in its own header and source files.
parent
660f17454a
commit
013be673ce
|
@ -73,6 +73,7 @@
|
||||||
#include "CBotInstr/CBotInt.h"
|
#include "CBotInstr/CBotInt.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
|
@ -52,82 +52,6 @@ class CBotIf; // if (...) {...} else {...}
|
||||||
class CBotDefParam; // paramerer list of a function
|
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);
|
extern bool SaveVar(FILE* pf, CBotVar* pVar);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
|
@ -22,11 +22,12 @@
|
||||||
|
|
||||||
#include "CBotToken.h"
|
#include "CBotToken.h"
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "CBotCall.h"
|
#include "CBotCall.h"
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
#include "CBotCallMethode.h"
|
#include "CBotCallMethode.h"
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBot.h"
|
#include "CBot.h"
|
||||||
|
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVarClass.h"
|
#include "CBotVar/CBotVarClass.h"
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
// Modules inlcude
|
// Modules inlcude
|
||||||
#include "CBotBlock.h"
|
#include "CBotBlock.h"
|
||||||
|
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotListInstr.h"
|
#include "CBotListInstr.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "CBotBoolExpr.h"
|
#include "CBotBoolExpr.h"
|
||||||
#include "CBotTwoOpExpr.h"
|
#include "CBotTwoOpExpr.h"
|
||||||
|
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBotInstArray.h"
|
#include "CBotInstArray.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotBreak.h"
|
#include "CBotBreak.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotExprNum.h"
|
#include "CBotExprNum.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBotExpression.h"
|
#include "CBotExpression.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBotInstArray.h"
|
#include "CBotInstArray.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVarPointer.h"
|
#include "CBotVar/CBotVarPointer.h"
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "CBotCondition.h"
|
#include "CBotCondition.h"
|
||||||
#include "CBotBoolExpr.h"
|
#include "CBotBoolExpr.h"
|
||||||
|
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBotCondition.h"
|
#include "CBotCondition.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotExprAlpha.h"
|
#include "CBotExprAlpha.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotExprBool.h"
|
#include "CBotExprBool.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotExprNum.h"
|
#include "CBotExprNum.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotParExpr.h"
|
#include "CBotParExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "CBotFieldExpr.h"
|
#include "CBotFieldExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVarArray.h"
|
#include "CBotVar/CBotVarArray.h"
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotTwoOpExpr.h"
|
#include "CBotTwoOpExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotFieldExpr.h"
|
#include "CBotFieldExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVarClass.h"
|
#include "CBotVar/CBotVarClass.h"
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBotInstArray.h"
|
#include "CBotInstArray.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBotBoolExpr.h"
|
#include "CBotBoolExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "CBotInstr/CBotListArray.h"
|
#include "CBotInstr/CBotListArray.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
#include "CBotDefParam.h"
|
#include "CBotDefParam.h"
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBotTwoOpExpr.h"
|
#include "CBotTwoOpExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBotInstr/CBotCondition.h"
|
#include "CBotInstr/CBotCondition.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotIndexExpr.h"
|
#include "CBotIndexExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVarArray.h"
|
#include "CBotVar/CBotVarArray.h"
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "CBotEmpty.h"
|
#include "CBotEmpty.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotDefines.h"
|
#include "CBotDefines.h"
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotExpression.h"
|
#include "CBotExpression.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotInstrMethode.h"
|
#include "CBotInstrMethode.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "CBotTwoOpExpr.h"
|
#include "CBotTwoOpExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBotExpression.h"
|
#include "CBotExpression.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVarArray.h"
|
#include "CBotVar/CBotVarArray.h"
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotLeftExprVar.h"
|
#include "CBotLeftExprVar.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBotTwoOpExpr.h"
|
#include "CBotTwoOpExpr.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "CBotInt.h"
|
#include "CBotInt.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotBlock.h"
|
#include "CBotBlock.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "CBotNew.h"
|
#include "CBotNew.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotExpression.h"
|
#include "CBotExpression.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "CBotExpression.h"
|
#include "CBotExpression.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotExpression.h"
|
#include "CBotExpression.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "CBotBlock.h"
|
#include "CBotBlock.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBotExpression.h"
|
#include "CBotExpression.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBotCondition.h"
|
#include "CBotCondition.h"
|
||||||
|
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "CBotCall.h"
|
#include "CBotCall.h"
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
|
|
||||||
|
|
|
@ -1133,392 +1133,3 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
}
|
}
|
||||||
return true;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBotToken.h"
|
#include "CBotToken.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
|
#include "CBotCStack.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ set(SOURCES
|
||||||
CBotClass.cpp
|
CBotClass.cpp
|
||||||
CBotProgram.cpp
|
CBotProgram.cpp
|
||||||
CBotStack.cpp
|
CBotStack.cpp
|
||||||
|
CBotCStack.cpp
|
||||||
CBotString.cpp
|
CBotString.cpp
|
||||||
CBotToken.cpp
|
CBotToken.cpp
|
||||||
CBotCall.cpp
|
CBotCall.cpp
|
||||||
|
|
Loading…
Reference in New Issue