nld.pas 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Type checking and register allocation for load/assignment 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 nld;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,
  22. {$ifdef state_tracking}
  23. nstate,
  24. {$endif}
  25. symconst,symbase,symtype,symsym,symdef;
  26. type
  27. Trttidatatype = (rdt_normal,rdt_ord2str,rdt_str2ord);
  28. tloadnodeflags = (
  29. loadnf_is_self,
  30. loadnf_load_self_pointer,
  31. loadnf_inherited,
  32. { the loadnode is generated internally and a varspez=vs_const should be ignore,
  33. this requires that the parameter is actually passed by value
  34. Be really carefull when using this flag! }
  35. loadnf_isinternal_ignoreconst,
  36. loadnf_only_uninitialized_hint
  37. );
  38. tloadnode = class(tunarynode)
  39. protected
  40. fprocdef : tprocdef;
  41. fprocdefderef : tderef;
  42. function handle_threadvar_access: tnode; virtual;
  43. public
  44. loadnodeflags : set of tloadnodeflags;
  45. symtableentry : tsym;
  46. symtableentryderef : tderef;
  47. symtable : TSymtable;
  48. constructor create(v : tsym;st : TSymtable);virtual;
  49. constructor create_procvar(v : tsym;d:tprocdef;st : TSymtable);virtual;
  50. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  51. procedure ppuwrite(ppufile:tcompilerppufile);override;
  52. procedure buildderefimpl;override;
  53. procedure derefimpl;override;
  54. procedure set_mp(p:tnode);
  55. function is_addr_param_load:boolean;virtual;
  56. function dogetcopy : tnode;override;
  57. function pass_1 : tnode;override;
  58. function pass_typecheck:tnode;override;
  59. procedure mark_write;override;
  60. function docompare(p: tnode): boolean; override;
  61. procedure printnodedata(var t:text);override;
  62. procedure setprocdef(p : tprocdef);
  63. property procdef: tprocdef read fprocdef write setprocdef;
  64. end;
  65. tloadnodeclass = class of tloadnode;
  66. { different assignment types }
  67. tassigntype = (at_normal,at_plus,at_minus,at_star,at_slash);
  68. tassignmentnode = class(tbinarynode)
  69. protected
  70. function direct_shortstring_assignment: boolean; virtual;
  71. public
  72. assigntype : tassigntype;
  73. constructor create(l,r : tnode);virtual;
  74. { no checks for validity of assignment }
  75. constructor create_internal(l,r : tnode);virtual;
  76. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  77. procedure ppuwrite(ppufile:tcompilerppufile);override;
  78. function dogetcopy : tnode;override;
  79. function pass_1 : tnode;override;
  80. function pass_typecheck:tnode;override;
  81. function simplify(forinline : boolean) : tnode;override;
  82. {$ifdef state_tracking}
  83. function track_state_pass(exec_known:boolean):boolean;override;
  84. {$endif state_tracking}
  85. function docompare(p: tnode): boolean; override;
  86. end;
  87. tassignmentnodeclass = class of tassignmentnode;
  88. tarrayconstructorrangenode = class(tbinarynode)
  89. constructor create(l,r : tnode);virtual;
  90. function pass_1 : tnode;override;
  91. function pass_typecheck:tnode;override;
  92. end;
  93. tarrayconstructorrangenodeclass = class of tarrayconstructorrangenode;
  94. tarrayconstructornode = class(tbinarynode)
  95. protected
  96. procedure wrapmanagedvarrec(var n: tnode);virtual;abstract;
  97. public
  98. constructor create(l,r : tnode);virtual;
  99. function dogetcopy : tnode;override;
  100. function pass_1 : tnode;override;
  101. function pass_typecheck:tnode;override;
  102. function docompare(p: tnode): boolean; override;
  103. procedure force_type(def:tdef);
  104. procedure insert_typeconvs;
  105. end;
  106. tarrayconstructornodeclass = class of tarrayconstructornode;
  107. ttypenode = class(tnode)
  108. allowed : boolean;
  109. helperallowed : boolean;
  110. typedef : tdef;
  111. typedefderef : tderef;
  112. typesym : tsym;
  113. typesymderef : tderef;
  114. constructor create(def:tdef);virtual;
  115. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  116. procedure ppuwrite(ppufile:tcompilerppufile);override;
  117. procedure buildderefimpl;override;
  118. procedure derefimpl;override;
  119. function pass_1 : tnode;override;
  120. function pass_typecheck:tnode;override;
  121. function dogetcopy : tnode;override;
  122. function docompare(p: tnode): boolean; override;
  123. end;
  124. ttypenodeclass = class of ttypenode;
  125. trttinode = class(tnode)
  126. l1,l2 : longint;
  127. rttitype : trttitype;
  128. rttidef : tstoreddef;
  129. rttidefderef : tderef;
  130. rttidatatype : Trttidatatype;
  131. constructor create(def:tstoreddef;rt:trttitype;dt:Trttidatatype);virtual;
  132. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  133. procedure ppuwrite(ppufile:tcompilerppufile);override;
  134. procedure buildderefimpl;override;
  135. procedure derefimpl;override;
  136. function dogetcopy : tnode;override;
  137. function pass_1 : tnode;override;
  138. function pass_typecheck:tnode;override;
  139. function docompare(p: tnode): boolean; override;
  140. end;
  141. trttinodeclass = class of trttinode;
  142. var
  143. cloadnode : tloadnodeclass = tloadnode;
  144. cassignmentnode : tassignmentnodeclass = tassignmentnode;
  145. carrayconstructorrangenode : tarrayconstructorrangenodeclass = tarrayconstructorrangenode;
  146. carrayconstructornode : tarrayconstructornodeclass = tarrayconstructornode;
  147. ctypenode : ttypenodeclass = ttypenode;
  148. crttinode : trttinodeclass = trttinode;
  149. { Current assignment node }
  150. aktassignmentnode : tassignmentnode;
  151. implementation
  152. uses
  153. cutils,verbose,globtype,globals,systems,constexp,
  154. symnot,symtable,
  155. defutil,defcmp,
  156. htypechk,pass_1,procinfo,paramgr,
  157. cpuinfo,
  158. ncon,ninl,ncnv,nmem,ncal,nutils,nbas,
  159. cgobj,cgbase
  160. ;
  161. {*****************************************************************************
  162. TLOADNODE
  163. *****************************************************************************}
  164. function tloadnode.handle_threadvar_access: tnode;
  165. begin
  166. { nothing special by default }
  167. result:=nil;
  168. end;
  169. constructor tloadnode.create(v : tsym;st : TSymtable);
  170. begin
  171. inherited create(loadn,nil);
  172. if not assigned(v) then
  173. internalerror(200108121);
  174. symtableentry:=v;
  175. symtable:=st;
  176. fprocdef:=nil;
  177. end;
  178. constructor tloadnode.create_procvar(v : tsym;d:tprocdef;st : TSymtable);
  179. begin
  180. inherited create(loadn,nil);
  181. if not assigned(v) then
  182. internalerror(200108122);
  183. symtableentry:=v;
  184. symtable:=st;
  185. fprocdef:=d;
  186. end;
  187. constructor tloadnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  188. begin
  189. inherited ppuload(t,ppufile);
  190. ppufile.getderef(symtableentryderef);
  191. symtable:=nil;
  192. ppufile.getderef(fprocdefderef);
  193. ppufile.getsmallset(loadnodeflags);
  194. end;
  195. procedure tloadnode.ppuwrite(ppufile:tcompilerppufile);
  196. begin
  197. inherited ppuwrite(ppufile);
  198. ppufile.putderef(symtableentryderef);
  199. ppufile.putderef(fprocdefderef);
  200. ppufile.putsmallset(loadnodeflags);
  201. end;
  202. procedure tloadnode.buildderefimpl;
  203. begin
  204. inherited buildderefimpl;
  205. symtableentryderef.build(symtableentry);
  206. fprocdefderef.build(fprocdef);
  207. end;
  208. procedure tloadnode.derefimpl;
  209. begin
  210. inherited derefimpl;
  211. symtableentry:=tsym(symtableentryderef.resolve);
  212. symtable:=symtableentry.owner;
  213. fprocdef:=tprocdef(fprocdefderef.resolve);
  214. end;
  215. procedure tloadnode.set_mp(p:tnode);
  216. begin
  217. { typen nodes should not be set }
  218. if p.nodetype=typen then
  219. internalerror(200301042);
  220. left:=p;
  221. end;
  222. function tloadnode.dogetcopy : tnode;
  223. var
  224. n : tloadnode;
  225. begin
  226. n:=tloadnode(inherited dogetcopy);
  227. n.symtable:=symtable;
  228. n.symtableentry:=symtableentry;
  229. n.fprocdef:=fprocdef;
  230. result:=n;
  231. end;
  232. function tloadnode.is_addr_param_load:boolean;
  233. begin
  234. result:=(symtable.symtabletype=parasymtable) and
  235. (symtableentry.typ=paravarsym) and
  236. not(vo_has_local_copy in tparavarsym(symtableentry).varoptions) and
  237. not(loadnf_load_self_pointer in loadnodeflags) and
  238. paramanager.push_addr_param(tparavarsym(symtableentry).varspez,tparavarsym(symtableentry).vardef,tprocdef(symtable.defowner).proccalloption);
  239. end;
  240. function tloadnode.pass_typecheck:tnode;
  241. begin
  242. result:=nil;
  243. case symtableentry.typ of
  244. absolutevarsym :
  245. resultdef:=tabsolutevarsym(symtableentry).vardef;
  246. constsym:
  247. begin
  248. if tconstsym(symtableentry).consttyp=constresourcestring then
  249. resultdef:=getansistringdef
  250. else
  251. internalerror(22799);
  252. end;
  253. staticvarsym :
  254. begin
  255. tabstractvarsym(symtableentry).IncRefCountBy(1);
  256. { static variables referenced in procedures or from finalization,
  257. variable needs to be in memory.
  258. It is too hard and the benefit is too small to detect whether a
  259. variable is only used in the finalization to add support for it (PFV) }
  260. if assigned(current_procinfo) and
  261. (symtable.symtabletype=staticsymtable) and
  262. (
  263. (symtable.symtablelevel<>current_procinfo.procdef.localst.symtablelevel) or
  264. (current_procinfo.procdef.proctypeoption=potype_unitfinalize)
  265. ) then
  266. make_not_regable(self,[ra_addr_taken]);
  267. resultdef:=tabstractvarsym(symtableentry).vardef;
  268. if vo_is_thread_var in tstaticvarsym(symtableentry).varoptions then
  269. result:=handle_threadvar_access;
  270. end;
  271. paravarsym,
  272. localvarsym :
  273. begin
  274. tabstractvarsym(symtableentry).IncRefCountBy(1);
  275. { Nested variable? The we need to load the framepointer of
  276. the parent procedure }
  277. if assigned(current_procinfo) and
  278. (symtable.symtabletype in [localsymtable,parasymtable]) and
  279. (symtable.symtablelevel<>current_procinfo.procdef.parast.symtablelevel) then
  280. begin
  281. if assigned(left) then
  282. internalerror(200309289);
  283. left:=cloadparentfpnode.create(tprocdef(symtable.defowner));
  284. { we can't inline the referenced parent procedure }
  285. exclude(tprocdef(symtable.defowner).procoptions,po_inline);
  286. { reference in nested procedures, variable needs to be in memory }
  287. { and behaves as if its address escapes its parent block }
  288. make_not_regable(self,[ra_addr_taken]);
  289. end;
  290. { fix self type which is declared as voidpointer in the
  291. definition }
  292. if vo_is_self in tabstractvarsym(symtableentry).varoptions then
  293. begin
  294. resultdef:=tprocdef(symtableentry.owner.defowner).struct;
  295. if is_objectpascal_helper(resultdef) then
  296. resultdef:=tobjectdef(resultdef).extendeddef;
  297. if (po_classmethod in tprocdef(symtableentry.owner.defowner).procoptions) or
  298. (po_staticmethod in tprocdef(symtableentry.owner.defowner).procoptions) then
  299. resultdef:=tclassrefdef.create(resultdef)
  300. else if (is_object(resultdef) or is_record(resultdef)) and
  301. (loadnf_load_self_pointer in loadnodeflags) then
  302. resultdef:=getpointerdef(resultdef);
  303. end
  304. else if vo_is_vmt in tabstractvarsym(symtableentry).varoptions then
  305. begin
  306. resultdef:=tprocdef(symtableentry.owner.defowner).struct;
  307. resultdef:=tclassrefdef.create(resultdef);
  308. end
  309. else
  310. resultdef:=tabstractvarsym(symtableentry).vardef;
  311. end;
  312. procsym :
  313. begin
  314. { Return the first procdef. In case of overloaded
  315. procdefs the matching procdef will be choosen
  316. when the expected procvardef is known, see get_information
  317. in htypechk.pas (PFV) }
  318. if not assigned(fprocdef) then
  319. fprocdef:=tprocdef(tprocsym(symtableentry).ProcdefList[0])
  320. else if po_kylixlocal in fprocdef.procoptions then
  321. CGMessage(type_e_cant_take_address_of_local_subroutine);
  322. { the result is a fprocdef, addrn and proc_to_procvar
  323. typeconvn need this as resultdef so they know
  324. that the address needs to be returned }
  325. resultdef:=fprocdef;
  326. { process methodpointer/framepointer }
  327. if assigned(left) then
  328. typecheckpass(left);
  329. end;
  330. labelsym:
  331. begin
  332. tlabelsym(symtableentry).used:=true;
  333. resultdef:=voidtype;
  334. end;
  335. else
  336. internalerror(200104141);
  337. end;
  338. end;
  339. procedure Tloadnode.mark_write;
  340. begin
  341. include(flags,nf_write);
  342. end;
  343. function tloadnode.pass_1 : tnode;
  344. begin
  345. result:=nil;
  346. expectloc:=LOC_REFERENCE;
  347. if (cs_create_pic in current_settings.moduleswitches) and
  348. not(symtableentry.typ in [paravarsym,localvarsym]) then
  349. include(current_procinfo.flags,pi_needs_got);
  350. case symtableentry.typ of
  351. absolutevarsym :
  352. ;
  353. constsym:
  354. begin
  355. if tconstsym(symtableentry).consttyp=constresourcestring then
  356. expectloc:=LOC_CREFERENCE;
  357. end;
  358. staticvarsym,
  359. localvarsym,
  360. paravarsym :
  361. begin
  362. if assigned(left) then
  363. firstpass(left);
  364. if not is_addr_param_load and
  365. tabstractvarsym(symtableentry).is_regvar(is_addr_param_load) then
  366. expectloc:=tvarregable2tcgloc[tabstractvarsym(symtableentry).varregable]
  367. else
  368. if (tabstractvarsym(symtableentry).varspez=vs_const) then
  369. expectloc:=LOC_CREFERENCE;
  370. if (target_info.system=system_powerpc_darwin) and
  371. ([vo_is_dll_var,vo_is_external] * tabstractvarsym(symtableentry).varoptions <> []) then
  372. include(current_procinfo.flags,pi_needs_got);
  373. { call to get address of threadvar }
  374. if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then
  375. include(current_procinfo.flags,pi_do_call);
  376. if nf_write in flags then
  377. Tabstractvarsym(symtableentry).trigger_notifications(vn_onwrite)
  378. else
  379. Tabstractvarsym(symtableentry).trigger_notifications(vn_onread);
  380. end;
  381. procsym :
  382. begin
  383. { initialise left for nested procs if necessary }
  384. if (m_nested_procvars in current_settings.modeswitches) then
  385. setprocdef(fprocdef);
  386. { method pointer or nested proc ? }
  387. if assigned(left) then
  388. begin
  389. expectloc:=LOC_CREFERENCE;
  390. firstpass(left);
  391. end;
  392. end;
  393. labelsym :
  394. begin
  395. if not assigned(tlabelsym(symtableentry).asmblocklabel) and
  396. not assigned(tlabelsym(symtableentry).code) then
  397. Message(parser_e_label_outside_proc);
  398. end
  399. else
  400. internalerror(200104143);
  401. end;
  402. end;
  403. function tloadnode.docompare(p: tnode): boolean;
  404. begin
  405. docompare :=
  406. inherited docompare(p) and
  407. (symtableentry = tloadnode(p).symtableentry) and
  408. (fprocdef = tloadnode(p).fprocdef) and
  409. (symtable = tloadnode(p).symtable);
  410. end;
  411. procedure tloadnode.printnodedata(var t:text);
  412. begin
  413. inherited printnodedata(t);
  414. write(t,printnodeindention,'symbol = ',symtableentry.name);
  415. if symtableentry.typ=procsym then
  416. write(t,printnodeindention,'procdef = ',fprocdef.mangledname);
  417. writeln(t,'');
  418. end;
  419. procedure tloadnode.setprocdef(p : tprocdef);
  420. begin
  421. fprocdef:=p;
  422. resultdef:=p;
  423. { nested procedure? }
  424. if assigned(p) and
  425. is_nested_pd(p) then
  426. begin
  427. if not(m_nested_procvars in current_settings.modeswitches) then
  428. CGMessage(type_e_cant_take_address_of_local_subroutine)
  429. else
  430. begin
  431. { parent frame pointer pointer as "self" }
  432. left.free;
  433. left:=cloadparentfpnode.create(tprocdef(p.owner.defowner));
  434. end;
  435. end
  436. { we should never go from nested to non-nested }
  437. else if assigned(left) and
  438. (left.nodetype=loadparentfpn) then
  439. internalerror(2010072201);
  440. end;
  441. {*****************************************************************************
  442. TASSIGNMENTNODE
  443. *****************************************************************************}
  444. function tassignmentnode.direct_shortstring_assignment: boolean;
  445. begin
  446. result:=
  447. is_char(right.resultdef) or
  448. (right.resultdef.typ=stringdef);
  449. end;
  450. constructor tassignmentnode.create(l,r : tnode);
  451. begin
  452. inherited create(assignn,l,r);
  453. l.mark_write;
  454. assigntype:=at_normal;
  455. if r.nodetype = typeconvn then
  456. ttypeconvnode(r).warn_pointer_to_signed:=false;
  457. end;
  458. constructor tassignmentnode.create_internal(l, r: tnode);
  459. begin
  460. create(l,r);
  461. include(flags,nf_internal);
  462. end;
  463. constructor tassignmentnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  464. begin
  465. inherited ppuload(t,ppufile);
  466. assigntype:=tassigntype(ppufile.getbyte);
  467. end;
  468. procedure tassignmentnode.ppuwrite(ppufile:tcompilerppufile);
  469. begin
  470. inherited ppuwrite(ppufile);
  471. ppufile.putbyte(byte(assigntype));
  472. end;
  473. function tassignmentnode.dogetcopy : tnode;
  474. var
  475. n : tassignmentnode;
  476. begin
  477. n:=tassignmentnode(inherited dogetcopy);
  478. n.assigntype:=assigntype;
  479. result:=n;
  480. end;
  481. function tassignmentnode.simplify(forinline : boolean) : tnode;
  482. begin
  483. result:=nil;
  484. { assignment nodes can perform several floating point }
  485. { type conversions directly, so no typeconversions }
  486. { are inserted in those cases. When inlining, a }
  487. { variable may be replaced by a constant which can be }
  488. { converted at compile time, so check for this case }
  489. if is_real(left.resultdef) and
  490. is_real(right.resultdef) and
  491. is_constrealnode(right) and
  492. not equal_defs(right.resultdef,left.resultdef) then
  493. inserttypeconv(right,left.resultdef);
  494. end;
  495. function tassignmentnode.pass_typecheck:tnode;
  496. var
  497. hp : tnode;
  498. useshelper : boolean;
  499. oldassignmentnode : tassignmentnode;
  500. begin
  501. result:=nil;
  502. resultdef:=voidtype;
  503. { must be made unique }
  504. set_unique(left);
  505. typecheckpass(left);
  506. { PI. This is needed to return correct resultdef of add nodes for ansistrings
  507. rawbytestring return needs to be replaced by left.resultdef }
  508. oldassignmentnode:=aktassignmentnode;
  509. aktassignmentnode:=self;
  510. typecheckpass(right);
  511. aktassignmentnode:=oldassignmentnode;
  512. set_varstate(right,vs_read,[vsf_must_be_valid]);
  513. set_varstate(left,vs_written,[]);
  514. if codegenerror then
  515. exit;
  516. { tp procvar support, when we don't expect a procvar
  517. then we need to call the procvar }
  518. if (left.resultdef.typ<>procvardef) then
  519. maybe_call_procvar(right,true);
  520. { assignments to formaldefs and open arrays aren't allowed }
  521. if is_open_array(left.resultdef) then
  522. CGMessage(type_e_assignment_not_allowed)
  523. else if (left.resultdef.typ=formaldef) then
  524. if not(target_info.system in systems_managed_vm) then
  525. CGMessage(type_e_assignment_not_allowed)
  526. else
  527. begin
  528. { on managed platforms, assigning to formaldefs is allowed (but
  529. typecasting them on the left hand side isn't), but primitive
  530. values need to be boxed first }
  531. if (right.resultdef.typ in [orddef,floatdef]) then
  532. begin
  533. right:=cinlinenode.create(in_box_x,false,ccallparanode.create(right,nil));
  534. typecheckpass(right);
  535. end;
  536. end;
  537. { test if node can be assigned, properties are allowed }
  538. if not(nf_internal in flags) then
  539. valid_for_assignment(left,true);
  540. { assigning nil to a dynamic array clears the array }
  541. if is_dynamic_array(left.resultdef) and
  542. (right.nodetype=niln) then
  543. begin
  544. { remove property flag to avoid errors, see comments for }
  545. { tf_winlikewidestring assignments below }
  546. exclude(left.flags,nf_isproperty);
  547. { generate a setlength node so it can be intercepted by
  548. target-specific code }
  549. result:=cinlinenode.create(in_setlength_x,false,
  550. ccallparanode.create(genintconstnode(0),
  551. ccallparanode.create(left,nil)));
  552. left:=nil;
  553. exit;
  554. end;
  555. { shortstring helpers can do the conversion directly,
  556. so treat them separatly }
  557. if (is_shortstring(left.resultdef)) then
  558. begin
  559. { insert typeconv, except for chars that are handled in
  560. secondpass and except for ansi/wide string that can
  561. be converted immediatly }
  562. if not direct_shortstring_assignment then
  563. inserttypeconv(right,left.resultdef);
  564. if right.resultdef.typ=stringdef then
  565. begin
  566. useshelper:=true;
  567. { convert constant strings to shortstrings. But
  568. skip empty constant strings, that will be handled
  569. in secondpass }
  570. if (right.nodetype=stringconstn) then
  571. begin
  572. { verify if range fits within shortstring }
  573. { just emit a warning, delphi gives an }
  574. { error, only if the type definition of }
  575. { of the string is less < 255 characters }
  576. if not is_open_string(left.resultdef) and
  577. (tstringconstnode(right).len > tstringdef(left.resultdef).len) then
  578. cgmessage(type_w_string_too_long);
  579. inserttypeconv(right,left.resultdef);
  580. if (right.nodetype=stringconstn) and
  581. (tstringconstnode(right).len=0) then
  582. useshelper:=false;
  583. end
  584. else if (tstringdef(right.resultdef).stringtype in [st_unicodestring,st_widestring]) then
  585. Message2(type_w_implicit_string_cast_loss,right.resultdef.typename,left.resultdef.typename);
  586. { rest is done in pass 1 (JM) }
  587. if useshelper then
  588. exit;
  589. end
  590. end
  591. { floating point assignments can also perform the conversion directly }
  592. else if is_real(left.resultdef) and is_real(right.resultdef) and
  593. not is_constrealnode(right)
  594. {$ifdef cpufpemu}
  595. { the emulator can't do this obviously }
  596. and not(current_settings.fputype in [fpu_libgcc,fpu_soft])
  597. {$endif cpufpemu}
  598. {$ifdef x86}
  599. { the assignment node code can't convert a double in an }
  600. { sse register to an extended value in memory more }
  601. { efficiently than a type conversion node, so don't }
  602. { bother implementing support for that }
  603. and (use_vectorfpu(left.resultdef) or not(use_vectorfpu(right.resultdef)))
  604. {$endif}
  605. {$ifdef arm}
  606. { the assignment node code can't convert a single in
  607. an interger register to a double in an mmregister or
  608. vice versa }
  609. and (use_vectorfpu(left.resultdef) and
  610. use_vectorfpu(right.resultdef) and
  611. (tfloatdef(left.resultdef).floattype=tfloatdef(right.resultdef).floattype))
  612. {$endif}
  613. then
  614. begin
  615. check_ranges(fileinfo,right,left.resultdef);
  616. end
  617. else
  618. begin
  619. { check if the assignment may cause a range check error }
  620. check_ranges(fileinfo,right,left.resultdef);
  621. { beginners might be confused about an error message like
  622. Incompatible types: got "untyped" expected "LongInt"
  623. when trying to assign the result of a procedure, so give
  624. a better error message, see also #19122 }
  625. if (left.resultdef.typ<>procvardef) and
  626. (right.nodetype=calln) and is_void(right.resultdef) then
  627. CGMessage(type_e_procedures_return_no_value)
  628. else
  629. inserttypeconv(right,left.resultdef);
  630. end;
  631. { call helpers for interface }
  632. if is_interfacecom_or_dispinterface(left.resultdef) then
  633. begin
  634. { Normal interface assignments are handled by the generic refcount incr/decr }
  635. if not right.resultdef.is_related(left.resultdef) then
  636. begin
  637. { remove property flag to avoid errors, see comments for }
  638. { tf_winlikewidestring assignments below }
  639. exclude(left.flags,nf_isproperty);
  640. hp:=
  641. ccallparanode.create(
  642. cguidconstnode.create(tobjectdef(left.resultdef).iidguid^),
  643. ccallparanode.create(
  644. ctypeconvnode.create_internal(right,voidpointertype),
  645. ccallparanode.create(
  646. ctypeconvnode.create_internal(left,voidpointertype),
  647. nil)));
  648. result:=ccallnode.createintern('fpc_intf_assign_by_iid',hp);
  649. left:=nil;
  650. right:=nil;
  651. exit;
  652. end;
  653. end;
  654. { check if local proc/func is assigned to procvar }
  655. if right.resultdef.typ=procvardef then
  656. test_local_to_procvar(tprocvardef(right.resultdef),left.resultdef);
  657. end;
  658. function tassignmentnode.pass_1 : tnode;
  659. var
  660. hp: tnode;
  661. oldassignmentnode : tassignmentnode;
  662. hdef: tdef;
  663. hs: string;
  664. needrtti: boolean;
  665. begin
  666. result:=nil;
  667. expectloc:=LOC_VOID;
  668. firstpass(left);
  669. { Optimize the reuse of the destination of the assingment in left.
  670. Allow the use of the left inside the tree generated on the right.
  671. This is especially useful for string routines where the destination
  672. is pushed as a parameter. Using the final destination of left directly
  673. save a temp allocation and copy of data (PFV) }
  674. oldassignmentnode:=aktassignmentnode;
  675. aktassignmentnode:=self;
  676. firstpass(right);
  677. aktassignmentnode:=oldassignmentnode;
  678. if nf_assign_done_in_right in flags then
  679. begin
  680. result:=right;
  681. right:=nil;
  682. exit;
  683. end;
  684. if codegenerror then
  685. exit;
  686. { assignment to refcounted variable -> inc/decref }
  687. if is_managed_type(left.resultdef) then
  688. include(current_procinfo.flags,pi_do_call);
  689. needrtti:=false;
  690. if (is_shortstring(left.resultdef)) then
  691. begin
  692. if right.resultdef.typ=stringdef then
  693. begin
  694. if (right.nodetype<>stringconstn) or
  695. (tstringconstnode(right).len<>0) then
  696. begin
  697. { remove property flag to avoid errors, see comments for }
  698. { tf_winlikewidestring assignments below }
  699. exclude(left.flags, nf_isproperty);
  700. hp:=ccallparanode.create
  701. (right,
  702. ccallparanode.create(left,nil));
  703. result:=ccallnode.createintern('fpc_'+tstringdef(right.resultdef).stringtypname+'_to_shortstr',hp);
  704. firstpass(result);
  705. left:=nil;
  706. right:=nil;
  707. end;
  708. end;
  709. exit;
  710. end
  711. { call helpers for composite types containing automated types }
  712. else if is_managed_type(left.resultdef) and
  713. (left.resultdef.typ in [arraydef,objectdef,recorddef]) and
  714. not is_interfacecom_or_dispinterface(left.resultdef) and
  715. not is_dynamic_array(left.resultdef) and
  716. not(target_info.system in systems_garbage_collected_managed_types) then
  717. begin
  718. hp:=ccallparanode.create(caddrnode.create_internal(
  719. crttinode.create(tstoreddef(left.resultdef),initrtti,rdt_normal)),
  720. ccallparanode.create(ctypeconvnode.create_internal(
  721. caddrnode.create_internal(left),voidpointertype),
  722. ccallparanode.create(ctypeconvnode.create_internal(
  723. caddrnode.create_internal(right),voidpointertype),
  724. nil)));
  725. result:=ccallnode.createintern('fpc_copy_proc',hp);
  726. firstpass(result);
  727. left:=nil;
  728. right:=nil;
  729. exit;
  730. end
  731. { call helpers for variant, they can contain non ref. counted types like
  732. vararrays which must be really copied }
  733. else if (left.resultdef.typ=variantdef) and
  734. not(target_info.system in systems_garbage_collected_managed_types) then
  735. begin
  736. { remove property flag to avoid errors, see comments for }
  737. { tf_winlikewidestring assignments below }
  738. exclude(left.flags,nf_isproperty);
  739. hdef:=search_system_type('TVARDATA').typedef;
  740. hp:=ccallparanode.create(ctypeconvnode.create_internal(
  741. right,hdef),
  742. ccallparanode.create(ctypeconvnode.create_internal(
  743. left,hdef),
  744. nil));
  745. result:=ccallnode.createintern('fpc_variant_copy',hp);
  746. firstpass(result);
  747. left:=nil;
  748. right:=nil;
  749. exit;
  750. end
  751. else if not(target_info.system in systems_garbage_collected_managed_types) then
  752. begin
  753. { call helpers for pointer-sized managed types }
  754. if is_widestring(left.resultdef) then
  755. hs:='fpc_widestr_assign'
  756. else if is_ansistring(left.resultdef) then
  757. hs:='fpc_ansistr_assign'
  758. else if is_unicodestring(left.resultdef) then
  759. hs:='fpc_unicodestr_assign'
  760. else if is_interfacecom_or_dispinterface(left.resultdef) then
  761. hs:='fpc_intf_assign'
  762. else if is_dynamic_array(left.resultdef) then
  763. begin
  764. hs:='fpc_dynarray_assign';
  765. needrtti:=true;
  766. end
  767. else
  768. exit;
  769. end
  770. else
  771. exit;
  772. { The first argument of these procedures is a var parameter. Properties cannot }
  773. { be passed to var or out parameters, because in that case setters/getters are not }
  774. { used. Further, if we would allow it in case there are no getters or setters, you }
  775. { would need source changes in case these are introduced later on, thus defeating }
  776. { part of the transparency advantages of properties. In this particular case, }
  777. { however: }
  778. { a) if there is a setter, this code will not be used since then the assignment }
  779. { will be converted to a procedure call }
  780. { b) the getter is irrelevant, because fpc_widestr_assign must always decrease }
  781. { the refcount of the field to which we are writing }
  782. { c) source code changes are not required if a setter is added/removed, because }
  783. { this transformation is handled at compile time }
  784. { -> we can remove the nf_isproperty flag (if any) from left, so that in case it }
  785. { is a property which refers to a field without a setter call, we will not get }
  786. { an error about trying to pass a property as a var parameter }
  787. exclude(left.flags,nf_isproperty);
  788. hp:=ccallparanode.create(ctypeconvnode.create_internal(right,voidpointertype),
  789. ccallparanode.create(ctypeconvnode.create_internal(left,voidpointertype),
  790. nil));
  791. if needrtti then
  792. hp:=ccallparanode.create(
  793. caddrnode.create_internal(
  794. crttinode.create(tstoreddef(left.resultdef),initrtti,rdt_normal)),
  795. hp);
  796. result:=ccallnode.createintern(hs,hp);
  797. firstpass(result);
  798. left:=nil;
  799. right:=nil;
  800. end;
  801. function tassignmentnode.docompare(p: tnode): boolean;
  802. begin
  803. docompare :=
  804. inherited docompare(p) and
  805. (assigntype = tassignmentnode(p).assigntype);
  806. end;
  807. {$ifdef state_tracking}
  808. function Tassignmentnode.track_state_pass(exec_known:boolean):boolean;
  809. var se:Tstate_entry;
  810. begin
  811. track_state_pass:=false;
  812. if exec_known then
  813. begin
  814. track_state_pass:=right.track_state_pass(exec_known);
  815. {Force a new resultdef pass.}
  816. right.resultdef:=nil;
  817. do_typecheckpass(right);
  818. typecheckpass(right);
  819. aktstate.store_fact(left.getcopy,right.getcopy);
  820. end
  821. else
  822. aktstate.delete_fact(left);
  823. end;
  824. {$endif}
  825. {*****************************************************************************
  826. TARRAYCONSTRUCTORRANGENODE
  827. *****************************************************************************}
  828. constructor tarrayconstructorrangenode.create(l,r : tnode);
  829. begin
  830. inherited create(arrayconstructorrangen,l,r);
  831. end;
  832. function tarrayconstructorrangenode.pass_typecheck:tnode;
  833. begin
  834. result:=nil;
  835. typecheckpass(left);
  836. typecheckpass(right);
  837. set_varstate(left,vs_read,[vsf_must_be_valid]);
  838. set_varstate(right,vs_read,[vsf_must_be_valid]);
  839. if codegenerror then
  840. exit;
  841. resultdef:=left.resultdef;
  842. end;
  843. function tarrayconstructorrangenode.pass_1 : tnode;
  844. begin
  845. result:=nil;
  846. CGMessage(parser_e_illegal_expression);
  847. end;
  848. {****************************************************************************
  849. TARRAYCONSTRUCTORNODE
  850. *****************************************************************************}
  851. constructor tarrayconstructornode.create(l,r : tnode);
  852. begin
  853. inherited create(arrayconstructorn,l,r);
  854. end;
  855. function tarrayconstructornode.dogetcopy : tnode;
  856. var
  857. n : tarrayconstructornode;
  858. begin
  859. n:=tarrayconstructornode(inherited dogetcopy);
  860. result:=n;
  861. end;
  862. function tarrayconstructornode.pass_typecheck:tnode;
  863. var
  864. hdef : tdef;
  865. hp : tarrayconstructornode;
  866. len : longint;
  867. varia : boolean;
  868. eq : tequaltype;
  869. hnodetype : tnodetype;
  870. begin
  871. result:=nil;
  872. { are we allowing array constructor? Then convert it to a set.
  873. Do this only if we didn't convert the arrayconstructor yet. This
  874. is needed for the cases where the resultdef is forced for a second
  875. run }
  876. if not(allow_array_constructor) then
  877. begin
  878. hp:=tarrayconstructornode(getcopy);
  879. arrayconstructor_to_set(tnode(hp));
  880. result:=hp;
  881. exit;
  882. end;
  883. { only pass left tree, right tree contains next construct if any }
  884. hdef:=nil;
  885. hnodetype:=errorn;
  886. len:=0;
  887. varia:=false;
  888. if assigned(left) then
  889. begin
  890. hp:=self;
  891. while assigned(hp) do
  892. begin
  893. typecheckpass(hp.left);
  894. set_varstate(hp.left,vs_read,[vsf_must_be_valid]);
  895. if (hdef=nil) then
  896. begin
  897. hdef:=hp.left.resultdef;
  898. hnodetype:=hp.left.nodetype;
  899. end
  900. else
  901. begin
  902. { If we got a niln we don't know the type yet and need to take the
  903. type of the next array element.
  904. This is to handle things like [nil,tclass,tclass], see also tw8371 (PFV) }
  905. if hnodetype=niln then
  906. begin
  907. eq:=compare_defs(hp.left.resultdef,hdef,hnodetype);
  908. if eq>te_incompatible then
  909. begin
  910. hdef:=hp.left.resultdef;
  911. hnodetype:=hp.left.nodetype;
  912. end;
  913. end
  914. else
  915. eq:=compare_defs(hdef,hp.left.resultdef,hp.left.nodetype);
  916. if (not varia) and (eq<te_equal) then
  917. begin
  918. { If both are integers we need to take the type that can hold both
  919. defs }
  920. if is_integer(hdef) and is_integer(hp.left.resultdef) then
  921. begin
  922. if is_in_limit(hdef,hp.left.resultdef) then
  923. hdef:=hp.left.resultdef;
  924. end
  925. else
  926. if (nf_novariaallowed in flags) then
  927. varia:=true;
  928. end;
  929. end;
  930. inc(len);
  931. hp:=tarrayconstructornode(hp.right);
  932. end;
  933. end;
  934. { Set the type of empty or varia arrays to void. Also
  935. do this if the type is array of const/open array
  936. because those can't be used with setelementdef }
  937. if not assigned(hdef) or
  938. varia or
  939. is_array_of_const(hdef) or
  940. is_open_array(hdef) then
  941. hdef:=voidtype;
  942. resultdef:=tarraydef.create(0,len-1,s32inttype);
  943. tarraydef(resultdef).elementdef:=hdef;
  944. include(tarraydef(resultdef).arrayoptions,ado_IsConstructor);
  945. if varia then
  946. include(tarraydef(resultdef).arrayoptions,ado_IsVariant);
  947. end;
  948. procedure tarrayconstructornode.force_type(def:tdef);
  949. var
  950. hp : tarrayconstructornode;
  951. begin
  952. tarraydef(resultdef).elementdef:=def;
  953. include(tarraydef(resultdef).arrayoptions,ado_IsConstructor);
  954. exclude(tarraydef(resultdef).arrayoptions,ado_IsVariant);
  955. if assigned(left) then
  956. begin
  957. hp:=self;
  958. while assigned(hp) do
  959. begin
  960. inserttypeconv(hp.left,def);
  961. hp:=tarrayconstructornode(hp.right);
  962. end;
  963. end;
  964. end;
  965. procedure tarrayconstructornode.insert_typeconvs;
  966. var
  967. hp : tarrayconstructornode;
  968. dovariant : boolean;
  969. begin
  970. dovariant:=(nf_forcevaria in flags) or (ado_isvariant in tarraydef(resultdef).arrayoptions);
  971. { only pass left tree, right tree contains next construct if any }
  972. if assigned(left) then
  973. begin
  974. hp:=self;
  975. while assigned(hp) do
  976. begin
  977. typecheckpass(hp.left);
  978. { Insert typeconvs for array of const }
  979. if dovariant then
  980. { at this time C varargs are no longer an arrayconstructornode }
  981. insert_varargstypeconv(hp.left,false);
  982. hp:=tarrayconstructornode(hp.right);
  983. end;
  984. end;
  985. end;
  986. function tarrayconstructornode.pass_1 : tnode;
  987. var
  988. hp : tarrayconstructornode;
  989. do_variant,
  990. do_managed_variant:boolean;
  991. begin
  992. do_variant:=(nf_forcevaria in flags) or (ado_isvariant in tarraydef(resultdef).arrayoptions);
  993. do_managed_variant:=
  994. do_variant and
  995. (target_info.system in systems_managed_vm);
  996. result:=nil;
  997. { Insert required type convs, this must be
  998. done in pass 1, because the call must be
  999. typecheckpassed already }
  1000. if assigned(left) then
  1001. begin
  1002. insert_typeconvs;
  1003. { call firstpass for all nodes }
  1004. hp:=self;
  1005. while assigned(hp) do
  1006. begin
  1007. if hp.left<>nil then
  1008. begin
  1009. {This check is pessimistic; a call will happen depending
  1010. on the location in which the elements will be found in
  1011. pass 2.}
  1012. if not do_variant then
  1013. include(current_procinfo.flags,pi_do_call);
  1014. firstpass(hp.left);
  1015. if do_managed_variant then
  1016. wrapmanagedvarrec(hp.left);
  1017. end;
  1018. hp:=tarrayconstructornode(hp.right);
  1019. end;
  1020. end;
  1021. { set the elementdef to the correct type in case of a managed
  1022. variant array }
  1023. if do_managed_variant then
  1024. tarraydef(resultdef).elementdef:=search_system_type('TVARREC').typedef;
  1025. expectloc:=LOC_CREFERENCE;
  1026. end;
  1027. function tarrayconstructornode.docompare(p: tnode): boolean;
  1028. begin
  1029. docompare:=inherited docompare(p);
  1030. end;
  1031. {*****************************************************************************
  1032. TTYPENODE
  1033. *****************************************************************************}
  1034. constructor ttypenode.create(def:tdef);
  1035. begin
  1036. inherited create(typen);
  1037. typedef:=def;
  1038. typesym:=def.typesym;
  1039. allowed:=false;
  1040. helperallowed:=false;
  1041. end;
  1042. constructor ttypenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1043. begin
  1044. inherited ppuload(t,ppufile);
  1045. ppufile.getderef(typedefderef);
  1046. ppufile.getderef(typesymderef);
  1047. allowed:=boolean(ppufile.getbyte);
  1048. helperallowed:=boolean(ppufile.getbyte);
  1049. end;
  1050. procedure ttypenode.ppuwrite(ppufile:tcompilerppufile);
  1051. begin
  1052. inherited ppuwrite(ppufile);
  1053. ppufile.putderef(typedefderef);
  1054. ppufile.putderef(typesymderef);
  1055. ppufile.putbyte(byte(allowed));
  1056. ppufile.putbyte(byte(helperallowed));
  1057. end;
  1058. procedure ttypenode.buildderefimpl;
  1059. begin
  1060. inherited buildderefimpl;
  1061. typedefderef.build(typedef);
  1062. typesymderef.build(typesym);
  1063. end;
  1064. procedure ttypenode.derefimpl;
  1065. begin
  1066. inherited derefimpl;
  1067. typedef:=tdef(typedefderef.resolve);
  1068. typesym:=tsym(typesymderef.resolve);
  1069. end;
  1070. function ttypenode.pass_typecheck:tnode;
  1071. begin
  1072. result:=nil;
  1073. resultdef:=typedef;
  1074. { check if it's valid }
  1075. if typedef.typ = errordef then
  1076. CGMessage(parser_e_illegal_expression);
  1077. end;
  1078. function ttypenode.pass_1 : tnode;
  1079. begin
  1080. result:=nil;
  1081. expectloc:=LOC_VOID;
  1082. { a typenode can't generate code, so we give here
  1083. an error. Else it'll be an abstract error in pass_generate_code.
  1084. Only when the allowed flag is set we don't generate
  1085. an error }
  1086. if not allowed then
  1087. CGMessage(parser_e_no_type_not_allowed_here);
  1088. if not helperallowed and is_objectpascal_helper(typedef) then
  1089. CGMessage(parser_e_no_category_as_types);
  1090. end;
  1091. function ttypenode.dogetcopy : tnode;
  1092. var
  1093. n : ttypenode;
  1094. begin
  1095. n:=ttypenode(inherited dogetcopy);
  1096. n.allowed:=allowed;
  1097. n.typedef:=typedef;
  1098. n.helperallowed:=helperallowed;
  1099. result:=n;
  1100. end;
  1101. function ttypenode.docompare(p: tnode): boolean;
  1102. begin
  1103. docompare :=
  1104. inherited docompare(p) and
  1105. (typedef=ttypenode(p).typedef) and
  1106. (allowed=ttypenode(p).allowed) and
  1107. (helperallowed=ttypenode(p).helperallowed);
  1108. end;
  1109. {*****************************************************************************
  1110. TRTTINODE
  1111. *****************************************************************************}
  1112. constructor trttinode.create(def:tstoreddef;rt:trttitype;dt:Trttidatatype);
  1113. begin
  1114. inherited create(rttin);
  1115. rttidef:=def;
  1116. rttitype:=rt;
  1117. rttidatatype:=dt;
  1118. end;
  1119. constructor trttinode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1120. begin
  1121. inherited ppuload(t,ppufile);
  1122. ppufile.getderef(rttidefderef);
  1123. rttitype:=trttitype(ppufile.getbyte);
  1124. rttidatatype:=trttidatatype(ppufile.getbyte);
  1125. end;
  1126. procedure trttinode.ppuwrite(ppufile:tcompilerppufile);
  1127. begin
  1128. inherited ppuwrite(ppufile);
  1129. ppufile.putderef(rttidefderef);
  1130. ppufile.putbyte(byte(rttitype));
  1131. ppufile.putbyte(byte(rttidatatype));
  1132. end;
  1133. procedure trttinode.buildderefimpl;
  1134. begin
  1135. inherited buildderefimpl;
  1136. rttidefderef.build(rttidef);
  1137. end;
  1138. procedure trttinode.derefimpl;
  1139. begin
  1140. inherited derefimpl;
  1141. rttidef:=tstoreddef(rttidefderef.resolve);
  1142. end;
  1143. function trttinode.dogetcopy : tnode;
  1144. var
  1145. n : trttinode;
  1146. begin
  1147. n:=trttinode(inherited dogetcopy);
  1148. n.rttidef:=rttidef;
  1149. n.rttitype:=rttitype;
  1150. n.rttidatatype:=rttidatatype;
  1151. result:=n;
  1152. end;
  1153. function trttinode.pass_typecheck:tnode;
  1154. begin
  1155. { rtti information will be returned as a void pointer }
  1156. result:=nil;
  1157. resultdef:=voidpointertype;
  1158. end;
  1159. function trttinode.pass_1 : tnode;
  1160. begin
  1161. result:=nil;
  1162. expectloc:=LOC_CREFERENCE;
  1163. end;
  1164. function trttinode.docompare(p: tnode): boolean;
  1165. begin
  1166. docompare :=
  1167. inherited docompare(p) and
  1168. (rttidef = trttinode(p).rttidef) and
  1169. (rttitype = trttinode(p).rttitype) and
  1170. (rttidatatype = trttinode(p).rttidatatype);
  1171. end;
  1172. end.