symdefh.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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. { definition contains the informations about a type }
  22. tdeftype = (abstractdef,arraydef,recorddef,pointerdef,orddef,
  23. stringdef,enumdef,procdef,objectdef,errordef,
  24. filedef,formaldef,setdef,procvardef,floatdef,
  25. classrefdef);
  26. pdef = ^tdef;
  27. tdef = object(tsymtableentry)
  28. deftype : tdeftype;
  29. savesize : longint;
  30. sym : ptypesym; { which type the definition was generated this def }
  31. has_inittable : boolean;
  32. { adress of init informations }
  33. inittable_label : pasmlabel;
  34. has_rtti : boolean;
  35. { address of rtti }
  36. rtti_label : pasmlabel;
  37. nextglobal,
  38. previousglobal : pdef;
  39. {$ifdef GDB}
  40. globalnb : word;
  41. is_def_stab_written : boolean;
  42. {$endif GDB}
  43. constructor init;
  44. constructor load;
  45. destructor done;virtual;
  46. { registers enumdef inside objects or
  47. record directly in the owner symtable !! }
  48. procedure correct_owner_symtable;
  49. function typename:string;
  50. procedure write;virtual;
  51. function size:longint;virtual;
  52. {$ifdef GDB}
  53. function NumberString:string;
  54. procedure set_globalnb;
  55. function stabstring : pchar;virtual;
  56. function allstabstring : pchar;
  57. procedure concatstabto(asmlist : paasmoutput);virtual;
  58. {$endif GDB}
  59. procedure deref;virtual;
  60. procedure symderef;virtual;
  61. { init. tables }
  62. function needs_inittable : boolean;virtual;
  63. procedure generate_inittable;
  64. function get_inittable_label : pasmlabel;
  65. { the default implemenation calls write_rtti_data }
  66. { if init and rtti data is different these procedures }
  67. { must be overloaded }
  68. procedure write_init_data;virtual;
  69. { writes rtti of child to avoid mixup of rtti }
  70. procedure write_child_init_data;virtual;
  71. { rtti }
  72. procedure write_rtti_name;
  73. function get_rtti_label : string;virtual;
  74. procedure generate_rtti;virtual;
  75. procedure write_rtti_data;virtual;
  76. procedure write_child_rtti_data;virtual;
  77. { returns true, if the definition can be published }
  78. function is_publishable : boolean;virtual;
  79. function is_in_current : boolean;
  80. function gettypename:string;virtual;
  81. end;
  82. targconvtyp = (act_convertable,act_equal,act_exact);
  83. tvarspez = (vs_value,vs_const,vs_var);
  84. pdefcoll = ^tdefcoll;
  85. tdefcoll = record
  86. data : pdef;
  87. next : pdefcoll;
  88. paratyp : tvarspez;
  89. argconvtyp : targconvtyp;
  90. convertlevel : byte;
  91. register : tregister;
  92. end;
  93. tfiletype = (ft_text,ft_typed,ft_untyped);
  94. pfiledef = ^tfiledef;
  95. tfiledef = object(tdef)
  96. filetype : tfiletype;
  97. typed_as : pdef;
  98. constructor init(ft : tfiletype;tas : pdef);
  99. constructor load;
  100. procedure write;virtual;
  101. procedure deref;virtual;
  102. procedure setsize;
  103. {$ifdef GDB}
  104. function stabstring : pchar;virtual;
  105. procedure concatstabto(asmlist : paasmoutput);virtual;
  106. {$endif GDB}
  107. function gettypename:string;virtual;
  108. end;
  109. pformaldef = ^tformaldef;
  110. tformaldef = object(tdef)
  111. constructor init;
  112. constructor load;
  113. procedure write;virtual;
  114. {$ifdef GDB}
  115. function stabstring : pchar;virtual;
  116. procedure concatstabto(asmlist : paasmoutput);virtual;
  117. {$endif GDB}
  118. function gettypename:string;virtual;
  119. end;
  120. perrordef = ^terrordef;
  121. terrordef = object(tdef)
  122. constructor init;
  123. {$ifdef GDB}
  124. function stabstring : pchar;virtual;
  125. {$endif GDB}
  126. function gettypename:string;virtual;
  127. end;
  128. { tpointerdef and tclassrefdef should get a common
  129. base class, but I derived tclassrefdef from tpointerdef
  130. to avoid problems with bugs (FK)
  131. }
  132. ppointerdef = ^tpointerdef;
  133. tpointerdef = object(tdef)
  134. definition : pdef;
  135. defsym : ptypesym;
  136. is_far : boolean;
  137. constructor init(def : pdef);
  138. constructor initfar(def : pdef);
  139. constructor load;
  140. procedure write;virtual;
  141. {$ifdef GDB}
  142. function stabstring : pchar;virtual;
  143. procedure concatstabto(asmlist : paasmoutput);virtual;
  144. {$endif GDB}
  145. procedure deref;virtual;
  146. function gettypename:string;virtual;
  147. end;
  148. pobjectdef = ^tobjectdef;
  149. tobjectdef = object(tdef)
  150. childof : pobjectdef;
  151. objname : pstring;
  152. { privatesyms : psymtable;
  153. protectedsyms : psymtable; }
  154. publicsyms : psymtable;
  155. options : longint;
  156. { to be able to have a variable vmt position }
  157. { and no vmt field for objects without virtuals }
  158. vmt_offset : longint;
  159. constructor init(const n : string;c : pobjectdef);
  160. destructor done;virtual;
  161. procedure check_forwards;
  162. function isrelated(d : pobjectdef) : boolean;
  163. function size : longint;virtual;
  164. constructor load;
  165. procedure write;virtual;
  166. function vmt_mangledname : string;
  167. function rtti_name : string;
  168. function isclass : boolean;
  169. procedure insertvmt;
  170. procedure set_parent(c : pobjectdef);
  171. {$ifdef GDB}
  172. function stabstring : pchar;virtual;
  173. {$endif GDB}
  174. procedure deref;virtual;
  175. function needs_inittable : boolean;virtual;
  176. procedure write_init_data;virtual;
  177. procedure write_child_init_data;virtual;
  178. { rtti }
  179. function get_rtti_label : string;virtual;
  180. procedure generate_rtti;virtual;
  181. procedure write_rtti_data;virtual;
  182. procedure write_child_rtti_data;virtual;
  183. function next_free_name_index : longint;
  184. function is_publishable : boolean;virtual;
  185. end;
  186. pclassrefdef = ^tclassrefdef;
  187. tclassrefdef = object(tpointerdef)
  188. constructor init(def : pdef);
  189. constructor load;
  190. procedure write;virtual;
  191. {$ifdef GDB}
  192. function stabstring : pchar;virtual;
  193. procedure concatstabto(asmlist : paasmoutput);virtual;
  194. {$endif GDB}
  195. function gettypename:string;virtual;
  196. end;
  197. parraydef = ^tarraydef;
  198. tarraydef = object(tdef)
  199. private
  200. rangenr : longint;
  201. public
  202. lowrange,
  203. highrange : longint;
  204. definition : pdef;
  205. rangedef : pdef;
  206. IsVariant,
  207. IsConstructor,
  208. IsArrayOfConst : boolean;
  209. function gettypename:string;virtual;
  210. function elesize : longint;
  211. constructor init(l,h : longint;rd : pdef);
  212. constructor load;
  213. procedure write;virtual;
  214. {$ifdef GDB}
  215. function stabstring : pchar;virtual;
  216. procedure concatstabto(asmlist : paasmoutput);virtual;
  217. {$endif GDB}
  218. procedure deref;virtual;
  219. function size : longint;virtual;
  220. { generates the ranges needed by the asm instruction BOUND (i386)
  221. or CMP2 (Motorola) }
  222. procedure genrangecheck;
  223. { returns the label of the range check string }
  224. function getrangecheckstring : string;
  225. function needs_inittable : boolean;virtual;
  226. procedure write_rtti_data;virtual;
  227. procedure write_child_rtti_data;virtual;
  228. end;
  229. precdef = ^trecdef;
  230. trecdef = object(tdef)
  231. symtable : psymtable;
  232. constructor init(p : psymtable);
  233. constructor load;
  234. destructor done;virtual;
  235. procedure write;virtual;
  236. {$ifdef GDB}
  237. function stabstring : pchar;virtual;
  238. procedure concatstabto(asmlist : paasmoutput);virtual;
  239. {$endif GDB}
  240. procedure deref;virtual;
  241. function needs_inittable : boolean;virtual;
  242. procedure write_rtti_data;virtual;
  243. procedure write_init_data;virtual;
  244. procedure write_child_rtti_data;virtual;
  245. procedure write_child_init_data;virtual;
  246. function gettypename:string;virtual;
  247. end;
  248. { base types }
  249. tbasetype = (uauto,uvoid,uchar,
  250. u8bit,u16bit,u32bit,
  251. s8bit,s16bit,s32bit,
  252. bool8bit,bool16bit,bool32bit { uwchar,bool1bit,bitfield},
  253. u64bit,s64bitint);
  254. porddef = ^torddef;
  255. torddef = object(tdef)
  256. low,high : longint;
  257. rangenr : longint;
  258. typ : tbasetype;
  259. {
  260. bits : byte;
  261. }
  262. constructor init(t : tbasetype;v,b : longint);
  263. constructor load;
  264. procedure write;virtual;
  265. {$ifdef GDB}
  266. function stabstring : pchar;virtual;
  267. {$endif GDB}
  268. procedure setsize;
  269. { generates the ranges needed by the asm instruction BOUND }
  270. { or CMP2 (Motorola) }
  271. procedure genrangecheck;
  272. { returns the label of the range check string }
  273. function getrangecheckstring : string;
  274. procedure write_rtti_data;virtual;
  275. function is_publishable : boolean;virtual;
  276. function gettypename:string;virtual;
  277. end;
  278. { sextreal is dependant on the cpu, s64bit is also }
  279. { dependant on the size (tp = 80bit for both) }
  280. { The EXTENDED format exists on the motorola FPU }
  281. { but it uses 96 bits instead of 80, with some }
  282. { unused bits within the number itself! Pretty }
  283. { complicated to support, so no support for the }
  284. { moment. }
  285. { s64 bit is considered as a real because all }
  286. { calculations are done by the fpu. }
  287. tfloattype = (s32real,s64real,s80real,s64comp,f16bit,f32bit);
  288. pfloatdef = ^tfloatdef;
  289. tfloatdef = object(tdef)
  290. typ : tfloattype;
  291. constructor init(t : tfloattype);
  292. constructor load;
  293. procedure write;virtual;
  294. {$ifdef GDB}
  295. function stabstring : pchar;virtual;
  296. {$endif GDB}
  297. procedure setsize;
  298. function is_publishable : boolean;virtual;
  299. procedure write_rtti_data;virtual;
  300. function gettypename:string;virtual;
  301. end;
  302. pabstractprocdef = ^tabstractprocdef;
  303. tabstractprocdef = object(tdef)
  304. { saves a definition to the return type }
  305. retdef : pdef;
  306. fpu_used : byte; { how many stack fpu must be empty }
  307. options : longint; { save the procedure options }
  308. para1 : pdefcoll;
  309. constructor init;
  310. constructor load;
  311. destructor done;virtual;
  312. procedure concatdef(p : pdef;vsp : tvarspez);
  313. procedure deref;virtual;
  314. function para_size : longint;
  315. function demangled_paras : string;
  316. {$ifdef GDB}
  317. function stabstring : pchar;virtual;
  318. procedure concatstabto(asmlist : paasmoutput);virtual;
  319. {$endif GDB}
  320. procedure test_if_fpu_result;
  321. procedure write;virtual;
  322. end;
  323. pprocvardef = ^tprocvardef;
  324. tprocvardef = object(tabstractprocdef)
  325. constructor init;
  326. constructor load;
  327. procedure write;virtual;
  328. function size : longint;virtual;
  329. {$ifdef GDB}
  330. function stabstring : pchar;virtual;
  331. procedure concatstabto(asmlist : paasmoutput); virtual;
  332. {$endif GDB}
  333. procedure write_child_rtti_data;virtual;
  334. function is_publishable : boolean;virtual;
  335. procedure write_rtti_data;virtual;
  336. function gettypename:string;virtual;
  337. end;
  338. tmessageinf = record
  339. case integer of
  340. 0 : (str : pchar);
  341. 1 : (i : longint);
  342. end;
  343. pprocdef = ^tprocdef;
  344. tprocdef = object(tabstractprocdef)
  345. extnumber : longint;
  346. messageinf : tmessageinf;
  347. nextoverloaded : pprocdef;
  348. { where is this function defined, needed here because there
  349. is only one symbol for all overloaded functions }
  350. fileinfo : tfileposinfo;
  351. { pointer to the local symbol table }
  352. localst : psymtable;
  353. { pointer to the parameter symbol table }
  354. parast : psymtable;
  355. { browser info }
  356. lastref,
  357. defref,
  358. lastwritten : pref;
  359. refcount : longint;
  360. _class : pobjectdef;
  361. _mangledname : pchar;
  362. { it's a tree, but this not easy to handle }
  363. { used for inlined procs }
  364. code : pointer;
  365. { true, if the procedure is only declared }
  366. { (forward procedure) }
  367. forwarddef,
  368. { true if the procedure is declared in the interface }
  369. interfacedef : boolean;
  370. { check the problems of manglednames }
  371. count : boolean;
  372. is_used : boolean;
  373. { set which contains the modified registers }
  374. {$ifdef i386}
  375. usedregisters : byte;
  376. {$endif}
  377. {$ifdef m68k}
  378. usedregisters : word;
  379. {$endif}
  380. {$ifdef alpha}
  381. usedregisters_int : longint;
  382. usedregisters_fpu : longint;
  383. {$endif}
  384. constructor init;
  385. destructor done;virtual;
  386. constructor load;
  387. procedure write;virtual;
  388. {$ifdef GDB}
  389. function cplusplusmangledname : string;
  390. function stabstring : pchar;virtual;
  391. procedure concatstabto(asmlist : paasmoutput);virtual;
  392. {$endif GDB}
  393. procedure deref;virtual;
  394. function mangledname : string;
  395. procedure setmangledname(const s : string);
  396. procedure load_references;
  397. function write_references : boolean;
  398. {$ifdef BrowserLog}
  399. procedure add_to_browserlog;
  400. {$endif BrowserLog}
  401. function haspara:boolean;
  402. end;
  403. tstringtype = (st_shortstring, st_longstring, st_ansistring, st_widestring);
  404. pstringdef = ^tstringdef;
  405. tstringdef = object(tdef)
  406. string_typ : tstringtype;
  407. len : longint;
  408. constructor shortinit(l : byte);
  409. constructor shortload;
  410. constructor longinit(l : longint);
  411. constructor longload;
  412. constructor ansiinit(l : longint);
  413. constructor ansiload;
  414. constructor wideinit(l : longint);
  415. constructor wideload;
  416. function stringtypname:string;
  417. function size : longint;virtual;
  418. procedure write;virtual;
  419. {$ifdef GDB}
  420. function stabstring : pchar;virtual;
  421. procedure concatstabto(asmlist : paasmoutput);virtual;
  422. {$endif GDB}
  423. function needs_inittable : boolean;virtual;
  424. procedure write_rtti_data;virtual;
  425. function is_publishable : boolean;virtual;
  426. function gettypename:string;virtual;
  427. end;
  428. penumdef = ^tenumdef;
  429. tenumdef = object(tdef)
  430. rangenr,
  431. minval,
  432. maxval : longint;
  433. has_jumps : boolean;
  434. firstenum : penumsym;
  435. basedef : penumdef;
  436. constructor init;
  437. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  438. constructor load;
  439. destructor done;virtual;
  440. procedure write;virtual;
  441. procedure deref;virtual;
  442. procedure calcsavesize;
  443. procedure setmax(_max:longint);
  444. procedure setmin(_min:longint);
  445. function min:longint;
  446. function max:longint;
  447. function getrangecheckstring:string;
  448. procedure genrangecheck;
  449. {$ifdef GDB}
  450. function stabstring : pchar;virtual;
  451. {$endif GDB}
  452. procedure write_child_rtti_data;virtual;
  453. procedure write_rtti_data;virtual;
  454. function is_publishable : boolean;virtual;
  455. function gettypename:string;virtual;
  456. end;
  457. tsettype = (normset,smallset,varset);
  458. psetdef = ^tsetdef;
  459. tsetdef = object(tdef)
  460. setof : pdef;
  461. settype : tsettype;
  462. constructor init(s : pdef;high : longint);
  463. constructor load;
  464. procedure write;virtual;
  465. {$ifdef GDB}
  466. function stabstring : pchar;virtual;
  467. procedure concatstabto(asmlist : paasmoutput);virtual;
  468. {$endif GDB}
  469. procedure deref;virtual;
  470. function is_publishable : boolean;virtual;
  471. procedure write_rtti_data;virtual;
  472. procedure write_child_rtti_data;virtual;
  473. function gettypename:string;virtual;
  474. end;
  475. {
  476. $Log$
  477. Revision 1.32 1999-06-02 10:11:51 florian
  478. * make cycle fixed i.e. compilation with 0.99.10
  479. * some fixes for qword
  480. * start of register calling conventions
  481. Revision 1.31 1999/05/31 16:42:35 peter
  482. * interfacedef flag for procdef if it's defined in the interface, to
  483. make a difference with 'forward;' directive forwarddef. Fixes 253
  484. Revision 1.30 1999/05/27 19:45:04 peter
  485. * removed oldasm
  486. * plabel -> pasmlabel
  487. * -a switches to source writing automaticly
  488. * assembler readers OOPed
  489. * asmsymbol automaticly external
  490. * jumptables and other label fixes for asm readers
  491. Revision 1.29 1999/05/23 18:42:15 florian
  492. * better error recovering in typed constants
  493. * some problems with arrays of const fixed, some problems
  494. due my previous
  495. - the location type of array constructor is now LOC_MEM
  496. - the pushing of high fixed
  497. - parameter copying fixed
  498. - zero temp. allocation removed
  499. * small problem in the assembler writers fixed:
  500. ref to nil wasn't written correctly
  501. Revision 1.28 1999/05/19 16:48:28 florian
  502. * tdef.typename: returns a now a proper type name for the most types
  503. Revision 1.27 1999/05/13 21:59:42 peter
  504. * removed oldppu code
  505. * warning if objpas is loaded from uses
  506. * first things for new deref writing
  507. Revision 1.26 1999/05/12 00:19:59 peter
  508. * removed R_DEFAULT_SEG
  509. * uniform float names
  510. Revision 1.25 1999/05/08 19:52:37 peter
  511. + MessagePos() which is enhanced Message() function but also gets the
  512. position info
  513. * Removed comp warnings
  514. Revision 1.24 1999/05/06 09:05:30 peter
  515. * generic write_float and str_float
  516. * fixed constant float conversions
  517. Revision 1.23 1999/04/26 18:30:02 peter
  518. * farpointerdef moved into pointerdef.is_far
  519. Revision 1.22 1999/04/26 13:31:49 peter
  520. * release storenumber,double_checksum
  521. Revision 1.21 1999/04/21 09:43:52 peter
  522. * storenumber works
  523. * fixed some typos in double_checksum
  524. + incompatible types type1 and type2 message (with storenumber)
  525. Revision 1.20 1999/04/14 09:15:00 peter
  526. * first things to store the symbol/def number in the ppu
  527. Revision 1.19 1999/04/08 15:57:52 peter
  528. + subrange checking for readln()
  529. Revision 1.18 1999/03/02 18:24:21 peter
  530. * fixed overloading of array of char
  531. Revision 1.17 1999/03/01 13:45:06 pierre
  532. + added staticppusymtable symtable type for local browsing
  533. Revision 1.16 1999/02/22 20:13:39 florian
  534. + first implementation of message keyword
  535. Revision 1.15 1999/01/20 14:18:40 pierre
  536. * bugs related to mangledname solved
  537. - linux external without name
  538. -external procs already used
  539. (added count and is_used boolean fiels in tprocvar)
  540. Revision 1.14 1999/01/12 14:25:33 peter
  541. + BrowserLog for browser.log generation
  542. + BrowserCol for browser info in TCollections
  543. * released all other UseBrowser
  544. Revision 1.13 1998/12/30 22:15:53 peter
  545. + farpointer type
  546. * absolutesym now also stores if its far
  547. Revision 1.12 1998/12/10 09:47:28 florian
  548. + basic operations with int64/qord (compiler with -dint64)
  549. + rtti of enumerations extended: names are now written
  550. Revision 1.11 1998/11/29 21:45:49 florian
  551. * problem with arrays with init tables fixed
  552. Revision 1.10 1998/11/20 15:36:00 florian
  553. * problems with rtti fixed, hope it works
  554. Revision 1.9 1998/11/10 10:09:14 peter
  555. * va_list -> array of const
  556. Revision 1.8 1998/11/09 11:44:37 peter
  557. + va_list for printf support
  558. Revision 1.7 1998/11/05 12:02:59 peter
  559. * released useansistring
  560. * removed -Sv, its now available in fpc modes
  561. Revision 1.6 1998/10/22 17:11:23 pierre
  562. + terminated the include exclude implementation for i386
  563. * enums inside records fixed
  564. Revision 1.5 1998/10/16 13:12:55 pierre
  565. * added vmt_offsets in destructors code also !!!
  566. * vmt_offset code for m68k
  567. Revision 1.4 1998/10/16 08:51:52 peter
  568. + target_os.stackalignment
  569. + stack can be aligned at 2 or 4 byte boundaries
  570. Revision 1.3 1998/10/05 21:33:30 peter
  571. * fixed 161,165,166,167,168
  572. Revision 1.2 1998/10/02 07:20:40 florian
  573. * range checking in units doesn't work if the units are smartlinked, fixed
  574. Revision 1.1 1998/09/23 12:03:57 peter
  575. * overloading fix for array of const
  576. }