nbas.pas 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. This unit implements some basic nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nbas;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cgbase,cgutils,
  23. aasmtai,aasmdata,aasmcpu,
  24. node,
  25. symtype;
  26. type
  27. tnothingnode = class(tnode)
  28. constructor create;virtual;
  29. function pass_1 : tnode;override;
  30. function pass_typecheck:tnode;override;
  31. end;
  32. tnothingnodeclass = class of tnothingnode;
  33. terrornode = class(tnode)
  34. constructor create;virtual;
  35. function pass_1 : tnode;override;
  36. function pass_typecheck:tnode;override;
  37. procedure mark_write;override;
  38. end;
  39. terrornodeclass = class of terrornode;
  40. tspecializenode = class(tunarynode)
  41. sym:tsym;
  42. getaddr:boolean;
  43. constructor create(l:tnode;g:boolean;s:tsym);virtual;
  44. function pass_1:tnode;override;
  45. function pass_typecheck:tnode;override;
  46. end;
  47. tspecializenodeclass = class of tspecializenode;
  48. tasmnode = class(tnode)
  49. p_asm : TAsmList;
  50. currenttai : tai;
  51. { Used registers in assembler block }
  52. has_registerlist : boolean;
  53. constructor create(p : TAsmList);virtual;
  54. constructor create_get_position;
  55. destructor destroy;override;
  56. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  57. procedure ppuwrite(ppufile:tcompilerppufile);override;
  58. procedure buildderefimpl;override;
  59. procedure derefimpl;override;
  60. function dogetcopy : tnode;override;
  61. function pass_1 : tnode;override;
  62. function pass_typecheck:tnode;override;
  63. function docompare(p: tnode): boolean; override;
  64. end;
  65. tasmnodeclass = class of tasmnode;
  66. tstatementnode = class(tbinarynode)
  67. constructor create(l,r : tnode);virtual;
  68. function simplify(forinline : boolean) : tnode; override;
  69. function pass_1 : tnode;override;
  70. function pass_typecheck:tnode;override;
  71. procedure printnodetree(var t:text);override;
  72. property statement : tnode read left write left;
  73. property next : tnode read right write right;
  74. end;
  75. tstatementnodeclass = class of tstatementnode;
  76. tblocknode = class(tunarynode)
  77. constructor create(l : tnode);virtual;
  78. destructor destroy; override;
  79. function simplify(forinline : boolean) : tnode; override;
  80. function pass_1 : tnode;override;
  81. function pass_typecheck:tnode;override;
  82. {$ifdef state_tracking}
  83. function track_state_pass(exec_known:boolean):boolean;override;
  84. {$endif state_tracking}
  85. property statements : tnode read left write left;
  86. end;
  87. tblocknodeclass = class of tblocknode;
  88. ttempcreatenode = class;
  89. ttempinfoflag = (
  90. { temp can be kept in a register as far as the original creator is
  91. concerned }
  92. ti_may_be_in_reg,
  93. { the ttempcreatenode has been process and the temp's location is
  94. valid (-> the ttempdeletenode has not yet been processed, or
  95. in case it's a "create_to_normal()" one, the final ttemprefnode
  96. has not yet been processed) }
  97. ti_valid,
  98. { when performing a getcopy of a nodetree, we have to hook up the
  99. copies of ttemprefnodes and ttempdestroynode to the copied
  100. ttempinfo. this is done by setting hookoncopy in the original
  101. ttempinfo to point to the new one. if the temp is deleted via a
  102. regular ttempdeletenode, the hookoncopy is simply set to nil once
  103. it's processed. otherwise, it sets the ti_nextref_set_hookoncopy_nil
  104. and after processing the final ttemprefnode, hookoncopy is set to nil
  105. }
  106. ti_nextref_set_hookoncopy_nil,
  107. { the address of this temp is taken (-> cannot be kept in a register,
  108. even if the creator didn't mind)
  109. }
  110. ti_addr_taken,
  111. { temps can get an extra node tree that contains the value to which
  112. they should be initialised when they are created. this initialisation
  113. has to be performed right before the first reference to the temp.
  114. this flag indicates that the ttempcreatenode has been
  115. processed by pass_generate_code, but that the first ttemprefnode
  116. hasn't yet and hence will have to perform the initialisation
  117. }
  118. ti_executeinitialisation,
  119. { in case an expression like "inc(x[func()],1)" is translated into
  120. a regular addition, you have to create a temp to hold the address
  121. representing x[func()], since otherwise func() will be called twice
  122. and that can spell trouble in case it has side effects. on platforms
  123. without pointers, we cannot just take the address though. this flag
  124. has to be combined with ti_executeinitialisation above and will,
  125. rather than loading the value at the calculated location and store
  126. it in the temp, keep a copy of the calculated location if possible
  127. and required (not possible for regvars, because SSA may change their
  128. register, but not required for them either since calculating their
  129. location has no side-effects
  130. }
  131. ti_reference,
  132. { this temp only allows reading (makes it possible to safely use as
  133. reference under more circumstances)
  134. }
  135. ti_readonly,
  136. { if this is a managed temp, it doesn't have to be finalised before use
  137. }
  138. ti_nofini,
  139. { the value described by this temp. node is const/immutable, this is important for
  140. managed types like ansistrings where temp. refs are pointers to the actual value
  141. -- in this case, assignments to the temp do not increase the
  142. reference count, and if the assigned value was a temp itself then
  143. that temp is not deallocated until this temp is deleted (since
  144. otherwise the assigned value may be freed before the last use of
  145. the temp) }
  146. ti_const,
  147. { the temp. needs no final sync instruction if it is located in a register,
  148. so there are no loops involved in the usage of the temp.
  149. }
  150. ti_no_final_regsync,
  151. { this applied only to delete nodes: the single purpose of the temp. delete node is to clean up memory. In case
  152. of cse it might happen that the tempcreate node is optimized away so tempinfo is never initialized properly but
  153. the allocated memory must be disposed
  154. If a temp. node has this flag set, the life time of the temp. data must be determined by reg. life, the temp.
  155. location (in the sense of stack space/register) is never release }
  156. ti_cleanup_only
  157. );
  158. ttempinfoflags = set of ttempinfoflag;
  159. const
  160. tempinfostoreflags = [ti_may_be_in_reg,ti_addr_taken,ti_reference,ti_readonly,ti_no_final_regsync];
  161. type
  162. { to allow access to the location by temp references even after the temp has }
  163. { already been disposed and to make sure the coherency between temps and }
  164. { temp references is kept after a getcopy }
  165. ptempinfo = ^ttempinfo;
  166. ttempinfo = object
  167. private
  168. flags : ttempinfoflags;
  169. public
  170. { set to the copy of a tempcreate pnode (if it gets copied) so that the }
  171. { refs and deletenode can hook to this copy once they get copied too }
  172. hookoncopy : ptempinfo;
  173. typedef : tdef;
  174. typedefderef : tderef;
  175. temptype : ttemptype;
  176. owner : ttempcreatenode;
  177. withnode : tnode;
  178. location : tlocation;
  179. tempinitcode : tnode;
  180. end;
  181. ttempinfoaccessor = class
  182. class procedure settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags); virtual;
  183. class function gettempinfoflags(tempinfo: ptempinfo): ttempinfoflags; static; inline;
  184. end;
  185. ttempinfoaccessorclass = class of ttempinfoaccessor;
  186. ttempbasenode = class(tnode)
  187. protected
  188. class var tempinfoaccessor: ttempinfoaccessorclass;
  189. protected
  190. procedure settempinfoflags(const tempflags: ttempinfoflags); inline;
  191. function gettempinfoflags: ttempinfoflags; inline;
  192. public
  193. tempinfo: ptempinfo;
  194. procedure includetempflag(flag: ttempinfoflag); inline;
  195. procedure excludetempflag(flag: ttempinfoflag); inline;
  196. property tempflags: ttempinfoflags read gettempinfoflags write settempinfoflags;
  197. end;
  198. { a node which will create a (non)persistent temp of a given type with a given }
  199. { size (the size is separate to allow creating "void" temps with a custom size) }
  200. ttempcreatenode = class(ttempbasenode)
  201. size: tcgint;
  202. ftemplvalue : tnode;
  203. { * persistent temps are used in manually written code where the temp }
  204. { be usable among different statements and where you can manually say }
  205. { when the temp has to be freed (using a ttempdeletenode) }
  206. { * non-persistent temps are mostly used in typeconversion helpers, }
  207. { where the node that receives the temp becomes responsible for }
  208. { freeing it. In this last case, you must use only one reference }
  209. { to it and *not* generate a ttempdeletenode }
  210. constructor create(_typedef: tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean); virtual;
  211. constructor create_withnode(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg:boolean; withnode: tnode); virtual;
  212. constructor create_value(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode);
  213. constructor create_reference(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode; readonly: boolean);
  214. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  215. procedure ppuwrite(ppufile:tcompilerppufile);override;
  216. procedure buildderefimpl;override;
  217. procedure derefimpl;override;
  218. function dogetcopy: tnode; override;
  219. function pass_1 : tnode; override;
  220. function pass_typecheck: tnode; override;
  221. function docompare(p: tnode): boolean; override;
  222. procedure printnodedata(var t:text);override;
  223. end;
  224. ttempcreatenodeclass = class of ttempcreatenode;
  225. { a node which is a reference to a certain temp }
  226. ttemprefnode = class(ttempbasenode)
  227. constructor create(const temp: ttempcreatenode); virtual;
  228. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  229. procedure ppuwrite(ppufile:tcompilerppufile);override;
  230. procedure resolveppuidx;override;
  231. function dogetcopy: tnode; override;
  232. function pass_1 : tnode; override;
  233. function pass_typecheck : tnode; override;
  234. procedure mark_write;override;
  235. function docompare(p: tnode): boolean; override;
  236. procedure printnodedata(var t:text);override;
  237. private
  238. tempidx : longint;
  239. end;
  240. ttemprefnodeclass = class of ttemprefnode;
  241. { a node which removes a temp }
  242. ttempdeletenode = class(ttempbasenode)
  243. constructor create(const temp: ttempcreatenode); virtual;
  244. { this will convert the persistant temp to a normal temp
  245. for returning to the other nodes }
  246. constructor create_normal_temp(const temp: ttempcreatenode);
  247. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  248. procedure ppuwrite(ppufile:tcompilerppufile);override;
  249. procedure resolveppuidx;override;
  250. function dogetcopy: tnode; override;
  251. function pass_1: tnode; override;
  252. function pass_typecheck: tnode; override;
  253. function docompare(p: tnode): boolean; override;
  254. destructor destroy; override;
  255. procedure printnodedata(var t:text);override;
  256. protected
  257. release_to_normal : boolean;
  258. private
  259. tempidx : longint;
  260. end;
  261. ttempdeletenodeclass = class of ttempdeletenode;
  262. var
  263. cnothingnode : tnothingnodeclass = tnothingnode;
  264. cerrornode : terrornodeclass = terrornode;
  265. cspecializenode : tspecializenodeclass = tspecializenode;
  266. casmnode : tasmnodeclass = tasmnode;
  267. cstatementnode : tstatementnodeclass = tstatementnode;
  268. cblocknode : tblocknodeclass = tblocknode;
  269. ctempinfoaccessor : ttempinfoaccessorclass = ttempinfoaccessor;
  270. ctempcreatenode : ttempcreatenodeclass = ttempcreatenode;
  271. ctemprefnode : ttemprefnodeclass = ttemprefnode;
  272. ctempdeletenode : ttempdeletenodeclass = ttempdeletenode;
  273. { Create a blocknode and statement node for multiple statements
  274. generated internally by the parser }
  275. function internalstatements(out laststatement:tstatementnode):tblocknode;
  276. function laststatement(block:tblocknode):tstatementnode;
  277. procedure addstatement(var laststatement:tstatementnode;n:tnode);
  278. { if the complexity of n is "high", creates a reference temp to n's
  279. location and replace n with a ttemprefnode referring to that location }
  280. function maybereplacewithtempref(var n: tnode; var block: tblocknode; var stat: tstatementnode; size: ASizeInt; readonly: boolean): ttempcreatenode;
  281. implementation
  282. uses
  283. verbose,globals,systems,
  284. symconst,symdef,defutil,defcmp,
  285. pass_1,
  286. nutils,nld,
  287. procinfo
  288. ;
  289. {*****************************************************************************
  290. Helpers
  291. *****************************************************************************}
  292. function internalstatements(out laststatement:tstatementnode):tblocknode;
  293. begin
  294. { create dummy initial statement }
  295. laststatement := cstatementnode.create(cnothingnode.create,nil);
  296. internalstatements := cblocknode.create(laststatement);
  297. end;
  298. function laststatement(block:tblocknode):tstatementnode;
  299. begin
  300. result:=tstatementnode(block.left);
  301. while assigned(result) and assigned(result.right) do
  302. result:=tstatementnode(result.right);
  303. end;
  304. procedure addstatement(var laststatement:tstatementnode;n:tnode);
  305. begin
  306. if assigned(laststatement.right) then
  307. internalerror(200204201);
  308. laststatement.right:=cstatementnode.create(n,nil);
  309. laststatement:=tstatementnode(laststatement.right);
  310. end;
  311. function maybereplacewithtempref(var n: tnode; var block: tblocknode; var stat: tstatementnode; size: ASizeInt; readonly: boolean): ttempcreatenode;
  312. begin
  313. result:=nil;
  314. if node_complexity(n) > 4 then
  315. begin
  316. result:=ctempcreatenode.create_reference(n.resultdef,size,tt_persistent,true,n,readonly);
  317. typecheckpass(tnode(result));
  318. n:=ctemprefnode.create(result);
  319. typecheckpass(n);
  320. if not assigned(stat) then
  321. block:=internalstatements(stat);
  322. addstatement(stat,result)
  323. end;
  324. end;
  325. {*****************************************************************************
  326. TFIRSTNOTHING
  327. *****************************************************************************}
  328. constructor tnothingnode.create;
  329. begin
  330. inherited create(nothingn);
  331. end;
  332. function tnothingnode.pass_typecheck:tnode;
  333. begin
  334. result:=nil;
  335. resultdef:=voidtype;
  336. end;
  337. function tnothingnode.pass_1 : tnode;
  338. begin
  339. result:=nil;
  340. expectloc:=LOC_VOID;
  341. end;
  342. {*****************************************************************************
  343. TFIRSTERROR
  344. *****************************************************************************}
  345. constructor terrornode.create;
  346. begin
  347. inherited create(errorn);
  348. end;
  349. function terrornode.pass_typecheck:tnode;
  350. begin
  351. result:=nil;
  352. include(flags,nf_error);
  353. codegenerror:=true;
  354. resultdef:=generrordef;
  355. end;
  356. function terrornode.pass_1 : tnode;
  357. begin
  358. result:=nil;
  359. expectloc:=LOC_VOID;
  360. codegenerror:=true;
  361. end;
  362. procedure terrornode.mark_write;
  363. begin
  364. end;
  365. {*****************************************************************************
  366. TSPECIALIZENODE
  367. *****************************************************************************}
  368. constructor tspecializenode.create(l:tnode;g:boolean;s:tsym);
  369. begin
  370. inherited create(specializen,l);
  371. sym:=s;
  372. getaddr:=g;
  373. end;
  374. function tspecializenode.pass_typecheck:tnode;
  375. begin
  376. result:=nil;
  377. resultdef:=cundefinedtype;
  378. end;
  379. function tspecializenode.pass_1:tnode;
  380. begin
  381. { such a node should not reach pass_1 }
  382. internalerror(2015071704);
  383. result:=nil;
  384. expectloc:=LOC_VOID;
  385. codegenerror:=true;
  386. end;
  387. {*****************************************************************************
  388. TSTATEMENTNODE
  389. *****************************************************************************}
  390. constructor tstatementnode.create(l,r : tnode);
  391. begin
  392. inherited create(statementn,l,r);
  393. end;
  394. function is_exit_statement(var n: tnode; arg: pointer): foreachnoderesult;
  395. begin
  396. if (n.nodetype<>exitn) then
  397. result:=fen_false
  398. else
  399. result:=fen_norecurse_true;
  400. end;
  401. function no_exit_statement_in_block(n: tnode): boolean;
  402. begin
  403. result:=not foreachnodestatic(n,@is_exit_statement,nil);
  404. end;
  405. function tstatementnode.simplify(forinline: boolean) : tnode;
  406. begin
  407. result:=nil;
  408. { these "optimizations" are only to make it more easy to recognise }
  409. { blocknodes which at the end of inlining only contain one single }
  410. { statement. Simplifying inside blocknode.simplify could be dangerous }
  411. { because if the main blocknode which makes up a procedure/function }
  412. { body were replaced with a statementn/nothingn, this could cause }
  413. { problems elsewhere in the compiler which expects a blocknode }
  414. { remove next statement if it's a nothing-statement (since if it's }
  415. { the last, it won't remove itself -- see next simplification) }
  416. while assigned(right) and
  417. (tstatementnode(right).left.nodetype = nothingn) do
  418. begin
  419. result:=tstatementnode(right).right;
  420. tstatementnode(right).right:=nil;
  421. right.free;
  422. right:=result;
  423. result:=nil;
  424. end;
  425. { Remove initial nothingn if there are other statements. If there }
  426. { are no other statements, returning nil doesn't help (will be }
  427. { interpreted as "can't be simplified") and replacing the }
  428. { statementnode with a nothingnode cannot be done (because it's }
  429. { possible this statementnode is a child of a blocknode, and }
  430. { blocknodes are expected to only contain statementnodes) }
  431. if (left.nodetype = nothingn) and
  432. assigned(right) then
  433. begin
  434. result:=right;
  435. right:=nil;
  436. exit;
  437. end;
  438. { if the current statement contains a block with one statement,
  439. replace the current statement with that block's statement
  440. (but only if the block does not have nf_block_with_exit set
  441. or has no exit statement, because otherwise it needs an own
  442. exit label, see tests/test/tinline10)
  443. Further, it might not be the user code entry
  444. }
  445. if (left.nodetype = blockn) and
  446. ((left.flags*[nf_block_with_exit,nf_usercode_entry]=[]) or
  447. ((left.flags*[nf_block_with_exit,nf_usercode_entry]=[nf_block_with_exit]) and no_exit_statement_in_block(left))) and
  448. assigned(tblocknode(left).left) and
  449. not assigned(tstatementnode(tblocknode(left).left).right) then
  450. begin
  451. result:=tblocknode(left).left;
  452. tstatementnode(result).right:=right;
  453. right:=nil;
  454. tblocknode(left).left:=nil;
  455. exit;
  456. end;
  457. end;
  458. function tstatementnode.pass_typecheck:tnode;
  459. begin
  460. result:=nil;
  461. resultdef:=voidtype;
  462. { left is the statement itself calln assignn or a complex one }
  463. typecheckpass(left);
  464. if codegenerror then
  465. exit;
  466. { right is the next statement in the list }
  467. if assigned(right) then
  468. typecheckpass(right);
  469. if codegenerror then
  470. exit;
  471. end;
  472. function tstatementnode.pass_1 : tnode;
  473. begin
  474. result:=nil;
  475. { left is the statement itself calln assignn or a complex one }
  476. firstpass(left);
  477. if codegenerror then
  478. exit;
  479. expectloc:=left.expectloc;
  480. { right is the next in the list }
  481. if assigned(right) then
  482. firstpass(right);
  483. if codegenerror then
  484. exit;
  485. end;
  486. procedure tstatementnode.printnodetree(var t:text);
  487. begin
  488. printnodelist(t);
  489. end;
  490. {*****************************************************************************
  491. TBLOCKNODE
  492. *****************************************************************************}
  493. constructor tblocknode.create(l : tnode);
  494. begin
  495. inherited create(blockn,l);
  496. end;
  497. destructor tblocknode.destroy;
  498. var
  499. hp, next: tstatementnode;
  500. begin
  501. hp := tstatementnode(left);
  502. left := nil;
  503. while assigned(hp) do
  504. begin
  505. next := tstatementnode(hp.right);
  506. hp.right := nil;
  507. hp.free;
  508. hp := next;
  509. end;
  510. inherited destroy;
  511. end;
  512. function tblocknode.simplify(forinline : boolean): tnode;
  513. begin
  514. result := nil;
  515. { Warning: never replace a blocknode with another node type, }
  516. { since the block may be the main block of a procedure/function/ }
  517. { main program body, and those nodes should always be blocknodes }
  518. { since that's what the compiler expects elsewhere. }
  519. if assigned(left) and
  520. not assigned(tstatementnode(left).right) then
  521. begin
  522. case tstatementnode(left).left.nodetype of
  523. blockn:
  524. begin
  525. { if the current block contains only one statement, and
  526. this one statement only contains another block, replace
  527. this block with that other block. }
  528. result:=tstatementnode(left).left;
  529. tstatementnode(left).left:=nil;
  530. { make sure the nf_block_with_exit flag is safeguarded }
  531. result.flags:=result.flags+(flags*[nf_block_with_exit,nf_usercode_entry]);
  532. exit;
  533. end;
  534. nothingn:
  535. begin
  536. { if the block contains only a statement with a nothing node,
  537. get rid of the statement }
  538. left.Free;
  539. left:=nil;
  540. exit;
  541. end;
  542. end;
  543. end;
  544. end;
  545. function tblocknode.pass_typecheck:tnode;
  546. var
  547. hp : tstatementnode;
  548. begin
  549. result:=nil;
  550. resultdef:=voidtype;
  551. hp:=tstatementnode(left);
  552. while assigned(hp) do
  553. begin
  554. if assigned(hp.left) then
  555. begin
  556. codegenerror:=false;
  557. typecheckpass(hp.left);
  558. { the resultdef of the block is the last type that is
  559. returned. Normally this is a voidtype. But when the
  560. compiler inserts a block of multiple statements then the
  561. last entry can return a value }
  562. resultdef:=hp.left.resultdef;
  563. end;
  564. hp:=tstatementnode(hp.right);
  565. end;
  566. end;
  567. function tblocknode.pass_1 : tnode;
  568. var
  569. hp : tstatementnode;
  570. //count : longint;
  571. begin
  572. result:=nil;
  573. expectloc:=LOC_VOID;
  574. //count:=0;
  575. hp:=tstatementnode(left);
  576. while assigned(hp) do
  577. begin
  578. if assigned(hp.left) then
  579. begin
  580. codegenerror:=false;
  581. firstpass(hp.left);
  582. hp.expectloc:=hp.left.expectloc;
  583. end;
  584. expectloc:=hp.expectloc;
  585. //inc(count);
  586. hp:=tstatementnode(hp.right);
  587. end;
  588. end;
  589. {$ifdef state_tracking}
  590. function Tblocknode.track_state_pass(exec_known:boolean):boolean;
  591. var hp:Tstatementnode;
  592. begin
  593. track_state_pass:=false;
  594. hp:=Tstatementnode(left);
  595. while assigned(hp) do
  596. begin
  597. if hp.left.track_state_pass(exec_known) then
  598. track_state_pass:=true;
  599. hp:=Tstatementnode(hp.right);
  600. end;
  601. end;
  602. {$endif state_tracking}
  603. {*****************************************************************************
  604. TASMNODE
  605. *****************************************************************************}
  606. constructor tasmnode.create(p : TAsmList);
  607. begin
  608. inherited create(asmn);
  609. p_asm:=p;
  610. currenttai:=nil;
  611. end;
  612. constructor tasmnode.create_get_position;
  613. begin
  614. inherited create(asmn);
  615. p_asm:=nil;
  616. include(flags,nf_get_asm_position);
  617. currenttai:=nil;
  618. end;
  619. destructor tasmnode.destroy;
  620. begin
  621. if assigned(p_asm) then
  622. p_asm.free;
  623. inherited destroy;
  624. end;
  625. constructor tasmnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  626. var
  627. hp : tai;
  628. begin
  629. inherited ppuload(t,ppufile);
  630. if not(nf_get_asm_position in flags) then
  631. begin
  632. p_asm:=TAsmList.create;
  633. repeat
  634. hp:=ppuloadai(ppufile);
  635. if hp=nil then
  636. break;
  637. p_asm.concat(hp);
  638. if hp.typ=ait_section then
  639. inc(p_asm.section_count);
  640. until false;
  641. end
  642. else
  643. p_asm:=nil;
  644. currenttai:=nil;
  645. end;
  646. procedure tasmnode.ppuwrite(ppufile:tcompilerppufile);
  647. var
  648. hp : tai;
  649. begin
  650. inherited ppuwrite(ppufile);
  651. { TODO: FIXME Add saving of register sets}
  652. if not(nf_get_asm_position in flags) then
  653. begin
  654. hp:=tai(p_asm.first);
  655. while assigned(hp) do
  656. begin
  657. ppuwriteai(ppufile,hp);
  658. hp:=tai(hp.next);
  659. end;
  660. { end is marked by a nil }
  661. ppuwriteai(ppufile,nil);
  662. end;
  663. end;
  664. procedure tasmnode.buildderefimpl;
  665. var
  666. hp : tai;
  667. begin
  668. inherited buildderefimpl;
  669. if not(nf_get_asm_position in flags) then
  670. begin
  671. hp:=tai(p_asm.first);
  672. while assigned(hp) do
  673. begin
  674. hp.buildderefimpl;
  675. hp:=tai(hp.next);
  676. end;
  677. end;
  678. end;
  679. procedure tasmnode.derefimpl;
  680. var
  681. hp : tai;
  682. begin
  683. inherited derefimpl;
  684. if not(nf_get_asm_position in flags) then
  685. begin
  686. hp:=tai(p_asm.first);
  687. while assigned(hp) do
  688. begin
  689. hp.derefimpl;
  690. hp:=tai(hp.next);
  691. end;
  692. end;
  693. end;
  694. function tasmnode.dogetcopy: tnode;
  695. var
  696. n: tasmnode;
  697. begin
  698. n := tasmnode(inherited dogetcopy);
  699. if assigned(p_asm) then
  700. begin
  701. n.p_asm:=TAsmList.create;
  702. n.p_asm.concatlistcopy(p_asm);
  703. n.p_asm.section_count:=p_asm.section_count;
  704. end
  705. else n.p_asm := nil;
  706. n.currenttai:=currenttai;
  707. n.has_registerlist:=has_registerlist;
  708. result:=n;
  709. end;
  710. function tasmnode.pass_typecheck:tnode;
  711. begin
  712. result:=nil;
  713. resultdef:=voidtype;
  714. if not(nf_get_asm_position in flags) then
  715. include(current_procinfo.flags,pi_has_assembler_block);
  716. end;
  717. function tasmnode.pass_1 : tnode;
  718. begin
  719. result:=nil;
  720. expectloc:=LOC_VOID;
  721. end;
  722. function tasmnode.docompare(p: tnode): boolean;
  723. begin
  724. { comparing of asmlists is not implemented (JM) }
  725. docompare := false;
  726. end;
  727. {*****************************************************************************
  728. TEMPBASENODE
  729. *****************************************************************************}
  730. class procedure ttempinfoaccessor.settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags);
  731. begin
  732. tempinfo^.flags:=flags;
  733. end;
  734. class function ttempinfoaccessor.gettempinfoflags(tempinfo: ptempinfo): ttempinfoflags;
  735. begin
  736. result:=tempinfo^.flags;
  737. end;
  738. {*****************************************************************************
  739. TEMPBASENODE
  740. *****************************************************************************}
  741. procedure ttempbasenode.settempinfoflags(const tempflags: ttempinfoflags);
  742. begin
  743. ctempinfoaccessor.settempinfoflags(tempinfo,tempflags);
  744. end;
  745. function ttempbasenode.gettempinfoflags: ttempinfoflags;
  746. begin
  747. result:=ctempinfoaccessor.gettempinfoflags(tempinfo);
  748. end;
  749. procedure ttempbasenode.includetempflag(flag: ttempinfoflag);
  750. begin
  751. { go through settempinfoflags() so it can filter out unsupported tempflags }
  752. settempinfoflags(gettempinfoflags+[flag])
  753. end;
  754. procedure ttempbasenode.excludetempflag(flag: ttempinfoflag);
  755. begin
  756. { go through settempinfoflags() so it can prevent required tempflags from
  757. being removed (if any) }
  758. settempinfoflags(gettempinfoflags-[flag])
  759. end;
  760. {*****************************************************************************
  761. TEMPCREATENODE
  762. *****************************************************************************}
  763. constructor ttempcreatenode.create(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean);
  764. begin
  765. inherited create(tempcreaten);
  766. size := _size;
  767. new(tempinfo);
  768. fillchar(tempinfo^,sizeof(tempinfo^),0);
  769. tempinfo^.typedef := _typedef;
  770. tempinfo^.temptype := _temptype;
  771. tempinfo^.owner := self;
  772. tempinfo^.withnode := nil;
  773. if allowreg and
  774. { temp must fit a single register }
  775. (tstoreddef(_typedef).is_fpuregable or
  776. (tstoreddef(_typedef).is_intregable and
  777. (_size<=TCGSize2Size[OS_64]))) and
  778. { size of register operations must be known }
  779. (def_cgsize(_typedef)<>OS_NO) and
  780. { no init/final needed }
  781. not is_managed_type(_typedef) then
  782. includetempflag(ti_may_be_in_reg);
  783. end;
  784. constructor ttempcreatenode.create_withnode(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg:boolean; withnode: tnode);
  785. begin
  786. self.create(_typedef,_size,_temptype,allowreg);
  787. tempinfo^.withnode:=withnode.getcopy;
  788. end;
  789. constructor ttempcreatenode.create_value(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode);
  790. begin
  791. self.create(_typedef,_size,_temptype,allowreg);
  792. // store in ppuwrite
  793. ftemplvalue:=templvalue;
  794. // create from stored ftemplvalue in ppuload
  795. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  796. end;
  797. constructor ttempcreatenode.create_reference(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg: boolean; templvalue: tnode; readonly: boolean);
  798. begin
  799. // store in ppuwrite
  800. self.create(_typedef,_size,_temptype,allowreg);
  801. ftemplvalue:=templvalue;
  802. // no assignment node, just the tempvalue
  803. tempinfo^.tempinitcode:=ftemplvalue;
  804. includetempflag(ti_reference);
  805. if readonly then
  806. includetempflag(ti_readonly);
  807. end;
  808. function ttempcreatenode.dogetcopy: tnode;
  809. var
  810. n: ttempcreatenode;
  811. begin
  812. n := ttempcreatenode(inherited dogetcopy);
  813. n.size := size;
  814. new(n.tempinfo);
  815. fillchar(n.tempinfo^,sizeof(n.tempinfo^),0);
  816. n.tempinfo^.owner:=n;
  817. n.tempinfo^.typedef := tempinfo^.typedef;
  818. n.tempinfo^.temptype := tempinfo^.temptype;
  819. n.tempflags := tempflags * tempinfostoreflags;
  820. { when the tempinfo has already a hookoncopy then it is not
  821. reset by a tempdeletenode }
  822. if assigned(tempinfo^.hookoncopy) then
  823. internalerror(200211262);
  824. { signal the temprefs that the temp they point to has been copied, }
  825. { so that if the refs get copied as well, they can hook themselves }
  826. { to the copy of the temp }
  827. tempinfo^.hookoncopy := n.tempinfo;
  828. excludetempflag(ti_nextref_set_hookoncopy_nil);
  829. if assigned(tempinfo^.withnode) then
  830. n.tempinfo^.withnode := tempinfo^.withnode.getcopy
  831. else
  832. n.tempinfo^.withnode := nil;
  833. if assigned(tempinfo^.tempinitcode) then
  834. n.tempinfo^.tempinitcode := tempinfo^.tempinitcode.getcopy
  835. else
  836. n.tempinfo^.tempinitcode := nil;
  837. result := n;
  838. end;
  839. constructor ttempcreatenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  840. begin
  841. inherited ppuload(t,ppufile);
  842. size:=ppufile.getlongint;
  843. new(tempinfo);
  844. fillchar(tempinfo^,sizeof(tempinfo^),0);
  845. ppufile.getsmallset(tempinfo^.flags);
  846. ppufile.getderef(tempinfo^.typedefderef);
  847. tempinfo^.temptype := ttemptype(ppufile.getbyte);
  848. tempinfo^.owner:=self;
  849. tempinfo^.withnode:=ppuloadnode(ppufile);
  850. ftemplvalue:=ppuloadnode(ppufile);
  851. end;
  852. procedure ttempcreatenode.ppuwrite(ppufile:tcompilerppufile);
  853. begin
  854. inherited ppuwrite(ppufile);
  855. ppufile.putlongint(size);
  856. ppufile.putsmallset(tempinfo^.flags);
  857. ppufile.putderef(tempinfo^.typedefderef);
  858. ppufile.putbyte(byte(tempinfo^.temptype));
  859. ppuwritenode(ppufile,tempinfo^.withnode);
  860. ppuwritenode(ppufile,ftemplvalue);
  861. end;
  862. procedure ttempcreatenode.buildderefimpl;
  863. begin
  864. inherited buildderefimpl;
  865. tempinfo^.typedefderef.build(tempinfo^.typedef);
  866. if assigned(tempinfo^.withnode) then
  867. tempinfo^.withnode.buildderefimpl;
  868. if assigned(ftemplvalue) then
  869. ftemplvalue.buildderefimpl;
  870. end;
  871. procedure ttempcreatenode.derefimpl;
  872. begin
  873. inherited derefimpl;
  874. tempinfo^.typedef:=tdef(tempinfo^.typedefderef.resolve);
  875. if assigned(tempinfo^.withnode) then
  876. tempinfo^.withnode.derefimpl;
  877. if assigned(ftemplvalue) then
  878. begin
  879. ftemplvalue.derefimpl;
  880. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  881. end;
  882. end;
  883. function ttempcreatenode.pass_1 : tnode;
  884. begin
  885. result := nil;
  886. expectloc:=LOC_VOID;
  887. { temps which are immutable do not need to be initialized/finalized }
  888. if (tempinfo^.typedef.needs_inittable) and not(ti_const in tempflags) then
  889. include(current_procinfo.flags,pi_needs_implicit_finally);
  890. if (cs_create_pic in current_settings.moduleswitches) and
  891. (tf_pic_uses_got in target_info.flags) and
  892. is_rtti_managed_type(tempinfo^.typedef) then
  893. include(current_procinfo.flags,pi_needs_got);
  894. if assigned(tempinfo^.withnode) then
  895. firstpass(tempinfo^.withnode);
  896. if assigned(tempinfo^.tempinitcode) then
  897. firstpass(tempinfo^.tempinitcode);
  898. inc(current_procinfo.estimatedtempsize,size);;
  899. end;
  900. function ttempcreatenode.pass_typecheck: tnode;
  901. begin
  902. result := nil;
  903. { a tempcreatenode doesn't have a resultdef, only temprefnodes do }
  904. resultdef := voidtype;
  905. if assigned(tempinfo^.withnode) then
  906. typecheckpass(tempinfo^.withnode);
  907. if assigned(tempinfo^.tempinitcode) then
  908. typecheckpass(tempinfo^.tempinitcode);
  909. end;
  910. function ttempcreatenode.docompare(p: tnode): boolean;
  911. begin
  912. result :=
  913. inherited docompare(p) and
  914. (ttempcreatenode(p).size = size) and
  915. (ttempcreatenode(p).tempflags*tempinfostoreflags=tempflags*tempinfostoreflags) and
  916. equal_defs(ttempcreatenode(p).tempinfo^.typedef,tempinfo^.typedef) and
  917. (ttempcreatenode(p).tempinfo^.withnode.isequal(tempinfo^.withnode)) and
  918. (ttempcreatenode(p).tempinfo^.tempinitcode.isequal(tempinfo^.tempinitcode));
  919. end;
  920. procedure ttempcreatenode.printnodedata(var t:text);
  921. begin
  922. inherited printnodedata(t);
  923. writeln(t,printnodeindention,'size = ',size,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  924. tempinfo^.typedef.GetTypeName,'", tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  925. writeln(t,printnodeindention,'tempinit =');
  926. printnode(t,tempinfo^.tempinitcode);
  927. end;
  928. {*****************************************************************************
  929. TEMPREFNODE
  930. *****************************************************************************}
  931. constructor ttemprefnode.create(const temp: ttempcreatenode);
  932. begin
  933. inherited create(temprefn);
  934. tempinfo := temp.tempinfo;
  935. end;
  936. function ttemprefnode.dogetcopy: tnode;
  937. var
  938. n: ttemprefnode;
  939. begin
  940. n := ttemprefnode(inherited dogetcopy);
  941. if assigned(tempinfo^.hookoncopy) then
  942. { if the temp has been copied, assume it becomes a new }
  943. { temp which has to be hooked by the copied reference }
  944. begin
  945. { hook the ref to the copied temp }
  946. n.tempinfo := tempinfo^.hookoncopy;
  947. { if we passed a ttempdeletenode that changed the temp }
  948. { from a persistent one into a normal one, we must be }
  949. { the last reference (since our parent should free the }
  950. { temp (JM) }
  951. if (ti_nextref_set_hookoncopy_nil in tempflags) then
  952. tempinfo^.hookoncopy := nil;
  953. end
  954. else
  955. { if the temp we refer to hasn't been copied, assume }
  956. { we're just a new reference to that temp }
  957. begin
  958. n.tempinfo := tempinfo;
  959. end;
  960. if not assigned(n.tempinfo) then
  961. internalerror(2005071901);
  962. result := n;
  963. end;
  964. constructor ttemprefnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  965. begin
  966. inherited ppuload(t,ppufile);
  967. tempidx:=ppufile.getlongint;
  968. end;
  969. procedure ttemprefnode.ppuwrite(ppufile:tcompilerppufile);
  970. begin
  971. inherited ppuwrite(ppufile);
  972. ppufile.putlongint(tempinfo^.owner.ppuidx);
  973. end;
  974. procedure ttemprefnode.resolveppuidx;
  975. var
  976. temp : ttempcreatenode;
  977. begin
  978. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  979. if temp.nodetype<>tempcreaten then
  980. internalerror(200311075);
  981. tempinfo:=temp.tempinfo;
  982. end;
  983. function ttemprefnode.pass_1 : tnode;
  984. begin
  985. expectloc := LOC_REFERENCE;
  986. if not tempinfo^.typedef.needs_inittable and
  987. (ti_may_be_in_reg in tempflags) then
  988. begin
  989. if tempinfo^.typedef.typ=floatdef then
  990. begin
  991. if not use_vectorfpu(tempinfo^.typedef) then
  992. if (tempinfo^.temptype = tt_persistent) then
  993. expectloc := LOC_CFPUREGISTER
  994. else
  995. expectloc := LOC_FPUREGISTER
  996. else
  997. if (tempinfo^.temptype = tt_persistent) then
  998. expectloc := LOC_CMMREGISTER
  999. else
  1000. expectloc := LOC_MMREGISTER
  1001. end
  1002. else
  1003. begin
  1004. if (tempinfo^.temptype = tt_persistent) then
  1005. expectloc := LOC_CREGISTER
  1006. else
  1007. expectloc := LOC_REGISTER;
  1008. end;
  1009. end;
  1010. result := nil;
  1011. end;
  1012. function ttemprefnode.pass_typecheck: tnode;
  1013. begin
  1014. { check if the temp is already resultdef passed }
  1015. if not assigned(tempinfo^.typedef) then
  1016. internalerror(200108233);
  1017. result := nil;
  1018. resultdef := tempinfo^.typedef;
  1019. end;
  1020. function ttemprefnode.docompare(p: tnode): boolean;
  1021. begin
  1022. result :=
  1023. inherited docompare(p) and
  1024. (ttemprefnode(p).tempinfo = tempinfo);
  1025. end;
  1026. procedure ttemprefnode.mark_write;
  1027. begin
  1028. include(flags,nf_write);
  1029. end;
  1030. procedure ttemprefnode.printnodedata(var t:text);
  1031. var
  1032. f : ttempinfoflag;
  1033. notfirst : Boolean;
  1034. begin
  1035. inherited printnodedata(t);
  1036. write(t,printnodeindention,'temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1037. tempinfo^.typedef.GetTypeName,'", (tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2),' flags = [');
  1038. notfirst:=false;
  1039. for f in tempinfo^.flags do
  1040. begin
  1041. if notfirst then
  1042. write(t,',');
  1043. write(t,f);
  1044. notfirst:=true;
  1045. end;
  1046. writeln(t,'])');
  1047. end;
  1048. {*****************************************************************************
  1049. TEMPDELETENODE
  1050. *****************************************************************************}
  1051. constructor ttempdeletenode.create(const temp: ttempcreatenode);
  1052. begin
  1053. inherited create(tempdeleten);
  1054. tempinfo := temp.tempinfo;
  1055. release_to_normal := false;
  1056. end;
  1057. constructor ttempdeletenode.create_normal_temp(const temp: ttempcreatenode);
  1058. begin
  1059. inherited create(tempdeleten);
  1060. tempinfo := temp.tempinfo;
  1061. release_to_normal := true;
  1062. if tempinfo^.temptype <> tt_persistent then
  1063. internalerror(200204211);
  1064. end;
  1065. function ttempdeletenode.dogetcopy: tnode;
  1066. var
  1067. n: ttempdeletenode;
  1068. begin
  1069. n:=ttempdeletenode(inherited dogetcopy);
  1070. n.release_to_normal:=release_to_normal;
  1071. if assigned(tempinfo^.hookoncopy) then
  1072. { if the temp has been copied, assume it becomes a new }
  1073. { temp which has to be hooked by the copied deletenode }
  1074. begin
  1075. { hook the tempdeletenode to the copied temp }
  1076. n.tempinfo:=tempinfo^.hookoncopy;
  1077. { the temp shall not be used, reset hookoncopy }
  1078. { Only if release_to_normal is false, otherwise }
  1079. { the temp can still be referenced once more (JM) }
  1080. if (not release_to_normal) then
  1081. tempinfo^.hookoncopy:=nil
  1082. else
  1083. includetempflag(ti_nextref_set_hookoncopy_nil);
  1084. end
  1085. else
  1086. { if the temp we refer to hasn't been copied, we have a }
  1087. { problem since that means we now have two delete nodes }
  1088. { for one temp }
  1089. internalerror(200108234);
  1090. result:=n;
  1091. end;
  1092. constructor ttempdeletenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1093. begin
  1094. inherited ppuload(t,ppufile);
  1095. tempidx:=ppufile.getlongint;
  1096. release_to_normal:=(ppufile.getbyte<>0);
  1097. end;
  1098. procedure ttempdeletenode.ppuwrite(ppufile:tcompilerppufile);
  1099. begin
  1100. inherited ppuwrite(ppufile);
  1101. ppufile.putlongint(tempinfo^.owner.ppuidx);
  1102. ppufile.putbyte(byte(release_to_normal));
  1103. end;
  1104. procedure ttempdeletenode.resolveppuidx;
  1105. var
  1106. temp : ttempcreatenode;
  1107. begin
  1108. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  1109. if temp.nodetype<>tempcreaten then
  1110. internalerror(200311075);
  1111. tempinfo:=temp.tempinfo;
  1112. end;
  1113. function ttempdeletenode.pass_1 : tnode;
  1114. begin
  1115. expectloc:=LOC_VOID;
  1116. result := nil;
  1117. end;
  1118. function ttempdeletenode.pass_typecheck: tnode;
  1119. begin
  1120. result := nil;
  1121. resultdef := voidtype;
  1122. end;
  1123. function ttempdeletenode.docompare(p: tnode): boolean;
  1124. begin
  1125. result :=
  1126. inherited docompare(p) and
  1127. (ttemprefnode(p).tempinfo = tempinfo);
  1128. end;
  1129. destructor ttempdeletenode.destroy;
  1130. begin
  1131. tempinfo^.withnode.free;
  1132. tempinfo^.tempinitcode.free;
  1133. dispose(tempinfo);
  1134. end;
  1135. procedure ttempdeletenode.printnodedata(var t:text);
  1136. begin
  1137. inherited printnodedata(t);
  1138. writeln(t,printnodeindention,'release_to_normal: ',release_to_normal,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1139. tempinfo^.typedef.GetTypeName,'", temptype = ',tempinfo^.temptype,', tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  1140. end;
  1141. end.