nflw.pas 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Type checking and register allocation for nodes that influence
  4. the flow
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nflw;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. node,cpubase,
  24. symnot,
  25. symtype,symbase,symdef,symsym,
  26. optunrol;
  27. type
  28. { flags used by loop nodes }
  29. tloopflag = (
  30. { set if it is a for ... downto ... do loop }
  31. lnf_backward,
  32. { Do we need to parse childs to set var state? }
  33. lnf_varstate,
  34. { Do a test at the begin of the loop?}
  35. lnf_testatbegin,
  36. { Negate the loop test? }
  37. lnf_checknegate,
  38. { Should the value of the loop variable on exit be correct. }
  39. lnf_dont_mind_loopvar_on_exit);
  40. tloopflags = set of tloopflag;
  41. const
  42. { loop flags which must match to consider loop nodes equal regarding the flags }
  43. loopflagsequal = [lnf_backward];
  44. type
  45. tlabelnode = class;
  46. tloopnode = class(tbinarynode)
  47. t1,t2 : tnode;
  48. loopflags : tloopflags;
  49. constructor create(tt : tnodetype;l,r,_t1,_t2 : tnode);virtual;
  50. destructor destroy;override;
  51. function _getcopy : tnode;override;
  52. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  53. procedure ppuwrite(ppufile:tcompilerppufile);override;
  54. procedure buildderefimpl;override;
  55. procedure derefimpl;override;
  56. procedure insertintolist(l : tnodelist);override;
  57. procedure printnodetree(var t:text);override;
  58. function docompare(p: tnode): boolean; override;
  59. end;
  60. twhilerepeatnode = class(tloopnode)
  61. constructor create(l,r:Tnode;tab,cn:boolean);virtual;
  62. function det_resulttype:tnode;override;
  63. function pass_1 : tnode;override;
  64. {$ifdef state_tracking}
  65. function track_state_pass(exec_known:boolean):boolean;override;
  66. {$endif}
  67. end;
  68. twhilerepeatnodeclass = class of twhilerepeatnode;
  69. tifnode = class(tloopnode)
  70. constructor create(l,r,_t1 : tnode);virtual;
  71. function det_resulttype:tnode;override;
  72. function pass_1 : tnode;override;
  73. end;
  74. tifnodeclass = class of tifnode;
  75. tfornode = class(tloopnode)
  76. { if count isn divisable by unrolls then
  77. the for loop must jump to this label to get the correct
  78. number of executions }
  79. entrylabel : tnode;
  80. loopvar_notid:cardinal;
  81. constructor create(l,r,_t1,_t2 : tnode;back : boolean);virtual;
  82. procedure loop_var_access(not_type:Tnotification_flag;symbol:Tsym);
  83. function det_resulttype:tnode;override;
  84. function pass_1 : tnode;override;
  85. end;
  86. tfornodeclass = class of tfornode;
  87. texitnode = class(tunarynode)
  88. constructor create(l:tnode);virtual;
  89. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  90. procedure ppuwrite(ppufile:tcompilerppufile);override;
  91. function det_resulttype:tnode;override;
  92. function pass_1 : tnode;override;
  93. end;
  94. texitnodeclass = class of texitnode;
  95. tbreaknode = class(tnode)
  96. constructor create;virtual;
  97. function det_resulttype:tnode;override;
  98. function pass_1 : tnode;override;
  99. end;
  100. tbreaknodeclass = class of tbreaknode;
  101. tcontinuenode = class(tnode)
  102. constructor create;virtual;
  103. function det_resulttype:tnode;override;
  104. function pass_1 : tnode;override;
  105. end;
  106. tcontinuenodeclass = class of tcontinuenode;
  107. tgotonode = class(tnode)
  108. { we still need this for resolving forward gotos }
  109. labelsym : tlabelsym;
  110. labelnode : tlabelnode;
  111. exceptionblock : integer;
  112. { internlab : tinterngotolabel;}
  113. constructor create(p : tlabelnode);virtual;
  114. { as long as we don't know the label node we can't resolve it }
  115. constructor create_sym(p : tlabelsym);virtual;
  116. { constructor createintern(g:tinterngotolabel);}
  117. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  118. procedure ppuwrite(ppufile:tcompilerppufile);override;
  119. procedure buildderefimpl;override;
  120. procedure derefimpl;override;
  121. function _getcopy : tnode;override;
  122. function det_resulttype:tnode;override;
  123. function pass_1 : tnode;override;
  124. function docompare(p: tnode): boolean; override;
  125. end;
  126. tgotonodeclass = class of tgotonode;
  127. tlabelnode = class(tunarynode)
  128. exceptionblock : integer;
  129. { when copying trees, this points to the newly created copy of a label }
  130. copiedto : tlabelnode;
  131. { contains all goto nodesrefering to this label }
  132. referinggotonodes : TFPObjectList;
  133. constructor create(l:tnode);virtual;
  134. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  135. procedure ppuwrite(ppufile:tcompilerppufile);override;
  136. procedure buildderefimpl;override;
  137. procedure derefimpl;override;
  138. function _getcopy : tnode;override;
  139. function det_resulttype:tnode;override;
  140. function pass_1 : tnode;override;
  141. function docompare(p: tnode): boolean; override;
  142. end;
  143. tlabelnodeclass = class of tlabelnode;
  144. traisenode = class(tbinarynode)
  145. frametree : tnode;
  146. constructor create(l,taddr,tframe:tnode);virtual;
  147. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  148. procedure ppuwrite(ppufile:tcompilerppufile);override;
  149. procedure buildderefimpl;override;
  150. procedure derefimpl;override;
  151. function _getcopy : tnode;override;
  152. procedure insertintolist(l : tnodelist);override;
  153. function det_resulttype:tnode;override;
  154. function pass_1 : tnode;override;
  155. function docompare(p: tnode): boolean; override;
  156. end;
  157. traisenodeclass = class of traisenode;
  158. ttryexceptnode = class(tloopnode)
  159. constructor create(l,r,_t1 : tnode);virtual;
  160. function det_resulttype:tnode;override;
  161. function pass_1 : tnode;override;
  162. end;
  163. ttryexceptnodeclass = class of ttryexceptnode;
  164. ttryfinallynode = class(tloopnode)
  165. implicitframe : boolean;
  166. constructor create(l,r:tnode);virtual;
  167. constructor create_implicit(l,r,_t1:tnode);virtual;
  168. function det_resulttype:tnode;override;
  169. function pass_1 : tnode;override;
  170. end;
  171. ttryfinallynodeclass = class of ttryfinallynode;
  172. tonnode = class(tbinarynode)
  173. exceptsymtable : tsymtable;
  174. excepttype : tobjectdef;
  175. constructor create(l,r:tnode);virtual;
  176. destructor destroy;override;
  177. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  178. function det_resulttype:tnode;override;
  179. function pass_1 : tnode;override;
  180. function _getcopy : tnode;override;
  181. function docompare(p: tnode): boolean; override;
  182. end;
  183. tonnodeclass = class of tonnode;
  184. var
  185. cwhilerepeatnode : twhilerepeatnodeclass;
  186. cifnode : tifnodeclass;
  187. cfornode : tfornodeclass;
  188. cexitnode : texitnodeclass;
  189. cbreaknode : tbreaknodeclass;
  190. ccontinuenode : tcontinuenodeclass;
  191. cgotonode : tgotonodeclass;
  192. clabelnode : tlabelnodeclass;
  193. craisenode : traisenodeclass;
  194. ctryexceptnode : ttryexceptnodeclass;
  195. ctryfinallynode : ttryfinallynodeclass;
  196. connode : tonnodeclass;
  197. implementation
  198. uses
  199. globtype,systems,
  200. cutils,verbose,globals,
  201. symconst,paramgr,defcmp,defutil,htypechk,pass_1,
  202. ncal,nadd,ncon,nmem,nld,ncnv,nbas,cgobj,nutils,
  203. {$ifdef prefetchnext}
  204. ninl,
  205. {$endif prefetchnext}
  206. {$ifdef state_tracking}
  207. nstate,
  208. {$endif}
  209. cgbase,procinfo
  210. ;
  211. {****************************************************************************
  212. TLOOPNODE
  213. *****************************************************************************}
  214. constructor tloopnode.create(tt : tnodetype;l,r,_t1,_t2 : tnode);
  215. begin
  216. inherited create(tt,l,r);
  217. t1:=_t1;
  218. t2:=_t2;
  219. fileinfo:=l.fileinfo;
  220. end;
  221. destructor tloopnode.destroy;
  222. begin
  223. t1.free;
  224. t2.free;
  225. inherited destroy;
  226. end;
  227. constructor tloopnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  228. begin
  229. inherited ppuload(t,ppufile);
  230. t1:=ppuloadnode(ppufile);
  231. t2:=ppuloadnode(ppufile);
  232. end;
  233. procedure tloopnode.ppuwrite(ppufile:tcompilerppufile);
  234. begin
  235. inherited ppuwrite(ppufile);
  236. ppuwritenode(ppufile,t1);
  237. ppuwritenode(ppufile,t2);
  238. end;
  239. procedure tloopnode.buildderefimpl;
  240. begin
  241. inherited buildderefimpl;
  242. if assigned(t1) then
  243. t1.buildderefimpl;
  244. if assigned(t2) then
  245. t2.buildderefimpl;
  246. end;
  247. procedure tloopnode.derefimpl;
  248. begin
  249. inherited derefimpl;
  250. if assigned(t1) then
  251. t1.derefimpl;
  252. if assigned(t2) then
  253. t2.derefimpl;
  254. end;
  255. function tloopnode._getcopy : tnode;
  256. var
  257. p : tloopnode;
  258. begin
  259. p:=tloopnode(inherited _getcopy);
  260. if assigned(t1) then
  261. p.t1:=t1._getcopy
  262. else
  263. p.t1:=nil;
  264. if assigned(t2) then
  265. p.t2:=t2._getcopy
  266. else
  267. p.t2:=nil;
  268. p.loopflags:=loopflags;
  269. _getcopy:=p;
  270. end;
  271. procedure tloopnode.insertintolist(l : tnodelist);
  272. begin
  273. end;
  274. procedure tloopnode.printnodetree(var t:text);
  275. begin
  276. write(t,printnodeindention,'(');
  277. printnodeindent;
  278. printnodeinfo(t);
  279. writeln(t);
  280. printnode(t,left);
  281. printnode(t,right);
  282. printnode(t,t1);
  283. printnode(t,t2);
  284. printnodeunindent;
  285. writeln(t,printnodeindention,')');
  286. end;
  287. function tloopnode.docompare(p: tnode): boolean;
  288. begin
  289. docompare :=
  290. inherited docompare(p) and
  291. (loopflags*loopflagsequal=tloopnode(p).loopflags*loopflagsequal) and
  292. t1.isequal(tloopnode(p).t1) and
  293. t2.isequal(tloopnode(p).t2);
  294. end;
  295. {****************************************************************************
  296. TWHILEREPEATNODE
  297. *****************************************************************************}
  298. constructor Twhilerepeatnode.create(l,r:Tnode;tab,cn:boolean);
  299. begin
  300. inherited create(whilerepeatn,l,r,nil,nil);
  301. if tab then
  302. include(loopflags, lnf_testatbegin);
  303. if cn then
  304. include(loopflags,lnf_checknegate);
  305. end;
  306. function twhilerepeatnode.det_resulttype:tnode;
  307. var
  308. t:Tunarynode;
  309. begin
  310. result:=nil;
  311. resulttype:=voidtype;
  312. resulttypepass(left);
  313. { tp procvar support }
  314. maybe_call_procvar(left,true);
  315. {A not node can be removed.}
  316. if left.nodetype=notn then
  317. begin
  318. t:=Tunarynode(left);
  319. left:=Tunarynode(left).left;
  320. t.left:=nil;
  321. t.destroy;
  322. {Symdif operator, in case you are wondering:}
  323. loopflags:=loopflags >< [lnf_checknegate];
  324. end;
  325. { loop instruction }
  326. if assigned(right) then
  327. resulttypepass(right);
  328. set_varstate(left,vs_read,[vsf_must_be_valid]);
  329. if codegenerror then
  330. exit;
  331. if not is_boolean(left.resulttype.def) then
  332. begin
  333. if left.resulttype.def.deftype=variantdef then
  334. inserttypeconv(left,booltype)
  335. else
  336. CGMessage1(type_e_boolean_expr_expected,left.resulttype.def.typename);
  337. end;
  338. { Give warnings for code that will never be executed for
  339. while false do }
  340. if (lnf_testatbegin in loopflags) and
  341. (left.nodetype=ordconstn) and
  342. (tordconstnode(left).value=0) and
  343. assigned(right) then
  344. CGMessagePos(right.fileinfo,cg_w_unreachable_code);
  345. end;
  346. {$ifdef prefetchnext}
  347. type
  348. passignmentquery = ^tassignmentquery;
  349. tassignmentquery = record
  350. towhat: tnode;
  351. source: tassignmentnode;
  352. statementcount: cardinal;
  353. end;
  354. function checkassignment(var n: tnode; arg: pointer): foreachnoderesult;
  355. var
  356. query: passignmentquery absolute arg;
  357. temp, prederef: tnode;
  358. begin
  359. result := fen_norecurse_false;
  360. if (n.nodetype in [assignn,inlinen,forn,calln,whilerepeatn,casen,ifn]) then
  361. inc(query^.statementcount);
  362. { make sure there's something else in the loop besides going to the }
  363. { next item }
  364. if (query^.statementcount > 1) and
  365. (n.nodetype = assignn) then
  366. begin
  367. { skip type conversions of assignment target }
  368. temp := tassignmentnode(n).left;
  369. while (temp.nodetype = typeconvn) do
  370. temp := ttypeconvnode(temp).left;
  371. { assignment to x of the while assigned(x) check? }
  372. if not(temp.isequal(query^.towhat)) then
  373. exit;
  374. { right hand side of assignment dereferenced field of }
  375. { x? (no derefn in case of class) }
  376. temp := tassignmentnode(n).right;
  377. while (temp.nodetype = typeconvn) do
  378. temp := ttypeconvnode(temp).left;
  379. if (temp.nodetype <> subscriptn) then
  380. exit;
  381. prederef := tsubscriptnode(temp).left;
  382. temp := prederef;
  383. while (temp.nodetype = typeconvn) do
  384. temp := ttypeconvnode(temp).left;
  385. { see tests/test/prefetch1.pp }
  386. if (temp.nodetype = derefn) then
  387. temp := tderefnode(temp).left
  388. else
  389. temp := prederef;
  390. if temp.isequal(query^.towhat) then
  391. begin
  392. query^.source := tassignmentnode(n);
  393. result := fen_norecurse_true;
  394. end
  395. end
  396. { don't check nodes which can't contain an assignment or whose }
  397. { final assignment can vary a lot }
  398. else if not(n.nodetype in [calln,inlinen,casen,whilerepeatn,forn]) then
  399. result := fen_false;
  400. end;
  401. function findassignment(where: tnode; towhat: tnode): tassignmentnode;
  402. var
  403. query: tassignmentquery;
  404. begin
  405. query.towhat := towhat;
  406. query.source := nil;
  407. query.statementcount := 0;
  408. if foreachnodestatic(where,@checkassignment,@query) then
  409. result := query.source
  410. else
  411. result := nil;
  412. end;
  413. {$endif prefetchnext}
  414. function twhilerepeatnode.pass_1 : tnode;
  415. var
  416. {$ifdef prefetchnext}
  417. runnernode, prefetchcode: tnode;
  418. assignmentnode: tassignmentnode;
  419. prefetchstatements: tstatementnode;
  420. {$endif prefetchnext}
  421. old_t_times : longint;
  422. begin
  423. result:=nil;
  424. expectloc:=LOC_VOID;
  425. old_t_times:=cg.t_times;
  426. { calc register weight }
  427. if not(cs_opt_size in aktoptimizerswitches) then
  428. cg.t_times:=cg.t_times*8;
  429. firstpass(left);
  430. if codegenerror then
  431. exit;
  432. registersint:=left.registersint;
  433. registersfpu:=left.registersfpu;
  434. {$ifdef SUPPORT_MMX}
  435. registersmmx:=left.registersmmx;
  436. {$endif SUPPORT_MMX}
  437. { loop instruction }
  438. if assigned(right) then
  439. begin
  440. firstpass(right);
  441. if codegenerror then
  442. exit;
  443. if registersint<right.registersint then
  444. registersint:=right.registersint;
  445. if registersfpu<right.registersfpu then
  446. registersfpu:=right.registersfpu;
  447. {$ifdef SUPPORT_MMX}
  448. if registersmmx<right.registersmmx then
  449. registersmmx:=right.registersmmx;
  450. {$endif SUPPORT_MMX}
  451. end;
  452. cg.t_times:=old_t_times;
  453. {$ifdef prefetchnext}
  454. { do at the end so all complex typeconversions are already }
  455. { converted to calln's }
  456. if (cs_opt_level1 in aktoptimizerswitches) and
  457. (lnf_testatbegin in loopflags) then
  458. begin
  459. { get first component of the while check }
  460. runnernode := left;
  461. while (runnernode.nodetype in [andn,orn,notn,xorn,typeconvn]) do
  462. runnernode := tunarynode(runnernode).left;
  463. { is it an assigned(x) check? }
  464. if ((runnernode.nodetype = inlinen) and
  465. (tinlinenode(runnernode).inlinenumber = in_assigned_x)) or
  466. ((runnernode.nodetype = unequaln) and
  467. (taddnode(runnernode).right.nodetype = niln)) then
  468. begin
  469. runnernode := tunarynode(runnernode).left;
  470. { in case of in_assigned_x, there's a callparan in between }
  471. if (runnernode.nodetype = callparan) then
  472. runnernode := tcallparanode(runnernode).left;
  473. while (runnernode.nodetype = typeconvn) do
  474. runnernode := ttypeconvnode(runnernode).left;
  475. { is there an "x := x(^).somefield"? }
  476. assignmentnode := findassignment(right,runnernode);
  477. if assigned(assignmentnode) then
  478. begin
  479. prefetchcode := internalstatements(prefetchstatements);
  480. addstatement(prefetchstatements,geninlinenode(in_prefetch_var,false,
  481. cderefnode.create(ctypeconvnode.create(assignmentnode.right.getcopy,voidpointertype))));
  482. addstatement(prefetchstatements,right);
  483. right := prefetchcode;
  484. resulttypepass(right);
  485. end;
  486. end;
  487. end;
  488. {$endif prefetchnext}
  489. end;
  490. {$ifdef state_tracking}
  491. function Twhilerepeatnode.track_state_pass(exec_known:boolean):boolean;
  492. var condition:Tnode;
  493. code:Tnode;
  494. done:boolean;
  495. value:boolean;
  496. change:boolean;
  497. firsttest:boolean;
  498. factval:Tnode;
  499. begin
  500. track_state_pass:=false;
  501. done:=false;
  502. firsttest:=true;
  503. {For repeat until statements, first do a pass through the code.}
  504. if not(lnf_testatbegin in flags) then
  505. begin
  506. code:=right.getcopy;
  507. if code.track_state_pass(exec_known) then
  508. track_state_pass:=true;
  509. code.destroy;
  510. end;
  511. repeat
  512. condition:=left.getcopy;
  513. code:=right.getcopy;
  514. change:=condition.track_state_pass(exec_known);
  515. factval:=aktstate.find_fact(left);
  516. if factval<>nil then
  517. begin
  518. condition.destroy;
  519. condition:=factval.getcopy;
  520. change:=true;
  521. end;
  522. if change then
  523. begin
  524. track_state_pass:=true;
  525. {Force new resulttype pass.}
  526. condition.resulttype.def:=nil;
  527. do_resulttypepass(condition);
  528. end;
  529. if is_constboolnode(condition) then
  530. begin
  531. {Try to turn a while loop into a repeat loop.}
  532. if firsttest then
  533. exclude(flags,testatbegin);
  534. value:=(Tordconstnode(condition).value<>0) xor checknegate;
  535. if value then
  536. begin
  537. if code.track_state_pass(exec_known) then
  538. track_state_pass:=true;
  539. end
  540. else
  541. done:=true;
  542. end
  543. else
  544. begin
  545. {Remove any modified variables from the state.}
  546. code.track_state_pass(false);
  547. done:=true;
  548. end;
  549. code.destroy;
  550. condition.destroy;
  551. firsttest:=false;
  552. until done;
  553. {The loop condition is also known, for example:
  554. while i<10 do
  555. begin
  556. ...
  557. end;
  558. When the loop is done, we do know that i<10 = false.
  559. }
  560. condition:=left.getcopy;
  561. if condition.track_state_pass(exec_known) then
  562. begin
  563. track_state_pass:=true;
  564. {Force new resulttype pass.}
  565. condition.resulttype.def:=nil;
  566. do_resulttypepass(condition);
  567. end;
  568. if not is_constboolnode(condition) then
  569. aktstate.store_fact(condition,
  570. cordconstnode.create(byte(checknegate),booltype,true))
  571. else
  572. condition.destroy;
  573. end;
  574. {$endif}
  575. {*****************************************************************************
  576. TIFNODE
  577. *****************************************************************************}
  578. constructor tifnode.create(l,r,_t1 : tnode);
  579. begin
  580. inherited create(ifn,l,r,_t1,nil);
  581. end;
  582. function tifnode.det_resulttype:tnode;
  583. begin
  584. result:=nil;
  585. resulttype:=voidtype;
  586. resulttypepass(left);
  587. { tp procvar support }
  588. maybe_call_procvar(left,true);
  589. { if path }
  590. if assigned(right) then
  591. resulttypepass(right);
  592. { else path }
  593. if assigned(t1) then
  594. resulttypepass(t1);
  595. set_varstate(left,vs_read,[vsf_must_be_valid]);
  596. if codegenerror then
  597. exit;
  598. if not is_boolean(left.resulttype.def) then
  599. begin
  600. if left.resulttype.def.deftype=variantdef then
  601. inserttypeconv(left,booltype)
  602. else
  603. Message1(type_e_boolean_expr_expected,left.resulttype.def.typename);
  604. end;
  605. { optimize constant expressions }
  606. if left.nodetype=ordconstn then
  607. begin
  608. if tordconstnode(left).value=1 then
  609. begin
  610. if assigned(right) then
  611. result:=right
  612. else
  613. result:=cnothingnode.create;
  614. right:=nil;
  615. if assigned(t1) then
  616. CGMessagePos(t1.fileinfo,cg_w_unreachable_code);
  617. end
  618. else
  619. begin
  620. if assigned(t1) then
  621. result:=t1
  622. else
  623. result:=cnothingnode.create;
  624. t1:=nil;
  625. if assigned(right) then
  626. CGMessagePos(right.fileinfo,cg_w_unreachable_code);
  627. end;
  628. end;
  629. end;
  630. function tifnode.pass_1 : tnode;
  631. var
  632. old_t_times : longint;
  633. begin
  634. result:=nil;
  635. expectloc:=LOC_VOID;
  636. old_t_times:=cg.t_times;
  637. firstpass(left);
  638. registersint:=left.registersint;
  639. registersfpu:=left.registersfpu;
  640. {$ifdef SUPPORT_MMX}
  641. registersmmx:=left.registersmmx;
  642. {$endif SUPPORT_MMX}
  643. { determines registers weigths }
  644. if not(cs_opt_size in aktoptimizerswitches) then
  645. cg.t_times:=cg.t_times div 2;
  646. if cg.t_times=0 then
  647. cg.t_times:=1;
  648. { if path }
  649. if assigned(right) then
  650. begin
  651. firstpass(right);
  652. if registersint<right.registersint then
  653. registersint:=right.registersint;
  654. if registersfpu<right.registersfpu then
  655. registersfpu:=right.registersfpu;
  656. {$ifdef SUPPORT_MMX}
  657. if registersmmx<right.registersmmx then
  658. registersmmx:=right.registersmmx;
  659. {$endif SUPPORT_MMX}
  660. end;
  661. { else path }
  662. if assigned(t1) then
  663. begin
  664. firstpass(t1);
  665. if registersint<t1.registersint then
  666. registersint:=t1.registersint;
  667. if registersfpu<t1.registersfpu then
  668. registersfpu:=t1.registersfpu;
  669. {$ifdef SUPPORT_MMX}
  670. if registersmmx<t1.registersmmx then
  671. registersmmx:=t1.registersmmx;
  672. {$endif SUPPORT_MMX}
  673. end;
  674. { leave if we've got an error in one of the paths }
  675. if codegenerror then
  676. exit;
  677. cg.t_times:=old_t_times;
  678. end;
  679. {*****************************************************************************
  680. TFORNODE
  681. *****************************************************************************}
  682. constructor tfornode.create(l,r,_t1,_t2 : tnode;back : boolean);
  683. begin
  684. inherited create(forn,l,r,_t1,_t2);
  685. if back then
  686. include(loopflags,lnf_backward);
  687. include(loopflags,lnf_testatbegin);
  688. end;
  689. procedure Tfornode.loop_var_access(not_type:Tnotification_flag;
  690. symbol:Tsym);
  691. begin
  692. {If there is a read access, the value of the loop counter is important;
  693. at the end of the loop the loop variable should contain the value it
  694. had in the last iteration.}
  695. if not_type=vn_onwrite then
  696. begin
  697. writeln('Loopvar does not matter on exit');
  698. end
  699. else
  700. begin
  701. exclude(loopflags,lnf_dont_mind_loopvar_on_exit);
  702. writeln('Loopvar does matter on exit');
  703. end;
  704. Tabstractvarsym(symbol).unregister_notification(loopvar_notid);
  705. end;
  706. function tfornode.det_resulttype:tnode;
  707. var
  708. unrollres : tnode;
  709. begin
  710. result:=nil;
  711. resulttype:=voidtype;
  712. { loop unrolling }
  713. if cs_opt_loopunroll in aktoptimizerswitches then
  714. begin
  715. unrollres:=unroll_loop(self);
  716. if assigned(unrollres) then
  717. begin
  718. resulttypepass(unrollres);
  719. result:=unrollres;
  720. exit;
  721. end;
  722. end;
  723. { process the loopvar, from and to, varstates are already set }
  724. resulttypepass(left);
  725. resulttypepass(right);
  726. resulttypepass(t1);
  727. {Can we spare the first comparision?}
  728. if (t1.nodetype=ordconstn) and
  729. (right.nodetype=ordconstn) and
  730. (
  731. (
  732. (lnf_backward in loopflags) and
  733. (Tordconstnode(right).value>=Tordconstnode(t1).value)
  734. ) or
  735. (
  736. not(lnf_backward in loopflags) and
  737. (Tordconstnode(right).value<=Tordconstnode(t1).value)
  738. )
  739. ) then
  740. exclude(loopflags,lnf_testatbegin);
  741. { Make sure that the loop var and the
  742. from and to values are compatible types }
  743. check_ranges(right.fileinfo,right,left.resulttype.def);
  744. inserttypeconv(right,left.resulttype);
  745. check_ranges(t1.fileinfo,t1,left.resulttype.def);
  746. inserttypeconv(t1,left.resulttype);
  747. if assigned(t2) then
  748. resulttypepass(t2);
  749. end;
  750. function tfornode.pass_1 : tnode;
  751. var
  752. old_t_times : longint;
  753. begin
  754. result:=nil;
  755. expectloc:=LOC_VOID;
  756. firstpass(left);
  757. if left.registersint>registersint then
  758. registersint:=left.registersint;
  759. if left.registersfpu>registersfpu then
  760. registersfpu:=left.registersfpu;
  761. {$ifdef SUPPORT_MMX}
  762. if left.registersmmx>registersmmx then
  763. registersmmx:=left.registersmmx;
  764. {$endif SUPPORT_MMX}
  765. firstpass(right);
  766. if right.registersint>registersint then
  767. registersint:=right.registersint;
  768. if right.registersfpu>registersfpu then
  769. registersfpu:=right.registersfpu;
  770. {$ifdef SUPPORT_MMX}
  771. if right.registersmmx>registersmmx then
  772. registersmmx:=right.registersmmx;
  773. {$endif SUPPORT_MMX}
  774. firstpass(t1);
  775. if t1.registersint>registersint then
  776. registersint:=t1.registersint;
  777. if t1.registersfpu>registersfpu then
  778. registersfpu:=t1.registersfpu;
  779. {$ifdef SUPPORT_MMX}
  780. if t1.registersmmx>registersmmx then
  781. registersmmx:=t1.registersmmx;
  782. {$endif SUPPORT_MMX}
  783. if assigned(t2) then
  784. begin
  785. { Calc register weight }
  786. old_t_times:=cg.t_times;
  787. if not(cs_opt_size in aktoptimizerswitches) then
  788. cg.t_times:=cg.t_times*8;
  789. firstpass(t2);
  790. if codegenerror then
  791. exit;
  792. if t2.registersint>registersint then
  793. registersint:=t2.registersint;
  794. if t2.registersfpu>registersfpu then
  795. registersfpu:=t2.registersfpu;
  796. {$ifdef SUPPORT_MMX}
  797. if t2.registersmmx>registersmmx then
  798. registersmmx:=t2.registersmmx;
  799. {$endif SUPPORT_MMX}
  800. cg.t_times:=old_t_times;
  801. end;
  802. { we need at least one register for comparisons PM }
  803. if registersint=0 then
  804. inc(registersint);
  805. end;
  806. {*****************************************************************************
  807. TEXITNODE
  808. *****************************************************************************}
  809. constructor texitnode.create(l:tnode);
  810. begin
  811. inherited create(exitn,l);
  812. end;
  813. constructor texitnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  814. begin
  815. inherited ppuload(t,ppufile);
  816. end;
  817. procedure texitnode.ppuwrite(ppufile:tcompilerppufile);
  818. begin
  819. inherited ppuwrite(ppufile);
  820. end;
  821. function texitnode.det_resulttype:tnode;
  822. begin
  823. result:=nil;
  824. if assigned(left) then
  825. begin
  826. { add assignment to funcretsym }
  827. inserttypeconv(left,current_procinfo.procdef.rettype);
  828. left:=cassignmentnode.create(
  829. cloadnode.create(current_procinfo.procdef.funcretsym,current_procinfo.procdef.funcretsym.owner),
  830. left);
  831. resulttypepass(left);
  832. set_varstate(left,vs_read,[vsf_must_be_valid]);
  833. end;
  834. resulttype:=voidtype;
  835. end;
  836. function texitnode.pass_1 : tnode;
  837. begin
  838. result:=nil;
  839. expectloc:=LOC_VOID;
  840. if assigned(left) then
  841. begin
  842. firstpass(left);
  843. if codegenerror then
  844. exit;
  845. registersint:=left.registersint;
  846. registersfpu:=left.registersfpu;
  847. {$ifdef SUPPORT_MMX}
  848. registersmmx:=left.registersmmx;
  849. {$endif SUPPORT_MMX}
  850. end;
  851. end;
  852. {*****************************************************************************
  853. TBREAKNODE
  854. *****************************************************************************}
  855. constructor tbreaknode.create;
  856. begin
  857. inherited create(breakn);
  858. end;
  859. function tbreaknode.det_resulttype:tnode;
  860. begin
  861. result:=nil;
  862. resulttype:=voidtype;
  863. end;
  864. function tbreaknode.pass_1 : tnode;
  865. begin
  866. result:=nil;
  867. expectloc:=LOC_VOID;
  868. end;
  869. {*****************************************************************************
  870. TCONTINUENODE
  871. *****************************************************************************}
  872. constructor tcontinuenode.create;
  873. begin
  874. inherited create(continuen);
  875. end;
  876. function tcontinuenode.det_resulttype:tnode;
  877. begin
  878. result:=nil;
  879. resulttype:=voidtype;
  880. end;
  881. function tcontinuenode.pass_1 : tnode;
  882. begin
  883. result:=nil;
  884. expectloc:=LOC_VOID;
  885. end;
  886. {*****************************************************************************
  887. TGOTONODE
  888. *****************************************************************************}
  889. constructor tgotonode.create(p : tlabelnode);
  890. begin
  891. inherited create(goton);
  892. exceptionblock:=aktexceptblock;
  893. labelnode:=p;
  894. labelsym:=nil;
  895. end;
  896. constructor tgotonode.create_sym(p : tlabelsym);
  897. begin
  898. inherited create(goton);
  899. exceptionblock:=aktexceptblock;
  900. if assigned(p.code) then
  901. labelnode:=tlabelnode(p.code)
  902. else
  903. labelnode:=nil;
  904. labelsym:=p;
  905. end;
  906. constructor tgotonode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  907. begin
  908. inherited ppuload(t,ppufile);
  909. labelnode:=tlabelnode(ppuloadnoderef(ppufile));
  910. exceptionblock:=ppufile.getbyte;
  911. end;
  912. procedure tgotonode.ppuwrite(ppufile:tcompilerppufile);
  913. begin
  914. inherited ppuwrite(ppufile);
  915. ppuwritenoderef(ppufile,labelnode);
  916. ppufile.putbyte(exceptionblock);
  917. end;
  918. procedure tgotonode.buildderefimpl;
  919. begin
  920. inherited buildderefimpl;
  921. //!!! deref(labelnode);
  922. end;
  923. procedure tgotonode.derefimpl;
  924. begin
  925. inherited derefimpl;
  926. //!!! deref(labelnode);
  927. end;
  928. function tgotonode.det_resulttype:tnode;
  929. begin
  930. result:=nil;
  931. resulttype:=voidtype;
  932. end;
  933. function tgotonode.pass_1 : tnode;
  934. begin
  935. result:=nil;
  936. expectloc:=LOC_VOID;
  937. include(current_procinfo.flags,pi_has_goto);
  938. if not(assigned(labelnode)) then
  939. begin
  940. if assigned(labelsym.code) then
  941. labelnode:=tlabelnode(labelsym.code)
  942. else
  943. internalerror(200506183);
  944. end;
  945. { check if we don't mess with exception blocks }
  946. if assigned(labelnode) and
  947. (exceptionblock<>labelnode.exceptionblock) then
  948. CGMessage(cg_e_goto_inout_of_exception_block);
  949. end;
  950. function tgotonode._getcopy : tnode;
  951. var
  952. p : tgotonode;
  953. i : aint;
  954. begin
  955. p:=tgotonode(inherited _getcopy);
  956. {
  957. p.exceptionblock:=exceptionblock;
  958. { When we copying, we do an ugly trick to determine if the label used
  959. by the current goto node is already copied: if the referinggotonodes
  960. contains the current label, it isn't copied yet, so copy also the
  961. label node and set the copiedto field to the newly created node.
  962. If a label to copy is reached the copiedto field is checked. If it's non nil
  963. the copiedto field is returned and the copiedto field is reset to nil.
  964. }
  965. { assume no copying }
  966. newlabelnode:=labelnode;
  967. for i:=0 to labelnode.copiedto.referingotonodes.count-1 do
  968. begin
  969. { copy labelnode? }
  970. if labelnode.copiedto.referinggotonodes[i]=self then
  971. begin
  972. oldlabelnode.copiedto:=newlabelnode;
  973. end;
  974. end;
  975. p.labelnode:=newlabelnode;
  976. p.labelnode.referinggotonodes.add(self);
  977. }
  978. result:=p;
  979. end;
  980. function tgotonode.docompare(p: tnode): boolean;
  981. begin
  982. docompare := false;
  983. end;
  984. {*****************************************************************************
  985. TLABELNODE
  986. *****************************************************************************}
  987. constructor tlabelnode.create(l:tnode);
  988. begin
  989. inherited create(labeln,l);
  990. exceptionblock:=aktexceptblock;
  991. end;
  992. constructor tlabelnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  993. begin
  994. inherited ppuload(t,ppufile);
  995. exceptionblock:=ppufile.getbyte;
  996. end;
  997. procedure tlabelnode.ppuwrite(ppufile:tcompilerppufile);
  998. begin
  999. inherited ppuwrite(ppufile);
  1000. ppufile.putbyte(exceptionblock);
  1001. end;
  1002. procedure tlabelnode.buildderefimpl;
  1003. begin
  1004. inherited buildderefimpl;
  1005. end;
  1006. procedure tlabelnode.derefimpl;
  1007. begin
  1008. inherited derefimpl;
  1009. end;
  1010. function tlabelnode.det_resulttype:tnode;
  1011. begin
  1012. result:=nil;
  1013. { left could still be unassigned }
  1014. if assigned(left) then
  1015. resulttypepass(left);
  1016. resulttype:=voidtype;
  1017. end;
  1018. function tlabelnode.pass_1 : tnode;
  1019. begin
  1020. result:=nil;
  1021. expectloc:=LOC_VOID;
  1022. if assigned(left) then
  1023. begin
  1024. firstpass(left);
  1025. registersint:=left.registersint;
  1026. registersfpu:=left.registersfpu;
  1027. {$ifdef SUPPORT_MMX}
  1028. registersmmx:=left.registersmmx;
  1029. {$endif SUPPORT_MMX}
  1030. end;
  1031. end;
  1032. function tlabelnode._getcopy : tnode;
  1033. var
  1034. p : tlabelnode;
  1035. begin
  1036. p:=tlabelnode(inherited _getcopy);
  1037. p.exceptionblock:=exceptionblock;
  1038. result:=p;
  1039. end;
  1040. function tlabelnode.docompare(p: tnode): boolean;
  1041. begin
  1042. docompare := false;
  1043. end;
  1044. {*****************************************************************************
  1045. TRAISENODE
  1046. *****************************************************************************}
  1047. constructor traisenode.create(l,taddr,tframe:tnode);
  1048. begin
  1049. inherited create(raisen,l,taddr);
  1050. frametree:=tframe;
  1051. end;
  1052. constructor traisenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1053. begin
  1054. inherited ppuload(t,ppufile);
  1055. frametree:=ppuloadnode(ppufile);
  1056. end;
  1057. procedure traisenode.ppuwrite(ppufile:tcompilerppufile);
  1058. begin
  1059. inherited ppuwrite(ppufile);
  1060. ppuwritenode(ppufile,frametree);
  1061. end;
  1062. procedure traisenode.buildderefimpl;
  1063. begin
  1064. inherited buildderefimpl;
  1065. if assigned(frametree) then
  1066. frametree.buildderefimpl;
  1067. end;
  1068. procedure traisenode.derefimpl;
  1069. begin
  1070. inherited derefimpl;
  1071. if assigned(frametree) then
  1072. frametree.derefimpl;
  1073. end;
  1074. function traisenode._getcopy : tnode;
  1075. var
  1076. n : traisenode;
  1077. begin
  1078. n:=traisenode(inherited _getcopy);
  1079. if assigned(frametree) then
  1080. n.frametree:=frametree._getcopy
  1081. else
  1082. n.frametree:=nil;
  1083. _getcopy:=n;
  1084. end;
  1085. procedure traisenode.insertintolist(l : tnodelist);
  1086. begin
  1087. end;
  1088. function traisenode.det_resulttype:tnode;
  1089. begin
  1090. result:=nil;
  1091. resulttype:=voidtype;
  1092. if assigned(left) then
  1093. begin
  1094. { first para must be a _class_ }
  1095. resulttypepass(left);
  1096. set_varstate(left,vs_read,[vsf_must_be_valid]);
  1097. if codegenerror then
  1098. exit;
  1099. if not(is_class(left.resulttype.def)) then
  1100. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1101. { insert needed typeconvs for addr,frame }
  1102. if assigned(right) then
  1103. begin
  1104. { addr }
  1105. resulttypepass(right);
  1106. inserttypeconv(right,voidpointertype);
  1107. { frame }
  1108. if assigned(frametree) then
  1109. begin
  1110. resulttypepass(frametree);
  1111. inserttypeconv(frametree,voidpointertype);
  1112. end;
  1113. end;
  1114. end;
  1115. end;
  1116. function traisenode.pass_1 : tnode;
  1117. begin
  1118. result:=nil;
  1119. include(current_procinfo.flags,pi_do_call);
  1120. expectloc:=LOC_VOID;
  1121. if assigned(left) then
  1122. begin
  1123. { first para must be a _class_ }
  1124. firstpass(left);
  1125. { insert needed typeconvs for addr,frame }
  1126. if assigned(right) then
  1127. begin
  1128. { addr }
  1129. firstpass(right);
  1130. { frame }
  1131. if assigned(frametree) then
  1132. firstpass(frametree);
  1133. end;
  1134. left_right_max;
  1135. end;
  1136. end;
  1137. function traisenode.docompare(p: tnode): boolean;
  1138. begin
  1139. docompare := false;
  1140. end;
  1141. {*****************************************************************************
  1142. TTRYEXCEPTNODE
  1143. *****************************************************************************}
  1144. constructor ttryexceptnode.create(l,r,_t1 : tnode);
  1145. begin
  1146. inherited create(tryexceptn,l,r,_t1,nil);
  1147. end;
  1148. function ttryexceptnode.det_resulttype:tnode;
  1149. begin
  1150. result:=nil;
  1151. resulttypepass(left);
  1152. { on statements }
  1153. if assigned(right) then
  1154. resulttypepass(right);
  1155. { else block }
  1156. if assigned(t1) then
  1157. resulttypepass(t1);
  1158. resulttype:=voidtype;
  1159. end;
  1160. function ttryexceptnode.pass_1 : tnode;
  1161. begin
  1162. result:=nil;
  1163. include(current_procinfo.flags,pi_do_call);
  1164. expectloc:=LOC_VOID;
  1165. firstpass(left);
  1166. { on statements }
  1167. if assigned(right) then
  1168. begin
  1169. firstpass(right);
  1170. registersint:=max(registersint,right.registersint);
  1171. registersfpu:=max(registersfpu,right.registersfpu);
  1172. {$ifdef SUPPORT_MMX}
  1173. registersmmx:=max(registersmmx,right.registersmmx);
  1174. {$endif SUPPORT_MMX}
  1175. end;
  1176. { else block }
  1177. if assigned(t1) then
  1178. begin
  1179. firstpass(t1);
  1180. registersint:=max(registersint,t1.registersint);
  1181. registersfpu:=max(registersfpu,t1.registersfpu);
  1182. {$ifdef SUPPORT_MMX}
  1183. registersmmx:=max(registersmmx,t1.registersmmx);
  1184. {$endif SUPPORT_MMX}
  1185. end;
  1186. end;
  1187. {*****************************************************************************
  1188. TTRYFINALLYNODE
  1189. *****************************************************************************}
  1190. constructor ttryfinallynode.create(l,r:tnode);
  1191. begin
  1192. inherited create(tryfinallyn,l,r,nil,nil);
  1193. implicitframe:=false;
  1194. end;
  1195. constructor ttryfinallynode.create_implicit(l,r,_t1:tnode);
  1196. begin
  1197. inherited create(tryfinallyn,l,r,_t1,nil);
  1198. implicitframe:=true;
  1199. end;
  1200. function ttryfinallynode.det_resulttype:tnode;
  1201. begin
  1202. result:=nil;
  1203. include(current_procinfo.flags,pi_do_call);
  1204. resulttype:=voidtype;
  1205. resulttypepass(left);
  1206. // "try block" is "used"? (JM)
  1207. set_varstate(left,vs_readwritten,[vsf_must_be_valid]);
  1208. resulttypepass(right);
  1209. // "except block" is "used"? (JM)
  1210. set_varstate(right,vs_readwritten,[vsf_must_be_valid]);
  1211. { special finally block only executed when there was an exception }
  1212. if assigned(t1) then
  1213. begin
  1214. resulttypepass(t1);
  1215. // "finally block" is "used"? (JM)
  1216. set_varstate(t1,vs_readwritten,[vsf_must_be_valid]);
  1217. end;
  1218. end;
  1219. function ttryfinallynode.pass_1 : tnode;
  1220. begin
  1221. result:=nil;
  1222. expectloc:=LOC_VOID;
  1223. firstpass(left);
  1224. firstpass(right);
  1225. left_right_max;
  1226. if assigned(t1) then
  1227. begin
  1228. firstpass(t1);
  1229. registersint:=max(registersint,t1.registersint);
  1230. registersfpu:=max(registersfpu,t1.registersfpu);
  1231. {$ifdef SUPPORT_MMX}
  1232. registersmmx:=max(registersmmx,t1.registersmmx);
  1233. {$endif SUPPORT_MMX}
  1234. end;
  1235. end;
  1236. {*****************************************************************************
  1237. TONNODE
  1238. *****************************************************************************}
  1239. constructor tonnode.create(l,r:tnode);
  1240. begin
  1241. inherited create(onn,l,r);
  1242. exceptsymtable:=nil;
  1243. excepttype:=nil;
  1244. end;
  1245. destructor tonnode.destroy;
  1246. begin
  1247. { copied nodes don't need to release the symtable }
  1248. if assigned(exceptsymtable) then
  1249. exceptsymtable.free;
  1250. inherited destroy;
  1251. end;
  1252. constructor tonnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1253. begin
  1254. inherited ppuload(t,ppufile);
  1255. exceptsymtable:=nil;
  1256. excepttype:=nil;
  1257. end;
  1258. function tonnode._getcopy : tnode;
  1259. var
  1260. n : tonnode;
  1261. begin
  1262. n:=tonnode(inherited _getcopy);
  1263. n.exceptsymtable:=exceptsymtable.getcopy;
  1264. n.excepttype:=excepttype;
  1265. result:=n;
  1266. end;
  1267. function tonnode.det_resulttype:tnode;
  1268. begin
  1269. result:=nil;
  1270. resulttype:=voidtype;
  1271. if not(is_class(excepttype)) then
  1272. CGMessage1(type_e_class_type_expected,excepttype.typename);
  1273. if assigned(left) then
  1274. resulttypepass(left);
  1275. if assigned(right) then
  1276. resulttypepass(right);
  1277. end;
  1278. function tonnode.pass_1 : tnode;
  1279. begin
  1280. result:=nil;
  1281. include(current_procinfo.flags,pi_do_call);
  1282. expectloc:=LOC_VOID;
  1283. registersint:=0;
  1284. registersfpu:=0;
  1285. {$ifdef SUPPORT_MMX}
  1286. registersmmx:=0;
  1287. {$endif SUPPORT_MMX}
  1288. if assigned(left) then
  1289. begin
  1290. firstpass(left);
  1291. registersint:=left.registersint;
  1292. registersfpu:=left.registersfpu;
  1293. {$ifdef SUPPORT_MMX}
  1294. registersmmx:=left.registersmmx;
  1295. {$endif SUPPORT_MMX}
  1296. end;
  1297. if assigned(right) then
  1298. begin
  1299. firstpass(right);
  1300. registersint:=max(registersint,right.registersint);
  1301. registersfpu:=max(registersfpu,right.registersfpu);
  1302. {$ifdef SUPPORT_MMX}
  1303. registersmmx:=max(registersmmx,right.registersmmx);
  1304. {$endif SUPPORT_MMX}
  1305. end;
  1306. end;
  1307. function tonnode.docompare(p: tnode): boolean;
  1308. begin
  1309. docompare := false;
  1310. end;
  1311. begin
  1312. cwhilerepeatnode:=twhilerepeatnode;
  1313. cifnode:=tifnode;
  1314. cfornode:=tfornode;
  1315. cexitnode:=texitnode;
  1316. cgotonode:=tgotonode;
  1317. clabelnode:=tlabelnode;
  1318. craisenode:=traisenode;
  1319. ctryexceptnode:=ttryexceptnode;
  1320. ctryfinallynode:=ttryfinallynode;
  1321. connode:=tonnode;
  1322. end.