2
0

symdefh.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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,farpointerdef);
  26. pdef = ^tdef;
  27. tdef = object
  28. deftype : tdeftype;
  29. indexnb : longint;
  30. savesize : longint;
  31. next : pdef;
  32. owner : psymtable;
  33. sym : ptypesym; { which type the definition was generated this def }
  34. has_inittable : boolean;
  35. { adress of init informations }
  36. inittable_label : plabel;
  37. has_rtti : boolean;
  38. { address of rtti }
  39. rtti_label : plabel;
  40. nextglobal,
  41. previousglobal : pdef;
  42. {$ifdef GDB}
  43. globalnb : word;
  44. is_def_stab_written : boolean;
  45. {$endif GDB}
  46. constructor init;
  47. constructor load;
  48. destructor done;virtual;
  49. { registers enumdef inside objects or
  50. record directly in the owner symtable !! }
  51. procedure correct_owner_symtable;
  52. procedure write;virtual;
  53. procedure writename;
  54. function size:longint;virtual;
  55. {$ifdef GDB}
  56. function NumberString:string;
  57. procedure set_globalnb;
  58. function stabstring : pchar;virtual;
  59. function allstabstring : pchar;
  60. procedure concatstabto(asmlist : paasmoutput);virtual;
  61. {$endif GDB}
  62. procedure deref;virtual;
  63. { init. tables }
  64. function needs_inittable : boolean;virtual;
  65. procedure generate_inittable;
  66. function get_inittable_label : plabel;
  67. { the default implemenation calls write_rtti_data }
  68. { if init and rtti data is different these procedures }
  69. { must be overloaded }
  70. procedure write_init_data;virtual;
  71. { writes rtti of child to avoid mixup of rtti }
  72. procedure write_child_init_data;virtual;
  73. { rtti }
  74. function get_rtti_label : string;virtual;
  75. procedure generate_rtti;virtual;
  76. procedure write_rtti_data;virtual;
  77. procedure write_child_rtti_data;virtual;
  78. { returns true, if the definition can be published }
  79. function is_publishable : boolean;virtual;
  80. function is_in_current : boolean;
  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. end;
  92. tfiletype = (ft_text,ft_typed,ft_untyped);
  93. pfiledef = ^tfiledef;
  94. tfiledef = object(tdef)
  95. filetype : tfiletype;
  96. typed_as : pdef;
  97. constructor init(ft : tfiletype;tas : pdef);
  98. constructor load;
  99. procedure write;virtual;
  100. procedure deref;virtual;
  101. procedure setsize;
  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. {$ifdef GDB}
  113. function stabstring : pchar;virtual;
  114. procedure concatstabto(asmlist : paasmoutput);virtual;
  115. {$endif GDB}
  116. end;
  117. perrordef = ^terrordef;
  118. terrordef = object(tdef)
  119. constructor init;
  120. {$ifdef GDB}
  121. function stabstring : pchar;virtual;
  122. {$endif GDB}
  123. end;
  124. { tpointerdef and tclassrefdef should get a common
  125. base class, but I derived tclassrefdef from tpointerdef
  126. to avoid problems with bugs (FK)
  127. }
  128. ppointerdef = ^tpointerdef;
  129. tpointerdef = object(tdef)
  130. definition : pdef;
  131. defsym : ptypesym;
  132. constructor init(def : pdef);
  133. constructor load;
  134. procedure write;virtual;
  135. {$ifdef GDB}
  136. function stabstring : pchar;virtual;
  137. procedure concatstabto(asmlist : paasmoutput);virtual;
  138. {$endif GDB}
  139. procedure deref;virtual;
  140. end;
  141. pfarpointerdef = ^tfarpointerdef;
  142. tfarpointerdef = object(tpointerdef)
  143. constructor init(def : pdef);
  144. constructor load;
  145. procedure write;virtual;
  146. end;
  147. pobjectdef = ^tobjectdef;
  148. tobjectdef = object(tdef)
  149. childof : pobjectdef;
  150. name : pstring;
  151. { privatesyms : psymtable;
  152. protectedsyms : psymtable; }
  153. publicsyms : psymtable;
  154. options : longint;
  155. { to be able to have a variable vmt position }
  156. { and no vmt field for objects without virtuals }
  157. vmt_offset : longint;
  158. constructor init(const n : string;c : pobjectdef);
  159. destructor done;virtual;
  160. procedure check_forwards;
  161. function isrelated(d : pobjectdef) : boolean;
  162. function size : longint;virtual;
  163. constructor load;
  164. procedure write;virtual;
  165. function vmt_mangledname : string;
  166. function rtti_name : string;
  167. function isclass : boolean;
  168. procedure insertvmt;
  169. procedure set_parent(c : pobjectdef);
  170. {$ifdef GDB}
  171. function stabstring : pchar;virtual;
  172. {$endif GDB}
  173. procedure deref;virtual;
  174. function needs_inittable : boolean;virtual;
  175. procedure write_init_data;virtual;
  176. procedure write_child_init_data;virtual;
  177. { rtti }
  178. function get_rtti_label : string;virtual;
  179. procedure generate_rtti;virtual;
  180. procedure write_rtti_data;virtual;
  181. procedure write_child_rtti_data;virtual;
  182. function next_free_name_index : longint;
  183. function is_publishable : boolean;virtual;
  184. end;
  185. pclassrefdef = ^tclassrefdef;
  186. tclassrefdef = object(tpointerdef)
  187. constructor init(def : pdef);
  188. constructor load;
  189. procedure write;virtual;
  190. {$ifdef GDB}
  191. function stabstring : pchar;virtual;
  192. procedure concatstabto(asmlist : paasmoutput);virtual;
  193. {$endif GDB}
  194. end;
  195. parraydef = ^tarraydef;
  196. tarraydef = object(tdef)
  197. private
  198. rangenr : longint;
  199. public
  200. lowrange,
  201. highrange : longint;
  202. definition : pdef;
  203. rangedef : pdef;
  204. IsVariant,
  205. IsConstructor,
  206. IsArrayOfConst : boolean;
  207. function elesize : longint;
  208. constructor init(l,h : longint;rd : pdef);
  209. constructor load;
  210. procedure write;virtual;
  211. {$ifdef GDB}
  212. function stabstring : pchar;virtual;
  213. procedure concatstabto(asmlist : paasmoutput);virtual;
  214. {$endif GDB}
  215. procedure deref;virtual;
  216. function size : longint;virtual;
  217. { generates the ranges needed by the asm instruction BOUND (i386)
  218. or CMP2 (Motorola) }
  219. procedure genrangecheck;
  220. { returns the label of the range check string }
  221. function getrangecheckstring : string;
  222. function needs_inittable : boolean;virtual;
  223. procedure write_rtti_data;virtual;
  224. procedure write_child_rtti_data;virtual;
  225. end;
  226. precdef = ^trecdef;
  227. trecdef = object(tdef)
  228. symtable : psymtable;
  229. constructor init(p : psymtable);
  230. constructor load;
  231. destructor done;virtual;
  232. procedure write;virtual;
  233. {$ifdef GDB}
  234. function stabstring : pchar;virtual;
  235. procedure concatstabto(asmlist : paasmoutput);virtual;
  236. {$endif GDB}
  237. procedure deref;virtual;
  238. function needs_inittable : boolean;virtual;
  239. procedure write_rtti_data;virtual;
  240. procedure write_init_data;virtual;
  241. procedure write_child_rtti_data;virtual;
  242. procedure write_child_init_data;virtual;
  243. end;
  244. { base types }
  245. tbasetype = (uauto,uvoid,uchar,
  246. u8bit,u16bit,u32bit,
  247. s8bit,s16bit,s32bit,
  248. bool8bit,bool16bit,bool32bit { uwchar,bool1bit,bitfield},
  249. u64bit,s64bitint);
  250. porddef = ^torddef;
  251. torddef = object(tdef)
  252. low,high : longint;
  253. rangenr : longint;
  254. typ : tbasetype;
  255. {
  256. bits : byte;
  257. }
  258. constructor init(t : tbasetype;v,b : longint);
  259. constructor load;
  260. procedure write;virtual;
  261. {$ifdef GDB}
  262. function stabstring : pchar;virtual;
  263. {$endif GDB}
  264. procedure setsize;
  265. { generates the ranges needed by the asm instruction BOUND }
  266. { or CMP2 (Motorola) }
  267. procedure genrangecheck;
  268. { returns the label of the range check string }
  269. function getrangecheckstring : string;
  270. procedure write_rtti_data;virtual;
  271. function is_publishable : boolean;virtual;
  272. end;
  273. { sextreal is dependant on the cpu, s64bit is also }
  274. { dependant on the size (tp = 80bit for both) }
  275. { The EXTENDED format exists on the motorola FPU }
  276. { but it uses 96 bits instead of 80, with some }
  277. { unused bits within the number itself! Pretty }
  278. { complicated to support, so no support for the }
  279. { moment. }
  280. { s64 bit is considered as a real because all }
  281. { calculations are done by the fpu. }
  282. tfloattype = (f32bit,s32real,s64real,s80real,s64bit,f16bit);
  283. pfloatdef = ^tfloatdef;
  284. tfloatdef = object(tdef)
  285. typ : tfloattype;
  286. constructor init(t : tfloattype);
  287. constructor load;
  288. procedure write;virtual;
  289. {$ifdef GDB}
  290. function stabstring : pchar;virtual;
  291. {$endif GDB}
  292. procedure setsize;
  293. function is_publishable : boolean;virtual;
  294. procedure write_rtti_data;virtual;
  295. end;
  296. pabstractprocdef = ^tabstractprocdef;
  297. tabstractprocdef = object(tdef)
  298. { saves a definition to the return type }
  299. retdef : pdef;
  300. fpu_used : byte; { how many stack fpu must be empty }
  301. options : longint; { save the procedure options }
  302. para1 : pdefcoll;
  303. constructor init;
  304. constructor load;
  305. destructor done;virtual;
  306. procedure concatdef(p : pdef;vsp : tvarspez);
  307. procedure deref;virtual;
  308. function para_size : longint;
  309. function demangled_paras : string;
  310. {$ifdef GDB}
  311. function stabstring : pchar;virtual;
  312. procedure concatstabto(asmlist : paasmoutput);virtual;
  313. {$endif GDB}
  314. procedure test_if_fpu_result;
  315. procedure write;virtual;
  316. end;
  317. pprocvardef = ^tprocvardef;
  318. tprocvardef = object(tabstractprocdef)
  319. constructor init;
  320. constructor load;
  321. procedure write;virtual;
  322. function size : longint;virtual;
  323. {$ifdef GDB}
  324. function stabstring : pchar;virtual;
  325. procedure concatstabto(asmlist : paasmoutput); virtual;
  326. {$endif GDB}
  327. procedure write_child_rtti_data;virtual;
  328. function is_publishable : boolean;virtual;
  329. procedure write_rtti_data;virtual;
  330. end;
  331. tmessageinf = record
  332. case integer of
  333. 0 : (str : pchar);
  334. 1 : (i : longint);
  335. end;
  336. pprocdef = ^tprocdef;
  337. tprocdef = object(tabstractprocdef)
  338. extnumber : longint;
  339. messageinf : tmessageinf;
  340. nextoverloaded : pprocdef;
  341. { pointer to the local symbol table }
  342. localst : psymtable;
  343. { pointer to the parameter symbol table }
  344. parast : psymtable;
  345. { browser info }
  346. lastref,
  347. defref,
  348. lastwritten : pref;
  349. refcount : longint;
  350. _class : pobjectdef;
  351. _mangledname : pchar;
  352. { it's a tree, but this not easy to handle }
  353. { used for inlined procs }
  354. code : pointer;
  355. { true, if the procedure is only declared }
  356. { (forward procedure) }
  357. forwarddef : boolean;
  358. { check the problems of manglednames }
  359. count : boolean;
  360. is_used : boolean;
  361. { set which contains the modified registers }
  362. {$ifdef i386}
  363. usedregisters : byte;
  364. {$endif}
  365. {$ifdef m68k}
  366. usedregisters : word;
  367. {$endif}
  368. {$ifdef alpha}
  369. usedregisters_int : longint;
  370. usedregisters_fpu : longint;
  371. {$endif}
  372. constructor init;
  373. destructor done;virtual;
  374. constructor load;
  375. procedure write;virtual;
  376. {$ifdef GDB}
  377. function cplusplusmangledname : string;
  378. function stabstring : pchar;virtual;
  379. procedure concatstabto(asmlist : paasmoutput);virtual;
  380. {$endif GDB}
  381. procedure deref;virtual;
  382. function mangledname : string;
  383. procedure setmangledname(const s : string);
  384. procedure load_references;
  385. function write_references : boolean;
  386. {$ifdef BrowserLog}
  387. procedure add_to_browserlog;
  388. {$endif BrowserLog}
  389. end;
  390. tstringtype = (st_shortstring, st_longstring, st_ansistring, st_widestring);
  391. pstringdef = ^tstringdef;
  392. tstringdef = object(tdef)
  393. string_typ : tstringtype;
  394. len : longint;
  395. constructor shortinit(l : byte);
  396. constructor shortload;
  397. constructor longinit(l : longint);
  398. constructor longload;
  399. constructor ansiinit(l : longint);
  400. constructor ansiload;
  401. constructor wideinit(l : longint);
  402. constructor wideload;
  403. function size : longint;virtual;
  404. procedure write;virtual;
  405. {$ifdef GDB}
  406. function stabstring : pchar;virtual;
  407. procedure concatstabto(asmlist : paasmoutput);virtual;
  408. {$endif GDB}
  409. function needs_inittable : boolean;virtual;
  410. procedure write_rtti_data;virtual;
  411. function is_publishable : boolean;virtual;
  412. end;
  413. penumdef = ^tenumdef;
  414. tenumdef = object(tdef)
  415. rangenr,
  416. minval,
  417. maxval : longint;
  418. has_jumps : boolean;
  419. first : penumsym;
  420. basedef : penumdef;
  421. constructor init;
  422. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  423. constructor load;
  424. destructor done;virtual;
  425. procedure write;virtual;
  426. procedure deref;virtual;
  427. procedure calcsavesize;
  428. procedure setmax(_max:longint);
  429. procedure setmin(_min:longint);
  430. function min:longint;
  431. function max:longint;
  432. function getrangecheckstring:string;
  433. procedure genrangecheck;
  434. {$ifdef GDB}
  435. function stabstring : pchar;virtual;
  436. {$endif GDB}
  437. procedure write_child_rtti_data;virtual;
  438. procedure write_rtti_data;virtual;
  439. function is_publishable : boolean;virtual;
  440. end;
  441. tsettype = (normset,smallset,varset);
  442. psetdef = ^tsetdef;
  443. tsetdef = object(tdef)
  444. setof : pdef;
  445. settype : tsettype;
  446. constructor init(s : pdef;high : longint);
  447. constructor load;
  448. procedure write;virtual;
  449. {$ifdef GDB}
  450. function stabstring : pchar;virtual;
  451. procedure concatstabto(asmlist : paasmoutput);virtual;
  452. {$endif GDB}
  453. procedure deref;virtual;
  454. function is_publishable : boolean;virtual;
  455. procedure write_rtti_data;virtual;
  456. procedure write_child_rtti_data;virtual;
  457. end;
  458. {
  459. $Log$
  460. Revision 1.18 1999-03-02 18:24:21 peter
  461. * fixed overloading of array of char
  462. Revision 1.17 1999/03/01 13:45:06 pierre
  463. + added staticppusymtable symtable type for local browsing
  464. Revision 1.16 1999/02/22 20:13:39 florian
  465. + first implementation of message keyword
  466. Revision 1.15 1999/01/20 14:18:40 pierre
  467. * bugs related to mangledname solved
  468. - linux external without name
  469. -external procs already used
  470. (added count and is_used boolean fiels in tprocvar)
  471. Revision 1.14 1999/01/12 14:25:33 peter
  472. + BrowserLog for browser.log generation
  473. + BrowserCol for browser info in TCollections
  474. * released all other UseBrowser
  475. Revision 1.13 1998/12/30 22:15:53 peter
  476. + farpointer type
  477. * absolutesym now also stores if its far
  478. Revision 1.12 1998/12/10 09:47:28 florian
  479. + basic operations with int64/qord (compiler with -dint64)
  480. + rtti of enumerations extended: names are now written
  481. Revision 1.11 1998/11/29 21:45:49 florian
  482. * problem with arrays with init tables fixed
  483. Revision 1.10 1998/11/20 15:36:00 florian
  484. * problems with rtti fixed, hope it works
  485. Revision 1.9 1998/11/10 10:09:14 peter
  486. * va_list -> array of const
  487. Revision 1.8 1998/11/09 11:44:37 peter
  488. + va_list for printf support
  489. Revision 1.7 1998/11/05 12:02:59 peter
  490. * released useansistring
  491. * removed -Sv, its now available in fpc modes
  492. Revision 1.6 1998/10/22 17:11:23 pierre
  493. + terminated the include exclude implementation for i386
  494. * enums inside records fixed
  495. Revision 1.5 1998/10/16 13:12:55 pierre
  496. * added vmt_offsets in destructors code also !!!
  497. * vmt_offset code for m68k
  498. Revision 1.4 1998/10/16 08:51:52 peter
  499. + target_os.stackalignment
  500. + stack can be aligned at 2 or 4 byte boundaries
  501. Revision 1.3 1998/10/05 21:33:30 peter
  502. * fixed 161,165,166,167,168
  503. Revision 1.2 1998/10/02 07:20:40 florian
  504. * range checking in units doesn't work if the units are smartlinked, fixed
  505. Revision 1.1 1998/09/23 12:03:57 peter
  506. * overloading fix for array of const
  507. }