symdefh.inc 21 KB

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