Colobot
CBotCStack.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/CBotVar/CBotVar.h"
23 #include "CBot/CBotProgram.h"
24 
25 namespace CBot
26 {
27 
28 class CBotInstr;
29 class CBotDefParam;
30 class CBotToken;
31 
36 {
37 public:
38 
43  CBotCStack(CBotCStack* ppapa);
44 
48  ~CBotCStack();
49 
54  bool IsOk();
55 
61 
68  CBotError GetError(int& start, int& end);
69 
74  void SetType(CBotTypResult& type);
75 
82  CBotTypResult GetTypResult(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
83 
89  int GetType(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
90 
96 
101  void AddVar(CBotVar* p);
102 
110  CBotVar* FindVar(CBotToken* &p);
111 
117  CBotVar* FindVar(CBotToken& Token);
118 
124  bool CheckVarLocal(CBotToken* &pToken);
125 
131  CBotVar* CopyVar(CBotToken& Token);
132 
139  CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false);
140 
147  CBotInstr* Return(CBotInstr* p, CBotCStack* pParent);
148 
156 
161  void SetVar( CBotVar* var );
162 
167  void SetCopyVar( CBotVar* var );
168 
173  CBotVar* GetVar();
174 
179  void SetStartError(int pos);
180 
186  void SetError(CBotError n, int pos);
187 
193  void SetError(CBotError n, CBotToken* p);
194 
201  void ResetError(CBotError n, int start, int end);
202 
207  void SetRetType(CBotTypResult& type);
208 
214 
219  void SetProgram(CBotProgram* p);
220 
226 
234  CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent);
235 
242  bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
243 
249  bool NextToken(CBotToken* &p);
250 
251 private:
252  CBotCStack* m_next;
253  CBotCStack* m_prev;
254 
255  static CBotError m_error;
256  static int m_end;
257  int m_start;
258 
260  CBotVar* m_var;
262  bool m_bBlock;
263  CBotVar* m_listVar;
265  static CBotProgram* m_prog;
266  static CBotTypResult m_retTyp;
267 };
268 
269 } // namespace CBot
CBotTypResult GetRetType()
GetRetType.
Definition: CBotCStack.cpp:279
void AddVar(CBotVar *p)
AddVar Adds a local variable.
Definition: CBotCStack.cpp:308
Class for one CBot instruction.
Definition: CBotInstr.h:86
A function declaration in the code.
Definition: CBotFunction.h:42
CBotError GetError()
GetError.
Definition: CBotCStack.cpp:131
The CBotDefParam class A list of parameters.
Definition: CBotDefParam.h:36
void SetCopyVar(CBotVar *var)
SetCopyVar Puts on the stack a copy of a variable.
Definition: CBotCStack.cpp:292
Class that manages a CBot program. This is the main entry point into the CBot engine.
Definition: CBotProgram.h:83
CBotProgram * GetProgram()
GetProgram.
Definition: CBotCStack.cpp:267
CBotTypResult CompileCall(CBotToken *&p, CBotVar **ppVars, long &nIdent)
CompileCall.
Definition: CBotCStack.cpp:345
GetTypeMode
Mode for GetType() and GetTypResult()
Definition: CBotVar.h:191
void SetProgram(CBotProgram *p)
SetProgram.
Definition: CBotCStack.cpp:261
~CBotCStack()
CBotCStack Destructor.
Definition: CBotCStack.cpp:63
void SetType(CBotTypResult &type)
SetType Set the type of instruction on the stack.
Definition: CBotCStack.cpp:163
CBotVar * GetVar()
GetVar.
Definition: CBotCStack.cpp:302
A CBot class definition.
Definition: CBotClass.h:105
void SetVar(CBotVar *var)
SetVar.
Definition: CBotCStack.cpp:285
bool NextToken(CBotToken *&p)
NextToken.
Definition: CBotCStack.cpp:249
CBotFunction * ReturnFunc(CBotFunction *p, CBotCStack *pParent)
ReturnFunc Transmits the result upper.
Definition: CBotCStack.cpp:106
bool CheckCall(CBotToken *&pToken, CBotDefParam *pParam)
CheckCall Test if a procedure name is already defined somewhere.
Definition: CBotCStack.cpp:366
CBotCStack(CBotCStack *ppapa)
CBotCStack.
Definition: CBotCStack.cpp:40
A CBot variable.
Definition: CBotVar.h:42
void SetRetType(CBotTypResult &type)
SetRetType.
Definition: CBotCStack.cpp:273
The CBotCStack class Management of the stack of compilation.
Definition: CBotCStack.h:35
CBotError
This enum contains possible CBot error values. Values in range 5000-5999 are compile errors...
Definition: CBotEnums.h:190
CBotCStack * TokenStack(CBotToken *pToken=nullptr, bool bBlock=false)
TokenStack Used only at compile.
Definition: CBotCStack.cpp:73
int GetType(CBotVar::GetTypeMode mode=CBotVar::GetTypeMode::NORMAL)
GetType Gives the type of value on the stack.
Definition: CBotCStack.cpp:145
CBotClass * GetClass()
GetClass Gives the class of the value on the stack.
Definition: CBotCStack.cpp:153
bool CheckVarLocal(CBotToken *&pToken)
CheckVarLocal Test whether a variable is already defined locally.
Definition: CBotCStack.cpp:324
CBotVar * CopyVar(CBotToken &Token)
CopyVar Finds and makes a copy.
Definition: CBotCStack.cpp:199
void ResetError(CBotError n, int start, int end)
ResetError.
Definition: CBotCStack.cpp:241
CBotInstr * Return(CBotInstr *p, CBotCStack *pParent)
Return Transmits the result upper.
Definition: CBotCStack.cpp:87
void SetError(CBotError n, int pos)
SetError.
Definition: CBotCStack.cpp:224
bool IsOk()
IsOk.
Definition: CBotCStack.cpp:211
CBotVar * FindVar(CBotToken *&p)
FindVar Finds a variable. Seeks a variable on the stack the token may be a result of TokenTypVar (obj...
Definition: CBotCStack.cpp:170
Class to define the complete type of a variable.
Definition: CBotTypResult.h:47
CBot engine.
Definition: CBotCallMethode.cpp:28
CBotTypResult GetTypResult(CBotVar::GetTypeMode mode=CBotVar::GetTypeMode::NORMAL)
GetTypResult Gives the type of value on the stack. Type of instruction on the stack.
Definition: CBotCStack.cpp:137
void SetStartError(int pos)
SetStartError.
Definition: CBotCStack.cpp:217
Class representing one token of a program.
Definition: CBotToken.h:80