statement.h 6.3 KB

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