nobj.pas 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Routines for the code generation of data structures
  5. like VMT, Messages, VTables, Interfaces descs
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit nobj;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. cutils,cclasses,cpuinfo,
  24. symdef,aasmbase,aasmtai,aasmcpu,globtype
  25. {$ifdef Delphi}
  26. ,dmisc
  27. {$endif}
  28. ;
  29. type
  30. pprocdeftree = ^tprocdeftree;
  31. tprocdeftree = record
  32. data : tprocdef;
  33. nl : tasmlabel;
  34. l,r : pprocdeftree;
  35. end;
  36. pprocdefcoll = ^tprocdefcoll;
  37. tprocdefcoll = record
  38. data : tprocdef;
  39. hidden : boolean;
  40. next : pprocdefcoll;
  41. end;
  42. psymcoll = ^tsymcoll;
  43. tsymcoll = record
  44. speedvalue : cardinal;
  45. name : pstring;
  46. data : pprocdefcoll;
  47. next : psymcoll;
  48. end;
  49. tclassheader=class
  50. private
  51. _Class : tobjectdef;
  52. count : integer;
  53. private
  54. { message tables }
  55. root : pprocdeftree;
  56. procedure disposeprocdeftree(p : pprocdeftree);
  57. procedure insertmsgint(p : tnamedindexitem;arg:pointer);
  58. procedure insertmsgstr(p : tnamedindexitem;arg:pointer);
  59. procedure insertint(p : pprocdeftree;var at : pprocdeftree);
  60. procedure insertstr(p : pprocdeftree;var at : pprocdeftree);
  61. procedure writenames(p : pprocdeftree);
  62. procedure writeintentry(p : pprocdeftree);
  63. procedure writestrentry(p : pprocdeftree);
  64. {$ifdef WITHDMT}
  65. private
  66. { dmt }
  67. procedure insertdmtentry(p : tnamedindexitem;arg:pointer);
  68. procedure writedmtindexentry(p : pprocdeftree);
  69. procedure writedmtaddressentry(p : pprocdeftree);
  70. {$endif}
  71. private
  72. { published methods }
  73. procedure do_count(p : tnamedindexitem;arg:pointer);
  74. procedure genpubmethodtableentry(p : tnamedindexitem;arg:pointer);
  75. private
  76. { vmt }
  77. wurzel : psymcoll;
  78. nextvirtnumber : integer;
  79. has_constructor,
  80. has_virtual_method : boolean;
  81. procedure eachsym(sym : tnamedindexitem;arg:pointer);
  82. procedure disposevmttree;
  83. procedure writevirtualmethods(List:TAAsmoutput);
  84. private
  85. { interface tables }
  86. function gintfgetvtbllabelname(intfindex: integer): string;
  87. procedure gintfcreatevtbl(intfindex: integer; rawdata,rawcode: TAAsmoutput);
  88. procedure gintfgenentry(intfindex, contintfindex: integer; rawdata: TAAsmoutput);
  89. procedure gintfoptimizevtbls(implvtbl : plongintarray);
  90. procedure gintfwritedata;
  91. function gintfgetcprocdef(proc: tprocdef;const name: string): tprocdef;
  92. procedure gintfdoonintf(intf: tobjectdef; intfindex: longint);
  93. procedure gintfwalkdowninterface(intf: tobjectdef; intfindex: longint);
  94. protected
  95. { adjusts the self value with ioffset when casting a interface
  96. to a class
  97. }
  98. procedure adjustselfvalue(procdef: tprocdef;ioffset: aword);virtual;
  99. { generates the wrapper for a call to a method via an interface }
  100. procedure cgintfwrapper(asmlist: TAAsmoutput; procdef: tprocdef; const labelname: string; ioffset: longint);virtual;abstract;
  101. public
  102. constructor create(c:tobjectdef);
  103. destructor destroy;override;
  104. { generates the message tables for a class }
  105. function genstrmsgtab : tasmlabel;
  106. function genintmsgtab : tasmlabel;
  107. function genpublishedmethodstable : tasmlabel;
  108. { generates a VMT entries }
  109. procedure genvmt;
  110. {$ifdef WITHDMT}
  111. { generates a DMT for _class }
  112. function gendmt : tasmlabel;
  113. {$endif WITHDMT}
  114. { interfaces }
  115. function genintftable: tasmlabel;
  116. { write the VMT to datasegment }
  117. procedure writevmt;
  118. procedure writeinterfaceids;
  119. end;
  120. tclassheaderclass=class of tclassheader;
  121. var
  122. cclassheader : tclassheaderclass;
  123. implementation
  124. uses
  125. {$ifdef delphi}
  126. sysutils,
  127. {$else}
  128. strings,
  129. {$endif}
  130. globals,verbose,
  131. symtable,symconst,symtype,symsym,defbase,paramgr,
  132. {$ifdef GDB}
  133. gdb,
  134. {$endif GDB}
  135. cpubase,cgbase,cginfo,cgobj,rgobj
  136. ;
  137. {*****************************************************************************
  138. TClassHeader
  139. *****************************************************************************}
  140. constructor tclassheader.create(c:tobjectdef);
  141. begin
  142. inherited Create;
  143. _Class:=c;
  144. end;
  145. destructor tclassheader.destroy;
  146. begin
  147. disposevmttree;
  148. end;
  149. {**************************************
  150. Message Tables
  151. **************************************}
  152. procedure tclassheader.disposeprocdeftree(p : pprocdeftree);
  153. begin
  154. if assigned(p^.l) then
  155. disposeprocdeftree(p^.l);
  156. if assigned(p^.r) then
  157. disposeprocdeftree(p^.r);
  158. dispose(p);
  159. end;
  160. procedure tclassheader.insertint(p : pprocdeftree;var at : pprocdeftree);
  161. begin
  162. if at=nil then
  163. begin
  164. at:=p;
  165. inc(count);
  166. end
  167. else
  168. begin
  169. if p^.data.messageinf.i<at^.data.messageinf.i then
  170. insertint(p,at^.l)
  171. else if p^.data.messageinf.i>at^.data.messageinf.i then
  172. insertint(p,at^.r)
  173. else
  174. Message1(parser_e_duplicate_message_label,tostr(p^.data.messageinf.i));
  175. end;
  176. end;
  177. procedure tclassheader.insertstr(p : pprocdeftree;var at : pprocdeftree);
  178. var
  179. i : integer;
  180. begin
  181. if at=nil then
  182. begin
  183. at:=p;
  184. inc(count);
  185. end
  186. else
  187. begin
  188. i:=strcomp(p^.data.messageinf.str,at^.data.messageinf.str);
  189. if i<0 then
  190. insertstr(p,at^.l)
  191. else if i>0 then
  192. insertstr(p,at^.r)
  193. else
  194. Message1(parser_e_duplicate_message_label,strpas(p^.data.messageinf.str));
  195. end;
  196. end;
  197. procedure tclassheader.insertmsgint(p : tnamedindexitem;arg:pointer);
  198. var
  199. i : cardinal;
  200. def: Tprocdef;
  201. pt : pprocdeftree;
  202. begin
  203. if tsym(p).typ=procsym then
  204. for i:=1 to Tprocsym(p).procdef_count do
  205. begin
  206. def:=Tprocsym(p).procdef[i];
  207. if po_msgint in def.procoptions then
  208. begin
  209. new(pt);
  210. pt^.data:=def;
  211. pt^.l:=nil;
  212. pt^.r:=nil;
  213. insertint(pt,root);
  214. end;
  215. end;
  216. end;
  217. procedure tclassheader.insertmsgstr(p : tnamedindexitem;arg:pointer);
  218. var
  219. i : cardinal;
  220. def: Tprocdef;
  221. pt : pprocdeftree;
  222. begin
  223. if tsym(p).typ=procsym then
  224. for i:=1 to Tprocsym(p).procdef_count do
  225. begin
  226. def:=Tprocsym(p).procdef[i];
  227. if po_msgstr in def.procoptions then
  228. begin
  229. new(pt);
  230. pt^.data:=def;
  231. pt^.l:=nil;
  232. pt^.r:=nil;
  233. insertstr(pt,root);
  234. end;
  235. end;
  236. end;
  237. procedure tclassheader.writenames(p : pprocdeftree);
  238. begin
  239. objectlibrary.getdatalabel(p^.nl);
  240. if assigned(p^.l) then
  241. writenames(p^.l);
  242. datasegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  243. dataSegment.concat(Tai_label.Create(p^.nl));
  244. dataSegment.concat(Tai_const.Create_8bit(strlen(p^.data.messageinf.str)));
  245. dataSegment.concat(Tai_string.Create_pchar(p^.data.messageinf.str));
  246. if assigned(p^.r) then
  247. writenames(p^.r);
  248. end;
  249. procedure tclassheader.writestrentry(p : pprocdeftree);
  250. begin
  251. if assigned(p^.l) then
  252. writestrentry(p^.l);
  253. { write name label }
  254. dataSegment.concat(Tai_const_symbol.Create(p^.nl));
  255. dataSegment.concat(Tai_const_symbol.Createname(p^.data.mangledname));
  256. if assigned(p^.r) then
  257. writestrentry(p^.r);
  258. end;
  259. function tclassheader.genstrmsgtab : tasmlabel;
  260. var
  261. r : tasmlabel;
  262. begin
  263. root:=nil;
  264. count:=0;
  265. { insert all message handlers into a tree, sorted by name }
  266. _class.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}insertmsgstr,nil);
  267. { write all names }
  268. if assigned(root) then
  269. writenames(root);
  270. { now start writing of the message string table }
  271. objectlibrary.getdatalabel(r);
  272. datasegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  273. dataSegment.concat(Tai_label.Create(r));
  274. genstrmsgtab:=r;
  275. dataSegment.concat(Tai_const.Create_32bit(count));
  276. if assigned(root) then
  277. begin
  278. writestrentry(root);
  279. disposeprocdeftree(root);
  280. end;
  281. end;
  282. procedure tclassheader.writeintentry(p : pprocdeftree);
  283. begin
  284. if assigned(p^.l) then
  285. writeintentry(p^.l);
  286. { write name label }
  287. dataSegment.concat(Tai_const.Create_32bit(p^.data.messageinf.i));
  288. dataSegment.concat(Tai_const_symbol.Createname(p^.data.mangledname));
  289. if assigned(p^.r) then
  290. writeintentry(p^.r);
  291. end;
  292. function tclassheader.genintmsgtab : tasmlabel;
  293. var
  294. r : tasmlabel;
  295. begin
  296. root:=nil;
  297. count:=0;
  298. { insert all message handlers into a tree, sorted by name }
  299. _class.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}insertmsgint,nil);
  300. { now start writing of the message string table }
  301. objectlibrary.getdatalabel(r);
  302. datasegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  303. dataSegment.concat(Tai_label.Create(r));
  304. genintmsgtab:=r;
  305. dataSegment.concat(Tai_const.Create_32bit(count));
  306. if assigned(root) then
  307. begin
  308. writeintentry(root);
  309. disposeprocdeftree(root);
  310. end;
  311. end;
  312. {$ifdef WITHDMT}
  313. {**************************************
  314. DMT
  315. **************************************}
  316. procedure tclassheader.insertdmtentry(p : tnamedindexitem;arg:pointer);
  317. var
  318. hp : tprocdef;
  319. pt : pprocdeftree;
  320. begin
  321. if tsym(p).typ=procsym then
  322. begin
  323. hp:=tprocsym(p).definition;
  324. while assigned(hp) do
  325. begin
  326. if (po_msgint in hp.procoptions) then
  327. begin
  328. new(pt);
  329. pt^.p:=hp;
  330. pt^.l:=nil;
  331. pt^.r:=nil;
  332. insertint(pt,root);
  333. end;
  334. hp:=hp.nextoverloaded;
  335. end;
  336. end;
  337. end;
  338. procedure tclassheader.writedmtindexentry(p : pprocdeftree);
  339. begin
  340. if assigned(p^.l) then
  341. writedmtindexentry(p^.l);
  342. dataSegment.concat(Tai_const.Create_32bit(p^.data.messageinf.i));
  343. if assigned(p^.r) then
  344. writedmtindexentry(p^.r);
  345. end;
  346. procedure tclassheader.writedmtaddressentry(p : pprocdeftree);
  347. begin
  348. if assigned(p^.l) then
  349. writedmtaddressentry(p^.l);
  350. dataSegment.concat(Tai_const_symbol.Createname(p^.data.mangledname));
  351. if assigned(p^.r) then
  352. writedmtaddressentry(p^.r);
  353. end;
  354. function tclassheader.gendmt : tasmlabel;
  355. var
  356. r : tasmlabel;
  357. begin
  358. root:=nil;
  359. count:=0;
  360. gendmt:=nil;
  361. { insert all message handlers into a tree, sorted by number }
  362. _class.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}insertdmtentry);
  363. if count>0 then
  364. begin
  365. objectlibrary.getdatalabel(r);
  366. gendmt:=r;
  367. datasegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  368. dataSegment.concat(Tai_label.Create(r));
  369. { entries for caching }
  370. dataSegment.concat(Tai_const.Create_32bit(0));
  371. dataSegment.concat(Tai_const.Create_32bit(0));
  372. dataSegment.concat(Tai_const.Create_32bit(count));
  373. if assigned(root) then
  374. begin
  375. writedmtindexentry(root);
  376. writedmtaddressentry(root);
  377. disposeprocdeftree(root);
  378. end;
  379. end;
  380. end;
  381. {$endif WITHDMT}
  382. {**************************************
  383. Published Methods
  384. **************************************}
  385. procedure tclassheader.do_count(p : tnamedindexitem;arg:pointer);
  386. begin
  387. if (tsym(p).typ=procsym) and (sp_published in tsym(p).symoptions) then
  388. inc(count);
  389. end;
  390. procedure tclassheader.genpubmethodtableentry(p : tnamedindexitem;arg:pointer);
  391. var
  392. hp : tprocdef;
  393. l : tasmlabel;
  394. begin
  395. if (tsym(p).typ=procsym) and (sp_published in tsym(p).symoptions) then
  396. begin
  397. if Tprocsym(p).procdef_count>1 then
  398. internalerror(1209992);
  399. hp:=tprocsym(p).first_procdef;
  400. objectlibrary.getdatalabel(l);
  401. consts.concat(tai_align.create(const_align(POINTER_SIZE)));
  402. Consts.concat(Tai_label.Create(l));
  403. Consts.concat(Tai_const.Create_8bit(length(p.name)));
  404. Consts.concat(Tai_string.Create(p.name));
  405. dataSegment.concat(Tai_const_symbol.Create(l));
  406. dataSegment.concat(Tai_const_symbol.Createname(hp.mangledname));
  407. end;
  408. end;
  409. function tclassheader.genpublishedmethodstable : tasmlabel;
  410. var
  411. l : tasmlabel;
  412. begin
  413. count:=0;
  414. _class.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}do_count,nil);
  415. if count>0 then
  416. begin
  417. objectlibrary.getdatalabel(l);
  418. datasegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  419. dataSegment.concat(Tai_label.Create(l));
  420. dataSegment.concat(Tai_const.Create_32bit(count));
  421. _class.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}genpubmethodtableentry,nil);
  422. genpublishedmethodstable:=l;
  423. end
  424. else
  425. genpublishedmethodstable:=nil;
  426. end;
  427. {**************************************
  428. VMT
  429. **************************************}
  430. procedure tclassheader.eachsym(sym : tnamedindexitem;arg:pointer);
  431. var
  432. procdefcoll : pprocdefcoll;
  433. hp : pprocdeflist;
  434. symcoll : psymcoll;
  435. _name : string;
  436. _speed : cardinal;
  437. procedure newdefentry(pd:tprocdef);
  438. begin
  439. new(procdefcoll);
  440. procdefcoll^.data:=pd;
  441. procdefcoll^.hidden:=false;
  442. procdefcoll^.next:=symcoll^.data;
  443. symcoll^.data:=procdefcoll;
  444. { if it's a virtual method }
  445. if (po_virtualmethod in pd.procoptions) then
  446. begin
  447. { then it gets a number ... }
  448. pd.extnumber:=nextvirtnumber;
  449. { and we inc the number }
  450. inc(nextvirtnumber);
  451. has_virtual_method:=true;
  452. end;
  453. if (pd.proctypeoption=potype_constructor) then
  454. has_constructor:=true;
  455. { check, if a method should be overridden }
  456. if (pd._class=_class) and
  457. (po_overridingmethod in pd.procoptions) then
  458. MessagePos1(pd.fileinfo,parser_e_nothing_to_be_overridden,pd.fullprocname);
  459. end;
  460. { creates a new entry in the procsym list }
  461. procedure newentry;
  462. var i:cardinal;
  463. begin
  464. { if not, generate a new symbol item }
  465. new(symcoll);
  466. symcoll^.speedvalue:=sym.speedvalue;
  467. symcoll^.name:=stringdup(sym.name);
  468. symcoll^.next:=wurzel;
  469. symcoll^.data:=nil;
  470. wurzel:=symcoll;
  471. { inserts all definitions }
  472. for i:=1 to Tprocsym(sym).procdef_count do
  473. newdefentry(Tprocsym(sym).procdef[i]);
  474. end;
  475. label
  476. handlenextdef;
  477. var
  478. pd : tprocdef;
  479. i : cardinal;
  480. is_visible,
  481. hasoverloads,
  482. pdoverload : boolean;
  483. begin
  484. { put only sub routines into the VMT, and routines
  485. that are visible to the current class. Skip private
  486. methods in other classes }
  487. if (tsym(sym).typ=procsym) then
  488. begin
  489. { is this symbol visible from the class that we are
  490. generating. This will be used to hide the other procdefs.
  491. When the symbol is not visible we don't hide the other
  492. procdefs, because they can be reused in the next class.
  493. The check to skip the invisible methods that are in the
  494. list is futher down in the code }
  495. is_visible:=tprocsym(sym).is_visible_for_object(_class);
  496. { check the current list of symbols }
  497. _name:=sym.name;
  498. _speed:=sym.speedvalue;
  499. symcoll:=wurzel;
  500. while assigned(symcoll) do
  501. begin
  502. { does the symbol already exist in the list? First
  503. compare speedvalue before doing the string compare to
  504. speed it up a little }
  505. if (_speed=symcoll^.speedvalue) and
  506. (_name=symcoll^.name^) then
  507. begin
  508. hasoverloads:=(Tprocsym(sym).procdef_count>1);
  509. { walk through all defs of the symbol }
  510. for i:=1 to Tprocsym(sym).procdef_count do
  511. begin
  512. pd:=Tprocsym(sym).procdef[i];
  513. if pd.procsym=sym then
  514. begin
  515. pdoverload:=(po_overload in pd.procoptions);
  516. { compare with all stored definitions }
  517. procdefcoll:=symcoll^.data;
  518. while assigned(procdefcoll) do
  519. begin
  520. { compare only if the definition is not hidden }
  521. if not procdefcoll^.hidden then
  522. begin
  523. { check if one of the two methods has virtual }
  524. if (po_virtualmethod in procdefcoll^.data.procoptions) or
  525. (po_virtualmethod in pd.procoptions) then
  526. begin
  527. { if the current definition has no virtual then hide the
  528. old virtual if the new definition has the same arguments or
  529. when it has no overload directive and no overloads }
  530. if not(po_virtualmethod in pd.procoptions) then
  531. begin
  532. if tstoredsym(procdefcoll^.data.procsym).is_visible_for_object(pd._class) and
  533. (not(pdoverload or hasoverloads) or
  534. equal_paras(procdefcoll^.data.para,pd.para,cp_value_equal_const,false)) then
  535. begin
  536. if is_visible then
  537. procdefcoll^.hidden:=true;
  538. if _class=pd._class then
  539. MessagePos1(pd.fileinfo,parser_w_should_use_override,pd.fullprocname);
  540. end;
  541. end
  542. { if both are virtual we check the header }
  543. else if (po_virtualmethod in pd.procoptions) and
  544. (po_virtualmethod in procdefcoll^.data.procoptions) then
  545. begin
  546. { new one has not override }
  547. if is_class(_class) and
  548. not(po_overridingmethod in pd.procoptions) then
  549. begin
  550. { we start a new virtual tree, hide the old }
  551. if (not(pdoverload or hasoverloads) or
  552. equal_paras(procdefcoll^.data.para,pd.para,cp_value_equal_const,false)) and
  553. (tstoredsym(procdefcoll^.data.procsym).is_visible_for_object(pd._class)) then
  554. begin
  555. if is_visible then
  556. procdefcoll^.hidden:=true;
  557. if _class=pd._class then
  558. MessagePos1(pd.fileinfo,parser_w_should_use_override,pd.fullprocname);
  559. end;
  560. end
  561. { check if the method to override is visible }
  562. else if (po_overridingmethod in pd.procoptions) and
  563. (not tstoredsym(procdefcoll^.data.procsym).is_visible_for_object(pd._class)) then
  564. begin
  565. { do nothing, the error will follow when adding the entry }
  566. end
  567. { same parameters }
  568. else if (equal_paras(procdefcoll^.data.para,pd.para,cp_value_equal_const,false)) then
  569. begin
  570. { overload is inherited }
  571. if (po_overload in procdefcoll^.data.procoptions) then
  572. include(pd.procoptions,po_overload);
  573. { the flags have to match except abstract and override }
  574. { only if both are virtual !! }
  575. if (procdefcoll^.data.proccalloption<>pd.proccalloption) or
  576. (procdefcoll^.data.proctypeoption<>pd.proctypeoption) or
  577. ((procdefcoll^.data.procoptions-
  578. [po_abstractmethod,po_overridingmethod,po_assembler,po_overload])<>
  579. (pd.procoptions-[po_abstractmethod,po_overridingmethod,po_assembler,po_overload])) then
  580. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,pd.fullprocname);
  581. { error, if the return types aren't equal }
  582. if not(is_equal(procdefcoll^.data.rettype.def,pd.rettype.def)) and
  583. not((procdefcoll^.data.rettype.def.deftype=objectdef) and
  584. (pd.rettype.def.deftype=objectdef) and
  585. is_class(procdefcoll^.data.rettype.def) and
  586. is_class(pd.rettype.def) and
  587. (tobjectdef(pd.rettype.def).is_related(
  588. tobjectdef(procdefcoll^.data.rettype.def)))) then
  589. Message2(parser_e_overridden_methods_not_same_ret,pd.fullprocnamewithret,
  590. procdefcoll^.data.fullprocnamewithret);
  591. { now set the number }
  592. pd.extnumber:=procdefcoll^.data.extnumber;
  593. { and exchange }
  594. procdefcoll^.data:=pd;
  595. goto handlenextdef;
  596. end
  597. { different parameters }
  598. else
  599. begin
  600. { when we got an override directive then can search futher for
  601. the procedure to override.
  602. If we are starting a new virtual tree then hide the old tree }
  603. if not(po_overridingmethod in pd.procoptions) and
  604. not pdoverload then
  605. begin
  606. if is_visible then
  607. procdefcoll^.hidden:=true;
  608. if _class=pd._class then
  609. MessagePos1(pd.fileinfo,parser_w_should_use_override,pd.fullprocname);
  610. end;
  611. end;
  612. end
  613. else
  614. begin
  615. { the new definition is virtual and the old static, we hide the old one
  616. if the new defintion has not the overload directive }
  617. if is_visible and
  618. ((not(pdoverload or hasoverloads)) or
  619. equal_paras(procdefcoll^.data.para,pd.para,cp_value_equal_const,false)) then
  620. procdefcoll^.hidden:=true;
  621. end;
  622. end
  623. else
  624. begin
  625. { both are static, we hide the old one if the new defintion
  626. has not the overload directive }
  627. if is_visible and
  628. ((not pdoverload) or
  629. equal_paras(procdefcoll^.data.para,pd.para,cp_value_equal_const,false)) then
  630. procdefcoll^.hidden:=true;
  631. end;
  632. end; { not hidden }
  633. procdefcoll:=procdefcoll^.next;
  634. end;
  635. { if it isn't saved in the list we create a new entry }
  636. newdefentry(pd);
  637. end;
  638. handlenextdef:
  639. end;
  640. exit;
  641. end;
  642. symcoll:=symcoll^.next;
  643. end;
  644. newentry;
  645. end;
  646. end;
  647. procedure tclassheader.disposevmttree;
  648. var
  649. symcoll : psymcoll;
  650. procdefcoll : pprocdefcoll;
  651. begin
  652. { disposes the above generated tree }
  653. symcoll:=wurzel;
  654. while assigned(symcoll) do
  655. begin
  656. wurzel:=symcoll^.next;
  657. stringdispose(symcoll^.name);
  658. procdefcoll:=symcoll^.data;
  659. while assigned(procdefcoll) do
  660. begin
  661. symcoll^.data:=procdefcoll^.next;
  662. dispose(procdefcoll);
  663. procdefcoll:=symcoll^.data;
  664. end;
  665. dispose(symcoll);
  666. symcoll:=wurzel;
  667. end;
  668. end;
  669. procedure tclassheader.genvmt;
  670. procedure do_genvmt(p : tobjectdef);
  671. begin
  672. { start with the base class }
  673. if assigned(p.childof) then
  674. do_genvmt(p.childof);
  675. { walk through all public syms }
  676. p.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}eachsym,nil);
  677. end;
  678. begin
  679. wurzel:=nil;
  680. nextvirtnumber:=0;
  681. has_constructor:=false;
  682. has_virtual_method:=false;
  683. { generates a tree of all used methods }
  684. do_genvmt(_class);
  685. if not(is_interface(_class)) and
  686. has_virtual_method and
  687. not(has_constructor) then
  688. Message1(parser_w_virtual_without_constructor,_class.objrealname^);
  689. end;
  690. {**************************************
  691. Interface tables
  692. **************************************}
  693. function tclassheader.gintfgetvtbllabelname(intfindex: integer): string;
  694. begin
  695. gintfgetvtbllabelname:=mangledname_prefix('VTBL',_class.owner)+_class.objname^+
  696. '_$_'+_class.implementedinterfaces.interfaces(intfindex).objname^;
  697. end;
  698. procedure tclassheader.gintfcreatevtbl(intfindex: integer; rawdata,rawcode: TAAsmoutput);
  699. var
  700. implintf: timplementedinterfaces;
  701. curintf: tobjectdef;
  702. proccount: integer;
  703. tmps: string;
  704. i: longint;
  705. begin
  706. implintf:=_class.implementedinterfaces;
  707. curintf:=implintf.interfaces(intfindex);
  708. if (cs_create_smart in aktmoduleswitches) then
  709. rawdata.concat(Tai_symbol.Createname_global(gintfgetvtbllabelname(intfindex),0))
  710. else
  711. rawdata.concat(Tai_symbol.Createname(gintfgetvtbllabelname(intfindex),0));
  712. proccount:=implintf.implproccount(intfindex);
  713. for i:=1 to proccount do
  714. begin
  715. tmps:=mangledname_prefix('WRPR',_class.owner)+_class.objname^+'_$_'+curintf.objname^+'_$_'+
  716. tostr(i)+'_$_'+
  717. implintf.implprocs(intfindex,i).mangledname;
  718. { create wrapper code }
  719. cgintfwrapper(rawcode,implintf.implprocs(intfindex,i),tmps,implintf.ioffsets(intfindex)^);
  720. { create reference }
  721. rawdata.concat(Tai_const_symbol.Createname(tmps));
  722. end;
  723. end;
  724. procedure tclassheader.gintfgenentry(intfindex, contintfindex: integer; rawdata: TAAsmoutput);
  725. var
  726. implintf: timplementedinterfaces;
  727. curintf: tobjectdef;
  728. tmplabel: tasmlabel;
  729. i: longint;
  730. begin
  731. implintf:=_class.implementedinterfaces;
  732. curintf:=implintf.interfaces(intfindex);
  733. { GUID }
  734. if curintf.objecttype in [odt_interfacecom] then
  735. begin
  736. { label for GUID }
  737. objectlibrary.getdatalabel(tmplabel);
  738. rawdata.concat(tai_align.create(const_align(pointer_size)));
  739. rawdata.concat(Tai_label.Create(tmplabel));
  740. rawdata.concat(Tai_const.Create_32bit(curintf.iidguid.D1));
  741. rawdata.concat(Tai_const.Create_16bit(curintf.iidguid.D2));
  742. rawdata.concat(Tai_const.Create_16bit(curintf.iidguid.D3));
  743. for i:=Low(curintf.iidguid.D4) to High(curintf.iidguid.D4) do
  744. rawdata.concat(Tai_const.Create_8bit(curintf.iidguid.D4[i]));
  745. dataSegment.concat(Tai_const_symbol.Create(tmplabel));
  746. end
  747. else
  748. begin
  749. { nil for Corba interfaces }
  750. dataSegment.concat(Tai_const.Create_32bit(0)); { nil }
  751. end;
  752. { VTable }
  753. dataSegment.concat(Tai_const_symbol.Createname(gintfgetvtbllabelname(contintfindex)));
  754. { IOffset field }
  755. dataSegment.concat(Tai_const.Create_32bit(implintf.ioffsets(contintfindex)^));
  756. { IIDStr }
  757. objectlibrary.getdatalabel(tmplabel);
  758. rawdata.concat(tai_align.create(const_align(pointer_size)));
  759. rawdata.concat(Tai_label.Create(tmplabel));
  760. rawdata.concat(Tai_const.Create_8bit(length(curintf.iidstr^)));
  761. if curintf.objecttype=odt_interfacecom then
  762. rawdata.concat(Tai_string.Create(upper(curintf.iidstr^)))
  763. else
  764. rawdata.concat(Tai_string.Create(curintf.iidstr^));
  765. dataSegment.concat(Tai_const_symbol.Create(tmplabel));
  766. end;
  767. procedure tclassheader.gintfoptimizevtbls(implvtbl : plongintarray);
  768. type
  769. tcompintfentry = record
  770. weight: longint;
  771. compintf: longint;
  772. end;
  773. { Max 1000 interface in the class header interfaces it's enough imho }
  774. tcompintfs = packed array[1..1000] of tcompintfentry;
  775. pcompintfs = ^tcompintfs;
  776. tequals = packed array[1..1000] of longint;
  777. pequals = ^tequals;
  778. var
  779. max: longint;
  780. equals: pequals;
  781. compats: pcompintfs;
  782. i: longint;
  783. j: longint;
  784. w: longint;
  785. cij: boolean;
  786. cji: boolean;
  787. begin
  788. max:=_class.implementedinterfaces.count;
  789. if max>High(tequals) then
  790. Internalerror(200006135);
  791. getmem(compats,sizeof(tcompintfentry)*max);
  792. getmem(equals,sizeof(longint)*max);
  793. fillchar(compats^,sizeof(tcompintfentry)*max,0);
  794. fillchar(equals^,sizeof(longint)*max,0);
  795. { ismergepossible is a containing relation
  796. meaning of ismergepossible(a,b,w) =
  797. if implementorfunction map of a is contained implementorfunction map of b
  798. imp(a,b) and imp(b,c) => imp(a,c) ; imp(a,b) and imp(b,a) => a == b
  799. }
  800. { the order is very important for correct allocation }
  801. for i:=1 to max do
  802. begin
  803. for j:=i+1 to max do
  804. begin
  805. cij:=_class.implementedinterfaces.isimplmergepossible(i,j,w);
  806. cji:=_class.implementedinterfaces.isimplmergepossible(j,i,w);
  807. if cij and cji then { i equal j }
  808. begin
  809. { get minimum index of equal }
  810. if equals^[j]=0 then
  811. equals^[j]:=i;
  812. end
  813. else if cij then
  814. begin
  815. { get minimum index of maximum weight }
  816. if compats^[i].weight<w then
  817. begin
  818. compats^[i].weight:=w;
  819. compats^[i].compintf:=j;
  820. end;
  821. end
  822. else if cji then
  823. begin
  824. { get minimum index of maximum weight }
  825. if (compats^[j].weight<w) then
  826. begin
  827. compats^[j].weight:=w;
  828. compats^[j].compintf:=i;
  829. end;
  830. end;
  831. end;
  832. end;
  833. for i:=1 to max do
  834. begin
  835. if compats^[i].compintf<>0 then
  836. implvtbl[i]:=compats^[i].compintf
  837. else if equals^[i]<>0 then
  838. implvtbl[i]:=equals^[i]
  839. else
  840. implvtbl[i]:=i;
  841. end;
  842. freemem(compats,sizeof(tcompintfentry)*max);
  843. freemem(equals,sizeof(longint)*max);
  844. end;
  845. procedure tclassheader.gintfwritedata;
  846. var
  847. rawdata,rawcode: taasmoutput;
  848. impintfindexes: plongintarray;
  849. max: longint;
  850. i: longint;
  851. begin
  852. max:=_class.implementedinterfaces.count;
  853. getmem(impintfindexes,(max+1)*sizeof(longint));
  854. gintfoptimizevtbls(impintfindexes);
  855. rawdata:=TAAsmOutput.Create;
  856. rawcode:=TAAsmOutput.Create;
  857. dataSegment.concat(Tai_const.Create_16bit(max));
  858. { Two pass, one for allocation and vtbl creation }
  859. for i:=1 to max do
  860. begin
  861. if impintfindexes[i]=i then { if implement itself }
  862. begin
  863. { allocate a pointer in the object memory }
  864. with tstoredsymtable(_class.symtable) do
  865. begin
  866. if (dataalignment>=pointer_size) then
  867. datasize:=align(datasize,dataalignment)
  868. else
  869. datasize:=align(datasize,pointer_size);
  870. _class.implementedinterfaces.ioffsets(i)^:=datasize;
  871. datasize:=datasize+pointer_size;
  872. end;
  873. { write vtbl }
  874. gintfcreatevtbl(i,rawdata,rawcode);
  875. end;
  876. end;
  877. { second pass: for fill interfacetable and remained ioffsets }
  878. for i:=1 to max do
  879. begin
  880. if i<>impintfindexes[i] then { why execute x:=x ? }
  881. with _class.implementedinterfaces do
  882. ioffsets(i)^:=ioffsets(impintfindexes[i])^;
  883. gintfgenentry(i,impintfindexes[i],rawdata);
  884. end;
  885. dataSegment.concatlist(rawdata);
  886. rawdata.free;
  887. codeSegment.concatlist(rawcode);
  888. rawcode.free;
  889. freemem(impintfindexes,(max+1)*sizeof(longint));
  890. end;
  891. function tclassheader.gintfgetcprocdef(proc: tprocdef;const name: string): tprocdef;
  892. var
  893. sym: tprocsym;
  894. implprocdef : Tprocdef;
  895. i: cardinal;
  896. begin
  897. gintfgetcprocdef:=nil;
  898. sym:=tprocsym(search_class_member(_class,name));
  899. if assigned(sym) and (sym.typ=procsym) then
  900. for i:=1 to sym.procdef_count do
  901. begin
  902. implprocdef:=sym.procdef[i];
  903. if equal_paras(proc.para,implprocdef.para,cp_none,false) and
  904. (proc.proccalloption=implprocdef.proccalloption) then
  905. begin
  906. gintfgetcprocdef:=implprocdef;
  907. exit;
  908. end;
  909. end;
  910. end;
  911. procedure tclassheader.gintfdoonintf(intf: tobjectdef; intfindex: longint);
  912. var
  913. i: longint;
  914. proc: tprocdef;
  915. procname: string; { for error }
  916. mappedname: string;
  917. nextexist: pointer;
  918. implprocdef: tprocdef;
  919. begin
  920. for i:=1 to intf.symtable.defindex.count do
  921. begin
  922. proc:=tprocdef(intf.symtable.defindex.search(i));
  923. if proc.deftype=procdef then
  924. begin
  925. procname:='';
  926. implprocdef:=nil;
  927. nextexist:=nil;
  928. repeat
  929. mappedname:=_class.implementedinterfaces.getmappings(intfindex,proc.procsym.name,nextexist);
  930. if procname='' then
  931. procname:=proc.procsym.name;
  932. //mappedname; { for error messages }
  933. if mappedname<>'' then
  934. implprocdef:=gintfgetcprocdef(proc,mappedname);
  935. until assigned(implprocdef) or not assigned(nextexist);
  936. if not assigned(implprocdef) then
  937. implprocdef:=gintfgetcprocdef(proc,proc.procsym.name);
  938. if procname='' then
  939. procname:=proc.procsym.name;
  940. if assigned(implprocdef) then
  941. _class.implementedinterfaces.addimplproc(intfindex,implprocdef)
  942. else
  943. Message1(sym_e_no_matching_implementation_found,proc.fullprocnamewithret);
  944. end;
  945. end;
  946. end;
  947. procedure tclassheader.gintfwalkdowninterface(intf: tobjectdef; intfindex: longint);
  948. begin
  949. if assigned(intf.childof) then
  950. gintfwalkdowninterface(intf.childof,intfindex);
  951. gintfdoonintf(intf,intfindex);
  952. end;
  953. function tclassheader.genintftable: tasmlabel;
  954. var
  955. intfindex: longint;
  956. curintf: tobjectdef;
  957. intftable: tasmlabel;
  958. begin
  959. { 1. step collect implementor functions into the implementedinterfaces.implprocs }
  960. for intfindex:=1 to _class.implementedinterfaces.count do
  961. begin
  962. curintf:=_class.implementedinterfaces.interfaces(intfindex);
  963. gintfwalkdowninterface(curintf,intfindex);
  964. end;
  965. { 2. step calc required fieldcount and their offsets in the object memory map
  966. and write data }
  967. objectlibrary.getdatalabel(intftable);
  968. dataSegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  969. dataSegment.concat(Tai_label.Create(intftable));
  970. gintfwritedata;
  971. _class.implementedinterfaces.clearimplprocs; { release temporary information }
  972. genintftable:=intftable;
  973. end;
  974. { Write interface identifiers to the data section }
  975. procedure tclassheader.writeinterfaceids;
  976. var
  977. i: longint;
  978. begin
  979. if _class.isiidguidvalid then
  980. begin
  981. if (cs_create_smart in aktmoduleswitches) then
  982. dataSegment.concat(Tai_cut.Create);
  983. dataSegment.concat(Tai_symbol.Createname_global(mangledname_prefix('IID',_class.owner)+_class.objname^,0));
  984. dataSegment.concat(Tai_const.Create_32bit(longint(_class.iidguid.D1)));
  985. dataSegment.concat(Tai_const.Create_16bit(_class.iidguid.D2));
  986. dataSegment.concat(Tai_const.Create_16bit(_class.iidguid.D3));
  987. for i:=Low(_class.iidguid.D4) to High(_class.iidguid.D4) do
  988. dataSegment.concat(Tai_const.Create_8bit(_class.iidguid.D4[i]));
  989. end;
  990. if (cs_create_smart in aktmoduleswitches) then
  991. dataSegment.concat(Tai_cut.Create);
  992. dataSegment.concat(Tai_symbol.Createname_global(mangledname_prefix('IIDSTR',_class.owner)+_class.objname^,0));
  993. dataSegment.concat(Tai_const.Create_8bit(length(_class.iidstr^)));
  994. dataSegment.concat(Tai_string.Create(_class.iidstr^));
  995. end;
  996. procedure tclassheader.writevirtualmethods(List:TAAsmoutput);
  997. var
  998. symcoll : psymcoll;
  999. procdefcoll : pprocdefcoll;
  1000. i : longint;
  1001. begin
  1002. { walk trough all numbers for virtual methods and search }
  1003. { the method }
  1004. for i:=0 to nextvirtnumber-1 do
  1005. begin
  1006. symcoll:=wurzel;
  1007. { walk trough all symbols }
  1008. while assigned(symcoll) do
  1009. begin
  1010. { walk trough all methods }
  1011. procdefcoll:=symcoll^.data;
  1012. while assigned(procdefcoll) do
  1013. begin
  1014. { writes the addresses to the VMT }
  1015. { but only this which are declared as virtual }
  1016. if procdefcoll^.data.extnumber=i then
  1017. begin
  1018. if (po_virtualmethod in procdefcoll^.data.procoptions) then
  1019. begin
  1020. { if a method is abstract, then is also the }
  1021. { class abstract and it's not allow to }
  1022. { generates an instance }
  1023. if (po_abstractmethod in procdefcoll^.data.procoptions) then
  1024. begin
  1025. include(_class.objectoptions,oo_has_abstract);
  1026. List.concat(Tai_const_symbol.Createname('FPC_ABSTRACTERROR'));
  1027. end
  1028. else
  1029. begin
  1030. List.concat(Tai_const_symbol.createname(procdefcoll^.data.mangledname));
  1031. end;
  1032. end;
  1033. end;
  1034. procdefcoll:=procdefcoll^.next;
  1035. end;
  1036. symcoll:=symcoll^.next;
  1037. end;
  1038. end;
  1039. end;
  1040. { generates the vmt for classes as well as for objects }
  1041. procedure tclassheader.writevmt;
  1042. var
  1043. methodnametable,intmessagetable,
  1044. strmessagetable,classnamelabel,
  1045. fieldtablelabel : tasmlabel;
  1046. {$ifdef WITHDMT}
  1047. dmtlabel : tasmlabel;
  1048. {$endif WITHDMT}
  1049. interfacetable : tasmlabel;
  1050. begin
  1051. {$ifdef WITHDMT}
  1052. dmtlabel:=gendmt;
  1053. {$endif WITHDMT}
  1054. if (cs_create_smart in aktmoduleswitches) then
  1055. dataSegment.concat(Tai_cut.Create);
  1056. { write tables for classes, this must be done before the actual
  1057. class is written, because we need the labels defined }
  1058. if is_class(_class) then
  1059. begin
  1060. { interface table }
  1061. if _class.implementedinterfaces.count>0 then
  1062. begin
  1063. if (cs_create_smart in aktmoduleswitches) then
  1064. codeSegment.concat(Tai_cut.Create);
  1065. interfacetable:=genintftable;
  1066. end;
  1067. methodnametable:=genpublishedmethodstable;
  1068. fieldtablelabel:=_class.generate_field_table;
  1069. { write class name }
  1070. objectlibrary.getdatalabel(classnamelabel);
  1071. dataSegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  1072. dataSegment.concat(Tai_label.Create(classnamelabel));
  1073. dataSegment.concat(Tai_const.Create_8bit(length(_class.objrealname^)));
  1074. dataSegment.concat(Tai_string.Create(_class.objrealname^));
  1075. { generate message and dynamic tables }
  1076. if (oo_has_msgstr in _class.objectoptions) then
  1077. strmessagetable:=genstrmsgtab;
  1078. if (oo_has_msgint in _class.objectoptions) then
  1079. intmessagetable:=genintmsgtab
  1080. else
  1081. dataSegment.concat(Tai_const.Create_32bit(0));
  1082. end;
  1083. { write debug info }
  1084. {$ifdef GDB}
  1085. if (cs_debuginfo in aktmoduleswitches) then
  1086. begin
  1087. do_count_dbx:=true;
  1088. if assigned(_class.owner) and assigned(_class.owner.name) then
  1089. dataSegment.concat(Tai_stabs.Create(strpnew('"vmt_'+_class.owner.name^+_class.name+':S'+
  1090. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+_class.vmt_mangledname)));
  1091. end;
  1092. {$endif GDB}
  1093. dataSegment.concat(tai_align.create(const_align(POINTER_SIZE)));
  1094. dataSegment.concat(Tai_symbol.Createdataname_global(_class.vmt_mangledname,0));
  1095. { determine the size with symtable.datasize, because }
  1096. { size gives back 4 for classes }
  1097. dataSegment.concat(Tai_const.Create_32bit(_class.symtable.datasize));
  1098. dataSegment.concat(Tai_const.Create_32bit(-_class.symtable.datasize));
  1099. {$ifdef WITHDMT}
  1100. if _class.classtype=ct_object then
  1101. begin
  1102. if assigned(dmtlabel) then
  1103. dataSegment.concat(Tai_const_symbol.Create(dmtlabel)))
  1104. else
  1105. dataSegment.concat(Tai_const.Create_32bit(0));
  1106. end;
  1107. {$endif WITHDMT}
  1108. { write pointer to parent VMT, this isn't implemented in TP }
  1109. { but this is not used in FPC ? (PM) }
  1110. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1111. { it is not written for parents that don't have any vmt !! }
  1112. if assigned(_class.childof) and
  1113. (oo_has_vmt in _class.childof.objectoptions) then
  1114. dataSegment.concat(Tai_const_symbol.Createname(_class.childof.vmt_mangledname))
  1115. else
  1116. dataSegment.concat(Tai_const.Create_32bit(0));
  1117. { write extended info for classes, for the order see rtl/inc/objpash.inc }
  1118. if is_class(_class) then
  1119. begin
  1120. { pointer to class name string }
  1121. dataSegment.concat(Tai_const_symbol.Create(classnamelabel));
  1122. { pointer to dynamic table }
  1123. if (oo_has_msgint in _class.objectoptions) then
  1124. dataSegment.concat(Tai_const_symbol.Create(intmessagetable))
  1125. else
  1126. dataSegment.concat(Tai_const.Create_32bit(0));
  1127. { pointer to method table }
  1128. if assigned(methodnametable) then
  1129. dataSegment.concat(Tai_const_symbol.Create(methodnametable))
  1130. else
  1131. dataSegment.concat(Tai_const.Create_32bit(0));
  1132. { pointer to field table }
  1133. dataSegment.concat(Tai_const_symbol.Create(fieldtablelabel));
  1134. { pointer to type info of published section }
  1135. if (oo_can_have_published in _class.objectoptions) then
  1136. dataSegment.concat(Tai_const_symbol.Create(_class.get_rtti_label(fullrtti)))
  1137. else
  1138. dataSegment.concat(Tai_const.Create_32bit(0));
  1139. { inittable for con-/destruction }
  1140. if _class.members_need_inittable then
  1141. dataSegment.concat(Tai_const_symbol.Create(_class.get_rtti_label(initrtti)))
  1142. else
  1143. dataSegment.concat(Tai_const.Create_32bit(0));
  1144. { auto table }
  1145. dataSegment.concat(Tai_const.Create_32bit(0));
  1146. { interface table }
  1147. if _class.implementedinterfaces.count>0 then
  1148. dataSegment.concat(Tai_const_symbol.Create(interfacetable))
  1149. else
  1150. dataSegment.concat(Tai_const.Create_32bit(0));
  1151. { table for string messages }
  1152. if (oo_has_msgstr in _class.objectoptions) then
  1153. dataSegment.concat(Tai_const_symbol.Create(strmessagetable))
  1154. else
  1155. dataSegment.concat(Tai_const.Create_32bit(0));
  1156. end;
  1157. { write virtual methods }
  1158. writevirtualmethods(dataSegment);
  1159. { write the size of the VMT }
  1160. dataSegment.concat(Tai_symbol_end.Createname(_class.vmt_mangledname));
  1161. end;
  1162. procedure tclassheader.adjustselfvalue(procdef: tprocdef;ioffset: aword);
  1163. var
  1164. href : treference;
  1165. l : tparalocation;
  1166. begin
  1167. l:=paramanager.getselflocation(procdef);
  1168. case l.loc of
  1169. LOC_REGISTER:
  1170. cg.a_op_const_reg(exprasmlist,OP_SUB,ioffset,l.register);
  1171. LOC_REFERENCE:
  1172. begin
  1173. reference_reset_base(href,l.reference.index,l.reference.offset);
  1174. cg.a_op_const_ref(exprasmlist,OP_SUB,OS_ADDR,ioffset,href);
  1175. end
  1176. else
  1177. internalerror(2002080801);
  1178. end;
  1179. end;
  1180. initialization
  1181. cclassheader:=tclassheader;
  1182. end.
  1183. {
  1184. $Log$
  1185. Revision 1.34 2002-11-09 15:35:35 carl
  1186. * major alignment updates for objects/class tables
  1187. Revision 1.33 2002/10/20 15:33:36 peter
  1188. * having overloads is the same as overload directive for hiding of
  1189. parent methods. This is required becuase it can be possible that a
  1190. method will then hide a method in the parent that an overloaded
  1191. method requires. See webbug tw2185
  1192. Revision 1.32 2002/10/19 15:09:24 peter
  1193. + tobjectdef.members_need_inittable that is used to generate only the
  1194. inittable when it is really used. This saves a lot of useless calls
  1195. to fpc_finalize when destroying classes
  1196. Revision 1.31 2002/10/15 19:00:42 peter
  1197. * small tweak to use speedvalue before comparing strings
  1198. Revision 1.30 2002/10/06 16:40:25 florian
  1199. * interface wrapper name mangling improved
  1200. Revision 1.29 2002/10/05 12:43:25 carl
  1201. * fixes for Delphi 6 compilation
  1202. (warning : Some features do not work under Delphi)
  1203. Revision 1.28 2002/09/16 14:11:13 peter
  1204. * add argument to equal_paras() to support default values or not
  1205. Revision 1.27 2002/09/03 16:26:26 daniel
  1206. * Make Tprocdef.defs protected
  1207. Revision 1.26 2002/09/03 15:44:44 peter
  1208. * fixed private methods hiding public virtual methods
  1209. Revision 1.25 2002/08/11 14:32:27 peter
  1210. * renamed current_library to objectlibrary
  1211. Revision 1.24 2002/08/11 13:24:12 peter
  1212. * saving of asmsymbols in ppu supported
  1213. * asmsymbollist global is removed and moved into a new class
  1214. tasmlibrarydata that will hold the info of a .a file which
  1215. corresponds with a single module. Added librarydata to tmodule
  1216. to keep the library info stored for the module. In the future the
  1217. objectfiles will also be stored to the tasmlibrarydata class
  1218. * all getlabel/newasmsymbol and friends are moved to the new class
  1219. Revision 1.23 2002/08/09 07:33:01 florian
  1220. * a couple of interface related fixes
  1221. Revision 1.22 2002/07/20 11:57:55 florian
  1222. * types.pas renamed to defbase.pas because D6 contains a types
  1223. unit so this would conflicts if D6 programms are compiled
  1224. + Willamette/SSE2 instructions to assembler added
  1225. Revision 1.21 2002/07/01 18:46:23 peter
  1226. * internal linker
  1227. * reorganized aasm layer
  1228. Revision 1.20 2002/05/18 13:34:10 peter
  1229. * readded missing revisions
  1230. Revision 1.19 2002/05/16 19:46:39 carl
  1231. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1232. + try to fix temp allocation (still in ifdef)
  1233. + generic constructor calls
  1234. + start of tassembler / tmodulebase class cleanup
  1235. Revision 1.17 2002/05/12 16:53:08 peter
  1236. * moved entry and exitcode to ncgutil and cgobj
  1237. * foreach gets extra argument for passing local data to the
  1238. iterator function
  1239. * -CR checks also class typecasts at runtime by changing them
  1240. into as
  1241. * fixed compiler to cycle with the -CR option
  1242. * fixed stabs with elf writer, finally the global variables can
  1243. be watched
  1244. * removed a lot of routines from cga unit and replaced them by
  1245. calls to cgobj
  1246. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1247. u32bit then the other is typecasted also to u32bit without giving
  1248. a rangecheck warning/error.
  1249. * fixed pascal calling method with reversing also the high tree in
  1250. the parast, detected by tcalcst3 test
  1251. Revision 1.16 2002/04/20 21:32:24 carl
  1252. + generic FPC_CHECKPOINTER
  1253. + first parameter offset in stack now portable
  1254. * rename some constants
  1255. + move some cpu stuff to other units
  1256. - remove unused constents
  1257. * fix stacksize for some targets
  1258. * fix generic size problems which depend now on EXTEND_SIZE constant
  1259. Revision 1.15 2002/04/19 15:46:01 peter
  1260. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  1261. in most cases and not written to the ppu
  1262. * add mangeledname_prefix() routine to generate the prefix of
  1263. manglednames depending on the current procedure, object and module
  1264. * removed static procprefix since the mangledname is now build only
  1265. on demand from tprocdef.mangledname
  1266. Revision 1.14 2002/04/15 18:59:07 carl
  1267. + target_info.size_of_pointer -> pointer_Size
  1268. Revision 1.13 2002/02/11 18:51:35 peter
  1269. * fixed vmt generation for private procedures that were skipped after
  1270. my previous changes
  1271. }