Colobot
CBotInstr.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 #include "CBot/CBotToken.h"
23 #include "CBot/CBotCStack.h"
24 
25 #include <vector>
26 
27 namespace CBot
28 {
29 class CBotDebug;
30 
86 class CBotInstr
87 {
88 public:
92  CBotInstr();
93 
97  virtual ~CBotInstr();
98 
123  static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
124 
133  static CBotInstr* CompileArray(CBotToken* &p,
134  CBotCStack* pStack,
135  CBotTypResult type,
136  bool first = true);
137 
143  virtual bool Execute(CBotStack* &pj);
144 
151  virtual bool Execute(CBotStack* &pj,
152  CBotVar* pVar);
153 
159  virtual void RestoreState(CBotStack* &pj,
160  bool bMain);
161 
168  virtual bool ExecuteVar(CBotVar* &pVar,
169  CBotCStack* &pile);
170 
180  virtual bool ExecuteVar(CBotVar* &pVar,
181  CBotStack* &pile,
182  CBotToken* prevToken,
183  bool bStep,
184  bool bExtend);
185 
191  virtual void RestoreStateVar(CBotStack* &pile,
192  bool bMain);
193 
202  virtual bool CompCase(CBotStack* &pj,
203  int val);
204 
209  void SetToken(CBotToken* p);
210 
216  int GetTokenType();
217 
222  CBotToken* GetToken();
223 
228  void AddNext(CBotInstr* n);
229 
234  CBotInstr* GetNext();
235 
240  void AddNext3(CBotInstr* n);
241 
246  CBotInstr* GetNext3();
247 
252  void AddNext3b(CBotInstr* n);
253 
258  CBotInstr* GetNext3b();
259 
264  static void IncLvl(std::string& label);
265 
269  static void IncLvl();
270 
274  static void DecLvl();
275 
282  static bool ChkLvl(const std::string& label, int type);
283 
284 protected:
285  friend class CBotDebug;
290  virtual const std::string GetDebugName() = 0;
295  virtual std::string GetDebugData() { return ""; }
300  virtual std::map<std::string, CBotInstr*> GetDebugLinks();
301 
302 protected:
313 
315  static int m_LoopLvl;
316  friend class CBotDefClass;
317  friend class CBotDefInt;
318  friend class CBotListArray;
319 
320 private:
322  static std::vector<std::string> m_labelLvl;
323 };
324 
325 } // namespace CBot
Class for one CBot instruction.
Definition: CBotInstr.h:86
virtual void RestoreState(CBotStack *&pj, bool bMain)
RestoreState.
Definition: CBotInstr.cpp:289
The execution stack.
Definition: CBotStack.h:44
int GetTokenType()
GetTokenType Return the type of the token assicated with the instruction.
Definition: CBotInstr.cpp:114
static CBotInstr * Compile(CBotToken *&p, CBotCStack *pStack)
Compile an instruction.
Definition: CBotInstr.cpp:168
virtual bool Execute(CBotStack *&pj)
Execute.
Definition: CBotInstr.cpp:273
Compilation of assignment of an array - {{1, 2, 3}, {3, 2, 1}}.
Definition: CBotListArray.h:30
CBotToken m_token
Keeps the token.
Definition: CBotInstr.h:304
virtual std::string GetDebugData()
Returns additional data associated with this instruction for debugging purposes.
Definition: CBotInstr.h:295
Various utilities used for debugging.
Definition: CBotDebug.h:29
void AddNext3(CBotInstr *n)
AddNext3.
Definition: CBotInstr.cpp:134
A CBot variable.
Definition: CBotVar.h:42
static CBotInstr * CompileArray(CBotToken *&p, CBotCStack *pStack, CBotTypResult type, bool first=true)
CompileArray.
Definition: CBotInstr.cpp:322
CBotInstr * m_next3b
Necessary for reporting tables.
Definition: CBotInstr.h:312
CBotToken * GetToken()
GetToken Return associated token.
Definition: CBotInstr.cpp:120
The CBotCStack class Management of the stack of compilation.
Definition: CBotCStack.h:35
CBotInstr * GetNext3b()
GetNext3b.
Definition: CBotInstr.cpp:162
void AddNext3b(CBotInstr *n)
AddNext3b.
Definition: CBotInstr.cpp:142
static int m_LoopLvl
Counter of nested loops, to determine the break and continue valid.
Definition: CBotInstr.h:315
void AddNext(CBotInstr *n)
AddNext Adds the statement following the other.
Definition: CBotInstr.cpp:126
virtual std::map< std::string, CBotInstr * > GetDebugLinks()
Definition: CBotInstr.cpp:362
static void DecLvl()
DecLvl Free a level.
Definition: CBotInstr.cpp:88
Definition of an integer variable - int a, b = 12.
Definition: CBotDefInt.h:30
virtual bool CompCase(CBotStack *&pj, int val)
CompCase This routine is defined only for the subclass CBotCase this allows to make the call on all i...
Definition: CBotInstr.cpp:316
virtual void RestoreStateVar(CBotStack *&pile, bool bMain)
RestoreStateVar.
Definition: CBotInstr.cpp:310
Definition of class instance variable.
Definition: CBotDefClass.h:40
CBotInstr * m_next
Linked command.
Definition: CBotInstr.h:306
CBotInstr * GetNext3()
GetNext3.
Definition: CBotInstr.cpp:156
CBotInstr * m_next2b
Second list definition chain.
Definition: CBotInstr.h:308
virtual bool ExecuteVar(CBotVar *&pVar, CBotCStack *&pile)
ExecuteVar.
Definition: CBotInstr.cpp:296
void SetToken(CBotToken *p)
SetToken Set the token corresponding to the instruction.
Definition: CBotInstr.cpp:108
static bool ChkLvl(const std::string &label, int type)
ChkLvl Control validity of break and continue.
Definition: CBotInstr.cpp:95
virtual const std::string GetDebugName()=0
Returns the name of this class.
Class to define the complete type of a variable.
Definition: CBotTypResult.h:47
static void IncLvl()
IncLvl Adds a level (switch statement).
Definition: CBotInstr.cpp:80
CBotInstr()
Constructor.
Definition: CBotInstr.cpp:54
CBot engine.
Definition: CBotCallMethode.cpp:28
CBotInstr * m_next3
Third list for indices and fields.
Definition: CBotInstr.h:310
CBotInstr * GetNext()
GetNext Returns next statement.
Definition: CBotInstr.cpp:150
virtual ~CBotInstr()
Destructor.
Definition: CBotInstr.cpp:63
Class representing one token of a program.
Definition: CBotToken.h:80