nld.pas 49 KB

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