nobj.pas 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Routines for the code generation of data structures
  4. like VMT, Messages, VTables, Interfaces descs
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nobj;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cutils,cclasses,
  23. globtype,
  24. symdef,symsym,
  25. aasmbase,aasmtai,aasmdata
  26. ;
  27. type
  28. TVMTBuilder=class
  29. private
  30. _Class : tobjectdef;
  31. handledprotocols: tfpobjectlist;
  32. function is_new_vmt_entry(pd:tprocdef; out overridesclasshelper: boolean):boolean;
  33. procedure add_new_vmt_entry(pd:tprocdef; allowoverridingmethod: boolean);
  34. function check_msg_str(vmtpd, pd: tprocdef):boolean;
  35. function intf_search_procdef_by_name(proc: tprocdef;const name: string): tprocdef;
  36. procedure intf_get_procdefs(ImplIntf:TImplementedInterface;IntfDef:TObjectDef);
  37. procedure intf_get_procdefs_recursive(ImplIntf:TImplementedInterface;IntfDef:TObjectDef);
  38. procedure prot_get_procdefs_recursive(ImplProt:TImplementedInterface;ProtDef:TObjectDef);
  39. procedure intf_optimize_vtbls;
  40. procedure intf_allocate_vtbls;
  41. public
  42. constructor create(c:tobjectdef);
  43. destructor destroy;override;
  44. procedure generate_vmt;
  45. procedure build_interface_mappings;
  46. end;
  47. type
  48. pprocdeftree = ^tprocdeftree;
  49. tprocdeftree = record
  50. data : tprocdef;
  51. nl : tasmlabel;
  52. l,r : pprocdeftree;
  53. end;
  54. TVMTWriter=class
  55. private
  56. _Class : tobjectdef;
  57. { message tables }
  58. root : pprocdeftree;
  59. procedure disposeprocdeftree(p : pprocdeftree);
  60. procedure insertmsgint(p:TObject;arg:pointer);
  61. procedure insertmsgstr(p:TObject;arg:pointer);
  62. procedure insertint(p : pprocdeftree;var at : pprocdeftree;var count:longint);
  63. procedure insertstr(p : pprocdeftree;var at : pprocdeftree;var count:longint);
  64. procedure writenames(p : pprocdeftree);
  65. procedure writeintentry(p : pprocdeftree);
  66. procedure writestrentry(p : pprocdeftree);
  67. {$ifdef WITHDMT}
  68. { dmt }
  69. procedure insertdmtentry(p:TObject;arg:pointer);
  70. procedure writedmtindexentry(p : pprocdeftree);
  71. procedure writedmtaddressentry(p : pprocdeftree);
  72. {$endif}
  73. { published methods }
  74. procedure do_count_published_methods(p:TObject;arg:pointer);
  75. procedure do_gen_published_methods(p:TObject;arg:pointer);
  76. { virtual methods }
  77. procedure writevirtualmethods(List:TAsmList);
  78. { interface tables }
  79. function intf_get_vtbl_name(AImplIntf:TImplementedInterface): string;
  80. procedure intf_create_vtbl(rawdata: TAsmList;AImplIntf:TImplementedInterface);
  81. procedure intf_gen_intf_ref(rawdata: TAsmList;AImplIntf:TImplementedInterface);
  82. function intf_write_table:TAsmLabel;
  83. { generates the message tables for a class }
  84. function genstrmsgtab : tasmlabel;
  85. function genintmsgtab : tasmlabel;
  86. function genpublishedmethodstable : tasmlabel;
  87. function generate_field_table : tasmlabel;
  88. {$ifdef WITHDMT}
  89. { generates a DMT for _class }
  90. function gendmt : tasmlabel;
  91. {$endif WITHDMT}
  92. public
  93. constructor create(c:tobjectdef);
  94. destructor destroy;override;
  95. { write the VMT to al_globals }
  96. procedure writevmt;
  97. procedure writeinterfaceids;
  98. end;
  99. implementation
  100. uses
  101. SysUtils,
  102. globals,verbose,systems,
  103. node,
  104. symbase,symtable,symconst,symtype,defcmp,
  105. dbgbase,
  106. ncgrtti,
  107. wpobase
  108. ;
  109. {*****************************************************************************
  110. TVMTBuilder
  111. *****************************************************************************}
  112. constructor TVMTBuilder.create(c:tobjectdef);
  113. begin
  114. inherited Create;
  115. _Class:=c;
  116. end;
  117. destructor TVMTBuilder.destroy;
  118. begin
  119. end;
  120. procedure TVMTBuilder.add_new_vmt_entry(pd:tprocdef; allowoverridingmethod: boolean);
  121. var
  122. i : longint;
  123. vmtentry : pvmtentry;
  124. vmtpd : tprocdef;
  125. begin
  126. { new entry is needed, override was not possible }
  127. { Allowed when overriding a category method for a parent class in a
  128. descendent Objective-C class }
  129. if not allowoverridingmethod and
  130. (po_overridingmethod in pd.procoptions) then
  131. MessagePos1(pd.fileinfo,parser_e_nothing_to_be_overridden,pd.fullprocname(false));
  132. { check that all methods have overload directive }
  133. if not(m_fpc in current_settings.modeswitches) then
  134. begin
  135. for i:=0 to _class.vmtentries.count-1 do
  136. begin
  137. vmtentry:=pvmtentry(_class.vmtentries[i]);
  138. vmtpd:=tprocdef(vmtentry^.procdef);
  139. if (vmtpd.procsym=pd.procsym) and
  140. (not(po_overload in pd.procoptions) or
  141. not(po_overload in vmtpd.procoptions)) then
  142. begin
  143. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,pd.procsym.realname);
  144. { recover }
  145. include(vmtpd.procoptions,po_overload);
  146. include(pd.procoptions,po_overload);
  147. end;
  148. end;
  149. end;
  150. { Register virtual method and give it a number }
  151. if (po_virtualmethod in pd.procoptions) then
  152. begin
  153. { store vmt entry number in procdef }
  154. if (pd.extnumber<>$ffff) and
  155. (pd.extnumber<>_class.VMTEntries.Count) then
  156. internalerror(200810283);
  157. pd.extnumber:=_class.VMTEntries.Count;
  158. new(vmtentry);
  159. vmtentry^.procdef:=pd;
  160. vmtentry^.procdefderef.reset;
  161. vmtentry^.visibility:=pd.visibility;
  162. _class.VMTEntries.Add(vmtentry);
  163. end;
  164. end;
  165. function TVMTBuilder.check_msg_str(vmtpd, pd: tprocdef): boolean;
  166. begin
  167. result:=true;
  168. if not(is_objc_class_or_protocol(_class)) then
  169. begin
  170. { the only requirement for normal methods is that both either
  171. have a message string or not (the value is irrelevant) }
  172. if ((pd.procoptions * [po_msgstr]) <> (vmtpd.procoptions * [po_msgstr])) then
  173. begin
  174. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,pd.fullprocname(false));
  175. tprocsym(vmtpd.procsym).write_parameter_lists(pd);
  176. result:=false;
  177. end
  178. end
  179. else
  180. begin
  181. { the compiler should have ensured that the protocol or parent
  182. class method has a message name specified }
  183. if not(po_msgstr in vmtpd.procoptions) then
  184. internalerror(2009070601);
  185. if not(po_msgstr in pd.procoptions) then
  186. begin
  187. { copy the protocol's/parent class' message name to the one in
  188. the class if none has been specified there }
  189. include(pd.procoptions,po_msgstr);
  190. pd.messageinf.str:=stringdup(vmtpd.messageinf.str^);
  191. end
  192. else
  193. begin
  194. { if both have a message name, make sure they are equal }
  195. if (vmtpd.messageinf.str^<>pd.messageinf.str^) then
  196. begin
  197. MessagePos2(pd.fileinfo,parser_e_objc_message_name_changed,vmtpd.messageinf.str^,pd.messageinf.str^);
  198. result:=false;
  199. end;
  200. end;
  201. end;
  202. end;
  203. function TVMTBuilder.is_new_vmt_entry(pd:tprocdef; out overridesclasshelper: boolean):boolean;
  204. const
  205. po_comp = [po_classmethod,po_virtualmethod,po_staticmethod,po_interrupt,po_iocheck,po_msgint,
  206. po_exports,po_varargs,po_explicitparaloc,po_nostackframe];
  207. var
  208. i : longint;
  209. hasequalpara,
  210. hasoverloads,
  211. pdoverload : boolean;
  212. srsym : tsym;
  213. st : tsymtable;
  214. // returns true if we can stop checking, false if we have to continue
  215. function found_entry(var vmtpd: tprocdef; var vmtentryvis: tvisibility; updatevalues: boolean): boolean;
  216. {$ifdef jvm}
  217. var
  218. javanewtreeok: boolean;
  219. {$endif jvm}
  220. begin
  221. result:=false;
  222. { ignore hidden entries (e.g. virtual overridden by a static) that are not visible anymore }
  223. if vmtentryvis=vis_hidden then
  224. exit;
  225. { ignore different names }
  226. if vmtpd.procsym.name<>pd.procsym.name then
  227. exit;
  228. { hide private methods that are not visible anymore. For this check we
  229. must override the visibility with the highest value in the override chain.
  230. This is required for case (see tw3292) with protected-private-protected where the
  231. same vmtentry is used (PFV) }
  232. if not is_visible_for_object(vmtpd.owner,vmtentryvis,_class) then
  233. exit;
  234. { inherit overload }
  235. if (po_overload in vmtpd.procoptions) then
  236. begin
  237. include(pd.procoptions,po_overload);
  238. pdoverload:=true;
  239. end;
  240. { compare parameter types only, no specifiers yet }
  241. hasequalpara:=(compare_paras(vmtpd.paras,pd.paras,cp_none,[cpo_ignoreuniv,cpo_ignorehidden])>=te_equal);
  242. { check that we are not trying to override a final method }
  243. { in Java, new virtual inheritance trees can never be started ->
  244. treat all methods as "overriding" in the context of this check
  245. (Java does check whether the mangled names are identical, so if they
  246. are not we can stil get away with it) }
  247. if (po_finalmethod in vmtpd.procoptions) and
  248. hasequalpara and
  249. ((po_overridingmethod in pd.procoptions) or
  250. (is_javaclass(_class) and
  251. (pd.mangledname=vmtpd.mangledname))) and
  252. (is_class(_class) or is_objectpascal_helper(_class) or is_javaclass(_class)) then
  253. MessagePos1(pd.fileinfo,parser_e_final_can_no_be_overridden,pd.fullprocname(false))
  254. else
  255. { old definition has virtual
  256. new definition has no virtual or override }
  257. if (po_virtualmethod in vmtpd.procoptions) and
  258. (
  259. not(po_virtualmethod in pd.procoptions) or
  260. (
  261. { new one does not have reintroduce in case of an objccategory }
  262. (is_objccategory(_class) and
  263. not(po_reintroduce in pd.procoptions)) or
  264. { new one does not have override in case of objpas/objc/java class/intf/proto }
  265. ((is_class_or_interface_or_objc_or_java(_class) or is_objectpascal_helper(_class)) and
  266. not is_objccategory(_class) and
  267. not(po_overridingmethod in pd.procoptions)
  268. )
  269. )
  270. ) then
  271. begin
  272. if (
  273. not(pdoverload or hasoverloads) or
  274. hasequalpara
  275. ) then
  276. begin
  277. {$ifdef jvm}
  278. { if the mangled names are different, the inheritance trees
  279. are different too in Java; exception: when the parent method
  280. is a virtual class method or virtual constructor, because
  281. those are looked up dynamicall by name }
  282. javanewtreeok:=
  283. is_java_class_or_interface(_class) and
  284. (pd.jvmmangledbasename(false)<>vmtpd.jvmmangledbasename(false)) and
  285. ((vmtpd.proctypeoption<>potype_constructor) and
  286. not(po_staticmethod in vmtpd.procoptions));
  287. {$endif}
  288. if not(po_reintroduce in pd.procoptions) and
  289. not(po_java_nonvirtual in vmtpd.procoptions) then
  290. if not(is_objc_class_or_protocol(_class))
  291. {$ifdef jvm}
  292. and (not is_java_class_or_interface(_class) or
  293. javanewtreeok)
  294. {$endif jvm}
  295. then
  296. MessagePos1(pd.fileinfo,parser_w_should_use_override,pd.fullprocname(false))
  297. else
  298. begin
  299. { In Objective-C, you cannot create a new VMT entry to
  300. start a new inheritance tree. We therefore give an
  301. error when the class is implemented in Pascal, to
  302. avoid confusion due to things working differently
  303. with Object Pascal classes.
  304. In case of external classes, we only give a hint,
  305. because requiring override everywhere may make
  306. automated header translation tools too complex.
  307. The same goes for Java. }
  308. if not(oo_is_external in _class.objectoptions) then
  309. if not is_objccategory(_class) then
  310. MessagePos1(pd.fileinfo,parser_e_must_use_override,FullTypeName(tdef(vmtpd.owner.defowner),nil))
  311. else
  312. MessagePos1(pd.fileinfo,parser_e_must_use_reintroduce_objc,FullTypeName(tdef(vmtpd.owner.defowner),nil))
  313. { there may be a lot of these in auto-translated
  314. headers, so only calculate the fulltypename if
  315. the hint will be shown }
  316. else if CheckVerbosity(V_Hint) then
  317. if not is_objccategory(_class) then
  318. MessagePos1(pd.fileinfo,parser_h_should_use_override,FullTypeName(tdef(vmtpd.owner.defowner),nil))
  319. else
  320. MessagePos1(pd.fileinfo,parser_h_should_use_reintroduce_objc,FullTypeName(tdef(vmtpd.owner.defowner),nil));
  321. { no new entry, but copy the message name if any from
  322. the procdef in the parent class }
  323. check_msg_str(vmtpd,pd);
  324. if updatevalues then
  325. begin
  326. { in case of Java, copy the real name from the parent,
  327. since overriding "Destroy" with "destroy" is not
  328. going to work very well }
  329. if is_java_class_or_interface(_class) and
  330. (pd.procsym.realname<>vmtpd.procsym.realname) then
  331. pd.procsym.realname:=vmtpd.procsym.realname;
  332. { in case we are overriding an abstract method,
  333. decrease the number of abstract methods in this class }
  334. if (po_abstractmethod in vmtpd.procoptions) then
  335. dec(tobjectdef(pd.owner.defowner).abstractcnt);
  336. if (vmtpd.extnumber<>i) then
  337. internalerror(2011083101);
  338. pd.extnumber:=vmtpd.extnumber;
  339. vmtpd:=pd;
  340. end;
  341. result:=true;
  342. exit;
  343. {$ifdef jvm}
  344. end
  345. else
  346. if not javanewtreeok and
  347. is_java_class_or_interface(_class) then
  348. begin
  349. { mangled names are the same -> can only override }
  350. MessagePos1(pd.fileinfo,parser_e_must_use_override,FullTypeName(tdef(vmtpd.owner.defowner),nil))
  351. {$endif jvm}
  352. end;
  353. { disable/hide old VMT entry }
  354. if updatevalues then
  355. vmtentryvis:=vis_hidden;
  356. end;
  357. end
  358. { both are virtual? }
  359. else if (po_virtualmethod in pd.procoptions) and
  360. (po_virtualmethod in vmtpd.procoptions) then
  361. begin
  362. { same parameter and return types (parameter specifiers will be checked below) }
  363. if hasequalpara and
  364. compatible_childmethod_resultdef(vmtpd.returndef,pd.returndef) then
  365. begin
  366. { inherite calling convention when it was explicit and the
  367. current definition has none explicit set }
  368. if (po_hascallingconvention in vmtpd.procoptions) and
  369. not(po_hascallingconvention in pd.procoptions) then
  370. begin
  371. pd.proccalloption:=vmtpd.proccalloption;
  372. include(pd.procoptions,po_hascallingconvention);
  373. end;
  374. { All parameter specifiers and some procedure the flags have to match
  375. except abstract and override }
  376. if (compare_paras(vmtpd.paras,pd.paras,cp_all,[cpo_ignoreuniv,cpo_ignorehidden])<te_equal) or
  377. (vmtpd.proccalloption<>pd.proccalloption) or
  378. (vmtpd.proctypeoption<>pd.proctypeoption) or
  379. ((vmtpd.procoptions*po_comp)<>(pd.procoptions*po_comp)) then
  380. begin
  381. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,pd.fullprocname(false));
  382. tprocsym(vmtpd.procsym).write_parameter_lists(pd);
  383. end;
  384. check_msg_str(vmtpd,pd);
  385. { Give a note if the new visibility is lower. For a higher
  386. visibility update the vmt info }
  387. if vmtentryvis>pd.visibility then
  388. MessagePos4(pd.fileinfo,parser_n_ignore_lower_visibility,pd.fullprocname(false),
  389. visibilityname[pd.visibility],tobjectdef(vmtpd.owner.defowner).objrealname^,visibilityname[vmtentryvis])
  390. else if pd.visibility>vmtentryvis then
  391. begin
  392. if updatevalues then
  393. vmtentryvis:=pd.visibility;
  394. end;
  395. { override old virtual method in VMT }
  396. if updatevalues then
  397. begin
  398. { in case we are overriding an abstract method,
  399. decrease the number of abstract methods in this class }
  400. if (po_overridingmethod in pd.procoptions) and
  401. (po_abstractmethod in vmtpd.procoptions) then
  402. dec(tobjectdef(pd.owner.defowner).abstractcnt);
  403. if (vmtpd.extnumber<>i) then
  404. internalerror(200611084);
  405. pd.extnumber:=vmtpd.extnumber;
  406. { in case of Java, copy the real name from the parent,
  407. since overriding "Destroy" with "destroy" is not
  408. going to work very well }
  409. if is_java_class_or_interface(_class) and
  410. (pd.procsym.realname<>vmtpd.procsym.realname) then
  411. pd.procsym.realname:=vmtpd.procsym.realname;
  412. vmtpd:=pd;
  413. end;
  414. result:=true;
  415. exit;
  416. end
  417. { different parameters }
  418. else
  419. begin
  420. { when we got an override directive then can search futher for
  421. the procedure to override.
  422. If we are starting a new virtual tree then hide the old tree }
  423. if not(po_overridingmethod in pd.procoptions) and
  424. not(pdoverload or hasoverloads) then
  425. begin
  426. if not(po_reintroduce in pd.procoptions) then
  427. begin
  428. if not is_object(_class) and
  429. not is_objc_class_or_protocol(_class) and
  430. not is_java_class_or_interface(_class) then
  431. MessagePos1(pd.fileinfo,parser_w_should_use_override,pd.fullprocname(false))
  432. else
  433. { objects don't allow starting a new virtual tree
  434. and neither do Objective-C or Java }
  435. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,vmtpd.fullprocname(false));
  436. end;
  437. { disable/hide old VMT entry }
  438. if updatevalues then
  439. vmtentryvis:=vis_hidden;
  440. end;
  441. end;
  442. end;
  443. end;
  444. function found_category_method(st: tsymtable): boolean;
  445. var
  446. entrycount: longint;
  447. cat: tobjectdef;
  448. vmtpd: tprocdef;
  449. vmtvis: tvisibility;
  450. begin
  451. result:=false;
  452. if is_objccategory(tdef(st.defowner)) then
  453. begin
  454. cat:=tobjectdef(st.defowner);
  455. { go through all of the category's methods to find the
  456. vmtentry corresponding to the procdef we are handling }
  457. for entrycount:=0 to cat.vmtentries.Count-1 do
  458. begin
  459. vmtpd:=pvmtentry(cat.vmtentries[entrycount])^.procdef;
  460. vmtvis:=pvmtentry(cat.vmtentries[entrycount])^.visibility;
  461. { don't change the vmtentry of the category }
  462. if found_entry(vmtpd,vmtvis,false) then
  463. begin
  464. result:=true;
  465. exit;
  466. end;
  467. end;
  468. end;
  469. end;
  470. begin
  471. result:=false;
  472. overridesclasshelper:=false;
  473. { Load other values for easier readability }
  474. hasoverloads:=(tprocsym(pd.procsym).ProcdefList.Count>1);
  475. pdoverload:=(po_overload in pd.procoptions);
  476. { compare with all stored definitions }
  477. for i:=0 to _class.vmtentries.Count-1 do
  478. begin
  479. if found_entry(pvmtentry(_class.vmtentries[i])^.procdef, pvmtentry(_class.vmtentries[i])^.visibility,true) then
  480. exit;
  481. end;
  482. { in case of Objective-C, also check the categories that apply to this
  483. class' *parent* for methods to override (don't allow class X to
  484. "override" a method added by a category to class X itself, since in
  485. that case the category method will in fact replace class X'
  486. "overriding" method }
  487. if is_objcclass(_class) and
  488. assigned(_class.childof) and
  489. search_objc_helper(_class.childof,pd.procsym.name,srsym,st) then
  490. begin
  491. overridesclasshelper:=found_category_method(st);
  492. end;
  493. { No entry found, we need to create a new entry }
  494. result:=true;
  495. end;
  496. function TVMTBuilder.intf_search_procdef_by_name(proc: tprocdef;const name: string): tprocdef;
  497. const
  498. po_comp = [po_classmethod,po_staticmethod,po_interrupt,po_iocheck,po_msgint,
  499. po_exports,po_varargs,po_explicitparaloc,po_nostackframe];
  500. var
  501. implprocdef : Tprocdef;
  502. i: cardinal;
  503. hclass : tobjectdef;
  504. hashedid : THashedIDString;
  505. srsym : tsym;
  506. begin
  507. result:=nil;
  508. hashedid.id:=name;
  509. hclass:=_class;
  510. while assigned(hclass) do
  511. begin
  512. srsym:=tsym(hclass.symtable.FindWithHash(hashedid));
  513. if assigned(srsym) and
  514. (srsym.typ=procsym) then
  515. begin
  516. for i:=0 to Tprocsym(srsym).ProcdefList.Count-1 do
  517. begin
  518. implprocdef:=tprocdef(tprocsym(srsym).ProcdefList[i]);
  519. if (implprocdef.procsym=tprocsym(srsym)) and
  520. (compare_paras(proc.paras,implprocdef.paras,cp_all,[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_ignoreuniv])>=te_equal) and
  521. (compare_defs(proc.returndef,implprocdef.returndef,nothingn)>=te_equal) and
  522. (proc.proccalloption=implprocdef.proccalloption) and
  523. (proc.proctypeoption=implprocdef.proctypeoption) and
  524. ((proc.procoptions*po_comp)=((implprocdef.procoptions+[po_virtualmethod])*po_comp)) and
  525. check_msg_str(proc,implprocdef) then
  526. begin
  527. { does the interface increase the visibility of the
  528. implementing method? }
  529. if implprocdef.visibility<proc.visibility then
  530. {$ifdef jvm}
  531. MessagePos2(implprocdef.fileinfo,type_e_interface_lower_visibility,proc.fullprocname(false),implprocdef.fullprocname(false));
  532. {$else}
  533. MessagePos2(implprocdef.fileinfo,type_w_interface_lower_visibility,proc.fullprocname(false),implprocdef.fullprocname(false));
  534. {$endif}
  535. result:=implprocdef;
  536. exit;
  537. end;
  538. end;
  539. end;
  540. hclass:=hclass.childof;
  541. end;
  542. end;
  543. procedure TVMTBuilder.intf_get_procdefs(ImplIntf:TImplementedInterface;IntfDef:TObjectDef);
  544. var
  545. i : longint;
  546. def : tdef;
  547. hs,
  548. prefix,
  549. mappedname: string;
  550. implprocdef: tprocdef;
  551. begin
  552. prefix:=ImplIntf.IntfDef.symtable.name^+'.';
  553. for i:=0 to IntfDef.symtable.DefList.Count-1 do
  554. begin
  555. def:=tdef(IntfDef.symtable.DefList[i]);
  556. if assigned(def) and
  557. (def.typ=procdef) then
  558. begin
  559. { Find implementing procdef
  560. 1. Check for mapped name
  561. 2. Use symbol name, but only if there's no mapping,
  562. or we're processing ancestor of interface.
  563. When modifying this code, ensure that webtbs/tw11862, webtbs/tw4950
  564. and webtbf/tw19591 stay correct. }
  565. implprocdef:=nil;
  566. hs:=prefix+tprocdef(def).procsym.name;
  567. mappedname:=ImplIntf.GetMapping(hs);
  568. if mappedname<>'' then
  569. implprocdef:=intf_search_procdef_by_name(tprocdef(def),mappedname);
  570. if not assigned(implprocdef) then
  571. if (mappedname='') or (ImplIntf.IntfDef<>IntfDef) then
  572. implprocdef:=intf_search_procdef_by_name(tprocdef(def),tprocdef(def).procsym.name);
  573. { Add procdef to the implemented interface }
  574. if assigned(implprocdef) then
  575. begin
  576. if (tobjectdef(implprocdef.struct).objecttype<>odt_objcclass) then
  577. begin
  578. { in case of Java, copy the real name from the parent,
  579. since overriding "Destroy" with "destroy" is not
  580. going to work very well }
  581. if is_javaclass(implprocdef.struct) and
  582. (implprocdef.procsym.realname<>tprocdef(def).procsym.realname) then
  583. implprocdef.procsym.realname:=tprocdef(def).procsym.realname;
  584. ImplIntf.AddImplProc(implprocdef);
  585. end
  586. else
  587. begin
  588. { If no message name has been specified for the method
  589. in the objcclass, copy it from the protocol
  590. definition. }
  591. if not(po_msgstr in tprocdef(def).procoptions) then
  592. begin
  593. include(tprocdef(def).procoptions,po_msgstr);
  594. implprocdef.messageinf.str:=stringdup(tprocdef(def).messageinf.str^);
  595. end
  596. else
  597. begin
  598. { If a message name has been specified in the
  599. objcclass, it has to match the message name in the
  600. protocol definition. }
  601. if (implprocdef.messageinf.str^<>tprocdef(def).messageinf.str^) then
  602. MessagePos2(implprocdef.fileinfo,parser_e_objc_message_name_changed,tprocdef(def).messageinf.str^,implprocdef.messageinf.str^);
  603. end;
  604. end;
  605. end
  606. else
  607. if (ImplIntf.IType=etStandard) and
  608. not(po_optional in tprocdef(def).procoptions) then
  609. MessagePos1(_Class.typesym.fileinfo,sym_e_no_matching_implementation_found,tprocdef(def).fullprocname(false));
  610. end;
  611. end;
  612. end;
  613. procedure TVMTBuilder.intf_get_procdefs_recursive(ImplIntf:TImplementedInterface;IntfDef:TObjectDef);
  614. begin
  615. if assigned(IntfDef.childof) then
  616. intf_get_procdefs_recursive(ImplIntf,IntfDef.childof);
  617. intf_get_procdefs(ImplIntf,IntfDef);
  618. end;
  619. procedure TVMTBuilder.prot_get_procdefs_recursive(ImplProt:TImplementedInterface;ProtDef:TObjectDef);
  620. var
  621. i: longint;
  622. begin
  623. { don't check the same protocol twice }
  624. if handledprotocols.IndexOf(ProtDef)<>-1 then
  625. exit;
  626. handledprotocols.add(ProtDef);
  627. for i:=0 to ProtDef.ImplementedInterfaces.count-1 do
  628. prot_get_procdefs_recursive(ImplProt,TImplementedInterface(ProtDef.ImplementedInterfaces[i]).intfdef);
  629. intf_get_procdefs(ImplProt,ProtDef);
  630. end;
  631. procedure TVMTBuilder.intf_optimize_vtbls;
  632. type
  633. tcompintfentry = record
  634. weight: longint;
  635. compintf: longint;
  636. end;
  637. { Max 1000 interface in the class header interfaces it's enough imho }
  638. tcompintfs = array[0..1000] of tcompintfentry;
  639. pcompintfs = ^tcompintfs;
  640. tequals = array[0..1000] of longint;
  641. pequals = ^tequals;
  642. timpls = array[0..1000] of longint;
  643. pimpls = ^timpls;
  644. var
  645. aequals: pequals;
  646. compats: pcompintfs;
  647. impls: pimpls;
  648. ImplIntfCount,
  649. w,i,j,k: longint;
  650. ImplIntfI,
  651. ImplIntfJ : TImplementedInterface;
  652. cij: boolean;
  653. cji: boolean;
  654. begin
  655. ImplIntfCount:=_class.ImplementedInterfaces.count;
  656. if ImplIntfCount>=High(tequals) then
  657. Internalerror(200006135);
  658. getmem(compats,sizeof(tcompintfentry)*ImplIntfCount);
  659. getmem(aequals,sizeof(longint)*ImplIntfCount);
  660. getmem(impls,sizeof(longint)*ImplIntfCount);
  661. filldword(compats^,(sizeof(tcompintfentry) div sizeof(dword))*ImplIntfCount,dword(-1));
  662. filldword(aequals^,ImplIntfCount,dword(-1));
  663. filldword(impls^,ImplIntfCount,dword(-1));
  664. { ismergepossible is a containing relation
  665. meaning of ismergepossible(a,b,w) =
  666. if implementorfunction map of a is contained implementorfunction map of b
  667. imp(a,b) and imp(b,c) => imp(a,c) ; imp(a,b) and imp(b,a) => a == b
  668. }
  669. { the order is very important for correct allocation }
  670. for i:=0 to ImplIntfCount-1 do
  671. begin
  672. for j:=i+1 to ImplIntfCount-1 do
  673. begin
  674. ImplIntfI:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  675. ImplIntfJ:=TImplementedInterface(_class.ImplementedInterfaces[j]);
  676. cij:=ImplIntfI.IsImplMergePossible(ImplIntfJ,w);
  677. cji:=ImplIntfJ.IsImplMergePossible(ImplIntfI,w);
  678. if cij and cji then { i equal j }
  679. begin
  680. { get minimum index of equal }
  681. if aequals^[j]=-1 then
  682. aequals^[j]:=i;
  683. end
  684. else if cij then
  685. begin
  686. { get minimum index of maximum weight }
  687. if compats^[i].weight<w then
  688. begin
  689. compats^[i].weight:=w;
  690. compats^[i].compintf:=j;
  691. end;
  692. end
  693. else if cji then
  694. begin
  695. { get minimum index of maximum weight }
  696. if (compats^[j].weight<w) then
  697. begin
  698. compats^[j].weight:=w;
  699. compats^[j].compintf:=i;
  700. end;
  701. end;
  702. end;
  703. end;
  704. { Reset, no replacements by default }
  705. for i:=0 to ImplIntfCount-1 do
  706. impls^[i]:=i;
  707. { Replace vtbls when equal or compat, repeat
  708. until there are no replacements possible anymore. This is
  709. needed for the cases like:
  710. First loop: 2->3, 3->1
  711. Second loop: 2->1 (because 3 was replaced with 1)
  712. }
  713. repeat
  714. k:=0;
  715. for i:=0 to ImplIntfCount-1 do
  716. begin
  717. if compats^[impls^[i]].compintf<>-1 then
  718. impls^[i]:=compats^[impls^[i]].compintf
  719. else if aequals^[impls^[i]]<>-1 then
  720. impls^[i]:=aequals^[impls^[i]]
  721. else
  722. inc(k);
  723. end;
  724. until k=ImplIntfCount;
  725. { Update the VtblImplIntf }
  726. for i:=0 to ImplIntfCount-1 do
  727. begin
  728. ImplIntfI:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  729. ImplIntfI.VtblImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[impls^[i]]);
  730. end;
  731. freemem(compats);
  732. freemem(aequals);
  733. freemem(impls);
  734. end;
  735. procedure TVMTBuilder.intf_allocate_vtbls;
  736. var
  737. i : longint;
  738. ImplIntf : TImplementedInterface;
  739. begin
  740. { Allocation vtbl space }
  741. for i:=0 to _class.ImplementedInterfaces.count-1 do
  742. begin
  743. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  744. { if it implements itself and if it's not implemented by delegation }
  745. if (ImplIntf.VtblImplIntf=ImplIntf) and (ImplIntf.IType=etStandard) then
  746. begin
  747. { allocate a pointer in the object memory }
  748. with tObjectSymtable(_class.symtable) do
  749. begin
  750. datasize:=align(datasize,sizeof(pint));
  751. ImplIntf.Ioffset:=datasize;
  752. datasize:=datasize+sizeof(pint);
  753. end;
  754. end;
  755. end;
  756. { Update ioffset of current interface with the ioffset from
  757. the interface that is reused to implements this interface }
  758. for i:=0 to _class.ImplementedInterfaces.count-1 do
  759. begin
  760. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  761. if ImplIntf.VtblImplIntf<>ImplIntf then
  762. ImplIntf.IOffset:=ImplIntf.VtblImplIntf.IOffset;
  763. end;
  764. end;
  765. procedure TVMTBuilder.generate_vmt;
  766. var
  767. i : longint;
  768. def : tdef;
  769. old_current_structdef : tabstractrecorddef;
  770. overridesclasshelper : boolean;
  771. begin
  772. old_current_structdef:=current_structdef;
  773. current_structdef:=_class;
  774. _class.resetvmtentries;
  775. { inherit (copy) VMT from parent object }
  776. if assigned(_class.childof) then
  777. begin
  778. if not assigned(_class.childof.vmtentries) then
  779. internalerror(200810281);
  780. _class.copyvmtentries(_class.childof);
  781. end;
  782. { process all procdefs, we must process the defs to
  783. keep the same order as that is written in the source
  784. to be compatible with the indexes in the interface vtable (PFV) }
  785. for i:=0 to _class.symtable.DefList.Count-1 do
  786. begin
  787. def:=tdef(_class.symtable.DefList[i]);
  788. if def.typ=procdef then
  789. begin
  790. { VMT entry }
  791. if is_new_vmt_entry(tprocdef(def),overridesclasshelper) then
  792. add_new_vmt_entry(tprocdef(def),overridesclasshelper);
  793. end;
  794. end;
  795. build_interface_mappings;
  796. if assigned(_class.ImplementedInterfaces) and
  797. not(is_objc_class_or_protocol(_class)) and
  798. not(is_java_class_or_interface(_class)) then
  799. begin
  800. { Optimize interface tables to reuse wrappers }
  801. intf_optimize_vtbls;
  802. { Allocate interface tables }
  803. intf_allocate_vtbls;
  804. end;
  805. current_structdef:=old_current_structdef;
  806. end;
  807. procedure TVMTBuilder.build_interface_mappings;
  808. var
  809. ImplIntf : TImplementedInterface;
  810. i: longint;
  811. begin
  812. { Find Procdefs implementing the interfaces (both Objective-C protocols
  813. and Java interfaces can have multiple parent interfaces, but in that
  814. case obviously no implementations are required) }
  815. if assigned(_class.ImplementedInterfaces) and
  816. not(_class.objecttype in [odt_objcprotocol,odt_interfacejava]) and
  817. // abstract java classes do not have to implement all interface
  818. // methods. todo: check that non-abstract descendents do!
  819. not((_class.objecttype=odt_javaclass) and (oo_is_abstract in _class.objectoptions)) then
  820. begin
  821. { Collect implementor functions into the tImplementedInterface.procdefs }
  822. case _class.objecttype of
  823. odt_class:
  824. begin
  825. for i:=0 to _class.ImplementedInterfaces.count-1 do
  826. begin
  827. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  828. intf_get_procdefs_recursive(ImplIntf,ImplIntf.IntfDef)
  829. end;
  830. end;
  831. odt_objcclass,
  832. odt_javaclass:
  833. begin
  834. { Object Pascal interfaces are afterwards optimized via the
  835. intf_optimize_vtbls() method, but we can't do this for
  836. protocols/Java interfaces -> check for duplicates here
  837. already. }
  838. handledprotocols:=tfpobjectlist.create(false);
  839. for i:=0 to _class.ImplementedInterfaces.count-1 do
  840. begin
  841. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  842. prot_get_procdefs_recursive(ImplIntf,ImplIntf.IntfDef);
  843. end;
  844. handledprotocols.free;
  845. end
  846. else
  847. internalerror(2009091801);
  848. end
  849. end;
  850. end;
  851. {*****************************************************************************
  852. TVMTWriter
  853. *****************************************************************************}
  854. constructor TVMTWriter.create(c:tobjectdef);
  855. begin
  856. inherited Create;
  857. _Class:=c;
  858. end;
  859. destructor TVMTWriter.destroy;
  860. begin
  861. end;
  862. {**************************************
  863. Message Tables
  864. **************************************}
  865. procedure TVMTWriter.disposeprocdeftree(p : pprocdeftree);
  866. begin
  867. if assigned(p^.l) then
  868. disposeprocdeftree(p^.l);
  869. if assigned(p^.r) then
  870. disposeprocdeftree(p^.r);
  871. dispose(p);
  872. end;
  873. procedure TVMTWriter.insertint(p : pprocdeftree;var at : pprocdeftree;var count:longint);
  874. begin
  875. if at=nil then
  876. begin
  877. at:=p;
  878. inc(count);
  879. end
  880. else
  881. begin
  882. if p^.data.messageinf.i<at^.data.messageinf.i then
  883. insertint(p,at^.l,count)
  884. else if p^.data.messageinf.i>at^.data.messageinf.i then
  885. insertint(p,at^.r,count)
  886. else
  887. Message1(parser_e_duplicate_message_label,tostr(p^.data.messageinf.i));
  888. end;
  889. end;
  890. procedure TVMTWriter.insertstr(p : pprocdeftree;var at : pprocdeftree;var count:longint);
  891. var
  892. i : integer;
  893. begin
  894. if at=nil then
  895. begin
  896. at:=p;
  897. inc(count);
  898. end
  899. else
  900. begin
  901. i:=CompareStr(p^.data.messageinf.str^,at^.data.messageinf.str^);
  902. if i<0 then
  903. insertstr(p,at^.l,count)
  904. else if i>0 then
  905. insertstr(p,at^.r,count)
  906. else
  907. Message1(parser_e_duplicate_message_label,p^.data.messageinf.str^);
  908. end;
  909. end;
  910. procedure TVMTWriter.insertmsgint(p:TObject;arg:pointer);
  911. var
  912. i : longint;
  913. pd : Tprocdef;
  914. pt : pprocdeftree;
  915. begin
  916. if tsym(p).typ<>procsym then
  917. exit;
  918. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  919. begin
  920. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  921. if po_msgint in pd.procoptions then
  922. begin
  923. new(pt);
  924. pt^.data:=pd;
  925. pt^.l:=nil;
  926. pt^.r:=nil;
  927. insertint(pt,root,plongint(arg)^);
  928. end;
  929. end;
  930. end;
  931. procedure TVMTWriter.insertmsgstr(p:TObject;arg:pointer);
  932. var
  933. i : longint;
  934. pd : Tprocdef;
  935. pt : pprocdeftree;
  936. begin
  937. if tsym(p).typ<>procsym then
  938. exit;
  939. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  940. begin
  941. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  942. if po_msgstr in pd.procoptions then
  943. begin
  944. new(pt);
  945. pt^.data:=pd;
  946. pt^.l:=nil;
  947. pt^.r:=nil;
  948. insertstr(pt,root,plongint(arg)^);
  949. end;
  950. end;
  951. end;
  952. procedure TVMTWriter.writenames(p : pprocdeftree);
  953. var
  954. ca : pchar;
  955. len : byte;
  956. begin
  957. current_asmdata.getdatalabel(p^.nl);
  958. if assigned(p^.l) then
  959. writenames(p^.l);
  960. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  961. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(p^.nl));
  962. len:=length(p^.data.messageinf.str^);
  963. current_asmdata.asmlists[al_globals].concat(tai_const.create_8bit(len));
  964. getmem(ca,len+1);
  965. move(p^.data.messageinf.str^[1],ca^,len);
  966. ca[len]:=#0;
  967. current_asmdata.asmlists[al_globals].concat(Tai_string.Create_pchar(ca,len));
  968. if assigned(p^.r) then
  969. writenames(p^.r);
  970. end;
  971. procedure TVMTWriter.writestrentry(p : pprocdeftree);
  972. begin
  973. if assigned(p^.l) then
  974. writestrentry(p^.l);
  975. { write name label }
  976. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  977. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(p^.nl));
  978. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  979. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(p^.data.mangledname,0));
  980. if assigned(p^.r) then
  981. writestrentry(p^.r);
  982. end;
  983. function TVMTWriter.genstrmsgtab : tasmlabel;
  984. var
  985. count : longint;
  986. begin
  987. root:=nil;
  988. count:=0;
  989. { insert all message handlers into a tree, sorted by name }
  990. _class.symtable.SymList.ForEachCall(@insertmsgstr,@count);
  991. { write all names }
  992. if assigned(root) then
  993. writenames(root);
  994. { now start writing of the message string table }
  995. current_asmdata.getdatalabel(result);
  996. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  997. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(result));
  998. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(longint))));
  999. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(count));
  1000. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1001. if assigned(root) then
  1002. begin
  1003. writestrentry(root);
  1004. disposeprocdeftree(root);
  1005. end;
  1006. end;
  1007. procedure TVMTWriter.writeintentry(p : pprocdeftree);
  1008. begin
  1009. if assigned(p^.l) then
  1010. writeintentry(p^.l);
  1011. { write name label }
  1012. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(longint))));
  1013. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(p^.data.messageinf.i));
  1014. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1015. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(p^.data.mangledname,0));
  1016. if assigned(p^.r) then
  1017. writeintentry(p^.r);
  1018. end;
  1019. function TVMTWriter.genintmsgtab : tasmlabel;
  1020. var
  1021. r : tasmlabel;
  1022. count : longint;
  1023. begin
  1024. root:=nil;
  1025. count:=0;
  1026. { insert all message handlers into a tree, sorted by name }
  1027. _class.symtable.SymList.ForEachCall(@insertmsgint,@count);
  1028. { now start writing of the message string table }
  1029. current_asmdata.getdatalabel(r);
  1030. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1031. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(r));
  1032. genintmsgtab:=r;
  1033. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(longint))));
  1034. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(count));
  1035. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1036. if assigned(root) then
  1037. begin
  1038. writeintentry(root);
  1039. disposeprocdeftree(root);
  1040. end;
  1041. end;
  1042. {$ifdef WITHDMT}
  1043. {**************************************
  1044. DMT
  1045. **************************************}
  1046. procedure TVMTWriter.insertdmtentry(p:TObject;arg:pointer);
  1047. var
  1048. hp : tprocdef;
  1049. pt : pprocdeftree;
  1050. begin
  1051. if tsym(p).typ=procsym then
  1052. begin
  1053. hp:=tprocsym(p).definition;
  1054. while assigned(hp) do
  1055. begin
  1056. if (po_msgint in hp.procoptions) then
  1057. begin
  1058. new(pt);
  1059. pt^.p:=hp;
  1060. pt^.l:=nil;
  1061. pt^.r:=nil;
  1062. insertint(pt,root);
  1063. end;
  1064. hp:=hp.nextoverloaded;
  1065. end;
  1066. end;
  1067. end;
  1068. procedure TVMTWriter.writedmtindexentry(p : pprocdeftree);
  1069. begin
  1070. if assigned(p^.l) then
  1071. writedmtindexentry(p^.l);
  1072. al_globals.concat(Tai_const.Create_32bit(p^.data.messageinf.i));
  1073. if assigned(p^.r) then
  1074. writedmtindexentry(p^.r);
  1075. end;
  1076. procedure TVMTWriter.writedmtaddressentry(p : pprocdeftree);
  1077. begin
  1078. if assigned(p^.l) then
  1079. writedmtaddressentry(p^.l);
  1080. al_globals.concat(Tai_const_symbol.Createname(p^.data.mangledname,0));
  1081. if assigned(p^.r) then
  1082. writedmtaddressentry(p^.r);
  1083. end;
  1084. function TVMTWriter.gendmt : tasmlabel;
  1085. var
  1086. r : tasmlabel;
  1087. begin
  1088. root:=nil;
  1089. count:=0;
  1090. gendmt:=nil;
  1091. { insert all message handlers into a tree, sorted by number }
  1092. _class.symtable.SymList.ForEachCall(insertdmtentry);
  1093. if count>0 then
  1094. begin
  1095. current_asmdata.getdatalabel(r);
  1096. gendmt:=r;
  1097. al_globals.concat(cai_align.create(const_align(sizeof(pint))));
  1098. al_globals.concat(Tai_label.Create(r));
  1099. { entries for caching }
  1100. al_globals.concat(Tai_const.Create_ptr(0));
  1101. al_globals.concat(Tai_const.Create_ptr(0));
  1102. al_globals.concat(Tai_const.Create_32bit(count));
  1103. if assigned(root) then
  1104. begin
  1105. writedmtindexentry(root);
  1106. writedmtaddressentry(root);
  1107. disposeprocdeftree(root);
  1108. end;
  1109. end;
  1110. end;
  1111. {$endif WITHDMT}
  1112. {**************************************
  1113. Published Methods
  1114. **************************************}
  1115. procedure TVMTWriter.do_count_published_methods(p:TObject;arg:pointer);
  1116. var
  1117. i : longint;
  1118. pd : tprocdef;
  1119. begin
  1120. if (tsym(p).typ<>procsym) then
  1121. exit;
  1122. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  1123. begin
  1124. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  1125. if (pd.procsym=tsym(p)) and
  1126. (pd.visibility=vis_published) then
  1127. inc(plongint(arg)^);
  1128. end;
  1129. end;
  1130. procedure TVMTWriter.do_gen_published_methods(p:TObject;arg:pointer);
  1131. var
  1132. i : longint;
  1133. l : tasmlabel;
  1134. pd : tprocdef;
  1135. begin
  1136. if (tsym(p).typ<>procsym) then
  1137. exit;
  1138. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  1139. begin
  1140. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  1141. if (pd.procsym=tsym(p)) and
  1142. (pd.visibility=vis_published) then
  1143. begin
  1144. current_asmdata.getdatalabel(l);
  1145. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,l.name,const_align(sizeof(pint)));
  1146. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l));
  1147. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(length(tsym(p).realname)));
  1148. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create(tsym(p).realname));
  1149. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(l));
  1150. if po_abstractmethod in pd.procoptions then
  1151. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil))
  1152. else
  1153. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(pd.mangledname,0));
  1154. end;
  1155. end;
  1156. end;
  1157. function TVMTWriter.genpublishedmethodstable : tasmlabel;
  1158. var
  1159. l : tasmlabel;
  1160. count : longint;
  1161. begin
  1162. count:=0;
  1163. _class.symtable.SymList.ForEachCall(@do_count_published_methods,@count);
  1164. if count>0 then
  1165. begin
  1166. current_asmdata.getdatalabel(l);
  1167. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1168. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(l));
  1169. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(count));
  1170. _class.symtable.SymList.ForEachCall(@do_gen_published_methods,nil);
  1171. genpublishedmethodstable:=l;
  1172. end
  1173. else
  1174. genpublishedmethodstable:=nil;
  1175. end;
  1176. function TVMTWriter.generate_field_table : tasmlabel;
  1177. var
  1178. i : longint;
  1179. sym : tsym;
  1180. fieldtable,
  1181. classtable : tasmlabel;
  1182. classindex,
  1183. fieldcount : longint;
  1184. classtablelist : TFPList;
  1185. begin
  1186. classtablelist:=TFPList.Create;
  1187. current_asmdata.getdatalabel(fieldtable);
  1188. current_asmdata.getdatalabel(classtable);
  1189. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  1190. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,classtable.name,const_align(sizeof(pint)));
  1191. { retrieve field info fields }
  1192. fieldcount:=0;
  1193. for i:=0 to _class.symtable.SymList.Count-1 do
  1194. begin
  1195. sym:=tsym(_class.symtable.SymList[i]);
  1196. if (sym.typ=fieldvarsym) and
  1197. (sym.visibility=vis_published) then
  1198. begin
  1199. if tfieldvarsym(sym).vardef.typ<>objectdef then
  1200. internalerror(200611032);
  1201. classindex:=classtablelist.IndexOf(tfieldvarsym(sym).vardef);
  1202. if classindex=-1 then
  1203. classtablelist.Add(tfieldvarsym(sym).vardef);
  1204. inc(fieldcount);
  1205. end;
  1206. end;
  1207. { write fields }
  1208. current_asmdata.asmlists[al_rtti].concat(Tai_label.Create(fieldtable));
  1209. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(fieldcount));
  1210. if (tf_requires_proper_alignment in target_info.flags) then
  1211. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  1212. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(classtable));
  1213. for i:=0 to _class.symtable.SymList.Count-1 do
  1214. begin
  1215. sym:=tsym(_class.symtable.SymList[i]);
  1216. if (sym.typ=fieldvarsym) and
  1217. (sym.visibility=vis_published) then
  1218. begin
  1219. if (tf_requires_proper_alignment in target_info.flags) then
  1220. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(pint)));
  1221. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_pint(tfieldvarsym(sym).fieldoffset));
  1222. classindex:=classtablelist.IndexOf(tfieldvarsym(sym).vardef);
  1223. if classindex=-1 then
  1224. internalerror(200611033);
  1225. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(classindex+1));
  1226. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(tfieldvarsym(sym).realname)));
  1227. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(tfieldvarsym(sym).realname));
  1228. end;
  1229. end;
  1230. { generate the class table }
  1231. current_asmdata.asmlists[al_rtti].concat(cai_align.create(const_align(sizeof(pint))));
  1232. current_asmdata.asmlists[al_rtti].concat(Tai_label.Create(classtable));
  1233. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(classtablelist.count));
  1234. if (tf_requires_proper_alignment in target_info.flags) then
  1235. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  1236. for i:=0 to classtablelist.Count-1 do
  1237. current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(tobjectdef(classtablelist[i]).vmt_mangledname,0));
  1238. classtablelist.free;
  1239. result:=fieldtable;
  1240. end;
  1241. {**************************************
  1242. Interface tables
  1243. **************************************}
  1244. function TVMTWriter.intf_get_vtbl_name(AImplIntf:TImplementedInterface): string;
  1245. begin
  1246. result:=make_mangledname('VTBL',_class.owner,_class.objname^+'_$_'+AImplIntf.IntfDef.objname^);
  1247. end;
  1248. procedure TVMTWriter.intf_create_vtbl(rawdata: TAsmList;AImplIntf:TImplementedInterface);
  1249. var
  1250. pd : tprocdef;
  1251. vtblstr,
  1252. hs : string;
  1253. i : longint;
  1254. begin
  1255. vtblstr:=intf_get_vtbl_name(AImplIntf);
  1256. section_symbol_start(rawdata,vtblstr,AT_DATA,true,sec_data,const_align(sizeof(pint)));
  1257. if assigned(AImplIntf.procdefs) then
  1258. begin
  1259. for i:=0 to AImplIntf.procdefs.count-1 do
  1260. begin
  1261. pd:=tprocdef(AImplIntf.procdefs[i]);
  1262. hs:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+AImplIntf.IntfDef.objname^+'_$_'+
  1263. tostr(i)+'_$_'+pd.mangledname);
  1264. { create reference }
  1265. rawdata.concat(Tai_const.Createname(hs,0));
  1266. end;
  1267. end;
  1268. section_symbol_end(rawdata,vtblstr);
  1269. end;
  1270. procedure TVMTWriter.intf_gen_intf_ref(rawdata: TAsmList;AImplIntf:TImplementedInterface);
  1271. var
  1272. iidlabel,
  1273. guidlabel : tasmlabel;
  1274. i: longint;
  1275. pd: tprocdef;
  1276. begin
  1277. { GUID }
  1278. if AImplIntf.IntfDef.objecttype in [odt_interfacecom] then
  1279. begin
  1280. { label for GUID }
  1281. current_asmdata.getdatalabel(guidlabel);
  1282. rawdata.concat(cai_align.create(const_align(sizeof(pint))));
  1283. rawdata.concat(Tai_label.Create(guidlabel));
  1284. with AImplIntf.IntfDef.iidguid^ do
  1285. begin
  1286. rawdata.concat(Tai_const.Create_32bit(longint(D1)));
  1287. rawdata.concat(Tai_const.Create_16bit(D2));
  1288. rawdata.concat(Tai_const.Create_16bit(D3));
  1289. for i:=Low(D4) to High(D4) do
  1290. rawdata.concat(Tai_const.Create_8bit(D4[i]));
  1291. end;
  1292. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(guidlabel));
  1293. end
  1294. else
  1295. begin
  1296. { nil for Corba interfaces }
  1297. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1298. end;
  1299. { VTable }
  1300. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(intf_get_vtbl_name(AImplIntf.VtblImplIntf),0));
  1301. { IOffset field }
  1302. case AImplIntf.VtblImplIntf.IType of
  1303. etFieldValue, etFieldValueClass,
  1304. etStandard:
  1305. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(AImplIntf.VtblImplIntf.IOffset));
  1306. etStaticMethodResult, etStaticMethodClass:
  1307. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(
  1308. tprocdef(tpropertysym(AImplIntf.ImplementsGetter).propaccesslist[palt_read].procdef).mangledname,
  1309. 0
  1310. ));
  1311. etVirtualMethodResult, etVirtualMethodClass:
  1312. begin
  1313. pd := tprocdef(tpropertysym(AImplIntf.ImplementsGetter).propaccesslist[palt_read].procdef);
  1314. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(tobjectdef(pd.struct).vmtmethodoffset(pd.extnumber)));
  1315. end;
  1316. else
  1317. internalerror(200802162);
  1318. end;
  1319. { IIDStr }
  1320. current_asmdata.getdatalabel(iidlabel);
  1321. rawdata.concat(cai_align.create(const_align(sizeof(pint))));
  1322. rawdata.concat(Tai_label.Create(iidlabel));
  1323. rawdata.concat(Tai_const.Create_8bit(length(AImplIntf.IntfDef.iidstr^)));
  1324. if AImplIntf.IntfDef.objecttype=odt_interfacecom then
  1325. rawdata.concat(Tai_string.Create(upper(AImplIntf.IntfDef.iidstr^)))
  1326. else
  1327. rawdata.concat(Tai_string.Create(AImplIntf.IntfDef.iidstr^));
  1328. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(iidlabel));
  1329. { IType }
  1330. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(aint(AImplIntf.VtblImplIntf.IType)));
  1331. end;
  1332. function TVMTWriter.intf_write_table:TAsmLabel;
  1333. var
  1334. rawdata : TAsmList;
  1335. i : longint;
  1336. ImplIntf : TImplementedInterface;
  1337. intftablelab : tasmlabel;
  1338. begin
  1339. current_asmdata.getdatalabel(intftablelab);
  1340. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1341. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(intftablelab));
  1342. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(_class.ImplementedInterfaces.count));
  1343. rawdata:=TAsmList.Create;
  1344. { Write vtbls }
  1345. for i:=0 to _class.ImplementedInterfaces.count-1 do
  1346. begin
  1347. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  1348. if ImplIntf.VtblImplIntf=ImplIntf then
  1349. intf_create_vtbl(rawdata,ImplIntf);
  1350. end;
  1351. { Write vtbl references }
  1352. for i:=0 to _class.ImplementedInterfaces.count-1 do
  1353. begin
  1354. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  1355. intf_gen_intf_ref(rawdata,ImplIntf);
  1356. end;
  1357. { Write interface table }
  1358. current_asmdata.asmlists[al_globals].concatlist(rawdata);
  1359. rawdata.free;
  1360. result:=intftablelab;
  1361. end;
  1362. { Write interface identifiers to the data section }
  1363. procedure TVMTWriter.writeinterfaceids;
  1364. var
  1365. i : longint;
  1366. s : string;
  1367. begin
  1368. if assigned(_class.iidguid) then
  1369. begin
  1370. s:=make_mangledname('IID',_class.owner,_class.objname^);
  1371. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1372. new_section(current_asmdata.asmlists[al_globals],sec_rodata,s,const_align(sizeof(pint)));
  1373. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(s,AT_DATA,0));
  1374. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(longint(_class.iidguid^.D1)));
  1375. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_16bit(_class.iidguid^.D2));
  1376. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_16bit(_class.iidguid^.D3));
  1377. for i:=Low(_class.iidguid^.D4) to High(_class.iidguid^.D4) do
  1378. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_8bit(_class.iidguid^.D4[i]));
  1379. end;
  1380. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1381. s:=make_mangledname('IIDSTR',_class.owner,_class.objname^);
  1382. new_section(current_asmdata.asmlists[al_globals],sec_rodata,s,0);
  1383. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(s,AT_DATA,0));
  1384. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_8bit(length(_class.iidstr^)));
  1385. current_asmdata.asmlists[al_globals].concat(Tai_string.Create(_class.iidstr^));
  1386. end;
  1387. procedure TVMTWriter.writevirtualmethods(List:TAsmList);
  1388. var
  1389. vmtpd : tprocdef;
  1390. vmtentry : pvmtentry;
  1391. i : longint;
  1392. procname : string;
  1393. {$ifdef vtentry}
  1394. hs : string;
  1395. {$endif vtentry}
  1396. begin
  1397. if not assigned(_class.VMTEntries) then
  1398. exit;
  1399. for i:=0 to _class.VMTEntries.Count-1 do
  1400. begin
  1401. vmtentry:=pvmtentry(_class.vmtentries[i]);
  1402. vmtpd:=vmtentry^.procdef;
  1403. { safety checks }
  1404. if not(po_virtualmethod in vmtpd.procoptions) then
  1405. internalerror(200611082);
  1406. if vmtpd.extnumber<>i then
  1407. internalerror(200611083);
  1408. if (po_abstractmethod in vmtpd.procoptions) then
  1409. procname:='FPC_ABSTRACTERROR'
  1410. else if not wpoinfomanager.optimized_name_for_vmt(_class,vmtpd,procname) then
  1411. procname:=vmtpd.mangledname;
  1412. List.concat(Tai_const.createname(procname,0));
  1413. {$ifdef vtentry}
  1414. hs:='VTENTRY'+'_'+_class.vmt_mangledname+'$$'+tostr(_class.vmtmethodoffset(i) div sizeof(pint));
  1415. current_asmdata.asmlists[al_globals].concat(tai_symbol.CreateName(hs,AT_DATA,0));
  1416. {$endif vtentry}
  1417. end;
  1418. end;
  1419. procedure TVMTWriter.writevmt;
  1420. var
  1421. methodnametable,intmessagetable,
  1422. strmessagetable,classnamelabel,
  1423. fieldtablelabel : tasmlabel;
  1424. hs: string;
  1425. {$ifdef WITHDMT}
  1426. dmtlabel : tasmlabel;
  1427. {$endif WITHDMT}
  1428. interfacetable : tasmlabel;
  1429. begin
  1430. {$ifdef WITHDMT}
  1431. dmtlabel:=gendmt;
  1432. {$endif WITHDMT}
  1433. { write tables for classes, this must be done before the actual
  1434. class is written, because we need the labels defined }
  1435. if is_class(_class) then
  1436. begin
  1437. current_asmdata.getdatalabel(classnamelabel);
  1438. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1439. new_section(current_asmdata.asmlists[al_globals],sec_rodata,classnamelabel.name,const_align(sizeof(pint)));
  1440. { interface table }
  1441. if _class.ImplementedInterfaces.count>0 then
  1442. interfacetable:=intf_write_table;
  1443. methodnametable:=genpublishedmethodstable;
  1444. fieldtablelabel:=generate_field_table;
  1445. { write class name }
  1446. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(classnamelabel));
  1447. hs:=_class.RttiName;
  1448. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_8bit(length(hs)));
  1449. current_asmdata.asmlists[al_globals].concat(Tai_string.Create(hs));
  1450. { generate message and dynamic tables }
  1451. if (oo_has_msgstr in _class.objectoptions) then
  1452. strmessagetable:=genstrmsgtab;
  1453. if (oo_has_msgint in _class.objectoptions) then
  1454. intmessagetable:=genintmsgtab;
  1455. end;
  1456. { write debug info }
  1457. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1458. new_section(current_asmdata.asmlists[al_globals],sec_rodata,_class.vmt_mangledname,const_align(sizeof(pint)));
  1459. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(_class.vmt_mangledname,AT_DATA,0));
  1460. { determine the size with symtable.datasize, because }
  1461. { size gives back 4 for classes }
  1462. current_asmdata.asmlists[al_globals].concat(Tai_const.Create(aitconst_ptr,tObjectSymtable(_class.symtable).datasize));
  1463. current_asmdata.asmlists[al_globals].concat(Tai_const.Create(aitconst_ptr,-int64(tObjectSymtable(_class.symtable).datasize)));
  1464. {$ifdef WITHDMT}
  1465. if _class.classtype=ct_object then
  1466. begin
  1467. if assigned(dmtlabel) then
  1468. current_asmdata.asmlists[al_globals].concat(Tai_const_symbol.Create(dmtlabel)))
  1469. else
  1470. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_ptr(0));
  1471. end;
  1472. {$endif WITHDMT}
  1473. { write pointer to parent VMT, this isn't implemented in TP }
  1474. { but this is not used in FPC ? (PM) }
  1475. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1476. { it is not written for parents that don't have any vmt !! }
  1477. if assigned(_class.childof) and
  1478. (oo_has_vmt in _class.childof.objectoptions) then
  1479. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(_class.childof.vmt_mangledname,0))
  1480. else
  1481. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1482. { write extended info for classes, for the order see rtl/inc/objpash.inc }
  1483. if is_class(_class) then
  1484. begin
  1485. { pointer to class name string }
  1486. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(classnamelabel));
  1487. { pointer to dynamic table or nil }
  1488. if (oo_has_msgint in _class.objectoptions) then
  1489. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(intmessagetable))
  1490. else
  1491. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1492. { pointer to method table or nil }
  1493. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(methodnametable));
  1494. { pointer to field table }
  1495. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(fieldtablelabel));
  1496. { pointer to type info of published section }
  1497. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(RTTIWriter.get_rtti_label(_class,fullrtti)));
  1498. { inittable for con-/destruction }
  1499. if _class.members_need_inittable then
  1500. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(RTTIWriter.get_rtti_label(_class,initrtti)))
  1501. else
  1502. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1503. { auto table }
  1504. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1505. { interface table }
  1506. if _class.ImplementedInterfaces.count>0 then
  1507. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(interfacetable))
  1508. else if _class.implements_any_interfaces then
  1509. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil))
  1510. else
  1511. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(current_asmdata.RefAsmSymbol('FPC_EMPTYINTF')));
  1512. { table for string messages }
  1513. if (oo_has_msgstr in _class.objectoptions) then
  1514. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(strmessagetable))
  1515. else
  1516. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1517. end;
  1518. { write virtual methods }
  1519. writevirtualmethods(current_asmdata.asmlists[al_globals]);
  1520. current_asmdata.asmlists[al_globals].concat(Tai_const.create(aitconst_ptr,0));
  1521. { write the size of the VMT }
  1522. current_asmdata.asmlists[al_globals].concat(Tai_symbol_end.Createname(_class.vmt_mangledname));
  1523. {$ifdef vtentry}
  1524. { write vtinherit symbol to notify the linker of the class inheritance tree }
  1525. hs:='VTINHERIT'+'_'+_class.vmt_mangledname+'$$';
  1526. if assigned(_class.childof) then
  1527. hs:=hs+_class.childof.vmt_mangledname
  1528. else
  1529. hs:=hs+_class.vmt_mangledname;
  1530. current_asmdata.asmlists[al_globals].concat(tai_symbol.CreateName(hs,AT_DATA,0));
  1531. {$endif vtentry}
  1532. end;
  1533. end.