nld.pas 49 KB

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