nutils.pas 24 KB

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