nobj.pas 68 KB

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