statement.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. del_,
  13. base_svar,
  14. base_lambda,
  15. operation,
  16. set_function,
  17. set_class,
  18. call_function,
  19. slice_,
  20. if_branch,
  21. while_branch,
  22. for_branch,
  23. try_branch,
  24. with_branch,
  25. break_cycle,
  26. continue_cycle,
  27. rego_if,
  28. restart,
  29. return_code,
  30. yield_code,
  31. raise_code,
  32. include_file,
  33. import_file,
  34. from_import_file,
  35. default_var,
  36. assert,
  37. label_,
  38. goto_,
  39. } type;
  40. union StatementU{
  41. struct base_value{
  42. enum BaseValueType{
  43. link_value = 0,
  44. string_str = 1,
  45. number_str = 2,
  46. bool_true = 3,
  47. bool_false = 4,
  48. pass_value = 5,
  49. null_value = 6,
  50. } type;
  51. struct LinkValue *value;
  52. wchar_t *str;
  53. } base_value;
  54. struct base_var{
  55. wchar_t *name;
  56. struct Statement *times;
  57. bool run;
  58. } base_var;
  59. struct{
  60. struct Statement *var;
  61. } del_;
  62. struct base_svar{
  63. struct Statement *name;
  64. struct Statement *times;
  65. bool run;
  66. } base_svar;
  67. struct {
  68. enum ListType type;
  69. struct Parameter *list;
  70. } base_list;
  71. struct {
  72. struct Parameter *dict;
  73. } base_dict;
  74. struct {
  75. struct Parameter *parameter;
  76. struct Statement *function;
  77. } base_lambda;
  78. struct operation{
  79. enum OperationType{
  80. OPT_ADD = 1,
  81. OPT_SUB = 2,
  82. OPT_MUL = 3,
  83. OPT_DIV = 4,
  84. OPT_ASS = 5,
  85. OPT_POINT = 6, // 成员运算
  86. OPT_BLOCK = 7, // 代码块
  87. OPT_LINK = 8, // 获取外部成员 TODO-szh 该名为OUTPOINT
  88. OPT_INTDIV = 9,
  89. OPT_MOD = 10,
  90. OPT_POW = 11,
  91. OPT_BAND = 12,
  92. OPT_BOR = 13,
  93. OPT_BXOR = 14,
  94. OPT_BNOT = 15,
  95. OPT_BL = 16,
  96. OPT_BR = 17,
  97. OPT_EQ = 18,
  98. OPT_MOREEQ = 19,
  99. OPT_LESSEQ = 20,
  100. OPT_MORE = 21,
  101. OPT_LESS = 22,
  102. OPT_NOTEQ = 23,
  103. OPT_AND = 24,
  104. OPT_OR = 25,
  105. OPT_NOT = 26,
  106. OPT_NEGATE = 27,
  107. } OperationType;
  108. struct Statement *left;
  109. struct Statement *right;
  110. } operation;
  111. struct {
  112. struct Statement *name;
  113. struct Statement *function;
  114. struct Statement *first_do;
  115. struct Parameter *parameter;
  116. struct DecorationStatement *decoration;
  117. } set_function;
  118. struct {
  119. struct Statement *name;
  120. struct Statement *st;
  121. struct Parameter *father;
  122. struct DecorationStatement *decoration;
  123. } set_class;
  124. struct {
  125. struct Statement *function;
  126. struct Parameter *parameter;
  127. } call_function;
  128. struct {
  129. struct Statement *element;
  130. struct Parameter *index;
  131. enum SliceType{
  132. SliceType_down_,
  133. SliceType_slice_,
  134. } type;
  135. } slice_;
  136. struct {
  137. struct StatementList *if_list; // if elif
  138. struct Statement *else_list; // else分支(无condition)
  139. struct Statement *finally;
  140. } if_branch;
  141. struct {
  142. enum {
  143. while_,
  144. do_while_,
  145. } type;
  146. struct Statement *first; // first do
  147. struct StatementList *while_list; // while循环体
  148. struct Statement *after; // after do
  149. struct Statement *else_list; // else分支(无condition)
  150. struct Statement *finally;
  151. } while_branch;
  152. struct {
  153. struct StatementList *for_list; // for循环体
  154. struct Statement *first_do;
  155. struct Statement *after_do;
  156. struct Statement *else_list; // else分支(无condition)
  157. struct Statement *finally;
  158. } for_branch;
  159. struct {
  160. struct Statement *try; // first do
  161. struct StatementList *except_list; // for循环体
  162. struct Statement *else_list; // else分支(无condition)
  163. struct Statement *finally;
  164. } try_branch;
  165. struct {
  166. struct StatementList *with_list; // for循环体
  167. struct Statement *else_list; // else分支(无condition)
  168. struct Statement *finally;
  169. } with_branch;
  170. struct {
  171. struct Statement *times;
  172. } break_cycle;
  173. struct {
  174. struct Statement *times;
  175. } continue_cycle;
  176. struct {
  177. struct Statement *times;
  178. } rego_if;
  179. struct {
  180. struct Statement *times;
  181. } restart;
  182. struct {
  183. struct Statement *value;
  184. } return_code;
  185. struct {
  186. struct Statement *value;
  187. } yield_code;
  188. struct {
  189. struct Statement *value;
  190. } raise_code;
  191. struct {
  192. struct Statement *file;
  193. } include_file;
  194. struct {
  195. struct Statement *file;
  196. struct Statement *as;
  197. bool is_lock;
  198. } import_file;
  199. struct {
  200. struct Statement *file;
  201. struct Parameter *pt;
  202. struct Parameter *as;
  203. bool is_lock;
  204. } from_import_file;
  205. struct {
  206. struct Parameter *var;
  207. enum DefaultType{
  208. default_,
  209. global_,
  210. nonlocal_,
  211. } default_type;
  212. } default_var;
  213. struct {
  214. struct Statement *conditions;
  215. } assert;
  216. struct {
  217. struct Statement *command;
  218. struct Statement *as;
  219. wchar_t *label;
  220. } label_;
  221. struct {
  222. struct Statement *times;
  223. struct Statement *return_;
  224. struct Statement *label;
  225. } goto_;
  226. }u;
  227. struct { // 运行info信息
  228. bool have_info;
  229. struct VarList *var_list;
  230. struct Statement *node;
  231. struct {
  232. struct StatementList *sl_node;
  233. enum StatementInfoStatus{
  234. info_vl_branch,
  235. info_else_branch,
  236. info_finally_branch,
  237. info_first_do,
  238. info_after_do,
  239. } status;
  240. struct{
  241. LinkValue *value;
  242. LinkValue *_exit_;
  243. LinkValue *_enter_;
  244. LinkValue *with_belong;
  245. } with_;
  246. struct{
  247. LinkValue *iter;
  248. } for_;
  249. } branch;
  250. } info;
  251. fline line;
  252. char *code_file;
  253. struct Statement *next;
  254. };
  255. struct StatementList{
  256. enum {
  257. if_b,
  258. do_b,
  259. while_b,
  260. except_b,
  261. for_b,
  262. with_b,
  263. } type;
  264. struct Statement *condition;
  265. struct Statement *var;
  266. struct Statement *code;
  267. struct StatementList *next;
  268. };
  269. struct DecorationStatement {
  270. struct Statement *decoration;
  271. struct DecorationStatement *next;
  272. };
  273. typedef struct Token Token;
  274. typedef struct Statement Statement;
  275. typedef struct StatementList StatementList;
  276. typedef struct DecorationStatement DecorationStatement;
  277. Statement *makeStatement(fline line, char *file);
  278. void setRunInfo(Statement *st);
  279. void freeRunInfo(Statement *st);
  280. void freeStatement(Statement *st);
  281. Statement *copyStatement(Statement *st);
  282. Statement *copyStatementCore(Statement *st);
  283. void connectStatement(Statement *base, Statement *new);
  284. Statement *makeOperationBaseStatement(enum OperationType type, fline line, char *file);
  285. Statement *makeOperationStatement(enum OperationType type, Statement *left, Statement *right);
  286. Statement *makeBaseLinkValueStatement(LinkValue *value, fline line, char *file);
  287. Statement *makeBaseStrValueStatement(wchar_t *value, enum BaseValueType type, fline line, char *file);
  288. Statement *makeBaseValueStatement(enum BaseValueType type, fline line, char *file);
  289. Statement *makeBaseVarStatement(wchar_t *name, Statement *times, fline line, char *file);
  290. Statement *makeBaseSVarStatement(Statement *name, Statement *times);
  291. Statement *makeBaseDictStatement(Parameter *pt, fline line, char *file);
  292. Statement *makeTupleStatement(Parameter *pt, enum ListType type, fline line, char *file);
  293. Statement *makeClassStatement(Statement *name, Statement *function, Parameter *pt);
  294. Statement *makeFunctionStatement(Statement *name, Statement *function, struct Parameter *pt);
  295. Statement *makeLambdaStatement(Statement *function, Parameter *pt);
  296. Statement *makeCallStatement(Statement *function, struct Parameter *pt);
  297. Statement *makeSliceStatement(Statement *element, Parameter *index, enum SliceType type);
  298. Statement *makeForStatement(fline line, char *file);
  299. Statement *makeIfStatement(fline line, char *file);
  300. Statement *makeWhileStatement(fline line, char *file);
  301. Statement *makeTryStatement(fline line, char *file);
  302. Statement *makeBreakStatement(Statement *times, fline line, char *file);
  303. Statement *makeWithStatement(fline line, char *file);
  304. Statement *makeContinueStatement(Statement *times, fline line, char *file);
  305. Statement *makeRegoStatement(Statement *times, fline line, char *file);
  306. Statement *makeRestartStatement(Statement *times, fline line, char *file);
  307. Statement *makeReturnStatement(Statement *value, fline line, char *file);
  308. Statement *makeYieldStatement(Statement *value, fline line, char *file);
  309. Statement *makeRaiseStatement(Statement *value, fline line, char *file);
  310. Statement *makeAssertStatement(Statement *conditions, fline line, char *file);
  311. Statement *makeIncludeStatement(Statement *file, fline line, char *file_dir);
  312. Statement *makeImportStatement(Statement *file, Statement *as, bool is_lock);
  313. Statement *makeFromImportStatement(Statement *file, Parameter *as, Parameter *pt, bool is_lock);
  314. Statement *makeDefaultVarStatement(Parameter *var, fline line, char *file_dir, enum DefaultType type);
  315. Statement *makeLabelStatement(Statement *var, Statement *command, wchar_t *label, fline line, char *file_dir);
  316. Statement *makeGotoStatement(Statement *return_, Statement *times, Statement *label, fline line, char *file_dir);
  317. Statement *makeDelStatement(Statement *var, fline line, char *file_dir);
  318. Token *setOperationFromToken(Statement **st_ad, Token *left, Token *right, enum OperationType type, bool is_right);
  319. StatementList *makeStatementList(Statement *condition, Statement *var, Statement *code, int type);
  320. StatementList *connectStatementList(StatementList *base, StatementList *new);
  321. void freeStatementList(StatementList *base);
  322. StatementList *copyStatementList(StatementList *sl);
  323. DecorationStatement *makeDecorationStatement();
  324. DecorationStatement *connectDecorationStatement(Statement *decoration, DecorationStatement *base);
  325. void freeDecorationStatement(DecorationStatement *base);
  326. DecorationStatement *copyDecorationStatement(DecorationStatement *ds);
  327. DecorationStatement *copyDecorationStatementCore(DecorationStatement *base);
  328. #endif //VIRTUALMATH_STATEMENT_H