ncgrtti.pas 67 KB

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