nobj.pas 68 KB

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