nld.pas 49 KB

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