nld.pas 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Type checking and register allocation for load/assignment nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nld;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,
  22. {$ifdef state_tracking}
  23. nstate,
  24. {$endif}
  25. symconst,symbase,symtype,symsym,symdef;
  26. type
  27. Trttidatatype = (rdt_normal,rdt_ord2str,rdt_str2ord);
  28. tloadnodeflags = (
  29. loadnf_is_self,
  30. loadnf_load_self_pointer,
  31. loadnf_inherited,
  32. { the loadnode is generated internally and a varspez=vs_const should be ignore,
  33. this requires that the parameter is actually passed by value
  34. Be really carefull when using this flag! }
  35. loadnf_isinternal_ignoreconst,
  36. loadnf_only_uninitialized_hint
  37. );
  38. tloadnode = class(tunarynode)
  39. protected
  40. fprocdef : tprocdef;
  41. fprocdefderef : tderef;
  42. function handle_threadvar_access: tnode; virtual;
  43. public
  44. loadnodeflags : set of tloadnodeflags;
  45. symtableentry : tsym;
  46. symtableentryderef : tderef;
  47. symtable : TSymtable;
  48. constructor create(v : tsym;st : TSymtable);virtual;
  49. constructor create_procvar(v : tsym;d:tprocdef;st : TSymtable);virtual;
  50. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  51. procedure ppuwrite(ppufile:tcompilerppufile);override;
  52. procedure buildderefimpl;override;
  53. procedure derefimpl;override;
  54. procedure set_mp(p:tnode);
  55. function is_addr_param_load:boolean;virtual;
  56. function dogetcopy : tnode;override;
  57. function pass_1 : tnode;override;
  58. function pass_typecheck:tnode;override;
  59. procedure mark_write;override;
  60. function docompare(p: tnode): boolean; override;
  61. procedure printnodedata(var t:text);override;
  62. procedure setprocdef(p : tprocdef);
  63. property procdef: tprocdef read fprocdef write setprocdef;
  64. end;
  65. tloadnodeclass = class of tloadnode;
  66. { different assignment types }
  67. tassigntype = (at_normal,at_plus,at_minus,at_star,at_slash);
  68. tassignmentnode = class(tbinarynode)
  69. protected
  70. function direct_shortstring_assignment: boolean; virtual;
  71. public
  72. assigntype : tassigntype;
  73. constructor create(l,r : tnode);virtual;
  74. { no checks for validity of assignment }
  75. constructor create_internal(l,r : tnode);virtual;
  76. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  77. procedure ppuwrite(ppufile:tcompilerppufile);override;
  78. function dogetcopy : tnode;override;
  79. function pass_1 : tnode;override;
  80. function pass_typecheck:tnode;override;
  81. function simplify(forinline : boolean) : tnode;override;
  82. {$ifdef state_tracking}
  83. function track_state_pass(exec_known:boolean):boolean;override;
  84. {$endif state_tracking}
  85. function docompare(p: tnode): boolean; override;
  86. end;
  87. tassignmentnodeclass = class of tassignmentnode;
  88. tarrayconstructorrangenode = class(tbinarynode)
  89. constructor create(l,r : tnode);virtual;
  90. function pass_1 : tnode;override;
  91. function pass_typecheck:tnode;override;
  92. end;
  93. tarrayconstructorrangenodeclass = class of tarrayconstructorrangenode;
  94. tarrayconstructornode = class(tbinarynode)
  95. protected
  96. procedure wrapmanagedvarrec(var n: tnode);virtual;abstract;
  97. public
  98. constructor create(l,r : tnode);virtual;
  99. function dogetcopy : tnode;override;
  100. function pass_1 : tnode;override;
  101. function pass_typecheck:tnode;override;
  102. function docompare(p: tnode): boolean; override;
  103. procedure force_type(def:tdef);
  104. procedure insert_typeconvs;
  105. end;
  106. tarrayconstructornodeclass = class of tarrayconstructornode;
  107. ttypenode = class(tnode)
  108. allowed : boolean;
  109. helperallowed : boolean;
  110. typedef : tdef;
  111. typedefderef : tderef;
  112. typesym : tsym;
  113. typesymderef : tderef;
  114. constructor create(def:tdef);virtual;
  115. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  116. procedure ppuwrite(ppufile:tcompilerppufile);override;
  117. procedure buildderefimpl;override;
  118. procedure derefimpl;override;
  119. function pass_1 : tnode;override;
  120. function pass_typecheck:tnode;override;
  121. function dogetcopy : tnode;override;
  122. function docompare(p: tnode): boolean; override;
  123. end;
  124. ttypenodeclass = class of ttypenode;
  125. trttinode = class(tnode)
  126. l1,l2 : longint;
  127. rttitype : trttitype;
  128. rttidef : tstoreddef;
  129. rttidefderef : tderef;
  130. rttidatatype : Trttidatatype;
  131. constructor create(def:tstoreddef;rt:trttitype;dt:Trttidatatype);virtual;
  132. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  133. procedure ppuwrite(ppufile:tcompilerppufile);override;
  134. procedure buildderefimpl;override;
  135. procedure derefimpl;override;
  136. function dogetcopy : tnode;override;
  137. function pass_1 : tnode;override;
  138. function pass_typecheck:tnode;override;
  139. function docompare(p: tnode): boolean; override;
  140. end;
  141. trttinodeclass = class of trttinode;
  142. var
  143. cloadnode : tloadnodeclass = tloadnode;
  144. cassignmentnode : tassignmentnodeclass = tassignmentnode;
  145. carrayconstructorrangenode : tarrayconstructorrangenodeclass = tarrayconstructorrangenode;
  146. carrayconstructornode : tarrayconstructornodeclass = tarrayconstructornode;
  147. ctypenode : ttypenodeclass = ttypenode;
  148. crttinode : trttinodeclass = trttinode;
  149. { Current assignment node }
  150. aktassignmentnode : tassignmentnode;
  151. implementation
  152. uses
  153. verbose,globtype,globals,systems,constexp,
  154. symtable,
  155. defutil,defcmp,
  156. htypechk,pass_1,procinfo,paramgr,
  157. cpuinfo,
  158. ncon,ninl,ncnv,nmem,ncal,nutils,
  159. cgbase
  160. ;
  161. {*****************************************************************************
  162. TLOADNODE
  163. *****************************************************************************}
  164. function tloadnode.handle_threadvar_access: tnode;
  165. begin
  166. { nothing special by default }
  167. result:=nil;
  168. end;
  169. constructor tloadnode.create(v : tsym;st : TSymtable);
  170. begin
  171. inherited create(loadn,nil);
  172. if not assigned(v) then
  173. internalerror(200108121);
  174. symtableentry:=v;
  175. symtable:=st;
  176. fprocdef:=nil;
  177. end;
  178. constructor tloadnode.create_procvar(v : tsym;d:tprocdef;st : TSymtable);
  179. begin
  180. inherited create(loadn,nil);
  181. if not assigned(v) then
  182. internalerror(200108122);
  183. symtableentry:=v;
  184. symtable:=st;
  185. fprocdef:=d;
  186. end;
  187. constructor tloadnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  188. begin
  189. inherited ppuload(t,ppufile);
  190. ppufile.getderef(symtableentryderef);
  191. symtable:=nil;
  192. ppufile.getderef(fprocdefderef);
  193. ppufile.getsmallset(loadnodeflags);
  194. end;
  195. procedure tloadnode.ppuwrite(ppufile:tcompilerppufile);
  196. begin
  197. inherited ppuwrite(ppufile);
  198. ppufile.putderef(symtableentryderef);
  199. ppufile.putderef(fprocdefderef);
  200. ppufile.putsmallset(loadnodeflags);
  201. end;
  202. procedure tloadnode.buildderefimpl;
  203. begin
  204. inherited buildderefimpl;
  205. symtableentryderef.build(symtableentry);
  206. fprocdefderef.build(fprocdef);
  207. end;
  208. procedure tloadnode.derefimpl;
  209. begin
  210. inherited derefimpl;
  211. symtableentry:=tsym(symtableentryderef.resolve);
  212. symtable:=symtableentry.owner;
  213. fprocdef:=tprocdef(fprocdefderef.resolve);
  214. end;
  215. procedure tloadnode.set_mp(p:tnode);
  216. begin
  217. { typen nodes should not be set }
  218. if p.nodetype=typen then
  219. internalerror(200301042);
  220. left:=p;
  221. end;
  222. function tloadnode.dogetcopy : tnode;
  223. var
  224. n : tloadnode;
  225. begin
  226. n:=tloadnode(inherited dogetcopy);
  227. n.symtable:=symtable;
  228. n.symtableentry:=symtableentry;
  229. n.fprocdef:=fprocdef;
  230. result:=n;
  231. end;
  232. function tloadnode.is_addr_param_load:boolean;
  233. begin
  234. result:=(symtable.symtabletype=parasymtable) and
  235. (symtableentry.typ=paravarsym) and
  236. not(vo_has_local_copy in tparavarsym(symtableentry).varoptions) and
  237. not(loadnf_load_self_pointer in loadnodeflags) and
  238. paramanager.push_addr_param(tparavarsym(symtableentry).varspez,tparavarsym(symtableentry).vardef,tprocdef(symtable.defowner).proccalloption);
  239. end;
  240. function tloadnode.pass_typecheck:tnode;
  241. begin
  242. result:=nil;
  243. case symtableentry.typ of
  244. absolutevarsym :
  245. resultdef:=tabsolutevarsym(symtableentry).vardef;
  246. constsym:
  247. begin
  248. if tconstsym(symtableentry).consttyp=constresourcestring then
  249. resultdef:=getansistringdef
  250. else
  251. internalerror(22799);
  252. end;
  253. staticvarsym :
  254. begin
  255. tabstractvarsym(symtableentry).IncRefCountBy(1);
  256. { static variables referenced in procedures or from finalization,
  257. variable needs to be in memory.
  258. It is too hard and the benefit is too small to detect whether a
  259. variable is only used in the finalization to add support for it (PFV) }
  260. if assigned(current_procinfo) and
  261. (symtable.symtabletype=staticsymtable) and
  262. (
  263. (symtable.symtablelevel<>current_procinfo.procdef.localst.symtablelevel) or
  264. (current_procinfo.procdef.proctypeoption=potype_unitfinalize)
  265. ) then
  266. make_not_regable(self,[ra_addr_taken]);
  267. resultdef:=tabstractvarsym(symtableentry).vardef;
  268. if vo_is_thread_var in tstaticvarsym(symtableentry).varoptions then
  269. result:=handle_threadvar_access;
  270. end;
  271. paravarsym,
  272. localvarsym :
  273. begin
  274. tabstractvarsym(symtableentry).IncRefCountBy(1);
  275. { Nested variable? The we need to load the framepointer of
  276. the parent procedure }
  277. if assigned(current_procinfo) and
  278. (symtable.symtabletype in [localsymtable,parasymtable]) and
  279. (symtable.symtablelevel<>current_procinfo.procdef.parast.symtablelevel) then
  280. begin
  281. if assigned(left) then
  282. internalerror(200309289);
  283. left:=cloadparentfpnode.create(tprocdef(symtable.defowner),lpf_forload);
  284. { we can't inline the referenced parent procedure }
  285. exclude(tprocdef(symtable.defowner).procoptions,po_inline);
  286. { reference in nested procedures, variable needs to be in memory }
  287. { and behaves as if its address escapes its parent block }
  288. make_not_regable(self,[ra_addr_taken]);
  289. end;
  290. resultdef:=tabstractvarsym(symtableentry).vardef;
  291. { self for objects is passed as var-parameter on the caller
  292. side, but on the callee-side we use it as a pointer ->
  293. adjust }
  294. if (vo_is_self in tabstractvarsym(symtableentry).varoptions) then
  295. begin
  296. if (is_object(resultdef) or is_record(resultdef)) and
  297. (loadnf_load_self_pointer in loadnodeflags) then
  298. resultdef:=cpointerdef.getreusable(resultdef)
  299. else if (resultdef=objc_idtype) and
  300. (po_classmethod in tprocdef(symtableentry.owner.defowner).procoptions) then
  301. resultdef:=cclassrefdef.create(tprocdef(symtableentry.owner.defowner).struct)
  302. end
  303. end;
  304. procsym :
  305. begin
  306. { Return the first procdef. In case of overloaded
  307. procdefs the matching procdef will be choosen
  308. when the expected procvardef is known, see get_information
  309. in htypechk.pas (PFV) }
  310. if not assigned(fprocdef) then
  311. fprocdef:=tprocdef(tprocsym(symtableentry).ProcdefList[0])
  312. else if po_kylixlocal in fprocdef.procoptions then
  313. CGMessage(type_e_cant_take_address_of_local_subroutine);
  314. { the result is a fprocdef, addrn and proc_to_procvar
  315. typeconvn need this as resultdef so they know
  316. that the address needs to be returned }
  317. resultdef:=fprocdef;
  318. { process methodpointer/framepointer }
  319. if assigned(left) then
  320. begin
  321. typecheckpass(left);
  322. if (po_classmethod in fprocdef.procoptions) and
  323. is_class(left.resultdef) and
  324. (left.nodetype<>niln) then
  325. begin
  326. left:=cloadvmtaddrnode.create(left);
  327. typecheckpass(left);
  328. end
  329. end;
  330. end;
  331. labelsym:
  332. begin
  333. tlabelsym(symtableentry).used:=true;
  334. resultdef:=voidtype;
  335. end;
  336. else
  337. internalerror(200104141);
  338. end;
  339. end;
  340. procedure Tloadnode.mark_write;
  341. begin
  342. include(flags,nf_write);
  343. end;
  344. function tloadnode.pass_1 : tnode;
  345. begin
  346. result:=nil;
  347. expectloc:=LOC_REFERENCE;
  348. if (cs_create_pic in current_settings.moduleswitches) and
  349. not(symtableentry.typ in [paravarsym,localvarsym]) then
  350. include(current_procinfo.flags,pi_needs_got);
  351. case symtableentry.typ of
  352. absolutevarsym :
  353. ;
  354. constsym:
  355. begin
  356. if tconstsym(symtableentry).consttyp=constresourcestring then
  357. expectloc:=LOC_CREFERENCE;
  358. end;
  359. staticvarsym,
  360. localvarsym,
  361. paravarsym :
  362. begin
  363. if assigned(left) then
  364. firstpass(left);
  365. if not is_addr_param_load and
  366. tabstractvarsym(symtableentry).is_regvar(is_addr_param_load) then
  367. expectloc:=tvarregable2tcgloc[tabstractvarsym(symtableentry).varregable]
  368. else
  369. if (tabstractvarsym(symtableentry).varspez=vs_const) then
  370. expectloc:=LOC_CREFERENCE;
  371. if (target_info.system=system_powerpc_darwin) and
  372. ([vo_is_dll_var,vo_is_external] * tabstractvarsym(symtableentry).varoptions <> []) then
  373. include(current_procinfo.flags,pi_needs_got);
  374. { call to get address of threadvar }
  375. if (vo_is_thread_var in tabstractvarsym(symtableentry).varoptions) then
  376. include(current_procinfo.flags,pi_do_call);
  377. end;
  378. procsym :
  379. begin
  380. { initialise left for nested procs if necessary }
  381. if (m_nested_procvars in current_settings.modeswitches) then
  382. setprocdef(fprocdef);
  383. { method pointer or nested proc ? }
  384. if assigned(left) then
  385. begin
  386. expectloc:=LOC_CREGISTER;
  387. firstpass(left);
  388. end;
  389. end;
  390. labelsym :
  391. begin
  392. if not assigned(tlabelsym(symtableentry).asmblocklabel) and
  393. not assigned(tlabelsym(symtableentry).code) then
  394. Message(parser_e_label_outside_proc);
  395. end
  396. else
  397. internalerror(200104143);
  398. end;
  399. end;
  400. function tloadnode.docompare(p: tnode): boolean;
  401. begin
  402. docompare :=
  403. inherited docompare(p) and
  404. (symtableentry = tloadnode(p).symtableentry) and
  405. (fprocdef = tloadnode(p).fprocdef) and
  406. (symtable = tloadnode(p).symtable);
  407. end;
  408. procedure tloadnode.printnodedata(var t:text);
  409. begin
  410. inherited printnodedata(t);
  411. write(t,printnodeindention,'symbol = ',symtableentry.name);
  412. if symtableentry.typ=procsym then
  413. write(t,printnodeindention,'procdef = ',fprocdef.mangledname);
  414. writeln(t,'');
  415. end;
  416. procedure tloadnode.setprocdef(p : tprocdef);
  417. begin
  418. fprocdef:=p;
  419. resultdef:=p;
  420. { nested procedure? }
  421. if assigned(p) and
  422. is_nested_pd(p) then
  423. begin
  424. if not(m_nested_procvars in current_settings.modeswitches) then
  425. CGMessage(type_e_cant_take_address_of_local_subroutine)
  426. else
  427. begin
  428. { parent frame pointer pointer as "self" }
  429. left.free;
  430. left:=cloadparentfpnode.create(tprocdef(p.owner.defowner),lpf_forpara);
  431. end;
  432. end
  433. { we should never go from nested to non-nested }
  434. else if assigned(left) and
  435. (left.nodetype=loadparentfpn) then
  436. internalerror(2010072201);
  437. end;
  438. {*****************************************************************************
  439. TASSIGNMENTNODE
  440. *****************************************************************************}
  441. function tassignmentnode.direct_shortstring_assignment: boolean;
  442. begin
  443. result:=
  444. is_char(right.resultdef) or
  445. (right.resultdef.typ=stringdef);
  446. end;
  447. constructor tassignmentnode.create(l,r : tnode);
  448. begin
  449. inherited create(assignn,l,r);
  450. l.mark_write;
  451. assigntype:=at_normal;
  452. if r.nodetype = typeconvn then
  453. ttypeconvnode(r).warn_pointer_to_signed:=false;
  454. end;
  455. constructor tassignmentnode.create_internal(l, r: tnode);
  456. begin
  457. create(l,r);
  458. include(flags,nf_internal);
  459. end;
  460. constructor tassignmentnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  461. begin
  462. inherited ppuload(t,ppufile);
  463. assigntype:=tassigntype(ppufile.getbyte);
  464. end;
  465. procedure tassignmentnode.ppuwrite(ppufile:tcompilerppufile);
  466. begin
  467. inherited ppuwrite(ppufile);
  468. ppufile.putbyte(byte(assigntype));
  469. end;
  470. function tassignmentnode.dogetcopy : tnode;
  471. var
  472. n : tassignmentnode;
  473. begin
  474. n:=tassignmentnode(inherited dogetcopy);
  475. n.assigntype:=assigntype;
  476. result:=n;
  477. end;
  478. function tassignmentnode.simplify(forinline : boolean) : tnode;
  479. begin
  480. result:=nil;
  481. { assignment nodes can perform several floating point }
  482. { type conversions directly, so no typeconversions }
  483. { are inserted in those cases. When inlining, a }
  484. { variable may be replaced by a constant which can be }
  485. { converted at compile time, so check for this case }
  486. if is_real(left.resultdef) and
  487. is_real(right.resultdef) and
  488. is_constrealnode(right) and
  489. not equal_defs(right.resultdef,left.resultdef) then
  490. inserttypeconv(right,left.resultdef);
  491. { replace i:=succ/pred(i) by inc/dec(i)? }
  492. if (right.nodetype=inlinen) and
  493. ((tinlinenode(right).inlinenumber=in_succ_x) or (tinlinenode(right).inlinenumber=in_pred_x)) and
  494. (tinlinenode(right).left.isequal(left)) and
  495. ((localswitches*[cs_check_overflow,cs_check_range])=[]) and
  496. ((right.localswitches*[cs_check_overflow,cs_check_range])=[]) and
  497. valid_for_var(tinlinenode(right).left,false) and
  498. not(might_have_sideeffects(tinlinenode(right).left)) then
  499. begin
  500. if tinlinenode(right).inlinenumber=in_succ_x then
  501. result:=cinlinenode.create(
  502. in_inc_x,false,ccallparanode.create(
  503. left.getcopy,nil))
  504. else
  505. result:=cinlinenode.createintern(
  506. in_dec_x,false,ccallparanode.create(
  507. left.getcopy,nil));
  508. exit;
  509. end;
  510. end;
  511. function tassignmentnode.pass_typecheck:tnode;
  512. var
  513. hp : tnode;
  514. useshelper : boolean;
  515. oldassignmentnode : tassignmentnode;
  516. begin
  517. result:=nil;
  518. resultdef:=voidtype;
  519. { must be made unique }
  520. set_unique(left);
  521. typecheckpass(left);
  522. { PI. This is needed to return correct resultdef of add nodes for ansistrings
  523. rawbytestring return needs to be replaced by left.resultdef }
  524. oldassignmentnode:=aktassignmentnode;
  525. aktassignmentnode:=self;
  526. typecheckpass(right);
  527. aktassignmentnode:=oldassignmentnode;
  528. set_varstate(right,vs_read,[vsf_must_be_valid]);
  529. set_varstate(left,vs_written,[]);
  530. if codegenerror then
  531. exit;
  532. { tp procvar support, when we don't expect a procvar
  533. then we need to call the procvar }
  534. if (left.resultdef.typ<>procvardef) then
  535. maybe_call_procvar(right,true);
  536. { assignments to formaldefs and open arrays aren't allowed }
  537. if is_open_array(left.resultdef) then
  538. CGMessage(type_e_assignment_not_allowed)
  539. else if (left.resultdef.typ=formaldef) then
  540. if not(target_info.system in systems_managed_vm) then
  541. CGMessage(type_e_assignment_not_allowed)
  542. else
  543. begin
  544. { on managed platforms, assigning to formaldefs is allowed (but
  545. typecasting them on the left hand side isn't), but primitive
  546. values need to be boxed first }
  547. if (right.resultdef.typ in [orddef,floatdef]) then
  548. begin
  549. right:=cinlinenode.create(in_box_x,false,ccallparanode.create(right,nil));
  550. typecheckpass(right);
  551. end;
  552. end;
  553. { test if node can be assigned, properties are allowed }
  554. if not(nf_internal in flags) then
  555. if not valid_for_assignment(left,true) then
  556. { errors can in situations that cause the compiler to run out of
  557. memory, such as assigning to an implicit pointer-to-array
  558. converted node (that array is 2^31 or 2^63 bytes large) }
  559. exit;
  560. { assigning nil to a dynamic array clears the array }
  561. if is_dynamic_array(left.resultdef) and
  562. (right.nodetype=niln) 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. end;
  882. function tarrayconstructornode.dogetcopy : tnode;
  883. var
  884. n : tarrayconstructornode;
  885. begin
  886. n:=tarrayconstructornode(inherited dogetcopy);
  887. result:=n;
  888. end;
  889. function tarrayconstructornode.pass_typecheck:tnode;
  890. var
  891. hdef : tdef;
  892. hp : tarrayconstructornode;
  893. len : longint;
  894. varia : boolean;
  895. eq : tequaltype;
  896. hnodetype : tnodetype;
  897. begin
  898. result:=nil;
  899. { are we allowing array constructor? Then convert it to a set.
  900. Do this only if we didn't convert the arrayconstructor yet. This
  901. is needed for the cases where the resultdef is forced for a second
  902. run }
  903. if not(allow_array_constructor) then
  904. begin
  905. hp:=tarrayconstructornode(getcopy);
  906. arrayconstructor_to_set(tnode(hp));
  907. result:=hp;
  908. exit;
  909. end;
  910. { only pass left tree, right tree contains next construct if any }
  911. hdef:=nil;
  912. hnodetype:=errorn;
  913. len:=0;
  914. varia:=false;
  915. if assigned(left) then
  916. begin
  917. hp:=self;
  918. while assigned(hp) do
  919. begin
  920. typecheckpass(hp.left);
  921. set_varstate(hp.left,vs_read,[vsf_must_be_valid]);
  922. if (hdef=nil) then
  923. begin
  924. hdef:=hp.left.resultdef;
  925. hnodetype:=hp.left.nodetype;
  926. end
  927. else
  928. begin
  929. { If we got a niln we don't know the type yet and need to take the
  930. type of the next array element.
  931. This is to handle things like [nil,tclass,tclass], see also tw8371 (PFV) }
  932. if hnodetype=niln then
  933. begin
  934. eq:=compare_defs(hp.left.resultdef,hdef,hnodetype);
  935. if eq>te_incompatible then
  936. begin
  937. hdef:=hp.left.resultdef;
  938. hnodetype:=hp.left.nodetype;
  939. end;
  940. end
  941. else
  942. eq:=compare_defs(hdef,hp.left.resultdef,hp.left.nodetype);
  943. if (not varia) and (eq<te_equal) then
  944. begin
  945. { If both are integers we need to take the type that can hold both
  946. defs }
  947. if is_integer(hdef) and is_integer(hp.left.resultdef) then
  948. begin
  949. if is_in_limit(hdef,hp.left.resultdef) then
  950. hdef:=hp.left.resultdef;
  951. end
  952. else
  953. if (nf_novariaallowed in flags) then
  954. varia:=true;
  955. end;
  956. end;
  957. inc(len);
  958. hp:=tarrayconstructornode(hp.right);
  959. end;
  960. end;
  961. { Set the type of empty or varia arrays to void. Also
  962. do this if the type is array of const/open array
  963. because those can't be used with setelementdef }
  964. if not assigned(hdef) or
  965. varia or
  966. is_array_of_const(hdef) or
  967. is_open_array(hdef) then
  968. hdef:=voidtype;
  969. resultdef:=carraydef.create(0,len-1,s32inttype);
  970. tarraydef(resultdef).elementdef:=hdef;
  971. include(tarraydef(resultdef).arrayoptions,ado_IsConstructor);
  972. if varia then
  973. include(tarraydef(resultdef).arrayoptions,ado_IsVariant);
  974. end;
  975. procedure tarrayconstructornode.force_type(def:tdef);
  976. var
  977. hp : tarrayconstructornode;
  978. begin
  979. tarraydef(resultdef).elementdef:=def;
  980. include(tarraydef(resultdef).arrayoptions,ado_IsConstructor);
  981. exclude(tarraydef(resultdef).arrayoptions,ado_IsVariant);
  982. if assigned(left) then
  983. begin
  984. hp:=self;
  985. while assigned(hp) do
  986. begin
  987. inserttypeconv(hp.left,def);
  988. hp:=tarrayconstructornode(hp.right);
  989. end;
  990. end;
  991. end;
  992. procedure tarrayconstructornode.insert_typeconvs;
  993. var
  994. hp : tarrayconstructornode;
  995. dovariant : boolean;
  996. begin
  997. dovariant:=(nf_forcevaria in flags) or (ado_isvariant in tarraydef(resultdef).arrayoptions);
  998. { only pass left tree, right tree contains next construct if any }
  999. if assigned(left) then
  1000. begin
  1001. hp:=self;
  1002. while assigned(hp) do
  1003. begin
  1004. typecheckpass(hp.left);
  1005. { Insert typeconvs for array of const }
  1006. if dovariant then
  1007. { at this time C varargs are no longer an arrayconstructornode }
  1008. insert_varargstypeconv(hp.left,false);
  1009. hp:=tarrayconstructornode(hp.right);
  1010. end;
  1011. end;
  1012. end;
  1013. function tarrayconstructornode.pass_1 : tnode;
  1014. var
  1015. hp : tarrayconstructornode;
  1016. do_variant,
  1017. do_managed_variant:boolean;
  1018. begin
  1019. do_variant:=(nf_forcevaria in flags) or (ado_isvariant in tarraydef(resultdef).arrayoptions);
  1020. do_managed_variant:=
  1021. do_variant and
  1022. (target_info.system in systems_managed_vm);
  1023. result:=nil;
  1024. { Insert required type convs, this must be
  1025. done in pass 1, because the call must be
  1026. typecheckpassed already }
  1027. if assigned(left) then
  1028. begin
  1029. insert_typeconvs;
  1030. { call firstpass for all nodes }
  1031. hp:=self;
  1032. while assigned(hp) do
  1033. begin
  1034. if hp.left<>nil then
  1035. begin
  1036. {This check is pessimistic; a call will happen depending
  1037. on the location in which the elements will be found in
  1038. pass 2.}
  1039. if not do_variant then
  1040. include(current_procinfo.flags,pi_do_call);
  1041. firstpass(hp.left);
  1042. if do_managed_variant then
  1043. wrapmanagedvarrec(hp.left);
  1044. end;
  1045. hp:=tarrayconstructornode(hp.right);
  1046. end;
  1047. end;
  1048. { set the elementdef to the correct type in case of a variant array }
  1049. if do_variant then
  1050. tarraydef(resultdef).elementdef:=search_system_type('TVARREC').typedef;
  1051. expectloc:=LOC_CREFERENCE;
  1052. end;
  1053. function tarrayconstructornode.docompare(p: tnode): boolean;
  1054. begin
  1055. docompare:=inherited docompare(p);
  1056. end;
  1057. {*****************************************************************************
  1058. TTYPENODE
  1059. *****************************************************************************}
  1060. constructor ttypenode.create(def:tdef);
  1061. begin
  1062. inherited create(typen);
  1063. typedef:=def;
  1064. typesym:=def.typesym;
  1065. allowed:=false;
  1066. helperallowed:=false;
  1067. end;
  1068. constructor ttypenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1069. begin
  1070. inherited ppuload(t,ppufile);
  1071. ppufile.getderef(typedefderef);
  1072. ppufile.getderef(typesymderef);
  1073. allowed:=boolean(ppufile.getbyte);
  1074. helperallowed:=boolean(ppufile.getbyte);
  1075. end;
  1076. procedure ttypenode.ppuwrite(ppufile:tcompilerppufile);
  1077. begin
  1078. inherited ppuwrite(ppufile);
  1079. ppufile.putderef(typedefderef);
  1080. ppufile.putderef(typesymderef);
  1081. ppufile.putbyte(byte(allowed));
  1082. ppufile.putbyte(byte(helperallowed));
  1083. end;
  1084. procedure ttypenode.buildderefimpl;
  1085. begin
  1086. inherited buildderefimpl;
  1087. typedefderef.build(typedef);
  1088. typesymderef.build(typesym);
  1089. end;
  1090. procedure ttypenode.derefimpl;
  1091. begin
  1092. inherited derefimpl;
  1093. typedef:=tdef(typedefderef.resolve);
  1094. typesym:=tsym(typesymderef.resolve);
  1095. end;
  1096. function ttypenode.pass_typecheck:tnode;
  1097. begin
  1098. result:=nil;
  1099. resultdef:=typedef;
  1100. { check if it's valid }
  1101. if typedef.typ = errordef then
  1102. CGMessage(parser_e_illegal_expression);
  1103. end;
  1104. function ttypenode.pass_1 : tnode;
  1105. begin
  1106. result:=nil;
  1107. expectloc:=LOC_VOID;
  1108. { a typenode can't generate code, so we give here
  1109. an error. Else it'll be an abstract error in pass_generate_code.
  1110. Only when the allowed flag is set we don't generate
  1111. an error }
  1112. if not allowed then
  1113. CGMessage(parser_e_no_type_not_allowed_here);
  1114. if not helperallowed and is_objectpascal_helper(typedef) then
  1115. CGMessage(parser_e_no_category_as_types);
  1116. end;
  1117. function ttypenode.dogetcopy : tnode;
  1118. var
  1119. n : ttypenode;
  1120. begin
  1121. n:=ttypenode(inherited dogetcopy);
  1122. n.allowed:=allowed;
  1123. n.typedef:=typedef;
  1124. n.helperallowed:=helperallowed;
  1125. result:=n;
  1126. end;
  1127. function ttypenode.docompare(p: tnode): boolean;
  1128. begin
  1129. docompare :=
  1130. inherited docompare(p) and
  1131. (typedef=ttypenode(p).typedef) and
  1132. (allowed=ttypenode(p).allowed) and
  1133. (helperallowed=ttypenode(p).helperallowed);
  1134. end;
  1135. {*****************************************************************************
  1136. TRTTINODE
  1137. *****************************************************************************}
  1138. constructor trttinode.create(def:tstoreddef;rt:trttitype;dt:Trttidatatype);
  1139. begin
  1140. inherited create(rttin);
  1141. rttidef:=def;
  1142. rttitype:=rt;
  1143. rttidatatype:=dt;
  1144. end;
  1145. constructor trttinode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1146. begin
  1147. inherited ppuload(t,ppufile);
  1148. ppufile.getderef(rttidefderef);
  1149. rttitype:=trttitype(ppufile.getbyte);
  1150. rttidatatype:=trttidatatype(ppufile.getbyte);
  1151. end;
  1152. procedure trttinode.ppuwrite(ppufile:tcompilerppufile);
  1153. begin
  1154. inherited ppuwrite(ppufile);
  1155. ppufile.putderef(rttidefderef);
  1156. ppufile.putbyte(byte(rttitype));
  1157. ppufile.putbyte(byte(rttidatatype));
  1158. end;
  1159. procedure trttinode.buildderefimpl;
  1160. begin
  1161. inherited buildderefimpl;
  1162. rttidefderef.build(rttidef);
  1163. end;
  1164. procedure trttinode.derefimpl;
  1165. begin
  1166. inherited derefimpl;
  1167. rttidef:=tstoreddef(rttidefderef.resolve);
  1168. end;
  1169. function trttinode.dogetcopy : tnode;
  1170. var
  1171. n : trttinode;
  1172. begin
  1173. n:=trttinode(inherited dogetcopy);
  1174. n.rttidef:=rttidef;
  1175. n.rttitype:=rttitype;
  1176. n.rttidatatype:=rttidatatype;
  1177. result:=n;
  1178. end;
  1179. function trttinode.pass_typecheck:tnode;
  1180. begin
  1181. { rtti information will be returned as a void pointer }
  1182. result:=nil;
  1183. resultdef:=voidpointertype;
  1184. end;
  1185. function trttinode.pass_1 : tnode;
  1186. begin
  1187. result:=nil;
  1188. expectloc:=LOC_CREFERENCE;
  1189. if (cs_create_pic in current_settings.moduleswitches) and
  1190. (tf_pic_uses_got in target_info.flags) then
  1191. include(current_procinfo.flags,pi_needs_got);
  1192. end;
  1193. function trttinode.docompare(p: tnode): boolean;
  1194. begin
  1195. docompare :=
  1196. inherited docompare(p) and
  1197. (rttidef = trttinode(p).rttidef) and
  1198. (rttitype = trttinode(p).rttitype) and
  1199. (rttidatatype = trttinode(p).rttidatatype);
  1200. end;
  1201. end.