symdefh.inc 22 KB

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