Moving CBotIf class in its own header and source files.

dev-time-step
Grunaka 2015-11-14 11:59:32 +01:00
parent c0e2201c70
commit 8c04d7fc65
5 changed files with 91 additions and 31 deletions

View File

@ -67,6 +67,7 @@
#include "CBotInstr/CBotBoolean.h"
#include "CBotInstr/CBotEmpty.h"
#include "CBotInstr/CBotReturn.h"
#include "CBotInstr/CBotIf.h"
// Local include

View File

@ -467,23 +467,6 @@ public:
bool IsOfClass(CBotString name);
};
class CBotIf : public CBotInstr
{
private:
CBotInstr* m_Condition; // condition
CBotInstr* m_Block; // instructions
CBotInstr* m_BlockElse; // instructions
public:
CBotIf();
~CBotIf();
static
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
bool Execute(CBotStack* &pj) override;
void RestoreState(CBotStack* &pj, bool bMain) override;
};
// definition of an integer
class CBotInt : public CBotInstr

View File

@ -17,15 +17,17 @@
* along with this program. If not, see http://gnu.org/licenses
*/
///////////////////////////////////////////////////////////////////////
// instruction if (condition) operation1 else operation2;
#include "CBot.h"
// Modules inlcude
#include "CBotIf.h"
#include "CBotInstr/CBotBlock.h"
#include "CBotInstr/CBotCondition.h"
// various constructors / destructors
// Local include
// Global include
////////////////////////////////////////////////////////////////////////////////
CBotIf::CBotIf()
{
m_Condition =
@ -34,6 +36,7 @@ CBotIf::CBotIf()
name = "CBotIf"; // debug
}
////////////////////////////////////////////////////////////////////////////////
CBotIf::~CBotIf()
{
delete m_Condition; // frees the condition
@ -41,9 +44,7 @@ CBotIf::~CBotIf()
delete m_BlockElse; // frees the block of instruction2
}
// compilation (static routine)
// called when the token "if" has been found
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotToken* pp = p; // preserves at the ^ token (starting instruction)
@ -89,9 +90,7 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
return pStack->Return(nullptr, pStk);
}
// execution of the instruction
////////////////////////////////////////////////////////////////////////////////
bool CBotIf :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // adds an item to the stack
@ -134,7 +133,7 @@ bool CBotIf :: Execute(CBotStack* &pj)
return pj->Return(pile);
}
////////////////////////////////////////////////////////////////////////////////
void CBotIf :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;

View File

@ -0,0 +1,77 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
// Modules inlcude
#include "CBot.h"
// Local include
// Global include
/*!
* \brief The CBotIf class Instruction if (condition) operation1 else operation2;
*/
class CBotIf : public CBotInstr
{
public:
/*!
* \brief CBotIf
*/
CBotIf();
/*!
* \brief ~CBotIf
*/
~CBotIf();
/*!
* \brief Compile Compilation (static routine) called when the token "if"
* has been found
* \param p
* \param pStack
* \return
*/
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
/*!
* \brief Execute Execution of the instruction.
* \param pj
* \return
*/
bool Execute(CBotStack* &pj) override;
/*!
* \brief RestoreState
* \param pj
* \param bMain
*/
void RestoreState(CBotStack* &pj, bool bMain) override;
private:
//! Condition
CBotInstr* m_Condition;
//! Instruction
CBotInstr* m_Block;
//! Instruction
CBotInstr* m_BlockElse;
};

View File

@ -2,7 +2,6 @@ set(SOURCES
CBot.cpp
CBotClass.cpp
CBotFunction.cpp
CBotIf.cpp
CBotProgram.cpp
CBotStack.cpp
CBotString.cpp
@ -48,6 +47,7 @@ set(SOURCES
CBotInstr/CBotBoolean.cpp
CBotInstr/CBotEmpty.cpp
CBotInstr/CBotReturn.cpp
CBotInstr/CBotIf.cpp
)
# Includes