symsym.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Implementation for the symbols 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. unit symsym;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,
  24. { target }
  25. globtype,globals,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,defcmp,
  28. { ppu }
  29. ppu,
  30. cclasses,symnot,
  31. { aasm }
  32. aasmbase,aasmtai,
  33. cpuinfo,cpubase,cgbase,cgutils,parabase
  34. ;
  35. type
  36. { this class is the base for all symbol objects }
  37. tstoredsym = class(tsym)
  38. protected
  39. _mangledname : pstring;
  40. public
  41. constructor create(const n : string);
  42. constructor loadsym(ppufile:tcompilerppufile);
  43. destructor destroy;override;
  44. {$ifdef GDB}
  45. function get_var_value(const s:string):string;
  46. function stabstr_evaluate(const s:string;vars:array of string):Pchar;
  47. procedure concatstabto(asmlist : taasmoutput);
  48. {$endif GDB}
  49. function mangledname : string;
  50. procedure generate_mangledname;virtual;abstract;
  51. end;
  52. tlabelsym = class(tstoredsym)
  53. lab : tasmlabel;
  54. used,
  55. defined : boolean;
  56. code : pointer; { should be tnode }
  57. constructor create(const n : string; l : tasmlabel);
  58. constructor ppuload(ppufile:tcompilerppufile);
  59. procedure generate_mangledname;override;
  60. procedure ppuwrite(ppufile:tcompilerppufile);override;
  61. {$ifdef GDB}
  62. function stabstring : pchar;override;
  63. {$endif GDB}
  64. end;
  65. tunitsym = class(Tsym)
  66. unitsymtable : tsymtable;
  67. constructor create(const n : string;ref : tsymtable);
  68. constructor ppuload(ppufile:tcompilerppufile);
  69. destructor destroy;override;
  70. procedure ppuwrite(ppufile:tcompilerppufile);override;
  71. end;
  72. terrorsym = class(Tsym)
  73. constructor create;
  74. end;
  75. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  76. tprocsym = class(tstoredsym)
  77. protected
  78. pdlistfirst,
  79. pdlistlast : pprocdeflist; { linked list of overloaded procdefs }
  80. function getprocdef(nr:cardinal):Tprocdef;
  81. public
  82. procdef_count : byte;
  83. {$ifdef GDB}
  84. is_global : boolean;
  85. {$endif GDB}
  86. overloadchecked : boolean;
  87. overloadcount : word; { amount of overloaded functions in this module }
  88. property procdef[nr:cardinal]:Tprocdef read getprocdef;
  89. constructor create(const n : string);
  90. constructor ppuload(ppufile:tcompilerppufile);
  91. destructor destroy;override;
  92. { writes all declarations except the specified one }
  93. procedure write_parameter_lists(skipdef:tprocdef);
  94. { tests, if all procedures definitions are defined and not }
  95. { only forward }
  96. procedure check_forward;
  97. procedure unchain_overload;
  98. procedure ppuwrite(ppufile:tcompilerppufile);override;
  99. procedure buildderef;override;
  100. procedure deref;override;
  101. procedure addprocdef(p:tprocdef);
  102. procedure addprocdef_deref(const d:tderef);
  103. procedure add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  104. procedure concat_procdefs_to(s:Tprocsym);
  105. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  106. function first_procdef:Tprocdef;
  107. function last_procdef:Tprocdef;
  108. function search_procdef_nopara_boolret:Tprocdef;
  109. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  110. function search_procdef_bypara(params:Tlinkedlist;
  111. retdef:tdef;
  112. cpoptions:tcompare_paras_options):Tprocdef;
  113. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  114. function search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  115. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  116. function is_visible_for_object(currobjdef:tdef):boolean;override;
  117. {$ifdef GDB}
  118. function stabstring : pchar;override;
  119. {$endif GDB}
  120. end;
  121. ttypesym = class(Tsym)
  122. restype : ttype;
  123. constructor create(const n : string;const tt : ttype);
  124. constructor ppuload(ppufile:tcompilerppufile);
  125. procedure ppuwrite(ppufile:tcompilerppufile);override;
  126. procedure buildderef;override;
  127. procedure deref;override;
  128. function gettypedef:tdef;override;
  129. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  130. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  131. {$ifdef GDB}
  132. function stabstring : pchar;override;
  133. {$endif GDB}
  134. end;
  135. tvarsym = class(tstoredsym)
  136. defaultconstsym : tsym;
  137. varoptions : tvaroptions;
  138. varspez : tvarspez; { sets the type of access }
  139. varregable : tvarregable;
  140. varstate : tvarstate;
  141. localloc : TLocation; { register/reference for local var }
  142. fieldoffset : longint; { offset in record/object }
  143. paraitem : tparaitem;
  144. notifications : Tlinkedlist;
  145. constructor create(const n : string;vsp:tvarspez;const tt : ttype);
  146. constructor create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  147. constructor create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  148. constructor ppuload(ppufile:tcompilerppufile);
  149. destructor destroy;override;
  150. procedure ppuwrite(ppufile:tcompilerppufile);override;
  151. procedure buildderef;override;
  152. procedure deref;override;
  153. procedure generate_mangledname;override;
  154. procedure set_mangledname(const s:string);
  155. function getsize : longint;
  156. function is_regvar:boolean;
  157. procedure trigger_notifications(what:Tnotification_flag);
  158. function register_notification(flags:Tnotification_flags;
  159. callback:Tnotification_callback):cardinal;
  160. procedure unregister_notification(id:cardinal);
  161. {$ifdef GDB}
  162. function stabstring : pchar;override;
  163. {$endif GDB}
  164. private
  165. procedure setvartype(const newtype: ttype);
  166. _vartype : ttype;
  167. public
  168. property vartype: ttype read _vartype write setvartype;
  169. end;
  170. tpropertysym = class(Tsym)
  171. propoptions : tpropertyoptions;
  172. propoverriden : tpropertysym;
  173. propoverridenderef : tderef;
  174. proptype,
  175. indextype : ttype;
  176. index,
  177. default : longint;
  178. readaccess,
  179. writeaccess,
  180. storedaccess : tsymlist;
  181. constructor create(const n : string);
  182. destructor destroy;override;
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. function getsize : longint;
  185. procedure ppuwrite(ppufile:tcompilerppufile);override;
  186. function gettypedef:tdef;override;
  187. procedure buildderef;override;
  188. procedure deref;override;
  189. procedure dooverride(overriden:tpropertysym);
  190. end;
  191. tabsolutesym = class(Tvarsym)
  192. abstyp : absolutetyp;
  193. {$ifdef i386}
  194. absseg : boolean;
  195. {$endif i386}
  196. asmname : pstring;
  197. ref : tsymlist;
  198. constructor create(const n : string;const tt : ttype);
  199. constructor create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  200. destructor destroy;override;
  201. constructor ppuload(ppufile:tcompilerppufile);
  202. procedure buildderef;override;
  203. procedure deref;override;
  204. function mangledname : string;
  205. procedure ppuwrite(ppufile:tcompilerppufile);override;
  206. {$ifdef gdb}
  207. function stabstring:Pchar;override;
  208. {$endif}
  209. end;
  210. ttypedconstsym = class(tstoredsym)
  211. typedconsttype : ttype;
  212. is_writable : boolean;
  213. constructor create(const n : string;p : tdef;writable : boolean);
  214. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  215. constructor ppuload(ppufile:tcompilerppufile);
  216. destructor destroy;override;
  217. procedure generate_mangledname;override;
  218. procedure ppuwrite(ppufile:tcompilerppufile);override;
  219. procedure buildderef;override;
  220. procedure deref;override;
  221. function getsize:longint;
  222. {$ifdef GDB}
  223. function stabstring : pchar;override;
  224. {$endif GDB}
  225. end;
  226. tconstvalue = record
  227. case integer of
  228. 0: (valueord : tconstexprint);
  229. 1: (valueordptr : tconstptruint);
  230. 2: (valueptr : pointer; len : longint);
  231. end;
  232. tconstsym = class(tstoredsym)
  233. consttype : ttype;
  234. consttyp : tconsttyp;
  235. value : tconstvalue;
  236. resstrindex : longint; { needed for resource strings }
  237. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  238. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  239. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  240. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  241. constructor ppuload(ppufile:tcompilerppufile);
  242. destructor destroy;override;
  243. procedure buildderef;override;
  244. procedure deref;override;
  245. procedure ppuwrite(ppufile:tcompilerppufile);override;
  246. {$ifdef GDB}
  247. function stabstring : pchar;override;
  248. {$endif GDB}
  249. end;
  250. tenumsym = class(Tsym)
  251. value : longint;
  252. definition : tenumdef;
  253. definitionderef : tderef;
  254. nextenum : tenumsym;
  255. constructor create(const n : string;def : tenumdef;v : longint);
  256. constructor ppuload(ppufile:tcompilerppufile);
  257. procedure ppuwrite(ppufile:tcompilerppufile);override;
  258. procedure buildderef;override;
  259. procedure deref;override;
  260. procedure order;
  261. end;
  262. tsyssym = class(Tsym)
  263. number : longint;
  264. constructor create(const n : string;l : longint);
  265. constructor ppuload(ppufile:tcompilerppufile);
  266. destructor destroy;override;
  267. procedure ppuwrite(ppufile:tcompilerppufile);override;
  268. end;
  269. { compiler generated symbol to point to rtti and init/finalize tables }
  270. trttisym = class(tstoredsym)
  271. lab : tasmsymbol;
  272. rttityp : trttitype;
  273. constructor create(const n:string;rt:trttitype);
  274. constructor ppuload(ppufile:tcompilerppufile);
  275. procedure ppuwrite(ppufile:tcompilerppufile);override;
  276. function mangledname:string;
  277. function get_label:tasmsymbol;
  278. end;
  279. var
  280. generrorsym : tsym;
  281. implementation
  282. uses
  283. { global }
  284. verbose,
  285. { target }
  286. systems,
  287. { symtable }
  288. defutil,symtable,
  289. { tree }
  290. node,
  291. { aasm }
  292. {$ifdef gdb}
  293. gdb,
  294. {$endif gdb}
  295. { codegen }
  296. paramgr,cresstr,
  297. procinfo
  298. ;
  299. {****************************************************************************
  300. Helpers
  301. ****************************************************************************}
  302. {****************************************************************************
  303. TSYM (base for all symtypes)
  304. ****************************************************************************}
  305. constructor tstoredsym.create(const n : string);
  306. begin
  307. inherited create(n);
  308. _mangledname:=nil;
  309. end;
  310. constructor tstoredsym.loadsym(ppufile:tcompilerppufile);
  311. begin
  312. inherited loadsym(ppufile);
  313. _mangledname:=nil;
  314. end;
  315. { procedure tstoredsym.buildderef;
  316. begin
  317. end;
  318. procedure tstoredsym.deref;
  319. begin
  320. end;}
  321. destructor tstoredsym.destroy;
  322. begin
  323. if assigned(_mangledname) then
  324. begin
  325. {$ifdef MEMDEBUG}
  326. memmanglednames.start;
  327. {$endif MEMDEBUG}
  328. stringdispose(_mangledname);
  329. {$ifdef MEMDEBUG}
  330. memmanglednames.stop;
  331. {$endif MEMDEBUG}
  332. end;
  333. if assigned(defref) then
  334. begin
  335. {$ifdef MEMDEBUG}
  336. membrowser.start;
  337. {$endif MEMDEBUG}
  338. defref.freechain;
  339. defref.free;
  340. {$ifdef MEMDEBUG}
  341. membrowser.stop;
  342. {$endif MEMDEBUG}
  343. end;
  344. inherited destroy;
  345. end;
  346. {$ifdef GDB}
  347. function Tstoredsym.get_var_value(const s:string):string;
  348. begin
  349. if s='mangledname' then
  350. get_var_value:=mangledname
  351. else
  352. get_var_value:=inherited get_var_value(s);
  353. end;
  354. function Tstoredsym.stabstr_evaluate(const s:string;vars:array of string):Pchar;
  355. begin
  356. stabstr_evaluate:=string_evaluate(s,@get_var_value,vars);
  357. end;
  358. procedure tstoredsym.concatstabto(asmlist : taasmoutput);
  359. var
  360. stabstr : Pchar;
  361. begin
  362. stabstr:=stabstring;
  363. if stabstr<>nil then
  364. asmlist.concat(Tai_stabs.create(stabstr));
  365. end;
  366. {$endif GDB}
  367. function tstoredsym.mangledname : string;
  368. begin
  369. if not assigned(_mangledname) then
  370. begin
  371. generate_mangledname;
  372. if not assigned(_mangledname) then
  373. internalerror(200204171);
  374. end;
  375. {$ifdef compress}
  376. mangledname:=minilzw_decode(_mangledname^);
  377. {$else}
  378. mangledname:=_mangledname^;
  379. {$endif}
  380. end;
  381. {****************************************************************************
  382. TLABELSYM
  383. ****************************************************************************}
  384. constructor tlabelsym.create(const n : string; l : tasmlabel);
  385. begin
  386. inherited create(n);
  387. typ:=labelsym;
  388. lab:=l;
  389. used:=false;
  390. defined:=false;
  391. code:=nil;
  392. end;
  393. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  394. begin
  395. inherited loadsym(ppufile);
  396. typ:=labelsym;
  397. { this is all dummy
  398. it is only used for local browsing }
  399. lab:=nil;
  400. code:=nil;
  401. used:=false;
  402. defined:=true;
  403. end;
  404. procedure tlabelsym.generate_mangledname;
  405. begin
  406. {$ifdef compress}
  407. _mangledname:=stringdup(minilzw_encode(lab.name));
  408. {$else}
  409. _mangledname:=stringdup(lab.name);
  410. {$endif}
  411. end;
  412. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  413. begin
  414. if owner.symtabletype=globalsymtable then
  415. Message(sym_e_ill_label_decl)
  416. else
  417. begin
  418. inherited writesym(ppufile);
  419. ppufile.writeentry(iblabelsym);
  420. end;
  421. end;
  422. {$ifdef GDB}
  423. function Tlabelsym.stabstring : pchar;
  424. begin
  425. stabstring:=stabstr_evaluate('"${name}",${N_LSYM},0,${line},0',[]);
  426. end;
  427. {$endif GDB}
  428. {****************************************************************************
  429. TUNITSYM
  430. ****************************************************************************}
  431. constructor tunitsym.create(const n : string;ref : tsymtable);
  432. var
  433. old_make_ref : boolean;
  434. begin
  435. old_make_ref:=make_ref;
  436. make_ref:=false;
  437. inherited create(n);
  438. make_ref:=old_make_ref;
  439. typ:=unitsym;
  440. unitsymtable:=ref;
  441. end;
  442. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  443. begin
  444. inherited loadsym(ppufile);
  445. typ:=unitsym;
  446. unitsymtable:=nil;
  447. refs:=0;
  448. end;
  449. destructor tunitsym.destroy;
  450. begin
  451. inherited destroy;
  452. end;
  453. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  454. begin
  455. inherited writesym(ppufile);
  456. ppufile.writeentry(ibunitsym);
  457. end;
  458. {****************************************************************************
  459. TPROCSYM
  460. ****************************************************************************}
  461. constructor tprocsym.create(const n : string);
  462. begin
  463. inherited create(n);
  464. typ:=procsym;
  465. pdlistfirst:=nil;
  466. pdlistlast:=nil;
  467. owner:=nil;
  468. {$ifdef GDB}
  469. is_global:=false;
  470. {$endif GDB}
  471. { the tprocdef have their own symoptions, make the procsym
  472. always visible }
  473. symoptions:=[sp_public];
  474. overloadchecked:=false;
  475. overloadcount:=0;
  476. procdef_count:=0;
  477. end;
  478. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  479. var
  480. pdderef : tderef;
  481. i,n : longint;
  482. begin
  483. inherited loadsym(ppufile);
  484. typ:=procsym;
  485. pdlistfirst:=nil;
  486. pdlistlast:=nil;
  487. procdef_count:=0;
  488. n:=ppufile.getword;
  489. for i:=1to n do
  490. begin
  491. ppufile.getderef(pdderef);
  492. addprocdef_deref(pdderef);
  493. end;
  494. {$ifdef GDB}
  495. is_global:=false;
  496. {$endif GDB}
  497. overloadchecked:=false;
  498. overloadcount:=$ffff; { invalid, not used anymore }
  499. end;
  500. destructor tprocsym.destroy;
  501. var
  502. hp,p : pprocdeflist;
  503. begin
  504. p:=pdlistfirst;
  505. while assigned(p) do
  506. begin
  507. hp:=p^.next;
  508. dispose(p);
  509. p:=hp;
  510. end;
  511. inherited destroy;
  512. end;
  513. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  514. var
  515. p : pprocdeflist;
  516. n : word;
  517. begin
  518. inherited writesym(ppufile);
  519. { count procdefs }
  520. n:=0;
  521. p:=pdlistfirst;
  522. while assigned(p) do
  523. begin
  524. { only write the proc definitions that belong
  525. to this procsym and are in the global symtable }
  526. if p^.own and
  527. (p^.def.owner.symtabletype in [globalsymtable,objectsymtable]) then
  528. inc(n);
  529. p:=p^.next;
  530. end;
  531. ppufile.putword(n);
  532. { write procdefs }
  533. p:=pdlistfirst;
  534. while assigned(p) do
  535. begin
  536. { only write the proc definitions that belong
  537. to this procsym and are in the global symtable }
  538. if p^.own and
  539. (p^.def.owner.symtabletype in [globalsymtable,objectsymtable]) then
  540. ppufile.putderef(p^.defderef);
  541. p:=p^.next;
  542. end;
  543. ppufile.writeentry(ibprocsym);
  544. end;
  545. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  546. var
  547. p : pprocdeflist;
  548. begin
  549. p:=pdlistfirst;
  550. while assigned(p) do
  551. begin
  552. if p^.def<>skipdef then
  553. MessagePos1(p^.def.fileinfo,sym_h_param_list,p^.def.fullprocname(false));
  554. p:=p^.next;
  555. end;
  556. end;
  557. {Makes implicit externals (procedures declared in the interface
  558. section which do not have a counterpart in the implementation)
  559. to be an imported procedure. For mode macpas.}
  560. procedure import_implict_external(pd:tabstractprocdef);
  561. begin
  562. tprocdef(pd).forwarddef:=false;
  563. tprocdef(pd).setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  564. end;
  565. procedure tprocsym.check_forward;
  566. var
  567. p : pprocdeflist;
  568. begin
  569. p:=pdlistfirst;
  570. while assigned(p) do
  571. begin
  572. if p^.own and (p^.def.forwarddef) then
  573. begin
  574. if (m_mac in aktmodeswitches) and (p^.def.interfacedef) then
  575. import_implict_external(p^.def)
  576. else
  577. begin
  578. MessagePos1(p^.def.fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname(false));
  579. { Turn further error messages off }
  580. p^.def.forwarddef:=false;
  581. end
  582. end;
  583. p:=p^.next;
  584. end;
  585. end;
  586. procedure tprocsym.buildderef;
  587. var
  588. p : pprocdeflist;
  589. begin
  590. p:=pdlistfirst;
  591. while assigned(p) do
  592. begin
  593. if p^.own then
  594. p^.defderef.build(p^.def);
  595. p:=p^.next;
  596. end;
  597. end;
  598. procedure tprocsym.deref;
  599. var
  600. p : pprocdeflist;
  601. begin
  602. { We have removed the overloaded entries, because they
  603. are not valid anymore and we can't deref them because
  604. the unit were they come from is not necessary in
  605. our uses clause (PFV) }
  606. unchain_overload;
  607. { Deref our own procdefs }
  608. p:=pdlistfirst;
  609. while assigned(p) do
  610. begin
  611. if not p^.own then
  612. internalerror(200310291);
  613. p^.def:=tprocdef(p^.defderef.resolve);
  614. p:=p^.next;
  615. end;
  616. end;
  617. procedure tprocsym.addprocdef(p:tprocdef);
  618. var
  619. pd : pprocdeflist;
  620. begin
  621. new(pd);
  622. pd^.def:=p;
  623. pd^.defderef.reset;
  624. pd^.next:=nil;
  625. pd^.own:=(pd^.def.procsym=self);
  626. { if not pd^.own then
  627. internalerror(2222222);}
  628. { Add at end of list to keep always
  629. a correct order, also after loading from ppu }
  630. if assigned(pdlistlast) then
  631. begin
  632. pdlistlast^.next:=pd;
  633. pdlistlast:=pd;
  634. end
  635. else
  636. begin
  637. pdlistfirst:=pd;
  638. pdlistlast:=pd;
  639. end;
  640. inc(procdef_count);
  641. end;
  642. procedure tprocsym.addprocdef_deref(const d:tderef);
  643. var
  644. pd : pprocdeflist;
  645. begin
  646. new(pd);
  647. pd^.def:=nil;
  648. pd^.defderef:=d;
  649. pd^.next:=nil;
  650. pd^.own:=true;
  651. { Add at end of list to keep always
  652. a correct order, also after loading from ppu }
  653. if assigned(pdlistlast) then
  654. begin
  655. pdlistlast^.next:=pd;
  656. pdlistlast:=pd;
  657. end
  658. else
  659. begin
  660. pdlistfirst:=pd;
  661. pdlistlast:=pd;
  662. end;
  663. inc(procdef_count);
  664. end;
  665. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  666. var
  667. i : cardinal;
  668. pd : pprocdeflist;
  669. begin
  670. pd:=pdlistfirst;
  671. for i:=2 to nr do
  672. begin
  673. if not assigned(pd) then
  674. internalerror(200209051);
  675. pd:=pd^.next;
  676. end;
  677. getprocdef:=pd^.def;
  678. end;
  679. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  680. var
  681. pd:pprocdeflist;
  682. begin
  683. pd:=pdlistfirst;
  684. while assigned(pd) do
  685. begin
  686. if Aprocsym.search_procdef_bypara(pd^.def.para,nil,cpoptions)=nil then
  687. Aprocsym.addprocdef(pd^.def);
  688. pd:=pd^.next;
  689. end;
  690. end;
  691. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  692. var
  693. pd : pprocdeflist;
  694. begin
  695. pd:=pdlistfirst;
  696. while assigned(pd) do
  697. begin
  698. s.addprocdef(pd^.def);
  699. pd:=pd^.next;
  700. end;
  701. end;
  702. function Tprocsym.first_procdef:Tprocdef;
  703. begin
  704. if assigned(pdlistfirst) then
  705. first_procdef:=pdlistfirst^.def
  706. else
  707. first_procdef:=nil;
  708. end;
  709. function Tprocsym.last_procdef:Tprocdef;
  710. begin
  711. if assigned(pdlistlast) then
  712. last_procdef:=pdlistlast^.def
  713. else
  714. last_procdef:=nil;
  715. end;
  716. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  717. var
  718. p : pprocdeflist;
  719. begin
  720. p:=pdlistfirst;
  721. while assigned(p) do
  722. begin
  723. proc2call(p^.def,arg);
  724. p:=p^.next;
  725. end;
  726. end;
  727. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  728. var
  729. p : pprocdeflist;
  730. begin
  731. search_procdef_nopara_boolret:=nil;
  732. p:=pdlistfirst;
  733. while p<>nil do
  734. begin
  735. if (p^.def.maxparacount=0) and
  736. is_boolean(p^.def.rettype.def) then
  737. begin
  738. search_procdef_nopara_boolret:=p^.def;
  739. break;
  740. end;
  741. p:=p^.next;
  742. end;
  743. end;
  744. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  745. var
  746. p : pprocdeflist;
  747. begin
  748. search_procdef_bytype:=nil;
  749. p:=pdlistfirst;
  750. while p<>nil do
  751. begin
  752. if p^.def.proctypeoption=pt then
  753. begin
  754. search_procdef_bytype:=p^.def;
  755. break;
  756. end;
  757. p:=p^.next;
  758. end;
  759. end;
  760. function Tprocsym.search_procdef_bypara(params:Tlinkedlist;
  761. retdef:tdef;
  762. cpoptions:tcompare_paras_options):Tprocdef;
  763. var
  764. pd : pprocdeflist;
  765. eq : tequaltype;
  766. begin
  767. search_procdef_bypara:=nil;
  768. pd:=pdlistfirst;
  769. while assigned(pd) do
  770. begin
  771. if assigned(retdef) then
  772. eq:=compare_defs(retdef,pd^.def.rettype.def,nothingn)
  773. else
  774. eq:=te_equal;
  775. if (eq>=te_equal) or
  776. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  777. begin
  778. eq:=compare_paras(params,pd^.def.para,cp_value_equal_const,cpoptions);
  779. if (eq>=te_equal) or
  780. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  781. begin
  782. search_procdef_bypara:=pd^.def;
  783. break;
  784. end;
  785. end;
  786. pd:=pd^.next;
  787. end;
  788. end;
  789. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  790. var
  791. pd : pprocdeflist;
  792. eq,besteq : tequaltype;
  793. bestpd : tprocdef;
  794. begin
  795. { This function will return the pprocdef of pprocsym that
  796. is the best match for procvardef. When there are multiple
  797. matches it returns nil.}
  798. search_procdef_byprocvardef:=nil;
  799. bestpd:=nil;
  800. besteq:=te_incompatible;
  801. pd:=pdlistfirst;
  802. while assigned(pd) do
  803. begin
  804. eq:=proc_to_procvar_equal(pd^.def,d,false);
  805. if eq>=te_equal then
  806. begin
  807. { multiple procvars with the same equal level }
  808. if assigned(bestpd) and
  809. (besteq=eq) then
  810. exit;
  811. if eq>besteq then
  812. begin
  813. besteq:=eq;
  814. bestpd:=pd^.def;
  815. end;
  816. end;
  817. pd:=pd^.next;
  818. end;
  819. search_procdef_byprocvardef:=bestpd;
  820. end;
  821. function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  822. var
  823. convtyp : tconverttype;
  824. pd : pprocdeflist;
  825. bestpd : tprocdef;
  826. eq,
  827. besteq : tequaltype;
  828. hpd : tprocdef;
  829. currpara : tparaitem;
  830. begin
  831. result:=nil;
  832. bestpd:=nil;
  833. besteq:=te_incompatible;
  834. pd:=pdlistfirst;
  835. while assigned(pd) do
  836. begin
  837. if equal_defs(todef,pd^.def.rettype.def) then
  838. begin
  839. currpara:=Tparaitem(pd^.def.para.first);
  840. { ignore vs_hidden parameters }
  841. while assigned(currpara) and (currpara.is_hidden) do
  842. currpara:=tparaitem(currpara.next);
  843. if assigned(currpara) then
  844. begin
  845. eq:=compare_defs_ext(fromdef,currpara.paratype.def,nothingn,convtyp,hpd,[]);
  846. if eq=te_exact then
  847. begin
  848. result:=pd^.def;
  849. exit;
  850. end;
  851. if eq>besteq then
  852. begin
  853. bestpd:=pd^.def;
  854. besteq:=eq;
  855. end;
  856. end;
  857. end;
  858. pd:=pd^.next;
  859. end;
  860. result:=bestpd;
  861. end;
  862. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  863. var
  864. p : pprocdeflist;
  865. begin
  866. write_references:=false;
  867. if not inherited write_references(ppufile,locals) then
  868. exit;
  869. write_references:=true;
  870. p:=pdlistfirst;
  871. while assigned(p) do
  872. begin
  873. if p^.own then
  874. p^.def.write_references(ppufile,locals);
  875. p:=p^.next;
  876. end;
  877. end;
  878. procedure tprocsym.unchain_overload;
  879. var
  880. p,hp : pprocdeflist;
  881. begin
  882. { remove all overloaded procdefs from the
  883. procdeflist that are not in the current symtable }
  884. overloadchecked:=false;
  885. p:=pdlistfirst;
  886. { reset new lists }
  887. pdlistfirst:=nil;
  888. pdlistlast:=nil;
  889. while assigned(p) do
  890. begin
  891. hp:=p^.next;
  892. if p^.own then
  893. begin
  894. { keep, add to list }
  895. if assigned(pdlistlast) then
  896. begin
  897. pdlistlast^.next:=p;
  898. pdlistlast:=p;
  899. end
  900. else
  901. begin
  902. pdlistfirst:=p;
  903. pdlistlast:=p;
  904. end;
  905. p^.next:=nil;
  906. end
  907. else
  908. begin
  909. { remove }
  910. dispose(p);
  911. dec(procdef_count);
  912. end;
  913. p:=hp;
  914. end;
  915. end;
  916. function tprocsym.is_visible_for_object(currobjdef:tdef):boolean;
  917. var
  918. p : pprocdeflist;
  919. begin
  920. { This procsym is visible, when there is at least
  921. one of the procdefs visible }
  922. result:=false;
  923. p:=pdlistfirst;
  924. while assigned(p) do
  925. begin
  926. if p^.own and
  927. p^.def.is_visible_for_object(tobjectdef(currobjdef)) then
  928. begin
  929. result:=true;
  930. exit;
  931. end;
  932. p:=p^.next;
  933. end;
  934. end;
  935. {$ifdef GDB}
  936. function tprocsym.stabstring : pchar;
  937. begin
  938. internalerror(200111171);
  939. result:=nil;
  940. end;
  941. {$endif GDB}
  942. {****************************************************************************
  943. TERRORSYM
  944. ****************************************************************************}
  945. constructor terrorsym.create;
  946. begin
  947. inherited create('');
  948. typ:=errorsym;
  949. end;
  950. {****************************************************************************
  951. TPROPERTYSYM
  952. ****************************************************************************}
  953. constructor tpropertysym.create(const n : string);
  954. begin
  955. inherited create(n);
  956. typ:=propertysym;
  957. propoptions:=[];
  958. index:=0;
  959. default:=0;
  960. proptype.reset;
  961. indextype.reset;
  962. readaccess:=tsymlist.create;
  963. writeaccess:=tsymlist.create;
  964. storedaccess:=tsymlist.create;
  965. end;
  966. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  967. begin
  968. inherited loadsym(ppufile);
  969. typ:=propertysym;
  970. ppufile.getsmallset(propoptions);
  971. if (ppo_is_override in propoptions) then
  972. begin
  973. ppufile.getderef(propoverridenderef);
  974. { we need to have these objects initialized }
  975. readaccess:=tsymlist.create;
  976. writeaccess:=tsymlist.create;
  977. storedaccess:=tsymlist.create;
  978. end
  979. else
  980. begin
  981. ppufile.gettype(proptype);
  982. index:=ppufile.getlongint;
  983. default:=ppufile.getlongint;
  984. ppufile.gettype(indextype);
  985. readaccess:=ppufile.getsymlist;
  986. writeaccess:=ppufile.getsymlist;
  987. storedaccess:=ppufile.getsymlist;
  988. end;
  989. end;
  990. destructor tpropertysym.destroy;
  991. begin
  992. readaccess.free;
  993. writeaccess.free;
  994. storedaccess.free;
  995. inherited destroy;
  996. end;
  997. function tpropertysym.gettypedef:tdef;
  998. begin
  999. gettypedef:=proptype.def;
  1000. end;
  1001. procedure tpropertysym.buildderef;
  1002. begin
  1003. if (ppo_is_override in propoptions) then
  1004. begin
  1005. propoverridenderef.build(propoverriden);
  1006. end
  1007. else
  1008. begin
  1009. proptype.buildderef;
  1010. indextype.buildderef;
  1011. readaccess.buildderef;
  1012. writeaccess.buildderef;
  1013. storedaccess.buildderef;
  1014. end;
  1015. end;
  1016. procedure tpropertysym.deref;
  1017. begin
  1018. if (ppo_is_override in propoptions) then
  1019. begin
  1020. propoverriden:=tpropertysym(propoverridenderef.resolve);
  1021. dooverride(propoverriden);
  1022. end
  1023. else
  1024. begin
  1025. proptype.resolve;
  1026. indextype.resolve;
  1027. readaccess.resolve;
  1028. writeaccess.resolve;
  1029. storedaccess.resolve;
  1030. end;
  1031. end;
  1032. function tpropertysym.getsize : longint;
  1033. begin
  1034. getsize:=0;
  1035. end;
  1036. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1037. begin
  1038. inherited writesym(ppufile);
  1039. ppufile.putsmallset(propoptions);
  1040. if (ppo_is_override in propoptions) then
  1041. ppufile.putderef(propoverridenderef)
  1042. else
  1043. begin
  1044. ppufile.puttype(proptype);
  1045. ppufile.putlongint(index);
  1046. ppufile.putlongint(default);
  1047. ppufile.puttype(indextype);
  1048. ppufile.putsymlist(readaccess);
  1049. ppufile.putsymlist(writeaccess);
  1050. ppufile.putsymlist(storedaccess);
  1051. end;
  1052. ppufile.writeentry(ibpropertysym);
  1053. end;
  1054. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1055. begin
  1056. propoverriden:=overriden;
  1057. proptype:=overriden.proptype;
  1058. propoptions:=overriden.propoptions+[ppo_is_override];
  1059. index:=overriden.index;
  1060. default:=overriden.default;
  1061. indextype:=overriden.indextype;
  1062. readaccess.free;
  1063. readaccess:=overriden.readaccess.getcopy;
  1064. writeaccess.free;
  1065. writeaccess:=overriden.writeaccess.getcopy;
  1066. storedaccess.free;
  1067. storedaccess:=overriden.storedaccess.getcopy;
  1068. end;
  1069. {****************************************************************************
  1070. TABSOLUTESYM
  1071. ****************************************************************************}
  1072. constructor tabsolutesym.create(const n : string;const tt : ttype);
  1073. begin
  1074. inherited create(n,vs_value,tt);
  1075. typ:=absolutesym;
  1076. ref:=nil;
  1077. end;
  1078. constructor tabsolutesym.create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  1079. begin
  1080. inherited create(n,vs_value,tt);
  1081. typ:=absolutesym;
  1082. ref:=_ref;
  1083. end;
  1084. destructor tabsolutesym.destroy;
  1085. begin
  1086. if assigned(ref) then
  1087. ref.free;
  1088. inherited destroy;
  1089. end;
  1090. constructor tabsolutesym.ppuload(ppufile:tcompilerppufile);
  1091. begin
  1092. { Note: This needs to load everything of tvarsym.write }
  1093. inherited ppuload(ppufile);
  1094. { load absolute }
  1095. typ:=absolutesym;
  1096. ref:=nil;
  1097. fieldoffset:=0;
  1098. asmname:=nil;
  1099. abstyp:=absolutetyp(ppufile.getbyte);
  1100. {$ifdef i386}
  1101. absseg:=false;
  1102. {$endif i386}
  1103. case abstyp of
  1104. tovar :
  1105. ref:=ppufile.getsymlist;
  1106. toasm :
  1107. asmname:=stringdup(ppufile.getstring);
  1108. toaddr :
  1109. begin
  1110. fieldoffset:=ppufile.getlongint;
  1111. {$ifdef i386}
  1112. absseg:=boolean(ppufile.getbyte);
  1113. {$endif i386}
  1114. end;
  1115. end;
  1116. end;
  1117. procedure tabsolutesym.ppuwrite(ppufile:tcompilerppufile);
  1118. var
  1119. oldintfcrc : boolean;
  1120. begin
  1121. { Note: This needs to write everything of tvarsym.write }
  1122. inherited writesym(ppufile);
  1123. ppufile.putbyte(byte(varspez));
  1124. oldintfcrc:=ppufile.do_crc;
  1125. ppufile.do_crc:=false;
  1126. ppufile.putbyte(byte(varregable));
  1127. ppufile.do_crc:=oldintfcrc;
  1128. ppufile.putlongint(fieldoffset);
  1129. { write only definition or definitionsym }
  1130. ppufile.puttype(vartype);
  1131. ppufile.putsmallset(varoptions);
  1132. ppufile.putbyte(byte(abstyp));
  1133. case abstyp of
  1134. tovar :
  1135. ppufile.putsymlist(ref);
  1136. toasm :
  1137. ppufile.putstring(asmname^);
  1138. toaddr :
  1139. begin
  1140. ppufile.putlongint(fieldoffset);
  1141. {$ifdef i386}
  1142. ppufile.putbyte(byte(absseg));
  1143. {$endif i386}
  1144. end;
  1145. end;
  1146. ppufile.writeentry(ibabsolutesym);
  1147. end;
  1148. procedure tabsolutesym.buildderef;
  1149. begin
  1150. { inheritance of varsym.deref ! }
  1151. vartype.buildderef;
  1152. if (abstyp=tovar) then
  1153. ref.buildderef;
  1154. end;
  1155. procedure tabsolutesym.deref;
  1156. begin
  1157. { inheritance of varsym.deref ! }
  1158. vartype.resolve;
  1159. { own absolute deref }
  1160. if (abstyp=tovar) then
  1161. ref.resolve;
  1162. end;
  1163. function tabsolutesym.mangledname : string;
  1164. begin
  1165. case abstyp of
  1166. toasm :
  1167. mangledname:=asmname^;
  1168. toaddr :
  1169. mangledname:='$'+tostr(fieldoffset);
  1170. else
  1171. internalerror(10002);
  1172. end;
  1173. end;
  1174. {$ifdef GDB}
  1175. function Tabsolutesym.stabstring:Pchar;
  1176. begin
  1177. stabstring:=nil;
  1178. end;
  1179. {$endif GDB}
  1180. {****************************************************************************
  1181. TVARSYM
  1182. ****************************************************************************}
  1183. constructor tvarsym.create(const n : string;vsp:tvarspez;const tt : ttype);
  1184. begin
  1185. inherited create(n);
  1186. typ:=varsym;
  1187. vartype:=tt;
  1188. _mangledname:=nil;
  1189. varspez:=vsp;
  1190. fieldoffset:=0;
  1191. fillchar(localloc,sizeof(localloc),0);
  1192. defaultconstsym:=nil;
  1193. refs:=0;
  1194. varstate:=vs_declared;
  1195. varoptions:=[];
  1196. end;
  1197. constructor tvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1198. begin
  1199. tvarsym(self).create(n,vsp,tt);
  1200. include(varoptions,vo_is_dll_var);
  1201. end;
  1202. constructor tvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1203. begin
  1204. tvarsym(self).create(n,vsp,tt);
  1205. stringdispose(_mangledname);
  1206. {$ifdef compress}
  1207. _mangledname:=stringdup(minilzw_encode(mangled));
  1208. {$else}
  1209. _mangledname:=stringdup(mangled);
  1210. {$endif}
  1211. end;
  1212. constructor tvarsym.ppuload(ppufile:tcompilerppufile);
  1213. begin
  1214. inherited loadsym(ppufile);
  1215. typ:=varsym;
  1216. fillchar(localloc,sizeof(localloc),0);
  1217. refs := 0;
  1218. varstate:=vs_used;
  1219. varspez:=tvarspez(ppufile.getbyte);
  1220. varregable:=tvarregable(ppufile.getbyte);
  1221. fieldoffset:=ppufile.getlongint;
  1222. defaultconstsym:=nil;
  1223. ppufile.gettype(_vartype);
  1224. ppufile.getsmallset(varoptions);
  1225. if [vo_is_C_var,vo_is_dll_var]*varoptions<>[] then
  1226. _mangledname:=stringdup(ppufile.getstring);
  1227. end;
  1228. destructor tvarsym.destroy;
  1229. begin
  1230. if assigned(notifications) then
  1231. notifications.destroy;
  1232. inherited destroy;
  1233. end;
  1234. procedure tvarsym.buildderef;
  1235. begin
  1236. vartype.buildderef;
  1237. end;
  1238. procedure tvarsym.deref;
  1239. begin
  1240. vartype.resolve;
  1241. end;
  1242. procedure tvarsym.ppuwrite(ppufile:tcompilerppufile);
  1243. var
  1244. oldintfcrc : boolean;
  1245. begin
  1246. inherited writesym(ppufile);
  1247. ppufile.putbyte(byte(varspez));
  1248. oldintfcrc:=ppufile.do_crc;
  1249. ppufile.do_crc:=false;
  1250. ppufile.putbyte(byte(varregable));
  1251. ppufile.do_crc:=oldintfcrc;
  1252. ppufile.putlongint(fieldoffset);
  1253. ppufile.puttype(vartype);
  1254. ppufile.putsmallset(varoptions);
  1255. if [vo_is_C_var,vo_is_dll_var]*varoptions<>[] then
  1256. ppufile.putstring(_mangledname^);
  1257. ppufile.writeentry(ibvarsym);
  1258. end;
  1259. procedure tvarsym.generate_mangledname;
  1260. begin
  1261. {$ifdef compress}
  1262. _mangledname:=stringdup(minilzw_encode(make_mangledname('U',owner,name)));
  1263. {$else}
  1264. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1265. {$endif}
  1266. end;
  1267. procedure tvarsym.set_mangledname(const s:string);
  1268. begin
  1269. stringdispose(_mangledname);
  1270. {$ifdef compress}
  1271. _mangledname:=stringdup(minilzw_encode(s));
  1272. {$else}
  1273. _mangledname:=stringdup(s);
  1274. {$endif}
  1275. end;
  1276. function tvarsym.getsize : longint;
  1277. begin
  1278. if assigned(vartype.def) and
  1279. ((vartype.def.deftype<>arraydef) or
  1280. tarraydef(vartype.def).isDynamicArray or
  1281. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1282. result:=vartype.def.size
  1283. else
  1284. result:=0;
  1285. end;
  1286. function tvarsym.is_regvar:boolean;
  1287. begin
  1288. result:=(cs_regvars in aktglobalswitches) and
  1289. not(pi_has_assembler_block in current_procinfo.flags) and
  1290. not(pi_uses_exceptions in current_procinfo.flags) and
  1291. not(vo_has_local_copy in varoptions) and
  1292. (varregable<>vr_none);
  1293. end;
  1294. procedure Tvarsym.trigger_notifications(what:Tnotification_flag);
  1295. var n:Tnotification;
  1296. begin
  1297. if assigned(notifications) then
  1298. begin
  1299. n:=Tnotification(notifications.first);
  1300. while assigned(n) do
  1301. begin
  1302. if what in n.flags then
  1303. n.callback(what,self);
  1304. n:=Tnotification(n.next);
  1305. end;
  1306. end;
  1307. end;
  1308. function Tvarsym.register_notification(flags:Tnotification_flags;callback:
  1309. Tnotification_callback):cardinal;
  1310. var n:Tnotification;
  1311. begin
  1312. if not assigned(notifications) then
  1313. notifications:=Tlinkedlist.create;
  1314. n:=Tnotification.create(flags,callback);
  1315. register_notification:=n.id;
  1316. notifications.concat(n);
  1317. end;
  1318. procedure Tvarsym.unregister_notification(id:cardinal);
  1319. var n:Tnotification;
  1320. begin
  1321. if not assigned(notifications) then
  1322. internalerror(200212311)
  1323. else
  1324. begin
  1325. n:=Tnotification(notifications.first);
  1326. while assigned(n) do
  1327. begin
  1328. if n.id=id then
  1329. begin
  1330. notifications.remove(n);
  1331. n.destroy;
  1332. exit;
  1333. end;
  1334. n:=Tnotification(n.next);
  1335. end;
  1336. internalerror(200212311)
  1337. end;
  1338. end;
  1339. {$ifdef GDB}
  1340. function Tvarsym.stabstring:Pchar;
  1341. var st:string;
  1342. threadvaroffset:string;
  1343. regidx:Tregisterindex;
  1344. c:char;
  1345. loc: tcgloc;
  1346. begin
  1347. { set loc to LOC_REFERENCE to get somewhat usable debugging info for -Or }
  1348. { while stabs aren't adapted for regvars yet }
  1349. stabstring:=nil;
  1350. loc := localloc.loc;
  1351. if (vo_is_self in varoptions) then
  1352. begin
  1353. case loc of
  1354. LOC_REGISTER,
  1355. LOC_CREGISTER:
  1356. regidx:=findreg_by_number(localloc.register);
  1357. LOC_REFERENCE: ;
  1358. else
  1359. internalerror(2003091815);
  1360. end;
  1361. if (po_classmethod in current_procinfo.procdef.procoptions) or
  1362. (po_staticmethod in current_procinfo.procdef.procoptions) then
  1363. begin
  1364. if (loc=LOC_REFERENCE) then
  1365. stabstring:=stabstr_evaluate('"pvmt:p$1",${N_TSYM},0,0,$2',
  1366. [Tstoreddef(pvmttype.def).numberstring,tostr(localloc.reference.offset)]);
  1367. (* else
  1368. stabstring:=stabstr_evaluate('"pvmt:r$1",${N_RSYM},0,0,$2',
  1369. [Tstoreddef(pvmttype.def).numberstring,tostr(regstabs_table[regidx])]) *)
  1370. end
  1371. else
  1372. begin
  1373. if not(is_class(current_procinfo.procdef._class)) then
  1374. c:='v'
  1375. else
  1376. c:='p';
  1377. if (loc=LOC_REFERENCE) then
  1378. stabstring:=stabstr_evaluate('"$$t:$1",${N_TSYM},0,0,$2',
  1379. [c+current_procinfo.procdef._class.numberstring,tostr(localloc.reference.offset)]);
  1380. (* else
  1381. stabstring:=stabstr_evaluate('"$$t:r$1",${N_RSYM},0,0,$2',
  1382. [c+current_procinfo.procdef._class.numberstring,tostr(regstabs_table[regidx])]); *)
  1383. end;
  1384. end
  1385. else
  1386. begin
  1387. st:=tstoreddef(vartype.def).numberstring;
  1388. if (vo_is_thread_var in varoptions) then
  1389. threadvaroffset:='+'+tostr(sizeof(aint))
  1390. else
  1391. threadvaroffset:='';
  1392. case owner.symtabletype of
  1393. objectsymtable:
  1394. if (sp_static in symoptions) then
  1395. begin
  1396. if (cs_gdb_gsym in aktglobalswitches) then
  1397. st:='G'+st
  1398. else
  1399. st:='S'+st;
  1400. stabstring:=stabstr_evaluate('"${ownername}__${name}:$1",${N_LCSYM},0,${line},${mangledname}$2',
  1401. [st,threadvaroffset]);
  1402. end;
  1403. globalsymtable:
  1404. begin
  1405. { Here we used S instead of
  1406. because with G GDB doesn't look at the address field
  1407. but searches the same name or with a leading underscore
  1408. but these names don't exist in pascal !}
  1409. if (cs_gdb_gsym in aktglobalswitches) then
  1410. st:='G'+st
  1411. else
  1412. st:='S'+st;
  1413. stabstring:=stabstr_evaluate('"${name}:$1",${N_LCSYM},0,${line},${mangledname}$2',[st,threadvaroffset]);
  1414. end;
  1415. staticsymtable :
  1416. stabstring:=stabstr_evaluate('"${name}:S$1",${N_LCSYM},0,${line},${mangledname}$2',[st,threadvaroffset]);
  1417. parasymtable,localsymtable:
  1418. begin
  1419. { There is no space allocated for not referenced locals }
  1420. if (owner.symtabletype=localsymtable) and (refs=0) then
  1421. exit;
  1422. if (vo_is_C_var in varoptions) then
  1423. begin
  1424. stabstring:=stabstr_evaluate('"${name}:S$1",${N_LCSYM},0,${line},${mangledname}',[st]);
  1425. exit;
  1426. end;
  1427. if (owner.symtabletype=parasymtable) then
  1428. begin
  1429. if paramanager.push_addr_param(varspez,vartype.def,tprocdef(owner.defowner).proccalloption) and
  1430. not(vo_has_local_copy in varoptions) and
  1431. not is_open_string(vartype.def) then
  1432. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1433. else
  1434. st := 'p'+st;
  1435. end;
  1436. case loc of
  1437. LOC_REGISTER,
  1438. LOC_CREGISTER,
  1439. LOC_MMREGISTER,
  1440. LOC_CMMREGISTER,
  1441. LOC_FPUREGISTER,
  1442. LOC_CFPUREGISTER :
  1443. begin
  1444. regidx:=findreg_by_number(localloc.register);
  1445. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1446. { this is the register order for GDB}
  1447. if regidx<>0 then
  1448. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1449. end;
  1450. LOC_REFERENCE :
  1451. { offset to ebp => will not work if the framepointer is esp
  1452. so some optimizing will make things harder to debug }
  1453. stabstring:=stabstr_evaluate('"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(localloc.reference.offset)])
  1454. else
  1455. internalerror(2003091814);
  1456. end;
  1457. end;
  1458. else
  1459. stabstring := inherited stabstring;
  1460. end;
  1461. end;
  1462. end;
  1463. {$endif GDB}
  1464. procedure tvarsym.setvartype(const newtype: ttype);
  1465. begin
  1466. _vartype := newtype;
  1467. { can we load the value into a register ? }
  1468. if not assigned(owner) or
  1469. (owner.symtabletype in [localsymtable,parasymtable]) or
  1470. (
  1471. (owner.symtabletype=staticsymtable) and
  1472. not(cs_create_pic in aktmoduleswitches)
  1473. ) then
  1474. begin
  1475. if tstoreddef(vartype.def).is_intregable then
  1476. varregable:=vr_intreg
  1477. else
  1478. {$warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0}
  1479. if (
  1480. not assigned(owner) or
  1481. (owner.symtabletype<>staticsymtable)
  1482. ) and
  1483. tstoreddef(vartype.def).is_fpuregable then
  1484. varregable:=vr_fpureg;
  1485. end;
  1486. end;
  1487. {****************************************************************************
  1488. TTYPEDCONSTSYM
  1489. *****************************************************************************}
  1490. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1491. begin
  1492. inherited create(n);
  1493. typ:=typedconstsym;
  1494. typedconsttype.setdef(p);
  1495. is_writable:=writable;
  1496. end;
  1497. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1498. begin
  1499. inherited create(n);
  1500. typ:=typedconstsym;
  1501. typedconsttype:=tt;
  1502. is_writable:=writable;
  1503. end;
  1504. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1505. begin
  1506. inherited loadsym(ppufile);
  1507. typ:=typedconstsym;
  1508. ppufile.gettype(typedconsttype);
  1509. is_writable:=boolean(ppufile.getbyte);
  1510. end;
  1511. destructor ttypedconstsym.destroy;
  1512. begin
  1513. inherited destroy;
  1514. end;
  1515. procedure ttypedconstsym.generate_mangledname;
  1516. begin
  1517. {$ifdef compress}
  1518. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1519. {$else}
  1520. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1521. {$endif}
  1522. end;
  1523. function ttypedconstsym.getsize : longint;
  1524. begin
  1525. if assigned(typedconsttype.def) then
  1526. getsize:=typedconsttype.def.size
  1527. else
  1528. getsize:=0;
  1529. end;
  1530. procedure ttypedconstsym.buildderef;
  1531. begin
  1532. typedconsttype.buildderef;
  1533. end;
  1534. procedure ttypedconstsym.deref;
  1535. begin
  1536. typedconsttype.resolve;
  1537. end;
  1538. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1539. begin
  1540. inherited writesym(ppufile);
  1541. ppufile.puttype(typedconsttype);
  1542. ppufile.putbyte(byte(is_writable));
  1543. ppufile.writeentry(ibtypedconstsym);
  1544. end;
  1545. {$ifdef GDB}
  1546. function ttypedconstsym.stabstring : pchar;
  1547. var st:char;
  1548. begin
  1549. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1550. st:='G'
  1551. else
  1552. st:='S';
  1553. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_STSYM},0,${line},${mangledname}',
  1554. [st,Tstoreddef(typedconsttype.def).numberstring]);
  1555. end;
  1556. {$endif GDB}
  1557. {****************************************************************************
  1558. TCONSTSYM
  1559. ****************************************************************************}
  1560. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1561. begin
  1562. inherited create(n);
  1563. fillchar(value, sizeof(value), #0);
  1564. typ:=constsym;
  1565. consttyp:=t;
  1566. value.valueord:=v;
  1567. ResStrIndex:=0;
  1568. consttype:=tt;
  1569. end;
  1570. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1571. begin
  1572. inherited create(n);
  1573. fillchar(value, sizeof(value), #0);
  1574. typ:=constsym;
  1575. consttyp:=t;
  1576. value.valueordptr:=v;
  1577. ResStrIndex:=0;
  1578. consttype:=tt;
  1579. end;
  1580. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1581. begin
  1582. inherited create(n);
  1583. fillchar(value, sizeof(value), #0);
  1584. typ:=constsym;
  1585. consttyp:=t;
  1586. value.valueptr:=v;
  1587. ResStrIndex:=0;
  1588. consttype:=tt;
  1589. end;
  1590. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1591. begin
  1592. inherited create(n);
  1593. fillchar(value, sizeof(value), #0);
  1594. typ:=constsym;
  1595. consttyp:=t;
  1596. value.valueptr:=str;
  1597. consttype.reset;
  1598. value.len:=l;
  1599. if t=constresourcestring then
  1600. ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
  1601. end;
  1602. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1603. var
  1604. pd : pbestreal;
  1605. ps : pnormalset;
  1606. pc : pchar;
  1607. begin
  1608. inherited loadsym(ppufile);
  1609. typ:=constsym;
  1610. consttype.reset;
  1611. consttyp:=tconsttyp(ppufile.getbyte);
  1612. fillchar(value, sizeof(value), #0);
  1613. case consttyp of
  1614. constord :
  1615. begin
  1616. ppufile.gettype(consttype);
  1617. value.valueord:=ppufile.getexprint;
  1618. end;
  1619. constpointer :
  1620. begin
  1621. ppufile.gettype(consttype);
  1622. value.valueordptr:=ppufile.getptruint;
  1623. end;
  1624. conststring,
  1625. constresourcestring :
  1626. begin
  1627. value.len:=ppufile.getlongint;
  1628. getmem(pc,value.len+1);
  1629. ppufile.getdata(pc^,value.len);
  1630. if consttyp=constresourcestring then
  1631. ResStrIndex:=ppufile.getlongint;
  1632. value.valueptr:=pc;
  1633. end;
  1634. constreal :
  1635. begin
  1636. new(pd);
  1637. pd^:=ppufile.getreal;
  1638. value.valueptr:=pd;
  1639. end;
  1640. constset :
  1641. begin
  1642. ppufile.gettype(consttype);
  1643. new(ps);
  1644. ppufile.getnormalset(ps^);
  1645. value.valueptr:=ps;
  1646. end;
  1647. constguid :
  1648. begin
  1649. new(pguid(value.valueptr));
  1650. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1651. end;
  1652. constnil : ;
  1653. else
  1654. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1655. end;
  1656. end;
  1657. destructor tconstsym.destroy;
  1658. begin
  1659. case consttyp of
  1660. conststring,
  1661. constresourcestring :
  1662. freemem(pchar(value.valueptr),value.len+1);
  1663. constreal :
  1664. dispose(pbestreal(value.valueptr));
  1665. constset :
  1666. dispose(pnormalset(value.valueptr));
  1667. constguid :
  1668. dispose(pguid(value.valueptr));
  1669. end;
  1670. inherited destroy;
  1671. end;
  1672. procedure tconstsym.buildderef;
  1673. begin
  1674. if consttyp in [constord,constpointer,constset] then
  1675. consttype.buildderef;
  1676. end;
  1677. procedure tconstsym.deref;
  1678. begin
  1679. if consttyp in [constord,constpointer,constset] then
  1680. consttype.resolve;
  1681. end;
  1682. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1683. begin
  1684. inherited writesym(ppufile);
  1685. ppufile.putbyte(byte(consttyp));
  1686. case consttyp of
  1687. constnil : ;
  1688. constord :
  1689. begin
  1690. ppufile.puttype(consttype);
  1691. ppufile.putexprint(value.valueord);
  1692. end;
  1693. constpointer :
  1694. begin
  1695. ppufile.puttype(consttype);
  1696. ppufile.putptruint(value.valueordptr);
  1697. end;
  1698. conststring,
  1699. constresourcestring :
  1700. begin
  1701. ppufile.putlongint(value.len);
  1702. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1703. if consttyp=constresourcestring then
  1704. ppufile.putlongint(ResStrIndex);
  1705. end;
  1706. constreal :
  1707. ppufile.putreal(pbestreal(value.valueptr)^);
  1708. constset :
  1709. begin
  1710. ppufile.puttype(consttype);
  1711. ppufile.putnormalset(value.valueptr^);
  1712. end;
  1713. constguid :
  1714. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1715. else
  1716. internalerror(13);
  1717. end;
  1718. ppufile.writeentry(ibconstsym);
  1719. end;
  1720. {$ifdef GDB}
  1721. function Tconstsym.stabstring:Pchar;
  1722. var st : string;
  1723. begin
  1724. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1725. case consttyp of
  1726. conststring:
  1727. st:='s'''+backspace_quote(octal_quote(strpas(pchar(value.valueptr)),[#0..#9,#11,#12,#14..#31,'''']),['"','\',#10,#13])+'''';
  1728. constord:
  1729. st:='i'+tostr(value.valueord);
  1730. constpointer:
  1731. st:='i'+tostr(value.valueordptr);
  1732. constreal:
  1733. begin
  1734. system.str(pbestreal(value.valueptr)^,st);
  1735. st := 'r'+st;
  1736. end;
  1737. { if we don't know just put zero !! }
  1738. else st:='i0';
  1739. {***SETCONST}
  1740. {constset:;} {*** I don't know what to do with a set.}
  1741. { sets are not recognized by GDB}
  1742. {***}
  1743. end;
  1744. { valgrind does not support constants }
  1745. if cs_gdb_valgrind in aktglobalswitches then
  1746. stabstring:=nil
  1747. else
  1748. stabstring:=stabstr_evaluate('"${name}:c=$1;",${N_FUNCTION},0,${line},0',[st]);
  1749. end;
  1750. {$endif GDB}
  1751. {****************************************************************************
  1752. TENUMSYM
  1753. ****************************************************************************}
  1754. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1755. begin
  1756. inherited create(n);
  1757. typ:=enumsym;
  1758. definition:=def;
  1759. value:=v;
  1760. { check for jumps }
  1761. if v>def.max+1 then
  1762. def.has_jumps:=true;
  1763. { update low and high }
  1764. if def.min>v then
  1765. def.setmin(v);
  1766. if def.max<v then
  1767. def.setmax(v);
  1768. order;
  1769. { nextenum:=Tenumsym(def.firstenum);
  1770. def.firstenum:=self;}
  1771. end;
  1772. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1773. begin
  1774. inherited loadsym(ppufile);
  1775. typ:=enumsym;
  1776. ppufile.getderef(definitionderef);
  1777. value:=ppufile.getlongint;
  1778. nextenum := Nil;
  1779. end;
  1780. procedure tenumsym.buildderef;
  1781. begin
  1782. definitionderef.build(definition);
  1783. end;
  1784. procedure tenumsym.deref;
  1785. begin
  1786. definition:=tenumdef(definitionderef.resolve);
  1787. order;
  1788. end;
  1789. procedure tenumsym.order;
  1790. var
  1791. sym : tenumsym;
  1792. begin
  1793. sym := tenumsym(definition.firstenum);
  1794. if sym = nil then
  1795. begin
  1796. definition.firstenum := self;
  1797. nextenum := nil;
  1798. exit;
  1799. end;
  1800. { reorder the symbols in increasing value }
  1801. if value < sym.value then
  1802. begin
  1803. nextenum := sym;
  1804. definition.firstenum := self;
  1805. end
  1806. else
  1807. begin
  1808. while (sym.value <= value) and assigned(sym.nextenum) do
  1809. sym := sym.nextenum;
  1810. nextenum := sym.nextenum;
  1811. sym.nextenum := self;
  1812. end;
  1813. end;
  1814. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1815. begin
  1816. inherited writesym(ppufile);
  1817. ppufile.putderef(definitionderef);
  1818. ppufile.putlongint(value);
  1819. ppufile.writeentry(ibenumsym);
  1820. end;
  1821. {****************************************************************************
  1822. TTYPESYM
  1823. ****************************************************************************}
  1824. constructor ttypesym.create(const n : string;const tt : ttype);
  1825. begin
  1826. inherited create(n);
  1827. typ:=typesym;
  1828. restype:=tt;
  1829. { register the typesym for the definition }
  1830. if assigned(restype.def) and
  1831. (restype.def.deftype<>errordef) and
  1832. not(assigned(restype.def.typesym)) then
  1833. restype.def.typesym:=self;
  1834. end;
  1835. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1836. begin
  1837. inherited loadsym(ppufile);
  1838. typ:=typesym;
  1839. ppufile.gettype(restype);
  1840. end;
  1841. function ttypesym.gettypedef:tdef;
  1842. begin
  1843. gettypedef:=restype.def;
  1844. end;
  1845. procedure ttypesym.buildderef;
  1846. begin
  1847. restype.buildderef;
  1848. end;
  1849. procedure ttypesym.deref;
  1850. begin
  1851. restype.resolve;
  1852. end;
  1853. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1854. begin
  1855. inherited writesym(ppufile);
  1856. ppufile.puttype(restype);
  1857. ppufile.writeentry(ibtypesym);
  1858. end;
  1859. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1860. begin
  1861. inherited load_references(ppufile,locals);
  1862. if (restype.def.deftype=recorddef) then
  1863. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1864. if (restype.def.deftype=objectdef) then
  1865. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1866. end;
  1867. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1868. var
  1869. d : tderef;
  1870. begin
  1871. d.reset;
  1872. if not inherited write_references(ppufile,locals) then
  1873. begin
  1874. { write address of this symbol if record or object
  1875. even if no real refs are there
  1876. because we need it for the symtable }
  1877. if (restype.def.deftype in [recorddef,objectdef]) then
  1878. begin
  1879. d.build(self);
  1880. ppufile.putderef(d);
  1881. ppufile.writeentry(ibsymref);
  1882. end;
  1883. end;
  1884. write_references:=true;
  1885. if (restype.def.deftype=recorddef) then
  1886. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  1887. if (restype.def.deftype=objectdef) then
  1888. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  1889. end;
  1890. {$ifdef GDB}
  1891. function ttypesym.stabstring : pchar;
  1892. var stabchar:string[2];
  1893. begin
  1894. stabstring:=nil;
  1895. if restype.def<>nil then
  1896. begin
  1897. if restype.def.deftype in tagtypes then
  1898. stabchar:='Tt'
  1899. else
  1900. stabchar:='t';
  1901. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,tstoreddef(restype.def).numberstring]);
  1902. end;
  1903. end;
  1904. {$endif GDB}
  1905. {****************************************************************************
  1906. TSYSSYM
  1907. ****************************************************************************}
  1908. constructor tsyssym.create(const n : string;l : longint);
  1909. begin
  1910. inherited create(n);
  1911. typ:=syssym;
  1912. number:=l;
  1913. end;
  1914. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1915. begin
  1916. inherited loadsym(ppufile);
  1917. typ:=syssym;
  1918. number:=ppufile.getlongint;
  1919. end;
  1920. destructor tsyssym.destroy;
  1921. begin
  1922. inherited destroy;
  1923. end;
  1924. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1925. begin
  1926. inherited writesym(ppufile);
  1927. ppufile.putlongint(number);
  1928. ppufile.writeentry(ibsyssym);
  1929. end;
  1930. {****************************************************************************
  1931. TRTTISYM
  1932. ****************************************************************************}
  1933. constructor trttisym.create(const n:string;rt:trttitype);
  1934. const
  1935. prefix : array[trttitype] of string[5]=('$rtti','$init');
  1936. begin
  1937. inherited create(prefix[rt]+n);
  1938. include(symoptions,sp_internal);
  1939. typ:=rttisym;
  1940. lab:=nil;
  1941. rttityp:=rt;
  1942. end;
  1943. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  1944. begin
  1945. inherited loadsym(ppufile);
  1946. typ:=rttisym;
  1947. lab:=nil;
  1948. rttityp:=trttitype(ppufile.getbyte);
  1949. end;
  1950. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  1951. begin
  1952. inherited writesym(ppufile);
  1953. ppufile.putbyte(byte(rttityp));
  1954. ppufile.writeentry(ibrttisym);
  1955. end;
  1956. function trttisym.mangledname : string;
  1957. const
  1958. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  1959. begin
  1960. result:=make_mangledname(prefix[rttityp],owner,Copy(name,5,255));
  1961. end;
  1962. function trttisym.get_label:tasmsymbol;
  1963. begin
  1964. { the label is always a global label }
  1965. if not assigned(lab) then
  1966. lab:=objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA);
  1967. get_label:=lab;
  1968. end;
  1969. end.
  1970. {
  1971. $Log$
  1972. Revision 1.190 2004-11-04 17:09:54 peter
  1973. fixed debuginfo for variables in staticsymtable
  1974. Revision 1.189 2004/10/31 21:45:03 peter
  1975. * generic tlocation
  1976. * move tlocation to cgutils
  1977. Revision 1.188 2004/10/15 09:14:17 mazen
  1978. - remove $IFDEF DELPHI and related code
  1979. - remove $IFDEF FPCPROCVAR and related code
  1980. Revision 1.187 2004/10/13 18:47:45 peter
  1981. * fix misplaced begin..end for self stabs
  1982. * no fpu regable for staticsymtable
  1983. Revision 1.186 2004/10/12 14:34:49 peter
  1984. * fixed visibility for procsyms
  1985. * fixed override check when there was no entry yet
  1986. Revision 1.185 2004/10/11 20:48:34 peter
  1987. * don't generate stabs for self when it is in a regvar
  1988. Revision 1.184 2004/10/11 15:48:15 peter
  1989. * small regvar for para fixes
  1990. * function tvarsym.is_regvar added
  1991. * tvarsym.getvaluesize removed, use getsize instead
  1992. Revision 1.183 2004/10/10 21:08:55 peter
  1993. * parameter regvar fixes
  1994. Revision 1.182 2004/10/10 20:22:53 peter
  1995. * symtable allocation rewritten
  1996. * loading of parameters to local temps/regs cleanup
  1997. * regvar support for parameters
  1998. * regvar support for staticsymtable (main body)
  1999. Revision 1.181 2004/10/10 09:31:28 peter
  2000. regvar ppu writing doesn't affect any crc
  2001. Revision 1.180 2004/10/08 17:09:43 peter
  2002. * tvarsym.varregable added, split vo_regable from varoptions
  2003. Revision 1.179 2004/10/06 19:26:50 jonas
  2004. * regvar fixes from Peter
  2005. Revision 1.178 2004/10/01 15:22:22 peter
  2006. * don't add stabs for register variables
  2007. Revision 1.177 2004/09/26 17:45:30 peter
  2008. * simple regvar support, not yet finished
  2009. Revision 1.176 2004/09/21 17:25:12 peter
  2010. * paraloc branch merged
  2011. Revision 1.175.4.1 2004/08/31 20:43:06 peter
  2012. * paraloc patch
  2013. Revision 1.175 2004/08/15 12:06:03 jonas
  2014. * add cprefix to procedures which are autoamtically marked as external in
  2015. macpas mode
  2016. Revision 1.174 2004/06/20 08:55:30 florian
  2017. * logs truncated
  2018. Revision 1.173 2004/06/16 20:07:09 florian
  2019. * dwarf branch merged
  2020. Revision 1.172 2004/05/22 23:32:52 peter
  2021. quote all low ascii chars in stabs
  2022. Revision 1.171 2004/05/11 22:52:48 olle
  2023. * Moved import_implicit_external to symsym
  2024. Revision 1.170 2004/05/11 18:29:41 olle
  2025. + mode macpas: support for implicit external
  2026. Revision 1.169.2.3 2004/05/01 16:02:09 peter
  2027. * POINTER_SIZE replaced with sizeof(aint)
  2028. * aint,aword,tconst*int moved to globtype
  2029. }