ncgrtti.pas 47 KB

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