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