ncgrtti.pas 67 KB

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