symsym.pas 78 KB

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