symdefh.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl, Pierre Muller
  4. Interface for the definition types of the symtable
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {************************************************
  19. TDef
  20. ************************************************}
  21. tdef = object(tsymtableentry)
  22. deftype : tdeftype;
  23. typesym : ptypesym; { which type the definition was generated this def }
  24. has_inittable : boolean;
  25. { adress of init informations }
  26. inittable_label : pasmlabel;
  27. has_rtti : boolean;
  28. { address of rtti }
  29. rtti_label : pasmlabel;
  30. nextglobal,
  31. previousglobal : pdef;
  32. {$ifdef GDB}
  33. globalnb : word;
  34. is_def_stab_written : tdefstabstatus;
  35. {$endif GDB}
  36. constructor init;
  37. constructor load;
  38. destructor done;virtual;
  39. procedure deref;virtual;
  40. function typename:string;
  41. procedure write;virtual;
  42. function size:longint;virtual;
  43. function alignment:longint;virtual;
  44. function gettypename:string;virtual;
  45. function is_publishable : boolean;virtual;
  46. function is_in_current : boolean;
  47. procedure correct_owner_symtable; { registers enumdef inside objects or
  48. record directly in the owner symtable !! }
  49. { debug }
  50. {$ifdef GDB}
  51. function stabstring : pchar;virtual;
  52. procedure concatstabto(asmlist : paasmoutput);virtual;
  53. function NumberString:string;
  54. procedure set_globalnb;virtual;
  55. function allstabstring : pchar;
  56. {$endif GDB}
  57. { init. tables }
  58. function needs_inittable : boolean;virtual;
  59. procedure generate_inittable;
  60. function get_inittable_label : pasmlabel;
  61. { the default implemenation calls write_rtti_data }
  62. { if init and rtti data is different these procedures }
  63. { must be overloaded }
  64. procedure write_init_data;virtual;
  65. procedure write_child_init_data;virtual;
  66. { rtti }
  67. procedure write_rtti_name;
  68. function get_rtti_label : string;virtual;
  69. procedure generate_rtti;virtual;
  70. procedure write_rtti_data;virtual;
  71. procedure write_child_rtti_data;virtual;
  72. function is_intregable : boolean;
  73. function is_fpuregable : boolean;
  74. private
  75. savesize : longint;
  76. end;
  77. targconvtyp = (act_convertable,act_equal,act_exact);
  78. tvarspez = (vs_value,vs_const,vs_var,vs_out);
  79. pparaitem = ^tparaitem;
  80. tparaitem = object(tlinkedlist_item)
  81. paratype : ttype;
  82. paratyp : tvarspez;
  83. argconvtyp : targconvtyp;
  84. convertlevel : byte;
  85. register : tregister;
  86. defaultvalue : psym; { pconstsym }
  87. end;
  88. { this is only here to override the count method,
  89. which can't be used }
  90. pparalinkedlist = ^tparalinkedlist;
  91. tparalinkedlist = object(tlinkedlist)
  92. function count:longint;
  93. end;
  94. tfiletyp = (ft_text,ft_typed,ft_untyped);
  95. pfiledef = ^tfiledef;
  96. tfiledef = object(tdef)
  97. filetyp : tfiletyp;
  98. typedfiletype : ttype;
  99. constructor inittext;
  100. constructor inituntyped;
  101. constructor inittyped(const tt : ttype);
  102. constructor inittypeddef(p : pdef);
  103. constructor load;
  104. procedure write;virtual;
  105. procedure deref;virtual;
  106. function gettypename:string;virtual;
  107. procedure setsize;
  108. { debug }
  109. {$ifdef GDB}
  110. function stabstring : pchar;virtual;
  111. procedure concatstabto(asmlist : paasmoutput);virtual;
  112. {$endif GDB}
  113. end;
  114. pformaldef = ^tformaldef;
  115. tformaldef = object(tdef)
  116. constructor init;
  117. constructor load;
  118. procedure write;virtual;
  119. function gettypename:string;virtual;
  120. {$ifdef GDB}
  121. function stabstring : pchar;virtual;
  122. procedure concatstabto(asmlist : paasmoutput);virtual;
  123. {$endif GDB}
  124. end;
  125. pforwarddef = ^tforwarddef;
  126. tforwarddef = object(tdef)
  127. tosymname : string;
  128. forwardpos : tfileposinfo;
  129. constructor init(const s:string;const pos : tfileposinfo);
  130. function gettypename:string;virtual;
  131. end;
  132. perrordef = ^terrordef;
  133. terrordef = object(tdef)
  134. constructor init;
  135. function gettypename:string;virtual;
  136. { debug }
  137. {$ifdef GDB}
  138. function stabstring : pchar;virtual;
  139. {$endif GDB}
  140. end;
  141. { tpointerdef and tclassrefdef should get a common
  142. base class, but I derived tclassrefdef from tpointerdef
  143. to avoid problems with bugs (FK)
  144. }
  145. ppointerdef = ^tpointerdef;
  146. tpointerdef = object(tdef)
  147. pointertype : ttype;
  148. is_far : boolean;
  149. constructor init(const tt : ttype);
  150. constructor initfar(const tt : ttype);
  151. constructor initdef(p : pdef);
  152. constructor initfardef(p : pdef);
  153. constructor load;
  154. destructor done;virtual;
  155. procedure write;virtual;
  156. procedure deref;virtual;
  157. function gettypename:string;virtual;
  158. { debug }
  159. {$ifdef GDB}
  160. function stabstring : pchar;virtual;
  161. procedure concatstabto(asmlist : paasmoutput);virtual;
  162. {$endif GDB}
  163. {private}
  164. public
  165. { I don't know the use of this FK }
  166. pointertypeis_forwarddef: boolean;
  167. end;
  168. pprocdef = ^tprocdef;
  169. pimplementedinterfaces = ^timplementedinterfaces;
  170. pobjectdef = ^tobjectdef;
  171. tobjectdef = object(tdef)
  172. childof : pobjectdef;
  173. objname : pstring;
  174. symtable : psymtable;
  175. objectoptions : tobjectoptions;
  176. { to be able to have a variable vmt position }
  177. { and no vmt field for objects without virtuals }
  178. vmt_offset : longint;
  179. {$ifdef GDB}
  180. classglobalnb,
  181. classptrglobalnb : word;
  182. writing_stabs : boolean;
  183. {$endif GDB}
  184. objecttype : tobjectdeftype;
  185. isiidguidvalid: boolean;
  186. iidguid: TGUID;
  187. iidstr: pstring;
  188. lastvtableindex: longint;
  189. { store implemented interfaces defs and name mappings }
  190. implementedinterfaces: pimplementedinterfaces;
  191. constructor init(odt : tobjectdeftype; const n : string;c : pobjectdef);
  192. constructor load;
  193. destructor done;virtual;
  194. procedure write;virtual;
  195. procedure deref;virtual;
  196. function size : longint;virtual;
  197. function alignment:longint;virtual;
  198. function vmtmethodoffset(index:longint):longint;
  199. function is_publishable : boolean;virtual;
  200. function vmt_mangledname : string;
  201. function rtti_name : string;
  202. procedure check_forwards;
  203. function is_related(d : pobjectdef) : boolean;
  204. function next_free_name_index : longint;
  205. procedure insertvmt;
  206. procedure set_parent(c : pobjectdef);
  207. function searchdestructor : pprocdef;
  208. { debug }
  209. {$ifdef GDB}
  210. function stabstring : pchar;virtual;
  211. procedure set_globalnb;virtual;
  212. function classnumberstring : string;
  213. function classptrnumberstring : string;
  214. procedure concatstabto(asmlist : paasmoutput);virtual;
  215. {$endif GDB}
  216. { init/final }
  217. function needs_inittable : boolean;virtual;
  218. procedure write_init_data;virtual;
  219. procedure write_child_init_data;virtual;
  220. { rtti }
  221. function get_rtti_label : string;virtual;
  222. procedure generate_rtti;virtual;
  223. procedure write_rtti_data;virtual;
  224. procedure write_child_rtti_data;virtual;
  225. function generate_field_table : pasmlabel;
  226. end;
  227. timplementedinterfaces = object
  228. constructor init;
  229. destructor done; virtual;
  230. function count: longint;
  231. function interfaces(intfindex: longint): pobjectdef;
  232. function ioffsets(intfindex: longint): plongint;
  233. function searchintf(def: pdef): longint;
  234. procedure addintf(def: pdef);
  235. procedure deref;
  236. procedure addintfref(def: pdef);
  237. procedure clearmappings;
  238. procedure addmappings(intfindex: longint; const name, newname: string);
  239. function getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  240. procedure clearimplprocs;
  241. procedure addimplproc(intfindex: longint; procdef: pprocdef);
  242. function implproccount(intfindex: longint): longint;
  243. function implprocs(intfindex: longint; procindex: longint): pprocdef;
  244. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  245. private
  246. finterfaces: tindexarray;
  247. procedure checkindex(intfindex: longint);
  248. end;
  249. pclassrefdef = ^tclassrefdef;
  250. tclassrefdef = object(tpointerdef)
  251. constructor init(def : pdef);
  252. constructor load;
  253. procedure write;virtual;
  254. function gettypename:string;virtual;
  255. { debug }
  256. {$ifdef GDB}
  257. function stabstring : pchar;virtual;
  258. procedure concatstabto(asmlist : paasmoutput);virtual;
  259. {$endif GDB}
  260. end;
  261. parraydef = ^tarraydef;
  262. tarraydef = object(tdef)
  263. private
  264. rangenr : longint;
  265. public
  266. lowrange,
  267. highrange : longint;
  268. elementtype,
  269. rangetype : ttype;
  270. IsDynamicArray,
  271. IsVariant,
  272. IsConstructor,
  273. IsArrayOfConst : boolean;
  274. function gettypename:string;virtual;
  275. function elesize : longint;
  276. constructor init(l,h : longint;rd : pdef);
  277. constructor load;
  278. procedure write;virtual;
  279. {$ifdef GDB}
  280. function stabstring : pchar;virtual;
  281. procedure concatstabto(asmlist : paasmoutput);virtual;
  282. {$endif GDB}
  283. procedure deref;virtual;
  284. function size : longint;virtual;
  285. function alignment : longint;virtual;
  286. { generates the ranges needed by the asm instruction BOUND (i386)
  287. or CMP2 (Motorola) }
  288. procedure genrangecheck;
  289. { returns the label of the range check string }
  290. function getrangecheckstring : string;
  291. function needs_inittable : boolean;virtual;
  292. procedure write_rtti_data;virtual;
  293. procedure write_child_rtti_data;virtual;
  294. end;
  295. precorddef = ^trecorddef;
  296. trecorddef = object(tdef)
  297. symtable : psymtable;
  298. constructor init(p : psymtable);
  299. constructor load;
  300. destructor done;virtual;
  301. procedure write;virtual;
  302. procedure deref;virtual;
  303. function size:longint;virtual;
  304. function alignment : longint;virtual;
  305. function gettypename:string;virtual;
  306. { debug }
  307. {$ifdef GDB}
  308. function stabstring : pchar;virtual;
  309. procedure concatstabto(asmlist : paasmoutput);virtual;
  310. {$endif GDB}
  311. { init/final }
  312. procedure write_init_data;virtual;
  313. procedure write_child_init_data;virtual;
  314. function needs_inittable : boolean;virtual;
  315. { rtti }
  316. procedure write_rtti_data;virtual;
  317. procedure write_child_rtti_data;virtual;
  318. end;
  319. porddef = ^torddef;
  320. torddef = object(tdef)
  321. private
  322. rangenr : longint;
  323. public
  324. low,high : longint;
  325. typ : tbasetype;
  326. constructor init(t : tbasetype;v,b : longint);
  327. constructor load;
  328. procedure write;virtual;
  329. function is_publishable : boolean;virtual;
  330. function gettypename:string;virtual;
  331. procedure setsize;
  332. { generates the ranges needed by the asm instruction BOUND }
  333. { or CMP2 (Motorola) }
  334. procedure genrangecheck;
  335. function getrangecheckstring : string;
  336. { debug }
  337. {$ifdef GDB}
  338. function stabstring : pchar;virtual;
  339. {$endif GDB}
  340. { rtti }
  341. procedure write_rtti_data;virtual;
  342. end;
  343. pfloatdef = ^tfloatdef;
  344. tfloatdef = object(tdef)
  345. typ : tfloattype;
  346. constructor init(t : tfloattype);
  347. constructor load;
  348. procedure write;virtual;
  349. function gettypename:string;virtual;
  350. function is_publishable : boolean;virtual;
  351. procedure setsize;
  352. { debug }
  353. {$ifdef GDB}
  354. function stabstring : pchar;virtual;
  355. {$endif GDB}
  356. { rtti }
  357. procedure write_rtti_data;virtual;
  358. end;
  359. pabstractprocdef = ^tabstractprocdef;
  360. tabstractprocdef = object(tdef)
  361. { saves a definition to the return type }
  362. rettype : ttype;
  363. proctypeoption : tproctypeoption;
  364. proccalloptions : tproccalloptions;
  365. procoptions : tprocoptions;
  366. para : pparalinkedlist;
  367. maxparacount,
  368. minparacount : longint;
  369. symtablelevel : byte;
  370. fpu_used : byte; { how many stack fpu must be empty }
  371. constructor init;
  372. constructor load;
  373. destructor done;virtual;
  374. procedure write;virtual;
  375. procedure deref;virtual;
  376. procedure concatpara(tt:ttype;vsp : tvarspez;defval:psym);
  377. function para_size(alignsize:longint) : longint;
  378. function demangled_paras : string;
  379. function proccalloption2str : string;
  380. procedure test_if_fpu_result;
  381. { debug }
  382. {$ifdef GDB}
  383. function stabstring : pchar;virtual;
  384. procedure concatstabto(asmlist : paasmoutput);virtual;
  385. {$endif GDB}
  386. end;
  387. pprocvardef = ^tprocvardef;
  388. tprocvardef = object(tabstractprocdef)
  389. constructor init;
  390. constructor load;
  391. procedure write;virtual;
  392. function size : longint;virtual;
  393. function gettypename:string;virtual;
  394. function is_publishable : boolean;virtual;
  395. { debug }
  396. {$ifdef GDB}
  397. function stabstring : pchar;virtual;
  398. procedure concatstabto(asmlist : paasmoutput); virtual;
  399. {$endif GDB}
  400. { rtti }
  401. procedure write_child_rtti_data;virtual;
  402. procedure write_rtti_data;virtual;
  403. end;
  404. tmessageinf = record
  405. case integer of
  406. 0 : (str : pchar);
  407. 1 : (i : longint);
  408. end;
  409. tprocdef = object(tabstractprocdef)
  410. private
  411. _mangledname : pstring;
  412. public
  413. extnumber : longint;
  414. messageinf : tmessageinf;
  415. nextoverloaded : pprocdef;
  416. { where is this function defined, needed here because there
  417. is only one symbol for all overloaded functions }
  418. fileinfo : tfileposinfo;
  419. { pointer to the local symbol table }
  420. localst : psymtable;
  421. { pointer to the parameter symbol table }
  422. parast : psymtable;
  423. { symbol owning this definition }
  424. procsym : pprocsym;
  425. { browser info }
  426. lastref,
  427. defref,
  428. crossref,
  429. lastwritten : pref;
  430. refcount : longint;
  431. _class : pobjectdef;
  432. { it's a tree, but this not easy to handle }
  433. { used for inlined procs }
  434. code : pointer;
  435. { info about register variables (JM) }
  436. regvarinfo: pointer;
  437. { true, if the procedure is only declared }
  438. { (forward procedure) }
  439. forwarddef,
  440. { true if the procedure is declared in the interface }
  441. interfacedef : boolean;
  442. { true if the procedure has a forward declaration }
  443. hasforward : boolean;
  444. { check the problems of manglednames }
  445. count : boolean;
  446. is_used : boolean;
  447. { small set which contains the modified registers }
  448. {$ifdef newcg}
  449. usedregisters : tregisterset;
  450. {$else newcg}
  451. usedregisters : longint;
  452. {$endif newcg}
  453. constructor init;
  454. constructor load;
  455. destructor done;virtual;
  456. procedure write;virtual;
  457. procedure deref;virtual;
  458. function haspara:boolean;
  459. function mangledname : string;
  460. procedure setmangledname(const s : string);
  461. procedure load_references;
  462. function write_references : boolean;
  463. {$ifdef dummy}
  464. function procname: string;
  465. {$endif dummy}
  466. function cplusplusmangledname : string;
  467. { debug }
  468. {$ifdef GDB}
  469. function stabstring : pchar;virtual;
  470. procedure concatstabto(asmlist : paasmoutput);virtual;
  471. {$endif GDB}
  472. { browser }
  473. {$ifdef BrowserLog}
  474. procedure add_to_browserlog;
  475. {$endif BrowserLog}
  476. end;
  477. pstringdef = ^tstringdef;
  478. tstringdef = object(tdef)
  479. string_typ : tstringtype;
  480. len : longint;
  481. constructor shortinit(l : byte);
  482. constructor shortload;
  483. constructor longinit(l : longint);
  484. constructor longload;
  485. constructor ansiinit(l : longint);
  486. constructor ansiload;
  487. constructor wideinit(l : longint);
  488. constructor wideload;
  489. function stringtypname:string;
  490. function size : longint;virtual;
  491. procedure write;virtual;
  492. function gettypename:string;virtual;
  493. function is_publishable : boolean;virtual;
  494. { debug }
  495. {$ifdef GDB}
  496. function stabstring : pchar;virtual;
  497. procedure concatstabto(asmlist : paasmoutput);virtual;
  498. {$endif GDB}
  499. { init/final }
  500. function needs_inittable : boolean;virtual;
  501. { rtti }
  502. procedure write_rtti_data;virtual;
  503. end;
  504. penumdef = ^tenumdef;
  505. tenumdef = object(tdef)
  506. rangenr,
  507. minval,
  508. maxval : longint;
  509. has_jumps : boolean;
  510. firstenum : penumsym;
  511. basedef : penumdef;
  512. constructor init;
  513. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  514. constructor load;
  515. destructor done;virtual;
  516. procedure write;virtual;
  517. procedure deref;virtual;
  518. function gettypename:string;virtual;
  519. function is_publishable : boolean;virtual;
  520. procedure calcsavesize;
  521. procedure setmax(_max:longint);
  522. procedure setmin(_min:longint);
  523. function min:longint;
  524. function max:longint;
  525. function getrangecheckstring:string;
  526. procedure genrangecheck;
  527. { debug }
  528. {$ifdef GDB}
  529. function stabstring : pchar;virtual;
  530. {$endif GDB}
  531. { rtti }
  532. procedure write_child_rtti_data;virtual;
  533. procedure write_rtti_data;virtual;
  534. end;
  535. psetdef = ^tsetdef;
  536. tsetdef = object(tdef)
  537. elementtype : ttype;
  538. settype : tsettype;
  539. constructor init(s : pdef;high : longint);
  540. constructor load;
  541. destructor done;virtual;
  542. procedure write;virtual;
  543. procedure deref;virtual;
  544. function gettypename:string;virtual;
  545. function is_publishable : boolean;virtual;
  546. { debug }
  547. {$ifdef GDB}
  548. function stabstring : pchar;virtual;
  549. procedure concatstabto(asmlist : paasmoutput);virtual;
  550. {$endif GDB}
  551. { rtti }
  552. procedure write_rtti_data;virtual;
  553. procedure write_child_rtti_data;virtual;
  554. end;
  555. {
  556. $Log$
  557. Revision 1.15 2000-11-04 14:25:22 florian
  558. + merged Attila's changes for interfaces, not tested yet
  559. Revision 1.14 2000/10/31 22:02:52 peter
  560. * symtable splitted, no real code changes
  561. Revision 1.13 2000/10/21 18:16:12 florian
  562. * a lot of changes:
  563. - basic dyn. array support
  564. - basic C++ support
  565. - some work for interfaces done
  566. ....
  567. Revision 1.12 2000/10/15 07:47:52 peter
  568. * unit names and procedure names are stored mixed case
  569. Revision 1.11 2000/10/14 10:14:53 peter
  570. * moehrendorf oct 2000 rewrite
  571. Revision 1.10 2000/09/24 15:06:29 peter
  572. * use defines.inc
  573. Revision 1.9 2000/09/19 23:08:03 pierre
  574. * fixes for local class debuggging problem (merged)
  575. Revision 1.8 2000/08/21 11:27:44 pierre
  576. * fix the stabs problems
  577. Revision 1.7 2000/08/06 19:39:28 peter
  578. * default parameters working !
  579. Revision 1.6 2000/08/06 14:17:15 peter
  580. * overload fixes (merged)
  581. Revision 1.5 2000/08/03 13:17:26 jonas
  582. + allow regvars to be used inside inlined procs, which required the
  583. following changes:
  584. + load regvars in genentrycode/free them in genexitcode (cgai386)
  585. * moved all regvar related code to new regvars unit
  586. + added pregvarinfo type to hcodegen
  587. + added regvarinfo field to tprocinfo (symdef/symdefh)
  588. * deallocate the regvars of the caller in secondprocinline before
  589. inlining the called procedure and reallocate them afterwards
  590. Revision 1.4 2000/08/02 19:49:59 peter
  591. * first things for default parameters
  592. Revision 1.3 2000/07/13 12:08:27 michael
  593. + patched to 1.1.0 with former 1.09patch from peter
  594. Revision 1.2 2000/07/13 11:32:49 michael
  595. + removed logs
  596. }