Colobot
CBot.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2015, 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 
21 
26 #pragma once
27 
28 #include "resource.h"
29 #include "CBotDll.h" // public definitions
30 #include "CBotToken.h" // token management
31 
32 #define STACKRUN 1
33 #define STACKMEM 1
34 #define MAXSTACK 990
35 
36 #define EOX (reinterpret_cast<CBotStack*>(-1))
37 
38 
40 // forward declaration
41 
42 class CBotCompExpr; // an expression like
43  // () <= ()
44 class CBotAddExpr; // an expression like
45  // () + ()
46 class CBotParExpr; // basic type or instruction in parenthesis
47  // Toto.truc
48  // 12.5
49  // "string"
50  // ( expression )
51 class CBotExprVar; // a variable name as
52  // Toto
53  // chose.truc.machin
54 class CBotWhile; // while (...) {...};
55 class CBotIf; // if (...) {...} else {...}
56 class CBotDefParam; // paramerer list of a function
57 
58 
59 
61 // Management of the execution stack
63 
64 // actually, externally, the only thing it can do
65 // is to create an instance of a stack
66 // to use for routine CBotProgram :: Execute (CBotStack)
67 
68 
73 class CBotStack
74 {
75 public:
76 #if STACKMEM
77 
81  static CBotStack * FirstStack();
82 
84  void Delete();
85 #endif
86 
91  CBotStack(CBotStack* ppapa);
92 
93 
95  ~CBotStack();
96 
101  bool StackOver();
102 
109  int GetError(int& start, int& end);
110 
115  int GetError();// rend le numéro d'erreur retourné
116 
121  void Reset(void* pUser);
122 
127  void SetType(CBotTypResult& type);
128 
134  int GetType(int mode = 0);
135 
141  CBotTypResult GetTypResult(int mode = 0);
142 
147  void AddVar(CBotVar* p);
148 
157  CBotVar* FindVar(CBotToken* &pToken, bool bUpdate = false,
158  bool bModif = false);
159 
168  CBotVar* FindVar(CBotToken& pToken, bool bUpdate = false,
169  bool bModif = false);
170 
176  CBotVar* FindVar(const char* name);
177 
186  CBotVar* FindVar(long ident, bool bUpdate = false,
187  bool bModif = false);
188 
195  CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false);
196 
197 
198  CBotStack* AddStack(CBotInstr* instr = nullptr, bool bBlock = false); // extends the stack
199  CBotStack* AddStackEOX(CBotCall* instr = nullptr, bool bBlock = false); // extends the stack
200  CBotStack* RestoreStack(CBotInstr* instr = nullptr);
201  CBotStack* RestoreStackEOX(CBotCall* instr = nullptr);
202 
203  CBotStack* AddStack2(bool bBlock = false); // extends the stack
204  bool Return(CBotStack* pFils); // transmits the result over
205  bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack
206  bool BreakReturn(CBotStack* pfils, const char* name = nullptr);
207  // in case of eventual break
208  bool IfContinue(int state, const char* name);
209  // or "continue"
210 
211  bool IsOk();
212 
213  bool SetState(int n, int lim = -10); // select a state
214  int GetState(); // in what state am I?
215  bool IncState(int lim = -10); // passes to the next state
216  bool IfStep(); // do step by step
217  bool Execute();
218 
219  void SetVar( CBotVar* var );
220  void SetCopyVar( CBotVar* var );
221  CBotVar* GetVar();
222  CBotVar* GetCopyVar();
223  CBotVar* GetPtVar();
224  bool GetRetVar(bool bRet);
225  long GetVal();
226 
227  void SetStartError(int pos);
228  void SetError(int n, CBotToken* token = nullptr);
229  void SetPosError(CBotToken* token);
230  void ResetError(int n, int start, int end);
231  void SetBreak(int val, const char* name);
232 
233  void SetBotCall(CBotProgram* p);
234  CBotProgram* GetBotCall(bool bFirst = false);
235  void* GetPUser();
236  bool GetBlock();
237 
238 
239  bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype);
240  void RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar);
241 
242  bool SaveState(FILE* pf);
243  bool RestoreState(FILE* pf, CBotStack* &pStack);
244 
245  static
246  void SetTimer(int n);
247 
248  void GetRunPos(const char* &FunctionName, int &start, int &end);
249  CBotVar* GetStackVars(const char* &FunctionName, int level);
250 
251  int m_temp;
252 
253 private:
254  CBotStack* m_next;
255  CBotStack* m_next2;
256  CBotStack* m_prev;
257  friend class CBotInstArray;
258 
259 #ifdef _DEBUG
260  int m_index;
261 #endif
262  int m_state;
263  int m_step;
264  static int m_error;
265  static int m_start;
266  static int m_end;
267  static
268  CBotVar* m_retvar; // result of a return
269 
270  CBotVar* m_var; // result of the operations
271  CBotVar* m_listVar; // variables declared at this level
272 
273  bool m_bBlock; // is part of a block (variables are local to this block)
274  bool m_bOver; // stack limits?
275 // bool m_bDontDelete; // special, not to destroy the variable during delete
276  CBotProgram* m_prog; // user-defined functions
277 
278  static
279  int m_initimer;
280  static
281  int m_timer;
282  static
283  CBotString m_labelBreak;
284  static
285  void* m_pUser;
286 
287  CBotInstr* m_instr; // the corresponding instruction
288  bool m_bFunc; // an input of a function?
289  CBotCall* m_call; // recovery point in a extern call
290  friend class CBotTry;
291 };
292 
293 // inline routinees must be declared in file.h
294 
295 inline bool CBotStack::IsOk()
296 {
297  return (m_error == 0);
298 }
299 
300 inline int CBotStack::GetState()
301 {
302  return m_state;
303 }
304 
306 {
307  return m_error;
308 }
309 
311 // Management of the stack of compilation
313 
314 
316 {
317 private:
318  CBotCStack* m_next;
319  CBotCStack* m_prev;
320 
321  static int m_error;
322  static int m_end;
323  int m_start;
324 
325  CBotVar* m_var; // result of the operations
326 
327  bool m_bBlock; // is part of a block (variables are local to this block)
328  CBotVar* m_listVar;
329 
330  static
331  CBotProgram* m_prog; // list of compiled functions
332  static
333  CBotTypResult m_retTyp;
334 // static
335 // CBotToken* m_retClass;
336 
337 public:
338  CBotCStack(CBotCStack* ppapa);
339  ~CBotCStack();
340 
341  bool IsOk();
342  int GetError();
343  int GetError(int& start, int& end);
344  // gives error number
345 
346  void SetType(CBotTypResult& type);// determines the type
347  CBotTypResult GetTypResult(int mode = 0); // gives the type of value on the stack
348  int GetType(int mode = 0); // gives the type of value on the stack
349  CBotClass* GetClass(); // gives the class of the value on the stack
350 
351  void AddVar(CBotVar* p); // adds a local variable
352  CBotVar* FindVar(CBotToken* &p); // finds a variable
353  CBotVar* FindVar(CBotToken& Token);
354  bool CheckVarLocal(CBotToken* &pToken);
355  CBotVar* CopyVar(CBotToken& Token); // finds and makes a copy
356 
357  CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false);
358  CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmits the result upper
359  CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmits the result upper
360 
361  void SetVar( CBotVar* var );
362  void SetCopyVar( CBotVar* var );
363  CBotVar* GetVar();
364 
365  void SetStartError(int pos);
366  void SetError(int n, int pos);
367  void SetError(int n, CBotToken* p);
368  void ResetError(int n, int start, int end);
369 
370  void SetRetType(CBotTypResult& type);
371  CBotTypResult GetRetType();
372 
373 // void SetBotCall(CBotFunction* &pFunc);
374  void SetBotCall(CBotProgram* p);
375  CBotProgram* GetBotCall();
376  CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent);
377  bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
378 
379  bool NextToken(CBotToken* &p);
380 };
381 
382 
383 extern bool SaveVar(FILE* pf, CBotVar* pVar);
384 
385 
387 // class defining an instruction
389 {
390 private:
391  static
393  m_labelLvl;
394 protected:
395  CBotToken m_token; // keeps the token
396  CBotString name; // debug
397  CBotInstr* m_next; // linked command
398  CBotInstr* m_next2b; // second list definition chain
399  CBotInstr* m_next3; // third list for indices and fields
400  CBotInstr* m_next3b; // necessary for reporting tables
401 /*
402  for example, the following program
403  int x[]; x[1] = 4;
404  int y[x[1]][10], z;
405  is generated
406  CBotInstrArray
407  m_next3b-> CBotEmpty
408  m_next->
409  CBotExpression ....
410  m_next->
411  CBotInstrArray
412  m_next3b-> CBotExpression ('x') ( m_next3-> CBotIndexExpr ('1') )
413  m_next3b-> CBotExpression ('10')
414  m_next2-> 'z'
415  m_next->...
416 
417 */
418 
419  static
420  int m_LoopLvl;
421  friend class CBotClassInst;
422  friend class CBotInt;
423  friend class CBotListArray;
424 
425 public:
426  CBotInstr();
427  virtual
428  ~CBotInstr();
429 
430  static
431  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
432  static
433  CBotInstr* CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first = true);
434 
435  virtual
436  bool Execute(CBotStack* &pj);
437  virtual
438  bool Execute(CBotStack* &pj, CBotVar* pVar);
439  virtual
440  void RestoreState(CBotStack* &pj, bool bMain);
441 
442  virtual
443  bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
444  virtual
445  bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend);
446  virtual
447  void RestoreStateVar(CBotStack* &pile, bool bMain);
448 
449  virtual
450  bool CompCase(CBotStack* &pj, int val);
451 
452  void SetToken(CBotToken* p);
453  int GetTokenType();
454  CBotToken* GetToken();
455 
456  void AddNext(CBotInstr* n);
457  CBotInstr* GetNext();
458  void AddNext3(CBotInstr* n);
459  CBotInstr* GetNext3();
460  void AddNext3b(CBotInstr* n);
461  CBotInstr* GetNext3b();
462 
463  static
464  void IncLvl(CBotString& label);
465  static
466  void IncLvl();
467  static
468  void DecLvl();
469  static
470  bool ChkLvl(const CBotString& label, int type);
471 
472  bool IsOfClass(CBotString name);
473 };
474 
475 class CBotWhile : public CBotInstr
476 {
477 private:
478  CBotInstr* m_Condition; // condition
479  CBotInstr* m_Block; // instructions
480  CBotString m_label; // a label if there is
481 
482 public:
483  CBotWhile();
484  ~CBotWhile();
485  static
486  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
487  bool Execute(CBotStack* &pj) override;
488  void RestoreState(CBotStack* &pj, bool bMain) override;
489 };
490 
491 class CBotDo : public CBotInstr
492 {
493 private:
494  CBotInstr* m_Block; // instruction
495  CBotInstr* m_Condition; // conditions
496  CBotString m_label; // a label if there is
497 
498 public:
499  CBotDo();
500  ~CBotDo();
501  static
502  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
503  bool Execute(CBotStack* &pj) override;
504  void RestoreState(CBotStack* &pj, bool bMain) override;
505 };
506 
507 class CBotFor : public CBotInstr
508 {
509 private:
510  CBotInstr* m_Init; // initial intruction
511  CBotInstr* m_Test; // test condition
512  CBotInstr* m_Incr; // instruction for increment
513  CBotInstr* m_Block; // instructions
514  CBotString m_label; // a label if there is
515 
516 public:
517  CBotFor();
518  ~CBotFor();
519  static
520  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
521  bool Execute(CBotStack* &pj) override;
522  void RestoreState(CBotStack* &pj, bool bMain) override;
523 };
524 
525 class CBotBreak : public CBotInstr
526 {
527 private:
528  CBotString m_label; // a label if there is
529 
530 public:
531  CBotBreak();
532  ~CBotBreak();
533  static
534  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
535  bool Execute(CBotStack* &pj) override;
536  void RestoreState(CBotStack* &pj, bool bMain) override;
537 };
538 
539 class CBotReturn : public CBotInstr
540 {
541 private:
542  CBotInstr* m_Instr; // paramter of return
543 
544 public:
545  CBotReturn();
546  ~CBotReturn();
547  static
548  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
549  bool Execute(CBotStack* &pj) override;
550  void RestoreState(CBotStack* &pj, bool bMain) override;
551 };
552 
553 
554 class CBotSwitch : public CBotInstr
555 {
556 private:
557  CBotInstr* m_Value; // value to seek
558  CBotInstr* m_Block; // instructions
559 
560 public:
561  CBotSwitch();
562  ~CBotSwitch();
563  static
564  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
565  bool Execute(CBotStack* &pj) override;
566  void RestoreState(CBotStack* &pj, bool bMain) override;
567 };
568 
569 
570 class CBotCase : public CBotInstr
571 {
572 private:
573  CBotInstr* m_Value; // value to compare
574 
575 public:
576  CBotCase();
577  ~CBotCase();
578  static
579  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
580  bool Execute(CBotStack* &pj) override;
581  void RestoreState(CBotStack* &pj, bool bMain) override;
582  bool CompCase(CBotStack* &pj, int val) override;
583 };
584 
585 class CBotCatch : public CBotInstr
586 {
587 private:
588  CBotInstr* m_Block; // instructions
589  CBotInstr* m_Cond; //condition
590  CBotCatch* m_next; //following catch
591  friend class CBotTry;
592 
593 public:
594  CBotCatch();
595  ~CBotCatch();
596  static
597  CBotCatch* Compile(CBotToken* &p, CBotCStack* pStack);
598  bool TestCatch(CBotStack* &pj, int val);
599  bool Execute(CBotStack* &pj) override;
600  void RestoreState(CBotStack* &pj, bool bMain) override;
601  void RestoreCondState(CBotStack* &pj, bool bMain);
602 };
603 
604 class CBotTry : public CBotInstr
605 {
606 private:
607  CBotInstr* m_Block; // instructions
608  CBotCatch* m_ListCatch; // catches
609  CBotInstr* m_FinalInst; // final instruction
610 
611 public:
612  CBotTry();
613  ~CBotTry();
614  static
615  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
616  bool Execute(CBotStack* &pj) override;
617  void RestoreState(CBotStack* &pj, bool bMain) override;
618 };
619 
620 class CBotThrow : public CBotInstr
621 {
622 private:
623  CBotInstr* m_Value; // the value to send
624 
625 public:
626  CBotThrow();
627  ~CBotThrow();
628  static
629  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
630  bool Execute(CBotStack* &pj) override;
631  void RestoreState(CBotStack* &pj, bool bMain) override;
632 };
633 
634 
636 {
637 private:
638 
639 public:
641  ~CBotStartDebugDD();
642  static
643  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
644  bool Execute(CBotStack* &pj) override;
645 };
646 
647 
648 class CBotIf : public CBotInstr
649 {
650 private:
651  CBotInstr* m_Condition; // condition
652  CBotInstr* m_Block; // instructions
653  CBotInstr* m_BlockElse; // instructions
654 
655 public:
656  CBotIf();
657  ~CBotIf();
658  static
659  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
660  bool Execute(CBotStack* &pj) override;
661  void RestoreState(CBotStack* &pj, bool bMain) override;
662 };
663 
664 
665 // definition of an integer
666 
667 class CBotInt : public CBotInstr
668 {
669 private:
670  CBotInstr* m_var; // the variable to initialize
671  CBotInstr* m_expr; // a value to put, if there is
673 
674 public:
675  CBotInt();
676  ~CBotInt();
677  static
678  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip = false);
679  bool Execute(CBotStack* &pj) override;
680  void RestoreState(CBotStack* &pj, bool bMain) override;
681 };
682 
683 // definition of an array
684 
685 class CBotInstArray : public CBotInstr
686 {
687 private:
688  CBotInstr* m_var; // the variables to initialize
689  CBotInstr* m_listass; // list of assignments for array
691  m_typevar; // type of elements
692 // CBotString m_ClassName;
693 
694 public:
695  CBotInstArray();
696  ~CBotInstArray();
697  static
698  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
699  bool Execute(CBotStack* &pj) override;
700  void RestoreState(CBotStack* &pj, bool bMain) override;
701 };
702 
703 
704 // definition of a assignment list for a table
705 // int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ;
706 
707 class CBotListArray : public CBotInstr
708 {
709 private:
710  CBotInstr* m_expr; // an expression for an element
711  // others are linked with CBotInstr :: m_next3;
712 public:
713  CBotListArray();
714  ~CBotListArray();
715  static
716  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
717  bool Execute(CBotStack* &pj, CBotVar* pVar) override;
718  void RestoreState(CBotStack* &pj, bool bMain) override;
719 };
720 
721 
722 class CBotEmpty : public CBotInstr
723 {
724  bool Execute(CBotStack* &pj) override;
725  void RestoreState(CBotStack* &pj, bool bMain) override;
726 };
727 
728 // defininition of a boolean
729 
730 class CBotBoolean : public CBotInstr
731 {
732 private:
733  CBotInstr* m_var; // variable to initialise
734  CBotInstr* m_expr; // a value to put, if there is
735 
736 public:
737  CBotBoolean();
738  ~CBotBoolean();
739  static
740  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
741  bool Execute(CBotStack* &pj) override;
742  void RestoreState(CBotStack* &pj, bool bMain) override;
743 };
744 
745 
746 // definition of a real number
747 
748 class CBotFloat : public CBotInstr
749 {
750 private:
751  CBotInstr* m_var; // variable to initialise
752  CBotInstr* m_expr; // a value to put, if there is
753 
754 public:
755  CBotFloat();
756  ~CBotFloat();
757  static
758  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
759  bool Execute(CBotStack* &pj) override;
760  void RestoreState(CBotStack* &pj, bool bMain) override;
761 };
762 
763 // definition of an element string
764 
765 class CBotIString : public CBotInstr
766 {
767 private:
768  CBotInstr* m_var; // variable to initialise
769  CBotInstr* m_expr; // a value to put, if there is
770 
771 public:
772  CBotIString();
773  ~CBotIString();
774  static
775  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
776  bool Execute(CBotStack* &pj) override;
777  void RestoreState(CBotStack* &pj, bool bMain) override;
778 };
779 
780 // definition of an element of any class
781 
782 class CBotClassInst : public CBotInstr
783 {
784 private:
785  CBotInstr* m_var; // variable to initialise
786  CBotClass* m_pClass; // reference to the class
787  CBotInstr* m_Parameters; // parameters to be evaluated for the contructor
788  CBotInstr* m_expr; // a value to put, if there is
789  bool m_hasParams; // has it parameters?
790  long m_nMethodeIdent;
791 
792 public:
793  CBotClassInst();
794  ~CBotClassInst();
795  static
796  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr);
797  bool Execute(CBotStack* &pj) override;
798  void RestoreState(CBotStack* &pj, bool bMain) override;
799 };
800 
801 class CBotCondition : public CBotInstr
802 {
803 private:
804 
805 public:
806 
807  static
808  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
809 };
810 
811 
812 // left operand
813 // accept the expressions that be to the left of assignment
814 
815 class CBotLeftExpr : public CBotInstr
816 {
817 private:
818  long m_nIdent;
819 
820 public:
821  CBotLeftExpr();
822  ~CBotLeftExpr();
823  static
824  CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack);
825  bool Execute(CBotStack* &pStack, CBotStack* array);
826 
827  bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
828  bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep);
829  void RestoreStateVar(CBotStack* &pile, bool bMain) override;
830 };
831 
832 
833 // management of the fields of an instance
834 
835 class CBotFieldExpr : public CBotInstr
836 {
837 private:
838  friend class CBotExpression;
839  int m_nIdent;
840 
841 public:
842  CBotFieldExpr();
843  ~CBotFieldExpr();
844  void SetUniqNum(int num);
845 // static
846 // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
847  bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
848  bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override;
849  void RestoreStateVar(CBotStack* &pj, bool bMain) override;
850 };
851 
852 // management of indices of the tables
853 
854 class CBotIndexExpr : public CBotInstr
855 {
856 private:
857  CBotInstr* m_expr; // expression for calculating the index
858  friend class CBotLeftExpr;
859  friend class CBotExprVar;
860 
861 public:
862  CBotIndexExpr();
863  ~CBotIndexExpr();
864 // static
865 // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
866  bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
867  bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override;
868  void RestoreStateVar(CBotStack* &pj, bool bMain) override;
869 };
870 
871 // expressions like
872 // x = a;
873 // x * y + 3;
874 
875 class CBotExpression : public CBotInstr
876 {
877 private:
878  CBotLeftExpr* m_leftop; // left operand
879  CBotInstr* m_rightop; // right operant
880 
881 public:
882  CBotExpression();
883  ~CBotExpression();
884  static
885  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
886  bool Execute(CBotStack* &pStack) override;
887  void RestoreState(CBotStack* &pj, bool bMain) override;
888 };
889 
891 {
892 private:
893  CBotInstr* m_Expr; // the first expression to be evaluated
894 
895 public:
898  static
899  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
900  bool Execute(CBotStack* &pStack) override;
901  void RestoreState(CBotStack* &pj, bool bMain) override;
902 };
903 
904 class CBotLogicExpr : public CBotInstr
905 {
906 private:
907  CBotInstr* m_condition; // test to evaluate
908  CBotInstr* m_op1; // left element
909  CBotInstr* m_op2; // right element
910  friend class CBotTwoOpExpr;
911 
912 public:
913  CBotLogicExpr();
914  ~CBotLogicExpr();
915 // static
916 // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
917  bool Execute(CBotStack* &pStack) override;
918  void RestoreState(CBotStack* &pj, bool bMain) override;
919 };
920 
921 
922 
923 class CBotBoolExpr : public CBotInstr
924 {
925 private:
926 
927 public:
928  static
929  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
930 };
931 
932 
933 
934 // possibly an expression in parentheses ( ... )
935 // there is never an instance of this class
936 // being the object returned inside the parenthesis
937 class CBotParExpr : public CBotInstr
938 {
939 private:
940 
941 public:
942  static
943  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
944 };
945 
946 // unary expression
947 class CBotExprUnaire : public CBotInstr
948 {
949 private:
950  CBotInstr* m_Expr; // expression to be evaluated
951 public:
952  CBotExprUnaire();
953  ~CBotExprUnaire();
954  static
955  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
956  bool Execute(CBotStack* &pStack) override;
957  void RestoreState(CBotStack* &pj, bool bMain) override;
958 };
959 
960 // all operations with two operands
961 
962 class CBotTwoOpExpr : public CBotInstr
963 {
964 private:
965  CBotInstr* m_leftop; // left element
966  CBotInstr* m_rightop; // right element
967 public:
968  CBotTwoOpExpr();
969  ~CBotTwoOpExpr();
970  static
971  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = nullptr);
972  bool Execute(CBotStack* &pStack) override;
973  void RestoreState(CBotStack* &pj, bool bMain) override;
974 };
975 
976 
977 
978 
979 // an instruction block { .... }
980 class CBotBlock : public CBotInstr
981 {
982 public:
983  static
984  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
985  static
986  CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false);
987 private:
988  CBotBlock();
989  CBotBlock(const CBotBlock &);
990 };
991 
992 
993 // the content of a block of instructions ... ; ... ; ... ; ... ;
994 class CBotListInstr : public CBotInstr
995 {
996 private:
997  CBotInstr* m_Instr; // instructions to do
998 
999 public:
1000  CBotListInstr();
1001  ~CBotListInstr();
1002  static
1003  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
1004  bool Execute(CBotStack* &pj) override;
1005  void RestoreState(CBotStack* &pj, bool bMain) override;
1006 };
1007 
1008 
1009 class CBotInstrCall : public CBotInstr
1010 {
1011 private:
1012  CBotInstr* m_Parameters; // the parameters to be evaluated
1013 // int m_typeRes; // type of the result
1014 // CBotString m_RetClassName; // class of the result
1016  m_typRes; // complete type of the result
1017  long m_nFuncIdent; // id of a function
1018 
1019 public:
1020  CBotInstrCall();
1021  ~CBotInstrCall();
1022  static
1023  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1024  bool Execute(CBotStack* &pj) override;
1025  void RestoreState(CBotStack* &pj, bool bMain) override;
1026 };
1027 
1028 // a call of method
1029 
1031 {
1032 private:
1033  CBotInstr* m_Parameters; // the parameters to be evaluated
1034 // int m_typeRes; // type of the result
1035 // CBotString m_RetClassName; // class of the result
1037  m_typRes; // complete type of the result
1038 
1039  CBotString m_NomMethod; // name of the method
1040  long m_MethodeIdent; // identifier of the method
1041 // long m_nThisIdent; // identifier for "this"
1042  CBotString m_ClassName; // name of the class
1043 
1044 public:
1045  CBotInstrMethode();
1046  ~CBotInstrMethode();
1047  static
1048  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* pVar);
1049  bool Execute(CBotStack* &pj) override;
1050  bool ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend) override;
1051  void RestoreStateVar(CBotStack* &pj, bool bMain) override;
1052 };
1053 
1054 // expression for the variable name
1055 
1056 class CBotExprVar : public CBotInstr
1057 {
1058 private:
1059  long m_nIdent;
1060  friend class CBotPostIncExpr;
1061  friend class CBotPreIncExpr;
1062 
1063 public:
1064  CBotExprVar();
1065  ~CBotExprVar();
1066  static
1067  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int privat=PR_PROTECT);
1068  static
1069  CBotInstr* CompileMethode(CBotToken* &p, CBotCStack* pStack);
1070 
1071  bool Execute(CBotStack* &pj) override;
1072  void RestoreState(CBotStack* &pj, bool bMain) override;
1073  bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep);
1074  bool Execute2Var(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep);
1075  void RestoreStateVar(CBotStack* &pj, bool bMain) override;
1076 };
1077 
1079 {
1080 private:
1081  CBotInstr* m_Instr;
1082  friend class CBotParExpr;
1083 
1084 public:
1085  CBotPostIncExpr();
1086  ~CBotPostIncExpr();
1087 // static
1088 // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1089  bool Execute(CBotStack* &pj) override;
1090  void RestoreState(CBotStack* &pj, bool bMain) override;
1091 };
1092 
1094 {
1095 private:
1096  CBotInstr* m_Instr;
1097  friend class CBotParExpr;
1098 
1099 public:
1100  CBotPreIncExpr();
1101  ~CBotPreIncExpr();
1102 // static
1103 // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1104  bool Execute(CBotStack* &pj) override;
1105  void RestoreState(CBotStack* &pj, bool bMain) override;
1106 };
1107 
1108 
1110 {
1111 private:
1112 public:
1114  m_typevar; // type of variable declared
1115  long m_nIdent; // unique identifier for that variable
1116 
1117 public:
1118  CBotLeftExprVar();
1119  ~CBotLeftExprVar();
1120  static
1121  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1122  bool Execute(CBotStack* &pj) override;
1123  void RestoreState(CBotStack* &pj, bool bMain) override;
1124 };
1125 
1126 
1127 class CBotExprBool : public CBotInstr
1128 {
1129 private:
1130 
1131 public:
1132  CBotExprBool();
1133  ~CBotExprBool();
1134 
1135  static
1136  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1137  bool Execute(CBotStack* &pj) override;
1138  void RestoreState(CBotStack* &pj, bool bMain) override;
1139 };
1140 
1141 
1142 class CBotExprNull : public CBotInstr
1143 {
1144 private:
1145 
1146 public:
1147  CBotExprNull();
1148  ~CBotExprNull();
1149 
1150  bool Execute(CBotStack* &pj) override;
1151  void RestoreState(CBotStack* &pj, bool bMain) override;
1152 };
1153 
1154 class CBotExprNan : public CBotInstr
1155 {
1156 private:
1157 
1158 public:
1159  CBotExprNan();
1160  ~CBotExprNan();
1161 
1162  bool Execute(CBotStack* &pj) override;
1163  void RestoreState(CBotStack* &pj, bool bMain) override;
1164 };
1165 
1166 class CBotNew : public CBotInstr
1167 {
1168 private:
1169  CBotInstr* m_Parameters; // the parameters to be evaluated
1170  long m_nMethodeIdent;
1171 // long m_nThisIdent;
1172  CBotToken m_vartoken;
1173 
1174 public:
1175  CBotNew();
1176  ~CBotNew();
1177 
1178  static
1179  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1180  bool Execute(CBotStack* &pj) override;
1181  void RestoreState(CBotStack* &pj, bool bMain) override;
1182 };
1183 
1184 // expression representing a number
1185 
1186 class CBotExprNum : public CBotInstr
1187 {
1188 private:
1189  int m_numtype; // et the type of number
1190  long m_valint; // value for an int
1191  float m_valfloat; // value for a float
1192 
1193 public:
1194  CBotExprNum();
1195  ~CBotExprNum();
1196  static
1197  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1198  bool Execute(CBotStack* &pj) override;
1199  void RestoreState(CBotStack* &pj, bool bMain) override;
1200 };
1201 
1202 
1203 
1204 // expression representing a string
1205 
1206 class CBotExprAlpha : public CBotInstr
1207 {
1208 private:
1209 
1210 public:
1211  CBotExprAlpha();
1212  ~CBotExprAlpha();
1213  static
1214  CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
1215  bool Execute(CBotStack* &pj) override;
1216  void RestoreState(CBotStack* &pj, bool bMain) override;
1217 };
1218 
1219 
1220 #define MAX(a,b) ((a>b) ? a : b)
1221 
1222 
1223 // class for the management of integer numbers (int)
1224 class CBotVarInt : public CBotVar
1225 {
1226 private:
1227  int m_val; // the value
1228  CBotString m_defnum; // the name if given by DefineNum
1229  friend class CBotVar;
1230 
1231 public:
1232  CBotVarInt( const CBotToken* name );
1233 // ~CBotVarInt();
1234 
1235  void SetValInt(int val, const char* s = nullptr) override;
1236  void SetValFloat(float val) override;
1237  int GetValInt() override;
1238  float GetValFloat() override;
1239  CBotString GetValString() override;
1240 
1241  void Copy(CBotVar* pSrc, bool bName=true) override;
1242 
1243 
1244  void Add(CBotVar* left, CBotVar* right) override; // addition
1245  void Sub(CBotVar* left, CBotVar* right) override; // substraction
1246  void Mul(CBotVar* left, CBotVar* right) override; // multiplication
1247  int Div(CBotVar* left, CBotVar* right) override; // division
1248  int Modulo(CBotVar* left, CBotVar* right) override; // remainder of division
1249  void Power(CBotVar* left, CBotVar* right) override; // power
1250 
1251  bool Lo(CBotVar* left, CBotVar* right) override;
1252  bool Hi(CBotVar* left, CBotVar* right) override;
1253  bool Ls(CBotVar* left, CBotVar* right) override;
1254  bool Hs(CBotVar* left, CBotVar* right) override;
1255  bool Eq(CBotVar* left, CBotVar* right) override;
1256  bool Ne(CBotVar* left, CBotVar* right) override;
1257 
1258  void XOr(CBotVar* left, CBotVar* right) override;
1259  void Or(CBotVar* left, CBotVar* right) override;
1260  void And(CBotVar* left, CBotVar* right) override;
1261 
1262  void SL(CBotVar* left, CBotVar* right) override;
1263  void SR(CBotVar* left, CBotVar* right) override;
1264  void ASR(CBotVar* left, CBotVar* right) override;
1265 
1266  void Neg() override;
1267  void Not() override;
1268  void Inc() override;
1269  void Dec() override;
1270 
1271  bool Save0State(FILE* pf) override;
1272  bool Save1State(FILE* pf) override;
1273 
1274 };
1275 
1276 // Class for managing real numbers (float)
1277 class CBotVarFloat : public CBotVar
1278 {
1279 private:
1280  float m_val; // the value
1281 
1282 public:
1283  CBotVarFloat( const CBotToken* name );
1284 // ~CBotVarFloat();
1285 
1286  void SetValInt(int val, const char* s = nullptr) override;
1287  void SetValFloat(float val) override;
1288  int GetValInt() override;
1289  float GetValFloat() override;
1290  CBotString GetValString() override;
1291 
1292  void Copy(CBotVar* pSrc, bool bName=true) override;
1293 
1294 
1295  void Add(CBotVar* left, CBotVar* right) override; // addition
1296  void Sub(CBotVar* left, CBotVar* right) override; // substraction
1297  void Mul(CBotVar* left, CBotVar* right) override; // multiplication
1298  int Div(CBotVar* left, CBotVar* right) override; // division
1299  int Modulo(CBotVar* left, CBotVar* right) override; // remainder of division
1300  void Power(CBotVar* left, CBotVar* right) override; // power
1301 
1302  bool Lo(CBotVar* left, CBotVar* right) override;
1303  bool Hi(CBotVar* left, CBotVar* right) override;
1304  bool Ls(CBotVar* left, CBotVar* right) override;
1305  bool Hs(CBotVar* left, CBotVar* right) override;
1306  bool Eq(CBotVar* left, CBotVar* right) override;
1307  bool Ne(CBotVar* left, CBotVar* right) override;
1308 
1309  void Neg() override;
1310  void Inc() override;
1311  void Dec() override;
1312 
1313  bool Save1State(FILE* pf) override;
1314 };
1315 
1316 
1317 // class for management of strings (String)
1318 class CBotVarString : public CBotVar
1319 {
1320 private:
1321  CBotString m_val; // the value
1322 
1323 public:
1324  CBotVarString( const CBotToken* name );
1325 // ~CBotVarString();
1326 
1327  void SetValString(const char* p) override;
1328  CBotString GetValString() override;
1329 
1330  void Copy(CBotVar* pSrc, bool bName=true) override;
1331 
1332  void Add(CBotVar* left, CBotVar* right) override; // addition
1333 
1334  bool Lo(CBotVar* left, CBotVar* right) override;
1335  bool Hi(CBotVar* left, CBotVar* right) override;
1336  bool Ls(CBotVar* left, CBotVar* right) override;
1337  bool Hs(CBotVar* left, CBotVar* right) override;
1338  bool Eq(CBotVar* left, CBotVar* right) override;
1339  bool Ne(CBotVar* left, CBotVar* right) override;
1340 
1341  bool Save1State(FILE* pf) override;
1342 };
1343 
1344 // class for the management of boolean
1345 class CBotVarBoolean : public CBotVar
1346 {
1347 private:
1348  bool m_val; // the value
1349 
1350 public:
1351  CBotVarBoolean( const CBotToken* name );
1352 // ~CBotVarBoolean();
1353 
1354  void SetValInt(int val, const char* s = nullptr) override;
1355  void SetValFloat(float val) override;
1356  int GetValInt() override;
1357  float GetValFloat() override;
1358  CBotString GetValString() override;
1359 
1360  void Copy(CBotVar* pSrc, bool bName=true) override;
1361 
1362  void And(CBotVar* left, CBotVar* right) override;
1363  void Or(CBotVar* left, CBotVar* right) override;
1364  void XOr(CBotVar* left, CBotVar* right) override;
1365  void Not() override;
1366  bool Eq(CBotVar* left, CBotVar* right) override;
1367  bool Ne(CBotVar* left, CBotVar* right) override;
1368 
1369  bool Save1State(FILE* pf) override;
1370 };
1371 
1372 
1373 // class management class instances
1374 class CBotVarClass : public CBotVar
1375 {
1376 private:
1377  static
1378  CBotVarClass* m_ExClass; // list of existing instances at some point
1379  CBotVarClass* m_ExNext; // for this general list
1380  CBotVarClass* m_ExPrev; // for this general list
1381 
1382 private:
1383  CBotClass* m_pClass; // the class definition
1384  CBotVarClass* m_pParent; // the instance of a parent class
1385  CBotVar* m_pVar; // contents
1386  friend class CBotVar; // my daddy is a buddy WHAT? :D(\TODO mon papa est un copain )
1387  friend class CBotVarPointer; // and also the pointer
1388  int m_CptUse; // counter usage
1389  long m_ItemIdent; // identifier (unique) of an instance
1390  bool m_bConstructor; // set if a constructor has been called
1391 
1392 public:
1393  CBotVarClass( const CBotToken* name, const CBotTypResult& type );
1394 // CBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent );
1395  ~CBotVarClass();
1396 // void InitCBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent );
1397 
1398  void Copy(CBotVar* pSrc, bool bName=true) override;
1399  void SetClass(CBotClass* pClass) override; //, int &nIdent);
1400  CBotClass* GetClass() override;
1401  CBotVar* GetItem(const char* name) override; // return an element of a class according to its name (*)
1402  CBotVar* GetItemRef(int nIdent) override;
1403 
1404  CBotVar* GetItem(int n, bool bExtend) override;
1405  CBotVar* GetItemList() override;
1406 
1407  CBotString GetValString() override;
1408 
1409  bool Save1State(FILE* pf) override;
1410  void Maj(void* pUser, bool bContinue) override;
1411 
1412  void IncrementUse(); // a reference to incrementation
1413  void DecrementUse(); // a reference to decrementation
1414 
1415  CBotVarClass*
1416  GetPointer() override;
1417  void SetItemList(CBotVar* pVar);
1418 
1419  void SetIdent(long n) override;
1420 
1421  static CBotVarClass* Find(long id);
1422 
1423 
1424 // CBotVar* GetMyThis();
1425 
1426  bool Eq(CBotVar* left, CBotVar* right) override;
1427  bool Ne(CBotVar* left, CBotVar* right) override;
1428 
1429  void ConstructorSet() override;
1430 };
1431 
1432 
1433 // class for the management of pointers to a class instances
1434 class CBotVarPointer : public CBotVar
1435 {
1436 private:
1437  CBotVarClass*
1438  m_pVarClass; // contents
1439  CBotClass* m_pClass; // class provided for this pointer
1440  friend class CBotVar; // my daddy is a buddy
1441 
1442 public:
1443  CBotVarPointer( const CBotToken* name, CBotTypResult& type );
1444  ~CBotVarPointer();
1445 
1446  void Copy(CBotVar* pSrc, bool bName=true) override;
1447  void SetClass(CBotClass* pClass) override;
1448  CBotClass* GetClass() override;
1449  CBotVar* GetItem(const char* name) override; // return an element of a class according to its name (*)
1450  CBotVar* GetItemRef(int nIdent) override;
1451  CBotVar* GetItemList() override;
1452 
1453  CBotString GetValString() override;
1454  void SetPointer(CBotVar* p) override;
1455  CBotVarClass*
1456  GetPointer() override;
1457 
1458  void SetIdent(long n) override; // associates an identification number (unique)
1459  long GetIdent(); // gives the identification number associated with
1460  void ConstructorSet() override;
1461 
1462  bool Save1State(FILE* pf) override;
1463  void Maj(void* pUser, bool bContinue) override;
1464 
1465  bool Eq(CBotVar* left, CBotVar* right) override;
1466  bool Ne(CBotVar* left, CBotVar* right) override;
1467 };
1468 
1469 
1470 // classe pour les tableaux
1471 
1472 #define MAXARRAYSIZE 9999
1473 
1474 class CBotVarArray : public CBotVar
1475 {
1476 private:
1477  CBotVarClass*
1478  m_pInstance; // instance manager of table
1479 
1480  friend class CBotVar; // my daddy is a buddy
1481 
1482 public:
1483  CBotVarArray( const CBotToken* name, CBotTypResult& type );
1484  ~CBotVarArray();
1485 
1486  void SetPointer(CBotVar* p) override;
1487  CBotVarClass*
1488  GetPointer() override;
1489 
1490  void Copy(CBotVar* pSrc, bool bName=true) override;
1491  CBotVar* GetItem(int n, bool bGrow=false) override; // makes an element according to its numeric index
1492  // enlarged the table if necessary if bExtend
1493 // CBotVar* GetItem(const char* name); // makes a element by literal index
1494  CBotVar* GetItemList() override; // gives the first item in the list
1495 
1496  CBotString GetValString() override; // gets the contents of the array into a string
1497 
1498  bool Save1State(FILE* pf) override;
1499 };
1500 
1501 
1502 extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars);
1503 
1504 extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 );
1505 extern bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 );
1506 
1507 extern bool WriteWord(FILE* pf, unsigned short w);
1508 extern bool ReadWord(FILE* pf, unsigned short& w);
1509 extern bool ReadLong(FILE* pf, long& w);
1510 extern bool WriteFloat(FILE* pf, float w);
1511 extern bool WriteLong(FILE* pf, long w);
1512 extern bool ReadFloat(FILE* pf, float& w);
1513 extern bool WriteString(FILE* pf, CBotString s);
1514 extern bool ReadString(FILE* pf, CBotString& s);
1515 extern bool WriteType(FILE* pf, CBotTypResult type);
1516 extern bool ReadType(FILE* pf, CBotTypResult& type);
1517 
1518 extern float GetNumFloat( const char* p );
1519 
1520 #if 0
1521 extern void DEBUG( const char* text, int val, CBotStack* pile );
1522 #endif
1523 
1525 // class for routine calls (external)
1526 
1528 {
1529 private:
1530  static
1531  CBotCall* m_ListCalls;
1532  static
1533  void* m_pUser;
1534  long m_nFuncIdent;
1535 
1536 private:
1537  CBotString m_name;
1538  bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser) ;
1540  (*m_rComp) (CBotVar* &pVar, void* pUser) ;
1541  CBotCall* m_next;
1542 
1543 public:
1544  CBotCall(const char* name,
1545  bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
1546  CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
1547  ~CBotCall();
1548 
1549  static
1550  bool AddFunction(const char* name,
1551  bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
1552  CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
1553 
1554  static
1556  CompileCall(CBotToken* &p, CBotVar** ppVars, CBotCStack* pStack, long& nIdent);
1557  static
1558  bool CheckCall(const char* name);
1559 
1560 // static
1561 // int DoCall(CBotToken* &p, CBotVar** ppVars, CBotStack* pStack, CBotTypResult& rettype);
1562  static
1563  int DoCall(long& nIdent, CBotToken* token, CBotVar** ppVars, CBotStack* pStack, CBotTypResult& rettype);
1564 #if STACKRUN
1565  bool Run(CBotStack* pStack);
1566  static
1567  bool RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack);
1568 #endif
1569 
1570  CBotString GetName();
1571  CBotCall* Next();
1572 
1573  static void SetPUser(void* pUser);
1574  static void Free();
1575 };
1576 
1577 // class managing the methods declared by AddFunction on a class
1578 
1580 {
1581 private:
1582  CBotString m_name;
1583  bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user);
1585  (*m_rComp) (CBotVar* pThis, CBotVar* &pVar);
1586  CBotCallMethode* m_next;
1587  friend class CBotClass;
1588  long m_nFuncIdent;
1589 
1590 public:
1591  CBotCallMethode(const char* name,
1592  bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
1593  CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
1594  ~CBotCallMethode();
1595 
1597  CompileCall(const char* name, CBotVar* pThis,
1598  CBotVar** ppVars, CBotCStack* pStack,
1599  long& nIdent);
1600 
1601  int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pFunc);
1602 
1603  CBotString GetName();
1604  CBotCallMethode* Next();
1605  void AddNext(CBotCallMethode* p);
1606 
1607 };
1608 
1609 // a list of parameters
1610 
1612 {
1613 private:
1614  CBotToken m_token; // name of the parameter
1615  CBotString m_typename; // type name
1616  CBotTypResult m_type; // type of paramteter
1617  CBotDefParam* m_next; // next parameter
1618  long m_nIdent;
1619 
1620 public:
1621  CBotDefParam();
1622  ~CBotDefParam();
1623  static
1624  CBotDefParam* Compile(CBotToken* &p, CBotCStack* pStack);
1625  bool Execute(CBotVar** ppVars, CBotStack* &pj);
1626  void RestoreState(CBotStack* &pj, bool bMain);
1627 
1628  void AddNext(CBotDefParam* p);
1629  int GetType();
1630  CBotTypResult GetTypResult();
1631  CBotDefParam* GetNext();
1632 
1633  CBotString GetParamString();
1634 };
1635 
1636 
1637 // a function declaration
1638 
1640 {
1641 private:
1642  // management of list of (static) public functions
1643  static
1644  CBotFunction* m_listPublic;
1645  CBotFunction* m_nextpublic;
1646  CBotFunction* m_prevpublic;
1647  friend class CBotCStack;
1648 // long m_nThisIdent;
1649  long m_nFuncIdent;
1650  bool m_bSynchro; // synchronized method?
1651 
1652 private:
1653  CBotDefParam* m_Param; // parameter list
1654  CBotInstr* m_Block; // the instruction block
1655  CBotFunction* m_next;
1656  CBotToken m_retToken; // if returns CBotTypClass
1657  CBotTypResult m_retTyp; // complete type of the result
1658 
1659  bool m_bPublic; // public function
1660  bool m_bExtern; // extern function
1661  CBotString m_MasterClass; // name of the class we derive
1662  CBotProgram* m_pProg;
1663  friend class CBotProgram;
1664  friend class CBotClass;
1665 
1666  CBotToken m_extern; // for the position of the word "extern"
1667  CBotToken m_openpar;
1668  CBotToken m_closepar;
1669  CBotToken m_openblk;
1670  CBotToken m_closeblk;
1671 public:
1672  CBotFunction();
1673  ~CBotFunction();
1674  static
1675  CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, bool bLocal = true);
1676  static
1677  CBotFunction* Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass);
1678  bool Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr);
1679  void RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr);
1680 
1681  void AddNext(CBotFunction* p);
1682  CBotTypResult CompileCall(const char* name, CBotVar** ppVars, long& nIdent);
1683  CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic = true);
1684 
1685  int DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken);
1686  void RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack);
1687  int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass);
1688  void RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass);
1689  bool CheckParam(CBotDefParam* pParam);
1690 
1691  static
1692  void AddPublic(CBotFunction* pfunc);
1693 
1694  CBotString GetName();
1695  CBotString GetParams();
1696  bool IsPublic();
1697  bool IsExtern();
1698  CBotFunction* Next();
1699 
1700  bool GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop);
1701 };
Definition: CBot.h:525
Definition: CBot.h:620
Definition: CBot.h:388
Definition: CBot.h:1166
Definition: CBotDll.h:903
CBotStack(CBotStack *ppapa)
CBotStack Constructor of the stack.
Definition: CBotStack.cpp:85
Definition: CBot.h:685
Definition: CBot.h:1611
Definition: CBot.h:507
Definition: CBot.h:980
Definition: CBot.h:1527
Definition: CBot.h:1206
Definition: CBot.h:1639
Definition: CBot.h:923
CBotVar * FindVar(CBotToken *&pToken, bool bUpdate=false, bool bModif=false)
Fetch a variable by its token.
Definition: CBotStack.cpp:476
void Delete()
Delete Remove current stack.
Definition: CBotStack.cpp:96
Definition: CBot.h:1345
int GetError()
GetError Get error number.
Definition: CBot.h:305
Definition: CBot.h:730
Library for interpretation of CBOT language.
Definition: CBot.h:667
Definition: CBot.h:835
Definition: CBot.h:962
Definition: CBot.h:604
Definition: CBot.h:707
Definition: CBot.h:539
Definition: CBot.h:801
Definition: CBot.h:491
Definition: CBot.h:1579
Definition: CBot.h:1434
Definition: CBot.h:315
Definition: CBot.h:1009
Definition: CBot.h:1224
Definition: CBot.h:1030
Definition: CBotDll.h:365
int GetType(int mode=0)
GetType Get the type of value on the stack.
Definition: CBotStack.cpp:457
Definition: CBot.h:875
static CBotStack * FirstStack()
FirstStack Allocate first stack.
Definition: CBotStack.cpp:47
Definition: CBot.h:854
void Reset(void *pUser)
Reset Reset error at and set user.
Definition: CBotStack.cpp:355
Definition: CBot.h:648
CBotString Class used to work on strings.
Definition: CBotDll.h:259
Management of the execution stack.
Definition: CBot.h:73
CBotVar * CopyVar(CBotToken &Token, bool bUpdate=false)
Find variable by its token and returns a copy of it.
Definition: CBotStack.cpp:549
Definition: CBot.h:765
CBotTypResult GetTypResult(int mode=0)
Getes the type of complete value on the stack.
Definition: CBotStack.cpp:463
Definition: CBot.h:1127
Definition: CBot.h:1318
static CBotInstr * Compile(CBotToken *&p, CBotCStack *pStack, CBotClass *pClass=nullptr)
Definition: CBotClass.cpp:476
Definition: CBot.h:1142
Definition: CBot.h:1093
Definition: CBot.h:475
Definition: CBot.h:1154
Definition: CBot.h:635
Definition: CBot.h:1056
Definition: CBot.h:1186
Definition: CBot.h:904
Definition: CBot.h:815
bool StackOver()
StackOver Check if end of stack is reached.
Definition: CBotStack.cpp:236
Definition: CBot.h:1277
Definition: CBot.h:1374
Definition: CBot.h:1109
Definition: CBot.h:947
CBotTypResult class to define the complete type of a result.
Definition: CBotDll.h:90
Definition: CBot.h:722
Definition: CBot.h:782
Definition: CBotDll.h:334
Definition: CBot.h:585
Definition: CBot.h:570
Definition: CBotDll.h:557
Definition: CBot.h:748
void SetType(CBotTypResult &type)
SetType Determines the type.
Definition: CBotStack.cpp:469
Definition: CBotDll.h:776
Definition: CBot.h:1474
void AddVar(CBotVar *p)
Adds a local variable.
Definition: CBotStack.cpp:684
Definition: CBot.h:937
CBotInt()
CBotInstr* m_next; // several definitions chained.
Definition: CBot.cpp:917
~CBotStack()
~CBotStack Destructor
Definition: CBotStack.cpp:91
Definition: CBot.h:890
Definition: CBot.h:994
Definition: CBot.h:1078
Definition: CBot.h:554