statement.h 6.6 KB

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