symdefh.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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 : boolean;
  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;
  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);
  79. pparaitem = ^tparaitem;
  80. tparaitem = object(tlinkedlist_item)
  81. paratype : ttype;
  82. paratyp : tvarspez;
  83. argconvtyp : targconvtyp;
  84. convertlevel : byte;
  85. register : tregister;
  86. end;
  87. tfiletyp = (ft_text,ft_typed,ft_untyped);
  88. pfiledef = ^tfiledef;
  89. tfiledef = object(tdef)
  90. filetyp : tfiletyp;
  91. typedfiletype : ttype;
  92. constructor inittext;
  93. constructor inituntyped;
  94. constructor inittyped(const tt : ttype);
  95. constructor inittypeddef(p : pdef);
  96. constructor load;
  97. procedure write;virtual;
  98. procedure deref;virtual;
  99. function gettypename:string;virtual;
  100. procedure setsize;
  101. { debug }
  102. {$ifdef GDB}
  103. function stabstring : pchar;virtual;
  104. procedure concatstabto(asmlist : paasmoutput);virtual;
  105. {$endif GDB}
  106. end;
  107. pformaldef = ^tformaldef;
  108. tformaldef = object(tdef)
  109. constructor init;
  110. constructor load;
  111. procedure write;virtual;
  112. function gettypename:string;virtual;
  113. {$ifdef GDB}
  114. function stabstring : pchar;virtual;
  115. procedure concatstabto(asmlist : paasmoutput);virtual;
  116. {$endif GDB}
  117. end;
  118. pforwarddef = ^tforwarddef;
  119. tforwarddef = object(tdef)
  120. tosymname : string;
  121. forwardpos : tfileposinfo;
  122. constructor init(const s:string;const pos : tfileposinfo);
  123. function gettypename:string;virtual;
  124. end;
  125. perrordef = ^terrordef;
  126. terrordef = object(tdef)
  127. constructor init;
  128. function gettypename:string;virtual;
  129. { debug }
  130. {$ifdef GDB}
  131. function stabstring : pchar;virtual;
  132. {$endif GDB}
  133. end;
  134. { tpointerdef and tclassrefdef should get a common
  135. base class, but I derived tclassrefdef from tpointerdef
  136. to avoid problems with bugs (FK)
  137. }
  138. ppointerdef = ^tpointerdef;
  139. tpointerdef = object(tdef)
  140. pointertype : ttype;
  141. is_far : boolean;
  142. constructor init(const tt : ttype);
  143. constructor initfar(const tt : ttype);
  144. constructor initdef(p : pdef);
  145. constructor initfardef(p : pdef);
  146. constructor load;
  147. destructor done;virtual;
  148. procedure write;virtual;
  149. procedure deref;virtual;
  150. function gettypename:string;virtual;
  151. { debug }
  152. {$ifdef GDB}
  153. function stabstring : pchar;virtual;
  154. procedure concatstabto(asmlist : paasmoutput);virtual;
  155. {$endif GDB}
  156. end;
  157. pprocdef = ^tprocdef;
  158. pobjectdef = ^tobjectdef;
  159. tobjectdef = object(tdef)
  160. childof : pobjectdef;
  161. objname : pstring;
  162. symtable : psymtable;
  163. objectoptions : tobjectoptions;
  164. { to be able to have a variable vmt position }
  165. { and no vmt field for objects without virtuals }
  166. vmt_offset : longint;
  167. constructor init(const n : string;c : pobjectdef);
  168. constructor load;
  169. destructor done;virtual;
  170. procedure write;virtual;
  171. procedure deref;virtual;
  172. function size : longint;virtual;
  173. function alignment:longint;virtual;
  174. function vmtmethodoffset(index:longint):longint;
  175. function is_publishable : boolean;virtual;
  176. function vmt_mangledname : string;
  177. function rtti_name : string;
  178. procedure check_forwards;
  179. function is_related(d : pobjectdef) : boolean;
  180. function is_class : boolean;
  181. function next_free_name_index : longint;
  182. procedure insertvmt;
  183. procedure set_parent(c : pobjectdef);
  184. function searchdestructor : pprocdef;
  185. { debug }
  186. {$ifdef GDB}
  187. function stabstring : pchar;virtual;
  188. {$endif GDB}
  189. { init/final }
  190. function needs_inittable : boolean;virtual;
  191. procedure write_init_data;virtual;
  192. procedure write_child_init_data;virtual;
  193. { rtti }
  194. function get_rtti_label : string;virtual;
  195. procedure generate_rtti;virtual;
  196. procedure write_rtti_data;virtual;
  197. procedure write_child_rtti_data;virtual;
  198. function generate_field_table : pasmlabel;
  199. end;
  200. pclassrefdef = ^tclassrefdef;
  201. tclassrefdef = object(tpointerdef)
  202. constructor init(def : pdef);
  203. constructor load;
  204. procedure write;virtual;
  205. function gettypename:string;virtual;
  206. { debug }
  207. {$ifdef GDB}
  208. function stabstring : pchar;virtual;
  209. procedure concatstabto(asmlist : paasmoutput);virtual;
  210. {$endif GDB}
  211. end;
  212. parraydef = ^tarraydef;
  213. tarraydef = object(tdef)
  214. private
  215. rangenr : longint;
  216. public
  217. lowrange,
  218. highrange : longint;
  219. elementtype,
  220. rangetype : ttype;
  221. IsVariant,
  222. IsConstructor,
  223. IsArrayOfConst : boolean;
  224. function gettypename:string;virtual;
  225. function elesize : longint;
  226. constructor init(l,h : longint;rd : pdef);
  227. constructor load;
  228. procedure write;virtual;
  229. {$ifdef GDB}
  230. function stabstring : pchar;virtual;
  231. procedure concatstabto(asmlist : paasmoutput);virtual;
  232. {$endif GDB}
  233. procedure deref;virtual;
  234. function size : longint;virtual;
  235. function alignment : longint;virtual;
  236. { generates the ranges needed by the asm instruction BOUND (i386)
  237. or CMP2 (Motorola) }
  238. procedure genrangecheck;
  239. { returns the label of the range check string }
  240. function getrangecheckstring : string;
  241. function needs_inittable : boolean;virtual;
  242. procedure write_rtti_data;virtual;
  243. procedure write_child_rtti_data;virtual;
  244. end;
  245. precorddef = ^trecorddef;
  246. trecorddef = object(tdef)
  247. symtable : psymtable;
  248. constructor init(p : psymtable);
  249. constructor load;
  250. destructor done;virtual;
  251. procedure write;virtual;
  252. procedure deref;virtual;
  253. function size:longint;virtual;
  254. function alignment : longint;virtual;
  255. function gettypename:string;virtual;
  256. { debug }
  257. {$ifdef GDB}
  258. function stabstring : pchar;virtual;
  259. procedure concatstabto(asmlist : paasmoutput);virtual;
  260. {$endif GDB}
  261. { init/final }
  262. procedure write_init_data;virtual;
  263. procedure write_child_init_data;virtual;
  264. function needs_inittable : boolean;virtual;
  265. { rtti }
  266. procedure write_rtti_data;virtual;
  267. procedure write_child_rtti_data;virtual;
  268. end;
  269. porddef = ^torddef;
  270. torddef = object(tdef)
  271. private
  272. rangenr : longint;
  273. public
  274. low,high : longint;
  275. typ : tbasetype;
  276. constructor init(t : tbasetype;v,b : longint);
  277. constructor load;
  278. procedure write;virtual;
  279. function is_publishable : boolean;virtual;
  280. function gettypename:string;virtual;
  281. procedure setsize;
  282. { generates the ranges needed by the asm instruction BOUND }
  283. { or CMP2 (Motorola) }
  284. procedure genrangecheck;
  285. function getrangecheckstring : string;
  286. { debug }
  287. {$ifdef GDB}
  288. function stabstring : pchar;virtual;
  289. {$endif GDB}
  290. { rtti }
  291. procedure write_rtti_data;virtual;
  292. end;
  293. pfloatdef = ^tfloatdef;
  294. tfloatdef = object(tdef)
  295. typ : tfloattype;
  296. constructor init(t : tfloattype);
  297. constructor load;
  298. procedure write;virtual;
  299. function gettypename:string;virtual;
  300. function is_publishable : boolean;virtual;
  301. procedure setsize;
  302. { debug }
  303. {$ifdef GDB}
  304. function stabstring : pchar;virtual;
  305. {$endif GDB}
  306. { rtti }
  307. procedure write_rtti_data;virtual;
  308. end;
  309. pabstractprocdef = ^tabstractprocdef;
  310. tabstractprocdef = object(tdef)
  311. { saves a definition to the return type }
  312. rettype : ttype;
  313. proctypeoption : tproctypeoption;
  314. proccalloptions : tproccalloptions;
  315. procoptions : tprocoptions;
  316. para : plinkedlist;
  317. symtablelevel : byte;
  318. fpu_used : byte; { how many stack fpu must be empty }
  319. constructor init;
  320. constructor load;
  321. destructor done;virtual;
  322. procedure write;virtual;
  323. procedure deref;virtual;
  324. procedure concatpara(tt:ttype;vsp : tvarspez);
  325. function para_size(alignsize:longint) : longint;
  326. function demangled_paras : string;
  327. function proccalloption2str : string;
  328. procedure test_if_fpu_result;
  329. { debug }
  330. {$ifdef GDB}
  331. function stabstring : pchar;virtual;
  332. procedure concatstabto(asmlist : paasmoutput);virtual;
  333. {$endif GDB}
  334. end;
  335. pprocvardef = ^tprocvardef;
  336. tprocvardef = object(tabstractprocdef)
  337. constructor init;
  338. constructor load;
  339. procedure write;virtual;
  340. function size : longint;virtual;
  341. function gettypename:string;virtual;
  342. function is_publishable : boolean;virtual;
  343. { debug }
  344. {$ifdef GDB}
  345. function stabstring : pchar;virtual;
  346. procedure concatstabto(asmlist : paasmoutput); virtual;
  347. {$endif GDB}
  348. { rtti }
  349. procedure write_child_rtti_data;virtual;
  350. procedure write_rtti_data;virtual;
  351. end;
  352. tmessageinf = record
  353. case integer of
  354. 0 : (str : pchar);
  355. 1 : (i : longint);
  356. end;
  357. tprocdef = object(tabstractprocdef)
  358. private
  359. _mangledname : pchar;
  360. public
  361. extnumber : longint;
  362. messageinf : tmessageinf;
  363. nextoverloaded : pprocdef;
  364. { where is this function defined, needed here because there
  365. is only one symbol for all overloaded functions }
  366. fileinfo : tfileposinfo;
  367. { pointer to the local symbol table }
  368. localst : psymtable;
  369. { pointer to the parameter symbol table }
  370. parast : psymtable;
  371. { symbol owning this definition }
  372. procsym : pprocsym;
  373. { browser info }
  374. lastref,
  375. defref,
  376. crossref,
  377. lastwritten : pref;
  378. refcount : longint;
  379. _class : pobjectdef;
  380. { it's a tree, but this not easy to handle }
  381. { used for inlined procs }
  382. code : pointer;
  383. { true, if the procedure is only declared }
  384. { (forward procedure) }
  385. forwarddef,
  386. { true if the procedure is declared in the interface }
  387. interfacedef : boolean;
  388. { check the problems of manglednames }
  389. count : boolean;
  390. is_used : boolean;
  391. { small set which contains the modified registers }
  392. {$ifdef newcg}
  393. usedregisters : tregisterset;
  394. {$else newcg}
  395. usedregisters : longint;
  396. {$endif newcg}
  397. constructor init;
  398. constructor load;
  399. destructor done;virtual;
  400. procedure write;virtual;
  401. procedure deref;virtual;
  402. function haspara:boolean;
  403. function mangledname : string;
  404. procedure setmangledname(const s : string);
  405. procedure load_references;
  406. function write_references : boolean;
  407. function procname: string;
  408. { debug }
  409. {$ifdef GDB}
  410. function cplusplusmangledname : string;
  411. function stabstring : pchar;virtual;
  412. procedure concatstabto(asmlist : paasmoutput);virtual;
  413. {$endif GDB}
  414. { browser }
  415. {$ifdef BrowserLog}
  416. procedure add_to_browserlog;
  417. {$endif BrowserLog}
  418. end;
  419. pstringdef = ^tstringdef;
  420. tstringdef = object(tdef)
  421. string_typ : tstringtype;
  422. len : longint;
  423. constructor shortinit(l : byte);
  424. constructor shortload;
  425. constructor longinit(l : longint);
  426. constructor longload;
  427. constructor ansiinit(l : longint);
  428. constructor ansiload;
  429. constructor wideinit(l : longint);
  430. constructor wideload;
  431. function stringtypname:string;
  432. function size : longint;virtual;
  433. procedure write;virtual;
  434. function gettypename:string;virtual;
  435. function is_publishable : boolean;virtual;
  436. { debug }
  437. {$ifdef GDB}
  438. function stabstring : pchar;virtual;
  439. procedure concatstabto(asmlist : paasmoutput);virtual;
  440. {$endif GDB}
  441. { init/final }
  442. function needs_inittable : boolean;virtual;
  443. { rtti }
  444. procedure write_rtti_data;virtual;
  445. end;
  446. penumdef = ^tenumdef;
  447. tenumdef = object(tdef)
  448. rangenr,
  449. minval,
  450. maxval : longint;
  451. has_jumps : boolean;
  452. firstenum : penumsym;
  453. basedef : penumdef;
  454. constructor init;
  455. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  456. constructor load;
  457. destructor done;virtual;
  458. procedure write;virtual;
  459. procedure deref;virtual;
  460. function gettypename:string;virtual;
  461. function is_publishable : boolean;virtual;
  462. procedure calcsavesize;
  463. procedure setmax(_max:longint);
  464. procedure setmin(_min:longint);
  465. function min:longint;
  466. function max:longint;
  467. function getrangecheckstring:string;
  468. procedure genrangecheck;
  469. { debug }
  470. {$ifdef GDB}
  471. function stabstring : pchar;virtual;
  472. {$endif GDB}
  473. { rtti }
  474. procedure write_child_rtti_data;virtual;
  475. procedure write_rtti_data;virtual;
  476. end;
  477. psetdef = ^tsetdef;
  478. tsetdef = object(tdef)
  479. elementtype : ttype;
  480. settype : tsettype;
  481. constructor init(s : pdef;high : longint);
  482. constructor load;
  483. destructor done;virtual;
  484. procedure write;virtual;
  485. procedure deref;virtual;
  486. function gettypename:string;virtual;
  487. function is_publishable : boolean;virtual;
  488. { debug }
  489. {$ifdef GDB}
  490. function stabstring : pchar;virtual;
  491. procedure concatstabto(asmlist : paasmoutput);virtual;
  492. {$endif GDB}
  493. { rtti }
  494. procedure write_rtti_data;virtual;
  495. procedure write_child_rtti_data;virtual;
  496. end;
  497. {
  498. $Log$
  499. Revision 1.54 2000-06-02 18:48:48 florian
  500. + fieldtable support for classes
  501. Revision 1.53 2000/02/09 13:23:04 peter
  502. * log truncated
  503. Revision 1.52 2000/02/04 20:00:22 florian
  504. * an exception in a construcor calls now the destructor (this applies only
  505. to classes)
  506. Revision 1.51 2000/01/26 12:02:30 peter
  507. * abstractprocdef.para_size needs alignment parameter
  508. * secondcallparan gets para_alignment size instead of dword_align
  509. Revision 1.50 2000/01/07 01:14:40 peter
  510. * updated copyright to 2000
  511. Revision 1.49 2000/01/03 19:26:04 peter
  512. * fixed resolving of ttypesym which are reference from object/record
  513. fields.
  514. Revision 1.48 1999/11/30 10:40:55 peter
  515. + ttype, tsymlist
  516. Revision 1.47 1999/11/17 17:05:04 pierre
  517. * Notes/hints changes
  518. Revision 1.46 1999/11/09 23:35:50 pierre
  519. + better reference pos for forward defs
  520. Revision 1.45 1999/11/06 14:34:27 peter
  521. * truncated log to 20 revs
  522. Revision 1.44 1999/10/26 12:30:45 peter
  523. * const parameter is now checked
  524. * better and generic check if a node can be used for assigning
  525. * export fixes
  526. * procvar equal works now (it never had worked at least from 0.99.8)
  527. * defcoll changed to linkedlist with pparaitem so it can easily be
  528. walked both directions
  529. Revision 1.43 1999/10/01 10:05:44 peter
  530. + procedure directive support in const declarations, fixes bug 232
  531. Revision 1.42 1999/10/01 08:02:48 peter
  532. * forward type declaration rewritten
  533. Revision 1.41 1999/08/10 12:34:49 pierre
  534. + procsym field in tprocdef to allow correct gdb info generation
  535. Revision 1.40 1999/08/09 22:19:57 peter
  536. * classes vmt changed to only positive addresses
  537. * sharedlib creation is working
  538. Revision 1.39 1999/08/07 14:21:02 florian
  539. * some small problems fixed
  540. Revision 1.38 1999/08/05 16:53:15 peter
  541. * V_Fatal=1, all other V_ are also increased
  542. * Check for local procedure when assigning procvar
  543. * fixed comment parsing because directives
  544. * oldtp mode directives better supported
  545. * added some messages to errore.msg
  546. Revision 1.37 1999/08/03 22:03:16 peter
  547. * moved bitmask constants to sets
  548. * some other type/const renamings
  549. Revision 1.36 1999/08/02 21:29:04 florian
  550. * the main branch psub.pas is now used for
  551. newcg compiler
  552. Revision 1.35 1999/07/27 23:42:20 peter
  553. * indirect type referencing is now allowed
  554. Revision 1.34 1999/07/23 16:05:30 peter
  555. * alignment is now saved in the symtable
  556. * C alignment added for records
  557. * PPU version increased to solve .12 <-> .13 probs
  558. }