statement.c 24 KB

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