symdefh.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. pobjectdef = ^tobjectdef;
  158. tobjectdef = object(tdef)
  159. childof : pobjectdef;
  160. objname : pstring;
  161. symtable : psymtable;
  162. objectoptions : tobjectoptions;
  163. { to be able to have a variable vmt position }
  164. { and no vmt field for objects without virtuals }
  165. vmt_offset : longint;
  166. constructor init(const n : string;c : pobjectdef);
  167. constructor load;
  168. destructor done;virtual;
  169. procedure write;virtual;
  170. procedure deref;virtual;
  171. function size : longint;virtual;
  172. function alignment:longint;virtual;
  173. function vmtmethodoffset(index:longint):longint;
  174. function is_publishable : boolean;virtual;
  175. function vmt_mangledname : string;
  176. function rtti_name : string;
  177. procedure check_forwards;
  178. function is_related(d : pobjectdef) : boolean;
  179. function is_class : boolean;
  180. function next_free_name_index : longint;
  181. procedure insertvmt;
  182. procedure set_parent(c : pobjectdef);
  183. { debug }
  184. {$ifdef GDB}
  185. function stabstring : pchar;virtual;
  186. {$endif GDB}
  187. { init/final }
  188. function needs_inittable : boolean;virtual;
  189. procedure write_init_data;virtual;
  190. procedure write_child_init_data;virtual;
  191. { rtti }
  192. function get_rtti_label : string;virtual;
  193. procedure generate_rtti;virtual;
  194. procedure write_rtti_data;virtual;
  195. procedure write_child_rtti_data;virtual;
  196. end;
  197. pclassrefdef = ^tclassrefdef;
  198. tclassrefdef = object(tpointerdef)
  199. constructor init(def : pdef);
  200. constructor load;
  201. procedure write;virtual;
  202. function gettypename:string;virtual;
  203. { debug }
  204. {$ifdef GDB}
  205. function stabstring : pchar;virtual;
  206. procedure concatstabto(asmlist : paasmoutput);virtual;
  207. {$endif GDB}
  208. end;
  209. parraydef = ^tarraydef;
  210. tarraydef = object(tdef)
  211. private
  212. rangenr : longint;
  213. public
  214. lowrange,
  215. highrange : longint;
  216. elementtype,
  217. rangetype : ttype;
  218. IsVariant,
  219. IsConstructor,
  220. IsArrayOfConst : boolean;
  221. function gettypename:string;virtual;
  222. function elesize : longint;
  223. constructor init(l,h : longint;rd : pdef);
  224. constructor load;
  225. procedure write;virtual;
  226. {$ifdef GDB}
  227. function stabstring : pchar;virtual;
  228. procedure concatstabto(asmlist : paasmoutput);virtual;
  229. {$endif GDB}
  230. procedure deref;virtual;
  231. function size : longint;virtual;
  232. function alignment : longint;virtual;
  233. { generates the ranges needed by the asm instruction BOUND (i386)
  234. or CMP2 (Motorola) }
  235. procedure genrangecheck;
  236. { returns the label of the range check string }
  237. function getrangecheckstring : string;
  238. function needs_inittable : boolean;virtual;
  239. procedure write_rtti_data;virtual;
  240. procedure write_child_rtti_data;virtual;
  241. end;
  242. precorddef = ^trecorddef;
  243. trecorddef = object(tdef)
  244. symtable : psymtable;
  245. constructor init(p : psymtable);
  246. constructor load;
  247. destructor done;virtual;
  248. procedure write;virtual;
  249. procedure deref;virtual;
  250. function size:longint;virtual;
  251. function alignment : longint;virtual;
  252. function gettypename:string;virtual;
  253. { debug }
  254. {$ifdef GDB}
  255. function stabstring : pchar;virtual;
  256. procedure concatstabto(asmlist : paasmoutput);virtual;
  257. {$endif GDB}
  258. { init/final }
  259. procedure write_init_data;virtual;
  260. procedure write_child_init_data;virtual;
  261. function needs_inittable : boolean;virtual;
  262. { rtti }
  263. procedure write_rtti_data;virtual;
  264. procedure write_child_rtti_data;virtual;
  265. end;
  266. porddef = ^torddef;
  267. torddef = object(tdef)
  268. private
  269. rangenr : longint;
  270. public
  271. low,high : longint;
  272. typ : tbasetype;
  273. constructor init(t : tbasetype;v,b : longint);
  274. constructor load;
  275. procedure write;virtual;
  276. function is_publishable : boolean;virtual;
  277. function gettypename:string;virtual;
  278. procedure setsize;
  279. { generates the ranges needed by the asm instruction BOUND }
  280. { or CMP2 (Motorola) }
  281. procedure genrangecheck;
  282. function getrangecheckstring : string;
  283. { debug }
  284. {$ifdef GDB}
  285. function stabstring : pchar;virtual;
  286. {$endif GDB}
  287. { rtti }
  288. procedure write_rtti_data;virtual;
  289. end;
  290. pfloatdef = ^tfloatdef;
  291. tfloatdef = object(tdef)
  292. typ : tfloattype;
  293. constructor init(t : tfloattype);
  294. constructor load;
  295. procedure write;virtual;
  296. function gettypename:string;virtual;
  297. function is_publishable : boolean;virtual;
  298. procedure setsize;
  299. { debug }
  300. {$ifdef GDB}
  301. function stabstring : pchar;virtual;
  302. {$endif GDB}
  303. { rtti }
  304. procedure write_rtti_data;virtual;
  305. end;
  306. pabstractprocdef = ^tabstractprocdef;
  307. tabstractprocdef = object(tdef)
  308. { saves a definition to the return type }
  309. rettype : ttype;
  310. proctypeoption : tproctypeoption;
  311. proccalloptions : tproccalloptions;
  312. procoptions : tprocoptions;
  313. para : plinkedlist;
  314. symtablelevel : byte;
  315. fpu_used : byte; { how many stack fpu must be empty }
  316. constructor init;
  317. constructor load;
  318. destructor done;virtual;
  319. procedure write;virtual;
  320. procedure deref;virtual;
  321. procedure concatpara(tt:ttype;vsp : tvarspez);
  322. function para_size : longint;
  323. function demangled_paras : string;
  324. function proccalloption2str : string;
  325. procedure test_if_fpu_result;
  326. { debug }
  327. {$ifdef GDB}
  328. function stabstring : pchar;virtual;
  329. procedure concatstabto(asmlist : paasmoutput);virtual;
  330. {$endif GDB}
  331. end;
  332. pprocvardef = ^tprocvardef;
  333. tprocvardef = object(tabstractprocdef)
  334. constructor init;
  335. constructor load;
  336. procedure write;virtual;
  337. function size : longint;virtual;
  338. function gettypename:string;virtual;
  339. function is_publishable : boolean;virtual;
  340. { debug }
  341. {$ifdef GDB}
  342. function stabstring : pchar;virtual;
  343. procedure concatstabto(asmlist : paasmoutput); virtual;
  344. {$endif GDB}
  345. { rtti }
  346. procedure write_child_rtti_data;virtual;
  347. procedure write_rtti_data;virtual;
  348. end;
  349. tmessageinf = record
  350. case integer of
  351. 0 : (str : pchar);
  352. 1 : (i : longint);
  353. end;
  354. pprocdef = ^tprocdef;
  355. tprocdef = object(tabstractprocdef)
  356. private
  357. _mangledname : pchar;
  358. public
  359. extnumber : longint;
  360. messageinf : tmessageinf;
  361. nextoverloaded : pprocdef;
  362. { where is this function defined, needed here because there
  363. is only one symbol for all overloaded functions }
  364. fileinfo : tfileposinfo;
  365. { pointer to the local symbol table }
  366. localst : psymtable;
  367. { pointer to the parameter symbol table }
  368. parast : psymtable;
  369. { symbol owning this definition }
  370. procsym : pprocsym;
  371. { browser info }
  372. lastref,
  373. defref,
  374. crossref,
  375. lastwritten : pref;
  376. refcount : longint;
  377. _class : pobjectdef;
  378. { it's a tree, but this not easy to handle }
  379. { used for inlined procs }
  380. code : pointer;
  381. { true, if the procedure is only declared }
  382. { (forward procedure) }
  383. forwarddef,
  384. { true if the procedure is declared in the interface }
  385. interfacedef : boolean;
  386. { check the problems of manglednames }
  387. count : boolean;
  388. is_used : boolean;
  389. { small set which contains the modified registers }
  390. {$ifdef newcg}
  391. usedregisters : tregisterset;
  392. {$else newcg}
  393. usedregisters : longint;
  394. {$endif newcg}
  395. constructor init;
  396. constructor load;
  397. destructor done;virtual;
  398. procedure write;virtual;
  399. procedure deref;virtual;
  400. function haspara:boolean;
  401. function mangledname : string;
  402. procedure setmangledname(const s : string);
  403. procedure load_references;
  404. function write_references : boolean;
  405. function procname: string;
  406. { debug }
  407. {$ifdef GDB}
  408. function cplusplusmangledname : string;
  409. function stabstring : pchar;virtual;
  410. procedure concatstabto(asmlist : paasmoutput);virtual;
  411. {$endif GDB}
  412. { browser }
  413. {$ifdef BrowserLog}
  414. procedure add_to_browserlog;
  415. {$endif BrowserLog}
  416. end;
  417. pstringdef = ^tstringdef;
  418. tstringdef = object(tdef)
  419. string_typ : tstringtype;
  420. len : longint;
  421. constructor shortinit(l : byte);
  422. constructor shortload;
  423. constructor longinit(l : longint);
  424. constructor longload;
  425. constructor ansiinit(l : longint);
  426. constructor ansiload;
  427. constructor wideinit(l : longint);
  428. constructor wideload;
  429. function stringtypname:string;
  430. function size : longint;virtual;
  431. procedure write;virtual;
  432. function gettypename:string;virtual;
  433. function is_publishable : boolean;virtual;
  434. { debug }
  435. {$ifdef GDB}
  436. function stabstring : pchar;virtual;
  437. procedure concatstabto(asmlist : paasmoutput);virtual;
  438. {$endif GDB}
  439. { init/final }
  440. function needs_inittable : boolean;virtual;
  441. { rtti }
  442. procedure write_rtti_data;virtual;
  443. end;
  444. penumdef = ^tenumdef;
  445. tenumdef = object(tdef)
  446. rangenr,
  447. minval,
  448. maxval : longint;
  449. has_jumps : boolean;
  450. firstenum : penumsym;
  451. basedef : penumdef;
  452. constructor init;
  453. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  454. constructor load;
  455. destructor done;virtual;
  456. procedure write;virtual;
  457. procedure deref;virtual;
  458. function gettypename:string;virtual;
  459. function is_publishable : boolean;virtual;
  460. procedure calcsavesize;
  461. procedure setmax(_max:longint);
  462. procedure setmin(_min:longint);
  463. function min:longint;
  464. function max:longint;
  465. function getrangecheckstring:string;
  466. procedure genrangecheck;
  467. { debug }
  468. {$ifdef GDB}
  469. function stabstring : pchar;virtual;
  470. {$endif GDB}
  471. { rtti }
  472. procedure write_child_rtti_data;virtual;
  473. procedure write_rtti_data;virtual;
  474. end;
  475. psetdef = ^tsetdef;
  476. tsetdef = object(tdef)
  477. elementtype : ttype;
  478. settype : tsettype;
  479. constructor init(s : pdef;high : longint);
  480. constructor load;
  481. destructor done;virtual;
  482. procedure write;virtual;
  483. procedure deref;virtual;
  484. function gettypename:string;virtual;
  485. function is_publishable : boolean;virtual;
  486. { debug }
  487. {$ifdef GDB}
  488. function stabstring : pchar;virtual;
  489. procedure concatstabto(asmlist : paasmoutput);virtual;
  490. {$endif GDB}
  491. { rtti }
  492. procedure write_rtti_data;virtual;
  493. procedure write_child_rtti_data;virtual;
  494. end;
  495. {
  496. $Log$
  497. Revision 1.50 2000-01-07 01:14:40 peter
  498. * updated copyright to 2000
  499. Revision 1.49 2000/01/03 19:26:04 peter
  500. * fixed resolving of ttypesym which are reference from object/record
  501. fields.
  502. Revision 1.48 1999/11/30 10:40:55 peter
  503. + ttype, tsymlist
  504. Revision 1.47 1999/11/17 17:05:04 pierre
  505. * Notes/hints changes
  506. Revision 1.46 1999/11/09 23:35:50 pierre
  507. + better reference pos for forward defs
  508. Revision 1.45 1999/11/06 14:34:27 peter
  509. * truncated log to 20 revs
  510. Revision 1.44 1999/10/26 12:30:45 peter
  511. * const parameter is now checked
  512. * better and generic check if a node can be used for assigning
  513. * export fixes
  514. * procvar equal works now (it never had worked at least from 0.99.8)
  515. * defcoll changed to linkedlist with pparaitem so it can easily be
  516. walked both directions
  517. Revision 1.43 1999/10/01 10:05:44 peter
  518. + procedure directive support in const declarations, fixes bug 232
  519. Revision 1.42 1999/10/01 08:02:48 peter
  520. * forward type declaration rewritten
  521. Revision 1.41 1999/08/10 12:34:49 pierre
  522. + procsym field in tprocdef to allow correct gdb info generation
  523. Revision 1.40 1999/08/09 22:19:57 peter
  524. * classes vmt changed to only positive addresses
  525. * sharedlib creation is working
  526. Revision 1.39 1999/08/07 14:21:02 florian
  527. * some small problems fixed
  528. Revision 1.38 1999/08/05 16:53:15 peter
  529. * V_Fatal=1, all other V_ are also increased
  530. * Check for local procedure when assigning procvar
  531. * fixed comment parsing because directives
  532. * oldtp mode directives better supported
  533. * added some messages to errore.msg
  534. Revision 1.37 1999/08/03 22:03:16 peter
  535. * moved bitmask constants to sets
  536. * some other type/const renamings
  537. Revision 1.36 1999/08/02 21:29:04 florian
  538. * the main branch psub.pas is now used for
  539. newcg compiler
  540. Revision 1.35 1999/07/27 23:42:20 peter
  541. * indirect type referencing is now allowed
  542. Revision 1.34 1999/07/23 16:05:30 peter
  543. * alignment is now saved in the symtable
  544. * C alignment added for records
  545. * PPU version increased to solve .12 <-> .13 probs
  546. Revision 1.33 1999/06/22 16:24:45 pierre
  547. * local browser stuff corrected
  548. Revision 1.32 1999/06/02 10:11:51 florian
  549. * make cycle fixed i.e. compilation with 0.99.10
  550. * some fixes for qword
  551. * start of register calling conventions
  552. Revision 1.31 1999/05/31 16:42:35 peter
  553. * interfacedef flag for procdef if it's defined in the interface, to
  554. make a difference with 'forward;' directive forwarddef. Fixes 253
  555. Revision 1.30 1999/05/27 19:45:04 peter
  556. * removed oldasm
  557. * plabel -> pasmlabel
  558. * -a switches to source writing automaticly
  559. * assembler readers OOPed
  560. * asmsymbol automaticly external
  561. * jumptables and other label fixes for asm readers
  562. Revision 1.29 1999/05/23 18:42:15 florian
  563. * better error recovering in typed constants
  564. * some problems with arrays of const fixed, some problems
  565. due my previous
  566. - the location type of array constructor is now LOC_MEM
  567. - the pushing of high fixed
  568. - parameter copying fixed
  569. - zero temp. allocation removed
  570. * small problem in the assembler writers fixed:
  571. ref to nil wasn't written correctly
  572. Revision 1.28 1999/05/19 16:48:28 florian
  573. * tdef.typename: returns a now a proper type name for the most types
  574. Revision 1.27 1999/05/13 21:59:42 peter
  575. * removed oldppu code
  576. * warning if objpas is loaded from uses
  577. * first things for new deref writing
  578. Revision 1.26 1999/05/12 00:19:59 peter
  579. * removed R_DEFAULT_SEG
  580. * uniform float names
  581. Revision 1.25 1999/05/08 19:52:37 peter
  582. + MessagePos() which is enhanced Message() function but also gets the
  583. position info
  584. * Removed comp warnings
  585. }