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