nobj.pas 67 KB

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