Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
CBotFunction.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/CBotInstr/CBotInstr.h"
23 
24 #include <set>
25 
26 namespace CBot
27 {
28 
42 class CBotFunction : public CBotInstr
43 {
44 public:
45  CBotFunction();
46  ~CBotFunction();
47 
57  static CBotFunction* Compile(CBotToken* &p,
58  CBotCStack* pStack,
59  CBotFunction* pFunc,
60  bool bLocal = true);
61 
69  static CBotFunction* Compile1(CBotToken* &p,
70  CBotCStack* pStack,
71  CBotClass* pClass);
72 
80  bool Execute(CBotVar** ppVars,
81  CBotStack* &pj,
82  CBotVar* pInstance = nullptr);
83 
90  void RestoreState(CBotVar** ppVars,
91  CBotStack* &pj,
92  CBotVar* pInstance = nullptr);
93 
98  void AddNext(CBotFunction* p);
99 
107  CBotTypResult CompileCall(const std::string& name,
108  CBotVar** ppVars,
109  long& nIdent);
110 
121  CBotFunction* FindLocalOrPublic(long& nIdent, const std::string& name,
122  CBotVar** ppVars,
123  CBotTypResult& TypeOrError,
124  bool bPublic = true);
125 
136  int DoCall(long& nIdent,
137  const std::string& name,
138  CBotVar** ppVars,
139  CBotStack* pStack,
140  CBotToken* pToken);
141 
149  void RestoreCall(long& nIdent,
150  const std::string& name,
151  CBotVar** ppVars,
152  CBotStack* pStack);
153 
166  int DoCall(long& nIdent,
167  const std::string& name,
168  CBotVar* pThis,
169  CBotVar** ppVars,
170  CBotStack* pStack,
171  CBotToken* pToken,
172  CBotClass* pClass);
173 
184  bool RestoreCall(long& nIdent,
185  const std::string& name,
186  CBotVar* pThis,
187  CBotVar** ppVars,
188  CBotStack* pStack,
189  CBotClass* pClass);
190 
196  bool CheckParam(CBotDefParam* pParam);
197 
202  static void AddPublic(CBotFunction* pfunc);
203 
208  std::string GetName();
209 
214  std::string GetParams();
215 
220  bool IsPublic();
221 
226  bool IsExtern();
227 
232  CBotFunction* Next();
233 
242  bool GetPosition(int& start, int& stop,
243  CBotGet modestart,
244  CBotGet modestop);
245 
246 protected:
247  virtual const std::string GetDebugName() override { return "CBotFunction"; }
248  virtual std::string GetDebugData() override;
249  virtual std::map<std::string, CBotInstr*> GetDebugLinks() override;
250 
251 private:
252  friend class CBotDebug;
253  long m_nFuncIdent;
255  bool m_bSynchro;
256 
258  CBotDefParam* m_param;
260  CBotInstr* m_block;
261  CBotFunction* m_next;
263  CBotToken m_retToken;
265  CBotTypResult m_retTyp;
267  bool m_bPublic;
269  bool m_bExtern;
271  std::string m_MasterClass;
273  CBotToken m_classToken;
274  CBotProgram* m_pProg;
276  CBotToken m_extern;
277  CBotToken m_openpar;
278  CBotToken m_closepar;
279  CBotToken m_openblk;
280  CBotToken m_closeblk;
281 
283  static std::set<CBotFunction*> m_publicFunctions;
284 
285  friend class CBotProgram;
286  friend class CBotClass;
287  friend class CBotCStack;
288 
289 };
290 
291 } // namespace CBot
Class for one CBot instruction.
Definition: CBotInstr.h:86
A function declaration in the code.
Definition: CBotFunction.h:42
bool GetPosition(int &start, int &stop, CBotGet modestart, CBotGet modestop)
GetPosition.
Definition: CBotFunction.cpp:88
The CBotDefParam class A list of parameters.
Definition: CBotDefParam.h:36
Class that manages a CBot program. This is the main entry point into the CBot engine.
Definition: CBotProgram.h:83
The execution stack.
Definition: CBotStack.h:44
int DoCall(long &nIdent, const std::string &name, CBotVar **ppVars, CBotStack *pStack, CBotToken *pToken)
DoCall Fait un appel à une fonction.
Definition: CBotFunction.cpp:613
void AddNext(CBotFunction *p)
AddNext.
Definition: CBotFunction.cpp:415
bool Execute(CBotVar **ppVars, CBotStack *&pj, CBotVar *pInstance=nullptr)
Execute.
Definition: CBotFunction.cpp:330
A CBot class definition.
Definition: CBotClass.h:105
static CBotFunction * Compile1(CBotToken *&p, CBotCStack *pStack, CBotClass *pClass)
Compile1 Pre-compile a new function.
Definition: CBotFunction.cpp:240
CBotFunction * FindLocalOrPublic(long &nIdent, const std::string &name, CBotVar **ppVars, CBotTypResult &TypeOrError, bool bPublic=true)
FindLocalOrPublic Is a function according to its unique identifier if the identifier is not found...
Definition: CBotFunction.cpp:435
Various utilities used for debugging.
Definition: CBotDebug.h:29
A CBot variable.
Definition: CBotVar.h:42
std::string GetParams()
GetParams.
Definition: CBotFunction.cpp:888
virtual const std::string GetDebugName() override
Returns the name of this class.
Definition: CBotFunction.h:247
The CBotCStack class Management of the stack of compilation.
Definition: CBotCStack.h:35
CBotTypResult CompileCall(const std::string &name, CBotVar **ppVars, long &nIdent)
CompileCall.
Definition: CBotFunction.cpp:424
virtual std::string GetDebugData() override
Returns additional data associated with this instruction for debugging purposes.
Definition: CBotFunction.cpp:918
bool IsExtern()
IsExtern.
Definition: CBotFunction.cpp:82
virtual std::map< std::string, CBotInstr * > GetDebugLinks() override
Definition: CBotFunction.cpp:928
bool CheckParam(CBotDefParam *pParam)
CheckParam See if the "signature" of parameters is identical.
Definition: CBotFunction.cpp:867
void RestoreCall(long &nIdent, const std::string &name, CBotVar **ppVars, CBotStack *pStack)
RestoreCall.
Definition: CBotFunction.cpp:686
CBotGet
Different modes for CBotProgram::GetPosition.
Definition: CBotEnums.h:62
Class to define the complete type of a variable.
Definition: CBotTypResult.h:47
static CBotFunction * Compile(CBotToken *&p, CBotCStack *pStack, CBotFunction *pFunc, bool bLocal=true)
Compile Compiles a new function.
Definition: CBotFunction.cpp:130
CBot engine.
Definition: CBotCallMethode.cpp:28
CBotFunction * Next()
Next.
Definition: CBotFunction.cpp:907
void RestoreState(CBotVar **ppVars, CBotStack *&pj, CBotVar *pInstance=nullptr)
RestoreState.
Definition: CBotFunction.cpp:386
static void AddPublic(CBotFunction *pfunc)
AddPublic.
Definition: CBotFunction.cpp:913
std::string GetName()
GetName.
Definition: CBotFunction.cpp:882
bool IsPublic()
IsPublic.
Definition: CBotFunction.cpp:76
Class representing one token of a program.
Definition: CBotToken.h:80