stmtnode.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #ifndef STMTNODE_H
  2. #define STMTNODE_H
  3. #include "node.h"
  4. struct StmtNode : public Node{
  5. int pos; //offset in source stream
  6. StmtNode():pos(-1){}
  7. void debug( int pos,Codegen *g );
  8. virtual void semant( Environ *e ){}
  9. virtual void translate( Codegen *g ){}
  10. };
  11. struct StmtSeqNode : public Node{
  12. string file;
  13. vector<StmtNode*> stmts;
  14. StmtSeqNode( const string &f ):file(f){}
  15. ~StmtSeqNode(){ for( ;stmts.size();stmts.pop_back() ) delete stmts.back(); }
  16. void semant( Environ *e );
  17. void translate( Codegen *g );
  18. void push_back( StmtNode *s ){ stmts.push_back( s ); }
  19. int size(){ return stmts.size(); }
  20. static void reset( const string &file,const string &lab );
  21. };
  22. #include "exprnode.h"
  23. #include "declnode.h"
  24. struct IncludeNode : public StmtNode{
  25. string file,label;
  26. StmtSeqNode *stmts;
  27. IncludeNode( const string &t,StmtSeqNode *ss ):file(t),stmts(ss){}
  28. ~IncludeNode(){ delete stmts; }
  29. void semant( Environ *e );
  30. void translate( Codegen *g );
  31. };
  32. struct DeclStmtNode : public StmtNode{
  33. DeclNode *decl;
  34. DeclStmtNode( DeclNode *d ):decl(d){ pos=d->pos; }
  35. ~DeclStmtNode(){ delete decl; }
  36. void semant( Environ *e );
  37. void translate( Codegen *g );
  38. };
  39. struct DimNode : public StmtNode{
  40. string ident,tag;
  41. ExprSeqNode *exprs;
  42. ArrayType *sem_type;
  43. Decl *sem_decl;
  44. DimNode( const string &i,const string &t,ExprSeqNode *e ):ident(i),tag(t),exprs(e){}
  45. ~DimNode(){ delete exprs; }
  46. void semant( Environ *e );
  47. void translate( Codegen *g );
  48. };
  49. struct AssNode : public StmtNode{
  50. VarNode *var;
  51. ExprNode *expr;
  52. AssNode( VarNode *var,ExprNode *expr ):var(var),expr(expr){}
  53. ~AssNode(){ delete var;delete expr; }
  54. void semant( Environ *e );
  55. void translate( Codegen *g );
  56. };
  57. struct ExprStmtNode : public StmtNode{
  58. ExprNode *expr;
  59. ExprStmtNode( ExprNode *e ):expr(e){}
  60. ~ExprStmtNode(){ delete expr; }
  61. void semant( Environ *e );
  62. void translate( Codegen *g );
  63. };
  64. struct LabelNode : public StmtNode{
  65. string ident;
  66. int data_sz;
  67. LabelNode( const string &s,int sz ):ident(s),data_sz(sz){}
  68. void semant( Environ *e );
  69. void translate( Codegen *g );
  70. };
  71. struct GotoNode : public StmtNode{
  72. string ident;
  73. GotoNode( const string &s ):ident(s){}
  74. void semant( Environ *e );
  75. void translate( Codegen *g );
  76. };
  77. struct GosubNode : public StmtNode{
  78. string ident;
  79. GosubNode( const string &s ):ident(s){}
  80. void semant( Environ *e );
  81. void translate( Codegen *g );
  82. };
  83. struct IfNode : public StmtNode{
  84. ExprNode *expr;
  85. StmtSeqNode *stmts,*elseOpt;
  86. IfNode( ExprNode *e,StmtSeqNode *s,StmtSeqNode *o ):expr(e),stmts(s),elseOpt(o){}
  87. ~IfNode(){ delete expr;delete stmts;delete elseOpt; }
  88. void semant( Environ *e );
  89. void translate( Codegen *g );
  90. };
  91. struct ExitNode : public StmtNode{
  92. string sem_brk;
  93. void semant( Environ *e );
  94. void translate( Codegen *g );
  95. };
  96. struct WhileNode : public StmtNode{
  97. int wendPos;
  98. ExprNode *expr;
  99. StmtSeqNode *stmts;
  100. string sem_brk;
  101. WhileNode( ExprNode *e,StmtSeqNode *s,int wp ):expr(e),stmts(s),wendPos(wp){}
  102. ~WhileNode(){ delete expr;delete stmts; }
  103. void semant( Environ *e );
  104. void translate( Codegen *g );
  105. };
  106. struct ForNode : public StmtNode{
  107. int nextPos;
  108. VarNode *var;
  109. ExprNode *fromExpr,*toExpr,*stepExpr;
  110. StmtSeqNode *stmts;
  111. string sem_brk;
  112. ForNode( VarNode *v,ExprNode *f,ExprNode *t,ExprNode *s,StmtSeqNode *ss,int np );
  113. ~ForNode();
  114. void semant( Environ *e );
  115. void translate( Codegen *g );
  116. };
  117. struct ForEachNode : public StmtNode{
  118. int nextPos;
  119. VarNode *var;
  120. string typeIdent;
  121. StmtSeqNode *stmts;
  122. string sem_brk;
  123. ForEachNode( VarNode *v,const string &t,StmtSeqNode *s,int np):var(v),typeIdent(t),stmts(s),nextPos(np){}
  124. ~ForEachNode(){ delete var;delete stmts; }
  125. void semant( Environ *e );
  126. void translate( Codegen *g );
  127. };
  128. struct ReturnNode : public StmtNode{
  129. ExprNode *expr;
  130. string returnLabel;
  131. ReturnNode( ExprNode *e ):expr( e ){}
  132. ~ReturnNode(){ delete expr; }
  133. void semant( Environ *e );
  134. void translate( Codegen *g );
  135. };
  136. struct DeleteNode : public StmtNode{
  137. ExprNode *expr;
  138. DeleteNode( ExprNode *e ):expr(e){}
  139. ~DeleteNode(){ delete expr; }
  140. void semant( Environ *e );
  141. void translate( Codegen *g );
  142. };
  143. struct DeleteEachNode : public StmtNode{
  144. string typeIdent;
  145. DeleteEachNode( const string &t ):typeIdent(t){}
  146. void semant( Environ *e );
  147. void translate( Codegen *g );
  148. };
  149. struct InsertNode : public StmtNode{
  150. ExprNode *expr1,*expr2;
  151. bool before;
  152. InsertNode( ExprNode *e1,ExprNode *e2,bool b ):expr1(e1),expr2(e2),before(b){}
  153. ~InsertNode(){ delete expr1;delete expr2; }
  154. void semant( Environ *e );
  155. void translate( Codegen *g );
  156. };
  157. struct CaseNode : public Node{
  158. ExprSeqNode *exprs;
  159. StmtSeqNode *stmts;
  160. CaseNode( ExprSeqNode *e,StmtSeqNode *s ):exprs(e),stmts(s){}
  161. ~CaseNode(){ delete exprs;delete stmts; }
  162. };
  163. struct SelectNode : public StmtNode{
  164. ExprNode *expr;
  165. StmtSeqNode *defStmts;
  166. vector<CaseNode*> cases;
  167. VarNode *sem_temp;
  168. SelectNode( ExprNode *e ):expr(e),defStmts(0),sem_temp(0){}
  169. ~SelectNode(){ delete expr;delete defStmts;delete sem_temp;for( ;cases.size();cases.pop_back() ) delete cases.back(); }
  170. void push_back( CaseNode *c ){ cases.push_back( c ); }
  171. void semant( Environ *e );
  172. void translate( Codegen *g );
  173. };
  174. struct RepeatNode : public StmtNode{
  175. int untilPos;
  176. StmtSeqNode *stmts;
  177. ExprNode *expr;
  178. string sem_brk;
  179. RepeatNode( StmtSeqNode *s,ExprNode *e,int up ):stmts(s),expr(e),untilPos(up){}
  180. ~RepeatNode(){ delete stmts;delete expr; }
  181. void semant( Environ *e );
  182. void translate( Codegen *g );
  183. };
  184. struct ReadNode : public StmtNode{
  185. VarNode *var;
  186. ReadNode( VarNode *v ):var(v){}
  187. ~ReadNode(){ delete var; }
  188. void semant( Environ *e );
  189. void translate( Codegen *g );
  190. };
  191. struct RestoreNode : public StmtNode{
  192. string ident;
  193. Label *sem_label;
  194. RestoreNode( const string &i ):ident(i){}
  195. void semant( Environ *e );
  196. void translate( Codegen *g );
  197. };
  198. #endif