statement.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. OPT_ADD = 1,
  50. OPT_SUB,
  51. OPT_MUL,
  52. OPT_DIV,
  53. OPT_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. long int line;
  124. char *code_file;
  125. struct Statement *next;
  126. };
  127. struct StatementList{
  128. enum {
  129. if_b,
  130. do_b,
  131. while_b,
  132. except_b,
  133. } type;
  134. struct Statement *condition;
  135. struct Statement *var;
  136. struct Statement *code;
  137. struct StatementList *next;
  138. };
  139. typedef struct Statement Statement;
  140. typedef struct StatementList StatementList;
  141. Statement *makeStatement(long int line, char *file);
  142. void freeStatement(Statement *st);
  143. Statement *copyStatement(Statement *st);
  144. Statement *copyStatementCore(Statement *st);
  145. void connectStatement(Statement *base, Statement *new);
  146. Statement *makeOperationStatement(int type, long int line, char *file);
  147. Statement *makeBaseValueStatement(LinkValue *value, long int line, char *file);
  148. Statement *makeBaseVarStatement(char *name, Statement *times, long int line, char *file);
  149. Statement *makeBaseSVarStatement(Statement *name, Statement *times);
  150. Statement *makeBaseDictStatement(Parameter *pt, long int line, char *file);
  151. Statement *makeTupleStatement(Parameter *pt, enum ListType type, long int line, char *file);
  152. Statement *makeFunctionStatement(Statement *name, Statement *function, struct Parameter *pt);
  153. Statement *makeCallStatement(Statement *function, struct Parameter *pt);
  154. Statement *makeIfStatement(long int line, char *file);
  155. Statement *makeWhileStatement(long int line, char *file);
  156. Statement *makeTryStatement(long int line, char *file);
  157. Statement *makeBreakStatement(Statement *times, long int line, char *file);
  158. Statement *makeContinueStatement(Statement *times, long int line, char *file);
  159. Statement *makeRegoStatement(Statement *times, long int line, char *file);
  160. Statement *makeRestartStatement(Statement *times, long int line, char *file);
  161. Statement *makeReturnStatement(Statement *value, long int line, char *file);
  162. Statement *makeRaiseStatement(Statement *value, long int line, char *file);
  163. Statement *makeIncludeStatement(Statement *file, long int line, char *file_dir);
  164. struct Token *setOperationFromToken(Statement **st_ad, struct Token *left, struct Token *right, int type, bool is_right);
  165. StatementList *makeStatementList(Statement *condition, Statement *var, Statement *code, int type);
  166. StatementList *connectStatementList(StatementList *base, StatementList *new);
  167. void freeStatementList(StatementList *base);
  168. StatementList *copyStatementList(StatementList *sl);
  169. #define makeConnectStatementList(base, condition, var, code, type) connectStatementList(base, makeStatementList(condition, var, code, type))
  170. #endif //VIRTUALMATH_STATEMENT_H