ncgrtti.pas 46 KB

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