stm.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #ifndef STM_H
  2. #define STM_H
  3. #include "exp.h"
  4. struct Decl;
  5. struct Stm{
  6. string source_info;
  7. virtual ~Stm();
  8. virtual void eval( Block *b )=0;
  9. };
  10. struct DebugInfoStm : public Stm{
  11. void eval( Block *b );
  12. };
  13. struct RemStm : public Stm{
  14. string comment;
  15. void eval( Block *b );
  16. };
  17. struct StmStm : public Stm{
  18. CGStm *stm;
  19. StmStm( CGStm *s ):stm(s){}
  20. void eval( Block *b );
  21. };
  22. struct EvalClassBlocksStm : public Stm{
  23. void eval( Block *b );
  24. };
  25. struct LabelStm : public Stm{
  26. CGSym *goto_sym,*restore_sym;
  27. LabelStm( CGSym *x,CGSym *y ):goto_sym(x),restore_sym(y){}
  28. void eval( Block *b );
  29. };
  30. struct GotoStm : public Stm{
  31. string ident;
  32. GotoStm( string id ):ident(id){}
  33. void eval( Block *b );
  34. };
  35. struct EvalStm : public Stm{
  36. Exp *exp;
  37. EvalStm( Exp *e ):exp(e){}
  38. void eval( Block *b );
  39. };
  40. struct CtorStm : public Stm{
  41. ClassBlock *block;
  42. Block *ctor_new;
  43. CtorStm( ClassBlock *b,Block *n ):block(b),ctor_new(n){}
  44. void eval( Block *b );
  45. };
  46. struct DtorStm : public Stm{
  47. ClassBlock *block;
  48. Block *dtor_delete;
  49. DtorStm( ClassBlock *b,Block *d ):block(b),dtor_delete(d){}
  50. void eval( Block *b );
  51. };
  52. struct LocalDeclStm : public Stm{
  53. string ident;
  54. Type *type;
  55. Exp *init;
  56. LocalDeclStm( string id,Type *ty,Exp *e ):ident(id),type(ty),init(e){}
  57. void eval( Block *b );
  58. };
  59. struct FieldDeclStm : public Stm{
  60. string ident;
  61. Type *type;
  62. Exp *init;
  63. FieldDeclStm( string id,Type *ty,Exp *e ):ident(id),type(ty),init(e){}
  64. void eval( Block *b );
  65. };
  66. struct GlobalDeclStm : public Stm{
  67. string ident;
  68. Type *type;
  69. Exp *init;
  70. bool pub;
  71. GlobalDeclStm( string id,Type *ty,Exp *e,bool p ):ident(id),type(ty),init(e),pub(p){}
  72. void eval( Block *b );
  73. };
  74. struct ExternDeclStm : public Stm{
  75. int toke;
  76. string ident;
  77. Type* type;
  78. CGExp* cg;
  79. bool pub;
  80. ExternDeclStm( int t,string id,Type *ty,CGExp *e,bool p ):toke(t),ident(id),type(ty),cg(e),pub(p){}
  81. void eval( Block *b );
  82. };
  83. struct ImportStm : public Stm{
  84. CGExp *entry;
  85. ImportStm( CGExp *e ):entry(e){}
  86. void eval( Block *b );
  87. };
  88. struct IncbinStm : public Stm{
  89. string name,path;
  90. IncbinStm( string n );
  91. void eval( Block *b );
  92. };
  93. struct AssignStm : public Stm{
  94. Exp *lhs,*rhs;
  95. AssignStm( Exp *l,Exp *r ):lhs(l),rhs(r){}
  96. void eval( Block *b );
  97. };
  98. struct OpAssignStm : public Stm{
  99. int op;
  100. Exp *lhs,*rhs;
  101. OpAssignStm( int o,Exp *l,Exp *r ):op(o),lhs(l),rhs(r){}
  102. void eval( Block *b );
  103. };
  104. struct IfStm : public Stm{
  105. Exp *exp;
  106. Block *then_block,*else_block;
  107. IfStm( Exp *e,Block *t,Block *l ):exp(e),then_block(t),else_block(l){}
  108. void eval( Block *b );
  109. };
  110. struct LoopCtrlStm : public Stm{
  111. int toke;
  112. string label;
  113. LoopCtrlStm( int t,string l ):toke(t),label(l){}
  114. void eval( Block *b );
  115. };
  116. struct ForStm : public Stm{
  117. Exp *var;
  118. Exp *init;
  119. Exp *to;
  120. Exp *step;
  121. bool until;
  122. LoopBlock *block;
  123. ForStm( Exp *v,Exp *i,Exp *t,Exp *s,LoopBlock *b,bool u ):var(v),init(i),to(t),step(s),block(b),until(u){}
  124. void eval( Block *b );
  125. };
  126. struct ForEachStm : public Stm{
  127. Exp *var;
  128. Exp *coll;
  129. LoopBlock *block;
  130. ForEachStm( Exp *v,Exp *c,LoopBlock *b ):var(v),coll(c),block(b){}
  131. void eval( Block *b );
  132. void evalArray( Block *b,Val *var,Val *arr );
  133. void evalString( Block *b,Val *var,Val *str );
  134. void evalCollection( Block *b,Val *var,Val *coll );
  135. ObjectType *checkObjMethod( Val *v );
  136. void checkInt32Method( Val *v );
  137. };
  138. struct WhileStm : public Stm{
  139. Exp *exp;
  140. LoopBlock *block;
  141. WhileStm( Exp *e,LoopBlock *b ):exp(e),block(b){}
  142. void eval( Block *b );
  143. };
  144. struct RepeatStm : public Stm{
  145. Exp *exp;
  146. LoopBlock *block;
  147. RepeatStm( Exp *e,LoopBlock *b ):exp(e),block(b){}
  148. void eval( Block *b );
  149. };
  150. struct ReturnStm : public Stm{
  151. Exp *exp;
  152. ReturnStm( Exp *e ):exp(e){}
  153. void eval( Block *b );
  154. };
  155. struct ReleaseStm : public Stm{
  156. Exp *exp;
  157. ReleaseStm( Exp *e ):exp(e){}
  158. void eval( Block *b );
  159. };
  160. struct DeleteStm : public Stm{
  161. Exp *exp;
  162. DeleteStm( Exp *e ):exp(e){}
  163. void eval( Block *b );
  164. };
  165. struct SelCase{
  166. ExpSeq exps;
  167. Block *block;
  168. string source_info;
  169. SelCase( Block *b ):block(b){}
  170. };
  171. struct SelectStm : public Stm{
  172. Exp *exp;
  173. vector<SelCase*> cases;
  174. Block *_default;
  175. SelectStm( Exp *e ):exp(e),_default(0){}
  176. void eval( Block *b );
  177. };
  178. struct AssertStm : public Stm{
  179. Exp *exp,*msg;
  180. AssertStm( Exp *e,Exp *m ):exp(e),msg(m){}
  181. void eval( Block *b );
  182. };
  183. struct EndStm : public Stm{
  184. void eval( Block *b );
  185. };
  186. struct TryCatch{
  187. string ident;
  188. Type *type;
  189. Block *block;
  190. string source_info;
  191. TryCatch( Block *b ):block(b){}
  192. };
  193. struct TryStm : public Stm{
  194. Block *block;
  195. vector<TryCatch*> catches;
  196. TryStm( Block *b ):block(b){}
  197. void eval( Block *b );
  198. };
  199. struct ThrowStm : public Stm{
  200. Exp *exp;
  201. ThrowStm( Exp *e ):exp(e){}
  202. void eval( Block *b );
  203. };
  204. struct DataStm : public Stm{
  205. ExpSeq exps;
  206. void eval( Block *b );
  207. };
  208. struct ReadStm : public Stm{
  209. ExpSeq exps;
  210. void eval( Block *b );
  211. };
  212. struct RestoreStm : public Stm{
  213. string ident;
  214. RestoreStm( string id ):ident(id){}
  215. void eval( Block *b );
  216. };
  217. #endif