ncgrtti.pas 47 KB

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