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. verbose,globtype,globals,systems,constexp,
  154. symtable,
  155. defutil,defcmp,
  156. htypechk,pass_1,procinfo,paramgr,
  157. cpuinfo,
  158. ncon,ninl,ncnv,nmem,ncal,nutils,
  159. 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),lpf_forload);
  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. resultdef:=tabstractvarsym(symtableentry).vardef;
  291. { self for objects is passed as var-parameter on the caller
  292. side, but on the callee-side we use it as a pointer ->
  293. adjust }
  294. if (vo_is_self in tabstractvarsym(symtableentry).varoptions) then
  295. begin
  296. if (is_object(resultdef) or is_record(resultdef)) and
  297. (loadnf_load_self_pointer in loadnodeflags) then
  298. resultdef:=cpointerdef.getreusable(resultdef)
  299. else if (resultdef=objc_idtype) and
  300. (po_classmethod in tprocdef(symtableentry.owner.defowner).procoptions) then
  301. resultdef:=cclassrefdef.create(tprocdef(symtableentry.owner.defowner).struct)
  302. end
  303. end;
  304. procsym :
  305. begin
  306. { Return the first procdef. In case of overloaded
  307. procdefs the matching procdef will be choosen
  308. when the expected procvardef is known, see get_information
  309. in htypechk.pas (PFV) }
  310. if not assigned(fprocdef) then
  311. fprocdef:=tprocdef(tprocsym(symtableentry).ProcdefList[0])
  312. else if po_kylixlocal in fprocdef.procoptions then
  313. CGMessage(type_e_cant_take_address_of_local_subroutine);
  314. { the result is a fprocdef, addrn and proc_to_procvar
  315. typeconvn need this as resultdef so they know
  316. that the address needs to be returned }
  317. resultdef:=fprocdef;
  318. { process methodpointer/framepointer }
  319. if assigned(left) then
  320. typecheckpass(left);
  321. end;
  322. labelsym:
  323. begin
  324. tlabelsym(symtableentry).used:=true;
  325. resultdef:=voidtype;
  326. end;
  327. else
  328. internalerror(200104141);
  329. end;
  330. end;
  331. procedure Tloadnode.mark_write;
  332. begin
  333. include(flags,nf_write);
  334. end;
  335. function tloadnode.pass_1 : tnode;
  336. begin
  337. result:=nil;
  338. expectloc:=LOC_REFERENCE;
  339. if (cs_create_pic in current_settings.moduleswitches) and
  340. not(symtableentry.typ in [paravarsym,localvarsym]) then
  341. include(current_procinfo.flags,pi_needs_got);
  342. case symtableentry.typ of
  343. absolutevarsym :
  344. ;
  345. constsym:
  346. begin
  347. if tconstsym(symtableentry).consttyp=constresourcestring then
  348. expectloc:=LOC_CREFERENCE;
  349. end;
  350. staticvarsym,
  351. localvarsym,
  352. paravarsym :
  353. begin
  354. if assigned(left) then
  355. firstpass(left);
  356. if not is_addr_param_load and
  357. tabstractvarsym(symtableentry).is_regvar(is_addr_param_load) then
  358. expectloc:=tvarregable2tcgloc[tabstractvarsym(symtableentry).varregable]
  359. else
  360. if (tabstractvarsym(symtableentry).varspez=vs_const) then
  361. expectloc:=LOC_CREFERENCE;
  362. if (target_info.system=system_powerpc_darwin) and
  363. ([vo_is_dll_var,vo_is_external] * tabstractvarsym(symtableentry).varoptions <> []) then
  364. include(current_procinfo.flags,pi_needs_got);
  365. { call to get address of threadvar }
  366. if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then
  367. include(current_procinfo.flags,pi_do_call);
  368. end;
  369. procsym :
  370. begin
  371. { initialise left for nested procs if necessary }
  372. if (m_nested_procvars in current_settings.modeswitches) then
  373. setprocdef(fprocdef);
  374. { method pointer or nested proc ? }
  375. if assigned(left) then
  376. begin
  377. expectloc:=LOC_CREGISTER;
  378. firstpass(left);
  379. end;
  380. end;
  381. labelsym :
  382. begin
  383. if not assigned(tlabelsym(symtableentry).asmblocklabel) and
  384. not assigned(tlabelsym(symtableentry).code) then
  385. Message(parser_e_label_outside_proc);
  386. end
  387. else
  388. internalerror(200104143);
  389. end;
  390. end;
  391. function tloadnode.docompare(p: tnode): boolean;
  392. begin
  393. docompare :=
  394. inherited docompare(p) and
  395. (symtableentry = tloadnode(p).symtableentry) and
  396. (fprocdef = tloadnode(p).fprocdef) and
  397. (symtable = tloadnode(p).symtable);
  398. end;
  399. procedure tloadnode.printnodedata(var t:text);
  400. begin
  401. inherited printnodedata(t);
  402. write(t,printnodeindention,'symbol = ',symtableentry.name);
  403. if symtableentry.typ=procsym then
  404. write(t,printnodeindention,'procdef = ',fprocdef.mangledname);
  405. writeln(t,'');
  406. end;
  407. procedure tloadnode.setprocdef(p : tprocdef);
  408. begin
  409. fprocdef:=p;
  410. resultdef:=p;
  411. { nested procedure? }
  412. if assigned(p) and
  413. is_nested_pd(p) then
  414. begin
  415. if not(m_nested_procvars in current_settings.modeswitches) then
  416. CGMessage(type_e_cant_take_address_of_local_subroutine)
  417. else
  418. begin
  419. { parent frame pointer pointer as "self" }
  420. left.free;
  421. left:=cloadparentfpnode.create(tprocdef(p.owner.defowner),lpf_forpara);
  422. end;
  423. end
  424. { we should never go from nested to non-nested }
  425. else if assigned(left) and
  426. (left.nodetype=loadparentfpn) then
  427. internalerror(2010072201);
  428. end;
  429. {*****************************************************************************
  430. TASSIGNMENTNODE
  431. *****************************************************************************}
  432. function tassignmentnode.direct_shortstring_assignment: boolean;
  433. begin
  434. result:=
  435. is_char(right.resultdef) or
  436. (right.resultdef.typ=stringdef);
  437. end;
  438. constructor tassignmentnode.create(l,r : tnode);
  439. begin
  440. inherited create(assignn,l,r);
  441. l.mark_write;
  442. assigntype:=at_normal;
  443. if r.nodetype = typeconvn then
  444. ttypeconvnode(r).warn_pointer_to_signed:=false;
  445. end;
  446. constructor tassignmentnode.create_internal(l, r: tnode);
  447. begin
  448. create(l,r);
  449. include(flags,nf_internal);
  450. end;
  451. constructor tassignmentnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  452. begin
  453. inherited ppuload(t,ppufile);
  454. assigntype:=tassigntype(ppufile.getbyte);
  455. end;
  456. procedure tassignmentnode.ppuwrite(ppufile:tcompilerppufile);
  457. begin
  458. inherited ppuwrite(ppufile);
  459. ppufile.putbyte(byte(assigntype));
  460. end;
  461. function tassignmentnode.dogetcopy : tnode;
  462. var
  463. n : tassignmentnode;
  464. begin
  465. n:=tassignmentnode(inherited dogetcopy);
  466. n.assigntype:=assigntype;
  467. result:=n;
  468. end;
  469. function tassignmentnode.simplify(forinline : boolean) : tnode;
  470. begin
  471. result:=nil;
  472. { assignment nodes can perform several floating point }
  473. { type conversions directly, so no typeconversions }
  474. { are inserted in those cases. When inlining, a }
  475. { variable may be replaced by a constant which can be }
  476. { converted at compile time, so check for this case }
  477. if is_real(left.resultdef) and
  478. is_real(right.resultdef) and
  479. is_constrealnode(right) and
  480. not equal_defs(right.resultdef,left.resultdef) then
  481. inserttypeconv(right,left.resultdef);
  482. end;
  483. function tassignmentnode.pass_typecheck:tnode;
  484. var
  485. hp : tnode;
  486. useshelper : boolean;
  487. oldassignmentnode : tassignmentnode;
  488. begin
  489. result:=nil;
  490. resultdef:=voidtype;
  491. { must be made unique }
  492. set_unique(left);
  493. typecheckpass(left);
  494. { PI. This is needed to return correct resultdef of add nodes for ansistrings
  495. rawbytestring return needs to be replaced by left.resultdef }
  496. oldassignmentnode:=aktassignmentnode;
  497. aktassignmentnode:=self;
  498. typecheckpass(right);
  499. aktassignmentnode:=oldassignmentnode;
  500. set_varstate(right,vs_read,[vsf_must_be_valid]);
  501. set_varstate(left,vs_written,[]);
  502. if codegenerror then
  503. exit;
  504. { tp procvar support, when we don't expect a procvar
  505. then we need to call the procvar }
  506. if (left.resultdef.typ<>procvardef) then
  507. maybe_call_procvar(right,true);
  508. { assignments to formaldefs and open arrays aren't allowed }
  509. if is_open_array(left.resultdef) then
  510. CGMessage(type_e_assignment_not_allowed)
  511. else if (left.resultdef.typ=formaldef) then
  512. if not(target_info.system in systems_managed_vm) then
  513. CGMessage(type_e_assignment_not_allowed)
  514. else
  515. begin
  516. { on managed platforms, assigning to formaldefs is allowed (but
  517. typecasting them on the left hand side isn't), but primitive
  518. values need to be boxed first }
  519. if (right.resultdef.typ in [orddef,floatdef]) then
  520. begin
  521. right:=cinlinenode.create(in_box_x,false,ccallparanode.create(right,nil));
  522. typecheckpass(right);
  523. end;
  524. end;
  525. { test if node can be assigned, properties are allowed }
  526. if not(nf_internal in flags) then
  527. if not valid_for_assignment(left,true) then
  528. { errors can in situations that cause the compiler to run out of
  529. memory, such as assigning to an implicit pointer-to-array
  530. converted node (that array is 2^31 or 2^63 bytes large) }
  531. exit;
  532. { assigning nil to a dynamic array clears the array }
  533. if is_dynamic_array(left.resultdef) and
  534. (right.nodetype=niln) then
  535. begin
  536. { remove property flag to avoid errors, see comments for }
  537. { tf_winlikewidestring assignments below }
  538. exclude(left.flags,nf_isproperty);
  539. { generate a setlength node so it can be intercepted by
  540. target-specific code }
  541. result:=cinlinenode.create(in_setlength_x,false,
  542. ccallparanode.create(genintconstnode(0),
  543. ccallparanode.create(left,nil)));
  544. left:=nil;
  545. exit;
  546. end;
  547. { shortstring helpers can do the conversion directly,
  548. so treat them separatly }
  549. if (is_shortstring(left.resultdef)) then
  550. begin
  551. { insert typeconv, except for chars that are handled in
  552. secondpass and except for ansi/wide string that can
  553. be converted immediatly }
  554. if not direct_shortstring_assignment then
  555. inserttypeconv(right,left.resultdef);
  556. if right.resultdef.typ=stringdef then
  557. begin
  558. useshelper:=true;
  559. { convert constant strings to shortstrings. But
  560. skip empty constant strings, that will be handled
  561. in secondpass }
  562. if (right.nodetype=stringconstn) then
  563. begin
  564. { verify if range fits within shortstring }
  565. { just emit a warning, delphi gives an }
  566. { error, only if the type definition of }
  567. { of the string is less < 255 characters }
  568. if not is_open_string(left.resultdef) and
  569. (tstringconstnode(right).len > tstringdef(left.resultdef).len) then
  570. cgmessage(type_w_string_too_long);
  571. inserttypeconv(right,left.resultdef);
  572. if (right.nodetype=stringconstn) and
  573. (tstringconstnode(right).len=0) then
  574. useshelper:=false;
  575. end
  576. else if (tstringdef(right.resultdef).stringtype in [st_unicodestring,st_widestring]) then
  577. Message2(type_w_implicit_string_cast_loss,right.resultdef.typename,left.resultdef.typename);
  578. { rest is done in pass 1 (JM) }
  579. if useshelper then
  580. exit;
  581. end
  582. end
  583. { floating point assignments can also perform the conversion directly }
  584. else if is_real(left.resultdef) and is_real(right.resultdef) and
  585. not is_constrealnode(right)
  586. {$ifdef cpufpemu}
  587. { the emulator can't do this obviously }
  588. and not(current_settings.fputype in [fpu_libgcc,fpu_soft])
  589. {$endif cpufpemu}
  590. {$ifdef x86}
  591. { the assignment node code can't convert a double in an }
  592. { sse register to an extended value in memory more }
  593. { efficiently than a type conversion node, so don't }
  594. { bother implementing support for that }
  595. and (use_vectorfpu(left.resultdef) or not(use_vectorfpu(right.resultdef)))
  596. {$endif}
  597. {$ifdef arm}
  598. { the assignment node code can't convert a single in
  599. an interger register to a double in an mmregister or
  600. vice versa }
  601. and (use_vectorfpu(left.resultdef) and
  602. use_vectorfpu(right.resultdef) and
  603. (tfloatdef(left.resultdef).floattype=tfloatdef(right.resultdef).floattype))
  604. {$endif}
  605. then
  606. begin
  607. if not(nf_internal in flags) then
  608. check_ranges(fileinfo,right,left.resultdef);
  609. end
  610. else
  611. begin
  612. { check if the assignment may cause a range check error }
  613. if not(nf_internal in flags) then
  614. check_ranges(fileinfo,right,left.resultdef);
  615. { beginners might be confused about an error message like
  616. Incompatible types: got "untyped" expected "LongInt"
  617. when trying to assign the result of a procedure, so give
  618. a better error message, see also #19122 }
  619. if (left.resultdef.typ<>procvardef) and
  620. (right.nodetype=calln) and is_void(right.resultdef) then
  621. CGMessage(type_e_procedures_return_no_value)
  622. else if nf_internal in flags then
  623. inserttypeconv_internal(right,left.resultdef)
  624. else
  625. inserttypeconv(right,left.resultdef);
  626. end;
  627. { call helpers for interface }
  628. if is_interfacecom_or_dispinterface(left.resultdef) then
  629. begin
  630. { Normal interface assignments are handled by the generic refcount incr/decr }
  631. if not def_is_related(right.resultdef,left.resultdef) then
  632. begin
  633. { remove property flag to avoid errors, see comments for }
  634. { tf_winlikewidestring assignments below }
  635. exclude(left.flags,nf_isproperty);
  636. hp:=
  637. ccallparanode.create(
  638. cguidconstnode.create(tobjectdef(left.resultdef).iidguid^),
  639. ccallparanode.create(
  640. ctypeconvnode.create_internal(right,voidpointertype),
  641. ccallparanode.create(
  642. ctypeconvnode.create_internal(left,voidpointertype),
  643. nil)));
  644. result:=ccallnode.createintern('fpc_intf_assign_by_iid',hp);
  645. left:=nil;
  646. right:=nil;
  647. exit;
  648. end;
  649. end;
  650. { check if local proc/func is assigned to procvar }
  651. if right.resultdef.typ=procvardef then
  652. test_local_to_procvar(tprocvardef(right.resultdef),left.resultdef);
  653. end;
  654. function tassignmentnode.pass_1 : tnode;
  655. var
  656. hp: tnode;
  657. oldassignmentnode : tassignmentnode;
  658. hdef: tdef;
  659. hs: string;
  660. needrtti: boolean;
  661. begin
  662. result:=nil;
  663. expectloc:=LOC_VOID;
  664. firstpass(left);
  665. { Optimize the reuse of the destination of the assingment in left.
  666. Allow the use of the left inside the tree generated on the right.
  667. This is especially useful for string routines where the destination
  668. is pushed as a parameter. Using the final destination of left directly
  669. save a temp allocation and copy of data (PFV) }
  670. oldassignmentnode:=aktassignmentnode;
  671. aktassignmentnode:=self;
  672. firstpass(right);
  673. aktassignmentnode:=oldassignmentnode;
  674. if nf_assign_done_in_right in flags then
  675. begin
  676. result:=right;
  677. right:=nil;
  678. exit;
  679. end;
  680. if codegenerror then
  681. exit;
  682. { assignment to refcounted variable -> inc/decref }
  683. if is_managed_type(left.resultdef) then
  684. include(current_procinfo.flags,pi_do_call);
  685. needrtti:=false;
  686. if (is_shortstring(left.resultdef)) then
  687. begin
  688. if right.resultdef.typ=stringdef then
  689. begin
  690. if (right.nodetype<>stringconstn) or
  691. (tstringconstnode(right).len<>0) then
  692. begin
  693. { remove property flag to avoid errors, see comments for }
  694. { tf_winlikewidestring assignments below }
  695. exclude(left.flags, nf_isproperty);
  696. hp:=ccallparanode.create
  697. (right,
  698. ccallparanode.create(left,nil));
  699. result:=ccallnode.createintern('fpc_'+tstringdef(right.resultdef).stringtypname+'_to_shortstr',hp);
  700. firstpass(result);
  701. left:=nil;
  702. right:=nil;
  703. end;
  704. end;
  705. exit;
  706. end
  707. { call helpers for composite types containing automated types }
  708. else if is_managed_type(left.resultdef) and
  709. (left.resultdef.typ in [arraydef,objectdef,recorddef]) and
  710. not is_interfacecom_or_dispinterface(left.resultdef) and
  711. not is_dynamic_array(left.resultdef) and
  712. not is_const(left) and
  713. not(target_info.system in systems_garbage_collected_managed_types) then
  714. begin
  715. hp:=ccallparanode.create(caddrnode.create_internal(
  716. crttinode.create(tstoreddef(left.resultdef),initrtti,rdt_normal)),
  717. ccallparanode.create(ctypeconvnode.create_internal(
  718. caddrnode.create_internal(left),voidpointertype),
  719. ccallparanode.create(ctypeconvnode.create_internal(
  720. caddrnode.create_internal(right),voidpointertype),
  721. nil)));
  722. result:=ccallnode.createintern('fpc_copy_proc',hp);
  723. firstpass(result);
  724. left:=nil;
  725. right:=nil;
  726. exit;
  727. end
  728. { call helpers for variant, they can contain non ref. counted types like
  729. vararrays which must be really copied }
  730. else if (left.resultdef.typ=variantdef) and
  731. not(target_info.system in systems_garbage_collected_managed_types) then
  732. begin
  733. { remove property flag to avoid errors, see comments for }
  734. { tf_winlikewidestring assignments below }
  735. exclude(left.flags,nf_isproperty);
  736. hdef:=search_system_type('TVARDATA').typedef;
  737. hp:=ccallparanode.create(ctypeconvnode.create_internal(
  738. right,hdef),
  739. ccallparanode.create(ctypeconvnode.create_internal(
  740. left,hdef),
  741. nil));
  742. result:=ccallnode.createintern('fpc_variant_copy',hp);
  743. firstpass(result);
  744. left:=nil;
  745. right:=nil;
  746. exit;
  747. end
  748. else if not(target_info.system in systems_garbage_collected_managed_types) and
  749. not(is_const(left)) then
  750. begin
  751. { call helpers for pointer-sized managed types }
  752. if is_widestring(left.resultdef) then
  753. hs:='fpc_widestr_assign'
  754. else if is_ansistring(left.resultdef) then
  755. hs:='fpc_ansistr_assign'
  756. else if is_unicodestring(left.resultdef) then
  757. hs:='fpc_unicodestr_assign'
  758. else if is_interfacecom_or_dispinterface(left.resultdef) then
  759. hs:='fpc_intf_assign'
  760. else if is_dynamic_array(left.resultdef) then
  761. begin
  762. hs:='fpc_dynarray_assign';
  763. needrtti:=true;
  764. end
  765. else
  766. exit;
  767. end
  768. else
  769. exit;
  770. { The first argument of these procedures is a var parameter. Properties cannot }
  771. { be passed to var or out parameters, because in that case setters/getters are not }
  772. { used. Further, if we would allow it in case there are no getters or setters, you }
  773. { would need source changes in case these are introduced later on, thus defeating }
  774. { part of the transparency advantages of properties. In this particular case, }
  775. { however: }
  776. { a) if there is a setter, this code will not be used since then the assignment }
  777. { will be converted to a procedure call }
  778. { b) the getter is irrelevant, because fpc_widestr_assign must always decrease }
  779. { the refcount of the field to which we are writing }
  780. { c) source code changes are not required if a setter is added/removed, because }
  781. { this transformation is handled at compile time }
  782. { -> we can remove the nf_isproperty flag (if any) from left, so that in case it }
  783. { is a property which refers to a field without a setter call, we will not get }
  784. { an error about trying to pass a property as a var parameter }
  785. exclude(left.flags,nf_isproperty);
  786. hp:=ccallparanode.create(ctypeconvnode.create_internal(right,voidpointertype),
  787. ccallparanode.create(ctypeconvnode.create_internal(left,voidpointertype),
  788. nil));
  789. if needrtti then
  790. hp:=ccallparanode.create(
  791. caddrnode.create_internal(
  792. crttinode.create(tstoreddef(left.resultdef),initrtti,rdt_normal)),
  793. hp);
  794. result:=ccallnode.createintern(hs,hp);
  795. firstpass(result);
  796. left:=nil;
  797. right:=nil;
  798. end;
  799. function tassignmentnode.docompare(p: tnode): boolean;
  800. begin
  801. docompare :=
  802. inherited docompare(p) and
  803. (assigntype = tassignmentnode(p).assigntype);
  804. end;
  805. {$ifdef state_tracking}
  806. function Tassignmentnode.track_state_pass(exec_known:boolean):boolean;
  807. var se:Tstate_entry;
  808. begin
  809. track_state_pass:=false;
  810. if exec_known then
  811. begin
  812. track_state_pass:=right.track_state_pass(exec_known);
  813. {Force a new resultdef pass.}
  814. right.resultdef:=nil;
  815. do_typecheckpass(right);
  816. typecheckpass(right);
  817. aktstate.store_fact(left.getcopy,right.getcopy);
  818. end
  819. else
  820. aktstate.delete_fact(left);
  821. end;
  822. {$endif}
  823. {*****************************************************************************
  824. TARRAYCONSTRUCTORRANGENODE
  825. *****************************************************************************}
  826. constructor tarrayconstructorrangenode.create(l,r : tnode);
  827. begin
  828. inherited create(arrayconstructorrangen,l,r);
  829. end;
  830. function tarrayconstructorrangenode.pass_typecheck:tnode;
  831. begin
  832. result:=nil;
  833. typecheckpass(left);
  834. typecheckpass(right);
  835. set_varstate(left,vs_read,[vsf_must_be_valid]);
  836. set_varstate(right,vs_read,[vsf_must_be_valid]);
  837. if codegenerror then
  838. exit;
  839. resultdef:=left.resultdef;
  840. end;
  841. function tarrayconstructorrangenode.pass_1 : tnode;
  842. begin
  843. result:=nil;
  844. CGMessage(parser_e_illegal_expression);
  845. end;
  846. {****************************************************************************
  847. TARRAYCONSTRUCTORNODE
  848. *****************************************************************************}
  849. constructor tarrayconstructornode.create(l,r : tnode);
  850. begin
  851. inherited create(arrayconstructorn,l,r);
  852. end;
  853. function tarrayconstructornode.dogetcopy : tnode;
  854. var
  855. n : tarrayconstructornode;
  856. begin
  857. n:=tarrayconstructornode(inherited dogetcopy);
  858. result:=n;
  859. end;
  860. function tarrayconstructornode.pass_typecheck:tnode;
  861. var
  862. hdef : tdef;
  863. hp : tarrayconstructornode;
  864. len : longint;
  865. varia : boolean;
  866. eq : tequaltype;
  867. hnodetype : tnodetype;
  868. begin
  869. result:=nil;
  870. { are we allowing array constructor? Then convert it to a set.
  871. Do this only if we didn't convert the arrayconstructor yet. This
  872. is needed for the cases where the resultdef is forced for a second
  873. run }
  874. if not(allow_array_constructor) then
  875. begin
  876. hp:=tarrayconstructornode(getcopy);
  877. arrayconstructor_to_set(tnode(hp));
  878. result:=hp;
  879. exit;
  880. end;
  881. { only pass left tree, right tree contains next construct if any }
  882. hdef:=nil;
  883. hnodetype:=errorn;
  884. len:=0;
  885. varia:=false;
  886. if assigned(left) then
  887. begin
  888. hp:=self;
  889. while assigned(hp) do
  890. begin
  891. typecheckpass(hp.left);
  892. set_varstate(hp.left,vs_read,[vsf_must_be_valid]);
  893. if (hdef=nil) then
  894. begin
  895. hdef:=hp.left.resultdef;
  896. hnodetype:=hp.left.nodetype;
  897. end
  898. else
  899. begin
  900. { If we got a niln we don't know the type yet and need to take the
  901. type of the next array element.
  902. This is to handle things like [nil,tclass,tclass], see also tw8371 (PFV) }
  903. if hnodetype=niln then
  904. begin
  905. eq:=compare_defs(hp.left.resultdef,hdef,hnodetype);
  906. if eq>te_incompatible then
  907. begin
  908. hdef:=hp.left.resultdef;
  909. hnodetype:=hp.left.nodetype;
  910. end;
  911. end
  912. else
  913. eq:=compare_defs(hdef,hp.left.resultdef,hp.left.nodetype);
  914. if (not varia) and (eq<te_equal) then
  915. begin
  916. { If both are integers we need to take the type that can hold both
  917. defs }
  918. if is_integer(hdef) and is_integer(hp.left.resultdef) then
  919. begin
  920. if is_in_limit(hdef,hp.left.resultdef) then
  921. hdef:=hp.left.resultdef;
  922. end
  923. else
  924. if (nf_novariaallowed in flags) then
  925. varia:=true;
  926. end;
  927. end;
  928. inc(len);
  929. hp:=tarrayconstructornode(hp.right);
  930. end;
  931. end;
  932. { Set the type of empty or varia arrays to void. Also
  933. do this if the type is array of const/open array
  934. because those can't be used with setelementdef }
  935. if not assigned(hdef) or
  936. varia or
  937. is_array_of_const(hdef) or
  938. is_open_array(hdef) then
  939. hdef:=voidtype;
  940. resultdef:=carraydef.create(0,len-1,s32inttype);
  941. tarraydef(resultdef).elementdef:=hdef;
  942. include(tarraydef(resultdef).arrayoptions,ado_IsConstructor);
  943. if varia then
  944. include(tarraydef(resultdef).arrayoptions,ado_IsVariant);
  945. end;
  946. procedure tarrayconstructornode.force_type(def:tdef);
  947. var
  948. hp : tarrayconstructornode;
  949. begin
  950. tarraydef(resultdef).elementdef:=def;
  951. include(tarraydef(resultdef).arrayoptions,ado_IsConstructor);
  952. exclude(tarraydef(resultdef).arrayoptions,ado_IsVariant);
  953. if assigned(left) then
  954. begin
  955. hp:=self;
  956. while assigned(hp) do
  957. begin
  958. inserttypeconv(hp.left,def);
  959. hp:=tarrayconstructornode(hp.right);
  960. end;
  961. end;
  962. end;
  963. procedure tarrayconstructornode.insert_typeconvs;
  964. var
  965. hp : tarrayconstructornode;
  966. dovariant : boolean;
  967. begin
  968. dovariant:=(nf_forcevaria in flags) or (ado_isvariant in tarraydef(resultdef).arrayoptions);
  969. { only pass left tree, right tree contains next construct if any }
  970. if assigned(left) then
  971. begin
  972. hp:=self;
  973. while assigned(hp) do
  974. begin
  975. typecheckpass(hp.left);
  976. { Insert typeconvs for array of const }
  977. if dovariant then
  978. { at this time C varargs are no longer an arrayconstructornode }
  979. insert_varargstypeconv(hp.left,false);
  980. hp:=tarrayconstructornode(hp.right);
  981. end;
  982. end;
  983. end;
  984. function tarrayconstructornode.pass_1 : tnode;
  985. var
  986. hp : tarrayconstructornode;
  987. do_variant,
  988. do_managed_variant:boolean;
  989. begin
  990. do_variant:=(nf_forcevaria in flags) or (ado_isvariant in tarraydef(resultdef).arrayoptions);
  991. do_managed_variant:=
  992. do_variant and
  993. (target_info.system in systems_managed_vm);
  994. result:=nil;
  995. { Insert required type convs, this must be
  996. done in pass 1, because the call must be
  997. typecheckpassed already }
  998. if assigned(left) then
  999. begin
  1000. insert_typeconvs;
  1001. { call firstpass for all nodes }
  1002. hp:=self;
  1003. while assigned(hp) do
  1004. begin
  1005. if hp.left<>nil then
  1006. begin
  1007. {This check is pessimistic; a call will happen depending
  1008. on the location in which the elements will be found in
  1009. pass 2.}
  1010. if not do_variant then
  1011. include(current_procinfo.flags,pi_do_call);
  1012. firstpass(hp.left);
  1013. if do_managed_variant then
  1014. wrapmanagedvarrec(hp.left);
  1015. end;
  1016. hp:=tarrayconstructornode(hp.right);
  1017. end;
  1018. end;
  1019. { set the elementdef to the correct type in case of a variant array }
  1020. if do_variant then
  1021. tarraydef(resultdef).elementdef:=search_system_type('TVARREC').typedef;
  1022. expectloc:=LOC_CREFERENCE;
  1023. end;
  1024. function tarrayconstructornode.docompare(p: tnode): boolean;
  1025. begin
  1026. docompare:=inherited docompare(p);
  1027. end;
  1028. {*****************************************************************************
  1029. TTYPENODE
  1030. *****************************************************************************}
  1031. constructor ttypenode.create(def:tdef);
  1032. begin
  1033. inherited create(typen);
  1034. typedef:=def;
  1035. typesym:=def.typesym;
  1036. allowed:=false;
  1037. helperallowed:=false;
  1038. end;
  1039. constructor ttypenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1040. begin
  1041. inherited ppuload(t,ppufile);
  1042. ppufile.getderef(typedefderef);
  1043. ppufile.getderef(typesymderef);
  1044. allowed:=boolean(ppufile.getbyte);
  1045. helperallowed:=boolean(ppufile.getbyte);
  1046. end;
  1047. procedure ttypenode.ppuwrite(ppufile:tcompilerppufile);
  1048. begin
  1049. inherited ppuwrite(ppufile);
  1050. ppufile.putderef(typedefderef);
  1051. ppufile.putderef(typesymderef);
  1052. ppufile.putbyte(byte(allowed));
  1053. ppufile.putbyte(byte(helperallowed));
  1054. end;
  1055. procedure ttypenode.buildderefimpl;
  1056. begin
  1057. inherited buildderefimpl;
  1058. typedefderef.build(typedef);
  1059. typesymderef.build(typesym);
  1060. end;
  1061. procedure ttypenode.derefimpl;
  1062. begin
  1063. inherited derefimpl;
  1064. typedef:=tdef(typedefderef.resolve);
  1065. typesym:=tsym(typesymderef.resolve);
  1066. end;
  1067. function ttypenode.pass_typecheck:tnode;
  1068. begin
  1069. result:=nil;
  1070. resultdef:=typedef;
  1071. { check if it's valid }
  1072. if typedef.typ = errordef then
  1073. CGMessage(parser_e_illegal_expression);
  1074. end;
  1075. function ttypenode.pass_1 : tnode;
  1076. begin
  1077. result:=nil;
  1078. expectloc:=LOC_VOID;
  1079. { a typenode can't generate code, so we give here
  1080. an error. Else it'll be an abstract error in pass_generate_code.
  1081. Only when the allowed flag is set we don't generate
  1082. an error }
  1083. if not allowed then
  1084. CGMessage(parser_e_no_type_not_allowed_here);
  1085. if not helperallowed and is_objectpascal_helper(typedef) then
  1086. CGMessage(parser_e_no_category_as_types);
  1087. end;
  1088. function ttypenode.dogetcopy : tnode;
  1089. var
  1090. n : ttypenode;
  1091. begin
  1092. n:=ttypenode(inherited dogetcopy);
  1093. n.allowed:=allowed;
  1094. n.typedef:=typedef;
  1095. n.helperallowed:=helperallowed;
  1096. result:=n;
  1097. end;
  1098. function ttypenode.docompare(p: tnode): boolean;
  1099. begin
  1100. docompare :=
  1101. inherited docompare(p) and
  1102. (typedef=ttypenode(p).typedef) and
  1103. (allowed=ttypenode(p).allowed) and
  1104. (helperallowed=ttypenode(p).helperallowed);
  1105. end;
  1106. {*****************************************************************************
  1107. TRTTINODE
  1108. *****************************************************************************}
  1109. constructor trttinode.create(def:tstoreddef;rt:trttitype;dt:Trttidatatype);
  1110. begin
  1111. inherited create(rttin);
  1112. rttidef:=def;
  1113. rttitype:=rt;
  1114. rttidatatype:=dt;
  1115. end;
  1116. constructor trttinode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1117. begin
  1118. inherited ppuload(t,ppufile);
  1119. ppufile.getderef(rttidefderef);
  1120. rttitype:=trttitype(ppufile.getbyte);
  1121. rttidatatype:=trttidatatype(ppufile.getbyte);
  1122. end;
  1123. procedure trttinode.ppuwrite(ppufile:tcompilerppufile);
  1124. begin
  1125. inherited ppuwrite(ppufile);
  1126. ppufile.putderef(rttidefderef);
  1127. ppufile.putbyte(byte(rttitype));
  1128. ppufile.putbyte(byte(rttidatatype));
  1129. end;
  1130. procedure trttinode.buildderefimpl;
  1131. begin
  1132. inherited buildderefimpl;
  1133. rttidefderef.build(rttidef);
  1134. end;
  1135. procedure trttinode.derefimpl;
  1136. begin
  1137. inherited derefimpl;
  1138. rttidef:=tstoreddef(rttidefderef.resolve);
  1139. end;
  1140. function trttinode.dogetcopy : tnode;
  1141. var
  1142. n : trttinode;
  1143. begin
  1144. n:=trttinode(inherited dogetcopy);
  1145. n.rttidef:=rttidef;
  1146. n.rttitype:=rttitype;
  1147. n.rttidatatype:=rttidatatype;
  1148. result:=n;
  1149. end;
  1150. function trttinode.pass_typecheck:tnode;
  1151. begin
  1152. { rtti information will be returned as a void pointer }
  1153. result:=nil;
  1154. resultdef:=voidpointertype;
  1155. end;
  1156. function trttinode.pass_1 : tnode;
  1157. begin
  1158. result:=nil;
  1159. expectloc:=LOC_CREFERENCE;
  1160. if (cs_create_pic in current_settings.moduleswitches) and
  1161. (tf_pic_uses_got in target_info.flags) then
  1162. include(current_procinfo.flags,pi_needs_got);
  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.