ncgrtti.pas 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  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,
  23. symbase,symconst,symtype,symdef;
  24. type
  25. { TRTTIWriter }
  26. TRTTIWriter=class
  27. private
  28. function fields_count(st:tsymtable;rt:trttitype):longint;
  29. procedure fields_write_rtti(st:tsymtable;rt:trttitype);
  30. procedure fields_write_rtti_data(st:tsymtable;rt:trttitype);
  31. procedure write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  32. procedure published_write_rtti(st:tsymtable;rt:trttitype);
  33. function published_properties_count(st:tsymtable):longint;
  34. procedure published_properties_write_rtti_data(propnamelist:TFPHashObjectList;st:tsymtable);
  35. procedure collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  36. procedure write_rtti_name(def:tdef);
  37. procedure write_rtti_data(def:tdef;rt:trttitype);
  38. procedure write_child_rtti_data(def:tdef;rt:trttitype);
  39. function ref_rtti(def:tdef;rt:trttitype):tasmsymbol;
  40. procedure write_header(def: tdef; typekind: byte);
  41. procedure write_string(const s: string);
  42. procedure maybe_write_align;
  43. public
  44. procedure write_rtti(def:tdef;rt:trttitype);
  45. function get_rtti_label(def:tdef;rt:trttitype):tasmsymbol;
  46. function get_rtti_label_ord2str(def:tdef;rt:trttitype):tasmsymbol;
  47. function get_rtti_label_str2ord(def:tdef;rt:trttitype):tasmsymbol;
  48. end;
  49. var
  50. RTTIWriter : TRTTIWriter;
  51. implementation
  52. uses
  53. cutils,
  54. globals,globtype,verbose,systems,
  55. fmodule,
  56. symsym,
  57. aasmtai,aasmdata,
  58. defutil,
  59. wpobase
  60. ;
  61. const
  62. rttidefstate : array[trttitype] of tdefstate =
  63. (ds_rtti_table_written,ds_init_table_written,
  64. { Objective-C related, does not pass here }
  65. symconst.ds_none,symconst.ds_none,
  66. symconst.ds_none,symconst.ds_none);
  67. type
  68. TPropNameListItem = class(TFPHashObject)
  69. propindex : longint;
  70. propowner : TSymtable;
  71. end;
  72. {***************************************************************************
  73. TRTTIWriter
  74. ***************************************************************************}
  75. procedure TRTTIWriter.maybe_write_align;
  76. begin
  77. if (tf_requires_proper_alignment in target_info.flags) then
  78. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  79. end;
  80. procedure TRTTIWriter.write_string(const s: string);
  81. begin
  82. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(s)));
  83. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(s));
  84. end;
  85. procedure TRTTIWriter.write_header(def: tdef; typekind: byte);
  86. begin
  87. if def.typ=arraydef then
  88. InternalError(201012211);
  89. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(typekind));
  90. if assigned(def.typesym) then
  91. write_string(ttypesym(def.typesym).realname)
  92. else
  93. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(#0));
  94. end;
  95. procedure TRTTIWriter.write_rtti_name(def:tdef);
  96. var
  97. hs : string;
  98. begin
  99. if is_open_array(def) then
  100. { open arrays never have a typesym with a name, since you cannot
  101. define an "open array type". Kylix prints the type of the
  102. elements in the array in this case (so together with the pfArray
  103. flag, you can reconstruct the full typename, I assume (JM))
  104. }
  105. def:=tarraydef(def).elementdef;
  106. { name }
  107. if assigned(def.typesym) then
  108. begin
  109. hs:=ttypesym(def.typesym).realname;
  110. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(chr(length(hs))+hs));
  111. end
  112. else
  113. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(#0));
  114. end;
  115. function TRTTIWriter.fields_count(st:tsymtable;rt:trttitype):longint;
  116. var
  117. i : longint;
  118. sym : tsym;
  119. begin
  120. result:=0;
  121. for i:=0 to st.SymList.Count-1 do
  122. begin
  123. sym:=tsym(st.SymList[i]);
  124. if (tsym(sym).typ=fieldvarsym) and
  125. not(sp_static in tsym(sym).symoptions) and
  126. (
  127. (rt=fullrtti) or
  128. tfieldvarsym(sym).vardef.needs_inittable
  129. ) then
  130. inc(result);
  131. end;
  132. end;
  133. procedure TRTTIWriter.fields_write_rtti_data(st:tsymtable;rt:trttitype);
  134. var
  135. i : longint;
  136. sym : tsym;
  137. begin
  138. for i:=0 to st.SymList.Count-1 do
  139. begin
  140. sym:=tsym(st.SymList[i]);
  141. if (tsym(sym).typ=fieldvarsym) and
  142. not(sp_static in tsym(sym).symoptions) and
  143. (
  144. (rt=fullrtti) or
  145. tfieldvarsym(sym).vardef.needs_inittable
  146. ) then
  147. begin
  148. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(tfieldvarsym(sym).vardef,rt)));
  149. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tfieldvarsym(sym).fieldoffset));
  150. end;
  151. end;
  152. end;
  153. procedure TRTTIWriter.fields_write_rtti(st:tsymtable;rt:trttitype);
  154. var
  155. i : longint;
  156. sym : tsym;
  157. begin
  158. for i:=0 to st.SymList.Count-1 do
  159. begin
  160. sym:=tsym(st.SymList[i]);
  161. if (tsym(sym).typ=fieldvarsym) and
  162. not(sp_static in tsym(sym).symoptions) and
  163. (
  164. (rt=fullrtti) or
  165. tfieldvarsym(sym).vardef.needs_inittable
  166. ) then
  167. write_rtti(tfieldvarsym(sym).vardef,rt);
  168. end;
  169. end;
  170. procedure TRTTIWriter.published_write_rtti(st:tsymtable;rt:trttitype);
  171. var
  172. i : longint;
  173. sym : tsym;
  174. begin
  175. for i:=0 to st.SymList.Count-1 do
  176. begin
  177. sym:=tsym(st.SymList[i]);
  178. if (sym.visibility=vis_published) then
  179. begin
  180. case tsym(sym).typ of
  181. propertysym:
  182. write_rtti(tpropertysym(sym).propdef,rt);
  183. fieldvarsym:
  184. write_rtti(tfieldvarsym(sym).vardef,rt);
  185. end;
  186. end;
  187. end;
  188. end;
  189. function TRTTIWriter.published_properties_count(st:tsymtable):longint;
  190. var
  191. i : longint;
  192. sym : tsym;
  193. begin
  194. result:=0;
  195. for i:=0 to st.SymList.Count-1 do
  196. begin
  197. sym:=tsym(st.SymList[i]);
  198. if (tsym(sym).typ=propertysym) and
  199. (sym.visibility=vis_published) then
  200. inc(result);
  201. end;
  202. end;
  203. procedure TRTTIWriter.collect_propnamelist(propnamelist:TFPHashObjectList;objdef:tobjectdef);
  204. var
  205. i : longint;
  206. sym : tsym;
  207. pn : tpropnamelistitem;
  208. begin
  209. if assigned(objdef.childof) then
  210. collect_propnamelist(propnamelist,objdef.childof);
  211. for i:=0 to objdef.symtable.SymList.Count-1 do
  212. begin
  213. sym:=tsym(objdef.symtable.SymList[i]);
  214. if (tsym(sym).typ=propertysym) and
  215. (sym.visibility=vis_published) then
  216. begin
  217. pn:=TPropNameListItem(propnamelist.Find(tsym(sym).name));
  218. if not assigned(pn) then
  219. begin
  220. pn:=tpropnamelistitem.create(propnamelist,tsym(sym).name);
  221. pn.propindex:=propnamelist.count-1;
  222. pn.propowner:=tsym(sym).owner;
  223. end;
  224. end;
  225. end;
  226. end;
  227. procedure TRTTIWriter.published_properties_write_rtti_data(propnamelist:TFPHashObjectList;st:tsymtable);
  228. var
  229. i : longint;
  230. sym : tsym;
  231. proctypesinfo : byte;
  232. propnameitem : tpropnamelistitem;
  233. procedure writeaccessproc(pap:tpropaccesslisttypes; shiftvalue : byte; unsetvalue: byte);
  234. var
  235. typvalue : byte;
  236. hp : ppropaccesslistitem;
  237. address,space : longint;
  238. def : tdef;
  239. hpropsym : tpropertysym;
  240. propaccesslist : tpropaccesslist;
  241. begin
  242. hpropsym:=tpropertysym(sym);
  243. repeat
  244. propaccesslist:=hpropsym.propaccesslist[pap];
  245. if not propaccesslist.empty then
  246. break;
  247. hpropsym:=hpropsym.overriddenpropsym;
  248. until not assigned(hpropsym);
  249. if not(assigned(propaccesslist) and assigned(propaccesslist.firstsym)) then
  250. begin
  251. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,unsetvalue));
  252. typvalue:=3;
  253. end
  254. else if propaccesslist.firstsym^.sym.typ=fieldvarsym then
  255. begin
  256. address:=0;
  257. hp:=propaccesslist.firstsym;
  258. def:=nil;
  259. while assigned(hp) do
  260. begin
  261. case hp^.sltype of
  262. sl_load :
  263. begin
  264. def:=tfieldvarsym(hp^.sym).vardef;
  265. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  266. end;
  267. sl_subscript :
  268. begin
  269. if not(assigned(def) and
  270. ((def.typ=recorddef) or
  271. is_object(def))) then
  272. internalerror(200402171);
  273. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  274. def:=tfieldvarsym(hp^.sym).vardef;
  275. end;
  276. sl_vec :
  277. begin
  278. if not(assigned(def) and (def.typ=arraydef)) then
  279. internalerror(200402172);
  280. def:=tarraydef(def).elementdef;
  281. {Hp.value is a Tconstexprint, which can be rather large,
  282. sanity check for longint overflow.}
  283. space:=(high(address)-address) div def.size;
  284. if int64(space)<hp^.value then
  285. internalerror(200706101);
  286. inc(address,int64(def.size*hp^.value));
  287. end;
  288. end;
  289. hp:=hp^.next;
  290. end;
  291. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,address));
  292. typvalue:=0;
  293. end
  294. else
  295. begin
  296. { When there was an error then procdef is not assigned }
  297. if not assigned(propaccesslist.procdef) then
  298. exit;
  299. if not(po_virtualmethod in tprocdef(propaccesslist.procdef).procoptions) then
  300. begin
  301. current_asmdata.asmlists[al_rtti].concat(Tai_const.createname(tprocdef(propaccesslist.procdef).mangledname,0));
  302. typvalue:=1;
  303. end
  304. else
  305. begin
  306. { virtual method, write vmt offset }
  307. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,
  308. tobjectdef(tprocdef(propaccesslist.procdef).struct).vmtmethodoffset(tprocdef(propaccesslist.procdef).extnumber)));
  309. { register for wpo }
  310. tobjectdef(tprocdef(propaccesslist.procdef).struct).register_vmt_call(tprocdef(propaccesslist.procdef).extnumber);
  311. {$ifdef vtentry}
  312. { not sure if we can insert those vtentry symbols safely here }
  313. {$error register methods used for published properties}
  314. {$endif vtentry}
  315. typvalue:=2;
  316. end;
  317. end;
  318. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  319. end;
  320. begin
  321. for i:=0 to st.SymList.Count-1 do
  322. begin
  323. sym:=tsym(st.SymList[i]);
  324. if (sym.typ=propertysym) and
  325. (sym.visibility=vis_published) then
  326. begin
  327. if ppo_indexed in tpropertysym(sym).propoptions then
  328. proctypesinfo:=$40
  329. else
  330. proctypesinfo:=0;
  331. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(tpropertysym(sym).propdef,fullrtti)));
  332. writeaccessproc(palt_read,0,0);
  333. writeaccessproc(palt_write,2,0);
  334. { is it stored ? }
  335. if not(ppo_stored in tpropertysym(sym).propoptions) then
  336. begin
  337. { no, so put a constant zero }
  338. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,0));
  339. proctypesinfo:=proctypesinfo or (3 shl 4);
  340. end
  341. else
  342. writeaccessproc(palt_stored,4,1); { maybe; if no procedure put a constant 1 (=true) }
  343. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  344. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  345. propnameitem:=TPropNameListItem(propnamelist.Find(tpropertysym(sym).name));
  346. if not assigned(propnameitem) then
  347. internalerror(200512201);
  348. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(propnameitem.propindex));
  349. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(proctypesinfo));
  350. write_string(tpropertysym(sym).realname);
  351. maybe_write_align;
  352. end;
  353. end;
  354. end;
  355. procedure TRTTIWriter.write_rtti_data(def:tdef;rt:trttitype);
  356. procedure unknown_rtti(def:tstoreddef);
  357. begin
  358. current_asmdata.asmlists[al_rtti].concat(tai_const.create_8bit(tkUnknown));
  359. write_rtti_name(def);
  360. end;
  361. procedure variantdef_rtti(def:tvariantdef);
  362. begin
  363. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkVariant));
  364. end;
  365. procedure stringdef_rtti(def:tstringdef);
  366. begin
  367. case def.stringtype of
  368. st_ansistring:
  369. write_header(def,tkAString);
  370. st_widestring:
  371. write_header(def,tkWString);
  372. st_unicodestring:
  373. write_header(def,tkUString);
  374. st_longstring:
  375. write_header(def,tkLString);
  376. st_shortstring:
  377. begin
  378. write_header(def,tkSString);
  379. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(def.len));
  380. maybe_write_align; // is align necessary here?
  381. end;
  382. end;
  383. end;
  384. procedure enumdef_rtti(def:tenumdef);
  385. var
  386. i : integer;
  387. hp : tenumsym;
  388. begin
  389. write_header(def,tkEnumeration);
  390. maybe_write_align;
  391. case longint(def.size) of
  392. 1 :
  393. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUByte));
  394. 2 :
  395. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUWord));
  396. 4 :
  397. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
  398. end;
  399. { we need to align by Tconstptruint here to satisfy the alignment rules set by
  400. records: in the typinfo unit we overlay a TTypeData record on this data, which at
  401. the innermost variant record needs an alignment of TConstPtrUint due to e.g.
  402. the "CompType" member for tkSet (also the "BaseType" member for tkEnumeration).
  403. We need to adhere to this, otherwise things will break.
  404. Note that other code (e.g. enumdef_rtti_calcstringtablestart()) relies on the
  405. exact sequence too. }
  406. maybe_write_align;
  407. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.min));
  408. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.max));
  409. maybe_write_align; // is align necessary here?
  410. { write base type }
  411. if assigned(def.basedef) then
  412. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.basedef,rt)))
  413. else
  414. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  415. for i := 0 to def.symtable.SymList.Count - 1 do
  416. begin
  417. hp:=tenumsym(def.symtable.SymList[i]);
  418. if hp.value<def.minval then
  419. continue
  420. else
  421. if hp.value>def.maxval then
  422. break;
  423. write_string(hp.realname);
  424. end;
  425. { write unit name }
  426. write_string(current_module.realmodulename^);
  427. end;
  428. procedure orddef_rtti(def:torddef);
  429. procedure dointeger(typekind: byte);
  430. const
  431. trans : array[tordtype] of byte =
  432. (otUByte{otNone},
  433. otUByte,otUWord,otULong,otUByte{otNone},
  434. otSByte,otSWord,otSLong,otUByte{otNone},
  435. otUByte,otSByte,otSWord,otSLong,otSByte,
  436. otUByte,otUWord,otUByte);
  437. begin
  438. write_header(def,typekind);
  439. maybe_write_align;
  440. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(byte(trans[def.ordtype])));
  441. maybe_write_align;
  442. {Convert to longint to smuggle values in high(longint)+1..high(cardinal) into asmlist.}
  443. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.low.svalue)));
  444. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.high.svalue)));
  445. end;
  446. begin
  447. case def.ordtype of
  448. s64bit :
  449. begin
  450. write_header(def,tkInt64);
  451. maybe_write_align;
  452. { low }
  453. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.low.svalue));
  454. { high }
  455. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.high.svalue));
  456. end;
  457. u64bit :
  458. begin
  459. write_header(def,tkQWord);
  460. maybe_write_align;
  461. {use svalue because Create_64bit accepts int64, prevents range checks}
  462. { low }
  463. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.low.svalue));
  464. { high }
  465. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.high.svalue));
  466. end;
  467. pasbool:
  468. dointeger(tkBool);
  469. uchar:
  470. dointeger(tkChar);
  471. uwidechar:
  472. dointeger(tkWChar);
  473. scurrency:
  474. begin
  475. write_header(def,tkFloat);
  476. maybe_write_align;
  477. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(ftCurr));
  478. end;
  479. else
  480. dointeger(tkInteger);
  481. end;
  482. end;
  483. procedure floatdef_rtti(def:tfloatdef);
  484. const
  485. {tfloattype = (s32real,s64real,s80real,sc80real,s64bit,s128bit);}
  486. translate : array[tfloattype] of byte =
  487. (ftSingle,ftDouble,ftExtended,ftExtended,ftComp,ftCurr,ftFloat128);
  488. begin
  489. write_header(def,tkFloat);
  490. maybe_write_align;
  491. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(translate[def.floattype]));
  492. end;
  493. procedure setdef_rtti(def:tsetdef);
  494. begin
  495. write_header(def,tkSet);
  496. maybe_write_align;
  497. case def.size of
  498. 1:
  499. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUByte));
  500. 2:
  501. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUWord));
  502. 4:
  503. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
  504. else
  505. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUByte));
  506. end;
  507. maybe_write_align;
  508. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)));
  509. end;
  510. procedure arraydef_rtti(def:tarraydef);
  511. begin
  512. if ado_IsDynamicArray in def.arrayoptions then
  513. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkdynarray))
  514. else
  515. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkarray));
  516. write_rtti_name(def);
  517. maybe_write_align;
  518. { size of elements }
  519. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_pint(def.elesize));
  520. if not(ado_IsDynamicArray in def.arrayoptions) then
  521. begin
  522. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_pint(pint(def.elecount)));
  523. { element type }
  524. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)));
  525. end
  526. else
  527. { write a delphi almost compatible dyn. array entry:
  528. there are two types, eltype and eltype2, the latter is nil if the element type needs
  529. no finalization, the former is always valid, delphi has this swapped, but for
  530. compatibility with older fpc versions we do it different, to be delphi compatible,
  531. the names are swapped in typinfo.pp
  532. }
  533. begin
  534. { element type }
  535. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)));
  536. end;
  537. { variant type }
  538. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tstoreddef(def.elementdef).getvardef));
  539. if ado_IsDynamicArray in def.arrayoptions then
  540. begin
  541. { element type }
  542. if def.elementdef.needs_inittable then
  543. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)))
  544. else
  545. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_pint(0));
  546. { write unit name }
  547. write_string(current_module.realmodulename^);
  548. end;
  549. end;
  550. procedure recorddef_rtti(def:trecorddef);
  551. var
  552. fieldcnt : longint;
  553. begin
  554. write_header(def,tkRecord);
  555. maybe_write_align;
  556. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
  557. fieldcnt:=fields_count(def.symtable,rt);
  558. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(fieldcnt));
  559. fields_write_rtti_data(def.symtable,rt);
  560. end;
  561. procedure procvardef_rtti(def:tprocvardef);
  562. const
  563. ProcCallOptionToCallConv: array[tproccalloption] of byte = (
  564. { pocall_none } 0,
  565. { pocall_cdecl } 1,
  566. { pocall_cppdecl } 5,
  567. { pocall_far16 } 6,
  568. { pocall_oldfpccall } 7,
  569. { pocall_internproc } 8,
  570. { pocall_syscall } 9,
  571. { pocall_pascal } 2,
  572. { pocall_register } 0,
  573. { pocall_safecall } 4,
  574. { pocall_stdcall } 3,
  575. { pocall_softfloat } 10,
  576. { pocall_mwpascal } 11
  577. );
  578. procedure write_para(parasym:tparavarsym);
  579. var
  580. paraspec : byte;
  581. begin
  582. { only store user visible parameters }
  583. if not(vo_is_hidden_para in parasym.varoptions) then
  584. begin
  585. case parasym.varspez of
  586. vs_value : paraspec := 0;
  587. vs_const : paraspec := pfConst;
  588. vs_var : paraspec := pfVar;
  589. vs_out : paraspec := pfOut;
  590. vs_constref: paraspec := pfConstRef;
  591. end;
  592. { Kylix also seems to always add both pfArray and pfReference
  593. in this case
  594. }
  595. if is_open_array(parasym.vardef) then
  596. paraspec:=paraspec or pfArray or pfReference;
  597. { and these for classes and interfaces (maybe because they
  598. are themselves addresses?)
  599. }
  600. if is_class_or_interface(parasym.vardef) then
  601. paraspec:=paraspec or pfAddress;
  602. { set bits run from the highest to the lowest bit on
  603. big endian systems
  604. }
  605. if (target_info.endian = endian_big) then
  606. paraspec:=reverse_byte(paraspec);
  607. { write flags for current parameter }
  608. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(paraspec));
  609. { write name of current parameter }
  610. write_string(parasym.realname);
  611. { write name of type of current parameter }
  612. write_rtti_name(parasym.vardef);
  613. end;
  614. end;
  615. var
  616. methodkind : byte;
  617. i : integer;
  618. begin
  619. if po_methodpointer in def.procoptions then
  620. begin
  621. { write method id and name }
  622. write_header(def,tkMethod);
  623. maybe_write_align;
  624. { write kind of method }
  625. case def.proctypeoption of
  626. potype_constructor: methodkind:=mkConstructor;
  627. potype_destructor: methodkind:=mkDestructor;
  628. potype_class_constructor: methodkind:=mkClassConstructor;
  629. potype_class_destructor: methodkind:=mkClassDestructor;
  630. potype_procedure:
  631. if po_classmethod in def.procoptions then
  632. methodkind:=mkClassProcedure
  633. else
  634. methodkind:=mkProcedure;
  635. potype_function:
  636. if po_classmethod in def.procoptions then
  637. methodkind:=mkClassFunction
  638. else
  639. methodkind:=mkFunction;
  640. else
  641. begin
  642. if def.returndef = voidtype then
  643. methodkind:=mkProcedure
  644. else
  645. methodkind:=mkFunction;
  646. end;
  647. end;
  648. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(methodkind));
  649. { write parameter info. The parameters must be written in reverse order
  650. if this method uses right to left parameter pushing! }
  651. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(def.maxparacount));
  652. for i:=0 to def.paras.count-1 do
  653. write_para(tparavarsym(def.paras[i]));
  654. if (methodkind=mkFunction) or (methodkind=mkClassFunction) then
  655. begin
  656. { write name of result type }
  657. write_rtti_name(def.returndef);
  658. maybe_write_align;
  659. { write result typeinfo }
  660. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.returndef,fullrtti)))
  661. end;
  662. { write calling convention }
  663. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(ProcCallOptionToCallConv[def.proccalloption]));
  664. maybe_write_align;
  665. { write params typeinfo }
  666. for i:=0 to def.paras.count-1 do
  667. if not(vo_is_hidden_para in tparavarsym(def.paras[i]).varoptions) then
  668. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(tparavarsym(def.paras[i]).vardef,fullrtti)));
  669. end
  670. else
  671. write_header(def,tkProcvar);
  672. end;
  673. procedure objectdef_rtti(def:tobjectdef);
  674. procedure objectdef_rtti_class_init(def:tobjectdef);
  675. begin
  676. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
  677. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(fields_count(def.symtable,rt)));
  678. fields_write_rtti_data(def.symtable,rt);
  679. end;
  680. procedure objectdef_rtti_interface_init(def:tobjectdef);
  681. begin
  682. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
  683. end;
  684. procedure objectdef_rtti_class_full(def:tobjectdef);
  685. var
  686. propnamelist : TFPHashObjectList;
  687. begin
  688. { Collect unique property names with nameindex }
  689. propnamelist:=TFPHashObjectList.Create;
  690. collect_propnamelist(propnamelist,def);
  691. if (oo_has_vmt in def.objectoptions) then
  692. current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(def.vmt_mangledname,0))
  693. else
  694. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  695. { write parent typeinfo }
  696. if assigned(def.childof) then
  697. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.childof,fullrtti)))
  698. else
  699. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  700. { total number of unique properties }
  701. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(propnamelist.count));
  702. { write unit name }
  703. write_string(current_module.realmodulename^);
  704. maybe_write_align;
  705. { write published properties for this object }
  706. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(published_properties_count(def.symtable)));
  707. maybe_write_align;
  708. published_properties_write_rtti_data(propnamelist,def.symtable);
  709. propnamelist.free;
  710. end;
  711. procedure objectdef_rtti_interface_full(def:tobjectdef);
  712. var
  713. i : longint;
  714. propnamelist : TFPHashObjectList;
  715. { if changed to a set, make sure it's still a byte large, and
  716. swap appropriately when cross-compiling
  717. }
  718. IntfFlags: byte;
  719. begin
  720. { Collect unique property names with nameindex }
  721. propnamelist:=TFPHashObjectList.Create;
  722. collect_propnamelist(propnamelist,def);
  723. { write parent typeinfo }
  724. if assigned(def.childof) then
  725. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.childof,fullrtti)))
  726. else
  727. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  728. { interface: write flags, iid and iidstr }
  729. IntfFlags:=0;
  730. if assigned(def.iidguid) then
  731. IntfFlags:=IntfFlags or (1 shl ord(ifHasGuid));
  732. if assigned(def.iidstr) then
  733. IntfFlags:=IntfFlags or (1 shl ord(ifHasStrGUID));
  734. if (def.objecttype=odt_dispinterface) then
  735. IntfFlags:=IntfFlags or (1 shl ord(ifDispInterface));
  736. if (target_info.endian=endian_big) then
  737. IntfFlags:=reverse_byte(IntfFlags);
  738. {
  739. ifDispatch, }
  740. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(IntfFlags));
  741. maybe_write_align;
  742. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.iidguid^.D1)));
  743. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(def.iidguid^.D2));
  744. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(def.iidguid^.D3));
  745. for i:=Low(def.iidguid^.D4) to High(def.iidguid^.D4) do
  746. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(def.iidguid^.D4[i]));
  747. { write unit name }
  748. write_string(current_module.realmodulename^);
  749. maybe_write_align;
  750. { write iidstr }
  751. if assigned(def.iidstr) then
  752. write_string(def.iidstr^)
  753. else
  754. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(0));
  755. maybe_write_align;
  756. { write published properties for this object }
  757. published_properties_write_rtti_data(propnamelist,def.symtable);
  758. propnamelist.free;
  759. end;
  760. begin
  761. case def.objecttype of
  762. odt_class:
  763. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkclass));
  764. odt_object:
  765. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkobject));
  766. odt_dispinterface,
  767. odt_interfacecom:
  768. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkinterface));
  769. odt_interfacecorba:
  770. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkinterfaceCorba));
  771. else
  772. internalerror(200611034);
  773. end;
  774. { generate the name }
  775. write_string(def.objrealname^);
  776. maybe_write_align;
  777. case rt of
  778. initrtti :
  779. begin
  780. if def.objecttype in [odt_class,odt_object] then
  781. objectdef_rtti_class_init(def)
  782. else
  783. objectdef_rtti_interface_init(def);
  784. end;
  785. fullrtti :
  786. begin
  787. if def.objecttype in [odt_class,odt_object] then
  788. objectdef_rtti_class_full(def)
  789. else
  790. objectdef_rtti_interface_full(def);
  791. end;
  792. end;
  793. end;
  794. begin
  795. case def.typ of
  796. variantdef :
  797. variantdef_rtti(tvariantdef(def));
  798. stringdef :
  799. stringdef_rtti(tstringdef(def));
  800. enumdef :
  801. enumdef_rtti(tenumdef(def));
  802. orddef :
  803. orddef_rtti(torddef(def));
  804. floatdef :
  805. floatdef_rtti(tfloatdef(def));
  806. setdef :
  807. setdef_rtti(tsetdef(def));
  808. procvardef :
  809. procvardef_rtti(tprocvardef(def));
  810. arraydef :
  811. begin
  812. if ado_IsBitPacked in tarraydef(def).arrayoptions then
  813. unknown_rtti(tstoreddef(def))
  814. else
  815. arraydef_rtti(tarraydef(def));
  816. end;
  817. recorddef :
  818. begin
  819. if trecorddef(def).is_packed then
  820. unknown_rtti(tstoreddef(def))
  821. else
  822. recorddef_rtti(trecorddef(def));
  823. end;
  824. objectdef :
  825. objectdef_rtti(tobjectdef(def));
  826. else
  827. unknown_rtti(tstoreddef(def));
  828. end;
  829. end;
  830. procedure TRTTIWriter.write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
  831. type Penumsym = ^Tenumsym;
  832. function enumdef_rtti_calcstringtablestart(const def : Tenumdef) : integer;
  833. begin
  834. { the alignment calls must correspond to the ones used during generating the
  835. actual data structure created elsewhere in this file }
  836. result:=1;
  837. if assigned(def.typesym) then
  838. inc(result,length(def.typesym.realname)+1)
  839. else
  840. inc(result);
  841. if (tf_requires_proper_alignment in target_info.flags) then
  842. result:=align(result,sizeof(Tconstptruint));
  843. inc(result);
  844. if (tf_requires_proper_alignment in target_info.flags) then
  845. result:=align(result,sizeof(Tconstptruint));
  846. inc(result, sizeof(longint) * 2);
  847. if (tf_requires_proper_alignment in target_info.flags) then
  848. result:=align(result,sizeof(Tconstptruint));
  849. inc(result, sizeof(pint));
  850. end;
  851. { Writes a helper table for accelerated conversion of ordinal enum values to strings.
  852. If you change something in this method, make sure to adapt the corresponding code
  853. in sstrings.inc. }
  854. procedure enumdef_rtti_ord2stringindex(const sym_count:longint; const offsets:plongint; const syms:Penumsym; const st:longint);
  855. var rttilab:Tasmsymbol;
  856. h,i,o:longint;
  857. mode:(lookup,search); {Modify with care, ordinal value of enum is written.}
  858. r:single; {Must be real type because of integer overflow risk.}
  859. begin
  860. {Decide wether a lookup array is size efficient.}
  861. mode:=lookup;
  862. if sym_count>0 then
  863. begin
  864. i:=1;
  865. r:=0;
  866. h:=syms[0].value; {Next expected enum value is min.}
  867. while i<sym_count do
  868. begin
  869. {Calculate size of hole between values. Avoid integer overflows.}
  870. r:=r+(single(syms[i].value)-single(h))-1;
  871. h:=syms[i].value;
  872. inc(i);
  873. end;
  874. if r>sym_count then
  875. mode:=search; {Don't waste more than 50% space.}
  876. end;
  877. { write rtti data; make sure that the alignment matches the corresponding data structure
  878. in the code that uses it (if alignment is required). }
  879. with current_asmdata do
  880. begin
  881. rttilab:=defineasmsymbol(Tstoreddef(def).rtti_mangledname(rt)+'_o2s',AB_GLOBAL,AT_DATA);
  882. maybe_new_object_file(asmlists[al_rtti]);
  883. new_section(asmlists[al_rtti],sec_rodata,rttilab.name,const_align(sizeof(pint)));
  884. asmlists[al_rtti].concat(Tai_symbol.create_global(rttilab,0));
  885. asmlists[al_rtti].concat(Tai_const.create_32bit(longint(mode)));
  886. if mode=lookup then
  887. begin
  888. maybe_write_align;
  889. o:=syms[0].value; {Start with min value.}
  890. for i:=0 to sym_count-1 do
  891. begin
  892. while o<syms[i].value do
  893. begin
  894. asmlists[al_rtti].concat(Tai_const.create_pint(0));
  895. inc(o);
  896. end;
  897. inc(o);
  898. asmlists[al_rtti].concat(Tai_const.create_sym_offset(mainrtti,st+offsets[i]));
  899. end;
  900. end
  901. else
  902. begin
  903. maybe_write_align;
  904. asmlists[al_rtti].concat(Tai_const.create_32bit(sym_count));
  905. for i:=0 to sym_count-1 do
  906. begin
  907. maybe_write_align;
  908. asmlists[al_rtti].concat(Tai_const.create_32bit(syms[i].value));
  909. maybe_write_align;
  910. asmlists[al_rtti].concat(Tai_const.create_sym_offset(mainrtti,st+offsets[i]));
  911. end;
  912. end;
  913. asmlists[al_rtti].concat(Tai_symbol_end.create(rttilab));
  914. end;
  915. end;
  916. { Writes a helper table for accelerated conversion of string to ordinal enum values.
  917. If you change something in this method, make sure to adapt the corresponding code
  918. in sstrings.inc. }
  919. procedure enumdef_rtti_string2ordindex(const sym_count:longint; const offsets:plongint; const syms:Penumsym; const st:longint);
  920. var rttilab:Tasmsymbol;
  921. i:longint;
  922. begin
  923. { write rtti data }
  924. with current_asmdata do
  925. begin
  926. rttilab:=defineasmsymbol(Tstoreddef(def).rtti_mangledname(rt)+'_s2o',AB_GLOBAL,AT_DATA);
  927. maybe_new_object_file(asmlists[al_rtti]);
  928. new_section(asmlists[al_rtti],sec_rodata,rttilab.name,const_align(sizeof(pint)));
  929. asmlists[al_rtti].concat(Tai_symbol.create_global(rttilab,0));
  930. asmlists[al_rtti].concat(Tai_const.create_32bit(sym_count));
  931. { need to align the entry record according to the largest member }
  932. maybe_write_align;
  933. for i:=0 to sym_count-1 do
  934. begin
  935. if (tf_requires_proper_alignment in target_info.flags) then
  936. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(4)); // necessary?
  937. asmlists[al_rtti].concat(Tai_const.create_32bit(syms[i].value));
  938. maybe_write_align;
  939. asmlists[al_rtti].concat(Tai_const.create_sym_offset(mainrtti,st+offsets[i]));
  940. end;
  941. asmlists[al_rtti].concat(Tai_symbol_end.create(rttilab));
  942. end;
  943. end;
  944. procedure enumdef_rtti_extrasyms(def:Tenumdef);
  945. var
  946. t:Tenumsym;
  947. syms:Penumsym;
  948. sym_count,sym_alloc:sizeuint;
  949. offsets:^longint;
  950. h,i,p,o,st:longint;
  951. begin
  952. {Random access needed, put in array.}
  953. getmem(syms,64*sizeof(Tenumsym));
  954. getmem(offsets,64*sizeof(longint));
  955. sym_count:=0;
  956. sym_alloc:=64;
  957. st:=0;
  958. for i := 0 to def.symtable.SymList.Count - 1 do
  959. begin
  960. t:=tenumsym(def.symtable.SymList[i]);
  961. if t.value<def.minval then
  962. continue
  963. else
  964. if t.value>def.maxval then
  965. break;
  966. if sym_count>=sym_alloc then
  967. begin
  968. reallocmem(syms,2*sym_alloc*sizeof(Tenumsym));
  969. reallocmem(offsets,2*sym_alloc*sizeof(longint));
  970. sym_alloc:=sym_alloc*2;
  971. end;
  972. syms[sym_count]:=t;
  973. offsets[sym_count]:=st;
  974. inc(sym_count);
  975. st:=st+length(t.realname)+1;
  976. end;
  977. {Sort the syms by enum name}
  978. if sym_count>=2 then
  979. begin
  980. p:=1;
  981. while 2*p<sym_count do
  982. p:=2*p;
  983. while p<>0 do
  984. begin
  985. for h:=p to sym_count-1 do
  986. begin
  987. i:=h;
  988. t:=syms[i];
  989. o:=offsets[i];
  990. repeat
  991. if syms[i-p].name<=t.name then
  992. break;
  993. syms[i]:=syms[i-p];
  994. offsets[i]:=offsets[i-p];
  995. dec(i,p);
  996. until i<p;
  997. syms[i]:=t;
  998. offsets[i]:=o;
  999. end;
  1000. p:=p shr 1;
  1001. end;
  1002. end;
  1003. st:=enumdef_rtti_calcstringtablestart(def);
  1004. enumdef_rtti_string2ordindex(sym_count,offsets,syms,st);
  1005. { Sort the syms by enum value }
  1006. if sym_count>=2 then
  1007. begin
  1008. p:=1;
  1009. while 2*p<sym_count do
  1010. p:=2*p;
  1011. while p<>0 do
  1012. begin
  1013. for h:=p to sym_count-1 do
  1014. begin
  1015. i:=h;
  1016. t:=syms[i];
  1017. o:=offsets[i];
  1018. repeat
  1019. if syms[i-p].value<=t.value then
  1020. break;
  1021. syms[i]:=syms[i-p];
  1022. offsets[i]:=offsets[i-p];
  1023. dec(i,p);
  1024. until i<p;
  1025. syms[i]:=t;
  1026. offsets[i]:=o;
  1027. end;
  1028. p:=p shr 1;
  1029. end;
  1030. end;
  1031. enumdef_rtti_ord2stringindex(sym_count,offsets,syms,st);
  1032. freemem(syms);
  1033. freemem(offsets);
  1034. end;
  1035. begin
  1036. case def.typ of
  1037. enumdef:
  1038. if rt=fullrtti then
  1039. begin
  1040. enumdef_rtti_extrasyms(Tenumdef(def));
  1041. end;
  1042. end;
  1043. end;
  1044. procedure TRTTIWriter.write_child_rtti_data(def:tdef;rt:trttitype);
  1045. begin
  1046. case def.typ of
  1047. enumdef :
  1048. if assigned(tenumdef(def).basedef) then
  1049. write_rtti(tenumdef(def).basedef,rt);
  1050. setdef :
  1051. write_rtti(tsetdef(def).elementdef,rt);
  1052. arraydef :
  1053. write_rtti(tarraydef(def).elementdef,rt);
  1054. recorddef :
  1055. fields_write_rtti(trecorddef(def).symtable,rt);
  1056. objectdef :
  1057. begin
  1058. if assigned(tobjectdef(def).childof) then
  1059. write_rtti(tobjectdef(def).childof,rt);
  1060. if rt=initrtti then
  1061. fields_write_rtti(tobjectdef(def).symtable,rt)
  1062. else
  1063. published_write_rtti(tobjectdef(def).symtable,rt);
  1064. end;
  1065. end;
  1066. end;
  1067. function TRTTIWriter.ref_rtti(def:tdef;rt:trttitype):tasmsymbol;
  1068. begin
  1069. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt));
  1070. end;
  1071. procedure TRTTIWriter.write_rtti(def:tdef;rt:trttitype);
  1072. var
  1073. rttilab : tasmsymbol;
  1074. begin
  1075. { only write rtti of definitions from the current module }
  1076. if not findunitsymtable(def.owner).iscurrentunit then
  1077. exit;
  1078. { prevent recursion }
  1079. if rttidefstate[rt] in def.defstates then
  1080. exit;
  1081. include(def.defstates,rttidefstate[rt]);
  1082. { write first all dependencies }
  1083. write_child_rtti_data(def,rt);
  1084. { write rtti data }
  1085. rttilab:=current_asmdata.DefineAsmSymbol(tstoreddef(def).rtti_mangledname(rt),AB_GLOBAL,AT_DATA);
  1086. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  1087. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,rttilab.name,const_align(sizeof(pint)));
  1088. current_asmdata.asmlists[al_rtti].concat(Tai_symbol.Create_global(rttilab,0));
  1089. write_rtti_data(def,rt);
  1090. current_asmdata.asmlists[al_rtti].concat(Tai_symbol_end.Create(rttilab));
  1091. write_rtti_extrasyms(def,rt,rttilab);
  1092. end;
  1093. function TRTTIWriter.get_rtti_label(def:tdef;rt:trttitype):tasmsymbol;
  1094. begin
  1095. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt));
  1096. end;
  1097. function TRTTIWriter.get_rtti_label_ord2str(def:tdef;rt:trttitype):tasmsymbol;
  1098. begin
  1099. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_o2s');
  1100. end;
  1101. function TRTTIWriter.get_rtti_label_str2ord(def:tdef;rt:trttitype):tasmsymbol;
  1102. begin
  1103. result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_s2o');
  1104. end;
  1105. end.