symsym.pas 66 KB

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