nobj.pas 68 KB

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