nbas.pas 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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. end
  711. else n.p_asm := nil;
  712. n.currenttai:=currenttai;
  713. n.has_registerlist:=has_registerlist;
  714. result:=n;
  715. end;
  716. function tasmnode.pass_typecheck:tnode;
  717. begin
  718. result:=nil;
  719. resultdef:=voidtype;
  720. if not(nf_get_asm_position in flags) then
  721. include(current_procinfo.flags,pi_has_assembler_block);
  722. end;
  723. function tasmnode.pass_1 : tnode;
  724. begin
  725. result:=nil;
  726. expectloc:=LOC_VOID;
  727. end;
  728. function tasmnode.docompare(p: tnode): boolean;
  729. begin
  730. { comparing of asmlists is not implemented (JM) }
  731. docompare := false;
  732. end;
  733. {*****************************************************************************
  734. TEMPBASENODE
  735. *****************************************************************************}
  736. class procedure ttempinfoaccessor.settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags);
  737. begin
  738. tempinfo^.flags:=flags;
  739. end;
  740. class function ttempinfoaccessor.gettempinfoflags(tempinfo: ptempinfo): ttempinfoflags;
  741. begin
  742. result:=tempinfo^.flags;
  743. end;
  744. {*****************************************************************************
  745. TEMPBASENODE
  746. *****************************************************************************}
  747. procedure ttempbasenode.settempinfoflags(const tempflags: ttempinfoflags);
  748. begin
  749. ctempinfoaccessor.settempinfoflags(tempinfo,tempflags);
  750. end;
  751. function ttempbasenode.gettempinfoflags: ttempinfoflags;
  752. begin
  753. result:=ctempinfoaccessor.gettempinfoflags(tempinfo);
  754. end;
  755. procedure ttempbasenode.includetempflag(flag: ttempinfoflag);
  756. begin
  757. { go through settempinfoflags() so it can filter out unsupported tempflags }
  758. settempinfoflags(gettempinfoflags+[flag])
  759. end;
  760. procedure ttempbasenode.excludetempflag(flag: ttempinfoflag);
  761. begin
  762. { go through settempinfoflags() so it can prevent required tempflags from
  763. being removed (if any) }
  764. settempinfoflags(gettempinfoflags-[flag])
  765. end;
  766. {*****************************************************************************
  767. TEMPCREATENODE
  768. *****************************************************************************}
  769. constructor ttempcreatenode.create(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean);
  770. begin
  771. inherited create(tempcreaten);
  772. size := _size;
  773. new(tempinfo);
  774. fillchar(tempinfo^,sizeof(tempinfo^),0);
  775. tempinfo^.typedef := _typedef;
  776. tempinfo^.temptype := _temptype;
  777. tempinfo^.owner := self;
  778. tempinfo^.withnode := nil;
  779. if allowreg and
  780. { temp must fit a single register }
  781. (tstoreddef(_typedef).is_fpuregable or
  782. (tstoreddef(_typedef).is_intregable and
  783. (_size<=TCGSize2Size[OS_64]))) and
  784. { size of register operations must be known }
  785. (def_cgsize(_typedef)<>OS_NO) and
  786. { no init/final needed }
  787. not is_managed_type(_typedef) then
  788. includetempflag(ti_may_be_in_reg);
  789. end;
  790. constructor ttempcreatenode.create_withnode(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg:boolean; withnode: tnode);
  791. begin
  792. self.create(_typedef,_size,_temptype,allowreg);
  793. tempinfo^.withnode:=withnode.getcopy;
  794. end;
  795. constructor ttempcreatenode.create_value(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode);
  796. begin
  797. self.create(_typedef,_size,_temptype,allowreg);
  798. // store in ppuwrite
  799. ftemplvalue:=templvalue;
  800. // create from stored ftemplvalue in ppuload
  801. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  802. end;
  803. constructor ttempcreatenode.create_reference(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg: boolean; templvalue: tnode; readonly: boolean);
  804. begin
  805. // store in ppuwrite
  806. self.create(_typedef,_size,_temptype,allowreg);
  807. ftemplvalue:=templvalue;
  808. // no assignment node, just the tempvalue
  809. tempinfo^.tempinitcode:=ftemplvalue;
  810. includetempflag(ti_reference);
  811. if readonly then
  812. includetempflag(ti_readonly);
  813. end;
  814. function ttempcreatenode.dogetcopy: tnode;
  815. var
  816. n: ttempcreatenode;
  817. begin
  818. n := ttempcreatenode(inherited dogetcopy);
  819. n.size := size;
  820. new(n.tempinfo);
  821. fillchar(n.tempinfo^,sizeof(n.tempinfo^),0);
  822. n.tempinfo^.owner:=n;
  823. n.tempinfo^.typedef := tempinfo^.typedef;
  824. n.tempinfo^.temptype := tempinfo^.temptype;
  825. n.tempflags := tempflags * tempinfostoreflags;
  826. { when the tempinfo has already a hookoncopy then it is not
  827. reset by a tempdeletenode }
  828. if assigned(tempinfo^.hookoncopy) then
  829. internalerror(200211262);
  830. { signal the temprefs that the temp they point to has been copied, }
  831. { so that if the refs get copied as well, they can hook themselves }
  832. { to the copy of the temp }
  833. tempinfo^.hookoncopy := n.tempinfo;
  834. excludetempflag(ti_nextref_set_hookoncopy_nil);
  835. if assigned(tempinfo^.withnode) then
  836. n.tempinfo^.withnode := tempinfo^.withnode.getcopy
  837. else
  838. n.tempinfo^.withnode := nil;
  839. if assigned(tempinfo^.tempinitcode) then
  840. n.tempinfo^.tempinitcode := tempinfo^.tempinitcode.getcopy
  841. else
  842. n.tempinfo^.tempinitcode := nil;
  843. result := n;
  844. end;
  845. constructor ttempcreatenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  846. begin
  847. inherited ppuload(t,ppufile);
  848. size:=ppufile.getlongint;
  849. new(tempinfo);
  850. fillchar(tempinfo^,sizeof(tempinfo^),0);
  851. ppufile.getsmallset(tempinfo^.flags);
  852. ppufile.getderef(tempinfo^.typedefderef);
  853. tempinfo^.temptype := ttemptype(ppufile.getbyte);
  854. tempinfo^.owner:=self;
  855. tempinfo^.withnode:=ppuloadnode(ppufile);
  856. ftemplvalue:=ppuloadnode(ppufile);
  857. end;
  858. procedure ttempcreatenode.ppuwrite(ppufile:tcompilerppufile);
  859. begin
  860. inherited ppuwrite(ppufile);
  861. ppufile.putlongint(size);
  862. ppufile.putsmallset(tempinfo^.flags);
  863. ppufile.putderef(tempinfo^.typedefderef);
  864. ppufile.putbyte(byte(tempinfo^.temptype));
  865. ppuwritenode(ppufile,tempinfo^.withnode);
  866. ppuwritenode(ppufile,ftemplvalue);
  867. end;
  868. procedure ttempcreatenode.buildderefimpl;
  869. begin
  870. inherited buildderefimpl;
  871. tempinfo^.typedefderef.build(tempinfo^.typedef);
  872. if assigned(tempinfo^.withnode) then
  873. tempinfo^.withnode.buildderefimpl;
  874. if assigned(ftemplvalue) then
  875. ftemplvalue.buildderefimpl;
  876. end;
  877. procedure ttempcreatenode.derefimpl;
  878. begin
  879. inherited derefimpl;
  880. tempinfo^.typedef:=tdef(tempinfo^.typedefderef.resolve);
  881. if assigned(tempinfo^.withnode) then
  882. tempinfo^.withnode.derefimpl;
  883. if assigned(ftemplvalue) then
  884. begin
  885. ftemplvalue.derefimpl;
  886. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  887. end;
  888. end;
  889. function ttempcreatenode.pass_1 : tnode;
  890. begin
  891. result := nil;
  892. expectloc:=LOC_VOID;
  893. { temps which are immutable do not need to be initialized/finalized }
  894. if (tempinfo^.typedef.needs_inittable) and not(ti_const in tempflags) then
  895. include(current_procinfo.flags,pi_needs_implicit_finally);
  896. if (cs_create_pic in current_settings.moduleswitches) and
  897. (tf_pic_uses_got in target_info.flags) and
  898. is_rtti_managed_type(tempinfo^.typedef) then
  899. include(current_procinfo.flags,pi_needs_got);
  900. if assigned(tempinfo^.withnode) then
  901. firstpass(tempinfo^.withnode);
  902. if assigned(tempinfo^.tempinitcode) then
  903. firstpass(tempinfo^.tempinitcode);
  904. inc(current_procinfo.estimatedtempsize,size);;
  905. end;
  906. function ttempcreatenode.pass_typecheck: tnode;
  907. begin
  908. result := nil;
  909. { a tempcreatenode doesn't have a resultdef, only temprefnodes do }
  910. resultdef := voidtype;
  911. if assigned(tempinfo^.withnode) then
  912. typecheckpass(tempinfo^.withnode);
  913. if assigned(tempinfo^.tempinitcode) then
  914. typecheckpass(tempinfo^.tempinitcode);
  915. end;
  916. function ttempcreatenode.docompare(p: tnode): boolean;
  917. begin
  918. result :=
  919. inherited docompare(p) and
  920. (ttempcreatenode(p).size = size) and
  921. (ttempcreatenode(p).tempflags*tempinfostoreflags=tempflags*tempinfostoreflags) and
  922. equal_defs(ttempcreatenode(p).tempinfo^.typedef,tempinfo^.typedef) and
  923. (ttempcreatenode(p).tempinfo^.withnode.isequal(tempinfo^.withnode)) and
  924. (ttempcreatenode(p).tempinfo^.tempinitcode.isequal(tempinfo^.tempinitcode));
  925. end;
  926. procedure ttempcreatenode.printnodedata(var t:text);
  927. begin
  928. inherited printnodedata(t);
  929. writeln(t,printnodeindention,'size = ',size,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  930. tempinfo^.typedef.GetTypeName,'", tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  931. writeln(t,printnodeindention,'tempinit =');
  932. printnode(t,tempinfo^.tempinitcode);
  933. end;
  934. {*****************************************************************************
  935. TEMPREFNODE
  936. *****************************************************************************}
  937. constructor ttemprefnode.create(const temp: ttempcreatenode);
  938. begin
  939. inherited create(temprefn);
  940. tempinfo := temp.tempinfo;
  941. end;
  942. function ttemprefnode.dogetcopy: tnode;
  943. var
  944. n: ttemprefnode;
  945. begin
  946. n := ttemprefnode(inherited dogetcopy);
  947. if assigned(tempinfo^.hookoncopy) then
  948. { if the temp has been copied, assume it becomes a new }
  949. { temp which has to be hooked by the copied reference }
  950. begin
  951. { hook the ref to the copied temp }
  952. n.tempinfo := tempinfo^.hookoncopy;
  953. { if we passed a ttempdeletenode that changed the temp }
  954. { from a persistent one into a normal one, we must be }
  955. { the last reference (since our parent should free the }
  956. { temp (JM) }
  957. if (ti_nextref_set_hookoncopy_nil in tempflags) then
  958. tempinfo^.hookoncopy := nil;
  959. end
  960. else
  961. { if the temp we refer to hasn't been copied, assume }
  962. { we're just a new reference to that temp }
  963. begin
  964. n.tempinfo := tempinfo;
  965. end;
  966. if not assigned(n.tempinfo) then
  967. internalerror(2005071901);
  968. result := n;
  969. end;
  970. constructor ttemprefnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  971. begin
  972. inherited ppuload(t,ppufile);
  973. tempidx:=ppufile.getlongint;
  974. end;
  975. procedure ttemprefnode.ppuwrite(ppufile:tcompilerppufile);
  976. begin
  977. inherited ppuwrite(ppufile);
  978. ppufile.putlongint(tempinfo^.owner.ppuidx);
  979. end;
  980. procedure ttemprefnode.resolveppuidx;
  981. var
  982. temp : ttempcreatenode;
  983. begin
  984. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  985. if temp.nodetype<>tempcreaten then
  986. internalerror(200311075);
  987. tempinfo:=temp.tempinfo;
  988. end;
  989. function ttemprefnode.pass_1 : tnode;
  990. begin
  991. expectloc := LOC_REFERENCE;
  992. if not tempinfo^.typedef.needs_inittable and
  993. (ti_may_be_in_reg in tempflags) then
  994. begin
  995. if tempinfo^.typedef.typ=floatdef then
  996. begin
  997. if not use_vectorfpu(tempinfo^.typedef) then
  998. if (tempinfo^.temptype = tt_persistent) then
  999. expectloc := LOC_CFPUREGISTER
  1000. else
  1001. expectloc := LOC_FPUREGISTER
  1002. else
  1003. if (tempinfo^.temptype = tt_persistent) then
  1004. expectloc := LOC_CMMREGISTER
  1005. else
  1006. expectloc := LOC_MMREGISTER
  1007. end
  1008. else
  1009. begin
  1010. if (tempinfo^.temptype = tt_persistent) then
  1011. expectloc := LOC_CREGISTER
  1012. else
  1013. expectloc := LOC_REGISTER;
  1014. end;
  1015. end;
  1016. result := nil;
  1017. end;
  1018. function ttemprefnode.pass_typecheck: tnode;
  1019. begin
  1020. { check if the temp is already resultdef passed }
  1021. if not assigned(tempinfo^.typedef) then
  1022. internalerror(200108233);
  1023. result := nil;
  1024. resultdef := tempinfo^.typedef;
  1025. end;
  1026. function ttemprefnode.docompare(p: tnode): boolean;
  1027. begin
  1028. result :=
  1029. inherited docompare(p) and
  1030. (ttemprefnode(p).tempinfo = tempinfo);
  1031. end;
  1032. procedure ttemprefnode.mark_write;
  1033. begin
  1034. include(flags,nf_write);
  1035. end;
  1036. procedure ttemprefnode.printnodedata(var t:text);
  1037. var
  1038. f : ttempinfoflag;
  1039. notfirst : Boolean;
  1040. begin
  1041. inherited printnodedata(t);
  1042. write(t,printnodeindention,'temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1043. tempinfo^.typedef.GetTypeName,'", (tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2),' flags = [');
  1044. notfirst:=false;
  1045. for f in tempinfo^.flags do
  1046. begin
  1047. if notfirst then
  1048. write(t,',');
  1049. write(t,f);
  1050. notfirst:=true;
  1051. end;
  1052. writeln(t,'])');
  1053. end;
  1054. {*****************************************************************************
  1055. TEMPDELETENODE
  1056. *****************************************************************************}
  1057. constructor ttempdeletenode.create(const temp: ttempcreatenode);
  1058. begin
  1059. inherited create(tempdeleten);
  1060. tempinfo := temp.tempinfo;
  1061. release_to_normal := false;
  1062. end;
  1063. constructor ttempdeletenode.create_normal_temp(const temp: ttempcreatenode);
  1064. begin
  1065. inherited create(tempdeleten);
  1066. tempinfo := temp.tempinfo;
  1067. release_to_normal := true;
  1068. if tempinfo^.temptype <> tt_persistent then
  1069. internalerror(200204211);
  1070. end;
  1071. function ttempdeletenode.dogetcopy: tnode;
  1072. var
  1073. n: ttempdeletenode;
  1074. begin
  1075. n:=ttempdeletenode(inherited dogetcopy);
  1076. n.release_to_normal:=release_to_normal;
  1077. if assigned(tempinfo^.hookoncopy) then
  1078. { if the temp has been copied, assume it becomes a new }
  1079. { temp which has to be hooked by the copied deletenode }
  1080. begin
  1081. { hook the tempdeletenode to the copied temp }
  1082. n.tempinfo:=tempinfo^.hookoncopy;
  1083. { the temp shall not be used, reset hookoncopy }
  1084. { Only if release_to_normal is false, otherwise }
  1085. { the temp can still be referenced once more (JM) }
  1086. if (not release_to_normal) then
  1087. tempinfo^.hookoncopy:=nil
  1088. else
  1089. includetempflag(ti_nextref_set_hookoncopy_nil);
  1090. end
  1091. else
  1092. { if the temp we refer to hasn't been copied, we have a }
  1093. { problem since that means we now have two delete nodes }
  1094. { for one temp }
  1095. internalerror(200108234);
  1096. result:=n;
  1097. end;
  1098. constructor ttempdeletenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1099. begin
  1100. inherited ppuload(t,ppufile);
  1101. tempidx:=ppufile.getlongint;
  1102. release_to_normal:=(ppufile.getbyte<>0);
  1103. end;
  1104. procedure ttempdeletenode.ppuwrite(ppufile:tcompilerppufile);
  1105. begin
  1106. inherited ppuwrite(ppufile);
  1107. ppufile.putlongint(tempinfo^.owner.ppuidx);
  1108. ppufile.putbyte(byte(release_to_normal));
  1109. end;
  1110. procedure ttempdeletenode.resolveppuidx;
  1111. var
  1112. temp : ttempcreatenode;
  1113. begin
  1114. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  1115. if temp.nodetype<>tempcreaten then
  1116. internalerror(200311075);
  1117. tempinfo:=temp.tempinfo;
  1118. end;
  1119. function ttempdeletenode.pass_1 : tnode;
  1120. begin
  1121. expectloc:=LOC_VOID;
  1122. result := nil;
  1123. end;
  1124. function ttempdeletenode.pass_typecheck: tnode;
  1125. begin
  1126. result := nil;
  1127. resultdef := voidtype;
  1128. end;
  1129. function ttempdeletenode.docompare(p: tnode): boolean;
  1130. begin
  1131. result :=
  1132. inherited docompare(p) and
  1133. (ttemprefnode(p).tempinfo = tempinfo);
  1134. end;
  1135. destructor ttempdeletenode.destroy;
  1136. begin
  1137. tempinfo^.withnode.free;
  1138. tempinfo^.tempinitcode.free;
  1139. dispose(tempinfo);
  1140. inherited destroy;
  1141. end;
  1142. procedure ttempdeletenode.printnodedata(var t:text);
  1143. begin
  1144. inherited printnodedata(t);
  1145. writeln(t,printnodeindention,'release_to_normal: ',release_to_normal,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1146. tempinfo^.typedef.GetTypeName,'", temptype = ',tempinfo^.temptype,', tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  1147. end;
  1148. end.