nobj.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  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. { in case of Java, copy the real name from the parent,
  325. since overriding "Destroy" with "destroy" is not
  326. going to work very well }
  327. if is_java_class_or_interface(_class) and
  328. (pd.procsym.realname<>vmtpd.procsym.realname) then
  329. pd.procsym.realname:=vmtpd.procsym.realname;
  330. { in case we are overriding an abstract method,
  331. decrease the number of abstract methods in this class }
  332. if (po_abstractmethod in vmtpd.procoptions) then
  333. dec(tobjectdef(pd.owner.defowner).abstractcnt);
  334. result:=true;
  335. exit;
  336. {$ifdef jvm}
  337. end
  338. else
  339. if not javanewtreeok and
  340. is_java_class_or_interface(_class) then
  341. begin
  342. { mangled names are the same -> can only override }
  343. MessagePos1(pd.fileinfo,parser_e_must_use_override,FullTypeName(tdef(vmtpd.owner.defowner),nil))
  344. {$endif jvm}
  345. end;
  346. { disable/hide old VMT entry }
  347. if updatevalues then
  348. vmtentryvis:=vis_hidden;
  349. end;
  350. end
  351. { both are virtual? }
  352. else if (po_virtualmethod in pd.procoptions) and
  353. (po_virtualmethod in vmtpd.procoptions) then
  354. begin
  355. { same parameter and return types (parameter specifiers will be checked below) }
  356. if hasequalpara and
  357. compatible_childmethod_resultdef(vmtpd.returndef,pd.returndef) then
  358. begin
  359. { inherite calling convention when it was explicit and the
  360. current definition has none explicit set }
  361. if (po_hascallingconvention in vmtpd.procoptions) and
  362. not(po_hascallingconvention in pd.procoptions) then
  363. begin
  364. pd.proccalloption:=vmtpd.proccalloption;
  365. include(pd.procoptions,po_hascallingconvention);
  366. end;
  367. { All parameter specifiers and some procedure the flags have to match
  368. except abstract and override }
  369. if (compare_paras(vmtpd.paras,pd.paras,cp_all,[cpo_ignoreuniv,cpo_ignorehidden])<te_equal) or
  370. (vmtpd.proccalloption<>pd.proccalloption) or
  371. (vmtpd.proctypeoption<>pd.proctypeoption) or
  372. ((vmtpd.procoptions*po_comp)<>(pd.procoptions*po_comp)) then
  373. begin
  374. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,pd.fullprocname(false));
  375. tprocsym(vmtpd.procsym).write_parameter_lists(pd);
  376. end;
  377. check_msg_str(vmtpd,pd);
  378. { Give a note if the new visibility is lower. For a higher
  379. visibility update the vmt info }
  380. if vmtentryvis>pd.visibility then
  381. MessagePos4(pd.fileinfo,parser_n_ignore_lower_visibility,pd.fullprocname(false),
  382. visibilityname[pd.visibility],tobjectdef(vmtpd.owner.defowner).objrealname^,visibilityname[vmtentryvis])
  383. else if pd.visibility>vmtentryvis then
  384. begin
  385. if updatevalues then
  386. vmtentryvis:=pd.visibility;
  387. end;
  388. { in case we are overriding an abstract method,
  389. decrease the number of abstract methods in this class }
  390. if (po_overridingmethod in pd.procoptions) and
  391. (po_abstractmethod in vmtpd.procoptions) then
  392. dec(tobjectdef(pd.owner.defowner).abstractcnt);
  393. { override old virtual method in VMT }
  394. if updatevalues then
  395. begin
  396. if (vmtpd.extnumber<>i) then
  397. internalerror(200611084);
  398. pd.extnumber:=vmtpd.extnumber;
  399. { in case of Java, copy the real name from the parent,
  400. since overriding "Destroy" with "destroy" is not
  401. going to work very well }
  402. if is_java_class_or_interface(_class) and
  403. (pd.procsym.realname<>vmtpd.procsym.realname) then
  404. pd.procsym.realname:=vmtpd.procsym.realname;
  405. vmtpd:=pd;
  406. end;
  407. result:=true;
  408. exit;
  409. end
  410. { different parameters }
  411. else
  412. begin
  413. { when we got an override directive then can search futher for
  414. the procedure to override.
  415. If we are starting a new virtual tree then hide the old tree }
  416. if not(po_overridingmethod in pd.procoptions) and
  417. not(pdoverload or hasoverloads) then
  418. begin
  419. if not(po_reintroduce in pd.procoptions) then
  420. begin
  421. if not is_object(_class) and
  422. not is_objc_class_or_protocol(_class) and
  423. not is_java_class_or_interface(_class) then
  424. MessagePos1(pd.fileinfo,parser_w_should_use_override,pd.fullprocname(false))
  425. else
  426. { objects don't allow starting a new virtual tree
  427. and neither do Objective-C or Java }
  428. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,vmtpd.fullprocname(false));
  429. end;
  430. { disable/hide old VMT entry }
  431. if updatevalues then
  432. vmtentryvis:=vis_hidden;
  433. end;
  434. end;
  435. end;
  436. end;
  437. function found_category_method(st: tsymtable): boolean;
  438. var
  439. entrycount: longint;
  440. cat: tobjectdef;
  441. vmtpd: tprocdef;
  442. vmtvis: tvisibility;
  443. begin
  444. result:=false;
  445. if is_objccategory(tdef(st.defowner)) then
  446. begin
  447. cat:=tobjectdef(st.defowner);
  448. { go through all of the category's methods to find the
  449. vmtentry corresponding to the procdef we are handling }
  450. for entrycount:=0 to cat.vmtentries.Count-1 do
  451. begin
  452. vmtpd:=pvmtentry(cat.vmtentries[entrycount])^.procdef;
  453. vmtvis:=pvmtentry(cat.vmtentries[entrycount])^.visibility;
  454. { don't change the vmtentry of the category }
  455. if found_entry(vmtpd,vmtvis,false) then
  456. begin
  457. result:=true;
  458. exit;
  459. end;
  460. end;
  461. end;
  462. end;
  463. begin
  464. result:=false;
  465. overridesclasshelper:=false;
  466. { Load other values for easier readability }
  467. hasoverloads:=(tprocsym(pd.procsym).ProcdefList.Count>1);
  468. pdoverload:=(po_overload in pd.procoptions);
  469. { compare with all stored definitions }
  470. for i:=0 to _class.vmtentries.Count-1 do
  471. begin
  472. if found_entry(pvmtentry(_class.vmtentries[i])^.procdef, pvmtentry(_class.vmtentries[i])^.visibility,true) then
  473. exit;
  474. end;
  475. { in case of Objective-C, also check the categories that apply to this
  476. class' *parent* for methods to override (don't allow class X to
  477. "override" a method added by a category to class X itself, since in
  478. that case the category method will in fact replace class X'
  479. "overriding" method }
  480. if is_objcclass(_class) and
  481. assigned(_class.childof) and
  482. search_objc_helper(_class.childof,pd.procsym.name,srsym,st) then
  483. begin
  484. overridesclasshelper:=found_category_method(st);
  485. end;
  486. { No entry found, we need to create a new entry }
  487. result:=true;
  488. end;
  489. function TVMTBuilder.intf_search_procdef_by_name(proc: tprocdef;const name: string): tprocdef;
  490. const
  491. po_comp = [po_classmethod,po_staticmethod,po_interrupt,po_iocheck,po_msgint,
  492. po_exports,po_varargs,po_explicitparaloc,po_nostackframe];
  493. var
  494. implprocdef : Tprocdef;
  495. i: cardinal;
  496. hclass : tobjectdef;
  497. hashedid : THashedIDString;
  498. srsym : tsym;
  499. begin
  500. result:=nil;
  501. hashedid.id:=name;
  502. hclass:=_class;
  503. while assigned(hclass) do
  504. begin
  505. srsym:=tsym(hclass.symtable.FindWithHash(hashedid));
  506. if assigned(srsym) and
  507. (srsym.typ=procsym) then
  508. begin
  509. for i:=0 to Tprocsym(srsym).ProcdefList.Count-1 do
  510. begin
  511. implprocdef:=tprocdef(tprocsym(srsym).ProcdefList[i]);
  512. if (implprocdef.procsym=tprocsym(srsym)) and
  513. (compare_paras(proc.paras,implprocdef.paras,cp_all,[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_ignoreuniv])>=te_equal) and
  514. (compare_defs(proc.returndef,implprocdef.returndef,nothingn)>=te_equal) and
  515. (proc.proccalloption=implprocdef.proccalloption) and
  516. (proc.proctypeoption=implprocdef.proctypeoption) and
  517. ((proc.procoptions*po_comp)=((implprocdef.procoptions+[po_virtualmethod])*po_comp)) and
  518. check_msg_str(proc,implprocdef) then
  519. begin
  520. result:=implprocdef;
  521. exit;
  522. end;
  523. end;
  524. end;
  525. hclass:=hclass.childof;
  526. end;
  527. end;
  528. procedure TVMTBuilder.intf_get_procdefs(ImplIntf:TImplementedInterface;IntfDef:TObjectDef);
  529. var
  530. i : longint;
  531. def : tdef;
  532. hs,
  533. prefix,
  534. mappedname: string;
  535. implprocdef: tprocdef;
  536. begin
  537. prefix:=ImplIntf.IntfDef.symtable.name^+'.';
  538. for i:=0 to IntfDef.symtable.DefList.Count-1 do
  539. begin
  540. def:=tdef(IntfDef.symtable.DefList[i]);
  541. if assigned(def) and
  542. (def.typ=procdef) then
  543. begin
  544. { Find implementing procdef
  545. 1. Check for mapped name
  546. 2. Use symbol name, but only if there's no mapping,
  547. or we're processing ancestor of interface.
  548. When modifying this code, ensure that webtbs/tw11862, webtbs/tw4950
  549. and webtbf/tw19591 stay correct. }
  550. implprocdef:=nil;
  551. hs:=prefix+tprocdef(def).procsym.name;
  552. mappedname:=ImplIntf.GetMapping(hs);
  553. if mappedname<>'' then
  554. implprocdef:=intf_search_procdef_by_name(tprocdef(def),mappedname);
  555. if not assigned(implprocdef) then
  556. if (mappedname='') or (ImplIntf.IntfDef<>IntfDef) then
  557. implprocdef:=intf_search_procdef_by_name(tprocdef(def),tprocdef(def).procsym.name);
  558. { Add procdef to the implemented interface }
  559. if assigned(implprocdef) then
  560. begin
  561. if (tobjectdef(implprocdef.struct).objecttype<>odt_objcclass) then
  562. begin
  563. { in case of Java, copy the real name from the parent,
  564. since overriding "Destroy" with "destroy" is not
  565. going to work very well }
  566. if is_javaclass(implprocdef.struct) and
  567. (implprocdef.procsym.realname<>tprocdef(def).procsym.realname) then
  568. implprocdef.procsym.realname:=tprocdef(def).procsym.realname;
  569. ImplIntf.AddImplProc(implprocdef);
  570. end
  571. else
  572. begin
  573. { If no message name has been specified for the method
  574. in the objcclass, copy it from the protocol
  575. definition. }
  576. if not(po_msgstr in tprocdef(def).procoptions) then
  577. begin
  578. include(tprocdef(def).procoptions,po_msgstr);
  579. implprocdef.messageinf.str:=stringdup(tprocdef(def).messageinf.str^);
  580. end
  581. else
  582. begin
  583. { If a message name has been specified in the
  584. objcclass, it has to match the message name in the
  585. protocol definition. }
  586. if (implprocdef.messageinf.str^<>tprocdef(def).messageinf.str^) then
  587. MessagePos2(implprocdef.fileinfo,parser_e_objc_message_name_changed,tprocdef(def).messageinf.str^,implprocdef.messageinf.str^);
  588. end;
  589. end;
  590. end
  591. else
  592. if (ImplIntf.IType=etStandard) and
  593. not(po_optional in tprocdef(def).procoptions) then
  594. MessagePos1(_Class.typesym.fileinfo,sym_e_no_matching_implementation_found,tprocdef(def).fullprocname(false));
  595. end;
  596. end;
  597. end;
  598. procedure TVMTBuilder.intf_get_procdefs_recursive(ImplIntf:TImplementedInterface;IntfDef:TObjectDef);
  599. begin
  600. if assigned(IntfDef.childof) then
  601. intf_get_procdefs_recursive(ImplIntf,IntfDef.childof);
  602. intf_get_procdefs(ImplIntf,IntfDef);
  603. end;
  604. procedure TVMTBuilder.prot_get_procdefs_recursive(ImplProt:TImplementedInterface;ProtDef:TObjectDef);
  605. var
  606. i: longint;
  607. begin
  608. { don't check the same protocol twice }
  609. if handledprotocols.IndexOf(ProtDef)<>-1 then
  610. exit;
  611. handledprotocols.add(ProtDef);
  612. for i:=0 to ProtDef.ImplementedInterfaces.count-1 do
  613. prot_get_procdefs_recursive(ImplProt,TImplementedInterface(ProtDef.ImplementedInterfaces[i]).intfdef);
  614. intf_get_procdefs(ImplProt,ProtDef);
  615. end;
  616. procedure TVMTBuilder.intf_optimize_vtbls;
  617. type
  618. tcompintfentry = record
  619. weight: longint;
  620. compintf: longint;
  621. end;
  622. { Max 1000 interface in the class header interfaces it's enough imho }
  623. tcompintfs = array[0..1000] of tcompintfentry;
  624. pcompintfs = ^tcompintfs;
  625. tequals = array[0..1000] of longint;
  626. pequals = ^tequals;
  627. timpls = array[0..1000] of longint;
  628. pimpls = ^timpls;
  629. var
  630. aequals: pequals;
  631. compats: pcompintfs;
  632. impls: pimpls;
  633. ImplIntfCount,
  634. w,i,j,k: longint;
  635. ImplIntfI,
  636. ImplIntfJ : TImplementedInterface;
  637. cij: boolean;
  638. cji: boolean;
  639. begin
  640. ImplIntfCount:=_class.ImplementedInterfaces.count;
  641. if ImplIntfCount>=High(tequals) then
  642. Internalerror(200006135);
  643. getmem(compats,sizeof(tcompintfentry)*ImplIntfCount);
  644. getmem(aequals,sizeof(longint)*ImplIntfCount);
  645. getmem(impls,sizeof(longint)*ImplIntfCount);
  646. filldword(compats^,(sizeof(tcompintfentry) div sizeof(dword))*ImplIntfCount,dword(-1));
  647. filldword(aequals^,ImplIntfCount,dword(-1));
  648. filldword(impls^,ImplIntfCount,dword(-1));
  649. { ismergepossible is a containing relation
  650. meaning of ismergepossible(a,b,w) =
  651. if implementorfunction map of a is contained implementorfunction map of b
  652. imp(a,b) and imp(b,c) => imp(a,c) ; imp(a,b) and imp(b,a) => a == b
  653. }
  654. { the order is very important for correct allocation }
  655. for i:=0 to ImplIntfCount-1 do
  656. begin
  657. for j:=i+1 to ImplIntfCount-1 do
  658. begin
  659. ImplIntfI:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  660. ImplIntfJ:=TImplementedInterface(_class.ImplementedInterfaces[j]);
  661. cij:=ImplIntfI.IsImplMergePossible(ImplIntfJ,w);
  662. cji:=ImplIntfJ.IsImplMergePossible(ImplIntfI,w);
  663. if cij and cji then { i equal j }
  664. begin
  665. { get minimum index of equal }
  666. if aequals^[j]=-1 then
  667. aequals^[j]:=i;
  668. end
  669. else if cij then
  670. begin
  671. { get minimum index of maximum weight }
  672. if compats^[i].weight<w then
  673. begin
  674. compats^[i].weight:=w;
  675. compats^[i].compintf:=j;
  676. end;
  677. end
  678. else if cji then
  679. begin
  680. { get minimum index of maximum weight }
  681. if (compats^[j].weight<w) then
  682. begin
  683. compats^[j].weight:=w;
  684. compats^[j].compintf:=i;
  685. end;
  686. end;
  687. end;
  688. end;
  689. { Reset, no replacements by default }
  690. for i:=0 to ImplIntfCount-1 do
  691. impls^[i]:=i;
  692. { Replace vtbls when equal or compat, repeat
  693. until there are no replacements possible anymore. This is
  694. needed for the cases like:
  695. First loop: 2->3, 3->1
  696. Second loop: 2->1 (because 3 was replaced with 1)
  697. }
  698. repeat
  699. k:=0;
  700. for i:=0 to ImplIntfCount-1 do
  701. begin
  702. if compats^[impls^[i]].compintf<>-1 then
  703. impls^[i]:=compats^[impls^[i]].compintf
  704. else if aequals^[impls^[i]]<>-1 then
  705. impls^[i]:=aequals^[impls^[i]]
  706. else
  707. inc(k);
  708. end;
  709. until k=ImplIntfCount;
  710. { Update the VtblImplIntf }
  711. for i:=0 to ImplIntfCount-1 do
  712. begin
  713. ImplIntfI:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  714. ImplIntfI.VtblImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[impls^[i]]);
  715. end;
  716. freemem(compats);
  717. freemem(aequals);
  718. freemem(impls);
  719. end;
  720. procedure TVMTBuilder.intf_allocate_vtbls;
  721. var
  722. i : longint;
  723. ImplIntf : TImplementedInterface;
  724. begin
  725. { Allocation vtbl space }
  726. for i:=0 to _class.ImplementedInterfaces.count-1 do
  727. begin
  728. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  729. { if it implements itself and if it's not implemented by delegation }
  730. if (ImplIntf.VtblImplIntf=ImplIntf) and (ImplIntf.IType=etStandard) then
  731. begin
  732. { allocate a pointer in the object memory }
  733. with tObjectSymtable(_class.symtable) do
  734. begin
  735. datasize:=align(datasize,sizeof(pint));
  736. ImplIntf.Ioffset:=datasize;
  737. datasize:=datasize+sizeof(pint);
  738. end;
  739. end;
  740. end;
  741. { Update ioffset of current interface with the ioffset from
  742. the interface that is reused to implements this interface }
  743. for i:=0 to _class.ImplementedInterfaces.count-1 do
  744. begin
  745. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  746. if ImplIntf.VtblImplIntf<>ImplIntf then
  747. ImplIntf.IOffset:=ImplIntf.VtblImplIntf.IOffset;
  748. end;
  749. end;
  750. procedure TVMTBuilder.generate_vmt;
  751. var
  752. i : longint;
  753. def : tdef;
  754. old_current_structdef : tabstractrecorddef;
  755. overridesclasshelper : boolean;
  756. begin
  757. old_current_structdef:=current_structdef;
  758. current_structdef:=_class;
  759. _class.resetvmtentries;
  760. { inherit (copy) VMT from parent object }
  761. if assigned(_class.childof) then
  762. begin
  763. if not assigned(_class.childof.vmtentries) then
  764. internalerror(200810281);
  765. _class.copyvmtentries(_class.childof);
  766. end;
  767. { process all procdefs, we must process the defs to
  768. keep the same order as that is written in the source
  769. to be compatible with the indexes in the interface vtable (PFV) }
  770. for i:=0 to _class.symtable.DefList.Count-1 do
  771. begin
  772. def:=tdef(_class.symtable.DefList[i]);
  773. if def.typ=procdef then
  774. begin
  775. { VMT entry }
  776. if is_new_vmt_entry(tprocdef(def),overridesclasshelper) then
  777. add_new_vmt_entry(tprocdef(def),overridesclasshelper);
  778. end;
  779. end;
  780. build_interface_mappings;
  781. if assigned(_class.ImplementedInterfaces) and
  782. not(is_objc_class_or_protocol(_class)) and
  783. not(is_java_class_or_interface(_class)) then
  784. begin
  785. { Optimize interface tables to reuse wrappers }
  786. intf_optimize_vtbls;
  787. { Allocate interface tables }
  788. intf_allocate_vtbls;
  789. end;
  790. current_structdef:=old_current_structdef;
  791. end;
  792. procedure TVMTBuilder.build_interface_mappings;
  793. var
  794. ImplIntf : TImplementedInterface;
  795. i: longint;
  796. begin
  797. { Find Procdefs implementing the interfaces (both Objective-C protocols
  798. and Java interfaces can have multiple parent interfaces, but in that
  799. case obviously no implementations are required) }
  800. if assigned(_class.ImplementedInterfaces) and
  801. not(_class.objecttype in [odt_objcprotocol,odt_interfacejava]) and
  802. // abstract java classes do not have to implement all interface
  803. // methods. todo: check that non-abstract descendents do!
  804. not((_class.objecttype=odt_javaclass) and (oo_is_abstract in _class.objectoptions)) then
  805. begin
  806. { Collect implementor functions into the tImplementedInterface.procdefs }
  807. case _class.objecttype of
  808. odt_class:
  809. begin
  810. for i:=0 to _class.ImplementedInterfaces.count-1 do
  811. begin
  812. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  813. intf_get_procdefs_recursive(ImplIntf,ImplIntf.IntfDef)
  814. end;
  815. end;
  816. odt_objcclass,
  817. odt_javaclass:
  818. begin
  819. { Object Pascal interfaces are afterwards optimized via the
  820. intf_optimize_vtbls() method, but we can't do this for
  821. protocols/Java interfaces -> check for duplicates here
  822. already. }
  823. handledprotocols:=tfpobjectlist.create(false);
  824. for i:=0 to _class.ImplementedInterfaces.count-1 do
  825. begin
  826. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  827. prot_get_procdefs_recursive(ImplIntf,ImplIntf.IntfDef);
  828. end;
  829. handledprotocols.free;
  830. end
  831. else
  832. internalerror(2009091801);
  833. end
  834. end;
  835. end;
  836. {*****************************************************************************
  837. TVMTWriter
  838. *****************************************************************************}
  839. constructor TVMTWriter.create(c:tobjectdef);
  840. begin
  841. inherited Create;
  842. _Class:=c;
  843. end;
  844. destructor TVMTWriter.destroy;
  845. begin
  846. end;
  847. {**************************************
  848. Message Tables
  849. **************************************}
  850. procedure TVMTWriter.disposeprocdeftree(p : pprocdeftree);
  851. begin
  852. if assigned(p^.l) then
  853. disposeprocdeftree(p^.l);
  854. if assigned(p^.r) then
  855. disposeprocdeftree(p^.r);
  856. dispose(p);
  857. end;
  858. procedure TVMTWriter.insertint(p : pprocdeftree;var at : pprocdeftree;var count:longint);
  859. begin
  860. if at=nil then
  861. begin
  862. at:=p;
  863. inc(count);
  864. end
  865. else
  866. begin
  867. if p^.data.messageinf.i<at^.data.messageinf.i then
  868. insertint(p,at^.l,count)
  869. else if p^.data.messageinf.i>at^.data.messageinf.i then
  870. insertint(p,at^.r,count)
  871. else
  872. Message1(parser_e_duplicate_message_label,tostr(p^.data.messageinf.i));
  873. end;
  874. end;
  875. procedure TVMTWriter.insertstr(p : pprocdeftree;var at : pprocdeftree;var count:longint);
  876. var
  877. i : integer;
  878. begin
  879. if at=nil then
  880. begin
  881. at:=p;
  882. inc(count);
  883. end
  884. else
  885. begin
  886. i:=CompareStr(p^.data.messageinf.str^,at^.data.messageinf.str^);
  887. if i<0 then
  888. insertstr(p,at^.l,count)
  889. else if i>0 then
  890. insertstr(p,at^.r,count)
  891. else
  892. Message1(parser_e_duplicate_message_label,p^.data.messageinf.str^);
  893. end;
  894. end;
  895. procedure TVMTWriter.insertmsgint(p:TObject;arg:pointer);
  896. var
  897. i : longint;
  898. pd : Tprocdef;
  899. pt : pprocdeftree;
  900. begin
  901. if tsym(p).typ<>procsym then
  902. exit;
  903. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  904. begin
  905. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  906. if po_msgint in pd.procoptions then
  907. begin
  908. new(pt);
  909. pt^.data:=pd;
  910. pt^.l:=nil;
  911. pt^.r:=nil;
  912. insertint(pt,root,plongint(arg)^);
  913. end;
  914. end;
  915. end;
  916. procedure TVMTWriter.insertmsgstr(p:TObject;arg:pointer);
  917. var
  918. i : longint;
  919. pd : Tprocdef;
  920. pt : pprocdeftree;
  921. begin
  922. if tsym(p).typ<>procsym then
  923. exit;
  924. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  925. begin
  926. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  927. if po_msgstr in pd.procoptions then
  928. begin
  929. new(pt);
  930. pt^.data:=pd;
  931. pt^.l:=nil;
  932. pt^.r:=nil;
  933. insertstr(pt,root,plongint(arg)^);
  934. end;
  935. end;
  936. end;
  937. procedure TVMTWriter.writenames(p : pprocdeftree);
  938. var
  939. ca : pchar;
  940. len : byte;
  941. begin
  942. current_asmdata.getdatalabel(p^.nl);
  943. if assigned(p^.l) then
  944. writenames(p^.l);
  945. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  946. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(p^.nl));
  947. len:=length(p^.data.messageinf.str^);
  948. current_asmdata.asmlists[al_globals].concat(tai_const.create_8bit(len));
  949. getmem(ca,len+1);
  950. move(p^.data.messageinf.str^[1],ca^,len);
  951. ca[len]:=#0;
  952. current_asmdata.asmlists[al_globals].concat(Tai_string.Create_pchar(ca,len));
  953. if assigned(p^.r) then
  954. writenames(p^.r);
  955. end;
  956. procedure TVMTWriter.writestrentry(p : pprocdeftree);
  957. begin
  958. if assigned(p^.l) then
  959. writestrentry(p^.l);
  960. { write name label }
  961. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  962. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(p^.nl));
  963. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  964. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(p^.data.mangledname,0));
  965. if assigned(p^.r) then
  966. writestrentry(p^.r);
  967. end;
  968. function TVMTWriter.genstrmsgtab : tasmlabel;
  969. var
  970. count : longint;
  971. begin
  972. root:=nil;
  973. count:=0;
  974. { insert all message handlers into a tree, sorted by name }
  975. _class.symtable.SymList.ForEachCall(@insertmsgstr,@count);
  976. { write all names }
  977. if assigned(root) then
  978. writenames(root);
  979. { now start writing of the message string table }
  980. current_asmdata.getdatalabel(result);
  981. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  982. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(result));
  983. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(longint))));
  984. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(count));
  985. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  986. if assigned(root) then
  987. begin
  988. writestrentry(root);
  989. disposeprocdeftree(root);
  990. end;
  991. end;
  992. procedure TVMTWriter.writeintentry(p : pprocdeftree);
  993. begin
  994. if assigned(p^.l) then
  995. writeintentry(p^.l);
  996. { write name label }
  997. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(longint))));
  998. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(p^.data.messageinf.i));
  999. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1000. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(p^.data.mangledname,0));
  1001. if assigned(p^.r) then
  1002. writeintentry(p^.r);
  1003. end;
  1004. function TVMTWriter.genintmsgtab : tasmlabel;
  1005. var
  1006. r : tasmlabel;
  1007. count : longint;
  1008. begin
  1009. root:=nil;
  1010. count:=0;
  1011. { insert all message handlers into a tree, sorted by name }
  1012. _class.symtable.SymList.ForEachCall(@insertmsgint,@count);
  1013. { now start writing of the message string table }
  1014. current_asmdata.getdatalabel(r);
  1015. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1016. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(r));
  1017. genintmsgtab:=r;
  1018. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(longint))));
  1019. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(count));
  1020. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1021. if assigned(root) then
  1022. begin
  1023. writeintentry(root);
  1024. disposeprocdeftree(root);
  1025. end;
  1026. end;
  1027. {$ifdef WITHDMT}
  1028. {**************************************
  1029. DMT
  1030. **************************************}
  1031. procedure TVMTWriter.insertdmtentry(p:TObject;arg:pointer);
  1032. var
  1033. hp : tprocdef;
  1034. pt : pprocdeftree;
  1035. begin
  1036. if tsym(p).typ=procsym then
  1037. begin
  1038. hp:=tprocsym(p).definition;
  1039. while assigned(hp) do
  1040. begin
  1041. if (po_msgint in hp.procoptions) then
  1042. begin
  1043. new(pt);
  1044. pt^.p:=hp;
  1045. pt^.l:=nil;
  1046. pt^.r:=nil;
  1047. insertint(pt,root);
  1048. end;
  1049. hp:=hp.nextoverloaded;
  1050. end;
  1051. end;
  1052. end;
  1053. procedure TVMTWriter.writedmtindexentry(p : pprocdeftree);
  1054. begin
  1055. if assigned(p^.l) then
  1056. writedmtindexentry(p^.l);
  1057. al_globals.concat(Tai_const.Create_32bit(p^.data.messageinf.i));
  1058. if assigned(p^.r) then
  1059. writedmtindexentry(p^.r);
  1060. end;
  1061. procedure TVMTWriter.writedmtaddressentry(p : pprocdeftree);
  1062. begin
  1063. if assigned(p^.l) then
  1064. writedmtaddressentry(p^.l);
  1065. al_globals.concat(Tai_const_symbol.Createname(p^.data.mangledname,0));
  1066. if assigned(p^.r) then
  1067. writedmtaddressentry(p^.r);
  1068. end;
  1069. function TVMTWriter.gendmt : tasmlabel;
  1070. var
  1071. r : tasmlabel;
  1072. begin
  1073. root:=nil;
  1074. count:=0;
  1075. gendmt:=nil;
  1076. { insert all message handlers into a tree, sorted by number }
  1077. _class.symtable.SymList.ForEachCall(insertdmtentry);
  1078. if count>0 then
  1079. begin
  1080. current_asmdata.getdatalabel(r);
  1081. gendmt:=r;
  1082. al_globals.concat(cai_align.create(const_align(sizeof(pint))));
  1083. al_globals.concat(Tai_label.Create(r));
  1084. { entries for caching }
  1085. al_globals.concat(Tai_const.Create_ptr(0));
  1086. al_globals.concat(Tai_const.Create_ptr(0));
  1087. al_globals.concat(Tai_const.Create_32bit(count));
  1088. if assigned(root) then
  1089. begin
  1090. writedmtindexentry(root);
  1091. writedmtaddressentry(root);
  1092. disposeprocdeftree(root);
  1093. end;
  1094. end;
  1095. end;
  1096. {$endif WITHDMT}
  1097. {**************************************
  1098. Published Methods
  1099. **************************************}
  1100. procedure TVMTWriter.do_count_published_methods(p:TObject;arg:pointer);
  1101. var
  1102. i : longint;
  1103. pd : tprocdef;
  1104. begin
  1105. if (tsym(p).typ<>procsym) then
  1106. exit;
  1107. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  1108. begin
  1109. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  1110. if (pd.procsym=tsym(p)) and
  1111. (pd.visibility=vis_published) then
  1112. inc(plongint(arg)^);
  1113. end;
  1114. end;
  1115. procedure TVMTWriter.do_gen_published_methods(p:TObject;arg:pointer);
  1116. var
  1117. i : longint;
  1118. l : tasmlabel;
  1119. pd : tprocdef;
  1120. begin
  1121. if (tsym(p).typ<>procsym) then
  1122. exit;
  1123. for i:=0 to Tprocsym(p).ProcdefList.Count-1 do
  1124. begin
  1125. pd:=tprocdef(Tprocsym(p).ProcdefList[i]);
  1126. if (pd.procsym=tsym(p)) and
  1127. (pd.visibility=vis_published) then
  1128. begin
  1129. current_asmdata.getdatalabel(l);
  1130. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,l.name,const_align(sizeof(pint)));
  1131. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l));
  1132. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(length(tsym(p).realname)));
  1133. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create(tsym(p).realname));
  1134. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(l));
  1135. if po_abstractmethod in pd.procoptions then
  1136. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil))
  1137. else
  1138. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(pd.mangledname,0));
  1139. end;
  1140. end;
  1141. end;
  1142. function TVMTWriter.genpublishedmethodstable : tasmlabel;
  1143. var
  1144. l : tasmlabel;
  1145. count : longint;
  1146. begin
  1147. count:=0;
  1148. _class.symtable.SymList.ForEachCall(@do_count_published_methods,@count);
  1149. if count>0 then
  1150. begin
  1151. current_asmdata.getdatalabel(l);
  1152. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1153. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(l));
  1154. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(count));
  1155. _class.symtable.SymList.ForEachCall(@do_gen_published_methods,nil);
  1156. genpublishedmethodstable:=l;
  1157. end
  1158. else
  1159. genpublishedmethodstable:=nil;
  1160. end;
  1161. function TVMTWriter.generate_field_table : tasmlabel;
  1162. var
  1163. i : longint;
  1164. sym : tsym;
  1165. fieldtable,
  1166. classtable : tasmlabel;
  1167. classindex,
  1168. fieldcount : longint;
  1169. classtablelist : TFPList;
  1170. begin
  1171. classtablelist:=TFPList.Create;
  1172. current_asmdata.getdatalabel(fieldtable);
  1173. current_asmdata.getdatalabel(classtable);
  1174. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  1175. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,classtable.name,const_align(sizeof(pint)));
  1176. { retrieve field info fields }
  1177. fieldcount:=0;
  1178. for i:=0 to _class.symtable.SymList.Count-1 do
  1179. begin
  1180. sym:=tsym(_class.symtable.SymList[i]);
  1181. if (sym.typ=fieldvarsym) and
  1182. (sym.visibility=vis_published) then
  1183. begin
  1184. if tfieldvarsym(sym).vardef.typ<>objectdef then
  1185. internalerror(200611032);
  1186. classindex:=classtablelist.IndexOf(tfieldvarsym(sym).vardef);
  1187. if classindex=-1 then
  1188. classtablelist.Add(tfieldvarsym(sym).vardef);
  1189. inc(fieldcount);
  1190. end;
  1191. end;
  1192. { write fields }
  1193. current_asmdata.asmlists[al_rtti].concat(Tai_label.Create(fieldtable));
  1194. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(fieldcount));
  1195. if (tf_requires_proper_alignment in target_info.flags) then
  1196. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  1197. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(classtable));
  1198. for i:=0 to _class.symtable.SymList.Count-1 do
  1199. begin
  1200. sym:=tsym(_class.symtable.SymList[i]);
  1201. if (sym.typ=fieldvarsym) and
  1202. (sym.visibility=vis_published) then
  1203. begin
  1204. if (tf_requires_proper_alignment in target_info.flags) then
  1205. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(pint)));
  1206. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_pint(tfieldvarsym(sym).fieldoffset));
  1207. classindex:=classtablelist.IndexOf(tfieldvarsym(sym).vardef);
  1208. if classindex=-1 then
  1209. internalerror(200611033);
  1210. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(classindex+1));
  1211. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(tfieldvarsym(sym).realname)));
  1212. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(tfieldvarsym(sym).realname));
  1213. end;
  1214. end;
  1215. { generate the class table }
  1216. current_asmdata.asmlists[al_rtti].concat(cai_align.create(const_align(sizeof(pint))));
  1217. current_asmdata.asmlists[al_rtti].concat(Tai_label.Create(classtable));
  1218. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(classtablelist.count));
  1219. if (tf_requires_proper_alignment in target_info.flags) then
  1220. current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
  1221. for i:=0 to classtablelist.Count-1 do
  1222. current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(tobjectdef(classtablelist[i]).vmt_mangledname,0));
  1223. classtablelist.free;
  1224. result:=fieldtable;
  1225. end;
  1226. {**************************************
  1227. Interface tables
  1228. **************************************}
  1229. function TVMTWriter.intf_get_vtbl_name(AImplIntf:TImplementedInterface): string;
  1230. begin
  1231. result:=make_mangledname('VTBL',_class.owner,_class.objname^+'_$_'+AImplIntf.IntfDef.objname^);
  1232. end;
  1233. procedure TVMTWriter.intf_create_vtbl(rawdata: TAsmList;AImplIntf:TImplementedInterface);
  1234. var
  1235. pd : tprocdef;
  1236. vtblstr,
  1237. hs : string;
  1238. i : longint;
  1239. begin
  1240. vtblstr:=intf_get_vtbl_name(AImplIntf);
  1241. section_symbol_start(rawdata,vtblstr,AT_DATA,true,sec_data,const_align(sizeof(pint)));
  1242. if assigned(AImplIntf.procdefs) then
  1243. begin
  1244. for i:=0 to AImplIntf.procdefs.count-1 do
  1245. begin
  1246. pd:=tprocdef(AImplIntf.procdefs[i]);
  1247. hs:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+AImplIntf.IntfDef.objname^+'_$_'+
  1248. tostr(i)+'_$_'+pd.mangledname);
  1249. { create reference }
  1250. rawdata.concat(Tai_const.Createname(hs,0));
  1251. end;
  1252. end;
  1253. section_symbol_end(rawdata,vtblstr);
  1254. end;
  1255. procedure TVMTWriter.intf_gen_intf_ref(rawdata: TAsmList;AImplIntf:TImplementedInterface);
  1256. var
  1257. iidlabel,
  1258. guidlabel : tasmlabel;
  1259. i: longint;
  1260. pd: tprocdef;
  1261. begin
  1262. { GUID }
  1263. if AImplIntf.IntfDef.objecttype in [odt_interfacecom] then
  1264. begin
  1265. { label for GUID }
  1266. current_asmdata.getdatalabel(guidlabel);
  1267. rawdata.concat(cai_align.create(const_align(sizeof(pint))));
  1268. rawdata.concat(Tai_label.Create(guidlabel));
  1269. with AImplIntf.IntfDef.iidguid^ do
  1270. begin
  1271. rawdata.concat(Tai_const.Create_32bit(longint(D1)));
  1272. rawdata.concat(Tai_const.Create_16bit(D2));
  1273. rawdata.concat(Tai_const.Create_16bit(D3));
  1274. for i:=Low(D4) to High(D4) do
  1275. rawdata.concat(Tai_const.Create_8bit(D4[i]));
  1276. end;
  1277. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(guidlabel));
  1278. end
  1279. else
  1280. begin
  1281. { nil for Corba interfaces }
  1282. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1283. end;
  1284. { VTable }
  1285. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(intf_get_vtbl_name(AImplIntf.VtblImplIntf),0));
  1286. { IOffset field }
  1287. case AImplIntf.VtblImplIntf.IType of
  1288. etFieldValue, etFieldValueClass,
  1289. etStandard:
  1290. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(AImplIntf.VtblImplIntf.IOffset));
  1291. etStaticMethodResult, etStaticMethodClass:
  1292. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(
  1293. tprocdef(tpropertysym(AImplIntf.ImplementsGetter).propaccesslist[palt_read].procdef).mangledname,
  1294. 0
  1295. ));
  1296. etVirtualMethodResult, etVirtualMethodClass:
  1297. begin
  1298. pd := tprocdef(tpropertysym(AImplIntf.ImplementsGetter).propaccesslist[palt_read].procdef);
  1299. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(tobjectdef(pd.struct).vmtmethodoffset(pd.extnumber)));
  1300. end;
  1301. else
  1302. internalerror(200802162);
  1303. end;
  1304. { IIDStr }
  1305. current_asmdata.getdatalabel(iidlabel);
  1306. rawdata.concat(cai_align.create(const_align(sizeof(pint))));
  1307. rawdata.concat(Tai_label.Create(iidlabel));
  1308. rawdata.concat(Tai_const.Create_8bit(length(AImplIntf.IntfDef.iidstr^)));
  1309. if AImplIntf.IntfDef.objecttype=odt_interfacecom then
  1310. rawdata.concat(Tai_string.Create(upper(AImplIntf.IntfDef.iidstr^)))
  1311. else
  1312. rawdata.concat(Tai_string.Create(AImplIntf.IntfDef.iidstr^));
  1313. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(iidlabel));
  1314. { IType }
  1315. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(aint(AImplIntf.VtblImplIntf.IType)));
  1316. end;
  1317. function TVMTWriter.intf_write_table:TAsmLabel;
  1318. var
  1319. rawdata : TAsmList;
  1320. i : longint;
  1321. ImplIntf : TImplementedInterface;
  1322. intftablelab : tasmlabel;
  1323. begin
  1324. current_asmdata.getdatalabel(intftablelab);
  1325. current_asmdata.asmlists[al_globals].concat(cai_align.create(const_align(sizeof(pint))));
  1326. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(intftablelab));
  1327. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(_class.ImplementedInterfaces.count));
  1328. rawdata:=TAsmList.Create;
  1329. { Write vtbls }
  1330. for i:=0 to _class.ImplementedInterfaces.count-1 do
  1331. begin
  1332. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  1333. if ImplIntf.VtblImplIntf=ImplIntf then
  1334. intf_create_vtbl(rawdata,ImplIntf);
  1335. end;
  1336. { Write vtbl references }
  1337. for i:=0 to _class.ImplementedInterfaces.count-1 do
  1338. begin
  1339. ImplIntf:=TImplementedInterface(_class.ImplementedInterfaces[i]);
  1340. intf_gen_intf_ref(rawdata,ImplIntf);
  1341. end;
  1342. { Write interface table }
  1343. current_asmdata.asmlists[al_globals].concatlist(rawdata);
  1344. rawdata.free;
  1345. result:=intftablelab;
  1346. end;
  1347. { Write interface identifiers to the data section }
  1348. procedure TVMTWriter.writeinterfaceids;
  1349. var
  1350. i : longint;
  1351. s : string;
  1352. begin
  1353. if assigned(_class.iidguid) then
  1354. begin
  1355. s:=make_mangledname('IID',_class.owner,_class.objname^);
  1356. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1357. new_section(current_asmdata.asmlists[al_globals],sec_rodata,s,const_align(sizeof(pint)));
  1358. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(s,AT_DATA,0));
  1359. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_32bit(longint(_class.iidguid^.D1)));
  1360. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_16bit(_class.iidguid^.D2));
  1361. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_16bit(_class.iidguid^.D3));
  1362. for i:=Low(_class.iidguid^.D4) to High(_class.iidguid^.D4) do
  1363. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_8bit(_class.iidguid^.D4[i]));
  1364. end;
  1365. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1366. s:=make_mangledname('IIDSTR',_class.owner,_class.objname^);
  1367. new_section(current_asmdata.asmlists[al_globals],sec_rodata,s,0);
  1368. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(s,AT_DATA,0));
  1369. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_8bit(length(_class.iidstr^)));
  1370. current_asmdata.asmlists[al_globals].concat(Tai_string.Create(_class.iidstr^));
  1371. end;
  1372. procedure TVMTWriter.writevirtualmethods(List:TAsmList);
  1373. var
  1374. vmtpd : tprocdef;
  1375. vmtentry : pvmtentry;
  1376. i : longint;
  1377. procname : string;
  1378. {$ifdef vtentry}
  1379. hs : string;
  1380. {$endif vtentry}
  1381. begin
  1382. if not assigned(_class.VMTEntries) then
  1383. exit;
  1384. for i:=0 to _class.VMTEntries.Count-1 do
  1385. begin
  1386. vmtentry:=pvmtentry(_class.vmtentries[i]);
  1387. vmtpd:=vmtentry^.procdef;
  1388. { safety checks }
  1389. if not(po_virtualmethod in vmtpd.procoptions) then
  1390. internalerror(200611082);
  1391. if vmtpd.extnumber<>i then
  1392. internalerror(200611083);
  1393. if (po_abstractmethod in vmtpd.procoptions) then
  1394. procname:='FPC_ABSTRACTERROR'
  1395. else if not wpoinfomanager.optimized_name_for_vmt(_class,vmtpd,procname) then
  1396. procname:=vmtpd.mangledname;
  1397. List.concat(Tai_const.createname(procname,0));
  1398. {$ifdef vtentry}
  1399. hs:='VTENTRY'+'_'+_class.vmt_mangledname+'$$'+tostr(_class.vmtmethodoffset(i) div sizeof(pint));
  1400. current_asmdata.asmlists[al_globals].concat(tai_symbol.CreateName(hs,AT_DATA,0));
  1401. {$endif vtentry}
  1402. end;
  1403. end;
  1404. procedure TVMTWriter.writevmt;
  1405. var
  1406. methodnametable,intmessagetable,
  1407. strmessagetable,classnamelabel,
  1408. fieldtablelabel : tasmlabel;
  1409. hs: string;
  1410. {$ifdef WITHDMT}
  1411. dmtlabel : tasmlabel;
  1412. {$endif WITHDMT}
  1413. interfacetable : tasmlabel;
  1414. begin
  1415. {$ifdef WITHDMT}
  1416. dmtlabel:=gendmt;
  1417. {$endif WITHDMT}
  1418. { write tables for classes, this must be done before the actual
  1419. class is written, because we need the labels defined }
  1420. if is_class(_class) then
  1421. begin
  1422. current_asmdata.getdatalabel(classnamelabel);
  1423. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1424. new_section(current_asmdata.asmlists[al_globals],sec_rodata,classnamelabel.name,const_align(sizeof(pint)));
  1425. { interface table }
  1426. if _class.ImplementedInterfaces.count>0 then
  1427. interfacetable:=intf_write_table;
  1428. methodnametable:=genpublishedmethodstable;
  1429. fieldtablelabel:=generate_field_table;
  1430. { write class name }
  1431. current_asmdata.asmlists[al_globals].concat(Tai_label.Create(classnamelabel));
  1432. hs:=_class.RttiName;
  1433. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_8bit(length(hs)));
  1434. current_asmdata.asmlists[al_globals].concat(Tai_string.Create(hs));
  1435. { generate message and dynamic tables }
  1436. if (oo_has_msgstr in _class.objectoptions) then
  1437. strmessagetable:=genstrmsgtab;
  1438. if (oo_has_msgint in _class.objectoptions) then
  1439. intmessagetable:=genintmsgtab;
  1440. end;
  1441. { write debug info }
  1442. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  1443. new_section(current_asmdata.asmlists[al_globals],sec_rodata,_class.vmt_mangledname,const_align(sizeof(pint)));
  1444. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(_class.vmt_mangledname,AT_DATA,0));
  1445. { determine the size with symtable.datasize, because }
  1446. { size gives back 4 for classes }
  1447. current_asmdata.asmlists[al_globals].concat(Tai_const.Create(aitconst_ptr,tObjectSymtable(_class.symtable).datasize));
  1448. current_asmdata.asmlists[al_globals].concat(Tai_const.Create(aitconst_ptr,-int64(tObjectSymtable(_class.symtable).datasize)));
  1449. {$ifdef WITHDMT}
  1450. if _class.classtype=ct_object then
  1451. begin
  1452. if assigned(dmtlabel) then
  1453. current_asmdata.asmlists[al_globals].concat(Tai_const_symbol.Create(dmtlabel)))
  1454. else
  1455. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_ptr(0));
  1456. end;
  1457. {$endif WITHDMT}
  1458. { write pointer to parent VMT, this isn't implemented in TP }
  1459. { but this is not used in FPC ? (PM) }
  1460. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1461. { it is not written for parents that don't have any vmt !! }
  1462. if assigned(_class.childof) and
  1463. (oo_has_vmt in _class.childof.objectoptions) then
  1464. current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(_class.childof.vmt_mangledname,0))
  1465. else
  1466. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1467. { write extended info for classes, for the order see rtl/inc/objpash.inc }
  1468. if is_class(_class) then
  1469. begin
  1470. { pointer to class name string }
  1471. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(classnamelabel));
  1472. { pointer to dynamic table or nil }
  1473. if (oo_has_msgint in _class.objectoptions) then
  1474. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(intmessagetable))
  1475. else
  1476. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1477. { pointer to method table or nil }
  1478. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(methodnametable));
  1479. { pointer to field table }
  1480. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(fieldtablelabel));
  1481. { pointer to type info of published section }
  1482. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(RTTIWriter.get_rtti_label(_class,fullrtti)));
  1483. { inittable for con-/destruction }
  1484. if _class.members_need_inittable then
  1485. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(RTTIWriter.get_rtti_label(_class,initrtti)))
  1486. else
  1487. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1488. { auto table }
  1489. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1490. { interface table }
  1491. if _class.ImplementedInterfaces.count>0 then
  1492. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(interfacetable))
  1493. else if _class.implements_any_interfaces then
  1494. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil))
  1495. else
  1496. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(current_asmdata.RefAsmSymbol('FPC_EMPTYINTF')));
  1497. { table for string messages }
  1498. if (oo_has_msgstr in _class.objectoptions) then
  1499. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(strmessagetable))
  1500. else
  1501. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  1502. end;
  1503. { write virtual methods }
  1504. writevirtualmethods(current_asmdata.asmlists[al_globals]);
  1505. current_asmdata.asmlists[al_globals].concat(Tai_const.create(aitconst_ptr,0));
  1506. { write the size of the VMT }
  1507. current_asmdata.asmlists[al_globals].concat(Tai_symbol_end.Createname(_class.vmt_mangledname));
  1508. {$ifdef vtentry}
  1509. { write vtinherit symbol to notify the linker of the class inheritance tree }
  1510. hs:='VTINHERIT'+'_'+_class.vmt_mangledname+'$$';
  1511. if assigned(_class.childof) then
  1512. hs:=hs+_class.childof.vmt_mangledname
  1513. else
  1514. hs:=hs+_class.vmt_mangledname;
  1515. current_asmdata.asmlists[al_globals].concat(tai_symbol.CreateName(hs,AT_DATA,0));
  1516. {$endif vtentry}
  1517. end;
  1518. end.