2
0

nld.pas 49 KB

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