symdefh.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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,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. constructor init(const n : string;c : pobjectdef);
  175. constructor load;
  176. destructor done;virtual;
  177. procedure write;virtual;
  178. procedure deref;virtual;
  179. function size : longint;virtual;
  180. function alignment:longint;virtual;
  181. function vmtmethodoffset(index:longint):longint;
  182. function is_publishable : boolean;virtual;
  183. function vmt_mangledname : string;
  184. function rtti_name : string;
  185. procedure check_forwards;
  186. function is_related(d : pobjectdef) : boolean;
  187. function is_class : boolean;
  188. function is_interface : boolean;
  189. function is_cppclass : boolean;
  190. function is_object : boolean;
  191. function next_free_name_index : longint;
  192. procedure insertvmt;
  193. procedure set_parent(c : pobjectdef);
  194. function searchdestructor : pprocdef;
  195. { debug }
  196. {$ifdef GDB}
  197. function stabstring : pchar;virtual;
  198. {$endif GDB}
  199. { init/final }
  200. function needs_inittable : boolean;virtual;
  201. procedure write_init_data;virtual;
  202. procedure write_child_init_data;virtual;
  203. { rtti }
  204. function get_rtti_label : string;virtual;
  205. procedure generate_rtti;virtual;
  206. procedure write_rtti_data;virtual;
  207. procedure write_child_rtti_data;virtual;
  208. function generate_field_table : pasmlabel;
  209. end;
  210. pclassrefdef = ^tclassrefdef;
  211. tclassrefdef = object(tpointerdef)
  212. constructor init(def : pdef);
  213. constructor load;
  214. procedure write;virtual;
  215. function gettypename:string;virtual;
  216. { debug }
  217. {$ifdef GDB}
  218. function stabstring : pchar;virtual;
  219. procedure concatstabto(asmlist : paasmoutput);virtual;
  220. {$endif GDB}
  221. end;
  222. parraydef = ^tarraydef;
  223. tarraydef = object(tdef)
  224. private
  225. rangenr : longint;
  226. public
  227. lowrange,
  228. highrange : longint;
  229. elementtype,
  230. rangetype : ttype;
  231. IsVariant,
  232. IsConstructor,
  233. IsArrayOfConst : boolean;
  234. function gettypename:string;virtual;
  235. function elesize : longint;
  236. constructor init(l,h : longint;rd : pdef);
  237. constructor load;
  238. procedure write;virtual;
  239. {$ifdef GDB}
  240. function stabstring : pchar;virtual;
  241. procedure concatstabto(asmlist : paasmoutput);virtual;
  242. {$endif GDB}
  243. procedure deref;virtual;
  244. function size : longint;virtual;
  245. function alignment : longint;virtual;
  246. { generates the ranges needed by the asm instruction BOUND (i386)
  247. or CMP2 (Motorola) }
  248. procedure genrangecheck;
  249. { returns the label of the range check string }
  250. function getrangecheckstring : string;
  251. function needs_inittable : boolean;virtual;
  252. procedure write_rtti_data;virtual;
  253. procedure write_child_rtti_data;virtual;
  254. end;
  255. precorddef = ^trecorddef;
  256. trecorddef = object(tdef)
  257. symtable : psymtable;
  258. constructor init(p : psymtable);
  259. constructor load;
  260. destructor done;virtual;
  261. procedure write;virtual;
  262. procedure deref;virtual;
  263. function size:longint;virtual;
  264. function alignment : longint;virtual;
  265. function gettypename:string;virtual;
  266. { debug }
  267. {$ifdef GDB}
  268. function stabstring : pchar;virtual;
  269. procedure concatstabto(asmlist : paasmoutput);virtual;
  270. {$endif GDB}
  271. { init/final }
  272. procedure write_init_data;virtual;
  273. procedure write_child_init_data;virtual;
  274. function needs_inittable : boolean;virtual;
  275. { rtti }
  276. procedure write_rtti_data;virtual;
  277. procedure write_child_rtti_data;virtual;
  278. end;
  279. porddef = ^torddef;
  280. torddef = object(tdef)
  281. private
  282. rangenr : longint;
  283. public
  284. low,high : longint;
  285. typ : tbasetype;
  286. constructor init(t : tbasetype;v,b : longint);
  287. constructor load;
  288. procedure write;virtual;
  289. function is_publishable : boolean;virtual;
  290. function gettypename:string;virtual;
  291. procedure setsize;
  292. { generates the ranges needed by the asm instruction BOUND }
  293. { or CMP2 (Motorola) }
  294. procedure genrangecheck;
  295. function getrangecheckstring : string;
  296. { debug }
  297. {$ifdef GDB}
  298. function stabstring : pchar;virtual;
  299. {$endif GDB}
  300. { rtti }
  301. procedure write_rtti_data;virtual;
  302. end;
  303. pfloatdef = ^tfloatdef;
  304. tfloatdef = object(tdef)
  305. typ : tfloattype;
  306. constructor init(t : tfloattype);
  307. constructor load;
  308. procedure write;virtual;
  309. function gettypename:string;virtual;
  310. function is_publishable : boolean;virtual;
  311. procedure setsize;
  312. { debug }
  313. {$ifdef GDB}
  314. function stabstring : pchar;virtual;
  315. {$endif GDB}
  316. { rtti }
  317. procedure write_rtti_data;virtual;
  318. end;
  319. pabstractprocdef = ^tabstractprocdef;
  320. tabstractprocdef = object(tdef)
  321. { saves a definition to the return type }
  322. rettype : ttype;
  323. proctypeoption : tproctypeoption;
  324. proccalloptions : tproccalloptions;
  325. procoptions : tprocoptions;
  326. para : pparalinkedlist;
  327. maxparacount,
  328. minparacount : longint;
  329. symtablelevel : byte;
  330. fpu_used : byte; { how many stack fpu must be empty }
  331. constructor init;
  332. constructor load;
  333. destructor done;virtual;
  334. procedure write;virtual;
  335. procedure deref;virtual;
  336. procedure concatpara(tt:ttype;vsp : tvarspez;defval:psym);
  337. function para_size(alignsize:longint) : longint;
  338. function demangled_paras : string;
  339. function proccalloption2str : string;
  340. procedure test_if_fpu_result;
  341. { debug }
  342. {$ifdef GDB}
  343. function stabstring : pchar;virtual;
  344. procedure concatstabto(asmlist : paasmoutput);virtual;
  345. {$endif GDB}
  346. end;
  347. pprocvardef = ^tprocvardef;
  348. tprocvardef = object(tabstractprocdef)
  349. constructor init;
  350. constructor load;
  351. procedure write;virtual;
  352. function size : longint;virtual;
  353. function gettypename:string;virtual;
  354. function is_publishable : boolean;virtual;
  355. { debug }
  356. {$ifdef GDB}
  357. function stabstring : pchar;virtual;
  358. procedure concatstabto(asmlist : paasmoutput); virtual;
  359. {$endif GDB}
  360. { rtti }
  361. procedure write_child_rtti_data;virtual;
  362. procedure write_rtti_data;virtual;
  363. end;
  364. tmessageinf = record
  365. case integer of
  366. 0 : (str : pchar);
  367. 1 : (i : longint);
  368. end;
  369. tprocdef = object(tabstractprocdef)
  370. private
  371. _mangledname : pchar;
  372. public
  373. extnumber : longint;
  374. messageinf : tmessageinf;
  375. nextoverloaded : pprocdef;
  376. { where is this function defined, needed here because there
  377. is only one symbol for all overloaded functions }
  378. fileinfo : tfileposinfo;
  379. { pointer to the local symbol table }
  380. localst : psymtable;
  381. { pointer to the parameter symbol table }
  382. parast : psymtable;
  383. { symbol owning this definition }
  384. procsym : pprocsym;
  385. { browser info }
  386. lastref,
  387. defref,
  388. crossref,
  389. lastwritten : pref;
  390. refcount : longint;
  391. _class : pobjectdef;
  392. { it's a tree, but this not easy to handle }
  393. { used for inlined procs }
  394. code : pointer;
  395. { info about register variables (JM) }
  396. regvarinfo: pointer;
  397. { true, if the procedure is only declared }
  398. { (forward procedure) }
  399. forwarddef,
  400. { true if the procedure is declared in the interface }
  401. interfacedef : boolean;
  402. { true if the procedure has a forward declaration }
  403. hasforward : boolean;
  404. { check the problems of manglednames }
  405. count : boolean;
  406. is_used : boolean;
  407. { small set which contains the modified registers }
  408. {$ifdef newcg}
  409. usedregisters : tregisterset;
  410. {$else newcg}
  411. usedregisters : longint;
  412. {$endif newcg}
  413. constructor init;
  414. constructor load;
  415. destructor done;virtual;
  416. procedure write;virtual;
  417. procedure deref;virtual;
  418. function haspara:boolean;
  419. function mangledname : string;
  420. procedure setmangledname(const s : string);
  421. procedure load_references;
  422. function write_references : boolean;
  423. function procname: string;
  424. { debug }
  425. {$ifdef GDB}
  426. function cplusplusmangledname : string;
  427. function stabstring : pchar;virtual;
  428. procedure concatstabto(asmlist : paasmoutput);virtual;
  429. {$endif GDB}
  430. { browser }
  431. {$ifdef BrowserLog}
  432. procedure add_to_browserlog;
  433. {$endif BrowserLog}
  434. end;
  435. pstringdef = ^tstringdef;
  436. tstringdef = object(tdef)
  437. string_typ : tstringtype;
  438. len : longint;
  439. constructor shortinit(l : byte);
  440. constructor shortload;
  441. constructor longinit(l : longint);
  442. constructor longload;
  443. constructor ansiinit(l : longint);
  444. constructor ansiload;
  445. constructor wideinit(l : longint);
  446. constructor wideload;
  447. function stringtypname:string;
  448. function size : longint;virtual;
  449. procedure write;virtual;
  450. function gettypename:string;virtual;
  451. function is_publishable : boolean;virtual;
  452. { debug }
  453. {$ifdef GDB}
  454. function stabstring : pchar;virtual;
  455. procedure concatstabto(asmlist : paasmoutput);virtual;
  456. {$endif GDB}
  457. { init/final }
  458. function needs_inittable : boolean;virtual;
  459. { rtti }
  460. procedure write_rtti_data;virtual;
  461. end;
  462. penumdef = ^tenumdef;
  463. tenumdef = object(tdef)
  464. rangenr,
  465. minval,
  466. maxval : longint;
  467. has_jumps : boolean;
  468. firstenum : penumsym;
  469. basedef : penumdef;
  470. constructor init;
  471. constructor init_subrange(_basedef:penumdef;_min,_max:longint);
  472. constructor load;
  473. destructor done;virtual;
  474. procedure write;virtual;
  475. procedure deref;virtual;
  476. function gettypename:string;virtual;
  477. function is_publishable : boolean;virtual;
  478. procedure calcsavesize;
  479. procedure setmax(_max:longint);
  480. procedure setmin(_min:longint);
  481. function min:longint;
  482. function max:longint;
  483. function getrangecheckstring:string;
  484. procedure genrangecheck;
  485. { debug }
  486. {$ifdef GDB}
  487. function stabstring : pchar;virtual;
  488. {$endif GDB}
  489. { rtti }
  490. procedure write_child_rtti_data;virtual;
  491. procedure write_rtti_data;virtual;
  492. end;
  493. psetdef = ^tsetdef;
  494. tsetdef = object(tdef)
  495. elementtype : ttype;
  496. settype : tsettype;
  497. constructor init(s : pdef;high : longint);
  498. constructor load;
  499. destructor done;virtual;
  500. procedure write;virtual;
  501. procedure deref;virtual;
  502. function gettypename:string;virtual;
  503. function is_publishable : boolean;virtual;
  504. { debug }
  505. {$ifdef GDB}
  506. function stabstring : pchar;virtual;
  507. procedure concatstabto(asmlist : paasmoutput);virtual;
  508. {$endif GDB}
  509. { rtti }
  510. procedure write_rtti_data;virtual;
  511. procedure write_child_rtti_data;virtual;
  512. end;
  513. {
  514. $Log$
  515. Revision 1.7 2000-08-06 19:39:28 peter
  516. * default parameters working !
  517. Revision 1.6 2000/08/06 14:17:15 peter
  518. * overload fixes (merged)
  519. Revision 1.5 2000/08/03 13:17:26 jonas
  520. + allow regvars to be used inside inlined procs, which required the
  521. following changes:
  522. + load regvars in genentrycode/free them in genexitcode (cgai386)
  523. * moved all regvar related code to new regvars unit
  524. + added pregvarinfo type to hcodegen
  525. + added regvarinfo field to tprocinfo (symdef/symdefh)
  526. * deallocate the regvars of the caller in secondprocinline before
  527. inlining the called procedure and reallocate them afterwards
  528. Revision 1.4 2000/08/02 19:49:59 peter
  529. * first things for default parameters
  530. Revision 1.3 2000/07/13 12:08:27 michael
  531. + patched to 1.1.0 with former 1.09patch from peter
  532. Revision 1.2 2000/07/13 11:32:49 michael
  533. + removed logs
  534. }