nld.pas 49 KB

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