nld.pas 48 KB

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