nld.pas 49 KB

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