statement.h 5.2 KB

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