symdefh.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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 : tdefstabstatus;
  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;virtual;
  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,vs_out);
  79. pparaitem = ^tparaitem;
  80. tparaitem = object(tlinkedlist_item)
  81. paratype : ttype;
  82. paratyp : tvarspez;
  83. argconvtyp : targconvtyp;
  84. convertlevel : byte;
  85. register : tregister;
  86. defaultvalue : psym; { pconstsym }
  87. end;
  88. { this is only here to override the count method,
  89. which can't be used }
  90. pparalinkedlist = ^tparalinkedlist;
  91. tparalinkedlist = object(tlinkedlist)
  92. function count:longint;
  93. end;
  94. tfiletyp = (ft_text,ft_typed,ft_untyped);
  95. pfiledef = ^tfiledef;
  96. tfiledef = object(tdef)
  97. filetyp : tfiletyp;
  98. typedfiletype : ttype;
  99. constructor inittext;
  100. constructor inituntyped;
  101. constructor inittyped(const tt : ttype);
  102. constructor inittypeddef(p : pdef);
  103. constructor load;
  104. procedure write;virtual;
  105. procedure deref;virtual;
  106. function gettypename:string;virtual;
  107. procedure setsize;
  108. { debug }
  109. {$ifdef GDB}
  110. function stabstring : pchar;virtual;
  111. procedure concatstabto(asmlist : paasmoutput);virtual;
  112. {$endif GDB}
  113. end;
  114. pformaldef = ^tformaldef;
  115. tformaldef = object(tdef)
  116. constructor init;
  117. constructor load;
  118. procedure write;virtual;
  119. function gettypename:string;virtual;
  120. {$ifdef GDB}
  121. function stabstring : pchar;virtual;
  122. procedure concatstabto(asmlist : paasmoutput);virtual;
  123. {$endif GDB}
  124. end;
  125. pforwarddef = ^tforwarddef;
  126. tforwarddef = object(tdef)
  127. tosymname : string;
  128. forwardpos : tfileposinfo;
  129. constructor init(const s:string;const pos : tfileposinfo);
  130. function gettypename:string;virtual;
  131. end;
  132. perrordef = ^terrordef;
  133. terrordef = object(tdef)
  134. constructor init;
  135. function gettypename:string;virtual;
  136. { debug }
  137. {$ifdef GDB}
  138. function stabstring : pchar;virtual;
  139. {$endif GDB}
  140. end;
  141. { tpointerdef and tclassrefdef should get a common
  142. base class, but I derived tclassrefdef from tpointerdef
  143. to avoid problems with bugs (FK)
  144. }
  145. ppointerdef = ^tpointerdef;
  146. tpointerdef = object(tdef)
  147. pointertype : ttype;
  148. is_far : boolean;
  149. constructor init(const tt : ttype);
  150. constructor initfar(const tt : ttype);
  151. constructor initdef(p : pdef);
  152. constructor initfardef(p : pdef);
  153. constructor load;
  154. destructor done;virtual;
  155. procedure write;virtual;
  156. procedure deref;virtual;
  157. function gettypename:string;virtual;
  158. { debug }
  159. {$ifdef GDB}
  160. function stabstring : pchar;virtual;
  161. procedure concatstabto(asmlist : paasmoutput);virtual;
  162. {$endif GDB}
  163. end;
  164. pprocdef = ^tprocdef;
  165. pobjectdef = ^tobjectdef;
  166. tobjectdef = object(tdef)
  167. childof : pobjectdef;
  168. objname : pstring;
  169. symtable : psymtable;
  170. objectoptions : tobjectoptions;
  171. { to be able to have a variable vmt position }
  172. { and no vmt field for objects without virtuals }
  173. vmt_offset : longint;
  174. {$ifdef GDB}
  175. writing_stabs : boolean;
  176. {$endif GDB}
  177. constructor init(const n : string;c : pobjectdef);
  178. constructor load;
  179. destructor done;virtual;
  180. procedure write;virtual;
  181. procedure deref;virtual;
  182. function size : longint;virtual;
  183. function alignment:longint;virtual;
  184. function vmtmethodoffset(index:longint):longint;
  185. function is_publishable : boolean;virtual;
  186. function vmt_mangledname : string;
  187. function rtti_name : string;
  188. procedure check_forwards;
  189. function is_related(d : pobjectdef) : boolean;
  190. function is_class : boolean;
  191. function is_interface : boolean;
  192. function is_cppclass : boolean;
  193. function is_object : boolean;
  194. function next_free_name_index : longint;
  195. procedure insertvmt;
  196. procedure set_parent(c : pobjectdef);
  197. function searchdestructor : pprocdef;
  198. { debug }
  199. {$ifdef GDB}
  200. function stabstring : pchar;virtual;
  201. procedure set_globalnb;virtual;
  202. function classnumberstring : string;
  203. procedure concatstabto(asmlist : paasmoutput);virtual;
  204. {$endif GDB}
  205. { init/final }
  206. function needs_inittable : boolean;virtual;
  207. procedure write_init_data;virtual;
  208. procedure write_child_init_data;virtual;
  209. { rtti }
  210. function get_rtti_label : string;virtual;
  211. procedure generate_rtti;virtual;
  212. procedure write_rtti_data;virtual;
  213. procedure write_child_rtti_data;virtual;
  214. function generate_field_table : pasmlabel;
  215. end;
  216. pclassrefdef = ^tclassrefdef;
  217. tclassrefdef = object(tpointerdef)
  218. constructor init(def : pdef);
  219. constructor load;
  220. procedure write;virtual;
  221. function gettypename:string;virtual;
  222. { debug }
  223. {$ifdef GDB}
  224. function stabstring : pchar;virtual;
  225. procedure concatstabto(asmlist : paasmoutput);virtual;
  226. {$endif GDB}
  227. end;
  228. parraydef = ^tarraydef;
  229. tarraydef = object(tdef)
  230. private
  231. rangenr : longint;
  232. public
  233. lowrange,
  234. highrange : longint;
  235. elementtype,
  236. rangetype : ttype;
  237. IsVariant,
  238. IsConstructor,
  239. IsArrayOfConst : boolean;
  240. function gettypename:string;virtual;
  241. function elesize : longint;
  242. constructor init(l,h : longint;rd : pdef);
  243. constructor load;
  244. procedure write;virtual;
  245. {$ifdef GDB}
  246. function stabstring : pchar;virtual;
  247. procedure concatstabto(asmlist : paasmoutput);virtual;
  248. {$endif GDB}
  249. procedure deref;virtual;
  250. function size : longint;virtual;
  251. function alignment : longint;virtual;
  252. { generates the ranges needed by the asm instruction BOUND (i386)
  253. or CMP2 (Motorola) }
  254. procedure genrangecheck;
  255. { returns the label of the range check string }
  256. function getrangecheckstring : string;
  257. function needs_inittable : boolean;virtual;
  258. procedure write_rtti_data;virtual;
  259. procedure write_child_rtti_data;virtual;
  260. end;
  261. precorddef = ^trecorddef;
  262. trecorddef = object(tdef)
  263. symtable : psymtable;
  264. constructor init(p : psymtable);
  265. constructor load;
  266. destructor done;virtual;
  267. procedure write;virtual;
  268. procedure deref;virtual;
  269. function size:longint;virtual;
  270. function alignment : longint;virtual;
  271. function gettypename:string;virtual;
  272. { debug }
  273. {$ifdef GDB}
  274. function stabstring : pchar;virtual;
  275. procedure concatstabto(asmlist : paasmoutput);virtual;
  276. {$endif GDB}
  277. { init/final }
  278. procedure write_init_data;virtual;
  279. procedure write_child_init_data;virtual;
  280. function needs_inittable : boolean;virtual;
  281. { rtti }
  282. procedure write_rtti_data;virtual;
  283. procedure write_child_rtti_data;virtual;
  284. end;
  285. porddef = ^torddef;
  286. torddef = object(tdef)
  287. private
  288. rangenr : longint;
  289. public
  290. low,high : longint;
  291. typ : tbasetype;
  292. constructor init(t : tbasetype;v,b : longint);
  293. constructor load;
  294. procedure write;virtual;
  295. function is_publishable : boolean;virtual;
  296. function gettypename:string;virtual;
  297. procedure setsize;
  298. { generates the ranges needed by the asm instruction BOUND }
  299. { or CMP2 (Motorola) }
  300. procedure genrangecheck;
  301. function getrangecheckstring : string;
  302. { debug }
  303. {$ifdef GDB}
  304. function stabstring : pchar;virtual;
  305. {$endif GDB}
  306. { rtti }
  307. procedure write_rtti_data;virtual;
  308. end;
  309. pfloatdef = ^tfloatdef;
  310. tfloatdef = object(tdef)
  311. typ : tfloattype;
  312. constructor init(t : tfloattype);
  313. constructor load;
  314. procedure write;virtual;
  315. function gettypename:string;virtual;
  316. function is_publishable : boolean;virtual;
  317. procedure setsize;
  318. { debug }
  319. {$ifdef GDB}
  320. function stabstring : pchar;virtual;
  321. {$endif GDB}
  322. { rtti }
  323. procedure write_rtti_data;virtual;
  324. end;
  325. pabstractprocdef = ^tabstractprocdef;
  326. tabstractprocdef = object(tdef)
  327. { saves a definition to the return type }
  328. rettype : ttype;
  329. proctypeoption : tproctypeoption;
  330. proccalloptions : tproccalloptions;
  331. procoptions : tprocoptions;
  332. para : pparalinkedlist;
  333. maxparacount,
  334. minparacount : longint;
  335. symtablelevel : byte;
  336. fpu_used : byte; { how many stack fpu must be empty }
  337. constructor init;
  338. constructor load;
  339. destructor done;virtual;
  340. procedure write;virtual;
  341. procedure deref;virtual;
  342. procedure concatpara(tt:ttype;vsp : tvarspez;defval:psym);
  343. function para_size(alignsize:longint) : longint;
  344. function demangled_paras : string;
  345. function proccalloption2str : string;
  346. procedure test_if_fpu_result;
  347. { debug }
  348. {$ifdef GDB}
  349. function stabstring : pchar;virtual;
  350. procedure concatstabto(asmlist : paasmoutput);virtual;
  351. {$endif GDB}
  352. end;
  353. pprocvardef = ^tprocvardef;
  354. tprocvardef = object(tabstractprocdef)
  355. constructor init;
  356. constructor load;
  357. procedure write;virtual;
  358. function size : longint;virtual;
  359. function gettypename:string;virtual;
  360. function is_publishable : boolean;virtual;
  361. { debug }
  362. {$ifdef GDB}
  363. function stabstring : pchar;virtual;
  364. procedure concatstabto(asmlist : paasmoutput); virtual;
  365. {$endif GDB}
  366. { rtti }
  367. procedure write_child_rtti_data;virtual;
  368. procedure write_rtti_data;virtual;
  369. end;
  370. tmessageinf = record
  371. case integer of
  372. 0 : (str : pchar);
  373. 1 : (i : longint);
  374. end;
  375. tprocdef = object(tabstractprocdef)
  376. private
  377. _mangledname : pstring;
  378. public
  379. extnumber : longint;
  380. messageinf : tmessageinf;
  381. nextoverloaded : pprocdef;
  382. { where is this function defined, needed here because there
  383. is only one symbol for all overloaded functions }
  384. fileinfo : tfileposinfo;
  385. { pointer to the local symbol table }
  386. localst : psymtable;
  387. { pointer to the parameter symbol table }
  388. parast : psymtable;
  389. { symbol owning this definition }
  390. procsym : pprocsym;
  391. { browser info }
  392. lastref,
  393. defref,
  394. crossref,
  395. lastwritten : pref;
  396. refcount : longint;
  397. _class : pobjectdef;
  398. { it's a tree, but this not easy to handle }
  399. { used for inlined procs }
  400. code : pointer;
  401. { info about register variables (JM) }
  402. regvarinfo: pointer;
  403. { true, if the procedure is only declared }
  404. { (forward procedure) }
  405. forwarddef,
  406. { true if the procedure is declared in the interface }
  407. interfacedef : boolean;
  408. { true if the procedure has a forward declaration }
  409. hasforward : boolean;
  410. { check the problems of manglednames }
  411. count : boolean;
  412. is_used : boolean;
  413. { small set which contains the modified registers }
  414. {$ifdef newcg}
  415. usedregisters : tregisterset;
  416. {$else newcg}
  417. usedregisters : longint;
  418. {$endif newcg}
  419. constructor init;
  420. constructor load;
  421. destructor done;virtual;
  422. procedure write;virtual;
  423. procedure deref;virtual;
  424. function haspara:boolean;
  425. function mangledname : string;
  426. procedure setmangledname(const s : string);
  427. procedure load_references;
  428. function write_references : boolean;
  429. function procname: string;
  430. { debug }
  431. {$ifdef GDB}
  432. function cplusplusmangledname : string;
  433. function stabstring : pchar;virtual;
  434. procedure concatstabto(asmlist : paasmoutput);virtual;
  435. {$endif GDB}
  436. { browser }
  437. {$ifdef BrowserLog}
  438. procedure add_to_browserlog;
  439. {$endif BrowserLog}
  440. end;
  441. pstringdef = ^tstringdef;
  442. tstringdef = object(tdef)
  443. string_typ : tstringtype;
  444. len : longint;
  445. constructor shortinit(l : byte);
  446. constructor shortload;
  447. constructor longinit(l : longint);
  448. constructor longload;
  449. constructor ansiinit(l : longint);
  450. constructor ansiload;
  451. constructor wideinit(l : longint);
  452. constructor wideload;
  453. function stringtypname:string;
  454. function size : longint;virtual;
  455. procedure write;virtual;
  456. function gettypename:string;virtual;
  457. function is_publishable : boolean;virtual;
  458. { debug }
  459. {$ifdef GDB}
  460. function stabstring : pchar;virtual;
  461. procedure concatstabto(asmlist : paasmoutput);virtual;
  462. {$endif GDB}
  463. { init/final }
  464. function needs_inittable : boolean;virtual;
  465. { rtti }
  466. procedure write_rtti_data;virtual;
  467. end;
  468. penumdef = ^tenumdef;
  469. tenumdef = object(tdef)
  470. rangenr,
  471. minval,
  472. maxval : longint;
  473. has_jumps : boolean;
  474. firstenum : penumsym;
  475. basedef : penumdef;
  476. constructor init;
  477. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  478. constructor load;
  479. destructor done;virtual;
  480. procedure write;virtual;
  481. procedure deref;virtual;
  482. function gettypename:string;virtual;
  483. function is_publishable : boolean;virtual;
  484. procedure calcsavesize;
  485. procedure setmax(_max:longint);
  486. procedure setmin(_min:longint);
  487. function min:longint;
  488. function max:longint;
  489. function getrangecheckstring:string;
  490. procedure genrangecheck;
  491. { debug }
  492. {$ifdef GDB}
  493. function stabstring : pchar;virtual;
  494. {$endif GDB}
  495. { rtti }
  496. procedure write_child_rtti_data;virtual;
  497. procedure write_rtti_data;virtual;
  498. end;
  499. psetdef = ^tsetdef;
  500. tsetdef = object(tdef)
  501. elementtype : ttype;
  502. settype : tsettype;
  503. constructor init(s : pdef;high : longint);
  504. constructor load;
  505. destructor done;virtual;
  506. procedure write;virtual;
  507. procedure deref;virtual;
  508. function gettypename:string;virtual;
  509. function is_publishable : boolean;virtual;
  510. { debug }
  511. {$ifdef GDB}
  512. function stabstring : pchar;virtual;
  513. procedure concatstabto(asmlist : paasmoutput);virtual;
  514. {$endif GDB}
  515. { rtti }
  516. procedure write_rtti_data;virtual;
  517. procedure write_child_rtti_data;virtual;
  518. end;
  519. {
  520. $Log$
  521. Revision 1.10 2000-09-24 15:06:29 peter
  522. * use defines.inc
  523. Revision 1.9 2000/09/19 23:08:03 pierre
  524. * fixes for local class debuggging problem (merged)
  525. Revision 1.8 2000/08/21 11:27:44 pierre
  526. * fix the stabs problems
  527. Revision 1.7 2000/08/06 19:39:28 peter
  528. * default parameters working !
  529. Revision 1.6 2000/08/06 14:17:15 peter
  530. * overload fixes (merged)
  531. Revision 1.5 2000/08/03 13:17:26 jonas
  532. + allow regvars to be used inside inlined procs, which required the
  533. following changes:
  534. + load regvars in genentrycode/free them in genexitcode (cgai386)
  535. * moved all regvar related code to new regvars unit
  536. + added pregvarinfo type to hcodegen
  537. + added regvarinfo field to tprocinfo (symdef/symdefh)
  538. * deallocate the regvars of the caller in secondprocinline before
  539. inlining the called procedure and reallocate them afterwards
  540. Revision 1.4 2000/08/02 19:49:59 peter
  541. * first things for default parameters
  542. Revision 1.3 2000/07/13 12:08:27 michael
  543. + patched to 1.1.0 with former 1.09patch from peter
  544. Revision 1.2 2000/07/13 11:32:49 michael
  545. + removed logs
  546. }