statement.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. #include "__virtualmath.h"
  2. Statement *makeStatement(fline line, char *file) {
  3. Statement *tmp = memCalloc(1, sizeof(Statement));
  4. tmp->type = start;
  5. tmp->next = NULL;
  6. tmp->aut = auto_aut;
  7. tmp->line = line;
  8. tmp->code_file = memStrcpy(file);
  9. setRunInfo(tmp);
  10. return tmp;
  11. }
  12. void setRunInfo(Statement *st){
  13. st->info.have_info = false;
  14. st->info.node = NULL;
  15. st->info.var_list = NULL;
  16. st->info.branch.sl_node = NULL;
  17. st->info.branch.status = info_vl_branch;
  18. st->info.branch.with_.value = NULL;
  19. st->info.branch.with_._exit_ = NULL;
  20. st->info.branch.with_._enter_ = NULL;
  21. st->info.branch.for_.iter = NULL;
  22. }
  23. void freeRunInfo(Statement *st) {
  24. if (st->info.var_list != NULL) {
  25. gc_freeTmpLink(&st->info.var_list->hashtable->gc_status);
  26. freeVarList(st->info.var_list);
  27. }
  28. if (st->info.branch.with_.value != NULL)
  29. gc_freeTmpLink(&st->info.branch.with_.value->gc_status);
  30. if (st->info.branch.with_._exit_ != NULL)
  31. gc_freeTmpLink(&st->info.branch.with_._exit_->gc_status);
  32. if (st->info.branch.with_._enter_ != NULL)
  33. gc_freeTmpLink(&st->info.branch.with_._enter_->gc_status);
  34. if (st->info.branch.for_.iter != NULL)
  35. gc_freeTmpLink(&st->info.branch.for_.iter->gc_status);
  36. setRunInfo(st);
  37. }
  38. Token *setOperationFromToken(Statement **st_ad, struct Token *left, struct Token *right, enum OperationType type, bool is_right) {
  39. Token *new_token = NULL;
  40. Statement *st = *st_ad, *left_st = left->data.st;
  41. if (is_right && left->data.st->type == operation &&
  42. left_st->u.operation.OperationType == st->u.operation.OperationType){
  43. st->u.operation.left = left_st->u.operation.right;
  44. left_st->u.operation.right = st;
  45. st->u.operation.right = right->data.st;
  46. st = left_st; // left_st是主中心
  47. }
  48. else{
  49. st->u.operation.left = left_st;
  50. st->u.operation.right = right->data.st;
  51. }
  52. new_token = makeToken(0);
  53. new_token->token_type = type;
  54. new_token->data.st = st;
  55. st->line = left->line;
  56. freeToken(left, false);
  57. freeToken(right, false);
  58. *st_ad = st;
  59. return new_token;
  60. }
  61. Statement *makeBaseLinkValueStatement(LinkValue *value, fline line, char *file) {
  62. Statement *tmp = makeStatement(line, file);
  63. tmp->type = base_value;
  64. tmp->u.base_value.type = link_value;
  65. tmp->u.base_value.value = value;
  66. tmp->u.base_value.str = NULL;
  67. gc_addStatementLink(&value->gc_status);
  68. return tmp;
  69. }
  70. Statement *makeBaseStrValueStatement(char *value, enum BaseValueType type, fline line, char *file){
  71. Statement *tmp = makeStatement(line, file);
  72. tmp->type = base_value;
  73. tmp->u.base_value.type = type;
  74. tmp->u.base_value.value = NULL;
  75. tmp->u.base_value.str = memStrcpy(value);
  76. return tmp;
  77. }
  78. Statement *makeBaseValueStatement(enum BaseValueType type, fline line, char *file) {
  79. Statement *tmp = makeStatement(line, file);
  80. tmp->type = base_value;
  81. tmp->u.base_value.type = type;
  82. tmp->u.base_value.value = NULL;
  83. tmp->u.base_value.str = NULL;
  84. return tmp;
  85. }
  86. Statement *makeBaseVarStatement(char *name, Statement *times, fline line, char *file){
  87. Statement *tmp = makeStatement(line, file);
  88. tmp->type = base_var;
  89. tmp->u.base_var.name = memStrcpy(name);
  90. tmp->u.base_var.times = times;
  91. return tmp;
  92. }
  93. Statement *makeBaseSVarStatement(Statement *name, Statement *times){
  94. Statement *tmp = makeStatement(name->line, name->code_file);
  95. tmp->type = base_svar;
  96. tmp->u.base_svar.name = name;
  97. tmp->u.base_svar.times = times;
  98. return tmp;
  99. }
  100. Statement *makeBaseDictStatement(Parameter *pt, fline line, char *file){
  101. Statement *tmp = makeStatement(line, file);
  102. tmp->type = base_dict;
  103. tmp->u.base_dict.dict = pt;
  104. return tmp;
  105. }
  106. Statement *makeOperationBaseStatement(enum OperationType type, fline line, char *file){
  107. Statement *tmp = makeStatement(line, file);
  108. tmp->type = operation;
  109. tmp->u.operation.OperationType = type;
  110. tmp->u.operation.left = NULL;
  111. tmp->u.operation.right = NULL;
  112. return tmp;
  113. }
  114. Statement *makeOperationStatement(enum OperationType type, Statement *left, Statement *right){
  115. Statement *tmp = makeOperationBaseStatement(type, left->line, left->code_file);
  116. tmp->u.operation.left = left;
  117. tmp->u.operation.right = right;
  118. return tmp;
  119. }
  120. Statement *makeTupleStatement(Parameter *pt, enum ListType type, fline line, char *file) {
  121. Statement *tmp = makeStatement(line, file);
  122. tmp->type = base_list;
  123. tmp->u.base_list.type = type;
  124. tmp->u.base_list.list = pt;
  125. return tmp;
  126. }
  127. Statement *makeClassStatement(Statement *name, Statement *function, Parameter *pt) {
  128. Statement *tmp = makeStatement(name->line, name->code_file);
  129. tmp->type = set_class;
  130. tmp->u.set_class.name = name;
  131. tmp->u.set_class.st = function;
  132. tmp->u.set_class.father = pt;
  133. tmp->u.set_class.decoration = NULL;
  134. return tmp;
  135. }
  136. Statement *makeFunctionStatement(Statement *name, Statement *function, Parameter *pt) {
  137. Statement *tmp = makeStatement(name->line, name->code_file);
  138. tmp->type = set_function;
  139. tmp->u.set_function.name = name;
  140. tmp->u.set_function.function = function;
  141. tmp->u.set_function.parameter = pt;
  142. tmp->u.set_function.decoration = NULL;
  143. tmp->u.set_function.first_do = NULL;
  144. return tmp;
  145. }
  146. Statement *makeLambdaStatement(Statement *function, Parameter *pt) {
  147. Statement *tmp = makeStatement(function->line, function->code_file);
  148. tmp->type = base_lambda;
  149. tmp->u.base_lambda.function = function;
  150. tmp->u.base_lambda.parameter = pt;
  151. return tmp;
  152. }
  153. Statement *makeCallStatement(Statement *function, Parameter *pt) {
  154. Statement *tmp = makeStatement(function->line, function->code_file);
  155. tmp->type = call_function;
  156. tmp->u.call_function.function = function;
  157. tmp->u.call_function.parameter = pt;
  158. return tmp;
  159. }
  160. Statement *makeSliceStatement(Statement *element, Parameter *index, enum SliceType type) {
  161. Statement *tmp = makeStatement(element->line, element->code_file);
  162. tmp->type = slice_;
  163. tmp->u.slice_.element = element;
  164. tmp->u.slice_.index = index;
  165. tmp->u.slice_.type = type;
  166. return tmp;
  167. }
  168. Statement *makeForStatement(fline line, char *file) {
  169. Statement *tmp = makeStatement(line, file);
  170. tmp->type = for_branch;
  171. tmp->u.for_branch.after_do = NULL;
  172. tmp->u.for_branch.first_do = NULL;
  173. tmp->u.for_branch.for_list = NULL;
  174. tmp->u.for_branch.else_list = NULL;
  175. tmp->u.for_branch.finally = NULL;
  176. return tmp;
  177. }
  178. Statement *makeIfStatement(fline line, char *file) {
  179. Statement *tmp = makeStatement(line, file);
  180. tmp->type = if_branch;
  181. tmp->u.if_branch.if_list = NULL;
  182. tmp->u.if_branch.else_list = NULL;
  183. tmp->u.if_branch.finally = NULL;
  184. return tmp;
  185. }
  186. Statement *makeWhileStatement(fline line, char *file) {
  187. Statement *tmp = makeStatement(line, file);
  188. tmp->type = while_branch;
  189. tmp->u.while_branch.type = while_;
  190. tmp->u.while_branch.while_list = NULL;
  191. tmp->u.while_branch.else_list = NULL;
  192. tmp->u.while_branch.finally = NULL;
  193. tmp->u.while_branch.first = NULL;
  194. tmp->u.while_branch.after = NULL;
  195. return tmp;
  196. }
  197. Statement *makeTryStatement(fline line, char *file) {
  198. Statement *tmp = makeStatement(line, file);
  199. tmp->type = try_branch;
  200. tmp->u.try_branch.except_list = NULL;
  201. tmp->u.try_branch.else_list = NULL;
  202. tmp->u.try_branch.finally = NULL;
  203. tmp->u.try_branch.try = NULL;
  204. return tmp;
  205. }
  206. Statement *makeWithStatement(fline line, char *file) {
  207. Statement *tmp = makeStatement(line, file);
  208. tmp->type = with_branch;
  209. tmp->u.with_branch.with_list = NULL;
  210. tmp->u.with_branch.else_list = NULL;
  211. tmp->u.with_branch.finally = NULL;
  212. return tmp;
  213. }
  214. Statement *makeBreakStatement(Statement *times, fline line, char *file){
  215. Statement *tmp = makeStatement(line, file);
  216. tmp->type = break_cycle;
  217. tmp->u.break_cycle.times = times;
  218. return tmp;
  219. }
  220. Statement *makeContinueStatement(Statement *times, fline line, char *file){
  221. Statement *tmp = makeStatement(line, file);
  222. tmp->type = continue_cycle;
  223. tmp->u.continue_cycle.times = times;
  224. return tmp;
  225. }
  226. Statement *makeRegoStatement(Statement *times, fline line, char *file){
  227. Statement *tmp = makeStatement(line, file);
  228. tmp->type = rego_if;
  229. tmp->u.rego_if.times = times;
  230. return tmp;
  231. }
  232. Statement *makeRestartStatement(Statement *times, fline line, char *file){
  233. Statement *tmp = makeStatement(line, file);
  234. tmp->type = restart;
  235. tmp->u.restart.times = times;
  236. return tmp;
  237. }
  238. Statement *makeReturnStatement(Statement *value, fline line, char *file){
  239. Statement *tmp = makeStatement(line, file);
  240. tmp->type = return_code;
  241. tmp->u.return_code.value = value;
  242. return tmp;
  243. }
  244. Statement *makeYieldStatement(Statement *value, fline line, char *file){
  245. Statement *tmp = makeStatement(line, file);
  246. tmp->type = yield_code;
  247. tmp->u.yield_code.value = value;
  248. return tmp;
  249. }
  250. Statement *makeRaiseStatement(Statement *value, fline line, char *file){
  251. Statement *tmp = makeStatement(line, file);
  252. tmp->type = raise_code;
  253. tmp->u.raise_code.value = value;
  254. return tmp;
  255. }
  256. Statement *makeAssertStatement(Statement *conditions, fline line, char *file){
  257. Statement *tmp = makeStatement(line, file);
  258. tmp->type = assert;
  259. tmp->u.assert.conditions = conditions;
  260. return tmp;
  261. }
  262. Statement *makeIncludeStatement(Statement *file, fline line, char *file_dir){
  263. Statement *tmp = makeStatement(line, file_dir);
  264. tmp->type = include_file;
  265. tmp->u.include_file.file = file;
  266. return tmp;
  267. }
  268. Statement *makeImportStatement(Statement *file, Statement *as) {
  269. Statement *tmp = makeStatement(file->line, file->code_file);
  270. tmp->type = import_file;
  271. tmp->u.import_file.file = file;
  272. tmp->u.import_file.as = as;
  273. return tmp;
  274. }
  275. Statement *makeFromImportStatement(Statement *file, Parameter *as, Parameter *pt) {
  276. Statement *tmp = makeStatement(file->line, file->code_file);
  277. tmp->type = from_import_file;
  278. tmp->u.from_import_file.file = file;
  279. tmp->u.from_import_file.as = as;
  280. tmp->u.from_import_file.pt = pt;
  281. return tmp;
  282. }
  283. Statement *makeDefaultVarStatement(Parameter *var, fline line, char *file_dir, enum DefaultType type) {
  284. Statement *tmp = makeStatement(line, file_dir);
  285. tmp->type = default_var;
  286. tmp->u.default_var.var = var;
  287. tmp->u.default_var.default_type = type;
  288. return tmp;
  289. }
  290. Statement *makeLabelStatement(Statement *var, Statement *command, char *label, fline line, char *file_dir) {
  291. Statement *tmp = makeStatement(line, file_dir);
  292. tmp->type = label_;
  293. tmp->u.label_.as = var;
  294. tmp->u.label_.command = command;
  295. tmp->u.label_.label = memStrcpy(label);
  296. return tmp;
  297. }
  298. Statement *makeGotoStatement(Statement *return_, Statement *times, Statement *label, fline line, char *file_dir) {
  299. Statement *tmp = makeStatement(line, file_dir);
  300. tmp->type = goto_;
  301. tmp->u.goto_.return_ = return_;
  302. tmp->u.goto_.times = times;
  303. tmp->u.goto_.label = label;
  304. return tmp;
  305. }
  306. Statement *makeDelStatement(Statement *var, fline line, char *file_dir) {
  307. Statement *tmp = makeStatement(line, file_dir);
  308. tmp->type = del_;
  309. tmp->u.del_.var = var;
  310. return tmp;
  311. }
  312. void connectStatement(Statement *base, Statement *new){
  313. for (PASS; base->next != NULL; base = base->next)
  314. PASS;
  315. base->next = new;
  316. }
  317. void freeStatement(Statement *st){
  318. Statement *next_tmp = NULL;
  319. FREE_BASE(st, return_);
  320. for (PASS; st != NULL; st = next_tmp){
  321. next_tmp = st->next;
  322. switch (st->type) {
  323. case operation:
  324. freeStatement(st->u.operation.right);
  325. freeStatement(st->u.operation.left);
  326. break;
  327. case base_value:
  328. if (st->u.base_value.type == link_value)
  329. gc_freeStatementLink(&st->u.base_value.value->gc_status);
  330. else
  331. memFree(st->u.base_value.str);
  332. break;
  333. case base_var:
  334. memFree(st->u.base_var.name);
  335. freeStatement(st->u.base_var.times);
  336. break;
  337. case del_:
  338. freeStatement(st->u.del_.var);
  339. break;
  340. case base_svar:
  341. freeStatement(st->u.base_svar.name);
  342. freeStatement(st->u.base_svar.times);
  343. break;
  344. case base_lambda:
  345. freeStatement(st->u.base_lambda.function);
  346. freeParameter(st->u.base_lambda.parameter, true);
  347. break;
  348. case set_function:
  349. freeStatement(st->u.set_function.name);
  350. freeStatement(st->u.set_function.function);
  351. freeParameter(st->u.set_function.parameter, true);
  352. freeDecorationStatement(st->u.set_function.decoration);
  353. freeStatement(st->u.set_function.first_do);
  354. break;
  355. case set_class:
  356. freeStatement(st->u.set_class.name);
  357. freeStatement(st->u.set_class.st);
  358. freeParameter(st->u.set_class.father, true);
  359. freeDecorationStatement(st->u.set_class.decoration);
  360. break;
  361. case call_function:
  362. freeStatement(st->u.call_function.function);
  363. freeParameter(st->u.call_function.parameter, true);
  364. break;
  365. case slice_:
  366. freeStatement(st->u.slice_.element);
  367. freeParameter(st->u.slice_.index, true);
  368. break;
  369. case base_list:
  370. freeParameter(st->u.base_list.list, true);
  371. break;
  372. case base_dict:
  373. freeParameter(st->u.base_dict.dict, true);
  374. break;
  375. case if_branch:
  376. freeStatementList(st->u.if_branch.if_list);
  377. freeStatement(st->u.if_branch.finally);
  378. freeStatement(st->u.if_branch.else_list);
  379. break;
  380. case while_branch:
  381. freeStatementList(st->u.while_branch.while_list);
  382. freeStatement(st->u.while_branch.first);
  383. freeStatement(st->u.while_branch.after);
  384. freeStatement(st->u.while_branch.else_list);
  385. freeStatement(st->u.while_branch.finally);
  386. break;
  387. case for_branch:
  388. freeStatementList(st->u.for_branch.for_list);
  389. freeStatement(st->u.for_branch.after_do);
  390. freeStatement(st->u.for_branch.first_do);
  391. freeStatement(st->u.for_branch.else_list);
  392. freeStatement(st->u.for_branch.finally);
  393. break;
  394. case try_branch:
  395. freeStatementList(st->u.try_branch.except_list);
  396. freeStatement(st->u.try_branch.try);
  397. freeStatement(st->u.try_branch.else_list);
  398. freeStatement(st->u.try_branch.finally);
  399. break;
  400. case with_branch:
  401. freeStatementList(st->u.with_branch.with_list);
  402. freeStatement(st->u.with_branch.else_list);
  403. freeStatement(st->u.with_branch.finally);
  404. break;
  405. case break_cycle:
  406. freeStatement(st->u.break_cycle.times);
  407. break;
  408. case continue_cycle:
  409. freeStatement(st->u.continue_cycle.times);
  410. break;
  411. case rego_if:
  412. freeStatement(st->u.rego_if.times);
  413. break;
  414. case restart:
  415. freeStatement(st->u.restart.times);
  416. break;
  417. case return_code:
  418. freeStatement(st->u.return_code.value);
  419. break;
  420. case yield_code:
  421. freeStatement(st->u.yield_code.value);
  422. break;
  423. case raise_code:
  424. freeStatement(st->u.raise_code.value);
  425. break;
  426. case include_file:
  427. freeStatement(st->u.include_file.file);
  428. break;
  429. case import_file:
  430. freeStatement(st->u.import_file.file);
  431. freeStatement(st->u.import_file.as);
  432. break;
  433. case from_import_file:
  434. freeStatement(st->u.from_import_file.file);
  435. freeParameter(st->u.from_import_file.as, true);
  436. freeParameter(st->u.from_import_file.pt, true);
  437. break;
  438. case default_var:
  439. freeParameter(st->u.default_var.var, true);
  440. break;
  441. case assert:
  442. freeStatement(st->u.assert.conditions);
  443. break;
  444. case label_:
  445. freeStatement(st->u.label_.command);
  446. freeStatement(st->u.label_.as);
  447. memFree(st->u.label_.label);
  448. break;
  449. case goto_:
  450. freeStatement(st->u.goto_.return_);
  451. freeStatement(st->u.goto_.times);
  452. freeStatement(st->u.goto_.label);
  453. break;
  454. default:
  455. break;
  456. }
  457. freeRunInfo(st);
  458. memFree(st->code_file);
  459. memFree(st);
  460. }
  461. return_:
  462. return;
  463. }
  464. Statement *copyStatement(Statement *st){
  465. Statement *base_tmp = NULL;
  466. Statement **tmp = &base_tmp;
  467. for (PASS; st != NULL; st = st->next, tmp = &(*tmp)->next)
  468. *tmp = copyStatementCore(st);
  469. return base_tmp;
  470. }
  471. Statement *copyStatementCore(Statement *st){
  472. Statement *new = makeStatement(st->line, st->code_file);
  473. new->type = st->type;
  474. new->aut = st->aut;
  475. new->next = NULL;
  476. switch (st->type) {
  477. case base_value:
  478. new->u.base_value.type = st->u.base_value.type;
  479. new->u.base_value.value = NULL;
  480. new->u.base_value.str = NULL;
  481. if (new->u.base_value.type == link_value) {
  482. new->u.base_value.value = st->u.base_value.value;
  483. gc_addStatementLink(&new->u.base_value.value->gc_status);
  484. }
  485. else if (new->u.base_value.type == string_str || new->u.base_value.type == number_str)
  486. new->u.base_value.str = memStrcpy(st->u.base_value.str);
  487. break;
  488. case operation:
  489. new->u.operation.OperationType = st->u.operation.OperationType;
  490. new->u.operation.right = copyStatement(st->u.operation.right);
  491. new->u.operation.left = copyStatement(st->u.operation.left);
  492. break;
  493. case base_var:
  494. new->u.base_var.name = memStrcpy(st->u.base_var.name);
  495. new->u.base_var.times = copyStatement(st->u.base_var.times);
  496. break;
  497. case del_:
  498. new->u.del_.var = copyStatement(st->u.del_.var);
  499. break;
  500. case base_svar:
  501. new->u.base_svar.name = copyStatement(st->u.base_svar.name);
  502. new->u.base_svar.times = copyStatement(st->u.base_svar.times);
  503. break;
  504. case base_lambda:
  505. new->u.base_lambda.function = copyStatement(st->u.base_lambda.function);
  506. new->u.base_lambda.parameter = copyParameter(st->u.base_lambda.parameter);
  507. break;
  508. case set_function:
  509. new->u.set_function.name = copyStatement(st->u.set_function.name);
  510. new->u.set_function.function = copyStatement(st->u.set_function.function);
  511. new->u.set_function.parameter = copyParameter(st->u.set_function.parameter);
  512. new->u.set_function.decoration = copyDecorationStatement(st->u.set_function.decoration);
  513. new->u.set_function.first_do = copyStatement(st->u.set_function.first_do);
  514. break;
  515. case set_class:
  516. new->u.set_class.name = copyStatement(st->u.set_class.name);
  517. new->u.set_class.st = copyStatement(st->u.set_class.st);
  518. new->u.set_class.father = copyParameter(st->u.set_class.father);
  519. new->u.set_class.decoration = copyDecorationStatement(st->u.set_class.decoration);
  520. break;
  521. case call_function:
  522. new->u.call_function.function = copyStatement(st->u.call_function.function);
  523. new->u.call_function.parameter = copyParameter(st->u.call_function.parameter);
  524. break;
  525. case slice_:
  526. new->u.slice_.element = copyStatement(st->u.slice_.element);
  527. new->u.slice_.index = copyParameter(st->u.slice_.index);
  528. break;
  529. case base_list:
  530. new->u.base_list.type = st->u.base_list.type;
  531. new->u.base_list.list = copyParameter(st->u.base_list.list);
  532. break;
  533. case base_dict:
  534. new->u.base_dict.dict = copyParameter(st->u.base_dict.dict);
  535. break;
  536. case if_branch:
  537. new->u.if_branch.if_list = copyStatementList(st->u.if_branch.if_list);
  538. new->u.if_branch.finally = copyStatement(st->u.if_branch.finally);
  539. new->u.if_branch.else_list = copyStatement(st->u.if_branch.else_list);
  540. break;
  541. case while_branch:
  542. new->u.while_branch.type = st->u.while_branch.type;
  543. new->u.while_branch.while_list = copyStatementList(st->u.while_branch.while_list);
  544. new->u.while_branch.first = copyStatement(st->u.while_branch.first);
  545. new->u.while_branch.after = copyStatement(st->u.while_branch.after);
  546. new->u.while_branch.else_list = copyStatement(st->u.while_branch.else_list);
  547. new->u.while_branch.finally = copyStatement(st->u.while_branch.finally);
  548. break;
  549. case for_branch:
  550. new->u.for_branch.for_list = copyStatementList(st->u.for_branch.for_list);
  551. new->u.for_branch.after_do = copyStatement(st->u.for_branch.after_do);
  552. new->u.for_branch.first_do = copyStatement(st->u.for_branch.first_do);
  553. new->u.for_branch.else_list = copyStatement(st->u.for_branch.else_list);
  554. new->u.for_branch.finally = copyStatement(st->u.for_branch.finally);
  555. break;
  556. case try_branch:
  557. new->u.try_branch.except_list = copyStatementList(st->u.try_branch.except_list);
  558. new->u.try_branch.try = copyStatement(st->u.try_branch.try);
  559. new->u.try_branch.else_list = copyStatement(st->u.try_branch.else_list);
  560. new->u.try_branch.finally = copyStatement(st->u.try_branch.finally);
  561. break;
  562. case with_branch:
  563. new->u.with_branch.with_list = copyStatementList(st->u.with_branch.with_list);
  564. new->u.with_branch.else_list = copyStatement(st->u.with_branch.else_list);
  565. new->u.with_branch.finally = copyStatement(st->u.with_branch.finally);
  566. break;
  567. case break_cycle:
  568. new->u.break_cycle.times = copyStatement(st->u.break_cycle.times);
  569. break;
  570. case continue_cycle:
  571. new->u.continue_cycle.times = copyStatement(st->u.continue_cycle.times);
  572. break;
  573. case rego_if:
  574. new->u.rego_if.times = copyStatement(st->u.rego_if.times);
  575. break;
  576. case restart:
  577. new->u.restart.times = copyStatement(st->u.restart.times);
  578. break;
  579. case return_code:
  580. new->u.return_code.value = copyStatement(st->u.return_code.value);
  581. break;
  582. case yield_code:
  583. new->u.yield_code.value = copyStatement(st->u.yield_code.value);
  584. break;
  585. case raise_code:
  586. new->u.raise_code.value = copyStatement(st->u.raise_code.value);
  587. break;
  588. case include_file:
  589. new->u.include_file.file = copyStatement(st->u.include_file.file);
  590. break;
  591. case import_file:
  592. new->u.import_file.file = copyStatement(st->u.import_file.file);
  593. new->u.import_file.as = copyStatement(st->u.import_file.as);
  594. break;
  595. case from_import_file:
  596. new->u.from_import_file.file = copyStatement(st->u.from_import_file.file);
  597. new->u.from_import_file.as = copyParameter(st->u.from_import_file.as);
  598. new->u.from_import_file.pt = copyParameter(st->u.from_import_file.pt);
  599. break;
  600. case default_var:
  601. new->u.default_var.var = copyParameter(st->u.default_var.var);
  602. break;
  603. case assert:
  604. new->u.assert.conditions = copyStatement(st->u.assert.conditions);
  605. break;
  606. case label_:
  607. new->u.label_.command = copyStatement(st->u.label_.command);
  608. new->u.label_.as = copyStatement(st->u.label_.as);
  609. new->u.label_.label = memStrcpy(st->u.label_.label);
  610. break;
  611. case goto_:
  612. new->u.goto_.times = copyStatement(st->u.goto_.times);
  613. new->u.goto_.return_ = copyStatement(st->u.goto_.return_);
  614. new->u.goto_.label = copyStatement(st->u.goto_.label);
  615. break;
  616. default:
  617. break;
  618. }
  619. return new;
  620. }
  621. StatementList *makeStatementList(Statement *condition, Statement *var, Statement *code, int type) {
  622. StatementList *tmp = memCalloc(1, sizeof(StatementList));
  623. tmp->condition = condition;
  624. tmp->var = var;
  625. tmp->code = code;
  626. tmp->type = type;
  627. tmp->next = NULL;
  628. return tmp;
  629. }
  630. StatementList *connectStatementList(StatementList *base, StatementList *new){
  631. StatementList **tmp = &base;
  632. for (PASS; *tmp != NULL; tmp = &(*tmp)->next)
  633. PASS;
  634. *tmp = new;
  635. return base;
  636. }
  637. void freeStatementList(StatementList *base){
  638. StatementList *next = NULL;
  639. for (PASS; base != NULL; base = next){
  640. next = base->next;
  641. freeStatement(base->condition);
  642. freeStatement(base->code);
  643. freeStatement(base->var);
  644. memFree(base);
  645. }
  646. }
  647. StatementList *copyStatementList(StatementList *sl){
  648. StatementList *base_tmp = NULL;
  649. StatementList **tmp = &base_tmp;
  650. for (PASS; sl != NULL; sl = sl->next, tmp = &(*tmp)->next)
  651. *tmp = makeStatementList(copyStatement(sl->condition), copyStatement(sl->var), copyStatement(sl->code), sl->type);
  652. return base_tmp;
  653. }
  654. DecorationStatement *makeDecorationStatement(){
  655. DecorationStatement *tmp;
  656. tmp = memCalloc(1, sizeof(DecorationStatement));
  657. tmp->decoration = NULL;
  658. tmp->next = NULL;
  659. return tmp;
  660. }
  661. DecorationStatement *connectDecorationStatement(Statement *decoration, DecorationStatement *base){
  662. DecorationStatement *tmp = makeDecorationStatement();
  663. tmp->decoration = decoration;
  664. tmp->next = base;
  665. return tmp;
  666. }
  667. void freeDecorationStatement(DecorationStatement *base){
  668. for (DecorationStatement *next; base != NULL; base = next) {
  669. next = base->next;
  670. freeStatement(base->decoration);
  671. memFree(base);
  672. }
  673. }
  674. DecorationStatement *copyDecorationStatement(DecorationStatement *ds){
  675. DecorationStatement *base = NULL;
  676. DecorationStatement **tmp = &base;
  677. for (PASS; ds != NULL; tmp = &(*tmp)->next, ds = ds->next)
  678. *tmp = copyDecorationStatementCore(ds);
  679. return base;
  680. }
  681. DecorationStatement *copyDecorationStatementCore(DecorationStatement *base){
  682. DecorationStatement *tmp = makeDecorationStatement();
  683. tmp->decoration = copyStatement(base->decoration);
  684. return tmp;
  685. }