symdefh.inc 21 KB

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