statement.h 7.0 KB

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