nflw.pas 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559
  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) and 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 : longint;
  954. begin
  955. p:=tgotonode(inherited _getcopy);
  956. p.exceptionblock:=exceptionblock;
  957. { force a valid labelnode }
  958. if not(assigned(labelnode)) then
  959. begin
  960. if assigned(labelsym) and assigned(labelsym.code) then
  961. labelnode:=tlabelnode(labelsym.code)
  962. else
  963. internalerror(200610291);
  964. end;
  965. p.labelnode:=tlabelnode(labelnode._getcopy);
  966. result:=p;
  967. end;
  968. function tgotonode.docompare(p: tnode): boolean;
  969. begin
  970. docompare := false;
  971. end;
  972. {*****************************************************************************
  973. TLABELNODE
  974. *****************************************************************************}
  975. constructor tlabelnode.create(l:tnode);
  976. begin
  977. inherited create(labeln,l);
  978. exceptionblock:=aktexceptblock;
  979. end;
  980. constructor tlabelnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  981. begin
  982. inherited ppuload(t,ppufile);
  983. exceptionblock:=ppufile.getbyte;
  984. end;
  985. procedure tlabelnode.ppuwrite(ppufile:tcompilerppufile);
  986. begin
  987. inherited ppuwrite(ppufile);
  988. ppufile.putbyte(exceptionblock);
  989. end;
  990. procedure tlabelnode.buildderefimpl;
  991. begin
  992. inherited buildderefimpl;
  993. end;
  994. procedure tlabelnode.derefimpl;
  995. begin
  996. inherited derefimpl;
  997. end;
  998. function tlabelnode.det_resulttype:tnode;
  999. begin
  1000. result:=nil;
  1001. { left could still be unassigned }
  1002. if assigned(left) then
  1003. resulttypepass(left);
  1004. resulttype:=voidtype;
  1005. end;
  1006. function tlabelnode.pass_1 : tnode;
  1007. begin
  1008. result:=nil;
  1009. expectloc:=LOC_VOID;
  1010. if assigned(left) then
  1011. begin
  1012. firstpass(left);
  1013. registersint:=left.registersint;
  1014. registersfpu:=left.registersfpu;
  1015. {$ifdef SUPPORT_MMX}
  1016. registersmmx:=left.registersmmx;
  1017. {$endif SUPPORT_MMX}
  1018. end;
  1019. end;
  1020. function tlabelnode._getcopy : tnode;
  1021. begin
  1022. if not(assigned(copiedto)) then
  1023. copiedto:=tlabelnode(inherited _getcopy);
  1024. copiedto.exceptionblock:=exceptionblock;
  1025. result:=copiedto;
  1026. end;
  1027. function tlabelnode.docompare(p: tnode): boolean;
  1028. begin
  1029. docompare := false;
  1030. end;
  1031. {*****************************************************************************
  1032. TRAISENODE
  1033. *****************************************************************************}
  1034. constructor traisenode.create(l,taddr,tframe:tnode);
  1035. begin
  1036. inherited create(raisen,l,taddr);
  1037. frametree:=tframe;
  1038. end;
  1039. constructor traisenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1040. begin
  1041. inherited ppuload(t,ppufile);
  1042. frametree:=ppuloadnode(ppufile);
  1043. end;
  1044. procedure traisenode.ppuwrite(ppufile:tcompilerppufile);
  1045. begin
  1046. inherited ppuwrite(ppufile);
  1047. ppuwritenode(ppufile,frametree);
  1048. end;
  1049. procedure traisenode.buildderefimpl;
  1050. begin
  1051. inherited buildderefimpl;
  1052. if assigned(frametree) then
  1053. frametree.buildderefimpl;
  1054. end;
  1055. procedure traisenode.derefimpl;
  1056. begin
  1057. inherited derefimpl;
  1058. if assigned(frametree) then
  1059. frametree.derefimpl;
  1060. end;
  1061. function traisenode._getcopy : tnode;
  1062. var
  1063. n : traisenode;
  1064. begin
  1065. n:=traisenode(inherited _getcopy);
  1066. if assigned(frametree) then
  1067. n.frametree:=frametree._getcopy
  1068. else
  1069. n.frametree:=nil;
  1070. _getcopy:=n;
  1071. end;
  1072. procedure traisenode.insertintolist(l : tnodelist);
  1073. begin
  1074. end;
  1075. function traisenode.det_resulttype:tnode;
  1076. begin
  1077. result:=nil;
  1078. resulttype:=voidtype;
  1079. if assigned(left) then
  1080. begin
  1081. { first para must be a _class_ }
  1082. resulttypepass(left);
  1083. set_varstate(left,vs_read,[vsf_must_be_valid]);
  1084. if codegenerror then
  1085. exit;
  1086. if not(is_class(left.resulttype.def)) then
  1087. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1088. { insert needed typeconvs for addr,frame }
  1089. if assigned(right) then
  1090. begin
  1091. { addr }
  1092. resulttypepass(right);
  1093. inserttypeconv(right,voidpointertype);
  1094. { frame }
  1095. if assigned(frametree) then
  1096. begin
  1097. resulttypepass(frametree);
  1098. inserttypeconv(frametree,voidpointertype);
  1099. end;
  1100. end;
  1101. end;
  1102. end;
  1103. function traisenode.pass_1 : tnode;
  1104. begin
  1105. result:=nil;
  1106. include(current_procinfo.flags,pi_do_call);
  1107. expectloc:=LOC_VOID;
  1108. if assigned(left) then
  1109. begin
  1110. { first para must be a _class_ }
  1111. firstpass(left);
  1112. { insert needed typeconvs for addr,frame }
  1113. if assigned(right) then
  1114. begin
  1115. { addr }
  1116. firstpass(right);
  1117. { frame }
  1118. if assigned(frametree) then
  1119. firstpass(frametree);
  1120. end;
  1121. left_right_max;
  1122. end;
  1123. end;
  1124. function traisenode.docompare(p: tnode): boolean;
  1125. begin
  1126. docompare := false;
  1127. end;
  1128. {*****************************************************************************
  1129. TTRYEXCEPTNODE
  1130. *****************************************************************************}
  1131. constructor ttryexceptnode.create(l,r,_t1 : tnode);
  1132. begin
  1133. inherited create(tryexceptn,l,r,_t1,nil);
  1134. end;
  1135. function ttryexceptnode.det_resulttype:tnode;
  1136. begin
  1137. result:=nil;
  1138. resulttypepass(left);
  1139. { on statements }
  1140. if assigned(right) then
  1141. resulttypepass(right);
  1142. { else block }
  1143. if assigned(t1) then
  1144. resulttypepass(t1);
  1145. resulttype:=voidtype;
  1146. end;
  1147. function ttryexceptnode.pass_1 : tnode;
  1148. begin
  1149. result:=nil;
  1150. include(current_procinfo.flags,pi_do_call);
  1151. expectloc:=LOC_VOID;
  1152. firstpass(left);
  1153. { on statements }
  1154. if assigned(right) then
  1155. begin
  1156. firstpass(right);
  1157. registersint:=max(registersint,right.registersint);
  1158. registersfpu:=max(registersfpu,right.registersfpu);
  1159. {$ifdef SUPPORT_MMX}
  1160. registersmmx:=max(registersmmx,right.registersmmx);
  1161. {$endif SUPPORT_MMX}
  1162. end;
  1163. { else block }
  1164. if assigned(t1) then
  1165. begin
  1166. firstpass(t1);
  1167. registersint:=max(registersint,t1.registersint);
  1168. registersfpu:=max(registersfpu,t1.registersfpu);
  1169. {$ifdef SUPPORT_MMX}
  1170. registersmmx:=max(registersmmx,t1.registersmmx);
  1171. {$endif SUPPORT_MMX}
  1172. end;
  1173. end;
  1174. {*****************************************************************************
  1175. TTRYFINALLYNODE
  1176. *****************************************************************************}
  1177. constructor ttryfinallynode.create(l,r:tnode);
  1178. begin
  1179. inherited create(tryfinallyn,l,r,nil,nil);
  1180. implicitframe:=false;
  1181. end;
  1182. constructor ttryfinallynode.create_implicit(l,r,_t1:tnode);
  1183. begin
  1184. inherited create(tryfinallyn,l,r,_t1,nil);
  1185. implicitframe:=true;
  1186. end;
  1187. function ttryfinallynode.det_resulttype:tnode;
  1188. begin
  1189. result:=nil;
  1190. include(current_procinfo.flags,pi_do_call);
  1191. resulttype:=voidtype;
  1192. resulttypepass(left);
  1193. // "try block" is "used"? (JM)
  1194. set_varstate(left,vs_readwritten,[vsf_must_be_valid]);
  1195. resulttypepass(right);
  1196. // "except block" is "used"? (JM)
  1197. set_varstate(right,vs_readwritten,[vsf_must_be_valid]);
  1198. { special finally block only executed when there was an exception }
  1199. if assigned(t1) then
  1200. begin
  1201. resulttypepass(t1);
  1202. // "finally block" is "used"? (JM)
  1203. set_varstate(t1,vs_readwritten,[vsf_must_be_valid]);
  1204. end;
  1205. end;
  1206. function ttryfinallynode.pass_1 : tnode;
  1207. begin
  1208. result:=nil;
  1209. expectloc:=LOC_VOID;
  1210. firstpass(left);
  1211. firstpass(right);
  1212. left_right_max;
  1213. if assigned(t1) then
  1214. begin
  1215. firstpass(t1);
  1216. registersint:=max(registersint,t1.registersint);
  1217. registersfpu:=max(registersfpu,t1.registersfpu);
  1218. {$ifdef SUPPORT_MMX}
  1219. registersmmx:=max(registersmmx,t1.registersmmx);
  1220. {$endif SUPPORT_MMX}
  1221. end;
  1222. end;
  1223. {*****************************************************************************
  1224. TONNODE
  1225. *****************************************************************************}
  1226. constructor tonnode.create(l,r:tnode);
  1227. begin
  1228. inherited create(onn,l,r);
  1229. exceptsymtable:=nil;
  1230. excepttype:=nil;
  1231. end;
  1232. destructor tonnode.destroy;
  1233. begin
  1234. { copied nodes don't need to release the symtable }
  1235. if assigned(exceptsymtable) then
  1236. exceptsymtable.free;
  1237. inherited destroy;
  1238. end;
  1239. constructor tonnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1240. begin
  1241. inherited ppuload(t,ppufile);
  1242. exceptsymtable:=nil;
  1243. excepttype:=nil;
  1244. end;
  1245. function tonnode._getcopy : tnode;
  1246. var
  1247. n : tonnode;
  1248. begin
  1249. n:=tonnode(inherited _getcopy);
  1250. n.exceptsymtable:=exceptsymtable.getcopy;
  1251. n.excepttype:=excepttype;
  1252. result:=n;
  1253. end;
  1254. function tonnode.det_resulttype:tnode;
  1255. begin
  1256. result:=nil;
  1257. resulttype:=voidtype;
  1258. if not(is_class(excepttype)) then
  1259. CGMessage1(type_e_class_type_expected,excepttype.typename);
  1260. if assigned(left) then
  1261. resulttypepass(left);
  1262. if assigned(right) then
  1263. resulttypepass(right);
  1264. end;
  1265. function tonnode.pass_1 : tnode;
  1266. begin
  1267. result:=nil;
  1268. include(current_procinfo.flags,pi_do_call);
  1269. expectloc:=LOC_VOID;
  1270. registersint:=0;
  1271. registersfpu:=0;
  1272. {$ifdef SUPPORT_MMX}
  1273. registersmmx:=0;
  1274. {$endif SUPPORT_MMX}
  1275. if assigned(left) then
  1276. begin
  1277. firstpass(left);
  1278. registersint:=left.registersint;
  1279. registersfpu:=left.registersfpu;
  1280. {$ifdef SUPPORT_MMX}
  1281. registersmmx:=left.registersmmx;
  1282. {$endif SUPPORT_MMX}
  1283. end;
  1284. if assigned(right) then
  1285. begin
  1286. firstpass(right);
  1287. registersint:=max(registersint,right.registersint);
  1288. registersfpu:=max(registersfpu,right.registersfpu);
  1289. {$ifdef SUPPORT_MMX}
  1290. registersmmx:=max(registersmmx,right.registersmmx);
  1291. {$endif SUPPORT_MMX}
  1292. end;
  1293. end;
  1294. function tonnode.docompare(p: tnode): boolean;
  1295. begin
  1296. docompare := false;
  1297. end;
  1298. begin
  1299. cwhilerepeatnode:=twhilerepeatnode;
  1300. cifnode:=tifnode;
  1301. cfornode:=tfornode;
  1302. cexitnode:=texitnode;
  1303. cgotonode:=tgotonode;
  1304. clabelnode:=tlabelnode;
  1305. craisenode:=traisenode;
  1306. ctryexceptnode:=ttryexceptnode;
  1307. ctryfinallynode:=ttryfinallynode;
  1308. connode:=tonnode;
  1309. end.