nobj.pas 68 KB

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