statement.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef VIRTUALMATH_STATEMENT_H
  2. #define VIRTUALMATH_STATEMENT_H
  3. #include "__macro.h"
  4. struct Statement{
  5. enum StatementType{
  6. start = 1,
  7. base_value,
  8. base_list,
  9. base_dict,
  10. base_var,
  11. base_svar,
  12. operation,
  13. set_function,
  14. call_function,
  15. if_branch,
  16. while_branch,
  17. for_branch,
  18. try_branch,
  19. with_branch,
  20. break_cycle,
  21. continue_cycle,
  22. rego_if,
  23. restart,
  24. return_code,
  25. raise_code,
  26. include_file,
  27. } type;
  28. union StatementU{
  29. struct base_value{
  30. struct LinkValue *value;
  31. } base_value;
  32. struct base_var{
  33. char *name;
  34. struct Statement *times;
  35. } base_var;
  36. struct base_svar{
  37. struct Statement *name;
  38. struct Statement *times;
  39. } base_svar;
  40. struct {
  41. enum ListType type;
  42. struct Parameter *list;
  43. } base_list;
  44. struct {
  45. struct Parameter *dict;
  46. } base_dict;
  47. struct operation{
  48. enum OperationType{
  49. ADD = 1,
  50. SUB,
  51. MUL,
  52. DIV,
  53. ASS,
  54. } OperationType;
  55. struct Statement *left;
  56. struct Statement *right;
  57. } operation;
  58. struct {
  59. struct Statement *name;
  60. struct Statement *function;
  61. struct Parameter *parameter;
  62. } set_function;
  63. struct {
  64. struct Statement *function;
  65. struct Parameter *parameter;
  66. } call_function;
  67. struct {
  68. struct StatementList *if_list; // if elif
  69. struct Statement *else_list; // else分支(无condition)
  70. struct Statement *finally;
  71. } if_branch;
  72. struct {
  73. enum {
  74. while_,
  75. do_while_,
  76. } type;
  77. struct Statement *first; // first do
  78. struct StatementList *while_list; // while循环体
  79. struct Statement *after; // after do
  80. struct Statement *else_list; // else分支(无condition)
  81. struct Statement *finally;
  82. } while_branch;
  83. struct {
  84. struct Statement *var; // first do
  85. struct Statement *iter; // after do
  86. struct StatementList *for_list; // for循环体
  87. struct Statement *else_list; // else分支(无condition)
  88. struct Statement *finally;
  89. } for_branch;
  90. struct {
  91. struct Statement *try; // first do
  92. struct StatementList *except_list; // for循环体
  93. struct Statement *else_list; // else分支(无condition)
  94. struct Statement *finally;
  95. } try_branch;
  96. struct {
  97. struct StatementList *with_list; // for循环体
  98. struct Statement *else_list; // else分支(无condition)
  99. struct Statement *finally;
  100. } with_branch;
  101. struct {
  102. struct Statement *times;
  103. } break_cycle;
  104. struct {
  105. struct Statement *times;
  106. } continue_cycle;
  107. struct {
  108. struct Statement *times;
  109. } rego_if;
  110. struct {
  111. struct Statement *times;
  112. } restart;
  113. struct {
  114. struct Statement *value;
  115. } return_code;
  116. struct {
  117. struct Statement *value;
  118. } raise_code;
  119. struct {
  120. struct Statement *file;
  121. } include_file;
  122. }u;
  123. struct Statement *next;
  124. };
  125. struct StatementList{
  126. enum {
  127. if_b,
  128. do_b,
  129. while_b,
  130. except_b,
  131. } type;
  132. struct Statement *condition;
  133. struct Statement *var;
  134. struct Statement *code;
  135. struct StatementList *next;
  136. };
  137. typedef struct Statement Statement;
  138. typedef struct StatementList StatementList;
  139. Statement *makeStatement();
  140. void freeStatement(Statement *st);
  141. Statement *copyStatement(Statement *st);
  142. Statement *copyStatementCore(Statement *st);
  143. void connectStatement(Statement *base, Statement *new);
  144. Statement *makeOperationStatement(int type);
  145. Statement *makeBaseValueStatement(LinkValue *value);
  146. Statement *makeBaseVarStatement(char *name, Statement *times);
  147. Statement *makeBaseSVarStatement(Statement *name, Statement *times);
  148. Statement *makeBaseDictStatement(Parameter *pt);
  149. Statement *makeTupleStatement(struct Parameter *pt, enum ListType type);
  150. Statement *makeFunctionStatement(Statement *name, Statement *function, struct Parameter *pt);
  151. Statement *makeCallStatement(Statement *function, struct Parameter *pt);
  152. Statement *makeIfStatement();
  153. Statement *makeWhileStatement();
  154. Statement *makeTryStatement();
  155. Statement *makeBreakStatement(Statement *times);
  156. Statement *makeContinueStatement(Statement *times);
  157. Statement *makeRegoStatement(Statement *times);
  158. Statement *makeRestartStatement(Statement *times);
  159. Statement *makeReturnStatement(Statement *value);
  160. Statement *makeRaiseStatement(Statement *value);
  161. Statement *makeIncludeStatement(Statement *file);
  162. struct Token *setOperationFromToken(Statement **st_ad, struct Token *left, struct Token *right, int type, bool is_right);
  163. StatementList *makeStatementList(Statement *condition, Statement *var, Statement *code, int type);
  164. StatementList *connectStatementList(StatementList *base, StatementList *new);
  165. void freeStatementList(StatementList *base);
  166. StatementList *copyStatementList(StatementList *sl);
  167. #define makeConnectStatementList(base, condition, var, code, type) connectStatementList(base, makeStatementList(condition, var, code, type))
  168. #endif //VIRTUALMATH_STATEMENT_H