nobj.pas 58 KB

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