CBot compiled instruction graphs; some code cleanup
parent
3b4ccc3535
commit
e3c53f9912
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CBot/CBotDebug.h"
|
||||||
|
|
||||||
|
#include "CBot/CBotProgram.h"
|
||||||
|
#include "CBot/CBotInstr/CBotFunction.h"
|
||||||
|
#include "CBot/CBotInstr/CBotInstrCall.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
|
||||||
|
namespace CBot
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::string GetPointerAsString(void* ptr)
|
||||||
|
{
|
||||||
|
char buffer[20];
|
||||||
|
sprintf(buffer, "instr%016lX", reinterpret_cast<unsigned long>(ptr));
|
||||||
|
return std::string(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBotDebug::DumpCompiledProgram(CBotProgram* program)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "digraph {" << std::endl;
|
||||||
|
|
||||||
|
CBotFunction* func = program->GetFunctions();
|
||||||
|
std::map<long, CBotFunction*> funcIdMap;
|
||||||
|
while (func != nullptr)
|
||||||
|
{
|
||||||
|
funcIdMap[func->m_nFuncIdent] = func;
|
||||||
|
func = func->Next();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<CBotInstr*> finished;
|
||||||
|
std::function<void(CBotInstr*)> DumpInstr = [&](CBotInstr* instr) {
|
||||||
|
if (finished.find(instr) != finished.end()) return;
|
||||||
|
finished.insert(instr);
|
||||||
|
|
||||||
|
std::string label = "<b>"+instr->GetDebugName()+"</b>\n";
|
||||||
|
std::string data = instr->GetDebugData();
|
||||||
|
boost::algorithm::replace_all(data, "&", "&");
|
||||||
|
boost::algorithm::replace_all(data, "<", "<");
|
||||||
|
boost::algorithm::replace_all(data, ">", ">");
|
||||||
|
label += data;
|
||||||
|
boost::algorithm::replace_all(label, "\n", "<br/>");
|
||||||
|
|
||||||
|
std::string additional = "";
|
||||||
|
if (instr->GetDebugName() == "CBotFunction")
|
||||||
|
{
|
||||||
|
label = instr->GetDebugData(); // hide the title
|
||||||
|
CBotFunction* function = static_cast<CBotFunction*>(instr);
|
||||||
|
if (function == program->m_entryPoint) additional += " shape=box3d";
|
||||||
|
else additional += " shape=box";
|
||||||
|
if (function->IsExtern()) additional += " color=cyan";
|
||||||
|
else additional += " color=blue";
|
||||||
|
additional += " group=func";
|
||||||
|
}
|
||||||
|
|
||||||
|
ss << GetPointerAsString(instr) << " [label=<" << label << ">" << additional << "]" << std::endl;
|
||||||
|
|
||||||
|
if (instr->GetDebugName() == "CBotInstrCall")
|
||||||
|
{
|
||||||
|
CBotInstrCall* call = static_cast<CBotInstrCall*>(instr);
|
||||||
|
if (funcIdMap.count(call->m_nFuncIdent) > 0)
|
||||||
|
{
|
||||||
|
ss << GetPointerAsString(instr) << " -> " << GetPointerAsString(funcIdMap[call->m_nFuncIdent]) << " [style=dotted color=gray weight=15]" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& it : instr->GetDebugLinks())
|
||||||
|
{
|
||||||
|
if (it.second == nullptr) continue;
|
||||||
|
if (it.second->GetDebugName() == "CBotFunction") continue;
|
||||||
|
DumpInstr(it.second);
|
||||||
|
ss << GetPointerAsString(instr) << " -> " << GetPointerAsString(it.second) << " [label=\"" << it.first << "\"" << (it.first == "m_next" ? " weight=1" : " weight=5") << "]" << std::endl;
|
||||||
|
if (it.first == "m_next" || (instr->GetDebugName() == "CBotFunction" && it.first == "m_block") || (instr->GetDebugName() == "CBotListInstr" && it.first == "m_instr"))
|
||||||
|
{
|
||||||
|
ss << "{ rank=same; " << GetPointerAsString(instr) << "; " << GetPointerAsString(it.second) << "; }" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (program->m_entryPoint != nullptr)
|
||||||
|
{
|
||||||
|
DumpInstr(program->m_entryPoint);
|
||||||
|
}
|
||||||
|
func = program->GetFunctions();
|
||||||
|
std::string prev = GetPointerAsString(program->m_entryPoint);
|
||||||
|
while (func != nullptr)
|
||||||
|
{
|
||||||
|
if (func != program->m_entryPoint)
|
||||||
|
{
|
||||||
|
DumpInstr(func);
|
||||||
|
|
||||||
|
//ss << prev << " -> " << GetPointerAsString(func) << " [style=invis]" << std::endl;
|
||||||
|
prev = GetPointerAsString(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
func = func->Next();
|
||||||
|
}
|
||||||
|
|
||||||
|
ss << "}" << std::endl;
|
||||||
|
std::cout << ss.str() << std::endl;
|
||||||
|
|
||||||
|
/* // Terrible platform-dependent code :P
|
||||||
|
std::stringstream filename;
|
||||||
|
filename << "compiled" << (program->m_entryPoint != nullptr ? "_"+program->m_entryPoint->GetName() : "") << ".png";
|
||||||
|
|
||||||
|
int pipeOut[2];
|
||||||
|
pipe(pipeOut);
|
||||||
|
if (fork())
|
||||||
|
{
|
||||||
|
close(pipeOut[0]);
|
||||||
|
write(pipeOut[1], ss.str().c_str(), ss.str().size());
|
||||||
|
close(pipeOut[1]);
|
||||||
|
int rv;
|
||||||
|
wait(&rv);
|
||||||
|
if(rv != 0) exit(rv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dup2(pipeOut[0], 0);
|
||||||
|
close(pipeOut[1]);
|
||||||
|
execl("/usr/bin/dot", "dot", "-Tpng", "-o", filename.str().c_str(), nullptr);
|
||||||
|
exit(1); // failed to start
|
||||||
|
} */
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CBot
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
namespace CBot
|
||||||
|
{
|
||||||
|
class CBotProgram;
|
||||||
|
|
||||||
|
class CBotDebug
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void DumpCompiledProgram(CBotProgram* program);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace CBot
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,7 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotBoolean::CBotBoolean()
|
CBotBoolean::CBotBoolean()
|
||||||
{
|
{
|
||||||
m_var =
|
m_var = m_expr = nullptr;
|
||||||
m_expr = nullptr;
|
|
||||||
name = "CBotBoolean";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -174,4 +172,12 @@ void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
|
m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotBoolean::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_var"] = m_var;
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -65,6 +65,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotBoolean"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Variable to initialise.
|
//! Variable to initialise.
|
||||||
CBotInstr* m_var;
|
CBotInstr* m_var;
|
||||||
|
|
|
@ -28,7 +28,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotBreak::CBotBreak()
|
CBotBreak::CBotBreak()
|
||||||
{
|
{
|
||||||
name = "CBotBreak"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -93,4 +92,9 @@ void CBotBreak :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
if ( bMain ) pj->RestoreStack(this);
|
if ( bMain ) pj->RestoreStack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotBreak::GetDebugData()
|
||||||
|
{
|
||||||
|
return !m_label.empty() ? "m_label = "+m_label : "";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -64,6 +64,9 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotBreak"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! A label if there is
|
//! A label if there is
|
||||||
|
|
|
@ -29,14 +29,13 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotCase::CBotCase()
|
CBotCase::CBotCase()
|
||||||
{
|
{
|
||||||
m_Value = nullptr; // nullptr so that delete is not possible further
|
m_value = nullptr;
|
||||||
name = "CBotCase"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotCase::~CBotCase()
|
CBotCase::~CBotCase()
|
||||||
{
|
{
|
||||||
delete m_Value; // frees the value
|
delete m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -51,8 +50,8 @@ CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
if ( pp->GetType() == ID_CASE )
|
if ( pp->GetType() == ID_CASE )
|
||||||
{
|
{
|
||||||
pp = p;
|
pp = p;
|
||||||
inst->m_Value = CBotExprNum::Compile(p, pStack);
|
inst->m_value = CBotExprNum::Compile(p, pStack);
|
||||||
if ( inst->m_Value == nullptr )
|
if (inst->m_value == nullptr )
|
||||||
{
|
{
|
||||||
pStack->SetError( CBotErrBadNum, pp );
|
pStack->SetError( CBotErrBadNum, pp );
|
||||||
delete inst;
|
delete inst;
|
||||||
|
@ -83,10 +82,17 @@ void CBotCase::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CBotCase::CompCase(CBotStack* &pile, int val)
|
bool CBotCase::CompCase(CBotStack* &pile, int val)
|
||||||
{
|
{
|
||||||
if ( m_Value == nullptr ) return true; // "default" case
|
if (m_value == nullptr ) return true; // "default" case
|
||||||
|
|
||||||
while (!m_Value->Execute(pile)); // puts the value on the correspondent stack (without interruption)
|
while (!m_value->Execute(pile)); // puts the value on the correspondent stack (without interruption)
|
||||||
return (pile->GetVal() == val); // compared with the given value
|
return (pile->GetVal() == val); // compared with the given value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotCase::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_value"] = m_value;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -74,9 +74,13 @@ public:
|
||||||
*/
|
*/
|
||||||
bool CompCase(CBotStack* &pj, int val) override;
|
bool CompCase(CBotStack* &pj, int val) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotCase"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Value to compare.
|
//! Value to compare.
|
||||||
CBotInstr* m_Value;
|
CBotInstr* m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -32,19 +32,17 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotCatch::CBotCatch()
|
CBotCatch::CBotCatch()
|
||||||
{
|
{
|
||||||
m_Cond =
|
m_cond = nullptr;
|
||||||
m_Block = nullptr; // nullptr so that delete is not possible further
|
m_block = nullptr;
|
||||||
m_next = nullptr;
|
m_next = nullptr;
|
||||||
|
|
||||||
name = "CBotCatch"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotCatch::~CBotCatch()
|
CBotCatch::~CBotCatch()
|
||||||
{
|
{
|
||||||
delete m_Cond; // frees the list
|
delete m_cond; // frees the list
|
||||||
delete m_Block; // frees the instruction block
|
delete m_block; // frees the instruction block
|
||||||
delete m_next; // and subsequent
|
delete m_next; // and subsequent
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -58,13 +56,13 @@ CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
if (IsOfType(p, ID_OPENPAR))
|
if (IsOfType(p, ID_OPENPAR))
|
||||||
{
|
{
|
||||||
inst->m_Cond = CBotExpression::Compile(p, pStack);
|
inst->m_cond = CBotExpression::Compile(p, pStack);
|
||||||
if (( pStack->GetType() < CBotTypLong ||
|
if (( pStack->GetType() < CBotTypLong ||
|
||||||
pStack->GetTypResult().Eq(CBotTypBoolean) )&& pStack->IsOk() )
|
pStack->GetTypResult().Eq(CBotTypBoolean) )&& pStack->IsOk() )
|
||||||
{
|
{
|
||||||
if (IsOfType(p, ID_CLOSEPAR))
|
if (IsOfType(p, ID_CLOSEPAR))
|
||||||
{
|
{
|
||||||
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStack );
|
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStack );
|
||||||
if ( pStack->IsOk() )
|
if ( pStack->IsOk() )
|
||||||
return inst; // return an object to the application
|
return inst; // return an object to the application
|
||||||
}
|
}
|
||||||
|
@ -80,26 +78,26 @@ CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CBotCatch :: Execute(CBotStack* &pj)
|
bool CBotCatch :: Execute(CBotStack* &pj)
|
||||||
{
|
{
|
||||||
if ( m_Block == nullptr ) return true;
|
if (m_block == nullptr ) return true;
|
||||||
return m_Block->Execute(pj); // executes the associated block
|
return m_block->Execute(pj); // executes the associated block
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void CBotCatch :: RestoreState(CBotStack* &pj, bool bMain)
|
void CBotCatch :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
{
|
{
|
||||||
if ( bMain && m_Block != nullptr ) m_Block->RestoreState(pj, bMain);
|
if ( bMain && m_block != nullptr ) m_block->RestoreState(pj, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void CBotCatch :: RestoreCondState(CBotStack* &pj, bool bMain)
|
void CBotCatch :: RestoreCondState(CBotStack* &pj, bool bMain)
|
||||||
{
|
{
|
||||||
m_Cond->RestoreState(pj, bMain);
|
m_cond->RestoreState(pj, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CBotCatch :: TestCatch(CBotStack* &pile, int val)
|
bool CBotCatch :: TestCatch(CBotStack* &pile, int val)
|
||||||
{
|
{
|
||||||
if ( !m_Cond->Execute(pile) ) return false;
|
if ( !m_cond->Execute(pile) ) return false;
|
||||||
|
|
||||||
if ( val > 0 || pile->GetVar() == nullptr || pile->GetVar()->GetType() != CBotTypBoolean )
|
if ( val > 0 || pile->GetVar() == nullptr || pile->GetVar()->GetType() != CBotTypBoolean )
|
||||||
{
|
{
|
||||||
|
@ -111,4 +109,13 @@ bool CBotCatch :: TestCatch(CBotStack* &pile, int val)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotCatch::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
links["m_cond"] = m_cond;
|
||||||
|
links["m_next"] = m_next;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -78,12 +78,15 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreCondState(CBotStack* &pj, bool bMain);
|
void RestoreCondState(CBotStack* &pj, bool bMain);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotCatch"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Instructions
|
//! Instructions
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
//! Condition
|
//! Condition
|
||||||
CBotInstr* m_Cond;
|
CBotInstr* m_cond;
|
||||||
//! Following catch
|
//! Following catch
|
||||||
CBotCatch* m_next;
|
CBotCatch* m_next;
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,10 @@ CBotClassInst::CBotClassInst()
|
||||||
{
|
{
|
||||||
m_next = nullptr;
|
m_next = nullptr;
|
||||||
m_var = nullptr;
|
m_var = nullptr;
|
||||||
m_Parameters = nullptr;
|
m_parameters = nullptr;
|
||||||
m_expr = nullptr;
|
m_expr = nullptr;
|
||||||
m_hasParams = false;
|
m_hasParams = false;
|
||||||
m_nMethodeIdent = 0;
|
m_nMethodeIdent = 0;
|
||||||
name = "CBotClassInst";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -123,14 +122,14 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
|
||||||
inst->m_hasParams = (p->GetType() == ID_OPENPAR);
|
inst->m_hasParams = (p->GetType() == ID_OPENPAR);
|
||||||
|
|
||||||
CBotVar* ppVars[1000];
|
CBotVar* ppVars[1000];
|
||||||
inst->m_Parameters = CompileParams(p, pStk, ppVars);
|
inst->m_parameters = CompileParams(p, pStk, ppVars);
|
||||||
if ( !pStk->IsOk() ) goto error;
|
if ( !pStk->IsOk() ) goto error;
|
||||||
|
|
||||||
// if there are parameters, is the equivalent to the stament "new"
|
// if there are parameters, is the equivalent to the stament "new"
|
||||||
// CPoint A ( 0, 0 ) is equivalent to
|
// CPoint A ( 0, 0 ) is equivalent to
|
||||||
// CPoint A = new CPoint( 0, 0 )
|
// CPoint A = new CPoint( 0, 0 )
|
||||||
|
|
||||||
// if ( nullptr != inst->m_Parameters )
|
// if ( nullptr != inst->m_parameters )
|
||||||
if ( inst->m_hasParams )
|
if ( inst->m_hasParams )
|
||||||
{
|
{
|
||||||
// the constructor is there?
|
// the constructor is there?
|
||||||
|
@ -142,7 +141,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
|
||||||
if (typ == CBotErrUndefCall)
|
if (typ == CBotErrUndefCall)
|
||||||
{
|
{
|
||||||
// si le constructeur n'existe pas
|
// si le constructeur n'existe pas
|
||||||
if (inst->m_Parameters != nullptr) // with parameters
|
if (inst->m_parameters != nullptr) // with parameters
|
||||||
{
|
{
|
||||||
pStk->SetError(CBotErrNoConstruct, vartoken);
|
pStk->SetError(CBotErrNoConstruct, vartoken);
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -310,7 +309,7 @@ bool CBotClassInst::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluates the parameters
|
// evaluates the parameters
|
||||||
// and places the values on the stack
|
// and places the values on the stack
|
||||||
// to (can) be interrupted (broken) at any time
|
// to (can) be interrupted (broken) at any time
|
||||||
|
@ -404,7 +403,7 @@ void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluates the parameters
|
// evaluates the parameters
|
||||||
// and the values an the stack
|
// and the values an the stack
|
||||||
// for the ability to be interrupted at any time (\TODO pour pouvoir être interrompu n'importe quand)
|
// for the ability to be interrupted at any time (\TODO pour pouvoir être interrompu n'importe quand)
|
||||||
|
@ -437,4 +436,13 @@ void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
|
m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotClassInst::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_var"] = m_var;
|
||||||
|
links["m_parameters"] = m_parameters;
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -66,18 +66,21 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotClassInstr"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! Variable to initialise.
|
//! Variable to initialise.
|
||||||
CBotInstr* m_var;
|
CBotInstr* m_var;
|
||||||
//! Reference to the class.
|
|
||||||
CBotClass* m_pClass;
|
|
||||||
//! Parameters to be evaluated for the contructor.
|
//! Parameters to be evaluated for the contructor.
|
||||||
CBotInstr* m_Parameters;
|
CBotInstr* m_parameters;
|
||||||
//! A value to put, if there is.
|
//! A value to put, if there is.
|
||||||
CBotInstr* m_expr;
|
CBotInstr* m_expr;
|
||||||
//! Has it parameters.
|
//! Has it parameters.
|
||||||
bool m_hasParams;
|
bool m_hasParams;
|
||||||
|
//! Constructor method unique identifier
|
||||||
long m_nMethodeIdent;
|
long m_nMethodeIdent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,16 +30,15 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotDo::CBotDo()
|
CBotDo::CBotDo()
|
||||||
{
|
{
|
||||||
m_Condition =
|
m_condition = nullptr;
|
||||||
m_Block = nullptr; // nullptr so that delete is not possible further
|
m_block = nullptr;
|
||||||
name = "CBotDo"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotDo::~CBotDo()
|
CBotDo::~CBotDo()
|
||||||
{
|
{
|
||||||
delete m_Condition; // frees the condition
|
delete m_condition; // frees the condition
|
||||||
delete m_Block; // frees the instruction block
|
delete m_block; // frees the instruction block
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -63,14 +62,14 @@ CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
// looking for a statement block after the do
|
// looking for a statement block after the do
|
||||||
IncLvl(inst->m_label);
|
IncLvl(inst->m_label);
|
||||||
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
|
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStk, true );
|
||||||
DecLvl();
|
DecLvl();
|
||||||
|
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
{
|
{
|
||||||
if (IsOfType(p, ID_WHILE))
|
if (IsOfType(p, ID_WHILE))
|
||||||
{
|
{
|
||||||
if ( nullptr != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
|
if ( nullptr != (inst->m_condition = CBotCondition::Compile(p, pStk )) )
|
||||||
{
|
{
|
||||||
// the condition exists
|
// the condition exists
|
||||||
if (IsOfType(p, ID_SEP))
|
if (IsOfType(p, ID_SEP))
|
||||||
|
@ -100,8 +99,8 @@ bool CBotDo :: Execute(CBotStack* &pj)
|
||||||
{ // there are two possible states (depending on recovery)
|
{ // there are two possible states (depending on recovery)
|
||||||
case 0:
|
case 0:
|
||||||
// evaluates the associated statement block
|
// evaluates the associated statement block
|
||||||
if ( m_Block != nullptr &&
|
if (m_block != nullptr &&
|
||||||
!m_Block->Execute(pile) )
|
!m_block->Execute(pile) )
|
||||||
{
|
{
|
||||||
if (pile->IfContinue(1, m_label)) continue; // if continued, will return to test
|
if (pile->IfContinue(1, m_label)) continue; // if continued, will return to test
|
||||||
return pj->BreakReturn(pile, m_label); // sends the results and releases the stack
|
return pj->BreakReturn(pile, m_label); // sends the results and releases the stack
|
||||||
|
@ -117,7 +116,7 @@ bool CBotDo :: Execute(CBotStack* &pj)
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// evaluates the condition
|
// evaluates the condition
|
||||||
if ( !m_Condition->Execute(pile) ) return false; // interrupted here ?
|
if ( !m_condition->Execute(pile) ) return false; // interrupted here ?
|
||||||
|
|
||||||
// the result of the condition is on the stack
|
// the result of the condition is on the stack
|
||||||
|
|
||||||
|
@ -145,14 +144,27 @@ void CBotDo :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
{ // there are two possible states (depending on recovery)
|
{ // there are two possible states (depending on recovery)
|
||||||
case 0:
|
case 0:
|
||||||
// restores the assosiated statement's block
|
// restores the assosiated statement's block
|
||||||
if ( m_Block != nullptr ) m_Block->RestoreState(pile, bMain);
|
if (m_block != nullptr ) m_block->RestoreState(pile, bMain);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// restores the condition
|
// restores the condition
|
||||||
m_Condition->RestoreState(pile, bMain);
|
m_condition->RestoreState(pile, bMain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotDo::GetDebugData()
|
||||||
|
{
|
||||||
|
return !m_label.empty() ? "m_label = "+m_label : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotDo::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
links["m_condition"] = m_condition;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -60,11 +60,16 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotDo"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Instruction
|
//! Instruction
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
//! Conditions
|
//! Conditions
|
||||||
CBotInstr* m_Condition;
|
CBotInstr* m_condition;
|
||||||
//! A label if there is
|
//! A label if there is
|
||||||
std::string m_label;
|
std::string m_label;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,6 +42,9 @@ class CBotEmpty : public CBotInstr
|
||||||
* \param bMain
|
* \param bMain
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotEmpty"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -30,7 +30,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprAlpha::CBotExprAlpha()
|
CBotExprAlpha::CBotExprAlpha()
|
||||||
{
|
{
|
||||||
name = "CBotExprAlpha";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -79,4 +78,9 @@ void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
if (bMain) pj->RestoreStack(this);
|
if (bMain) pj->RestoreStack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotExprAlpha::GetDebugData()
|
||||||
|
{
|
||||||
|
return m_token.GetString();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -62,6 +62,10 @@ public:
|
||||||
* \param bMain
|
* \param bMain
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExprAlpha"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -30,7 +30,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprBool::CBotExprBool()
|
CBotExprBool::CBotExprBool()
|
||||||
{
|
{
|
||||||
name = "CBotExprBool";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -62,6 +62,9 @@ public:
|
||||||
* \param bMain
|
* \param bMain
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExprBool"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -29,7 +29,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprNan::CBotExprNan()
|
CBotExprNan::CBotExprNan()
|
||||||
{
|
{
|
||||||
name = "CBotExprNan";
|
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprNan::~CBotExprNan()
|
CBotExprNan::~CBotExprNan()
|
||||||
|
|
|
@ -54,6 +54,10 @@ public:
|
||||||
* \param bMain
|
* \param bMain
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExprNan"; }
|
||||||
|
virtual std::string GetDebugData() { return "nan"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -29,7 +29,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprNull::CBotExprNull()
|
CBotExprNull::CBotExprNull()
|
||||||
{
|
{
|
||||||
name = "CBotExprNull";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -54,6 +54,10 @@ public:
|
||||||
* \param bMain
|
* \param bMain
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExprNull"; }
|
||||||
|
virtual std::string GetDebugData() { return "null"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include "CBot/CBotInstr/CBotExprNum.h"
|
#include "CBot/CBotInstr/CBotExprNum.h"
|
||||||
|
|
||||||
#include "CBot/CBotStack.h"
|
#include "CBot/CBotStack.h"
|
||||||
|
@ -32,7 +33,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprNum::CBotExprNum()
|
CBotExprNum::CBotExprNum()
|
||||||
{
|
{
|
||||||
name = "CBotExprNum";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -115,4 +115,11 @@ void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
if (bMain) pj->RestoreStack(this);
|
if (bMain) pj->RestoreStack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotExprNum::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "(" << (m_numtype == CBotTypFloat ? "float" : "int") << ") " << (m_numtype == CBotTypFloat ? m_valfloat : m_valint);
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -64,10 +64,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExprNum"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
|
||||||
|
private:
|
||||||
//! The type of number.
|
//! The type of number.
|
||||||
int m_numtype;
|
CBotType m_numtype;
|
||||||
//! Value for an int.
|
//! Value for an int.
|
||||||
long m_valint;
|
long m_valint;
|
||||||
//! Value for a float.
|
//! Value for a float.
|
||||||
|
|
|
@ -31,14 +31,13 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprUnaire::CBotExprUnaire()
|
CBotExprUnaire::CBotExprUnaire()
|
||||||
{
|
{
|
||||||
m_Expr = nullptr;
|
m_expr = nullptr;
|
||||||
name = "CBotExprUnaire";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprUnaire::~CBotExprUnaire()
|
CBotExprUnaire::~CBotExprUnaire()
|
||||||
{
|
{
|
||||||
delete m_Expr;
|
delete m_expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -53,7 +52,7 @@ CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
CBotExprUnaire* inst = new CBotExprUnaire();
|
CBotExprUnaire* inst = new CBotExprUnaire();
|
||||||
inst->SetToken(pp);
|
inst->SetToken(pp);
|
||||||
|
|
||||||
if (nullptr != (inst->m_Expr = CBotParExpr::Compile( p, pStk )))
|
if (nullptr != (inst->m_expr = CBotParExpr::Compile(p, pStk )))
|
||||||
{
|
{
|
||||||
if (op == ID_ADD && pStk->GetType() < CBotTypBoolean) // only with the number
|
if (op == ID_ADD && pStk->GetType() < CBotTypBoolean) // only with the number
|
||||||
return pStack->Return(inst, pStk);
|
return pStack->Return(inst, pStk);
|
||||||
|
@ -80,7 +79,7 @@ bool CBotExprUnaire::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
if (pile->GetState() == 0)
|
if (pile->GetState() == 0)
|
||||||
{
|
{
|
||||||
if (!m_Expr->Execute(pile)) return false; // interrupted ?
|
if (!m_expr->Execute(pile)) return false; // interrupted ?
|
||||||
pile->IncState();
|
pile->IncState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +114,16 @@ void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
if (pile->GetState() == 0)
|
if (pile->GetState() == 0)
|
||||||
{
|
{
|
||||||
m_Expr->RestoreState(pile, bMain); // interrupted here!
|
m_expr->RestoreState(pile, bMain); // interrupted here!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotExprUnaire::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -64,9 +64,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExprUnaire"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Expression to be evaluated.
|
//! Expression to be evaluated.
|
||||||
CBotInstr* m_Expr;
|
CBotInstr* m_expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include "CBot/CBotInstr/CBotExprVar.h"
|
#include "CBot/CBotInstr/CBotExprVar.h"
|
||||||
#include "CBot/CBotInstr/CBotInstrMethode.h"
|
#include "CBot/CBotInstr/CBotInstrMethode.h"
|
||||||
#include "CBot/CBotInstr/CBotExpression.h"
|
#include "CBot/CBotInstr/CBotExpression.h"
|
||||||
|
@ -34,7 +35,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotExprVar::CBotExprVar()
|
CBotExprVar::CBotExprVar()
|
||||||
{
|
{
|
||||||
name = "CBotExprVar";
|
|
||||||
m_nIdent = 0;
|
m_nIdent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,4 +304,12 @@ void CBotExprVar::RestoreStateVar(CBotStack* &pj, bool bMain)
|
||||||
m_next3->RestoreStateVar(pj, bMain);
|
m_next3->RestoreStateVar(pj, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotExprVar::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << m_token.GetString() << std::endl;
|
||||||
|
//ss << "VarID = " << m_nIdent;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -94,6 +94,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExprVar"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long m_nIdent;
|
long m_nIdent;
|
||||||
friend class CBotPostIncExpr;
|
friend class CBotPostIncExpr;
|
||||||
|
|
|
@ -37,8 +37,7 @@ namespace CBot
|
||||||
CBotExpression::CBotExpression()
|
CBotExpression::CBotExpression()
|
||||||
{
|
{
|
||||||
m_leftop = nullptr;
|
m_leftop = nullptr;
|
||||||
m_rightop = nullptr;
|
m_rightop = nullptr;
|
||||||
name = "CBotExpression";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -296,4 +295,12 @@ void CBotExpression::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotExpression::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_leftop"] = m_leftop;
|
||||||
|
links["m_rightop"] = m_rightop;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -76,6 +76,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotExpression"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Left operand
|
//! Left operand
|
||||||
CBotLeftExpr* m_leftop;
|
CBotLeftExpr* m_leftop;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "CBot/CBotVar/CBotVarClass.h"
|
#include "CBot/CBotVar/CBotVarClass.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace CBot
|
namespace CBot
|
||||||
{
|
{
|
||||||
|
@ -33,7 +34,6 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotFieldExpr::CBotFieldExpr()
|
CBotFieldExpr::CBotFieldExpr()
|
||||||
{
|
{
|
||||||
name = "CBotFieldExpr";
|
|
||||||
m_nIdent = 0;
|
m_nIdent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,4 +128,11 @@ void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain)
|
||||||
m_next3->RestoreStateVar(pj, bMain);
|
m_next3->RestoreStateVar(pj, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotFieldExpr::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "VarID = " << m_nIdent;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -74,6 +74,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotFieldExpr"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CBotExpression;
|
friend class CBotExpression;
|
||||||
int m_nIdent;
|
int m_nIdent;
|
||||||
|
|
|
@ -33,9 +33,8 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotFloat::CBotFloat()
|
CBotFloat::CBotFloat()
|
||||||
{
|
{
|
||||||
m_var =
|
m_var = nullptr;
|
||||||
m_expr = nullptr;
|
m_expr = nullptr;
|
||||||
name = "CBotFloat";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -172,4 +171,12 @@ void CBotFloat::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
m_next2b->RestoreState(pile, bMain);
|
m_next2b->RestoreState(pile, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotFloat::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_var"] = m_var;
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -65,6 +65,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotFloat"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Variable to initialise.
|
//! Variable to initialise.
|
||||||
CBotInstr* m_var;
|
CBotInstr* m_var;
|
||||||
|
|
|
@ -31,20 +31,19 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotFor::CBotFor()
|
CBotFor::CBotFor()
|
||||||
{
|
{
|
||||||
m_Init =
|
m_init = nullptr;
|
||||||
m_Test =
|
m_test = nullptr;
|
||||||
m_Incr =
|
m_incr = nullptr;
|
||||||
m_Block = nullptr; // nullptr so that delete is not possible further
|
m_block = nullptr;
|
||||||
name = "CBotFor"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotFor::~CBotFor()
|
CBotFor::~CBotFor()
|
||||||
{
|
{
|
||||||
delete m_Init;
|
delete m_init;
|
||||||
delete m_Test;
|
delete m_test;
|
||||||
delete m_Incr;
|
delete m_incr;
|
||||||
delete m_Block; // frees the instruction block
|
delete m_block; // frees the instruction block
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -71,7 +70,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
CBotCStack* pStk = pStack->TokenStack(pp, true); // un petit bout de pile svp
|
CBotCStack* pStk = pStack->TokenStack(pp, true); // un petit bout de pile svp
|
||||||
|
|
||||||
// compiles instructions for initialization
|
// compiles instructions for initialization
|
||||||
inst->m_Init = CBotListExpression::Compile( p, pStk );
|
inst->m_init = CBotListExpression::Compile(p, pStk );
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
{
|
{
|
||||||
if ( !IsOfType(p, ID_SEP)) // lack the semicolon?
|
if ( !IsOfType(p, ID_SEP)) // lack the semicolon?
|
||||||
|
@ -80,7 +79,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
delete inst;
|
delete inst;
|
||||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||||
}
|
}
|
||||||
inst->m_Test = CBotBoolExpr::Compile( p, pStk );
|
inst->m_test = CBotBoolExpr::Compile(p, pStk );
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
{
|
{
|
||||||
if ( !IsOfType(p, ID_SEP)) // lack the semicolon?
|
if ( !IsOfType(p, ID_SEP)) // lack the semicolon?
|
||||||
|
@ -89,13 +88,13 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
delete inst;
|
delete inst;
|
||||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||||
}
|
}
|
||||||
inst->m_Incr = CBotListExpression::Compile( p, pStk );
|
inst->m_incr = CBotListExpression::Compile(p, pStk );
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
{
|
{
|
||||||
if ( IsOfType(p, ID_CLOSEPAR)) // missing parenthesis ?
|
if ( IsOfType(p, ID_CLOSEPAR)) // missing parenthesis ?
|
||||||
{
|
{
|
||||||
IncLvl(inst->m_label);
|
IncLvl(inst->m_label);
|
||||||
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
|
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStk, true );
|
||||||
DecLvl();
|
DecLvl();
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
return pStack->Return(inst, pStk);;
|
return pStack->Return(inst, pStk);;
|
||||||
|
@ -123,15 +122,15 @@ bool CBotFor :: Execute(CBotStack* &pj)
|
||||||
{ // there are four possible states (depending on recovery)
|
{ // there are four possible states (depending on recovery)
|
||||||
case 0:
|
case 0:
|
||||||
// initialize
|
// initialize
|
||||||
if ( m_Init != nullptr &&
|
if (m_init != nullptr &&
|
||||||
!m_Init->Execute(pile) ) return false; // interrupted here ?
|
!m_init->Execute(pile) ) return false; // interrupted here ?
|
||||||
if (!pile->SetState(1)) return false; // ready for further
|
if (!pile->SetState(1)) return false; // ready for further
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// evaluates the condition
|
// evaluates the condition
|
||||||
if ( m_Test != nullptr ) // no strings attached? -> True!
|
if (m_test != nullptr ) // no strings attached? -> True!
|
||||||
{
|
{
|
||||||
if (!m_Test->Execute(pile) ) return false; // interrupted here ?
|
if (!m_test->Execute(pile) ) return false; // interrupted here ?
|
||||||
|
|
||||||
// the result of the condition is on the stack
|
// the result of the condition is on the stack
|
||||||
|
|
||||||
|
@ -147,8 +146,8 @@ bool CBotFor :: Execute(CBotStack* &pj)
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// evaluates the associated statement block
|
// evaluates the associated statement block
|
||||||
if ( m_Block != nullptr &&
|
if (m_block != nullptr &&
|
||||||
!m_Block->Execute(pile) )
|
!m_block->Execute(pile) )
|
||||||
{
|
{
|
||||||
if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation
|
if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation
|
||||||
return pj->BreakReturn(pile, m_label); // sends the results and releases the stack
|
return pj->BreakReturn(pile, m_label); // sends the results and releases the stack
|
||||||
|
@ -164,8 +163,8 @@ bool CBotFor :: Execute(CBotStack* &pj)
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
// evalutate the incrementation
|
// evalutate the incrementation
|
||||||
if ( m_Incr != nullptr &&
|
if (m_incr != nullptr &&
|
||||||
!m_Incr->Execute(pile) ) return false; // interrupted here ?
|
!m_incr->Execute(pile) ) return false; // interrupted here ?
|
||||||
|
|
||||||
// returns to the test again
|
// returns to the test again
|
||||||
if (!pile->SetState(1, 0)) return false; // returns to the test
|
if (!pile->SetState(1, 0)) return false; // returns to the test
|
||||||
|
@ -185,30 +184,45 @@ void CBotFor :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
{ // there are four possible states (depending on recovery)
|
{ // there are four possible states (depending on recovery)
|
||||||
case 0:
|
case 0:
|
||||||
// initialize
|
// initialize
|
||||||
if ( m_Init != nullptr ) m_Init->RestoreState(pile, true); // interrupted here !
|
if (m_init != nullptr ) m_init->RestoreState(pile, true); // interrupted here !
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variables definitions
|
if (m_init != nullptr ) m_init->RestoreState(pile, false); // variables definitions
|
||||||
|
|
||||||
// evaluates the condition
|
// evaluates the condition
|
||||||
if ( m_Test != nullptr ) m_Test->RestoreState(pile, true); // interrupted here !
|
if (m_test != nullptr ) m_test->RestoreState(pile, true); // interrupted here !
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variable definitions
|
if (m_init != nullptr ) m_init->RestoreState(pile, false); // variable definitions
|
||||||
|
|
||||||
// evaluates the associated statement block
|
// evaluates the associated statement block
|
||||||
if ( m_Block != nullptr ) m_Block->RestoreState(pile, true);
|
if (m_block != nullptr ) m_block->RestoreState(pile, true);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variable definitions
|
if (m_init != nullptr ) m_init->RestoreState(pile, false); // variable definitions
|
||||||
|
|
||||||
// evaluate the incrementation
|
// evaluate the incrementation
|
||||||
if ( m_Incr != nullptr ) m_Incr->RestoreState(pile, true); // interrupted here !
|
if (m_incr != nullptr ) m_incr->RestoreState(pile, true); // interrupted here !
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotFor::GetDebugData()
|
||||||
|
{
|
||||||
|
return !m_label.empty() ? "m_label = "+m_label : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotFor::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_init"] = m_init;
|
||||||
|
links["m_test"] = m_test;
|
||||||
|
links["m_incr"] = m_incr;
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -63,18 +63,22 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotFor"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
|
private:
|
||||||
//! Initial intruction
|
//! Initial intruction
|
||||||
CBotInstr* m_Init;
|
CBotInstr* m_init;
|
||||||
//! Test Condition
|
//! Test Condition
|
||||||
CBotInstr* m_Test;
|
CBotInstr* m_test;
|
||||||
//! instruction for increment
|
//! instruction for increment
|
||||||
CBotInstr* m_Incr;
|
CBotInstr* m_incr;
|
||||||
//! Instructions
|
//! Instructions
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
//! A label if there is
|
//! A label if there is
|
||||||
std::string m_label;
|
std::string m_label;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "CBot/CBotVar/CBotVar.h"
|
#include "CBot/CBotVar/CBotVar.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace CBot
|
namespace CBot
|
||||||
{
|
{
|
||||||
|
@ -43,8 +44,8 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotFunction::CBotFunction()
|
CBotFunction::CBotFunction()
|
||||||
{
|
{
|
||||||
m_Param = nullptr; // empty parameter list
|
m_param = nullptr; // empty parameter list
|
||||||
m_Block = nullptr; // the instruction block
|
m_block = nullptr; // the instruction block
|
||||||
m_next = nullptr; // functions can be chained
|
m_next = nullptr; // functions can be chained
|
||||||
m_bPublic = false; // function not public
|
m_bPublic = false; // function not public
|
||||||
m_bExtern = false; // function not extern
|
m_bExtern = false; // function not extern
|
||||||
|
@ -60,8 +61,8 @@ std::set<CBotFunction*> CBotFunction::m_publicFunctions{};
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotFunction::~CBotFunction()
|
CBotFunction::~CBotFunction()
|
||||||
{
|
{
|
||||||
delete m_Param; // empty parameter list
|
delete m_param; // empty parameter list
|
||||||
delete m_Block; // the instruction block
|
delete m_block; // the instruction block
|
||||||
delete m_next;
|
delete m_next;
|
||||||
|
|
||||||
// remove public list if there is
|
// remove public list if there is
|
||||||
|
@ -185,7 +186,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
|
||||||
|
|
||||||
}
|
}
|
||||||
func->m_openpar = *p;
|
func->m_openpar = *p;
|
||||||
func->m_Param = CBotDefParam::Compile( p, pStk );
|
func->m_param = CBotDefParam::Compile(p, pStk );
|
||||||
func->m_closepar = *(p->GetPrev());
|
func->m_closepar = *(p->GetPrev());
|
||||||
if (pStk->IsOk())
|
if (pStk->IsOk())
|
||||||
{
|
{
|
||||||
|
@ -219,7 +220,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
|
||||||
|
|
||||||
// and compiles the following instruction block
|
// and compiles the following instruction block
|
||||||
func->m_openblk = *p;
|
func->m_openblk = *p;
|
||||||
func->m_Block = CBotBlock::Compile(p, pStk, false);
|
func->m_block = CBotBlock::Compile(p, pStk, false);
|
||||||
func->m_closeblk = (p != nullptr && p->GetPrev() != nullptr) ? *(p->GetPrev()) : CBotToken();
|
func->m_closeblk = (p != nullptr && p->GetPrev() != nullptr) ? *(p->GetPrev()) : CBotToken();
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
{
|
{
|
||||||
|
@ -294,12 +295,12 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas
|
||||||
if (!IsOfType(p, TokenTypVar)) goto bad;
|
if (!IsOfType(p, TokenTypVar)) goto bad;
|
||||||
|
|
||||||
}
|
}
|
||||||
func->m_Param = CBotDefParam::Compile( p, pStk );
|
func->m_param = CBotDefParam::Compile(p, pStk );
|
||||||
if (pStk->IsOk())
|
if (pStk->IsOk())
|
||||||
{
|
{
|
||||||
// looks if the function exists elsewhere
|
// looks if the function exists elsewhere
|
||||||
if (( pClass != nullptr || !pStack->CheckCall(pp, func->m_Param)) &&
|
if (( pClass != nullptr || !pStack->CheckCall(pp, func->m_param)) &&
|
||||||
( pClass == nullptr || !pClass->CheckCall(pStack->GetProgram(), func->m_Param, pp)) )
|
( pClass == nullptr || !pClass->CheckCall(pStack->GetProgram(), func->m_param, pp)) )
|
||||||
{
|
{
|
||||||
if (IsOfType(p, ID_OPBLK))
|
if (IsOfType(p, ID_OPBLK))
|
||||||
{
|
{
|
||||||
|
@ -339,7 +340,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
|
||||||
|
|
||||||
if ( pile->GetState() == 0 )
|
if ( pile->GetState() == 0 )
|
||||||
{
|
{
|
||||||
if ( !m_Param->Execute(ppVars, pile) ) return false; // define parameters
|
if ( !m_param->Execute(ppVars, pile) ) return false; // define parameters
|
||||||
pile->IncState();
|
pile->IncState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +375,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
|
||||||
|
|
||||||
if ( pile->IfStep() ) return false;
|
if ( pile->IfStep() ) return false;
|
||||||
|
|
||||||
if ( !m_Block->Execute(pile) )
|
if ( !m_block->Execute(pile) )
|
||||||
{
|
{
|
||||||
if ( pile->GetError() < 0 )
|
if ( pile->GetError() < 0 )
|
||||||
pile->SetError( CBotNoErr );
|
pile->SetError( CBotNoErr );
|
||||||
|
@ -402,7 +403,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
|
||||||
pile2->Delete();
|
pile2->Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Param->RestoreState(pile2, true); // parameters
|
m_param->RestoreState(pile2, true); // parameters
|
||||||
|
|
||||||
if ( !m_MasterClass.empty() )
|
if ( !m_MasterClass.empty() )
|
||||||
{
|
{
|
||||||
|
@ -411,7 +412,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
|
||||||
pThis->SetUniqNum(-2);
|
pThis->SetUniqNum(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Block->RestoreState(pile2, true);
|
m_block->RestoreState(pile2, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -477,7 +478,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int alpha = 0; // signature of parameters
|
int alpha = 0; // signature of parameters
|
||||||
// parameters are compatible?
|
// parameters are compatible?
|
||||||
CBotDefParam* pv = pt->m_Param; // expected list of parameters
|
CBotDefParam* pv = pt->m_param; // expected list of parameters
|
||||||
CBotVar* pw = ppVars[i++]; // provided list parameter
|
CBotVar* pw = ppVars[i++]; // provided list parameter
|
||||||
while ( pv != nullptr && pw != nullptr)
|
while ( pv != nullptr && pw != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -532,7 +533,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int alpha = 0; // signature of parameters
|
int alpha = 0; // signature of parameters
|
||||||
// parameters sont-ils compatibles ?
|
// parameters sont-ils compatibles ?
|
||||||
CBotDefParam* pv = pt->m_Param; // list of expected parameters
|
CBotDefParam* pv = pt->m_param; // list of expected parameters
|
||||||
CBotVar* pw = ppVars[i++]; // list of provided parameters
|
CBotVar* pw = ppVars[i++]; // list of provided parameters
|
||||||
while ( pv != nullptr && pw != nullptr)
|
while ( pv != nullptr && pw != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -638,7 +639,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
|
||||||
}
|
}
|
||||||
|
|
||||||
// initializes the variables as parameters
|
// initializes the variables as parameters
|
||||||
pt->m_Param->Execute(ppVars, pStk3); // cannot be interrupted
|
pt->m_param->Execute(ppVars, pStk3); // cannot be interrupted
|
||||||
|
|
||||||
pStk1->IncState();
|
pStk1->IncState();
|
||||||
}
|
}
|
||||||
|
@ -646,7 +647,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
|
||||||
// finally execution of the found function
|
// finally execution of the found function
|
||||||
|
|
||||||
if ( !pStk3->GetRetVar( // puts the result on the stack
|
if ( !pStk3->GetRetVar( // puts the result on the stack
|
||||||
pt->m_Block->Execute(pStk3) )) // GetRetVar said if it is interrupted
|
pt->m_block->Execute(pStk3) )) // GetRetVar said if it is interrupted
|
||||||
{
|
{
|
||||||
if ( !pStk3->IsOk() && pt->m_pProg != m_pProg )
|
if ( !pStk3->IsOk() && pt->m_pProg != m_pProg )
|
||||||
{
|
{
|
||||||
|
@ -707,13 +708,13 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar**
|
||||||
|
|
||||||
if ( pStk1->GetState() == 0 )
|
if ( pStk1->GetState() == 0 )
|
||||||
{
|
{
|
||||||
pt->m_Param->RestoreState(pStk3, true);
|
pt->m_param->RestoreState(pStk3, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initializes the variables as parameters
|
// initializes the variables as parameters
|
||||||
pt->m_Param->RestoreState(pStk3, false);
|
pt->m_param->RestoreState(pStk3, false);
|
||||||
pt->m_Block->RestoreState(pStk3, true);
|
pt->m_block->RestoreState(pStk3, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,7 +757,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis,
|
||||||
pStk->AddVar(psuper);
|
pStk->AddVar(psuper);
|
||||||
}
|
}
|
||||||
// initializes the variables as parameters
|
// initializes the variables as parameters
|
||||||
pt->m_Param->Execute(ppVars, pStk3); // cannot be interrupted
|
pt->m_param->Execute(ppVars, pStk3); // cannot be interrupted
|
||||||
pStk->IncState();
|
pStk->IncState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -772,7 +773,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis,
|
||||||
// finally calls the found function
|
// finally calls the found function
|
||||||
|
|
||||||
if ( !pStk3->GetRetVar( // puts the result on the stack
|
if ( !pStk3->GetRetVar( // puts the result on the stack
|
||||||
pt->m_Block->Execute(pStk3) )) // GetRetVar said if it is interrupted
|
pt->m_block->Execute(pStk3) )) // GetRetVar said if it is interrupted
|
||||||
{
|
{
|
||||||
if ( !pStk3->IsOk() )
|
if ( !pStk3->IsOk() )
|
||||||
{
|
{
|
||||||
|
@ -818,7 +819,7 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* p
|
||||||
CBotStack* pStk3 = pStk->RestoreStack(nullptr); // to set parameters passed
|
CBotStack* pStk3 = pStk->RestoreStack(nullptr); // to set parameters passed
|
||||||
if ( pStk3 == nullptr ) return;
|
if ( pStk3 == nullptr ) return;
|
||||||
|
|
||||||
pt->m_Param->RestoreState(pStk3, true); // parameters
|
pt->m_param->RestoreState(pStk3, true); // parameters
|
||||||
|
|
||||||
if ( pStk->GetState() > 1 && // latching is effective?
|
if ( pStk->GetState() > 1 && // latching is effective?
|
||||||
pt->m_bSynchro )
|
pt->m_bSynchro )
|
||||||
|
@ -829,14 +830,14 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* p
|
||||||
|
|
||||||
// finally calls the found function
|
// finally calls the found function
|
||||||
|
|
||||||
pt->m_Block->RestoreState(pStk3, true); // interrupt !
|
pt->m_block->RestoreState(pStk3, true); // interrupt !
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CBotFunction::CheckParam(CBotDefParam* pParam)
|
bool CBotFunction::CheckParam(CBotDefParam* pParam)
|
||||||
{
|
{
|
||||||
CBotDefParam* pp = m_Param;
|
CBotDefParam* pp = m_param;
|
||||||
while ( pp != nullptr && pParam != nullptr )
|
while ( pp != nullptr && pParam != nullptr )
|
||||||
{
|
{
|
||||||
CBotTypResult type1 = pp->GetType();
|
CBotTypResult type1 = pp->GetType();
|
||||||
|
@ -857,10 +858,10 @@ std::string CBotFunction::GetName()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string CBotFunction::GetParams()
|
std::string CBotFunction::GetParams()
|
||||||
{
|
{
|
||||||
if ( m_Param == nullptr ) return std::string("()");
|
if (m_param == nullptr ) return std::string("()");
|
||||||
|
|
||||||
std::string params = "( ";
|
std::string params = "( ";
|
||||||
CBotDefParam* p = m_Param; // list of parameters
|
CBotDefParam* p = m_param; // list of parameters
|
||||||
|
|
||||||
while (p != nullptr)
|
while (p != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -885,4 +886,21 @@ void CBotFunction::AddPublic(CBotFunction* func)
|
||||||
m_publicFunctions.insert(func);
|
m_publicFunctions.insert(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotFunction::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
if (IsPublic()) ss << "public ";
|
||||||
|
if (IsExtern()) ss << "extern ";
|
||||||
|
ss << GetName() << GetParams();
|
||||||
|
//ss << "FuncID = " << m_nFuncIdent;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotFunction::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -241,15 +241,21 @@ public:
|
||||||
CBotGet modestart,
|
CBotGet modestart,
|
||||||
CBotGet modestop);
|
CBotGet modestop);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotFunction"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class CBotDebug;
|
||||||
long m_nFuncIdent;
|
long m_nFuncIdent;
|
||||||
//! Synchronized method.
|
//! Synchronized method.
|
||||||
bool m_bSynchro;
|
bool m_bSynchro;
|
||||||
|
|
||||||
//! Parameter list.
|
//! Parameter list.
|
||||||
CBotDefParam* m_Param;
|
CBotDefParam* m_param;
|
||||||
//! The instruction block.
|
//! The instruction block.
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
CBotFunction* m_next;
|
CBotFunction* m_next;
|
||||||
//! If returns CBotTypClass.
|
//! If returns CBotTypClass.
|
||||||
CBotToken m_retToken;
|
CBotToken m_retToken;
|
||||||
|
|
|
@ -32,9 +32,8 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotIString::CBotIString()
|
CBotIString::CBotIString()
|
||||||
{
|
{
|
||||||
m_var =
|
m_var = nullptr;
|
||||||
m_expr = nullptr;
|
m_expr = nullptr;
|
||||||
name = "CBotIString";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -157,4 +156,12 @@ void CBotIString::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
m_next2b->RestoreState(pile, bMain);
|
m_next2b->RestoreState(pile, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotIString::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_var"] = m_var;
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -65,6 +65,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotIString"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Variable to initialise.
|
//! Variable to initialise.
|
||||||
CBotInstr* m_var;
|
CBotInstr* m_var;
|
||||||
|
|
|
@ -30,18 +30,17 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotIf::CBotIf()
|
CBotIf::CBotIf()
|
||||||
{
|
{
|
||||||
m_Condition =
|
m_condition = nullptr;
|
||||||
m_Block =
|
m_block = nullptr;
|
||||||
m_BlockElse = nullptr; // nullptr so that delete is not possible further
|
m_blockElse = nullptr;
|
||||||
name = "CBotIf"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotIf::~CBotIf()
|
CBotIf::~CBotIf()
|
||||||
{
|
{
|
||||||
delete m_Condition; // frees the condition
|
delete m_condition; // frees the condition
|
||||||
delete m_Block; // frees the block of instruction1
|
delete m_block; // frees the block of instruction1
|
||||||
delete m_BlockElse; // frees the block of instruction2
|
delete m_blockElse; // frees the block of instruction2
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -56,11 +55,11 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
CBotIf* inst = new CBotIf(); // create the object
|
CBotIf* inst = new CBotIf(); // create the object
|
||||||
inst->SetToken( pp );
|
inst->SetToken( pp );
|
||||||
|
|
||||||
if ( nullptr != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
|
if ( nullptr != (inst->m_condition = CBotCondition::Compile(p, pStk )) )
|
||||||
{
|
{
|
||||||
// the condition does exist
|
// the condition does exist
|
||||||
|
|
||||||
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
|
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStk, true );
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
{
|
{
|
||||||
// the statement block is ok (can be empty)
|
// the statement block is ok (can be empty)
|
||||||
|
@ -69,7 +68,7 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
if (IsOfType(p, ID_ELSE))
|
if (IsOfType(p, ID_ELSE))
|
||||||
{
|
{
|
||||||
// if so, compiles the following statement block
|
// if so, compiles the following statement block
|
||||||
inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, true );
|
inst->m_blockElse = CBotBlock::CompileBlkOrInst(p, pStk, true );
|
||||||
if (!pStk->IsOk())
|
if (!pStk->IsOk())
|
||||||
{
|
{
|
||||||
// there is no correct block after the else
|
// there is no correct block after the else
|
||||||
|
@ -103,7 +102,7 @@ bool CBotIf :: Execute(CBotStack* &pj)
|
||||||
if( pile->GetState() == 0 )
|
if( pile->GetState() == 0 )
|
||||||
{
|
{
|
||||||
// evaluates the condition
|
// evaluates the condition
|
||||||
if ( !m_Condition->Execute(pile) ) return false; // interrupted here?
|
if ( !m_condition->Execute(pile) ) return false; // interrupted here?
|
||||||
|
|
||||||
// terminates if there is an error
|
// terminates if there is an error
|
||||||
if ( !pile->IsOk() )
|
if ( !pile->IsOk() )
|
||||||
|
@ -120,13 +119,13 @@ bool CBotIf :: Execute(CBotStack* &pj)
|
||||||
|
|
||||||
if ( pile->GetVal() == true ) // condition was true?
|
if ( pile->GetVal() == true ) // condition was true?
|
||||||
{
|
{
|
||||||
if ( m_Block != nullptr && // block may be absent
|
if (m_block != nullptr && // block may be absent
|
||||||
!m_Block->Execute(pile) ) return false; // interrupted here?
|
!m_block->Execute(pile) ) return false; // interrupted here?
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( m_BlockElse != nullptr && // if there is an alternate block
|
if (m_blockElse != nullptr && // if there is an alternate block
|
||||||
!m_BlockElse->Execute(pile) ) return false; // interrupted here
|
!m_blockElse->Execute(pile) ) return false; // interrupted here
|
||||||
}
|
}
|
||||||
|
|
||||||
// sends the results and releases the stack
|
// sends the results and releases the stack
|
||||||
|
@ -145,7 +144,7 @@ void CBotIf :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
if( pile->GetState() == 0 )
|
if( pile->GetState() == 0 )
|
||||||
{
|
{
|
||||||
// evaluates the condition
|
// evaluates the condition
|
||||||
m_Condition->RestoreState(pile, bMain); // interrupted here!
|
m_condition->RestoreState(pile, bMain); // interrupted here!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,14 +153,23 @@ void CBotIf :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
if ( pile->GetVal() == true ) // condition was true?
|
if ( pile->GetVal() == true ) // condition was true?
|
||||||
{
|
{
|
||||||
if ( m_Block != nullptr ) // block may be absent
|
if (m_block != nullptr ) // block may be absent
|
||||||
m_Block->RestoreState(pile, bMain); // interrupted here!
|
m_block->RestoreState(pile, bMain); // interrupted here!
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( m_BlockElse != nullptr ) // if there is an alternate block
|
if (m_blockElse != nullptr ) // if there is an alternate block
|
||||||
m_BlockElse->RestoreState(pile, bMain); // interrupted here!
|
m_blockElse->RestoreState(pile, bMain); // interrupted here!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotIf::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_condition"] = m_condition;
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
links["m_blockElse"] = m_blockElse;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -64,13 +64,17 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotIf"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Condition
|
//! Condition
|
||||||
CBotInstr* m_Condition;
|
CBotInstr* m_condition;
|
||||||
//! Instruction
|
//! Instruction
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
//! Instruction
|
//! Instruction
|
||||||
CBotInstr* m_BlockElse;
|
CBotInstr* m_blockElse;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -33,7 +33,6 @@ namespace CBot
|
||||||
CBotIndexExpr::CBotIndexExpr()
|
CBotIndexExpr::CBotIndexExpr()
|
||||||
{
|
{
|
||||||
m_expr = nullptr;
|
m_expr = nullptr;
|
||||||
name = "CBotIndexExpr";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -118,4 +117,11 @@ void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
|
||||||
m_next3->RestoreStateVar(pile, bMain);
|
m_next3->RestoreStateVar(pile, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotIndexExpr::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -70,6 +70,9 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotIndexExpr"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Expression for calculating the index.
|
//! Expression for calculating the index.
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include "CBot/CBotInstr/CBotInstArray.h"
|
#include "CBot/CBotInstr/CBotInstArray.h"
|
||||||
|
|
||||||
#include "CBot/CBotInstr/CBotLeftExprVar.h"
|
#include "CBot/CBotInstr/CBotLeftExprVar.h"
|
||||||
|
@ -37,9 +38,8 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotInstArray::CBotInstArray()
|
CBotInstArray::CBotInstArray()
|
||||||
{
|
{
|
||||||
m_var = nullptr;
|
m_var = nullptr;
|
||||||
m_listass = nullptr;
|
m_listass = nullptr;
|
||||||
name = "CBotInstArray";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -227,4 +227,19 @@ void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
if (m_next2b ) m_next2b->RestoreState( pile1, bMain);
|
if (m_next2b ) m_next2b->RestoreState( pile1, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotInstArray::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << m_typevar.ToString();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotInstArray::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_var"] = m_var;
|
||||||
|
links["m_listass"] = m_listass;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -67,8 +67,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotInstrArray"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
|
private:
|
||||||
//! The variables to initialize.
|
//! The variables to initialize.
|
||||||
CBotInstr* m_var;
|
CBotInstr* m_var;
|
||||||
//! List of assignments for array.
|
//! List of assignments for array.
|
||||||
|
|
|
@ -53,7 +53,6 @@ std::vector<std::string> CBotInstr::m_labelLvl = std::vector<std::string>();
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotInstr::CBotInstr()
|
CBotInstr::CBotInstr()
|
||||||
{
|
{
|
||||||
name = "CBotInstr";
|
|
||||||
m_next = nullptr;
|
m_next = nullptr;
|
||||||
m_next2b = nullptr;
|
m_next2b = nullptr;
|
||||||
m_next3 = nullptr;
|
m_next3 = nullptr;
|
||||||
|
@ -360,4 +359,14 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotInstr::GetDebugLinks()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{"m_next", m_next},
|
||||||
|
{"m_next2b", m_next2b},
|
||||||
|
{"m_next3", m_next3},
|
||||||
|
{"m_next3b", m_next3b}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
namespace CBot
|
namespace CBot
|
||||||
{
|
{
|
||||||
|
class CBotDebug;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for example, the following program
|
for example, the following program
|
||||||
|
@ -247,12 +248,16 @@ public:
|
||||||
*/
|
*/
|
||||||
static bool ChkLvl(const std::string& label, int type);
|
static bool ChkLvl(const std::string& label, int type);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class CBotDebug;
|
||||||
|
virtual const std::string GetDebugName() = 0;
|
||||||
|
virtual std::string GetDebugData() { return ""; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//! Keeps the token.
|
//! Keeps the token.
|
||||||
CBotToken m_token;
|
CBotToken m_token;
|
||||||
//! Debug.
|
|
||||||
std::string name;
|
|
||||||
//! Linked command.
|
//! Linked command.
|
||||||
CBotInstr* m_next;
|
CBotInstr* m_next;
|
||||||
//! Second list definition chain.
|
//! Second list definition chain.
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include "CBotInstrCall.h"
|
#include "CBotInstrCall.h"
|
||||||
#include "CBot/CBotInstr/CBotExpression.h"
|
#include "CBot/CBotInstr/CBotExpression.h"
|
||||||
|
|
||||||
|
@ -31,15 +32,14 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotInstrCall::CBotInstrCall()
|
CBotInstrCall::CBotInstrCall()
|
||||||
{
|
{
|
||||||
m_Parameters = nullptr;
|
m_parameters = nullptr;
|
||||||
m_nFuncIdent = 0;
|
m_nFuncIdent = 0;
|
||||||
name = "CBotInstrCall";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotInstrCall::~CBotInstrCall()
|
CBotInstrCall::~CBotInstrCall()
|
||||||
{
|
{
|
||||||
delete m_Parameters;
|
delete m_parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -69,8 +69,8 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
CBotInstr* param = CBotExpression::Compile(p, pile);
|
CBotInstr* param = CBotExpression::Compile(p, pile);
|
||||||
end = p->GetStart();
|
end = p->GetStart();
|
||||||
if ( inst->m_Parameters == nullptr ) inst->m_Parameters = param;
|
if (inst->m_parameters == nullptr ) inst->m_parameters = param;
|
||||||
else inst->m_Parameters->AddNext(param); // constructs the list
|
else inst->m_parameters->AddNext(param); // constructs the list
|
||||||
|
|
||||||
if ( !pile->IsOk() )
|
if ( !pile->IsOk() )
|
||||||
{
|
{
|
||||||
|
@ -140,7 +140,7 @@ bool CBotInstrCall::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluates parameters
|
// evaluates parameters
|
||||||
// and places the values on the stack
|
// and places the values on the stack
|
||||||
// for allow of interruption at any time
|
// for allow of interruption at any time
|
||||||
|
@ -178,7 +178,7 @@ void CBotInstrCall::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
CBotVar* ppVars[1000];
|
CBotVar* ppVars[1000];
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluate parameters
|
// evaluate parameters
|
||||||
// and place the values on the stack
|
// and place the values on the stack
|
||||||
// for allow of interruption at any time
|
// for allow of interruption at any time
|
||||||
|
@ -203,4 +203,20 @@ void CBotInstrCall::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
pile2->RestoreCall(m_nFuncIdent, GetToken(), ppVars);
|
pile2->RestoreCall(m_nFuncIdent, GetToken(), ppVars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotInstrCall::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << m_token.GetString() << std::endl;
|
||||||
|
//ss << "FuncID = " << m_nFuncIdent << std::endl;
|
||||||
|
ss << "resultType = " << m_typRes.ToString();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotInstrCall::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_parameters"] = m_parameters;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -63,13 +63,19 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotInstrCall"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! The parameters to be evaluated.
|
//! The parameters to be evaluated.
|
||||||
CBotInstr* m_Parameters;
|
CBotInstr* m_parameters;
|
||||||
//! Complete type of the result.
|
//! Complete type of the result.
|
||||||
CBotTypResult m_typRes;
|
CBotTypResult m_typRes;
|
||||||
//! Id of a function.
|
//! Id of a function.
|
||||||
long m_nFuncIdent;
|
long m_nFuncIdent;
|
||||||
|
friend class CBotDebug;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include "CBot/CBotInstr/CBotInstrMethode.h"
|
#include "CBot/CBotInstr/CBotInstrMethode.h"
|
||||||
|
|
||||||
#include "CBot/CBotInstr/CBotInstrUtils.h"
|
#include "CBot/CBotInstr/CBotInstrUtils.h"
|
||||||
|
@ -33,15 +34,14 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotInstrMethode::CBotInstrMethode()
|
CBotInstrMethode::CBotInstrMethode()
|
||||||
{
|
{
|
||||||
m_Parameters = nullptr;
|
m_parameters = nullptr;
|
||||||
m_MethodeIdent = 0;
|
m_MethodeIdent = 0;
|
||||||
name = "CBotInstrMethode";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotInstrMethode::~CBotInstrMethode()
|
CBotInstrMethode::~CBotInstrMethode()
|
||||||
{
|
{
|
||||||
delete m_Parameters;
|
delete m_parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -57,17 +57,17 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
|
||||||
|
|
||||||
if (p->GetType() == ID_OPENPAR)
|
if (p->GetType() == ID_OPENPAR)
|
||||||
{
|
{
|
||||||
inst->m_NomMethod = pp->GetString();
|
inst->m_methodName = pp->GetString();
|
||||||
|
|
||||||
// compiles the list of parameters
|
// compiles the list of parameters
|
||||||
CBotVar* ppVars[1000];
|
CBotVar* ppVars[1000];
|
||||||
inst->m_Parameters = CompileParams(p, pStack, ppVars);
|
inst->m_parameters = CompileParams(p, pStack, ppVars);
|
||||||
|
|
||||||
if (pStack->IsOk())
|
if (pStack->IsOk())
|
||||||
{
|
{
|
||||||
CBotClass* pClass = var->GetClass(); // pointer to the class
|
CBotClass* pClass = var->GetClass(); // pointer to the class
|
||||||
inst->m_ClassName = pClass->GetName(); // name of the class
|
inst->m_className = pClass->GetName(); // name of the class
|
||||||
CBotTypResult r = pClass->CompileMethode(inst->m_NomMethod, var, ppVars,
|
CBotTypResult r = pClass->CompileMethode(inst->m_methodName, var, ppVars,
|
||||||
pStack, inst->m_MethodeIdent);
|
pStack, inst->m_MethodeIdent);
|
||||||
delete pStack->TokenStack(); // release parameters on the stack
|
delete pStack->TokenStack(); // release parameters on the stack
|
||||||
inst->m_typRes = r;
|
inst->m_typRes = r;
|
||||||
|
@ -129,7 +129,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluate the parameters
|
// evaluate the parameters
|
||||||
// and places the values on the stack
|
// and places the values on the stack
|
||||||
// to be interrupted at any time
|
// to be interrupted at any time
|
||||||
|
@ -148,7 +148,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre
|
||||||
}
|
}
|
||||||
ppVars[i] = nullptr;
|
ppVars[i] = nullptr;
|
||||||
|
|
||||||
CBotClass* pClass = CBotClass::Find(m_ClassName);
|
CBotClass* pClass = CBotClass::Find(m_className);
|
||||||
CBotVar* pThis = pile1->FindVar(-2, false);
|
CBotVar* pThis = pile1->FindVar(-2, false);
|
||||||
CBotVar* pResult = nullptr;
|
CBotVar* pResult = nullptr;
|
||||||
if (m_typRes.GetType() > 0) pResult = CBotVar::Create("", m_typRes);
|
if (m_typRes.GetType() > 0) pResult = CBotVar::Create("", m_typRes);
|
||||||
|
@ -158,7 +158,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre
|
||||||
}
|
}
|
||||||
CBotVar* pRes = pResult;
|
CBotVar* pRes = pResult;
|
||||||
|
|
||||||
if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod,
|
if ( !pClass->ExecuteMethode(m_MethodeIdent, m_methodName,
|
||||||
pThis, ppVars,
|
pThis, ppVars,
|
||||||
pResult, pile2, GetToken())) return false;
|
pResult, pile2, GetToken())) return false;
|
||||||
if (pRes != pResult) delete pRes;
|
if (pRes != pResult) delete pRes;
|
||||||
|
@ -184,7 +184,7 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluate the parameters
|
// evaluate the parameters
|
||||||
// and places the values on the stack
|
// and places the values on the stack
|
||||||
// to be interrupted at any time
|
// to be interrupted at any time
|
||||||
|
@ -205,13 +205,13 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
|
||||||
}
|
}
|
||||||
ppVars[i] = nullptr;
|
ppVars[i] = nullptr;
|
||||||
|
|
||||||
CBotClass* pClass = CBotClass::Find(m_ClassName);
|
CBotClass* pClass = CBotClass::Find(m_className);
|
||||||
// CBotVar* pResult = nullptr;
|
// CBotVar* pResult = nullptr;
|
||||||
|
|
||||||
// CBotVar* pRes = pResult;
|
// CBotVar* pRes = pResult;
|
||||||
|
|
||||||
pClass->RestoreMethode(m_MethodeIdent, m_NomMethod,
|
pClass->RestoreMethode(m_MethodeIdent, m_methodName,
|
||||||
pThis, ppVars, pile2);
|
pThis, ppVars, pile2);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -236,7 +236,7 @@ bool CBotInstrMethode::Execute(CBotStack* &pj)
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluate the parameters
|
// evaluate the parameters
|
||||||
// and places the values on the stack
|
// and places the values on the stack
|
||||||
// to be interrupted at any time
|
// to be interrupted at any time
|
||||||
|
@ -254,7 +254,7 @@ bool CBotInstrMethode::Execute(CBotStack* &pj)
|
||||||
}
|
}
|
||||||
ppVars[i] = nullptr;
|
ppVars[i] = nullptr;
|
||||||
|
|
||||||
CBotClass* pClass = CBotClass::Find(m_ClassName);
|
CBotClass* pClass = CBotClass::Find(m_className);
|
||||||
CBotVar* pThis = pile1->FindVar("this");
|
CBotVar* pThis = pile1->FindVar("this");
|
||||||
CBotVar* pResult = nullptr;
|
CBotVar* pResult = nullptr;
|
||||||
if (m_typRes.GetType()>0) pResult = CBotVar::Create("", m_typRes);
|
if (m_typRes.GetType()>0) pResult = CBotVar::Create("", m_typRes);
|
||||||
|
@ -264,7 +264,7 @@ bool CBotInstrMethode::Execute(CBotStack* &pj)
|
||||||
}
|
}
|
||||||
CBotVar* pRes = pResult;
|
CBotVar* pRes = pResult;
|
||||||
|
|
||||||
if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod,
|
if ( !pClass->ExecuteMethode(m_MethodeIdent, m_methodName,
|
||||||
pThis, ppVars,
|
pThis, ppVars,
|
||||||
pResult, pile2, GetToken())) return false; // interupted
|
pResult, pile2, GetToken())) return false; // interupted
|
||||||
|
|
||||||
|
@ -277,4 +277,20 @@ bool CBotInstrMethode::Execute(CBotStack* &pj)
|
||||||
return pj->Return(pile2); // release the entire stack
|
return pj->Return(pile2); // release the entire stack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotInstrMethode::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << m_methodName << std::endl;
|
||||||
|
ss << "MethodID = " << m_MethodeIdent << std::endl;
|
||||||
|
ss << "result = " << m_typRes.GetType(); // TODO: Type to string?
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotInstrMethode::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_parameters"] = m_parameters;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -75,17 +75,22 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotInstrMethode"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! The parameters to be evaluated.
|
//! The parameters to be evaluated.
|
||||||
CBotInstr *m_Parameters;
|
CBotInstr* m_parameters;
|
||||||
//! Complete type of the result.
|
//! Complete type of the result.
|
||||||
CBotTypResult m_typRes;
|
CBotTypResult m_typRes;
|
||||||
//! Name of the method.
|
//! Name of the method.
|
||||||
std::string m_NomMethod;
|
std::string m_methodName;
|
||||||
//! Identifier of the method.
|
//! Identifier of the method.
|
||||||
long m_MethodeIdent;
|
long m_MethodeIdent;
|
||||||
//! Name of the class.
|
//! Name of the class.
|
||||||
std::string m_ClassName;
|
std::string m_className;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -35,9 +35,8 @@ namespace CBot
|
||||||
CBotInt::CBotInt()
|
CBotInt::CBotInt()
|
||||||
{
|
{
|
||||||
m_next = nullptr; // for multiple definitions
|
m_next = nullptr; // for multiple definitions
|
||||||
m_var =
|
m_var = nullptr;
|
||||||
m_expr = nullptr;
|
m_expr = nullptr;
|
||||||
name = "CBotInt";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -186,4 +185,12 @@ void CBotInt::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
if (m_next2b) m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
|
if (m_next2b) m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotInt::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_var"] = m_var;
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -66,8 +66,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotInt"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
|
private:
|
||||||
//! The variable to initialize.
|
//! The variable to initialize.
|
||||||
CBotInstr* m_var;
|
CBotInstr* m_var;
|
||||||
//! A value to put, if there is.
|
//! A value to put, if there is.
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include "CBot/CBotInstr/CBotLeftExpr.h"
|
#include "CBot/CBotInstr/CBotLeftExpr.h"
|
||||||
#include "CBot/CBotInstr/CBotFieldExpr.h"
|
#include "CBot/CBotInstr/CBotFieldExpr.h"
|
||||||
#include "CBot/CBotInstr/CBotIndexExpr.h"
|
#include "CBot/CBotInstr/CBotIndexExpr.h"
|
||||||
|
@ -34,7 +35,6 @@ namespace CBot
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotLeftExpr::CBotLeftExpr()
|
CBotLeftExpr::CBotLeftExpr()
|
||||||
{
|
{
|
||||||
name = "CBotLeftExpr";
|
|
||||||
m_nIdent = 0;
|
m_nIdent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,4 +241,12 @@ void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
|
||||||
m_next3->RestoreStateVar(pile, bMain);
|
m_next3->RestoreStateVar(pile, bMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotLeftExpr::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << m_token.GetString();
|
||||||
|
//ss << "VarID = " << m_nIdent;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -93,6 +93,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreStateVar(CBotStack* &pile, bool bMain) override;
|
void RestoreStateVar(CBotStack* &pile, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotLeftExpr"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long m_nIdent;
|
long m_nIdent;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
#include "CBot/CBotVar/CBotVar.h"
|
#include "CBot/CBotVar/CBotVar.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace CBot
|
namespace CBot
|
||||||
{
|
{
|
||||||
|
|
||||||
CBotLeftExprVar::CBotLeftExprVar()
|
CBotLeftExprVar::CBotLeftExprVar()
|
||||||
{
|
{
|
||||||
name = "CBotLeftExprVar";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotLeftExprVar::~CBotLeftExprVar()
|
CBotLeftExprVar::~CBotLeftExprVar()
|
||||||
|
@ -80,4 +80,13 @@ void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
var1->SetUniqNum(m_nIdent); // Restore the identifier
|
var1->SetUniqNum(m_nIdent); // Restore the identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotLeftExprVar::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << m_token.GetString() << std::endl;
|
||||||
|
//ss << "VarID = " << m_nIdent << std::endl;
|
||||||
|
ss << "type = " << m_typevar.ToString();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -50,8 +50,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
public:
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotLeftExprVar"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
|
||||||
|
public:
|
||||||
//! Type of variable declared.
|
//! Type of variable declared.
|
||||||
CBotTypResult m_typevar = -1;
|
CBotTypResult m_typevar = -1;
|
||||||
//! Unique identifier of that variable
|
//! Unique identifier of that variable
|
||||||
|
|
|
@ -35,8 +35,7 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotListArray::CBotListArray()
|
CBotListArray::CBotListArray()
|
||||||
{
|
{
|
||||||
m_expr = nullptr;
|
m_expr = nullptr;
|
||||||
name = "CBotListArray";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -179,4 +178,11 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotListArray::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -67,6 +67,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotListArray"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! An expression for an element others are linked with CBotInstr :: m_next3;
|
//! An expression for an element others are linked with CBotInstr :: m_next3;
|
||||||
CBotInstr* m_expr;
|
CBotInstr* m_expr;
|
||||||
|
|
|
@ -48,14 +48,13 @@ static CBotInstr* CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotListExpression::CBotListExpression()
|
CBotListExpression::CBotListExpression()
|
||||||
{
|
{
|
||||||
m_Expr = nullptr;
|
m_expr = nullptr;
|
||||||
name = "CBotListExpression";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotListExpression::~CBotListExpression()
|
CBotListExpression::~CBotListExpression()
|
||||||
{
|
{
|
||||||
delete m_Expr;
|
delete m_expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -63,13 +62,13 @@ CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
{
|
{
|
||||||
CBotListExpression* inst = new CBotListExpression();
|
CBotListExpression* inst = new CBotListExpression();
|
||||||
|
|
||||||
inst->m_Expr = CompileInstrOrDefVar( p, pStack ); // compile the first expression in a list
|
inst->m_expr = CompileInstrOrDefVar(p, pStack ); // compile the first expression in a list
|
||||||
if (pStack->IsOk())
|
if (pStack->IsOk())
|
||||||
{
|
{
|
||||||
while ( IsOfType(p, ID_COMMA) ) // more instructions?
|
while ( IsOfType(p, ID_COMMA) ) // more instructions?
|
||||||
{
|
{
|
||||||
CBotInstr* i = CompileInstrOrDefVar( p, pStack ); // Is this a declaration of an integer?
|
CBotInstr* i = CompileInstrOrDefVar( p, pStack ); // Is this a declaration of an integer?
|
||||||
inst->m_Expr->AddNext(i); // added after
|
inst->m_expr->AddNext(i); // added after
|
||||||
if ( !pStack->IsOk() )
|
if ( !pStack->IsOk() )
|
||||||
{
|
{
|
||||||
delete inst;
|
delete inst;
|
||||||
|
@ -86,7 +85,7 @@ CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
bool CBotListExpression::Execute(CBotStack* &pj)
|
bool CBotListExpression::Execute(CBotStack* &pj)
|
||||||
{
|
{
|
||||||
CBotStack* pile = pj->AddStack(); // essential
|
CBotStack* pile = pj->AddStack(); // essential
|
||||||
CBotInstr* p = m_Expr; // the first expression
|
CBotInstr* p = m_expr; // the first expression
|
||||||
|
|
||||||
int state = pile->GetState();
|
int state = pile->GetState();
|
||||||
while (state-->0) p = p->GetNext(); // returns to the interrupted operation
|
while (state-->0) p = p->GetNext(); // returns to the interrupted operation
|
||||||
|
@ -114,7 +113,7 @@ void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
state = pile->GetState();
|
state = pile->GetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotInstr* p = m_Expr; // the first expression
|
CBotInstr* p = m_expr; // the first expression
|
||||||
|
|
||||||
while (p != nullptr && state-->0)
|
while (p != nullptr && state-->0)
|
||||||
{
|
{
|
||||||
|
@ -128,4 +127,11 @@ void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotListExpression::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_expr"] = m_expr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -64,9 +64,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotListExpression"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! The first expression to be evaluated
|
//! The first expression to be evaluated
|
||||||
CBotInstr* m_Expr;
|
CBotInstr* m_expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -29,14 +29,13 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotListInstr::CBotListInstr()
|
CBotListInstr::CBotListInstr()
|
||||||
{
|
{
|
||||||
m_Instr = nullptr;
|
m_instr = nullptr;
|
||||||
name = "CBotListInstr";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotListInstr::~CBotListInstr()
|
CBotListInstr::~CBotListInstr()
|
||||||
{
|
{
|
||||||
delete m_Instr;
|
delete m_instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -68,8 +67,8 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal
|
||||||
return pStack->Return(nullptr, pStk);
|
return pStack->Return(nullptr, pStk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inst->m_Instr == nullptr) inst->m_Instr = i;
|
if (inst->m_instr == nullptr) inst->m_instr = i;
|
||||||
else inst->m_Instr->AddNext(i); // added a result
|
else inst->m_instr->AddNext(i); // added a result
|
||||||
}
|
}
|
||||||
return pStack->Return(inst, pStk);
|
return pStack->Return(inst, pStk);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +81,7 @@ bool CBotListInstr::Execute(CBotStack* &pj)
|
||||||
if (pile->StackOver() ) return pj->Return( pile);
|
if (pile->StackOver() ) return pj->Return( pile);
|
||||||
|
|
||||||
|
|
||||||
CBotInstr* p = m_Instr; // the first expression
|
CBotInstr* p = m_instr; // the first expression
|
||||||
|
|
||||||
int state = pile->GetState();
|
int state = pile->GetState();
|
||||||
while (state-->0) p = p->GetNext(); // returns to the interrupted operation
|
while (state-->0) p = p->GetNext(); // returns to the interrupted operation
|
||||||
|
@ -106,7 +105,7 @@ void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
CBotStack* pile = pj->RestoreStack(this);
|
CBotStack* pile = pj->RestoreStack(this);
|
||||||
if (pile == nullptr) return;
|
if (pile == nullptr) return;
|
||||||
|
|
||||||
CBotInstr* p = m_Instr; // the first expression
|
CBotInstr* p = m_instr; // the first expression
|
||||||
|
|
||||||
int state = pile->GetState();
|
int state = pile->GetState();
|
||||||
while ( p != nullptr && state-- > 0)
|
while ( p != nullptr && state-- > 0)
|
||||||
|
@ -118,4 +117,11 @@ void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
if (p != nullptr) p->RestoreState(pile, true);
|
if (p != nullptr) p->RestoreState(pile, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotListInstr::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_instr"] = m_instr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -65,9 +65,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotListInstr"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Instructions to do.
|
//! Instructions to do.
|
||||||
CBotInstr* m_Instr;
|
CBotInstr* m_instr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -27,10 +27,9 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotLogicExpr::CBotLogicExpr()
|
CBotLogicExpr::CBotLogicExpr()
|
||||||
{
|
{
|
||||||
m_condition =
|
m_condition = nullptr;
|
||||||
m_op1 =
|
m_op1 = nullptr;
|
||||||
m_op2 = nullptr; // nullptr to be able to delete without other
|
m_op2 = nullptr;
|
||||||
name = "CBotLogicExpr"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -90,4 +89,13 @@ void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotLogicExpr::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_op1"] = m_op1;
|
||||||
|
links["m_condition"] = m_condition;
|
||||||
|
links["m_op2"] = m_op2;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -55,8 +55,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotLogicExpr"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
|
private:
|
||||||
//! Test to evaluate
|
//! Test to evaluate
|
||||||
CBotInstr* m_condition;
|
CBotInstr* m_condition;
|
||||||
//! Left element
|
//! Left element
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include "CBot/CBotInstr/CBotNew.h"
|
#include "CBot/CBotInstr/CBotNew.h"
|
||||||
|
|
||||||
#include "CBot/CBotStack.h"
|
#include "CBot/CBotStack.h"
|
||||||
|
@ -33,8 +34,7 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotNew::CBotNew()
|
CBotNew::CBotNew()
|
||||||
{
|
{
|
||||||
name = "CBotNew";
|
m_parameters = nullptr;
|
||||||
m_Parameters = nullptr;
|
|
||||||
m_nMethodeIdent = 0;
|
m_nMethodeIdent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
{
|
{
|
||||||
// check if there are parameters
|
// check if there are parameters
|
||||||
CBotVar* ppVars[1000];
|
CBotVar* ppVars[1000];
|
||||||
inst->m_Parameters = CompileParams(p, pStk, ppVars);
|
inst->m_parameters = CompileParams(p, pStk, ppVars);
|
||||||
if (!pStk->IsOk()) goto error;
|
if (!pStk->IsOk()) goto error;
|
||||||
|
|
||||||
// constructor exist?
|
// constructor exist?
|
||||||
|
@ -83,7 +83,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
int typ = r.GetType();
|
int typ = r.GetType();
|
||||||
|
|
||||||
// if there is no constructor, and no parameters either, it's ok
|
// if there is no constructor, and no parameters either, it's ok
|
||||||
if (typ == CBotErrUndefCall && inst->m_Parameters == nullptr) typ = 0;
|
if (typ == CBotErrUndefCall && inst->m_parameters == nullptr) typ = 0;
|
||||||
pVar->SetInit(CBotVar::InitType::DEF); // mark the instance as init
|
pVar->SetInit(CBotVar::InitType::DEF); // mark the instance as init
|
||||||
|
|
||||||
if (typ>20)
|
if (typ>20)
|
||||||
|
@ -93,7 +93,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the constructor does not exist, but there are parameters
|
// if the constructor does not exist, but there are parameters
|
||||||
if (typ<0 && inst->m_Parameters != nullptr)
|
if (typ<0 && inst->m_parameters != nullptr)
|
||||||
{
|
{
|
||||||
pStk->SetError(CBotErrNoConstruct, &inst->m_vartoken);
|
pStk->SetError(CBotErrNoConstruct, &inst->m_vartoken);
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -153,7 +153,7 @@ bool CBotNew::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluate the parameters
|
// evaluate the parameters
|
||||||
// and places the values on the stack
|
// and places the values on the stack
|
||||||
// to be interrupted at any time
|
// to be interrupted at any time
|
||||||
|
@ -218,7 +218,7 @@ void CBotNew::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CBotInstr* p = m_Parameters;
|
CBotInstr* p = m_parameters;
|
||||||
// evaluate the parameters
|
// evaluate the parameters
|
||||||
// and places the values on the stack
|
// and places the values on the stack
|
||||||
// to be interrupted at any time
|
// to be interrupted at any time
|
||||||
|
@ -244,4 +244,18 @@ void CBotNew::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotNew::GetDebugData()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "ConstructorID = " << m_nMethodeIdent;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotNew::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_parameters"] = m_parameters;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -63,9 +63,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotNew"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! The parameters to be evaluated
|
//! The parameters to be evaluated
|
||||||
CBotInstr* m_Parameters;
|
CBotInstr* m_parameters;
|
||||||
long m_nMethodeIdent;
|
long m_nMethodeIdent;
|
||||||
CBotToken m_vartoken;
|
CBotToken m_vartoken;
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
CBotPostIncExpr* i = new CBotPostIncExpr();
|
CBotPostIncExpr* i = new CBotPostIncExpr();
|
||||||
i->SetToken(pp);
|
i->SetToken(pp);
|
||||||
i->m_Instr = inst; // associated statement
|
i->m_instr = inst; // associated statement
|
||||||
return pStack->Return(i, pStk);
|
return pStack->Return(i, pStk);
|
||||||
}
|
}
|
||||||
return pStack->Return(inst, pStk);
|
return pStack->Return(inst, pStk);
|
||||||
|
@ -119,7 +119,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
if (p->GetType() == TokenTypVar)
|
if (p->GetType() == TokenTypVar)
|
||||||
{
|
{
|
||||||
if (nullptr != (i->m_Instr = CBotExprVar::Compile(p, pStk, CBotVar::ProtectionLevel::ReadOnly)))
|
if (nullptr != (i->m_instr = CBotExprVar::Compile(p, pStk, CBotVar::ProtectionLevel::ReadOnly)))
|
||||||
{
|
{
|
||||||
if (pStk->GetType() >= CBotTypBoolean)
|
if (pStk->GetType() >= CBotTypBoolean)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,14 +30,13 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotPostIncExpr::CBotPostIncExpr()
|
CBotPostIncExpr::CBotPostIncExpr()
|
||||||
{
|
{
|
||||||
m_Instr = nullptr;
|
m_instr = nullptr;
|
||||||
name = "CBotPostIncExpr";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotPostIncExpr::~CBotPostIncExpr()
|
CBotPostIncExpr::~CBotPostIncExpr()
|
||||||
{
|
{
|
||||||
delete m_Instr;
|
delete m_instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -49,7 +48,7 @@ bool CBotPostIncExpr::Execute(CBotStack* &pj)
|
||||||
CBotVar* var1 = nullptr;
|
CBotVar* var1 = nullptr;
|
||||||
|
|
||||||
// retrieves the variable fields and indexes according
|
// retrieves the variable fields and indexes according
|
||||||
if (!(static_cast<CBotExprVar*>(m_Instr))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
if (!(static_cast<CBotExprVar*>(m_instr))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
||||||
|
|
||||||
pile1->SetState(1);
|
pile1->SetState(1);
|
||||||
pile1->SetCopyVar(var1); // places the result (before incrementation);
|
pile1->SetCopyVar(var1); // places the result (before incrementation);
|
||||||
|
@ -81,9 +80,16 @@ void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
CBotStack* pile1 = pj->RestoreStack(this);
|
CBotStack* pile1 = pj->RestoreStack(this);
|
||||||
if (pile1 == nullptr) return;
|
if (pile1 == nullptr) return;
|
||||||
|
|
||||||
(static_cast<CBotExprVar*>(m_Instr))->RestoreStateVar(pile1, bMain);
|
(static_cast<CBotExprVar*>(m_instr))->RestoreStateVar(pile1, bMain);
|
||||||
|
|
||||||
if (pile1 != nullptr) pile1->RestoreStack(this);
|
if (pile1 != nullptr) pile1->RestoreStack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotPostIncExpr::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_instr"] = m_instr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -61,8 +61,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotPostIncExpr"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CBotInstr* m_Instr;
|
CBotInstr* m_instr;
|
||||||
friend class CBotParExpr;
|
friend class CBotParExpr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,13 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotPreIncExpr::CBotPreIncExpr()
|
CBotPreIncExpr::CBotPreIncExpr()
|
||||||
{
|
{
|
||||||
m_Instr = nullptr;
|
m_instr = nullptr;
|
||||||
name = "CBotPreIncExpr";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotPreIncExpr::~CBotPreIncExpr()
|
CBotPreIncExpr::~CBotPreIncExpr()
|
||||||
{
|
{
|
||||||
delete m_Instr;
|
delete m_instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -54,7 +53,7 @@ bool CBotPreIncExpr::Execute(CBotStack* &pj)
|
||||||
CBotStack* pile2 = pile;
|
CBotStack* pile2 = pile;
|
||||||
// retrieves the variable fields and indexes according
|
// retrieves the variable fields and indexes according
|
||||||
// pile2 is modified on return
|
// pile2 is modified on return
|
||||||
if (!(static_cast<CBotExprVar*>(m_Instr))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
if (!(static_cast<CBotExprVar*>(m_instr))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
||||||
|
|
||||||
if (var1->IsNAN())
|
if (var1->IsNAN())
|
||||||
{
|
{
|
||||||
|
@ -74,7 +73,7 @@ bool CBotPreIncExpr::Execute(CBotStack* &pj)
|
||||||
pile->IncState();
|
pile->IncState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_Instr->Execute(pile)) return false;
|
if (!m_instr->Execute(pile)) return false;
|
||||||
return pj->Return(pile); // operation performed
|
return pj->Return(pile); // operation performed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +90,14 @@ void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Instr->RestoreState(pile, bMain);
|
m_instr->RestoreState(pile, bMain);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotPreIncExpr::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_instr"] = m_instr;
|
||||||
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -56,8 +56,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotPreIncExpr"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CBotInstr* m_Instr;
|
CBotInstr* m_instr;
|
||||||
friend class CBotParExpr;
|
friend class CBotParExpr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,13 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotReturn::CBotReturn()
|
CBotReturn::CBotReturn()
|
||||||
{
|
{
|
||||||
m_Instr = nullptr;
|
m_instr = nullptr;
|
||||||
name = "CBotReturn"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotReturn::~CBotReturn()
|
CBotReturn::~CBotReturn()
|
||||||
{
|
{
|
||||||
delete m_Instr;
|
delete m_instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -61,7 +60,7 @@ CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inst->m_Instr = CBotExpression::Compile(p, pStack);
|
inst->m_instr = CBotExpression::Compile(p, pStack);
|
||||||
if ( pStack->IsOk() )
|
if ( pStack->IsOk() )
|
||||||
{
|
{
|
||||||
CBotTypResult retType = pStack->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
|
CBotTypResult retType = pStack->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
|
||||||
|
@ -87,7 +86,7 @@ bool CBotReturn::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
if ( pile->GetState() == 0 )
|
if ( pile->GetState() == 0 )
|
||||||
{
|
{
|
||||||
if ( m_Instr != nullptr && !m_Instr->Execute(pile) ) return false; // evaluate the result
|
if (m_instr != nullptr && !m_instr->Execute(pile) ) return false; // evaluate the result
|
||||||
// the result is on the stack
|
// the result is on the stack
|
||||||
pile->IncState();
|
pile->IncState();
|
||||||
}
|
}
|
||||||
|
@ -107,9 +106,16 @@ void CBotReturn::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
if ( pile->GetState() == 0 )
|
if ( pile->GetState() == 0 )
|
||||||
{
|
{
|
||||||
if ( m_Instr != nullptr ) m_Instr->RestoreState(pile, bMain); // evaluate the result
|
if (m_instr != nullptr ) m_instr->RestoreState(pile, bMain); // evaluate the result
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotReturn::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_instr"] = m_instr;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -63,9 +63,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotReturn"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Parameter of return
|
//! Parameter of return
|
||||||
CBotInstr *m_Instr;
|
CBotInstr* m_instr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,16 +31,15 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotSwitch::CBotSwitch()
|
CBotSwitch::CBotSwitch()
|
||||||
{
|
{
|
||||||
m_Value =
|
m_value = nullptr;
|
||||||
m_Block = nullptr; // nullptr so that delete is not possible further
|
m_block = nullptr;
|
||||||
name = "CBotSwitch"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotSwitch::~CBotSwitch()
|
CBotSwitch::~CBotSwitch()
|
||||||
{
|
{
|
||||||
delete m_Value; // frees the value
|
delete m_value; // frees the value
|
||||||
delete m_Block; // frees the instruction block
|
delete m_block; // frees the instruction block
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -56,7 +55,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
if ( IsOfType(p, ID_OPENPAR ) )
|
if ( IsOfType(p, ID_OPENPAR ) )
|
||||||
{
|
{
|
||||||
if ( nullptr != (inst->m_Value = CBotExpression::Compile( p, pStk )) )
|
if ( nullptr != (inst->m_value = CBotExpression::Compile(p, pStk )) )
|
||||||
{
|
{
|
||||||
if ( pStk->GetType() < CBotTypLong )
|
if ( pStk->GetType() < CBotTypLong )
|
||||||
{
|
{
|
||||||
|
@ -79,12 +78,12 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
return pStack->Return(nullptr, pStk2);
|
return pStack->Return(nullptr, pStk2);
|
||||||
}
|
}
|
||||||
delete pStk2;
|
delete pStk2;
|
||||||
if ( inst->m_Block == nullptr ) inst->m_Block = i;
|
if (inst->m_block == nullptr ) inst->m_block = i;
|
||||||
else inst->m_Block->AddNext(i);
|
else inst->m_block->AddNext(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( inst->m_Block == nullptr )
|
if (inst->m_block == nullptr )
|
||||||
{
|
{
|
||||||
pStk->SetError(CBotErrNoCase, p->GetStart());
|
pStk->SetError(CBotErrNoCase, p->GetStart());
|
||||||
delete inst;
|
delete inst;
|
||||||
|
@ -97,7 +96,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
delete inst;
|
delete inst;
|
||||||
return pStack->Return(nullptr, pStk);
|
return pStack->Return(nullptr, pStk);
|
||||||
}
|
}
|
||||||
inst->m_Block->AddNext(i);
|
inst->m_block->AddNext(i);
|
||||||
|
|
||||||
if ( p == nullptr )
|
if ( p == nullptr )
|
||||||
{
|
{
|
||||||
|
@ -108,7 +107,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
}
|
}
|
||||||
DecLvl();
|
DecLvl();
|
||||||
|
|
||||||
if ( inst->m_Block == nullptr )
|
if (inst->m_block == nullptr )
|
||||||
{
|
{
|
||||||
pStk->SetError(CBotErrNoCase, p->GetStart());
|
pStk->SetError(CBotErrNoCase, p->GetStart());
|
||||||
delete inst;
|
delete inst;
|
||||||
|
@ -136,12 +135,12 @@ bool CBotSwitch :: Execute(CBotStack* &pj)
|
||||||
CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack
|
CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack
|
||||||
// if ( pile1 == EOX ) return true;
|
// if ( pile1 == EOX ) return true;
|
||||||
|
|
||||||
CBotInstr* p = m_Block; // first expression
|
CBotInstr* p = m_block; // first expression
|
||||||
|
|
||||||
int state = pile1->GetState();
|
int state = pile1->GetState();
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
{
|
{
|
||||||
if ( !m_Value->Execute(pile1) ) return false;
|
if ( !m_value->Execute(pile1) ) return false;
|
||||||
pile1->SetState(state = -1);
|
pile1->SetState(state = -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +165,7 @@ bool CBotSwitch :: Execute(CBotStack* &pj)
|
||||||
if ( !pile1->SetState(state) ) return false;
|
if ( !pile1->SetState(state) ) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = m_Block; // returns to the beginning
|
p = m_block; // returns to the beginning
|
||||||
while (state-->0) p = p->GetNext(); // advance in the list
|
while (state-->0) p = p->GetNext(); // advance in the list
|
||||||
|
|
||||||
while( p != nullptr )
|
while( p != nullptr )
|
||||||
|
@ -186,12 +185,12 @@ void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack
|
CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack
|
||||||
if ( pile1 == nullptr ) return;
|
if ( pile1 == nullptr ) return;
|
||||||
|
|
||||||
CBotInstr* p = m_Block; // first expression
|
CBotInstr* p = m_block; // first expression
|
||||||
|
|
||||||
int state = pile1->GetState();
|
int state = pile1->GetState();
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
{
|
{
|
||||||
m_Value->RestoreState(pile1, bMain);
|
m_value->RestoreState(pile1, bMain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +199,7 @@ void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// p = m_Block; // returns to the beginning
|
// p = m_block; // returns to the beginning
|
||||||
while ( p != nullptr && state-- > 0 )
|
while ( p != nullptr && state-- > 0 )
|
||||||
{
|
{
|
||||||
p->RestoreState(pile1, false);
|
p->RestoreState(pile1, false);
|
||||||
|
@ -214,4 +213,12 @@ void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotSwitch::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_value"] = m_value;
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -63,13 +63,15 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotSwitch"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! Value to seek
|
//! Value to seek
|
||||||
CBotInstr* m_Value;
|
CBotInstr* m_value;
|
||||||
//! Instructions
|
//! Instructions
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -29,15 +29,13 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotThrow::CBotThrow()
|
CBotThrow::CBotThrow()
|
||||||
{
|
{
|
||||||
m_Value = nullptr; // nullptr so that delete is not possible further
|
m_value = nullptr;
|
||||||
|
|
||||||
name = "CBotThrow"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotThrow::~CBotThrow()
|
CBotThrow::~CBotThrow()
|
||||||
{
|
{
|
||||||
delete m_Value;
|
delete m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -52,7 +50,7 @@ CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
if (!IsOfType(p, ID_THROW)) return nullptr; // should never happen
|
if (!IsOfType(p, ID_THROW)) return nullptr; // should never happen
|
||||||
|
|
||||||
inst->m_Value = CBotExpression::Compile( p, pStack );
|
inst->m_value = CBotExpression::Compile(p, pStack );
|
||||||
|
|
||||||
if (pStack->GetType() < CBotTypLong && pStack->IsOk())
|
if (pStack->GetType() < CBotTypLong && pStack->IsOk())
|
||||||
{
|
{
|
||||||
|
@ -72,7 +70,7 @@ bool CBotThrow::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
if ( pile->GetState() == 0 )
|
if ( pile->GetState() == 0 )
|
||||||
{
|
{
|
||||||
if ( !m_Value->Execute(pile) ) return false;
|
if ( !m_value->Execute(pile) ) return false;
|
||||||
pile->IncState();
|
pile->IncState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +92,16 @@ void CBotThrow::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
if ( pile->GetState() == 0 )
|
if ( pile->GetState() == 0 )
|
||||||
{
|
{
|
||||||
m_Value->RestoreState(pile, bMain);
|
m_value->RestoreState(pile, bMain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotThrow::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_value"] = m_value;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -63,9 +63,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotThrow"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! The value to send.
|
//! The value to send.
|
||||||
CBotInstr* m_Value;
|
CBotInstr* m_value;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,18 +30,17 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotTry::CBotTry()
|
CBotTry::CBotTry()
|
||||||
{
|
{
|
||||||
m_ListCatch = nullptr;
|
m_catchList = nullptr;
|
||||||
m_FinalInst =
|
m_finallyBlock = nullptr;
|
||||||
m_Block = nullptr; // nullptr so that delete is not possible further
|
m_block = nullptr;
|
||||||
name = "CBotTry"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotTry::~CBotTry()
|
CBotTry::~CBotTry()
|
||||||
{
|
{
|
||||||
delete m_ListCatch; // frees the list
|
delete m_catchList; // frees the list
|
||||||
delete m_Block; // frees the instruction block
|
delete m_block; // frees the instruction block
|
||||||
delete m_FinalInst;
|
delete m_finallyBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -55,8 +54,8 @@ CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
|
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
|
||||||
|
|
||||||
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk );
|
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStk );
|
||||||
CBotCatch** pn = &inst->m_ListCatch;
|
CBotCatch** pn = &inst->m_catchList;
|
||||||
|
|
||||||
while (pStk->IsOk() && p->GetType() == ID_CATCH)
|
while (pStk->IsOk() && p->GetType() == ID_CATCH)
|
||||||
{
|
{
|
||||||
|
@ -67,7 +66,7 @@ CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
|
||||||
if (pStk->IsOk() && IsOfType( p, ID_FINALLY) )
|
if (pStk->IsOk() && IsOfType( p, ID_FINALLY) )
|
||||||
{
|
{
|
||||||
inst->m_FinalInst = CBotBlock::CompileBlkOrInst( p, pStk );
|
inst->m_finallyBlock = CBotBlock::CompileBlkOrInst(p, pStk );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStk->IsOk())
|
if (pStk->IsOk())
|
||||||
|
@ -95,9 +94,9 @@ bool CBotTry::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
if ( pile1->GetState() == 0 )
|
if ( pile1->GetState() == 0 )
|
||||||
{
|
{
|
||||||
if ( m_Block->Execute(pile1) )
|
if ( m_block->Execute(pile1) )
|
||||||
{
|
{
|
||||||
if ( m_FinalInst == nullptr ) return pj->Return(pile1);
|
if (m_finallyBlock == nullptr ) return pj->Return(pile1);
|
||||||
pile1->SetState(-2); // passes final
|
pile1->SetState(-2); // passes final
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +115,7 @@ bool CBotTry::Execute(CBotStack* &pj)
|
||||||
// there was an interruption
|
// there was an interruption
|
||||||
// see what it returns
|
// see what it returns
|
||||||
|
|
||||||
CBotCatch* pc = m_ListCatch;
|
CBotCatch* pc = m_catchList;
|
||||||
int state = static_cast<short>(pile1->GetState()); // where were we?
|
int state = static_cast<short>(pile1->GetState()); // where were we?
|
||||||
val = pile2->GetState(); // what error?
|
val = pile2->GetState(); // what error?
|
||||||
pile0->SetState(1); // marking the GetRunPos
|
pile0->SetState(1); // marking the GetRunPos
|
||||||
|
@ -137,7 +136,7 @@ bool CBotTry::Execute(CBotStack* &pj)
|
||||||
// pile0->SetState(1);
|
// pile0->SetState(1);
|
||||||
|
|
||||||
if ( !pc->Execute(pile2) ) return false; // performs the operation
|
if ( !pc->Execute(pile2) ) return false; // performs the operation
|
||||||
if ( m_FinalInst == nullptr )
|
if (m_finallyBlock == nullptr )
|
||||||
return pj->Return(pile2); // ends the try
|
return pj->Return(pile2); // ends the try
|
||||||
|
|
||||||
pile1->SetState(-2); // passes final
|
pile1->SetState(-2); // passes final
|
||||||
|
@ -147,14 +146,14 @@ bool CBotTry::Execute(CBotStack* &pj)
|
||||||
}
|
}
|
||||||
pc = pc->m_next;
|
pc = pc->m_next;
|
||||||
}
|
}
|
||||||
if ( m_FinalInst != nullptr &&
|
if (m_finallyBlock != nullptr &&
|
||||||
pile1->GetState() > 0 && val != 0 ) pile1->SetState(-1);// if stop then made the final
|
pile1->GetState() > 0 && val != 0 ) pile1->SetState(-1);// if stop then made the final
|
||||||
|
|
||||||
if (pile1->GetState() <= -1)
|
if (pile1->GetState() <= -1)
|
||||||
{
|
{
|
||||||
// pile0->SetState(1);
|
// pile0->SetState(1);
|
||||||
|
|
||||||
if (!m_FinalInst->Execute(pile2) && pile2->IsOk()) return false;
|
if (!m_finallyBlock->Execute(pile2) && pile2->IsOk()) return false;
|
||||||
if (!pile2->IsOk()) return pj->Return(pile2); // keep this exception
|
if (!pile2->IsOk()) return pj->Return(pile2); // keep this exception
|
||||||
pile2->SetError(pile1->GetState()==-1 ? static_cast<CBotError>(val) : CBotNoErr); // gives the initial error
|
pile2->SetError(pile1->GetState()==-1 ? static_cast<CBotError>(val) : CBotNoErr); // gives the initial error
|
||||||
return pj->Return(pile2);
|
return pj->Return(pile2);
|
||||||
|
@ -162,7 +161,7 @@ bool CBotTry::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
pile1->SetState(0); // returns to the evaluation
|
pile1->SetState(0); // returns to the evaluation
|
||||||
pile0->SetState(0); // returns to the evaluation
|
pile0->SetState(0); // returns to the evaluation
|
||||||
if ( val != 0 && m_ListCatch == nullptr && m_FinalInst == nullptr )
|
if ( val != 0 && m_catchList == nullptr && m_finallyBlock == nullptr )
|
||||||
return pj->Return(pile2); // ends the try without exception
|
return pj->Return(pile2); // ends the try without exception
|
||||||
|
|
||||||
pile1->SetError(static_cast<CBotError>(val)); // gives the error
|
pile1->SetError(static_cast<CBotError>(val)); // gives the error
|
||||||
|
@ -184,7 +183,7 @@ void CBotTry::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
CBotStack* pile2 = pile0->RestoreStack();
|
CBotStack* pile2 = pile0->RestoreStack();
|
||||||
if ( pile2 == nullptr ) return;
|
if ( pile2 == nullptr ) return;
|
||||||
|
|
||||||
m_Block->RestoreState(pile1, bMain);
|
m_block->RestoreState(pile1, bMain);
|
||||||
if ( pile0->GetState() == 0 )
|
if ( pile0->GetState() == 0 )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -193,7 +192,7 @@ void CBotTry::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
// there was an interruption
|
// there was an interruption
|
||||||
// see what it returns
|
// see what it returns
|
||||||
|
|
||||||
CBotCatch* pc = m_ListCatch;
|
CBotCatch* pc = m_catchList;
|
||||||
int state = pile1->GetState(); // where were we ?
|
int state = pile1->GetState(); // where were we ?
|
||||||
val = pile2->GetState(); // what error ?
|
val = pile2->GetState(); // what error ?
|
||||||
|
|
||||||
|
@ -219,9 +218,18 @@ void CBotTry::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
|
|
||||||
if (pile1->GetState() <= -1)
|
if (pile1->GetState() <= -1)
|
||||||
{
|
{
|
||||||
m_FinalInst->RestoreState(pile2, bMain);
|
m_finallyBlock->RestoreState(pile2, bMain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotTry::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
links["m_catchList"] = m_catchList;
|
||||||
|
links["m_finallyBlock"] = m_finallyBlock;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -64,14 +64,17 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotTry"; }
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Instructions
|
//! Instructions
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
//! Catches
|
//! Catches
|
||||||
CBotCatch* m_ListCatch;
|
CBotCatch* m_catchList;
|
||||||
//! Final instruction
|
//! Final instruction
|
||||||
CBotInstr* m_FinalInst;
|
CBotInstr* m_finallyBlock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -38,9 +38,8 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotTwoOpExpr::CBotTwoOpExpr()
|
CBotTwoOpExpr::CBotTwoOpExpr()
|
||||||
{
|
{
|
||||||
m_leftop =
|
m_leftop = nullptr;
|
||||||
m_rightop = nullptr; // nullptr to be able to delete without other
|
m_rightop = nullptr;
|
||||||
name = "CBotTwoOpExpr"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -505,4 +504,17 @@ void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotTwoOpExpr::GetDebugData()
|
||||||
|
{
|
||||||
|
return m_token.GetString();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotTwoOpExpr::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_leftop"] = m_leftop;
|
||||||
|
links["m_rightop"] = m_rightop;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -67,6 +67,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotTwoOpExpr"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Left element
|
//! Left element
|
||||||
CBotInstr* m_leftop;
|
CBotInstr* m_leftop;
|
||||||
|
|
|
@ -30,16 +30,15 @@ namespace CBot
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotWhile::CBotWhile()
|
CBotWhile::CBotWhile()
|
||||||
{
|
{
|
||||||
m_Condition =
|
m_condition = nullptr;
|
||||||
m_Block = nullptr; // nullptr so that delete is not possible further
|
m_block = nullptr;
|
||||||
name = "CBotWhile"; // debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotWhile::~CBotWhile()
|
CBotWhile::~CBotWhile()
|
||||||
{
|
{
|
||||||
delete m_Condition; // frees the condition
|
delete m_condition; // frees the condition
|
||||||
delete m_Block; // releases the block instruction
|
delete m_block; // releases the block instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -60,12 +59,12 @@ CBotInstr* CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
|
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
|
||||||
// a bit of battery please (??)
|
// a bit of battery please (??)
|
||||||
|
|
||||||
if ( nullptr != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
|
if ( nullptr != (inst->m_condition = CBotCondition::Compile(p, pStk )) )
|
||||||
{
|
{
|
||||||
// the condition exists
|
// the condition exists
|
||||||
|
|
||||||
IncLvl(inst->m_label);
|
IncLvl(inst->m_label);
|
||||||
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
|
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStk, true );
|
||||||
DecLvl();
|
DecLvl();
|
||||||
|
|
||||||
if ( pStk->IsOk() )
|
if ( pStk->IsOk() )
|
||||||
|
@ -94,7 +93,7 @@ bool CBotWhile::Execute(CBotStack* &pj)
|
||||||
{ // there are two possible states (depending on recovery)
|
{ // there are two possible states (depending on recovery)
|
||||||
case 0:
|
case 0:
|
||||||
// evaluates the condition
|
// evaluates the condition
|
||||||
if ( !m_Condition->Execute(pile) ) return false; // interrupted here?
|
if ( !m_condition->Execute(pile) ) return false; // interrupted here?
|
||||||
|
|
||||||
// the result of the condition is on the stack
|
// the result of the condition is on the stack
|
||||||
|
|
||||||
|
@ -110,8 +109,8 @@ bool CBotWhile::Execute(CBotStack* &pj)
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// evaluates the associated statement block
|
// evaluates the associated statement block
|
||||||
if ( m_Block != nullptr &&
|
if (m_block != nullptr &&
|
||||||
!m_Block->Execute(pile) )
|
!m_block->Execute(pile) )
|
||||||
{
|
{
|
||||||
if (pile->IfContinue(0, m_label)) continue; // if continued, will return to test
|
if (pile->IfContinue(0, m_label)) continue; // if continued, will return to test
|
||||||
return pj->BreakReturn(pile, m_label); // sends the results and releases the stack
|
return pj->BreakReturn(pile, m_label); // sends the results and releases the stack
|
||||||
|
@ -140,14 +139,27 @@ void CBotWhile::RestoreState(CBotStack* &pj, bool bMain)
|
||||||
{ // there are two possible states (depending on recovery)
|
{ // there are two possible states (depending on recovery)
|
||||||
case 0:
|
case 0:
|
||||||
// evaluates the condition
|
// evaluates the condition
|
||||||
m_Condition->RestoreState(pile, bMain);
|
m_condition->RestoreState(pile, bMain);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// evaluates the associated statement block
|
// evaluates the associated statement block
|
||||||
if ( m_Block != nullptr ) m_Block->RestoreState(pile, bMain);
|
if (m_block != nullptr ) m_block->RestoreState(pile, bMain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotWhile::GetDebugData()
|
||||||
|
{
|
||||||
|
return !m_label.empty() ? "m_label = "+m_label : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, CBotInstr*> CBotWhile::GetDebugLinks()
|
||||||
|
{
|
||||||
|
auto links = CBotInstr::GetDebugLinks();
|
||||||
|
links["m_condition"] = m_condition;
|
||||||
|
links["m_block"] = m_block;
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -64,16 +64,18 @@ public:
|
||||||
*/
|
*/
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual const std::string GetDebugName() { return "CBotWhile"; }
|
||||||
|
virtual std::string GetDebugData();
|
||||||
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! Condition
|
//! Condition
|
||||||
CBotInstr* m_Condition;
|
CBotInstr* m_condition;
|
||||||
//! Instructions
|
//! Instructions
|
||||||
CBotInstr* m_Block;
|
CBotInstr* m_block;
|
||||||
//! A label if there is
|
//! A label if there is
|
||||||
std::string m_label;
|
std::string m_label;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -358,6 +358,7 @@ private:
|
||||||
//! "this" variable
|
//! "this" variable
|
||||||
CBotVar* m_thisVar = nullptr;
|
CBotVar* m_thisVar = nullptr;
|
||||||
friend class CBotFunction;
|
friend class CBotFunction;
|
||||||
|
friend class CBotDebug;
|
||||||
|
|
||||||
CBotError m_error = CBotNoErr;
|
CBotError m_error = CBotNoErr;
|
||||||
int m_errorStart = 0;
|
int m_errorStart = 0;
|
||||||
|
|
|
@ -173,4 +173,23 @@ CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CBotTypResult::ToString()
|
||||||
|
{
|
||||||
|
switch (m_type)
|
||||||
|
{
|
||||||
|
case CBotTypVoid: return "void";
|
||||||
|
case CBotTypInt: return "int";
|
||||||
|
case CBotTypFloat: return "float";
|
||||||
|
case CBotTypBoolean: return "bool";
|
||||||
|
case CBotTypString: return "string";
|
||||||
|
case CBotTypArrayPointer: return m_pNext->ToString()+"[]";
|
||||||
|
case CBotTypArrayBody: return m_pNext->ToString()+"[] (by value)";
|
||||||
|
case CBotTypPointer: return m_pClass->GetName();
|
||||||
|
case CBotTypNullPointer: return m_pClass->GetName()+" (null)";
|
||||||
|
case CBotTypClass: return m_pClass->GetName()+" (by value)";
|
||||||
|
case CBotTypIntrinsic: return m_pClass->GetName()+" (intr)";
|
||||||
|
}
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CBot
|
} // namespace CBot
|
||||||
|
|
|
@ -152,6 +152,8 @@ public:
|
||||||
*/
|
*/
|
||||||
CBotTypResult& operator=(const CBotTypResult& src);
|
CBotTypResult& operator=(const CBotTypResult& src);
|
||||||
|
|
||||||
|
std::string ToString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_type; //!< type, see ::CBotType and ::CBotError
|
int m_type; //!< type, see ::CBotType and ::CBotError
|
||||||
CBotTypResult* m_pNext; //!< type of array element
|
CBotTypResult* m_pNext; //!< type of array element
|
||||||
|
|
|
@ -1,74 +1,75 @@
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
CBotUtils.cpp
|
CBotUtils.cpp
|
||||||
CBotFileUtils.cpp
|
CBotFileUtils.cpp
|
||||||
CBotClass.cpp
|
CBotClass.cpp
|
||||||
CBotProgram.cpp
|
CBotDebug.cpp
|
||||||
CBotStack.cpp
|
CBotProgram.cpp
|
||||||
CBotCStack.cpp
|
CBotStack.cpp
|
||||||
CBotToken.cpp
|
CBotCStack.cpp
|
||||||
CBotExternalCall.cpp
|
CBotToken.cpp
|
||||||
CBotDefParam.cpp
|
CBotExternalCall.cpp
|
||||||
CBotCallMethode.cpp
|
CBotDefParam.cpp
|
||||||
CBotTypResult.cpp
|
CBotCallMethode.cpp
|
||||||
CBotInstr/CBotInstr.cpp
|
CBotTypResult.cpp
|
||||||
CBotInstr/CBotInstrUtils.cpp
|
CBotInstr/CBotInstr.cpp
|
||||||
CBotInstr/CBotWhile.cpp
|
CBotInstr/CBotInstrUtils.cpp
|
||||||
CBotInstr/CBotDo.cpp
|
CBotInstr/CBotWhile.cpp
|
||||||
CBotInstr/CBotFor.cpp
|
CBotInstr/CBotDo.cpp
|
||||||
CBotInstr/CBotListExpression.cpp
|
CBotInstr/CBotFor.cpp
|
||||||
CBotInstr/CBotSwitch.cpp
|
CBotInstr/CBotListExpression.cpp
|
||||||
CBotInstr/CBotCase.cpp
|
CBotInstr/CBotSwitch.cpp
|
||||||
CBotInstr/CBotBreak.cpp
|
CBotInstr/CBotCase.cpp
|
||||||
CBotInstr/CBotTry.cpp
|
CBotInstr/CBotBreak.cpp
|
||||||
CBotInstr/CBotCatch.cpp
|
CBotInstr/CBotTry.cpp
|
||||||
CBotInstr/CBotThrow.cpp
|
CBotInstr/CBotCatch.cpp
|
||||||
CBotInstr/CBotExprAlpha.cpp
|
CBotInstr/CBotThrow.cpp
|
||||||
CBotInstr/CBotExprNum.cpp
|
CBotInstr/CBotExprAlpha.cpp
|
||||||
CBotInstr/CBotNew.cpp
|
CBotInstr/CBotExprNum.cpp
|
||||||
CBotInstr/CBotExprNan.cpp
|
CBotInstr/CBotNew.cpp
|
||||||
CBotInstr/CBotExprNull.cpp
|
CBotInstr/CBotExprNan.cpp
|
||||||
CBotInstr/CBotExprBool.cpp
|
CBotInstr/CBotExprNull.cpp
|
||||||
CBotInstr/CBotLeftExprVar.cpp
|
CBotInstr/CBotExprBool.cpp
|
||||||
CBotInstr/CBotPreIncExpr.cpp
|
CBotInstr/CBotLeftExprVar.cpp
|
||||||
CBotInstr/CBotPostIncExpr.cpp
|
CBotInstr/CBotPreIncExpr.cpp
|
||||||
CBotInstr/CBotExprVar.cpp
|
CBotInstr/CBotPostIncExpr.cpp
|
||||||
CBotInstr/CBotInstrMethode.cpp
|
CBotInstr/CBotExprVar.cpp
|
||||||
CBotInstr/CBotInstrCall.cpp
|
CBotInstr/CBotInstrMethode.cpp
|
||||||
CBotInstr/CBotListInstr.cpp
|
CBotInstr/CBotInstrCall.cpp
|
||||||
CBotInstr/CBotBlock.cpp
|
CBotInstr/CBotListInstr.cpp
|
||||||
CBotInstr/CBotExprUnaire.cpp
|
CBotInstr/CBotBlock.cpp
|
||||||
CBotInstr/CBotParExpr.cpp
|
CBotInstr/CBotExprUnaire.cpp
|
||||||
CBotInstr/CBotBoolExpr.cpp
|
CBotInstr/CBotParExpr.cpp
|
||||||
CBotInstr/CBotLogicExpr.cpp
|
CBotInstr/CBotBoolExpr.cpp
|
||||||
CBotInstr/CBotTwoOpExpr.cpp
|
CBotInstr/CBotLogicExpr.cpp
|
||||||
CBotInstr/CBotExpression.cpp
|
CBotInstr/CBotTwoOpExpr.cpp
|
||||||
CBotInstr/CBotIndexExpr.cpp
|
CBotInstr/CBotExpression.cpp
|
||||||
CBotInstr/CBotFieldExpr.cpp
|
CBotInstr/CBotIndexExpr.cpp
|
||||||
CBotInstr/CBotLeftExpr.cpp
|
CBotInstr/CBotFieldExpr.cpp
|
||||||
CBotInstr/CBotCondition.cpp
|
CBotInstr/CBotLeftExpr.cpp
|
||||||
CBotInstr/CBotClassInst.cpp
|
CBotInstr/CBotCondition.cpp
|
||||||
CBotInstr/CBotIString.cpp
|
CBotInstr/CBotClassInst.cpp
|
||||||
CBotInstr/CBotFloat.cpp
|
CBotInstr/CBotIString.cpp
|
||||||
CBotInstr/CBotBoolean.cpp
|
CBotInstr/CBotFloat.cpp
|
||||||
CBotInstr/CBotEmpty.cpp
|
CBotInstr/CBotBoolean.cpp
|
||||||
CBotInstr/CBotReturn.cpp
|
CBotInstr/CBotEmpty.cpp
|
||||||
CBotInstr/CBotIf.cpp
|
CBotInstr/CBotReturn.cpp
|
||||||
CBotInstr/CBotListArray.cpp
|
CBotInstr/CBotIf.cpp
|
||||||
CBotInstr/CBotInstArray.cpp
|
CBotInstr/CBotListArray.cpp
|
||||||
CBotInstr/CBotInt.cpp
|
CBotInstr/CBotInstArray.cpp
|
||||||
CBotInstr/CBotFunction.cpp
|
CBotInstr/CBotInt.cpp
|
||||||
CBotVar/CBotVarArray.cpp
|
CBotInstr/CBotFunction.cpp
|
||||||
CBotVar/CBotVarPointer.cpp
|
CBotVar/CBotVarArray.cpp
|
||||||
CBotVar/CBotVarClass.cpp
|
CBotVar/CBotVarPointer.cpp
|
||||||
CBotVar/CBotVarBoolean.cpp
|
CBotVar/CBotVarClass.cpp
|
||||||
CBotVar/CBotVarString.cpp
|
CBotVar/CBotVarBoolean.cpp
|
||||||
CBotVar/CBotVarFloat.cpp
|
CBotVar/CBotVarString.cpp
|
||||||
CBotVar/CBotVarInt.cpp
|
CBotVar/CBotVarFloat.cpp
|
||||||
CBotVar/CBotVar.cpp
|
CBotVar/CBotVarInt.cpp
|
||||||
stdlib/FileFunctions.cpp
|
CBotVar/CBotVar.cpp
|
||||||
stdlib/StringFunctions.cpp
|
stdlib/FileFunctions.cpp
|
||||||
stdlib/MathFunctions.cpp
|
stdlib/StringFunctions.cpp
|
||||||
stdlib/Compilation.cpp
|
stdlib/MathFunctions.cpp
|
||||||
|
stdlib/Compilation.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Includes
|
# Includes
|
||||||
|
|
|
@ -1 +1,19 @@
|
||||||
add_subdirectory(console)
|
# Includes
|
||||||
|
include_directories(
|
||||||
|
${COLOBOT_LOCAL_INCLUDES}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
set(LIBS
|
||||||
|
CBot
|
||||||
|
colobotbase # Needed for error strings (TODO: why are they on Colobot side? :/)
|
||||||
|
${COLOBOT_LIBS} # Needed for colobotbase
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(CBot_console console.cpp)
|
||||||
|
target_link_libraries(CBot_console ${LIBS})
|
||||||
|
|
||||||
|
add_executable(CBot_compile_graph compile_graph.cpp)
|
||||||
|
target_link_libraries(CBot_compile_graph CBot)
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "CBot/CBot.h"
|
||||||
|
#include "CBot/CBotDebug.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file test/cbot/compile_graph.cpp
|
||||||
|
* \brief A tool for generating graphs of compiled CBot instructions
|
||||||
|
*
|
||||||
|
* To generate the graph, pass the output to GraphViz:
|
||||||
|
* \code{.sh}
|
||||||
|
* ./CBot_compile_graph < input_file.txt | dot -Tx11
|
||||||
|
* \endcode
|
||||||
|
*
|
||||||
|
* or for output to file:
|
||||||
|
*
|
||||||
|
* \code{.sh}
|
||||||
|
* ./CBot_compile_graph < input_file.txt | dot -Tpng -o output.png
|
||||||
|
* \endcode
|
||||||
|
*/
|
||||||
|
|
||||||
|
using namespace CBot;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
// Read program code from stdin
|
||||||
|
std::string code = "";
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(std::cin, line))
|
||||||
|
{
|
||||||
|
code += line;
|
||||||
|
code += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the CBot engine
|
||||||
|
CBotProgram::Init();
|
||||||
|
|
||||||
|
// Compile the program
|
||||||
|
std::vector<std::string> externFunctions;
|
||||||
|
std::unique_ptr<CBotProgram> program{new CBotProgram(nullptr)};
|
||||||
|
if (!program->Compile(code.c_str(), externFunctions, nullptr))
|
||||||
|
{
|
||||||
|
CBotError error;
|
||||||
|
int cursor1, cursor2;
|
||||||
|
program->GetError(error, cursor1, cursor2);
|
||||||
|
std::cerr << "COMPILE ERROR: " << error << " @ " << cursor1 << " - " << cursor2 << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate graphs for all compiled functions marked as "extern"
|
||||||
|
if (externFunctions.empty())
|
||||||
|
{
|
||||||
|
std::cerr << "NO EXTERN FUNCTIONS FOUND";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
for (const std::string& func : externFunctions)
|
||||||
|
{
|
||||||
|
program->Start(func);
|
||||||
|
std::cerr << "# Graph for " << func << std::endl;
|
||||||
|
CBotDebug::DumpCompiledProgram(program.get());
|
||||||
|
program->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free the engine
|
||||||
|
CBotProgram::Free();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,3 +1,22 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Sources
|
|
||||||
set(CBOT_CONSOLE_SOURCES
|
|
||||||
main.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
# Includes
|
|
||||||
include_directories(
|
|
||||||
${COLOBOT_LOCAL_INCLUDES}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Libraries
|
|
||||||
set(LIBS
|
|
||||||
CBot
|
|
||||||
colobotbase # Needed for error strings (TODO: why are they on Colobot side? :/)
|
|
||||||
${COLOBOT_LIBS} # Needed for colobotbase
|
|
||||||
)
|
|
||||||
# Targets
|
|
||||||
|
|
||||||
add_executable(CBot_console ${CBOT_CONSOLE_SOURCES})
|
|
||||||
target_link_libraries(CBot_console ${LIBS})
|
|
Loading…
Reference in New Issue