symdefh.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. crossref,
  359. lastwritten : pref;
  360. refcount : longint;
  361. _class : pobjectdef;
  362. _mangledname : pchar;
  363. { it's a tree, but this not easy to handle }
  364. { used for inlined procs }
  365. code : pointer;
  366. { true, if the procedure is only declared }
  367. { (forward procedure) }
  368. forwarddef,
  369. { true if the procedure is declared in the interface }
  370. interfacedef : boolean;
  371. { check the problems of manglednames }
  372. count : boolean;
  373. is_used : boolean;
  374. { set which contains the modified registers }
  375. {$ifdef i386}
  376. usedregisters : byte;
  377. {$endif}
  378. {$ifdef m68k}
  379. usedregisters : word;
  380. {$endif}
  381. {$ifdef alpha}
  382. usedregisters_int : longint;
  383. usedregisters_fpu : longint;
  384. {$endif}
  385. constructor init;
  386. destructor done;virtual;
  387. constructor load;
  388. procedure write;virtual;
  389. {$ifdef GDB}
  390. function cplusplusmangledname : string;
  391. function stabstring : pchar;virtual;
  392. procedure concatstabto(asmlist : paasmoutput);virtual;
  393. {$endif GDB}
  394. procedure deref;virtual;
  395. function mangledname : string;
  396. procedure setmangledname(const s : string);
  397. procedure load_references;
  398. function write_references : boolean;
  399. {$ifdef BrowserLog}
  400. procedure add_to_browserlog;
  401. {$endif BrowserLog}
  402. function haspara:boolean;
  403. end;
  404. tstringtype = (st_shortstring, st_longstring, st_ansistring, st_widestring);
  405. pstringdef = ^tstringdef;
  406. tstringdef = object(tdef)
  407. string_typ : tstringtype;
  408. len : longint;
  409. constructor shortinit(l : byte);
  410. constructor shortload;
  411. constructor longinit(l : longint);
  412. constructor longload;
  413. constructor ansiinit(l : longint);
  414. constructor ansiload;
  415. constructor wideinit(l : longint);
  416. constructor wideload;
  417. function stringtypname:string;
  418. function size : longint;virtual;
  419. procedure write;virtual;
  420. {$ifdef GDB}
  421. function stabstring : pchar;virtual;
  422. procedure concatstabto(asmlist : paasmoutput);virtual;
  423. {$endif GDB}
  424. function needs_inittable : boolean;virtual;
  425. procedure write_rtti_data;virtual;
  426. function is_publishable : boolean;virtual;
  427. function gettypename:string;virtual;
  428. end;
  429. penumdef = ^tenumdef;
  430. tenumdef = object(tdef)
  431. rangenr,
  432. minval,
  433. maxval : longint;
  434. has_jumps : boolean;
  435. firstenum : penumsym;
  436. basedef : penumdef;
  437. constructor init;
  438. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  439. constructor load;
  440. destructor done;virtual;
  441. procedure write;virtual;
  442. procedure deref;virtual;
  443. procedure calcsavesize;
  444. procedure setmax(_max:longint);
  445. procedure setmin(_min:longint);
  446. function min:longint;
  447. function max:longint;
  448. function getrangecheckstring:string;
  449. procedure genrangecheck;
  450. {$ifdef GDB}
  451. function stabstring : pchar;virtual;
  452. {$endif GDB}
  453. procedure write_child_rtti_data;virtual;
  454. procedure write_rtti_data;virtual;
  455. function is_publishable : boolean;virtual;
  456. function gettypename:string;virtual;
  457. end;
  458. tsettype = (normset,smallset,varset);
  459. psetdef = ^tsetdef;
  460. tsetdef = object(tdef)
  461. setof : pdef;
  462. settype : tsettype;
  463. constructor init(s : pdef;high : longint);
  464. constructor load;
  465. procedure write;virtual;
  466. {$ifdef GDB}
  467. function stabstring : pchar;virtual;
  468. procedure concatstabto(asmlist : paasmoutput);virtual;
  469. {$endif GDB}
  470. procedure deref;virtual;
  471. function is_publishable : boolean;virtual;
  472. procedure write_rtti_data;virtual;
  473. procedure write_child_rtti_data;virtual;
  474. function gettypename:string;virtual;
  475. end;
  476. {
  477. $Log$
  478. Revision 1.33 1999-06-22 16:24:45 pierre
  479. * local browser stuff corrected
  480. Revision 1.32 1999/06/02 10:11:51 florian
  481. * make cycle fixed i.e. compilation with 0.99.10
  482. * some fixes for qword
  483. * start of register calling conventions
  484. Revision 1.31 1999/05/31 16:42:35 peter
  485. * interfacedef flag for procdef if it's defined in the interface, to
  486. make a difference with 'forward;' directive forwarddef. Fixes 253
  487. Revision 1.30 1999/05/27 19:45:04 peter
  488. * removed oldasm
  489. * plabel -> pasmlabel
  490. * -a switches to source writing automaticly
  491. * assembler readers OOPed
  492. * asmsymbol automaticly external
  493. * jumptables and other label fixes for asm readers
  494. Revision 1.29 1999/05/23 18:42:15 florian
  495. * better error recovering in typed constants
  496. * some problems with arrays of const fixed, some problems
  497. due my previous
  498. - the location type of array constructor is now LOC_MEM
  499. - the pushing of high fixed
  500. - parameter copying fixed
  501. - zero temp. allocation removed
  502. * small problem in the assembler writers fixed:
  503. ref to nil wasn't written correctly
  504. Revision 1.28 1999/05/19 16:48:28 florian
  505. * tdef.typename: returns a now a proper type name for the most types
  506. Revision 1.27 1999/05/13 21:59:42 peter
  507. * removed oldppu code
  508. * warning if objpas is loaded from uses
  509. * first things for new deref writing
  510. Revision 1.26 1999/05/12 00:19:59 peter
  511. * removed R_DEFAULT_SEG
  512. * uniform float names
  513. Revision 1.25 1999/05/08 19:52:37 peter
  514. + MessagePos() which is enhanced Message() function but also gets the
  515. position info
  516. * Removed comp warnings
  517. Revision 1.24 1999/05/06 09:05:30 peter
  518. * generic write_float and str_float
  519. * fixed constant float conversions
  520. Revision 1.23 1999/04/26 18:30:02 peter
  521. * farpointerdef moved into pointerdef.is_far
  522. Revision 1.22 1999/04/26 13:31:49 peter
  523. * release storenumber,double_checksum
  524. Revision 1.21 1999/04/21 09:43:52 peter
  525. * storenumber works
  526. * fixed some typos in double_checksum
  527. + incompatible types type1 and type2 message (with storenumber)
  528. Revision 1.20 1999/04/14 09:15:00 peter
  529. * first things to store the symbol/def number in the ppu
  530. Revision 1.19 1999/04/08 15:57:52 peter
  531. + subrange checking for readln()
  532. Revision 1.18 1999/03/02 18:24:21 peter
  533. * fixed overloading of array of char
  534. Revision 1.17 1999/03/01 13:45:06 pierre
  535. + added staticppusymtable symtable type for local browsing
  536. Revision 1.16 1999/02/22 20:13:39 florian
  537. + first implementation of message keyword
  538. Revision 1.15 1999/01/20 14:18:40 pierre
  539. * bugs related to mangledname solved
  540. - linux external without name
  541. -external procs already used
  542. (added count and is_used boolean fiels in tprocvar)
  543. Revision 1.14 1999/01/12 14:25:33 peter
  544. + BrowserLog for browser.log generation
  545. + BrowserCol for browser info in TCollections
  546. * released all other UseBrowser
  547. Revision 1.13 1998/12/30 22:15:53 peter
  548. + farpointer type
  549. * absolutesym now also stores if its far
  550. Revision 1.12 1998/12/10 09:47:28 florian
  551. + basic operations with int64/qord (compiler with -dint64)
  552. + rtti of enumerations extended: names are now written
  553. Revision 1.11 1998/11/29 21:45:49 florian
  554. * problem with arrays with init tables fixed
  555. Revision 1.10 1998/11/20 15:36:00 florian
  556. * problems with rtti fixed, hope it works
  557. Revision 1.9 1998/11/10 10:09:14 peter
  558. * va_list -> array of const
  559. Revision 1.8 1998/11/09 11:44:37 peter
  560. + va_list for printf support
  561. Revision 1.7 1998/11/05 12:02:59 peter
  562. * released useansistring
  563. * removed -Sv, its now available in fpc modes
  564. Revision 1.6 1998/10/22 17:11:23 pierre
  565. + terminated the include exclude implementation for i386
  566. * enums inside records fixed
  567. Revision 1.5 1998/10/16 13:12:55 pierre
  568. * added vmt_offsets in destructors code also !!!
  569. * vmt_offset code for m68k
  570. Revision 1.4 1998/10/16 08:51:52 peter
  571. + target_os.stackalignment
  572. + stack can be aligned at 2 or 4 byte boundaries
  573. Revision 1.3 1998/10/05 21:33:30 peter
  574. * fixed 161,165,166,167,168
  575. Revision 1.2 1998/10/02 07:20:40 florian
  576. * range checking in units doesn't work if the units are smartlinked, fixed
  577. Revision 1.1 1998/09/23 12:03:57 peter
  578. * overloading fix for array of const
  579. }