statement.h 6.6 KB

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