nobj.pas 68 KB

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