ncgrtti.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Routines for the code generation of RTTI data structures
  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 ncgrtti;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,constexp,
  22. aasmbase,aasmcnst,
  23. symbase,symconst,symtype,symdef,symsym;
  24. type
  25. { TRTTIWriter }
  26. TRTTIWriter=class
  27. private
  28. { required internal alignment of the rtti data }
  29. reqalign: shortint;
  30. { required packing of all structures except for ttypeinfo and tpropinfo,
  31. which always use packrecords 1 }
  32. defaultpacking: shortint;
  33. procedure fields_write_rtti(st:tsymtable;rt:trttitype);
  34. procedure params_write_rtti(def:tabstractprocdef;rt:trttitype);
  35. procedure fields_write_rtti_data(tcb: ttai_typedconstbuilder; def: tabstractrecorddef; rt: trttitype);
  36. procedure write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  37. procedure published_write_rtti(st:tsymtable;rt:trttitype);
  38. function published_properties_count(st:tsymtable):longint;
  39. procedure published_properties_write_rtti_data(tcb: ttai_typedconstbuilder; propnamelist: TFPHashObjectList; st: tsymtable);
  40. procedure write_param_flag(tcb: ttai_typedconstbuilder; parasym:tparavarsym);
  41. procedure methods_write_rtti(tcb: ttai_typedconstbuilder; st:tsymtable);
  42. procedure collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  43. function ref_rtti(def:tdef;rt:trttitype):tasmsymbol;
  44. procedure write_rtti_name(tcb: ttai_typedconstbuilder; def: tdef);
  45. procedure write_rtti_data(tcb: ttai_typedconstbuilder; def:tdef; rt: trttitype);
  46. procedure write_child_rtti_data(def:tdef;rt:trttitype);
  47. procedure write_rtti_reference(tcb: ttai_typedconstbuilder; def: tdef; rt: trttitype);
  48. procedure write_header(tcb: ttai_typedconstbuilder; def: tdef; typekind: byte);
  49. public
  50. constructor create;
  51. procedure write_rtti(def:tdef;rt:trttitype);
  52. function get_rtti_label(def:tdef;rt:trttitype):tasmsymbol;
  53. function get_rtti_label_ord2str(def:tdef;rt:trttitype):tasmsymbol;
  54. function get_rtti_label_str2ord(def:tdef;rt:trttitype):tasmsymbol;
  55. end;
  56. { generate RTTI and init tables }
  57. procedure write_persistent_type_info(st:tsymtable;is_global:boolean);
  58. var
  59. RTTIWriter : TRTTIWriter;
  60. implementation
  61. uses
  62. cutils,
  63. globals,globtype,verbose,systems,
  64. fmodule, procinfo,
  65. symtable,
  66. aasmtai,aasmdata,
  67. defutil,
  68. wpobase,
  69. paramgr
  70. ;
  71. const
  72. rttidefstate : array[trttitype] of tdefstate =
  73. (ds_rtti_table_written,ds_init_table_written,
  74. { Objective-C related, does not pass here }
  75. symconst.ds_none,symconst.ds_none,
  76. symconst.ds_none,symconst.ds_none);
  77. ProcCallOptionToCallConv: array[tproccalloption] of byte = (
  78. { pocall_none } 0,
  79. { pocall_cdecl } 1,
  80. { pocall_cppdecl } 5,
  81. { pocall_far16 } 6,
  82. { pocall_oldfpccall } 7,
  83. { pocall_internproc } 8,
  84. { pocall_syscall } 9,
  85. { pocall_pascal } 2,
  86. { pocall_register } 0,
  87. { pocall_safecall } 4,
  88. { pocall_stdcall } 3,
  89. { pocall_softfloat } 10,
  90. { pocall_mwpascal } 11,
  91. { pocall_interrupt } 12,
  92. { pocall_hardfloat } 13
  93. );
  94. type
  95. TPropNameListItem = class(TFPHashObject)
  96. propindex : longint;
  97. propowner : TSymtable;
  98. end;
  99. procedure write_persistent_type_info(st: tsymtable; is_global: boolean);
  100. var
  101. i : longint;
  102. def : tdef;
  103. begin
  104. { no Delphi-style RTTI for managed platforms }
  105. if target_info.system in systems_managed_vm then
  106. exit;
  107. for i:=0 to st.DefList.Count-1 do
  108. begin
  109. def:=tdef(st.DefList[i]);
  110. { skip generics }
  111. if [df_generic,df_genconstraint]*def.defoptions<>[] then
  112. continue;
  113. case def.typ of
  114. recorddef:
  115. write_persistent_type_info(trecorddef(def).symtable,is_global);
  116. objectdef :
  117. begin
  118. { Skip forward defs }
  119. if (oo_is_forward in tobjectdef(def).objectoptions) then
  120. continue;
  121. write_persistent_type_info(tobjectdef(def).symtable,is_global);
  122. end;
  123. procdef :
  124. begin
  125. if assigned(tprocdef(def).localst) and
  126. (tprocdef(def).localst.symtabletype=localsymtable) then
  127. write_persistent_type_info(tprocdef(def).localst,false);
  128. if assigned(tprocdef(def).parast) then
  129. write_persistent_type_info(tprocdef(def).parast,false);
  130. end;
  131. end;
  132. { always generate persistent tables for types in the interface so
  133. they can be reused in other units and give always the same pointer
  134. location. }
  135. { Init }
  136. if (
  137. assigned(def.typesym) and
  138. is_global and
  139. not is_objc_class_or_protocol(def)
  140. ) or
  141. is_managed_type(def) or
  142. (ds_init_table_used in def.defstates) then
  143. RTTIWriter.write_rtti(def,initrtti);
  144. { RTTI }
  145. if (
  146. assigned(def.typesym) and
  147. is_global and
  148. not is_objc_class_or_protocol(def)
  149. ) or
  150. (ds_rtti_table_used in def.defstates) then
  151. RTTIWriter.write_rtti(def,fullrtti);
  152. end;
  153. end;
  154. {***************************************************************************
  155. TRTTIWriter
  156. ***************************************************************************}
  157. procedure TRTTIWriter.write_header(tcb: ttai_typedconstbuilder; def: tdef; typekind: byte);
  158. var
  159. name: shortstring;
  160. begin
  161. if assigned(def.typesym) then
  162. name:=ttypesym(def.typesym).realname
  163. else
  164. name:='';
  165. { TTypeInfo, always packed and doesn't need alignment }
  166. tcb.begin_anonymous_record(
  167. internaltypeprefixName[itp_rtti_header]+tostr(length(name)),1,1,
  168. targetinfos[target_info.system]^.alignment.recordalignmin,
  169. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  170. if def.typ=arraydef then
  171. InternalError(201012211);
  172. tcb.emit_tai(Tai_const.Create_8bit(typekind),u8inttype);
  173. tcb.emit_shortstring_const(name);
  174. tcb.end_anonymous_record;
  175. end;
  176. procedure TRTTIWriter.write_rtti_name(tcb: ttai_typedconstbuilder; def: tdef);
  177. begin
  178. if is_open_array(def) then
  179. { open arrays never have a typesym with a name, since you cannot
  180. define an "open array type". Kylix prints the type of the
  181. elements in the array in this case (so together with the pfArray
  182. flag, you can reconstruct the full typename, I assume (JM))
  183. }
  184. def:=tarraydef(def).elementdef;
  185. { name }
  186. if assigned(def.typesym) then
  187. tcb.emit_shortstring_const(ttypesym(def.typesym).realname)
  188. else
  189. tcb.emit_shortstring_const('');
  190. end;
  191. { writes a 32-bit count followed by array of field infos for given symtable }
  192. procedure TRTTIWriter.fields_write_rtti_data(tcb: ttai_typedconstbuilder; def: tabstractrecorddef; rt: trttitype);
  193. var
  194. i : longint;
  195. sym : tsym;
  196. fieldcnt: longint;
  197. st: tsymtable;
  198. fields: tfplist;
  199. parentrtti: boolean;
  200. begin
  201. fieldcnt:=0;
  202. parentrtti:=false;
  203. st:=def.symtable;
  204. fields:=tfplist.create;
  205. fields.capacity:=st.symlist.count+1;
  206. { For objects, treat parent (if any) as a field with offset 0. This
  207. provides correct handling of entire instance with RTL rtti routines. }
  208. if (def.typ=objectdef) and (tobjectdef(def).objecttype=odt_object) and
  209. Assigned(tobjectdef(def).childof) and
  210. ((rt=fullrtti) or (tobjectdef(def).childof.needs_inittable)) then
  211. begin
  212. parentrtti:=true;
  213. inc(fieldcnt);
  214. end;
  215. for i:=0 to st.SymList.Count-1 do
  216. begin
  217. sym:=tsym(st.SymList[i]);
  218. if (tsym(sym).typ=fieldvarsym) and
  219. not(sp_static in tsym(sym).symoptions) and
  220. (
  221. (rt=fullrtti) or
  222. tfieldvarsym(sym).vardef.needs_inittable
  223. ) and
  224. not is_objc_class_or_protocol(tfieldvarsym(sym).vardef) then
  225. begin
  226. fields.add(tfieldvarsym(sym));
  227. inc(fieldcnt);
  228. end;
  229. end;
  230. { insert field count before data }
  231. tcb.emit_ord_const(fieldcnt,u32inttype);
  232. { parent object? }
  233. if parentrtti then
  234. begin
  235. write_rtti_reference(tcb,tobjectdef(def).childof,rt);
  236. tcb.emit_ord_const(0,ptruinttype);
  237. end;
  238. { fields }
  239. for i:=0 to fields.count-1 do
  240. begin
  241. sym:=tsym(fields[i]);
  242. write_rtti_reference(tcb,tfieldvarsym(sym).vardef,rt);
  243. tcb.emit_ord_const(tfieldvarsym(sym).fieldoffset,ptruinttype);
  244. end;
  245. fields.free;
  246. end;
  247. procedure TRTTIWriter.fields_write_rtti(st:tsymtable;rt:trttitype);
  248. var
  249. i : longint;
  250. sym : tsym;
  251. begin
  252. for i:=0 to st.SymList.Count-1 do
  253. begin
  254. sym:=tsym(st.SymList[i]);
  255. if (tsym(sym).typ=fieldvarsym) and
  256. not(sp_static in tsym(sym).symoptions) and
  257. (
  258. (rt=fullrtti) or
  259. tfieldvarsym(sym).vardef.needs_inittable
  260. ) then
  261. write_rtti(tfieldvarsym(sym).vardef,rt);
  262. end;
  263. end;
  264. procedure TRTTIWriter.params_write_rtti(def:tabstractprocdef;rt:trttitype);
  265. var
  266. i : longint;
  267. sym : tparavarsym;
  268. begin
  269. for i:=0 to def.paras.count-1 do
  270. begin
  271. sym:=tparavarsym(def.paras[i]);
  272. if not (vo_is_hidden_para in sym.varoptions) then
  273. write_rtti(sym.vardef,rt);
  274. end;
  275. end;
  276. procedure TRTTIWriter.published_write_rtti(st:tsymtable;rt:trttitype);
  277. var
  278. i : longint;
  279. sym : tsym;
  280. begin
  281. for i:=0 to st.SymList.Count-1 do
  282. begin
  283. sym:=tsym(st.SymList[i]);
  284. if (sym.visibility=vis_published) then
  285. begin
  286. case tsym(sym).typ of
  287. propertysym:
  288. write_rtti(tpropertysym(sym).propdef,rt);
  289. fieldvarsym:
  290. write_rtti(tfieldvarsym(sym).vardef,rt);
  291. end;
  292. end;
  293. end;
  294. end;
  295. function TRTTIWriter.published_properties_count(st:tsymtable):longint;
  296. var
  297. i : longint;
  298. sym : tsym;
  299. begin
  300. result:=0;
  301. for i:=0 to st.SymList.Count-1 do
  302. begin
  303. sym:=tsym(st.SymList[i]);
  304. if (tsym(sym).typ=propertysym) and
  305. (sym.visibility=vis_published) then
  306. inc(result);
  307. end;
  308. end;
  309. procedure TRTTIWriter.collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  310. var
  311. i : longint;
  312. sym : tsym;
  313. pn : tpropnamelistitem;
  314. begin
  315. if assigned(objdef.childof) then
  316. collect_propnamelist(propnamelist,objdef.childof);
  317. for i:=0 to objdef.symtable.SymList.Count-1 do
  318. begin
  319. sym:=tsym(objdef.symtable.SymList[i]);
  320. if (tsym(sym).typ=propertysym) and
  321. (sym.visibility=vis_published) then
  322. begin
  323. pn:=TPropNameListItem(propnamelist.Find(tsym(sym).name));
  324. if not assigned(pn) then
  325. begin
  326. pn:=tpropnamelistitem.create(propnamelist,tsym(sym).name);
  327. pn.propindex:=propnamelist.count-1;
  328. pn.propowner:=tsym(sym).owner;
  329. end;
  330. end;
  331. end;
  332. end;
  333. procedure TRTTIWriter.published_properties_write_rtti_data(tcb: ttai_typedconstbuilder; propnamelist:TFPHashObjectList;st:tsymtable);
  334. var
  335. i : longint;
  336. sym : tsym;
  337. proctypesinfo : byte;
  338. propnameitem : tpropnamelistitem;
  339. propdefname : string;
  340. procedure writeaccessproc(pap:tpropaccesslisttypes; shiftvalue : byte; unsetvalue: byte);
  341. var
  342. typvalue : byte;
  343. hp : ppropaccesslistitem;
  344. extnumber: longint;
  345. address,space : longint;
  346. def : tdef;
  347. hpropsym : tpropertysym;
  348. propaccesslist : tpropaccesslist;
  349. begin
  350. hpropsym:=tpropertysym(sym);
  351. repeat
  352. propaccesslist:=hpropsym.propaccesslist[pap];
  353. if not propaccesslist.empty then
  354. break;
  355. hpropsym:=hpropsym.overriddenpropsym;
  356. until not assigned(hpropsym);
  357. if not(assigned(propaccesslist) and assigned(propaccesslist.firstsym)) then
  358. begin
  359. tcb.emit_tai(Tai_const.Create_int_codeptr(unsetvalue),codeptruinttype);
  360. typvalue:=3;
  361. end
  362. else if propaccesslist.firstsym^.sym.typ=fieldvarsym then
  363. begin
  364. address:=0;
  365. hp:=propaccesslist.firstsym;
  366. def:=nil;
  367. while assigned(hp) do
  368. begin
  369. case hp^.sltype of
  370. sl_load :
  371. begin
  372. def:=tfieldvarsym(hp^.sym).vardef;
  373. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  374. end;
  375. sl_subscript :
  376. begin
  377. if not(assigned(def) and
  378. ((def.typ=recorddef) or
  379. is_object(def))) then
  380. internalerror(200402171);
  381. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  382. def:=tfieldvarsym(hp^.sym).vardef;
  383. end;
  384. sl_vec :
  385. begin
  386. if not(assigned(def) and (def.typ=arraydef)) then
  387. internalerror(200402172);
  388. def:=tarraydef(def).elementdef;
  389. {Hp.value is a Tconstexprint, which can be rather large,
  390. sanity check for longint overflow.}
  391. space:=(high(address)-address) div def.size;
  392. if int64(space)<hp^.value then
  393. internalerror(200706101);
  394. inc(address,int64(def.size*hp^.value));
  395. end;
  396. end;
  397. hp:=hp^.next;
  398. end;
  399. tcb.emit_tai(Tai_const.Create_int_codeptr(address),codeptruinttype);
  400. typvalue:=0;
  401. end
  402. else
  403. begin
  404. { When there was an error then procdef is not assigned }
  405. if not assigned(propaccesslist.procdef) then
  406. exit;
  407. if not(po_virtualmethod in tprocdef(propaccesslist.procdef).procoptions) or
  408. is_objectpascal_helper(tprocdef(propaccesslist.procdef).struct) then
  409. begin
  410. tcb.queue_init(codeptruinttype);
  411. tcb.queue_emit_proc(tprocdef(propaccesslist.procdef));
  412. typvalue:=1;
  413. end
  414. else
  415. begin
  416. { virtual method, write vmt offset }
  417. extnumber:=tprocdef(propaccesslist.procdef).extnumber;
  418. tcb.emit_tai(Tai_const.Create_int_codeptr(
  419. tobjectdef(tprocdef(propaccesslist.procdef).struct).vmtmethodoffset(extnumber)),
  420. codeptruinttype);
  421. { register for wpo }
  422. tobjectdef(tprocdef(propaccesslist.procdef).struct).register_vmt_call(extnumber);
  423. {$ifdef vtentry}
  424. { not sure if we can insert those vtentry symbols safely here }
  425. {$error register methods used for published properties}
  426. {$endif vtentry}
  427. typvalue:=2;
  428. end;
  429. end;
  430. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  431. end;
  432. begin
  433. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  434. targetinfos[target_info.system]^.alignment.recordalignmin,
  435. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  436. tcb.emit_ord_const(published_properties_count(st),u16inttype);
  437. for i:=0 to st.SymList.Count-1 do
  438. begin
  439. sym:=tsym(st.SymList[i]);
  440. if (sym.typ=propertysym) and
  441. (sym.visibility=vis_published) then
  442. begin
  443. { we can only easily reuse defs if the property is not stored,
  444. because otherwise the rtti layout depends on how the "stored"
  445. is defined (field, indexed expression, virtual method, ...) }
  446. if not(ppo_stored in tpropertysym(sym).propoptions) then
  447. propdefname:=internaltypeprefixName[itp_rtti_prop]+tostr(length(tpropertysym(sym).realname))
  448. else
  449. propdefname:='';
  450. { TPropInfo is a packed record (even on targets that require
  451. alignment), but it starts aligned }
  452. tcb.begin_anonymous_record(
  453. propdefname,
  454. 1,reqalign,
  455. targetinfos[target_info.system]^.alignment.recordalignmin,
  456. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  457. if ppo_indexed in tpropertysym(sym).propoptions then
  458. proctypesinfo:=$40
  459. else
  460. proctypesinfo:=0;
  461. write_rtti_reference(tcb,tpropertysym(sym).propdef,fullrtti);
  462. writeaccessproc(palt_read,0,0);
  463. writeaccessproc(palt_write,2,0);
  464. { is it stored ? }
  465. if not(ppo_stored in tpropertysym(sym).propoptions) then
  466. begin
  467. { no, so put a constant zero }
  468. tcb.emit_tai(Tai_const.Create_nil_codeptr,codeptruinttype);
  469. proctypesinfo:=proctypesinfo or (3 shl 4);
  470. end
  471. else
  472. writeaccessproc(palt_stored,4,1); { maybe; if no procedure put a constant 1 (=true) }
  473. tcb.emit_ord_const(tpropertysym(sym).index,u32inttype);
  474. tcb.emit_ord_const(tpropertysym(sym).default,u32inttype);
  475. propnameitem:=TPropNameListItem(propnamelist.Find(tpropertysym(sym).name));
  476. if not assigned(propnameitem) then
  477. internalerror(200512201);
  478. tcb.emit_ord_const(propnameitem.propindex,u16inttype);
  479. tcb.emit_ord_const(proctypesinfo,u8inttype);
  480. tcb.emit_shortstring_const(tpropertysym(sym).realname);
  481. tcb.end_anonymous_record;
  482. end;
  483. end;
  484. tcb.end_anonymous_record;
  485. end;
  486. procedure TRTTIWriter.write_param_flag(tcb: ttai_typedconstbuilder; parasym:tparavarsym);
  487. var
  488. paraspec : byte;
  489. begin
  490. case parasym.varspez of
  491. vs_value : paraspec := 0;
  492. vs_const : paraspec := pfConst;
  493. vs_var : paraspec := pfVar;
  494. vs_out : paraspec := pfOut;
  495. vs_constref: paraspec := pfConstRef;
  496. else
  497. internalerror(2013112904);
  498. end;
  499. { Kylix also seems to always add both pfArray and pfReference
  500. in this case
  501. }
  502. if is_open_array(parasym.vardef) then
  503. paraspec:=paraspec or pfArray or pfReference;
  504. { and these for classes and interfaces (maybe because they
  505. are themselves addresses?)
  506. }
  507. if is_class_or_interface(parasym.vardef) then
  508. paraspec:=paraspec or pfAddress;
  509. { set bits run from the highest to the lowest bit on
  510. big endian systems
  511. }
  512. if (target_info.endian = endian_big) then
  513. paraspec:=reverse_byte(paraspec);
  514. { write flags for current parameter }
  515. tcb.emit_ord_const(paraspec,u8inttype);
  516. end;
  517. procedure TRTTIWriter.methods_write_rtti(tcb: ttai_typedconstbuilder; st: tsymtable);
  518. var
  519. count: Word;
  520. i,j,k: LongInt;
  521. sym : tprocsym;
  522. def : tabstractprocdef;
  523. para : tparavarsym;
  524. reg: Byte;
  525. off: LongInt;
  526. begin
  527. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  528. targetinfos[target_info.system]^.alignment.recordalignmin,
  529. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  530. count:=0;
  531. for i:=0 to st.SymList.Count-1 do
  532. if (tsym(st.SymList[i]).typ=procsym) then
  533. inc(count, tprocsym(st.SymList[i]).ProcdefList.count);
  534. tcb.emit_ord_const(count,u16inttype);
  535. tcb.emit_ord_const(count,u16inttype);
  536. for i:=0 to st.SymList.Count-1 do
  537. if (tsym(st.SymList[i]).typ=procsym) then
  538. begin
  539. sym:=tprocsym(st.SymList[i]);
  540. for j:=0 to sym.ProcdefList.count-1 do
  541. begin
  542. def:=tabstractprocdef(sym.ProcdefList[j]);
  543. def.init_paraloc_info(callerside);
  544. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  545. targetinfos[target_info.system]^.alignment.recordalignmin,
  546. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  547. tcb.emit_shortstring_const(sym.realname);
  548. tcb.emit_ord_const(3,u8inttype);
  549. tcb.emit_ord_const(ProcCallOptionToCallConv[def.proccalloption],u8inttype);
  550. write_rtti_reference(tcb,def.returndef,fullrtti);
  551. tcb.emit_ord_const(def.callerargareasize,u16inttype);
  552. tcb.emit_ord_const(def.maxparacount + 1,u8inttype);
  553. for k:=0 to def.paras.count-1 do
  554. begin
  555. para:=tparavarsym(def.paras[k]);
  556. if (vo_is_hidden_para in para.varoptions) and not (vo_is_self in para.varoptions) then
  557. continue;
  558. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  559. targetinfos[target_info.system]^.alignment.recordalignmin,
  560. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  561. { write flags for current parameter }
  562. write_param_flag(tcb, para);
  563. { write param type }
  564. write_rtti_reference(tcb,para.vardef,fullrtti);
  565. paramanager.get_para_regoff(def.proccalloption, para.paraloc[callerside].location,reg,off);
  566. tcb.emit_ord_const(reg,u8inttype);
  567. tcb.emit_ord_const(off,u32inttype);
  568. { write name of current parameter }
  569. tcb.emit_shortstring_const(para.realname);
  570. tcb.end_anonymous_record;
  571. end;
  572. tcb.end_anonymous_record;
  573. end;
  574. end;
  575. tcb.end_anonymous_record;
  576. end;
  577. procedure TRTTIWriter.write_rtti_data(tcb: ttai_typedconstbuilder; def: tdef; rt: trttitype);
  578. procedure unknown_rtti(def:tstoreddef);
  579. begin
  580. tcb.emit_ord_const(tkUnknown,u8inttype);
  581. write_rtti_name(tcb,def);
  582. end;
  583. procedure variantdef_rtti(def:tvariantdef);
  584. begin
  585. write_header(tcb,def,tkVariant);
  586. end;
  587. procedure stringdef_rtti(def:tstringdef);
  588. begin
  589. case def.stringtype of
  590. st_ansistring:
  591. begin
  592. write_header(tcb,def,tkAString);
  593. { align }
  594. tcb.begin_anonymous_record(
  595. internaltypeprefixName[itp_rtti_ansistr],
  596. defaultpacking,reqalign,
  597. targetinfos[target_info.system]^.alignment.recordalignmin,
  598. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  599. tcb.emit_ord_const(def.encoding,u16inttype);
  600. tcb.end_anonymous_record;
  601. end;
  602. st_widestring:
  603. write_header(tcb,def,tkWString);
  604. st_unicodestring:
  605. write_header(tcb,def,tkUString);
  606. st_longstring:
  607. write_header(tcb,def,tkLString);
  608. st_shortstring:
  609. begin
  610. write_header(tcb,def,tkSString);
  611. tcb.emit_ord_const(def.len,u8inttype);
  612. end;
  613. end;
  614. end;
  615. procedure enumdef_rtti(def: tenumdef);
  616. var
  617. i : integer;
  618. hp : tenumsym;
  619. begin
  620. write_header(tcb,def,tkEnumeration);
  621. { align; the named fields are so that we can let the compiler
  622. calculate the string offsets later on }
  623. tcb.next_field_name:='size_start_rec';
  624. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  625. targetinfos[target_info.system]^.alignment.recordalignmin,
  626. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  627. case longint(def.size) of
  628. 1 :
  629. tcb.emit_ord_const(otUByte,u8inttype);
  630. 2 :
  631. tcb.emit_ord_const(otUWord,u8inttype);
  632. 4 :
  633. tcb.emit_ord_const(otULong,u8inttype);
  634. end;
  635. { we need to align by Tconstptruint here to satisfy the alignment
  636. rules set by records: in the typinfo unit we overlay a TTypeData
  637. record on this data, which at the innermost variant record needs an
  638. alignment of TConstPtrUint due to e.g. the "CompType" member for
  639. tkSet (also the "BaseType" member for tkEnumeration).
  640. We need to adhere to this, otherwise things will break. }
  641. tcb.next_field_name:='min_max_rec';
  642. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  643. targetinfos[target_info.system]^.alignment.recordalignmin,
  644. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  645. tcb.emit_ord_const(def.min,s32inttype);
  646. tcb.emit_ord_const(def.max,s32inttype);
  647. tcb.next_field_name:='basetype_array_rec';
  648. { all strings must appear right after each other -> from now on
  649. packrecords 1 (but the start must still be aligned) }
  650. tcb.begin_anonymous_record('',1,reqalign,
  651. targetinfos[target_info.system]^.alignment.recordalignmin,
  652. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  653. { write base type }
  654. write_rtti_reference(tcb,def.basedef,rt);
  655. for i:=0 to def.symtable.SymList.Count-1 do
  656. begin
  657. hp:=tenumsym(def.symtable.SymList[i]);
  658. if hp.value<def.minval then
  659. continue
  660. else
  661. if hp.value>def.maxval then
  662. break;
  663. tcb.next_field_name:=hp.name;
  664. tcb.emit_shortstring_const(hp.realname);
  665. end;
  666. { write unit name }
  667. tcb.emit_shortstring_const(current_module.realmodulename^);
  668. { write zero which is required by RTL }
  669. tcb.emit_ord_const(0,u8inttype);
  670. { terminate all records }
  671. tcb.end_anonymous_record;
  672. tcb.end_anonymous_record;
  673. tcb.end_anonymous_record;
  674. end;
  675. procedure orddef_rtti(def:torddef);
  676. procedure dointeger(typekind: byte);
  677. const
  678. trans : array[tordtype] of byte =
  679. (otUByte{otNone},
  680. otUByte,otUWord,otULong,otUByte{otNone},otUByte{otNone},
  681. otSByte,otSWord,otSLong,otUByte{otNone},otUByte{otNone},
  682. otUByte,otUWord,otULong,otUByte,
  683. otSByte,otSWord,otSLong,otSByte,
  684. otUByte,otUWord,otUByte);
  685. begin
  686. write_header(tcb,def,typekind);
  687. tcb.begin_anonymous_record(
  688. internaltypeprefixName[itp_rtti_ord_outer],
  689. defaultpacking,reqalign,
  690. targetinfos[target_info.system]^.alignment.recordalignmin,
  691. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  692. tcb.emit_ord_const(byte(trans[def.ordtype]),u8inttype);
  693. tcb.begin_anonymous_record(
  694. internaltypeprefixName[itp_rtti_ord_inner],
  695. defaultpacking,reqalign,
  696. targetinfos[target_info.system]^.alignment.recordalignmin,
  697. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  698. {Convert to longint to smuggle values in high(longint)+1..high(cardinal) into asmlist.}
  699. tcb.emit_ord_const(longint(def.low.svalue),s32inttype);
  700. tcb.emit_ord_const(longint(def.high.svalue),s32inttype);
  701. tcb.end_anonymous_record;
  702. tcb.end_anonymous_record;
  703. end;
  704. begin
  705. case def.ordtype of
  706. s64bit :
  707. begin
  708. write_header(tcb,def,tkInt64);
  709. tcb.begin_anonymous_record(
  710. internaltypeprefixName[itp_rtti_ord_64bit],
  711. defaultpacking,reqalign,
  712. targetinfos[target_info.system]^.alignment.recordalignmin,
  713. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  714. { low }
  715. tcb.emit_ord_const(def.low.svalue,s64inttype);
  716. { high }
  717. tcb.emit_ord_const(def.high.svalue,s64inttype);
  718. tcb.end_anonymous_record;
  719. end;
  720. u64bit :
  721. begin
  722. write_header(tcb,def,tkQWord);
  723. tcb.begin_anonymous_record(
  724. internaltypeprefixName[itp_rtti_ord_64bit],
  725. defaultpacking,reqalign,
  726. targetinfos[target_info.system]^.alignment.recordalignmin,
  727. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  728. { use svalue because emit_ord_const accepts int64, prevents
  729. range check errors }
  730. { low }
  731. tcb.emit_ord_const(def.low.svalue,s64inttype);
  732. { high }
  733. tcb.emit_ord_const(def.high.svalue,s64inttype);
  734. tcb.end_anonymous_record;
  735. end;
  736. pasbool8:
  737. dointeger(tkBool);
  738. uchar:
  739. dointeger(tkChar);
  740. uwidechar:
  741. dointeger(tkWChar);
  742. scurrency:
  743. begin
  744. write_header(tcb,def,tkFloat);
  745. tcb.begin_anonymous_record(
  746. internaltypeprefixName[itp_1byte],
  747. defaultpacking,reqalign,
  748. targetinfos[target_info.system]^.alignment.recordalignmin,
  749. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  750. tcb.emit_ord_const(ftCurr,u8inttype);
  751. tcb.end_anonymous_record;
  752. end;
  753. else
  754. dointeger(tkInteger);
  755. end;
  756. end;
  757. procedure floatdef_rtti(def:tfloatdef);
  758. const
  759. {tfloattype = (s32real,s64real,s80real,sc80real,s64bit,s128bit);}
  760. translate : array[tfloattype] of byte =
  761. (ftSingle,ftDouble,ftExtended,ftExtended,ftComp,ftCurr,ftFloat128);
  762. begin
  763. write_header(tcb,def,tkFloat);
  764. tcb.begin_anonymous_record(
  765. internaltypeprefixName[itp_1byte],
  766. defaultpacking,reqalign,
  767. targetinfos[target_info.system]^.alignment.recordalignmin,
  768. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  769. tcb.emit_ord_const(translate[def.floattype],u8inttype);
  770. tcb.end_anonymous_record;
  771. end;
  772. procedure setdef_rtti(def:tsetdef);
  773. begin
  774. write_header(tcb,def,tkSet);
  775. tcb.begin_anonymous_record(
  776. internaltypeprefixName[itp_1byte],
  777. defaultpacking,reqalign,
  778. targetinfos[target_info.system]^.alignment.recordalignmin,
  779. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  780. case def.size of
  781. 1:
  782. tcb.emit_ord_const(otUByte,u8inttype);
  783. 2:
  784. tcb.emit_ord_const(otUWord,u8inttype);
  785. 4:
  786. tcb.emit_ord_const(otULong,u8inttype);
  787. else
  788. tcb.emit_ord_const(otUByte,u8inttype);
  789. end;
  790. { since this record has an alignment of reqalign, its size will also
  791. be rounded up to a multiple of reqalign -> the following value will
  792. also be properly aligned without having to start an extra record }
  793. tcb.end_anonymous_record;
  794. write_rtti_reference(tcb,def.elementdef,rt);
  795. end;
  796. procedure arraydef_rtti(def:tarraydef);
  797. var
  798. i,dimcount: byte;
  799. totalcount: asizeuint;
  800. finaldef: tdef;
  801. curdef:tarraydef;
  802. begin
  803. if ado_IsDynamicArray in def.arrayoptions then
  804. tcb.emit_ord_const(tkDynArray,u8inttype)
  805. else
  806. tcb.emit_ord_const(tkArray,u8inttype);
  807. write_rtti_name(tcb,def);
  808. if not(ado_IsDynamicArray in def.arrayoptions) then
  809. begin
  810. { remember tha last instruction. we will need to insert some
  811. calculated values after it }
  812. finaldef:=def;
  813. totalcount:=1;
  814. dimcount:=0;
  815. repeat
  816. curdef:=tarraydef(finaldef);
  817. finaldef:=curdef.elementdef;
  818. { Dims[i] PTypeInfo }
  819. inc(dimcount);
  820. totalcount:=totalcount*curdef.elecount;
  821. until (finaldef.typ<>arraydef) or
  822. (ado_IsDynamicArray in tarraydef(finaldef).arrayoptions);
  823. tcb.begin_anonymous_record(
  824. internaltypeprefixName[itp_rtti_normal_array]+tostr(dimcount),
  825. defaultpacking,reqalign,
  826. targetinfos[target_info.system]^.alignment.recordalignmin,
  827. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  828. { total size = elecount * elesize of the first arraydef }
  829. tcb.emit_tai(Tai_const.Create_pint(def.elecount*def.elesize),ptruinttype);
  830. { total element count }
  831. tcb.emit_tai(Tai_const.Create_pint(pint(totalcount)),ptruinttype);
  832. { last dimension element type }
  833. tcb.emit_tai(Tai_const.Create_sym(ref_rtti(curdef.elementdef,rt)),voidpointertype);
  834. { dimension count }
  835. tcb.emit_ord_const(dimcount,u8inttype);
  836. finaldef:=def;
  837. { ranges of the dimensions }
  838. for i:=1 to dimcount do
  839. begin
  840. curdef:=tarraydef(finaldef);
  841. finaldef:=curdef.elementdef;
  842. { Dims[i] PTypeInfo }
  843. write_rtti_reference(tcb,curdef.rangedef,rt);
  844. end;
  845. end
  846. else
  847. { write a delphi almost compatible dyn. array entry:
  848. there are two types, eltype and eltype2, the latter is nil if the element type needs
  849. no finalization, the former is always valid, delphi has this swapped, but for
  850. compatibility with older fpc versions we do it different, to be delphi compatible,
  851. the names are swapped in typinfo.pp
  852. }
  853. begin
  854. tcb.begin_anonymous_record(
  855. internaltypeprefixName[itp_rtti_dyn_array],
  856. defaultpacking,reqalign,
  857. targetinfos[target_info.system]^.alignment.recordalignmin,
  858. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  859. { size of elements }
  860. tcb.emit_tai(Tai_const.Create_pint(def.elesize),ptruinttype);
  861. { element type }
  862. write_rtti_reference(tcb,def.elementdef,rt);
  863. { variant type }
  864. tcb.emit_ord_const(tstoreddef(def.elementdef).getvardef,s32inttype);
  865. { element type }
  866. if def.elementdef.needs_inittable then
  867. write_rtti_reference(tcb,def.elementdef,rt)
  868. else
  869. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype);
  870. { write unit name }
  871. tcb.emit_shortstring_const(current_module.realmodulename^);
  872. end;
  873. tcb.end_anonymous_record;
  874. end;
  875. procedure classrefdef_rtti(def:tclassrefdef);
  876. begin
  877. write_header(tcb,def,tkClassRef);
  878. { will be aligned thanks to encompassing record }
  879. write_rtti_reference(tcb,def.pointeddef,rt);
  880. end;
  881. procedure pointerdef_rtti(def:tpointerdef);
  882. begin
  883. write_header(tcb,def,tkPointer);
  884. { will be aligned thanks to encompassing record }
  885. write_rtti_reference(tcb,def.pointeddef,rt);
  886. end;
  887. procedure recorddef_rtti(def:trecorddef);
  888. begin
  889. write_header(tcb,def,tkRecord);
  890. { need extra reqalign record, because otherwise the u32 int will
  891. only be aligned to 4 even on 64 bit target (while the rtti code
  892. in typinfo expects alignments to sizeof(pointer)) }
  893. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  894. targetinfos[target_info.system]^.alignment.recordalignmin,
  895. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  896. tcb.emit_ord_const(def.size,u32inttype);
  897. fields_write_rtti_data(tcb,def,rt);
  898. tcb.end_anonymous_record;
  899. end;
  900. procedure procvardef_rtti(def:tprocvardef);
  901. procedure write_para(parasym:tparavarsym);
  902. begin
  903. { only store user visible parameters }
  904. if not(vo_is_hidden_para in parasym.varoptions) then
  905. begin
  906. { write flags for current parameter }
  907. write_param_flag(tcb, parasym);
  908. { write name of current parameter }
  909. tcb.emit_shortstring_const(parasym.realname);
  910. { write name of type of current parameter }
  911. write_rtti_name(tcb,parasym.vardef);
  912. end;
  913. end;
  914. procedure write_procedure_param(parasym:tparavarsym);
  915. begin
  916. { only store user visible parameters }
  917. if not(vo_is_hidden_para in parasym.varoptions) then
  918. begin
  919. { every parameter is expected to start aligned }
  920. tcb.begin_anonymous_record(
  921. internaltypeprefixName[itp_rtti_proc_param]+tostr(length(parasym.realname)),
  922. defaultpacking,reqalign,
  923. targetinfos[target_info.system]^.alignment.recordalignmin,
  924. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  925. { write flags for current parameter }
  926. write_param_flag(tcb,parasym);
  927. { write param type }
  928. write_rtti_reference(tcb,parasym.vardef,fullrtti);
  929. { write name of current parameter }
  930. tcb.emit_shortstring_const(parasym.realname);
  931. tcb.end_anonymous_record;
  932. end;
  933. end;
  934. var
  935. methodkind : byte;
  936. i : integer;
  937. begin
  938. if po_methodpointer in def.procoptions then
  939. begin
  940. { write method id and name }
  941. write_header(tcb,def,tkMethod);
  942. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  943. targetinfos[target_info.system]^.alignment.recordalignmin,
  944. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  945. { write kind of method }
  946. case def.proctypeoption of
  947. potype_constructor: methodkind:=mkConstructor;
  948. potype_destructor: methodkind:=mkDestructor;
  949. potype_class_constructor: methodkind:=mkClassConstructor;
  950. potype_class_destructor: methodkind:=mkClassDestructor;
  951. potype_operator: methodkind:=mkOperatorOverload;
  952. potype_procedure:
  953. if po_classmethod in def.procoptions then
  954. methodkind:=mkClassProcedure
  955. else
  956. methodkind:=mkProcedure;
  957. potype_function:
  958. if po_classmethod in def.procoptions then
  959. methodkind:=mkClassFunction
  960. else
  961. methodkind:=mkFunction;
  962. else
  963. begin
  964. if def.returndef = voidtype then
  965. methodkind:=mkProcedure
  966. else
  967. methodkind:=mkFunction;
  968. end;
  969. end;
  970. tcb.emit_ord_const(methodkind,u8inttype);
  971. { write parameter info. The parameters must be written in reverse order
  972. if this method uses right to left parameter pushing! }
  973. tcb.emit_ord_const(def.maxparacount,u8inttype);
  974. for i:=0 to def.paras.count-1 do
  975. write_para(tparavarsym(def.paras[i]));
  976. if (methodkind=mkFunction) or (methodkind=mkClassFunction) then
  977. begin
  978. { write name of result type }
  979. write_rtti_name(tcb,def.returndef);
  980. { enclosing record takes care of alignment }
  981. { write result typeinfo }
  982. write_rtti_reference(tcb,def.returndef,fullrtti);
  983. end;
  984. { write calling convention }
  985. tcb.emit_ord_const(ProcCallOptionToCallConv[def.proccalloption],u8inttype);
  986. { enclosing record takes care of alignment }
  987. { write params typeinfo }
  988. for i:=0 to def.paras.count-1 do
  989. if not(vo_is_hidden_para in tparavarsym(def.paras[i]).varoptions) then
  990. write_rtti_reference(tcb,tparavarsym(def.paras[i]).vardef,fullrtti);
  991. tcb.end_anonymous_record;
  992. end
  993. else
  994. begin
  995. write_header(tcb,def,tkProcvar);
  996. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  997. targetinfos[target_info.system]^.alignment.recordalignmin,
  998. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  999. { flags }
  1000. tcb.emit_ord_const(0,u8inttype);
  1001. { write calling convention }
  1002. tcb.emit_ord_const(ProcCallOptionToCallConv[def.proccalloption],u8inttype);
  1003. { enclosing record takes care of alignment }
  1004. { write result typeinfo }
  1005. write_rtti_reference(tcb,def.returndef,fullrtti);
  1006. { write parameter count }
  1007. tcb.emit_ord_const(def.maxparacount,u8inttype);
  1008. for i:=0 to def.paras.count-1 do
  1009. write_procedure_param(tparavarsym(def.paras[i]));
  1010. tcb.end_anonymous_record;
  1011. end;
  1012. end;
  1013. procedure objectdef_rtti(def: tobjectdef);
  1014. procedure objectdef_rtti_fields(def:tobjectdef);
  1015. begin
  1016. tcb.emit_ord_const(def.size, u32inttype);
  1017. { enclosing record takes care of alignment }
  1018. fields_write_rtti_data(tcb,def,rt);
  1019. end;
  1020. procedure objectdef_rtti_interface_init(def:tobjectdef);
  1021. begin
  1022. tcb.emit_ord_const(def.size, u32inttype);
  1023. end;
  1024. procedure objectdef_rtti_class_full(def:tobjectdef);
  1025. var
  1026. propnamelist : TFPHashObjectList;
  1027. begin
  1028. { Collect unique property names with nameindex }
  1029. propnamelist:=TFPHashObjectList.Create;
  1030. collect_propnamelist(propnamelist,def);
  1031. if not is_objectpascal_helper(def) then
  1032. if (oo_has_vmt in def.objectoptions) then
  1033. tcb.emit_tai(
  1034. Tai_const.Createname(def.vmt_mangledname,AT_DATA,0),
  1035. cpointerdef.getreusable(def.vmt_def))
  1036. else
  1037. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype);
  1038. { write parent typeinfo }
  1039. write_rtti_reference(tcb,def.childof,fullrtti);
  1040. { write typeinfo of extended type }
  1041. if is_objectpascal_helper(def) then
  1042. if assigned(def.extendeddef) then
  1043. write_rtti_reference(tcb,def.extendeddef,fullrtti)
  1044. else
  1045. InternalError(2011033001);
  1046. { total number of unique properties }
  1047. tcb.emit_ord_const(propnamelist.count,u16inttype);
  1048. { write unit name }
  1049. tcb.emit_shortstring_const(current_module.realmodulename^);
  1050. { write published properties for this object }
  1051. published_properties_write_rtti_data(tcb,propnamelist,def.symtable);
  1052. propnamelist.free;
  1053. end;
  1054. procedure objectdef_rtti_interface_full(def:tobjectdef);
  1055. var
  1056. propnamelist : TFPHashObjectList;
  1057. { if changed to a set, make sure it's still a byte large, and
  1058. swap appropriately when cross-compiling
  1059. }
  1060. IntfFlags: byte;
  1061. begin
  1062. { Collect unique property names with nameindex }
  1063. propnamelist:=TFPHashObjectList.Create;
  1064. collect_propnamelist(propnamelist,def);
  1065. { write parent typeinfo }
  1066. write_rtti_reference(tcb,def.childof,fullrtti);
  1067. { interface: write flags, iid and iidstr }
  1068. IntfFlags:=0;
  1069. if assigned(def.iidguid) then
  1070. IntfFlags:=IntfFlags or (1 shl ord(ifHasGuid));
  1071. if (def.objecttype=odt_interfacecorba) and (def.iidstr^<>'') then
  1072. IntfFlags:=IntfFlags or (1 shl ord(ifHasStrGUID));
  1073. if (def.objecttype=odt_dispinterface) then
  1074. IntfFlags:=IntfFlags or (1 shl ord(ifDispInterface));
  1075. if (target_info.endian=endian_big) then
  1076. IntfFlags:=reverse_byte(IntfFlags);
  1077. {
  1078. ifDispatch, }
  1079. tcb.emit_ord_const(IntfFlags,u8inttype);
  1080. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1081. targetinfos[target_info.system]^.alignment.recordalignmin,
  1082. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1083. tcb.emit_guid_const(def.iidguid^);
  1084. { write unit name }
  1085. tcb.emit_shortstring_const(current_module.realmodulename^);
  1086. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1087. targetinfos[target_info.system]^.alignment.recordalignmin,
  1088. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1089. { write iidstr }
  1090. if def.objecttype=odt_interfacecorba then
  1091. begin
  1092. { prepareguid always allocates an empty string }
  1093. if not assigned(def.iidstr) then
  1094. internalerror(2016021901);
  1095. tcb.emit_shortstring_const(def.iidstr^)
  1096. end;
  1097. { write published properties for this object }
  1098. published_properties_write_rtti_data(tcb,propnamelist,def.symtable);
  1099. { write methods for this object }
  1100. methods_write_rtti(tcb, def.symtable);
  1101. tcb.end_anonymous_record;
  1102. tcb.end_anonymous_record;
  1103. propnamelist.free;
  1104. end;
  1105. begin
  1106. case def.objecttype of
  1107. odt_class:
  1108. tcb.emit_ord_const(tkclass,u8inttype);
  1109. odt_object:
  1110. tcb.emit_ord_const(tkobject,u8inttype);
  1111. odt_dispinterface,
  1112. odt_interfacecom:
  1113. tcb.emit_ord_const(tkInterface,u8inttype);
  1114. odt_interfacecorba:
  1115. tcb.emit_ord_const(tkinterfaceCorba,u8inttype);
  1116. odt_helper:
  1117. tcb.emit_ord_const(tkhelper,u8inttype);
  1118. else
  1119. internalerror(200611034);
  1120. end;
  1121. { generate the name }
  1122. tcb.emit_shortstring_const(def.objrealname^);
  1123. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1124. targetinfos[target_info.system]^.alignment.recordalignmin,
  1125. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1126. case rt of
  1127. initrtti :
  1128. begin
  1129. if def.objecttype in [odt_class,odt_object,odt_helper] then
  1130. objectdef_rtti_fields(def)
  1131. else
  1132. objectdef_rtti_interface_init(def);
  1133. end;
  1134. fullrtti :
  1135. begin
  1136. case def.objecttype of
  1137. odt_helper,
  1138. odt_class:
  1139. objectdef_rtti_class_full(def);
  1140. odt_object:
  1141. objectdef_rtti_fields(def);
  1142. else
  1143. objectdef_rtti_interface_full(def);
  1144. end;
  1145. end;
  1146. end;
  1147. tcb.end_anonymous_record;
  1148. end;
  1149. begin
  1150. case def.typ of
  1151. variantdef :
  1152. variantdef_rtti(tvariantdef(def));
  1153. stringdef :
  1154. stringdef_rtti(tstringdef(def));
  1155. enumdef :
  1156. enumdef_rtti(tenumdef(def));
  1157. orddef :
  1158. orddef_rtti(torddef(def));
  1159. floatdef :
  1160. floatdef_rtti(tfloatdef(def));
  1161. setdef :
  1162. setdef_rtti(tsetdef(def));
  1163. procvardef :
  1164. procvardef_rtti(tprocvardef(def));
  1165. arraydef :
  1166. begin
  1167. if ado_IsBitPacked in tarraydef(def).arrayoptions then
  1168. unknown_rtti(tstoreddef(def))
  1169. else
  1170. arraydef_rtti(tarraydef(def));
  1171. end;
  1172. recorddef :
  1173. begin
  1174. if trecorddef(def).is_packed then
  1175. unknown_rtti(tstoreddef(def))
  1176. else
  1177. recorddef_rtti(trecorddef(def));
  1178. end;
  1179. objectdef :
  1180. objectdef_rtti(tobjectdef(def));
  1181. classrefdef :
  1182. classrefdef_rtti(tclassrefdef(def));
  1183. pointerdef :
  1184. pointerdef_rtti(tpointerdef(def));
  1185. else
  1186. unknown_rtti(tstoreddef(def));
  1187. end;
  1188. end;
  1189. function enumsym_compare_name(item1, item2: pointer): Integer;
  1190. var
  1191. enum1: tenumsym absolute item1;
  1192. enum2: tenumsym absolute item2;
  1193. begin
  1194. if enum1=enum2 then
  1195. result:=0
  1196. else if enum1.name>enum2.name then
  1197. result:=1
  1198. else
  1199. { there can't be equal names, identifiers are unique }
  1200. result:=-1;
  1201. end;
  1202. function enumsym_compare_value(item1, item2: pointer): Integer;
  1203. var
  1204. enum1: tenumsym absolute item1;
  1205. enum2: tenumsym absolute item2;
  1206. begin
  1207. if enum1.value>enum2.value then
  1208. result:=1
  1209. else if enum1.value<enum2.value then
  1210. result:=-1
  1211. else
  1212. result:=0;
  1213. end;
  1214. procedure TRTTIWriter.write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  1215. type Penumsym = ^Tenumsym;
  1216. { Writes a helper table for accelerated conversion of ordinal enum values to strings.
  1217. If you change something in this method, make sure to adapt the corresponding code
  1218. in sstrings.inc. }
  1219. procedure enumdef_rtti_ord2stringindex(rttidef: trecorddef; const syms: tfplist);
  1220. var rttilab,rttilabind:Tasmsymbol;
  1221. h,i,o,prev_value:longint;
  1222. mode:(lookup,search); {Modify with care, ordinal value of enum is written.}
  1223. r:single; {Must be real type because of integer overflow risk.}
  1224. tcb: ttai_typedconstbuilder;
  1225. sym_count: integer;
  1226. begin
  1227. {Decide wether a lookup array is size efficient.}
  1228. mode:=lookup;
  1229. sym_count:=syms.count;
  1230. if sym_count>0 then
  1231. begin
  1232. i:=1;
  1233. r:=0;
  1234. h:=tenumsym(syms[0]).value; {Next expected enum value is min.}
  1235. { set prev_value for the first iteration to a value that is
  1236. different from the first one without risking overflow (it's used
  1237. to detect whether two enum values are the same) }
  1238. if h=0 then
  1239. prev_value:=1
  1240. else
  1241. prev_value:=0;
  1242. while i<sym_count do
  1243. begin
  1244. { if two enum values are the same, we have to create a table }
  1245. if (prev_value=h) then
  1246. begin
  1247. mode:=search;
  1248. break;
  1249. end;
  1250. {Calculate size of hole between values. Avoid integer overflows.}
  1251. r:=r+(single(tenumsym(syms[i]).value)-single(h))-1;
  1252. prev_value:=h;
  1253. h:=tenumsym(syms[i]).value;
  1254. inc(i);
  1255. end;
  1256. if r>sym_count then
  1257. mode:=search; {Don't waste more than 50% space.}
  1258. end;
  1259. { write rtti data; make sure that the alignment matches the corresponding data structure
  1260. in the code that uses it (if alignment is required). }
  1261. rttilab:=current_asmdata.DefineAsmSymbol(Tstoreddef(def).rtti_mangledname(rt)+'_o2s',AB_GLOBAL,AT_DATA);
  1262. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1263. { use TConstPtrUInt packrecords to ensure good alignment }
  1264. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1265. targetinfos[target_info.system]^.alignment.recordalignmin,
  1266. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1267. { now emit the data: first the mode }
  1268. tcb.emit_tai(Tai_const.create_32bit(longint(mode)),u32inttype);
  1269. { align }
  1270. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1271. targetinfos[target_info.system]^.alignment.recordalignmin,
  1272. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1273. if mode=lookup then
  1274. begin
  1275. o:=tenumsym(syms[0]).value; {Start with min value.}
  1276. for i:=0 to sym_count-1 do
  1277. begin
  1278. while o<tenumsym(syms[i]).value do
  1279. begin
  1280. tcb.emit_tai(Tai_const.create_pint(0),ptruinttype);
  1281. inc(o);
  1282. end;
  1283. inc(o);
  1284. tcb.queue_init(voidpointertype);
  1285. tcb.queue_subscriptn_multiple_by_name(rttidef,
  1286. ['size_start_rec',
  1287. 'min_max_rec',
  1288. 'basetype_array_rec',
  1289. tsym(syms[i]).Name]
  1290. );
  1291. tcb.queue_emit_asmsym(mainrtti,rttidef);
  1292. end;
  1293. end
  1294. else
  1295. begin
  1296. tcb.emit_ord_const(sym_count,u32inttype);
  1297. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1298. targetinfos[target_info.system]^.alignment.recordalignmin,
  1299. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1300. for i:=0 to sym_count-1 do
  1301. begin
  1302. tcb.emit_ord_const(tenumsym(syms[i]).value,s32inttype);
  1303. tcb.queue_init(voidpointertype);
  1304. tcb.queue_subscriptn_multiple_by_name(rttidef,
  1305. ['size_start_rec',
  1306. 'min_max_rec',
  1307. 'basetype_array_rec',
  1308. tsym(syms[i]).Name]
  1309. );
  1310. tcb.queue_emit_asmsym(mainrtti,rttidef);
  1311. end;
  1312. tcb.end_anonymous_record;
  1313. end;
  1314. tcb.end_anonymous_record;
  1315. current_asmdata.asmlists[al_rtti].concatlist(tcb.get_final_asmlist(
  1316. rttilab,tcb.end_anonymous_record,sec_rodata,
  1317. rttilab.name,const_align(sizeof(pint))));
  1318. tcb.free;
  1319. { write indirect symbol }
  1320. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1321. rttilabind:=current_asmdata.DefineAsmSymbol(Tstoreddef(def).rtti_mangledname(rt)+'_o2s',AB_INDIRECT,AT_DATA);
  1322. tcb.emit_tai(Tai_const.Createname(rttilab.name,AT_DATA,0),voidpointertype);
  1323. current_asmdata.AsmLists[al_rtti].concatList(
  1324. tcb.get_final_asmlist(rttilabind,voidpointertype,sec_rodata,rttilabind.name,const_align(sizeof(pint))));
  1325. tcb.free;
  1326. end;
  1327. { Writes a helper table for accelerated conversion of string to ordinal enum values.
  1328. If you change something in this method, make sure to adapt the corresponding code
  1329. in sstrings.inc. }
  1330. procedure enumdef_rtti_string2ordindex(rttidef: trecorddef; const syms: tfplist);
  1331. var
  1332. tcb: ttai_typedconstbuilder;
  1333. rttilab,
  1334. rttilabind : Tasmsymbol;
  1335. i:longint;
  1336. begin
  1337. { write rtti data }
  1338. rttilab:=current_asmdata.DefineAsmSymbol(Tstoreddef(def).rtti_mangledname(rt)+'_s2o',AB_GLOBAL,AT_DATA);
  1339. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1340. { begin of Tstring_to_ord }
  1341. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1342. targetinfos[target_info.system]^.alignment.recordalignmin,
  1343. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1344. tcb.emit_ord_const(syms.count,s32inttype);
  1345. { begin of "data" array in Tstring_to_ord }
  1346. tcb.begin_anonymous_record('',defaultpacking,reqalign,
  1347. targetinfos[target_info.system]^.alignment.recordalignmin,
  1348. targetinfos[target_info.system]^.alignment.maxCrecordalign);
  1349. for i:=0 to syms.count-1 do
  1350. begin
  1351. tcb.emit_ord_const(tenumsym(syms[i]).value,s32inttype);
  1352. { alignment of pointer value handled by enclosing record already }
  1353. tcb.queue_init(voidpointertype);
  1354. tcb.queue_subscriptn_multiple_by_name(rttidef,
  1355. ['size_start_rec',
  1356. 'min_max_rec',
  1357. 'basetype_array_rec',
  1358. tsym(syms[i]).Name]
  1359. );
  1360. tcb.queue_emit_asmsym(mainrtti,rttidef);
  1361. end;
  1362. tcb.end_anonymous_record;
  1363. current_asmdata.asmlists[al_rtti].concatlist(tcb.get_final_asmlist(
  1364. rttilab,tcb.end_anonymous_record,sec_rodata,
  1365. rttilab.name,const_align(sizeof(pint))));
  1366. tcb.free;
  1367. { write indirect symbol }
  1368. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1369. rttilabind:=current_asmdata.DefineAsmSymbol(Tstoreddef(def).rtti_mangledname(rt)+'_s2o',AB_INDIRECT,AT_DATA);
  1370. tcb.emit_tai(Tai_const.Createname(rttilab.name,AT_DATA,0),voidpointertype);
  1371. current_asmdata.AsmLists[al_rtti].concatList(
  1372. tcb.get_final_asmlist(rttilabind,voidpointertype,sec_rodata,rttilabind.name,const_align(sizeof(pint))));
  1373. tcb.free;
  1374. end;
  1375. procedure enumdef_rtti_extrasyms(def:Tenumdef);
  1376. var
  1377. t:Tenumsym;
  1378. syms:tfplist;
  1379. i:longint;
  1380. rttitypesym: ttypesym;
  1381. rttidef: trecorddef;
  1382. begin
  1383. { collect enumsyms belonging to this enum type (could be a subsection
  1384. in case of a subrange type) }
  1385. syms:=tfplist.create;
  1386. for i := 0 to def.symtable.SymList.Count - 1 do
  1387. begin
  1388. t:=tenumsym(def.symtable.SymList[i]);
  1389. if t.value<def.minval then
  1390. continue
  1391. else
  1392. if t.value>def.maxval then
  1393. break;
  1394. syms.add(t);
  1395. end;
  1396. { sort the syms by enum name }
  1397. syms.sort(@enumsym_compare_name);
  1398. rttitypesym:=try_search_current_module_type(internaltypeprefixName[itp_rttidef]+def.rtti_mangledname(fullrtti));
  1399. if not assigned(rttitypesym) or
  1400. (ttypesym(rttitypesym).typedef.typ<>recorddef) then
  1401. internalerror(2015071402);
  1402. rttidef:=trecorddef(ttypesym(rttitypesym).typedef);
  1403. enumdef_rtti_string2ordindex(rttidef,syms);
  1404. { sort the syms by enum value }
  1405. syms.sort(@enumsym_compare_value);
  1406. enumdef_rtti_ord2stringindex(rttidef,syms);
  1407. syms.free;
  1408. end;
  1409. begin
  1410. case def.typ of
  1411. enumdef:
  1412. if rt=fullrtti then
  1413. begin
  1414. enumdef_rtti_extrasyms(Tenumdef(def));
  1415. end;
  1416. end;
  1417. end;
  1418. procedure TRTTIWriter.write_child_rtti_data(def:tdef;rt:trttitype);
  1419. var
  1420. i,j: SizeInt;
  1421. begin
  1422. case def.typ of
  1423. enumdef :
  1424. if assigned(tenumdef(def).basedef) then
  1425. write_rtti(tenumdef(def).basedef,rt);
  1426. setdef :
  1427. write_rtti(tsetdef(def).elementdef,rt);
  1428. arraydef :
  1429. begin
  1430. write_rtti(tarraydef(def).rangedef,rt);
  1431. write_rtti(tarraydef(def).elementdef,rt);
  1432. end;
  1433. recorddef :
  1434. fields_write_rtti(trecorddef(def).symtable,rt);
  1435. objectdef :
  1436. begin
  1437. if assigned(tobjectdef(def).childof) then
  1438. write_rtti(tobjectdef(def).childof,rt);
  1439. if (rt=initrtti) or (tobjectdef(def).objecttype=odt_object) then
  1440. fields_write_rtti(tobjectdef(def).symtable,rt)
  1441. else
  1442. begin
  1443. published_write_rtti(tobjectdef(def).symtable,rt);
  1444. if is_any_interface_kind(def) then
  1445. with tobjectdef(def).symtable do
  1446. for i := 0 to SymList.Count-1 do
  1447. if (tsym(SymList[i]).typ=procsym) then
  1448. with tprocsym(tobjectdef(def).symtable.SymList[i]) do
  1449. for j := 0 to ProcdefList.Count - 1 do
  1450. begin
  1451. write_rtti(tabstractprocdef(ProcdefList[j]).returndef,rt);
  1452. params_write_rtti(tabstractprocdef(ProcdefList[j]),rt);
  1453. end;
  1454. end;
  1455. end;
  1456. classrefdef,
  1457. pointerdef:
  1458. if not is_objc_class_or_protocol(tabstractpointerdef(def).pointeddef) then
  1459. write_rtti(tabstractpointerdef(def).pointeddef,rt);
  1460. procvardef:
  1461. params_write_rtti(tabstractprocdef(def),rt);
  1462. end;
  1463. end;
  1464. procedure TRTTIWriter.write_rtti_reference(tcb: ttai_typedconstbuilder; def: tdef; rt: trttitype);
  1465. begin
  1466. { we don't care about the real type here, because
  1467. a) we don't index into these elements
  1468. b) we may not have the rtti type available at the point that we
  1469. are emitting this data, because of forward definitions etc
  1470. c) if the rtti is emitted in another unit, we won't have the type
  1471. available at all
  1472. For the cases where the type is emitted in the current unit and hence
  1473. the underlying system will detect and complain about symbol def
  1474. mismatches, type conversions will have to be inserted afterwards (like
  1475. in llvm/llvmtype)
  1476. }
  1477. if not assigned(def) or is_void(def) or ((rt<>initrtti) and is_objc_class_or_protocol(def)) then
  1478. tcb.emit_tai(Tai_const.Create_nil_dataptr,voidpointertype)
  1479. else
  1480. tcb.emit_tai(Tai_const.Create_sym(ref_rtti(def,rt)),voidpointertype);
  1481. end;
  1482. function TRTTIWriter.ref_rtti(def:tdef;rt:trttitype):tasmsymbol;
  1483. begin
  1484. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt),AT_DATA);
  1485. if (cs_create_pic in current_settings.moduleswitches) and
  1486. assigned(current_procinfo) then
  1487. include(current_procinfo.flags,pi_needs_got);
  1488. end;
  1489. procedure TRTTIWriter.write_rtti(def:tdef;rt:trttitype);
  1490. var
  1491. tcb: ttai_typedconstbuilder;
  1492. rttilab,
  1493. rttilabind : tasmsymbol;
  1494. rttidef: tdef;
  1495. begin
  1496. { only write rtti of definitions from the current module }
  1497. if not findunitsymtable(def.owner).iscurrentunit then
  1498. exit;
  1499. { check if separate initrtti is actually needed }
  1500. if (rt=initrtti) and (not def.needs_separate_initrtti) then
  1501. rt:=fullrtti;
  1502. { prevent recursion }
  1503. if rttidefstate[rt] in def.defstates then
  1504. exit;
  1505. include(def.defstates,rttidefstate[rt]);
  1506. { write first all dependencies }
  1507. write_child_rtti_data(def,rt);
  1508. { write rtti data }
  1509. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1510. rttilab:=current_asmdata.DefineAsmSymbol(tstoreddef(def).rtti_mangledname(rt),AB_GLOBAL,AT_DATA);
  1511. tcb.begin_anonymous_record(
  1512. internaltypeprefixName[itp_rttidef]+rttilab.Name,
  1513. defaultpacking,reqalign,
  1514. targetinfos[target_info.system]^.alignment.recordalignmin,
  1515. targetinfos[target_info.system]^.alignment.maxCrecordalign
  1516. );
  1517. write_rtti_data(tcb,def,rt);
  1518. rttidef:=tcb.end_anonymous_record;
  1519. current_asmdata.AsmLists[al_rtti].concatList(
  1520. tcb.get_final_asmlist(rttilab,rttidef,sec_rodata,rttilab.name,const_align(sizeof(pint))));
  1521. tcb.free;
  1522. { write indirect symbol }
  1523. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable]);
  1524. rttilabind:=current_asmdata.DefineAsmSymbol(tstoreddef(def).rtti_mangledname(rt),AB_INDIRECT,AT_DATA);
  1525. tcb.emit_tai(Tai_const.Createname(rttilab.name,AT_DATA,0),voidpointertype);
  1526. current_asmdata.AsmLists[al_rtti].concatList(
  1527. tcb.get_final_asmlist(rttilabind,voidpointertype,sec_rodata,rttilabind.name,const_align(sizeof(pint))));
  1528. tcb.free;
  1529. { write additional data }
  1530. write_rtti_extrasyms(def,rt,rttilab);
  1531. end;
  1532. constructor TRTTIWriter.create;
  1533. begin
  1534. if tf_requires_proper_alignment in target_info.flags then
  1535. begin
  1536. reqalign:=sizeof(TConstPtrUInt);
  1537. defaultpacking:=C_alignment;
  1538. end
  1539. else
  1540. begin
  1541. reqalign:=1;
  1542. defaultpacking:=1;
  1543. end;
  1544. end;
  1545. function TRTTIWriter.get_rtti_label(def:tdef;rt:trttitype):tasmsymbol;
  1546. begin
  1547. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt),AT_DATA);
  1548. if (cs_create_pic in current_settings.moduleswitches) and
  1549. assigned(current_procinfo) then
  1550. include(current_procinfo.flags,pi_needs_got);
  1551. end;
  1552. function TRTTIWriter.get_rtti_label_ord2str(def:tdef;rt:trttitype):tasmsymbol;
  1553. begin
  1554. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_o2s',AT_DATA);
  1555. if (cs_create_pic in current_settings.moduleswitches) and
  1556. assigned(current_procinfo) then
  1557. include(current_procinfo.flags,pi_needs_got);
  1558. end;
  1559. function TRTTIWriter.get_rtti_label_str2ord(def:tdef;rt:trttitype):tasmsymbol;
  1560. begin
  1561. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_s2o',AT_DATA);
  1562. if (cs_create_pic in current_settings.moduleswitches) and
  1563. assigned(current_procinfo) then
  1564. include(current_procinfo.flags,pi_needs_got);
  1565. end;
  1566. end.