2
0

nutils.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Type checking and register allocation for inline nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nutils;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globals,
  22. symtype,symsym,node;
  23. const
  24. NODE_COMPLEXITY_INF = 255;
  25. type
  26. { resultdef of functions that process on all nodes in a (sub)tree }
  27. foreachnoderesult = (
  28. { false, continue recursion }
  29. fen_false,
  30. { false, stop recursion }
  31. fen_norecurse_false,
  32. { true, continue recursion }
  33. fen_true,
  34. { true, stop recursion }
  35. fen_norecurse_true
  36. );
  37. tforeachprocmethod = (pm_preprocess,pm_postprocess);
  38. foreachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult of object;
  39. staticforeachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult;
  40. function foreachnode(var n: tnode; f: foreachnodefunction; arg: pointer): boolean;
  41. function foreachnodestatic(var n: tnode; f: staticforeachnodefunction; arg: pointer): boolean;
  42. function foreachnodestatic(procmethod : tforeachprocmethod;var n: tnode; f: staticforeachnodefunction; arg: pointer): boolean;
  43. { checks if the given node tree contains only nodes of the given type,
  44. if this isn't the case, an ie is thrown
  45. }
  46. procedure checktreenodetypes(n : tnode;typeset : tnodetypeset);
  47. procedure load_procvar_from_calln(var p1:tnode);
  48. function maybe_call_procvar(var p1:tnode;tponly:boolean):boolean;
  49. function get_high_value_sym(vs: tparavarsym):tsym; { marking it as inline causes IE 200311075 during loading from ppu file }
  50. function load_high_value_node(vs:tparavarsym):tnode;
  51. function load_self_node:tnode;
  52. function load_result_node:tnode;
  53. function load_self_pointer_node:tnode;
  54. function load_vmt_pointer_node:tnode;
  55. function is_self_node(p:tnode):boolean;
  56. function call_fail_node:tnode;
  57. function initialize_data_node(p:tnode):tnode;
  58. function finalize_data_node(p:tnode):tnode;
  59. function node_complexity(p: tnode): cardinal;
  60. procedure node_tree_set_filepos(var n:tnode;const filepos:tfileposinfo);
  61. { tries to simplify the given node }
  62. procedure dosimplify(var n : tnode);
  63. implementation
  64. uses
  65. globtype,verbose,
  66. symconst,symbase,symdef,symtable,
  67. defutil,defcmp,
  68. nbas,ncon,ncnv,nld,nflw,nset,ncal,nadd,nmem,
  69. cgbase,procinfo,
  70. pass_1;
  71. function foreachnode(var n: tnode; f: foreachnodefunction; arg: pointer): boolean;
  72. var
  73. i: longint;
  74. begin
  75. result := false;
  76. if not assigned(n) then
  77. exit;
  78. case f(n,arg) of
  79. fen_norecurse_false:
  80. exit;
  81. fen_norecurse_true:
  82. begin
  83. result := true;
  84. exit;
  85. end;
  86. fen_true:
  87. result := true;
  88. { result is already false
  89. fen_false:
  90. result := false; }
  91. end;
  92. case n.nodetype of
  93. asn:
  94. if assigned(tasnode(n).call) then
  95. begin
  96. result := foreachnode(tasnode(n).call,f,arg);
  97. exit
  98. end;
  99. calln:
  100. begin
  101. { not in one statement, won't work because of b- }
  102. result := foreachnode(tcallnode(n).methodpointerinit,f,arg) or result;
  103. result := foreachnode(tcallnode(n).methodpointer,f,arg) or result;
  104. result := foreachnode(tcallnode(n)._funcretnode,f,arg) or result;
  105. result := foreachnode(tcallnode(n).methodpointerdone,f,arg) or result;
  106. end;
  107. ifn, whilerepeatn, forn, tryexceptn, tryfinallyn:
  108. begin
  109. { not in one statement, won't work because of b- }
  110. result := foreachnode(tloopnode(n).t1,f,arg) or result;
  111. result := foreachnode(tloopnode(n).t2,f,arg) or result;
  112. end;
  113. raisen:
  114. result := foreachnode(traisenode(n).frametree,f,arg) or result;
  115. casen:
  116. begin
  117. for i := 0 to tcasenode(n).blocks.count-1 do
  118. if assigned(tcasenode(n).blocks[i]) then
  119. result := foreachnode(pcaseblock(tcasenode(n).blocks[i])^.statement,f,arg) or result;
  120. result := foreachnode(tcasenode(n).elseblock,f,arg) or result;
  121. end;
  122. end;
  123. if n.inheritsfrom(tbinarynode) then
  124. begin
  125. { first process the "payload" of statementnodes }
  126. result := foreachnode(tbinarynode(n).left,f,arg) or result;
  127. result := foreachnode(tbinarynode(n).right,f,arg) or result;
  128. end
  129. else if n.inheritsfrom(tunarynode) then
  130. result := foreachnode(tunarynode(n).left,f,arg) or result;
  131. end;
  132. function foreachnodestatic(procmethod : tforeachprocmethod;var n: tnode; f: staticforeachnodefunction; arg: pointer): boolean;
  133. function process_children(res : boolean) : boolean;
  134. var
  135. i: longint;
  136. begin
  137. result:=res;
  138. case n.nodetype of
  139. asn:
  140. if assigned(tasnode(n).call) then
  141. begin
  142. result := foreachnodestatic(procmethod,tasnode(n).call,f,arg);
  143. exit
  144. end;
  145. calln:
  146. begin
  147. result := foreachnodestatic(procmethod,tcallnode(n).methodpointerinit,f,arg) or result;
  148. result := foreachnodestatic(procmethod,tcallnode(n).methodpointer,f,arg) or result;
  149. result := foreachnodestatic(procmethod,tcallnode(n)._funcretnode,f,arg) or result;
  150. result := foreachnodestatic(procmethod,tcallnode(n).methodpointerdone,f,arg) or result;
  151. end;
  152. ifn, whilerepeatn, forn, tryexceptn, tryfinallyn:
  153. begin
  154. { not in one statement, won't work because of b- }
  155. result := foreachnodestatic(procmethod,tloopnode(n).t1,f,arg) or result;
  156. result := foreachnodestatic(procmethod,tloopnode(n).t2,f,arg) or result;
  157. end;
  158. raisen:
  159. result := foreachnodestatic(traisenode(n).frametree,f,arg) or result;
  160. casen:
  161. begin
  162. for i := 0 to tcasenode(n).blocks.count-1 do
  163. if assigned(tcasenode(n).blocks[i]) then
  164. result := foreachnodestatic(procmethod,pcaseblock(tcasenode(n).blocks[i])^.statement,f,arg) or result;
  165. result := foreachnodestatic(procmethod,tcasenode(n).elseblock,f,arg) or result;
  166. end;
  167. end;
  168. if n.inheritsfrom(tbinarynode) then
  169. begin
  170. { first process the "payload" of statementnodes }
  171. result := foreachnodestatic(procmethod,tbinarynode(n).left,f,arg) or result;
  172. result := foreachnodestatic(procmethod,tbinarynode(n).right,f,arg) or result;
  173. end
  174. else if n.inheritsfrom(tunarynode) then
  175. result := foreachnodestatic(procmethod,tunarynode(n).left,f,arg) or result;
  176. end;
  177. begin
  178. result := false;
  179. if not assigned(n) then
  180. exit;
  181. if procmethod=pm_preprocess then
  182. result:=process_children(result);
  183. case f(n,arg) of
  184. fen_norecurse_false:
  185. exit;
  186. fen_norecurse_true:
  187. begin
  188. result := true;
  189. exit;
  190. end;
  191. fen_true:
  192. result := true;
  193. { result is already false
  194. fen_false:
  195. result := false; }
  196. end;
  197. if procmethod=pm_postprocess then
  198. result:=process_children(result);
  199. end;
  200. function foreachnodestatic(var n: tnode; f: staticforeachnodefunction; arg: pointer): boolean;
  201. begin
  202. result:=foreachnodestatic(pm_postprocess,n,f,arg);
  203. end;
  204. function do_check(var n: tnode; arg: pointer): foreachnoderesult;
  205. begin
  206. if not(n.nodetype in pnodetypeset(arg)^) then
  207. internalerror(200610141);
  208. result:=fen_true;
  209. end;
  210. procedure checktreenodetypes(n : tnode;typeset : tnodetypeset);
  211. begin
  212. foreachnodestatic(n,@do_check,@typeset);
  213. end;
  214. procedure load_procvar_from_calln(var p1:tnode);
  215. var
  216. p2 : tnode;
  217. begin
  218. if p1.nodetype<>calln then
  219. internalerror(200212251);
  220. { was it a procvar, then we simply remove the calln and
  221. reuse the right }
  222. if assigned(tcallnode(p1).right) then
  223. begin
  224. p2:=tcallnode(p1).right;
  225. tcallnode(p1).right:=nil;
  226. end
  227. else
  228. begin
  229. p2:=cloadnode.create_procvar(tcallnode(p1).symtableprocentry,
  230. tprocdef(tcallnode(p1).procdefinition),tcallnode(p1).symtableproc);
  231. { when the methodpointer is typen we've something like:
  232. tobject.create. Then only the address is needed of the
  233. method without a self pointer }
  234. if assigned(tcallnode(p1).methodpointer) and
  235. (tcallnode(p1).methodpointer.nodetype<>typen) then
  236. tloadnode(p2).set_mp(tcallnode(p1).get_load_methodpointer);
  237. end;
  238. typecheckpass(p2);
  239. p1.free;
  240. p1:=p2;
  241. end;
  242. function maybe_call_procvar(var p1:tnode;tponly:boolean):boolean;
  243. var
  244. hp : tnode;
  245. begin
  246. result:=false;
  247. if (p1.resultdef.typ<>procvardef) or
  248. (tponly and
  249. not(m_tp_procvar in current_settings.modeswitches)) then
  250. exit;
  251. { ignore vecn,subscriptn }
  252. hp:=p1;
  253. repeat
  254. case hp.nodetype of
  255. vecn,
  256. derefn,
  257. typeconvn,
  258. subscriptn :
  259. hp:=tunarynode(hp).left;
  260. else
  261. break;
  262. end;
  263. until false;
  264. { a tempref is used when it is loaded from a withsymtable }
  265. if (hp.nodetype in [calln,loadn,temprefn]) then
  266. begin
  267. hp:=ccallnode.create_procvar(nil,p1);
  268. typecheckpass(hp);
  269. p1:=hp;
  270. result:=true;
  271. end;
  272. end;
  273. function get_high_value_sym(vs: tparavarsym):tsym;
  274. begin
  275. result := tsym(vs.owner.Find('high'+vs.name));
  276. end;
  277. function get_local_or_para_sym(const aname:string):tsym;
  278. var
  279. pd : tprocdef;
  280. begin
  281. { we can't use searchsym here, because the
  282. symtablestack is not fully setup when pass1
  283. is run for nested procedures }
  284. pd:=current_procinfo.procdef;
  285. repeat
  286. result := tsym(pd.localst.Find(aname));
  287. if assigned(result) then
  288. break;
  289. result := tsym(pd.parast.Find(aname));
  290. if assigned(result) then
  291. break;
  292. { try the parent of a nested function }
  293. if assigned(pd.owner.defowner) and
  294. (pd.owner.defowner.typ=procdef) then
  295. pd:=tprocdef(pd.owner.defowner)
  296. else
  297. break;
  298. until false;
  299. end;
  300. function load_high_value_node(vs:tparavarsym):tnode;
  301. var
  302. srsym : tsym;
  303. begin
  304. result:=nil;
  305. srsym:=get_high_value_sym(vs);
  306. if assigned(srsym) then
  307. begin
  308. result:=cloadnode.create(srsym,vs.owner);
  309. typecheckpass(result);
  310. end
  311. else
  312. CGMessage(parser_e_illegal_expression);
  313. end;
  314. function load_self_node:tnode;
  315. var
  316. srsym : tsym;
  317. begin
  318. result:=nil;
  319. srsym:=get_local_or_para_sym('self');
  320. if assigned(srsym) then
  321. begin
  322. result:=cloadnode.create(srsym,srsym.owner);
  323. include(result.flags,nf_is_self);
  324. end
  325. else
  326. begin
  327. result:=cerrornode.create;
  328. CGMessage(parser_e_illegal_expression);
  329. end;
  330. typecheckpass(result);
  331. end;
  332. function load_result_node:tnode;
  333. var
  334. srsym : tsym;
  335. begin
  336. result:=nil;
  337. srsym:=get_local_or_para_sym('result');
  338. if assigned(srsym) then
  339. result:=cloadnode.create(srsym,srsym.owner)
  340. else
  341. begin
  342. result:=cerrornode.create;
  343. CGMessage(parser_e_illegal_expression);
  344. end;
  345. typecheckpass(result);
  346. end;
  347. function load_self_pointer_node:tnode;
  348. var
  349. srsym : tsym;
  350. begin
  351. result:=nil;
  352. srsym:=get_local_or_para_sym('self');
  353. if assigned(srsym) then
  354. begin
  355. result:=cloadnode.create(srsym,srsym.owner);
  356. include(result.flags,nf_load_self_pointer);
  357. end
  358. else
  359. begin
  360. result:=cerrornode.create;
  361. CGMessage(parser_e_illegal_expression);
  362. end;
  363. typecheckpass(result);
  364. end;
  365. function load_vmt_pointer_node:tnode;
  366. var
  367. srsym : tsym;
  368. begin
  369. result:=nil;
  370. srsym:=get_local_or_para_sym('vmt');
  371. if assigned(srsym) then
  372. result:=cloadnode.create(srsym,srsym.owner)
  373. else
  374. begin
  375. result:=cerrornode.create;
  376. CGMessage(parser_e_illegal_expression);
  377. end;
  378. typecheckpass(result);
  379. end;
  380. function is_self_node(p:tnode):boolean;
  381. begin
  382. is_self_node:=(p.nodetype=loadn) and
  383. (tloadnode(p).symtableentry.typ=paravarsym) and
  384. (vo_is_self in tparavarsym(tloadnode(p).symtableentry).varoptions);
  385. end;
  386. function call_fail_node:tnode;
  387. var
  388. para : tcallparanode;
  389. newstatement : tstatementnode;
  390. srsym : tsym;
  391. begin
  392. result:=internalstatements(newstatement);
  393. { call fail helper and exit normal }
  394. if is_class(current_procinfo.procdef._class) then
  395. begin
  396. srsym:=search_class_member(current_procinfo.procdef._class,'FREEINSTANCE');
  397. if assigned(srsym) and
  398. (srsym.typ=procsym) then
  399. begin
  400. { if self<>0 and vmt<>0 then freeinstance }
  401. addstatement(newstatement,cifnode.create(
  402. caddnode.create(andn,
  403. caddnode.create(unequaln,
  404. load_self_pointer_node,
  405. cnilnode.create),
  406. caddnode.create(unequaln,
  407. load_vmt_pointer_node,
  408. cnilnode.create)),
  409. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  410. nil));
  411. end
  412. else
  413. internalerror(200305108);
  414. end
  415. else
  416. if is_object(current_procinfo.procdef._class) then
  417. begin
  418. { parameter 3 : vmt_offset }
  419. { parameter 2 : pointer to vmt }
  420. { parameter 1 : self pointer }
  421. para:=ccallparanode.create(
  422. cordconstnode.create(current_procinfo.procdef._class.vmt_offset,s32inttype,false),
  423. ccallparanode.create(
  424. ctypeconvnode.create_internal(
  425. load_vmt_pointer_node,
  426. voidpointertype),
  427. ccallparanode.create(
  428. ctypeconvnode.create_internal(
  429. load_self_pointer_node,
  430. voidpointertype),
  431. nil)));
  432. addstatement(newstatement,
  433. ccallnode.createintern('fpc_help_fail',para));
  434. end
  435. else
  436. internalerror(200305132);
  437. { self:=nil }
  438. addstatement(newstatement,cassignmentnode.create(
  439. load_self_pointer_node,
  440. cnilnode.create));
  441. { exit }
  442. addstatement(newstatement,cexitnode.create(nil));
  443. end;
  444. function initialize_data_node(p:tnode):tnode;
  445. begin
  446. if not assigned(p.resultdef) then
  447. typecheckpass(p);
  448. if is_ansistring(p.resultdef) or
  449. is_widestring(p.resultdef) or
  450. is_interfacecom(p.resultdef) or
  451. is_dynamic_array(p.resultdef) then
  452. begin
  453. result:=cassignmentnode.create(
  454. ctypeconvnode.create_internal(p,voidpointertype),
  455. cnilnode.create
  456. );
  457. end
  458. else
  459. begin
  460. result:=ccallnode.createintern('fpc_initialize',
  461. ccallparanode.create(
  462. caddrnode.create_internal(
  463. crttinode.create(
  464. tstoreddef(p.resultdef),initrtti)),
  465. ccallparanode.create(
  466. caddrnode.create_internal(p),
  467. nil)));
  468. end;
  469. end;
  470. function finalize_data_node(p:tnode):tnode;
  471. var
  472. newstatement : tstatementnode;
  473. begin
  474. if not assigned(p.resultdef) then
  475. typecheckpass(p);
  476. if is_ansistring(p.resultdef) then
  477. begin
  478. result:=internalstatements(newstatement);
  479. addstatement(newstatement,ccallnode.createintern('fpc_ansistr_decr_ref',
  480. ccallparanode.create(
  481. ctypeconvnode.create_internal(p,voidpointertype),
  482. nil)));
  483. addstatement(newstatement,cassignmentnode.create(
  484. ctypeconvnode.create_internal(p.getcopy,voidpointertype),
  485. cnilnode.create
  486. ));
  487. end
  488. else if is_widestring(p.resultdef) then
  489. begin
  490. result:=internalstatements(newstatement);
  491. addstatement(newstatement,ccallnode.createintern('fpc_widestr_decr_ref',
  492. ccallparanode.create(
  493. ctypeconvnode.create_internal(p,voidpointertype),
  494. nil)));
  495. addstatement(newstatement,cassignmentnode.create(
  496. ctypeconvnode.create_internal(p.getcopy,voidpointertype),
  497. cnilnode.create
  498. ));
  499. end
  500. else if is_interfacecom(p.resultdef) then
  501. begin
  502. result:=internalstatements(newstatement);
  503. addstatement(newstatement,ccallnode.createintern('fpc_intf_decr_ref',
  504. ccallparanode.create(
  505. ctypeconvnode.create_internal(p,voidpointertype),
  506. nil)));
  507. addstatement(newstatement,cassignmentnode.create(
  508. ctypeconvnode.create_internal(p.getcopy,voidpointertype),
  509. cnilnode.create
  510. ));
  511. end
  512. else
  513. result:=ccallnode.createintern('fpc_finalize',
  514. ccallparanode.create(
  515. caddrnode.create_internal(
  516. crttinode.create(
  517. tstoreddef(p.resultdef),initrtti)),
  518. ccallparanode.create(
  519. caddrnode.create_internal(p),
  520. nil)));
  521. end;
  522. { this function must return a very high value ("infinity") for }
  523. { trees containing a call, the rest can be balanced more or less }
  524. { at will, probably best mainly in terms of required memory }
  525. { accesses }
  526. function node_complexity(p: tnode): cardinal;
  527. begin
  528. result := 0;
  529. while assigned(p) do
  530. begin
  531. case p.nodetype of
  532. temprefn,
  533. loadvmtaddrn,
  534. { main reason for the next one: we can't take the address of }
  535. { loadparentfpnode, so replacing it by a temp which is the }
  536. { address of this node's location and then dereferencing }
  537. { doesn't work. If changed, check whether webtbs/tw0935 }
  538. { still works with nodeinlining (JM) }
  539. loadparentfpn:
  540. begin
  541. result := 1;
  542. exit;
  543. end;
  544. loadn:
  545. begin
  546. { threadvars need a helper call }
  547. if (tloadnode(p).symtableentry.typ=staticvarsym) and
  548. (vo_is_thread_var in tstaticvarsym(tloadnode(p).symtableentry).varoptions) then
  549. inc(result,5)
  550. else
  551. inc(result);
  552. if (result >= NODE_COMPLEXITY_INF) then
  553. result := NODE_COMPLEXITY_INF;
  554. exit;
  555. end;
  556. subscriptn,
  557. blockn,
  558. callparan:
  559. p := tunarynode(p).left;
  560. derefn :
  561. begin
  562. inc(result);
  563. if (result = NODE_COMPLEXITY_INF) then
  564. exit;
  565. p := tunarynode(p).left;
  566. end;
  567. typeconvn:
  568. begin
  569. { may be more complex in some cases }
  570. if not(ttypeconvnode(p).convtype in [tc_equal,tc_int_2_int,tc_bool_2_bool,tc_real_2_real,tc_cord_2_pointer]) then
  571. inc(result);
  572. if (result = NODE_COMPLEXITY_INF) then
  573. exit;
  574. p := tunarynode(p).left;
  575. end;
  576. vecn,
  577. statementn:
  578. begin
  579. inc(result,node_complexity(tbinarynode(p).left));
  580. if (result >= NODE_COMPLEXITY_INF) then
  581. begin
  582. result := NODE_COMPLEXITY_INF;
  583. exit;
  584. end;
  585. p := tbinarynode(p).right;
  586. end;
  587. { better: make muln/divn/modn more expensive }
  588. addn,subn,orn,andn,xorn,muln,divn,modn,symdifn,
  589. assignn:
  590. begin
  591. inc(result,node_complexity(tbinarynode(p).left)+1);
  592. if (result >= NODE_COMPLEXITY_INF) then
  593. begin
  594. result := NODE_COMPLEXITY_INF;
  595. exit;
  596. end;
  597. p := tbinarynode(p).right;
  598. end;
  599. tempcreaten,
  600. tempdeleten,
  601. ordconstn,
  602. pointerconstn,
  603. nothingn,
  604. niln:
  605. exit;
  606. else
  607. begin
  608. result := NODE_COMPLEXITY_INF;
  609. exit;
  610. end;
  611. end;
  612. end;
  613. end;
  614. function setnodefilepos(var n: tnode; arg: pointer): foreachnoderesult;
  615. begin
  616. result:=fen_true;
  617. n.fileinfo:=pfileposinfo(arg)^;
  618. end;
  619. procedure node_tree_set_filepos(var n:tnode;const filepos:tfileposinfo);
  620. begin
  621. foreachnodestatic(n,@setnodefilepos,@filepos);
  622. end;
  623. {$ifdef FPCMT}
  624. threadvar
  625. {$else FPCMT}
  626. var
  627. {$endif FPCMT}
  628. treechanged : boolean;
  629. function callsimplify(var n: tnode; arg: pointer): foreachnoderesult;
  630. var
  631. hn : tnode;
  632. begin
  633. result:=fen_false;
  634. // do_typecheckpass(n);
  635. hn:=n.simplify;
  636. if assigned(hn) then
  637. begin
  638. treechanged:=true;
  639. n.free;
  640. n:=hn;
  641. typecheckpass(n);
  642. end;
  643. end;
  644. { tries to simplify the given node calling the simplify method recursively }
  645. procedure dosimplify(var n : tnode);
  646. begin
  647. repeat
  648. treechanged:=false;
  649. foreachnodestatic(pm_preprocess,n,@callsimplify,nil);
  650. until not(treechanged);
  651. end;
  652. end.