symdefh.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. function typename:string;
  41. procedure write;virtual;
  42. function size:longint;virtual;
  43. function alignment:longint;virtual;
  44. function gettypename:string;virtual;
  45. function is_publishable : boolean;virtual;
  46. function is_in_current : boolean;
  47. procedure correct_owner_symtable; { registers enumdef inside objects or
  48. record directly in the owner symtable !! }
  49. { debug }
  50. {$ifdef GDB}
  51. function stabstring : pchar;virtual;
  52. procedure concatstabto(asmlist : paasmoutput);virtual;
  53. function NumberString:string;
  54. procedure set_globalnb;
  55. function allstabstring : pchar;
  56. {$endif GDB}
  57. { init. tables }
  58. function needs_inittable : boolean;virtual;
  59. procedure generate_inittable;
  60. function get_inittable_label : pasmlabel;
  61. { the default implemenation calls write_rtti_data }
  62. { if init and rtti data is different these procedures }
  63. { must be overloaded }
  64. procedure write_init_data;virtual;
  65. procedure write_child_init_data;virtual;
  66. { rtti }
  67. procedure write_rtti_name;
  68. function get_rtti_label : string;virtual;
  69. procedure generate_rtti;virtual;
  70. procedure write_rtti_data;virtual;
  71. procedure write_child_rtti_data;virtual;
  72. function is_intregable : boolean;
  73. function is_fpuregable : boolean;
  74. private
  75. savesize : longint;
  76. end;
  77. targconvtyp = (act_convertable,act_equal,act_exact);
  78. tvarspez = (vs_value,vs_const,vs_var);
  79. pparaitem = ^tparaitem;
  80. tparaitem = object(tlinkedlist_item)
  81. paratype : ttype;
  82. paratyp : tvarspez;
  83. argconvtyp : targconvtyp;
  84. convertlevel : byte;
  85. register : tregister;
  86. end;
  87. tfiletyp = (ft_text,ft_typed,ft_untyped);
  88. pfiledef = ^tfiledef;
  89. tfiledef = object(tdef)
  90. filetyp : tfiletyp;
  91. typedfiletype : ttype;
  92. constructor inittext;
  93. constructor inituntyped;
  94. constructor inittyped(const tt : ttype);
  95. constructor inittypeddef(p : 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. pointertype : ttype;
  141. is_far : boolean;
  142. constructor init(const tt : ttype);
  143. constructor initfar(const tt : ttype);
  144. constructor initdef(p : pdef);
  145. constructor initfardef(p : pdef);
  146. constructor load;
  147. destructor done;virtual;
  148. procedure write;virtual;
  149. procedure deref;virtual;
  150. function gettypename:string;virtual;
  151. { debug }
  152. {$ifdef GDB}
  153. function stabstring : pchar;virtual;
  154. procedure concatstabto(asmlist : paasmoutput);virtual;
  155. {$endif GDB}
  156. end;
  157. pprocdef = ^tprocdef;
  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. function searchdestructor : pprocdef;
  185. { debug }
  186. {$ifdef GDB}
  187. function stabstring : pchar;virtual;
  188. {$endif GDB}
  189. { init/final }
  190. function needs_inittable : boolean;virtual;
  191. procedure write_init_data;virtual;
  192. procedure write_child_init_data;virtual;
  193. { rtti }
  194. function get_rtti_label : string;virtual;
  195. procedure generate_rtti;virtual;
  196. procedure write_rtti_data;virtual;
  197. procedure write_child_rtti_data;virtual;
  198. end;
  199. pclassrefdef = ^tclassrefdef;
  200. tclassrefdef = object(tpointerdef)
  201. constructor init(def : pdef);
  202. constructor load;
  203. procedure write;virtual;
  204. function gettypename:string;virtual;
  205. { debug }
  206. {$ifdef GDB}
  207. function stabstring : pchar;virtual;
  208. procedure concatstabto(asmlist : paasmoutput);virtual;
  209. {$endif GDB}
  210. end;
  211. parraydef = ^tarraydef;
  212. tarraydef = object(tdef)
  213. private
  214. rangenr : longint;
  215. public
  216. lowrange,
  217. highrange : longint;
  218. elementtype,
  219. rangetype : ttype;
  220. IsVariant,
  221. IsConstructor,
  222. IsArrayOfConst : boolean;
  223. function gettypename:string;virtual;
  224. function elesize : longint;
  225. constructor init(l,h : longint;rd : pdef);
  226. constructor load;
  227. procedure write;virtual;
  228. {$ifdef GDB}
  229. function stabstring : pchar;virtual;
  230. procedure concatstabto(asmlist : paasmoutput);virtual;
  231. {$endif GDB}
  232. procedure deref;virtual;
  233. function size : longint;virtual;
  234. function alignment : longint;virtual;
  235. { generates the ranges needed by the asm instruction BOUND (i386)
  236. or CMP2 (Motorola) }
  237. procedure genrangecheck;
  238. { returns the label of the range check string }
  239. function getrangecheckstring : string;
  240. function needs_inittable : boolean;virtual;
  241. procedure write_rtti_data;virtual;
  242. procedure write_child_rtti_data;virtual;
  243. end;
  244. precorddef = ^trecorddef;
  245. trecorddef = object(tdef)
  246. symtable : psymtable;
  247. constructor init(p : psymtable);
  248. constructor load;
  249. destructor done;virtual;
  250. procedure write;virtual;
  251. procedure deref;virtual;
  252. function size:longint;virtual;
  253. function alignment : longint;virtual;
  254. function gettypename:string;virtual;
  255. { debug }
  256. {$ifdef GDB}
  257. function stabstring : pchar;virtual;
  258. procedure concatstabto(asmlist : paasmoutput);virtual;
  259. {$endif GDB}
  260. { init/final }
  261. procedure write_init_data;virtual;
  262. procedure write_child_init_data;virtual;
  263. function needs_inittable : boolean;virtual;
  264. { rtti }
  265. procedure write_rtti_data;virtual;
  266. procedure write_child_rtti_data;virtual;
  267. end;
  268. porddef = ^torddef;
  269. torddef = object(tdef)
  270. private
  271. rangenr : longint;
  272. public
  273. low,high : 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. rettype : ttype;
  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 concatpara(tt:ttype;vsp : tvarspez);
  324. function para_size(alignsize:longint) : 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. 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.53 2000-02-09 13:23:04 peter
  499. * log truncated
  500. Revision 1.52 2000/02/04 20:00:22 florian
  501. * an exception in a construcor calls now the destructor (this applies only
  502. to classes)
  503. Revision 1.51 2000/01/26 12:02:30 peter
  504. * abstractprocdef.para_size needs alignment parameter
  505. * secondcallparan gets para_alignment size instead of dword_align
  506. Revision 1.50 2000/01/07 01:14:40 peter
  507. * updated copyright to 2000
  508. Revision 1.49 2000/01/03 19:26:04 peter
  509. * fixed resolving of ttypesym which are reference from object/record
  510. fields.
  511. Revision 1.48 1999/11/30 10:40:55 peter
  512. + ttype, tsymlist
  513. Revision 1.47 1999/11/17 17:05:04 pierre
  514. * Notes/hints changes
  515. Revision 1.46 1999/11/09 23:35:50 pierre
  516. + better reference pos for forward defs
  517. Revision 1.45 1999/11/06 14:34:27 peter
  518. * truncated log to 20 revs
  519. Revision 1.44 1999/10/26 12:30:45 peter
  520. * const parameter is now checked
  521. * better and generic check if a node can be used for assigning
  522. * export fixes
  523. * procvar equal works now (it never had worked at least from 0.99.8)
  524. * defcoll changed to linkedlist with pparaitem so it can easily be
  525. walked both directions
  526. Revision 1.43 1999/10/01 10:05:44 peter
  527. + procedure directive support in const declarations, fixes bug 232
  528. Revision 1.42 1999/10/01 08:02:48 peter
  529. * forward type declaration rewritten
  530. Revision 1.41 1999/08/10 12:34:49 pierre
  531. + procsym field in tprocdef to allow correct gdb info generation
  532. Revision 1.40 1999/08/09 22:19:57 peter
  533. * classes vmt changed to only positive addresses
  534. * sharedlib creation is working
  535. Revision 1.39 1999/08/07 14:21:02 florian
  536. * some small problems fixed
  537. Revision 1.38 1999/08/05 16:53:15 peter
  538. * V_Fatal=1, all other V_ are also increased
  539. * Check for local procedure when assigning procvar
  540. * fixed comment parsing because directives
  541. * oldtp mode directives better supported
  542. * added some messages to errore.msg
  543. Revision 1.37 1999/08/03 22:03:16 peter
  544. * moved bitmask constants to sets
  545. * some other type/const renamings
  546. Revision 1.36 1999/08/02 21:29:04 florian
  547. * the main branch psub.pas is now used for
  548. newcg compiler
  549. Revision 1.35 1999/07/27 23:42:20 peter
  550. * indirect type referencing is now allowed
  551. Revision 1.34 1999/07/23 16:05:30 peter
  552. * alignment is now saved in the symtable
  553. * C alignment added for records
  554. * PPU version increased to solve .12 <-> .13 probs
  555. }