symdefh.inc 21 KB

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