symdefh.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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,forwarddef);
  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. function is_intregable : boolean;
  80. function is_fpuregable : boolean;
  81. private
  82. savesize : longint;
  83. end;
  84. targconvtyp = (act_convertable,act_equal,act_exact);
  85. tvarspez = (vs_value,vs_const,vs_var);
  86. pparaitem = ^tparaitem;
  87. tparaitem = object(tlinkedlist_item)
  88. data : pdef;
  89. datasym : ptypesym;
  90. paratyp : tvarspez;
  91. argconvtyp : targconvtyp;
  92. convertlevel : byte;
  93. register : tregister;
  94. end;
  95. tfiletype = (ft_text,ft_typed,ft_untyped);
  96. pfiledef = ^tfiledef;
  97. tfiledef = object(tdef)
  98. filetype : tfiletype;
  99. typed_as : pdef;
  100. constructor init(ft : tfiletype;tas : pdef);
  101. constructor load;
  102. procedure write;virtual;
  103. procedure deref;virtual;
  104. function gettypename:string;virtual;
  105. procedure setsize;
  106. { debug }
  107. {$ifdef GDB}
  108. function stabstring : pchar;virtual;
  109. procedure concatstabto(asmlist : paasmoutput);virtual;
  110. {$endif GDB}
  111. end;
  112. pformaldef = ^tformaldef;
  113. tformaldef = object(tdef)
  114. constructor init;
  115. constructor load;
  116. procedure write;virtual;
  117. function gettypename:string;virtual;
  118. {$ifdef GDB}
  119. function stabstring : pchar;virtual;
  120. procedure concatstabto(asmlist : paasmoutput);virtual;
  121. {$endif GDB}
  122. end;
  123. pforwarddef = ^tforwarddef;
  124. tforwarddef = object(tdef)
  125. tosymname : string;
  126. constructor init(const s:string);
  127. function gettypename:string;virtual;
  128. end;
  129. perrordef = ^terrordef;
  130. terrordef = object(tdef)
  131. constructor init;
  132. function gettypename:string;virtual;
  133. { debug }
  134. {$ifdef GDB}
  135. function stabstring : pchar;virtual;
  136. {$endif GDB}
  137. end;
  138. { tpointerdef and tclassrefdef should get a common
  139. base class, but I derived tclassrefdef from tpointerdef
  140. to avoid problems with bugs (FK)
  141. }
  142. ppointerdef = ^tpointerdef;
  143. tpointerdef = object(tdef)
  144. definition : pdef;
  145. defsym : ptypesym;
  146. is_far : boolean;
  147. constructor init(def : pdef);
  148. constructor initfar(def : pdef);
  149. constructor load;
  150. destructor done;virtual;
  151. procedure write;virtual;
  152. procedure deref;virtual;
  153. function gettypename:string;virtual;
  154. { debug }
  155. {$ifdef GDB}
  156. function stabstring : pchar;virtual;
  157. procedure concatstabto(asmlist : paasmoutput);virtual;
  158. {$endif GDB}
  159. end;
  160. pobjectdef = ^tobjectdef;
  161. tobjectdef = object(tdef)
  162. childof : pobjectdef;
  163. objname : pstring;
  164. symtable : psymtable;
  165. objectoptions : tobjectoptions;
  166. { to be able to have a variable vmt position }
  167. { and no vmt field for objects without virtuals }
  168. vmt_offset : longint;
  169. constructor init(const n : string;c : pobjectdef);
  170. constructor load;
  171. destructor done;virtual;
  172. procedure write;virtual;
  173. procedure deref;virtual;
  174. function size : longint;virtual;
  175. function alignment:longint;virtual;
  176. function vmtmethodoffset(index:longint):longint;
  177. function is_publishable : boolean;virtual;
  178. function vmt_mangledname : string;
  179. function rtti_name : string;
  180. procedure check_forwards;
  181. function is_related(d : pobjectdef) : boolean;
  182. function is_class : boolean;
  183. function next_free_name_index : longint;
  184. procedure insertvmt;
  185. procedure set_parent(c : pobjectdef);
  186. { debug }
  187. {$ifdef GDB}
  188. function stabstring : pchar;virtual;
  189. {$endif GDB}
  190. { init/final }
  191. function needs_inittable : boolean;virtual;
  192. procedure write_init_data;virtual;
  193. procedure write_child_init_data;virtual;
  194. { rtti }
  195. function get_rtti_label : string;virtual;
  196. procedure generate_rtti;virtual;
  197. procedure write_rtti_data;virtual;
  198. procedure write_child_rtti_data;virtual;
  199. end;
  200. pclassrefdef = ^tclassrefdef;
  201. tclassrefdef = object(tpointerdef)
  202. constructor init(def : pdef);
  203. constructor load;
  204. procedure write;virtual;
  205. function gettypename:string;virtual;
  206. { debug }
  207. {$ifdef GDB}
  208. function stabstring : pchar;virtual;
  209. procedure concatstabto(asmlist : paasmoutput);virtual;
  210. {$endif GDB}
  211. end;
  212. parraydef = ^tarraydef;
  213. tarraydef = object(tdef)
  214. private
  215. rangenr : longint;
  216. public
  217. lowrange,
  218. highrange : longint;
  219. definition : pdef;
  220. rangedef : pdef;
  221. IsVariant,
  222. IsConstructor,
  223. IsArrayOfConst : boolean;
  224. function gettypename:string;virtual;
  225. function elesize : longint;
  226. constructor init(l,h : longint;rd : pdef);
  227. constructor load;
  228. procedure write;virtual;
  229. {$ifdef GDB}
  230. function stabstring : pchar;virtual;
  231. procedure concatstabto(asmlist : paasmoutput);virtual;
  232. {$endif GDB}
  233. procedure deref;virtual;
  234. function size : longint;virtual;
  235. function alignment : longint;virtual;
  236. { generates the ranges needed by the asm instruction BOUND (i386)
  237. or CMP2 (Motorola) }
  238. procedure genrangecheck;
  239. { returns the label of the range check string }
  240. function getrangecheckstring : string;
  241. function needs_inittable : boolean;virtual;
  242. procedure write_rtti_data;virtual;
  243. procedure write_child_rtti_data;virtual;
  244. end;
  245. precorddef = ^trecorddef;
  246. trecorddef = object(tdef)
  247. symtable : psymtable;
  248. constructor init(p : psymtable);
  249. constructor load;
  250. destructor done;virtual;
  251. procedure write;virtual;
  252. procedure deref;virtual;
  253. function size:longint;virtual;
  254. function alignment : longint;virtual;
  255. function gettypename:string;virtual;
  256. { debug }
  257. {$ifdef GDB}
  258. function stabstring : pchar;virtual;
  259. procedure concatstabto(asmlist : paasmoutput);virtual;
  260. {$endif GDB}
  261. { init/final }
  262. procedure write_init_data;virtual;
  263. procedure write_child_init_data;virtual;
  264. function needs_inittable : boolean;virtual;
  265. { rtti }
  266. procedure write_rtti_data;virtual;
  267. procedure write_child_rtti_data;virtual;
  268. end;
  269. porddef = ^torddef;
  270. torddef = object(tdef)
  271. low,high : longint;
  272. rangenr : 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. retdef : pdef;
  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 concatdef(p : pdef;vsp : tvarspez);
  323. procedure concattypesym(p : ptypesym;vsp : tvarspez);
  324. function para_size : longint;
  325. function demangled_paras : string;
  326. function proccalloption2str : string;
  327. procedure test_if_fpu_result;
  328. { debug }
  329. {$ifdef GDB}
  330. function stabstring : pchar;virtual;
  331. procedure concatstabto(asmlist : paasmoutput);virtual;
  332. {$endif GDB}
  333. end;
  334. pprocvardef = ^tprocvardef;
  335. tprocvardef = object(tabstractprocdef)
  336. constructor init;
  337. constructor load;
  338. procedure write;virtual;
  339. function size : longint;virtual;
  340. function gettypename:string;virtual;
  341. function is_publishable : boolean;virtual;
  342. { debug }
  343. {$ifdef GDB}
  344. function stabstring : pchar;virtual;
  345. procedure concatstabto(asmlist : paasmoutput); virtual;
  346. {$endif GDB}
  347. { rtti }
  348. procedure write_child_rtti_data;virtual;
  349. procedure write_rtti_data;virtual;
  350. end;
  351. tmessageinf = record
  352. case integer of
  353. 0 : (str : pchar);
  354. 1 : (i : longint);
  355. end;
  356. pprocdef = ^tprocdef;
  357. tprocdef = object(tabstractprocdef)
  358. private
  359. _mangledname : pchar;
  360. public
  361. extnumber : longint;
  362. messageinf : tmessageinf;
  363. nextoverloaded : pprocdef;
  364. { where is this function defined, needed here because there
  365. is only one symbol for all overloaded functions }
  366. fileinfo : tfileposinfo;
  367. { pointer to the local symbol table }
  368. localst : psymtable;
  369. { pointer to the parameter symbol table }
  370. parast : psymtable;
  371. { symbol owning this definition }
  372. procsym : pprocsym;
  373. { browser info }
  374. lastref,
  375. defref,
  376. crossref,
  377. lastwritten : pref;
  378. refcount : longint;
  379. _class : pobjectdef;
  380. { it's a tree, but this not easy to handle }
  381. { used for inlined procs }
  382. code : pointer;
  383. { true, if the procedure is only declared }
  384. { (forward procedure) }
  385. forwarddef,
  386. { true if the procedure is declared in the interface }
  387. interfacedef : boolean;
  388. { check the problems of manglednames }
  389. count : boolean;
  390. is_used : boolean;
  391. { small set which contains the modified registers }
  392. {$ifdef newcg}
  393. usedregisters : tregisterset;
  394. {$else newcg}
  395. usedregisters : longint;
  396. {$endif newcg}
  397. constructor init;
  398. constructor load;
  399. destructor done;virtual;
  400. procedure write;virtual;
  401. procedure deref;virtual;
  402. function haspara:boolean;
  403. function mangledname : string;
  404. procedure setmangledname(const s : string);
  405. procedure load_references;
  406. function write_references : boolean;
  407. function procname: string;
  408. { debug }
  409. {$ifdef GDB}
  410. function cplusplusmangledname : string;
  411. function stabstring : pchar;virtual;
  412. procedure concatstabto(asmlist : paasmoutput);virtual;
  413. {$endif GDB}
  414. { browser }
  415. {$ifdef BrowserLog}
  416. procedure add_to_browserlog;
  417. {$endif BrowserLog}
  418. end;
  419. pstringdef = ^tstringdef;
  420. tstringdef = object(tdef)
  421. string_typ : tstringtype;
  422. len : longint;
  423. constructor shortinit(l : byte);
  424. constructor shortload;
  425. constructor longinit(l : longint);
  426. constructor longload;
  427. constructor ansiinit(l : longint);
  428. constructor ansiload;
  429. constructor wideinit(l : longint);
  430. constructor wideload;
  431. function stringtypname:string;
  432. function size : longint;virtual;
  433. procedure write;virtual;
  434. function gettypename:string;virtual;
  435. function is_publishable : boolean;virtual;
  436. { debug }
  437. {$ifdef GDB}
  438. function stabstring : pchar;virtual;
  439. procedure concatstabto(asmlist : paasmoutput);virtual;
  440. {$endif GDB}
  441. { init/final }
  442. function needs_inittable : boolean;virtual;
  443. { rtti }
  444. procedure write_rtti_data;virtual;
  445. end;
  446. penumdef = ^tenumdef;
  447. tenumdef = object(tdef)
  448. rangenr,
  449. minval,
  450. maxval : longint;
  451. has_jumps : boolean;
  452. firstenum : penumsym;
  453. basedef : penumdef;
  454. constructor init;
  455. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  456. constructor load;
  457. destructor done;virtual;
  458. procedure write;virtual;
  459. procedure deref;virtual;
  460. function gettypename:string;virtual;
  461. function is_publishable : boolean;virtual;
  462. procedure calcsavesize;
  463. procedure setmax(_max:longint);
  464. procedure setmin(_min:longint);
  465. function min:longint;
  466. function max:longint;
  467. function getrangecheckstring:string;
  468. procedure genrangecheck;
  469. { debug }
  470. {$ifdef GDB}
  471. function stabstring : pchar;virtual;
  472. {$endif GDB}
  473. { rtti }
  474. procedure write_child_rtti_data;virtual;
  475. procedure write_rtti_data;virtual;
  476. end;
  477. psetdef = ^tsetdef;
  478. tsetdef = object(tdef)
  479. setof : pdef;
  480. settype : tsettype;
  481. constructor init(s : pdef;high : longint);
  482. constructor load;
  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.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. }