Moving CBotBlock class in its own header and source files.
parent
840da007a9
commit
8eff62a78c
|
@ -357,58 +357,6 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val)
|
|||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// compiles a statement block " { i ; i ; } "
|
||||
|
||||
// this class have no constructor because there is never an instance of this
|
||||
// class
|
||||
// the object returned by Compile is usually of type CBotListInstr
|
||||
|
||||
|
||||
CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
{
|
||||
pStack->SetStartError(p->GetStart());
|
||||
|
||||
if (IsOfType(p, ID_OPBLK))
|
||||
{
|
||||
CBotInstr* inst = CBotListInstr::Compile(p, pStack, bLocal);
|
||||
|
||||
if (IsOfType(p, ID_CLBLK))
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
|
||||
pStack->SetError(TX_CLOSEBLK, p->GetStart()); // missing parenthesis
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pStack->SetError(TX_OPENBLK, p->GetStart());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
{
|
||||
// is this a new block
|
||||
if (p->GetType() == ID_OPBLK) return CBotBlock::Compile(p, pStack);
|
||||
|
||||
// otherwise, look for a single statement instead
|
||||
|
||||
// to handle the case with local definition instruction (*)
|
||||
CBotCStack* pStk = pStack->TokenStack(p, bLocal);
|
||||
|
||||
return pStack->Return( CBotInstr::Compile(p, pStk), // a single instruction
|
||||
pStk);
|
||||
}
|
||||
|
||||
// (*) is the case in the following statement
|
||||
// if (1 == 1) int x = 0;
|
||||
// where the variable x is known only in the block following the if
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// defining an array of any type
|
||||
// int a[12];
|
||||
|
|
|
@ -799,22 +799,6 @@ public:
|
|||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// an instruction block { .... }
|
||||
class CBotBlock : public CBotInstr
|
||||
{
|
||||
public:
|
||||
static
|
||||
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
||||
static
|
||||
CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false);
|
||||
private:
|
||||
CBotBlock() = delete;
|
||||
CBotBlock(const CBotBlock &) = delete;
|
||||
};
|
||||
|
||||
#define MAX(a,b) ((a>b) ? a : b)
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include "CBot.h"
|
||||
|
||||
#include "CBotInstr/CBotBlock.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "CBot.h"
|
||||
|
||||
#include "CBotInstr/CBotBlock.h"
|
||||
|
||||
// various constructors / destructors
|
||||
CBotIf::CBotIf()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see http://gnu.org/licenses
|
||||
*/
|
||||
|
||||
// Modules inlcude
|
||||
#include "CBotBlock.h"
|
||||
#include "CBotListInstr.h"
|
||||
|
||||
// Local include
|
||||
|
||||
// Global include
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
{
|
||||
pStack->SetStartError(p->GetStart());
|
||||
|
||||
if (IsOfType(p, ID_OPBLK))
|
||||
{
|
||||
CBotInstr* inst = CBotListInstr::Compile(p, pStack, bLocal);
|
||||
|
||||
if (IsOfType(p, ID_CLBLK))
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
|
||||
pStack->SetError(TX_CLOSEBLK, p->GetStart()); // missing parenthesis
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pStack->SetError(TX_OPENBLK, p->GetStart());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
{
|
||||
// is this a new block
|
||||
if (p->GetType() == ID_OPBLK) return CBotBlock::Compile(p, pStack);
|
||||
|
||||
// otherwise, look for a single statement instead
|
||||
|
||||
// to handle the case with local definition instruction (*)
|
||||
CBotCStack* pStk = pStack->TokenStack(p, bLocal);
|
||||
|
||||
return pStack->Return( CBotInstr::Compile(p, pStk), // a single instruction
|
||||
pStk);
|
||||
}
|
||||
|
||||
// (*) is the case in the following statement
|
||||
// if (1 == 1) int x = 0;
|
||||
// where the variable x is known only in the block following the if
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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 CBotBlock class An instruction block { .... }.
|
||||
*/
|
||||
class CBotBlock : public CBotInstr
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Compile Compiles a statement block " { i ; i ; } "
|
||||
* \param p
|
||||
* \param pStack
|
||||
* \param bLocal
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
||||
|
||||
/*!
|
||||
* \brief CompileBlkOrInst
|
||||
* \param p
|
||||
* \param pStack
|
||||
* \param bLocal
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false);
|
||||
|
||||
private:
|
||||
|
||||
/*!
|
||||
* \brief CBotBlock This class have no constructor because there is never an
|
||||
* instance of this class the object returned by Compile is usually of type
|
||||
* CBotListInstr
|
||||
*/
|
||||
CBotBlock() = delete;
|
||||
CBotBlock(const CBotBlock &) = delete;
|
||||
};
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
// Modules inlcude
|
||||
#include "CBotCatch.h"
|
||||
#include "CBotBlock.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
// Modules inlcude
|
||||
#include "CBotDo.h"
|
||||
#include "CBotBlock.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
// Modules inlcude
|
||||
#include "CBotFor.h"
|
||||
#include "CBotListExpression.h"
|
||||
#include "CBotBlock.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
// Modules inlcude
|
||||
#include "CBotListInstr.h"
|
||||
#include "CBotBlock.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
// Modules inlcude
|
||||
#include "CBotSwitch.h"
|
||||
#include "CBotCase.h"
|
||||
#include "CBotBlock.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
// Modules inlcude
|
||||
#include "CBotTry.h"
|
||||
#include "CBotBlock.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
// Modules inlcude
|
||||
#include "CBotWhile.h"
|
||||
#include "CBotBlock.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ set(SOURCES
|
|||
CBotInstr/CBotInstrMethode.cpp
|
||||
CBotInstr/CBotInstrCall.cpp
|
||||
CBotInstr/CBotListInstr.cpp
|
||||
CBotInstr/CBotBlock.cpp
|
||||
)
|
||||
|
||||
# Includes
|
||||
|
|
Loading…
Reference in New Issue