nflw.pas 45 KB

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