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