block.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef BLOCK_H
  2. #define BLOCK_H
  3. #include "decl.h"
  4. struct Stm;
  5. struct Block;
  6. struct FunBlock;
  7. struct LabelStm;
  8. struct Block : public Scope{
  9. Block *outer;
  10. DeclSeq decls;
  11. DeclSeq locals;
  12. vector<Stm*> stms;
  13. FunBlock *fun_block;
  14. CGSeq *cg_enter,*cg_leave;
  15. CGDat *cg_debug;
  16. bool debug_on;
  17. Block( Block *outer );
  18. CGDat* debugScope();
  19. void emit( Stm *t );
  20. void emit( CGStm *t );
  21. void declLocal( Decl *d );
  22. Val* linearizeRef( Val *v );
  23. void initRef( Val *lhs,Val *rhs );
  24. void assignRef( Val *lhs,Val *rhs );
  25. void initGlobalRef( Val *lhs,Val *rhs );
  26. virtual void decl( Decl *d );
  27. virtual Val* find( string id );
  28. virtual Val* _find( string id,Block *from );
  29. virtual void eval();
  30. static void resolveBlocks();
  31. static void evalFunBlocks();
  32. static void evalClassBlocks();
  33. };
  34. struct LoopBlock : public Block{
  35. CGSym *cont_sym,*exit_sym,*loop_sym;
  36. string label;
  37. LoopBlock( Block *outer,string lab );
  38. };
  39. struct FunBlock : public Block{
  40. FunType* type;
  41. Decl* fun_decl;
  42. Val* fun_scope;
  43. map<string,LabelStm*> labels;
  44. CGDat* data_ptr;
  45. CGDat* data_stms;
  46. CGFun* cg_fun;
  47. CGTmp* ret_tmp;
  48. CGSym* ret_sym;
  49. string sourceinfo;
  50. FunBlock();
  51. FunBlock( Block *outer,string id,FunType *ty,bool pub,ExpSeq *defs=0 );
  52. virtual Val *_find( string id,Block *from );
  53. void resolve();
  54. virtual void eval();
  55. CGTmp* gcTmp();
  56. static void genAssem();
  57. static void genInterface();
  58. CGDat* dataPtr();
  59. CGDat* dataStms();
  60. };
  61. struct ClassBlock : public Block{
  62. ClassType *type;
  63. Decl *class_decl;
  64. FunBlock *ctor,*dtor;
  65. Block *ctor_new;
  66. Block *dtor_delete;
  67. Block *field_ctors;
  68. string sourceinfo;
  69. ClassBlock( Block *outer,string id,ClassType *ty );
  70. void makeDtor();
  71. void resolve();
  72. virtual void eval();
  73. virtual void decl( Decl *d );
  74. };
  75. #endif