nbas.pas 46 KB

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