nld.pas 49 KB

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