2
0

symsym.pas 81 KB

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