symsym.pas 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  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,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,symdef,defcmp,
  27. { ppu }
  28. ppu,finput,
  29. cclasses,
  30. { aasm }
  31. aasmbase,
  32. cpuinfo,cpubase,cgbase,cgutils,parabase
  33. ;
  34. type
  35. { this class is the base for all symbol objects }
  36. tstoredsym = class(tsym)
  37. private
  38. procedure writeentry(ppufile: tcompilerppufile; ibnr: byte);
  39. protected
  40. procedure ppuwrite_platform(ppufile: tcompilerppufile);virtual;
  41. procedure ppuload_platform(ppufile: tcompilerppufile);virtual;
  42. public
  43. constructor create(st:tsymtyp;const n : string);
  44. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  45. destructor destroy;override;
  46. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  47. end;
  48. tlabelsym = class(tstoredsym)
  49. used,
  50. defined,
  51. nonlocal : boolean;
  52. { points to the matching node, only valid resultdef pass is run and
  53. the goto<->label relation in the node tree is created, should
  54. be a tnode }
  55. code : pointer;
  56. { points to the jump buffer }
  57. jumpbuf : tstoredsym;
  58. { when the label is defined in an asm block, this points to the
  59. generated asmlabel }
  60. asmblocklabel : tasmlabel;
  61. constructor create(const n : string);virtual;
  62. constructor ppuload(ppufile:tcompilerppufile);
  63. { do not override this routine in platform-specific subclasses,
  64. override ppuwrite_platform instead }
  65. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  66. function mangledname:TSymStr;override;
  67. end;
  68. tlabelsymclass = class of tlabelsym;
  69. tunitsym = class(Tstoredsym)
  70. module : tobject; { tmodule }
  71. constructor create(const n : string;amodule : tobject);virtual;
  72. constructor ppuload(ppufile:tcompilerppufile);
  73. destructor destroy;override;
  74. { do not override this routine in platform-specific subclasses,
  75. override ppuwrite_platform instead }
  76. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  77. end;
  78. tunitsymclass = class of tunitsym;
  79. tprogramparasym = class(Tstoredsym)
  80. isoindex : dword;
  81. constructor create(const n : string;i : dword);virtual;
  82. constructor ppuload(ppufile:tcompilerppufile);
  83. destructor destroy;override;
  84. { do not override this routine in platform-specific subclasses,
  85. override ppuwrite_platform instead }
  86. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  87. end;
  88. tprogramparasymclass = class of tprogramparasym;
  89. tnamespacesym = class(Tstoredsym)
  90. unitsym:tsym;
  91. unitsymderef:tderef;
  92. constructor create(const n : string);virtual;
  93. constructor ppuload(ppufile:tcompilerppufile);
  94. { do not override this routine in platform-specific subclasses,
  95. override ppuwrite_platform instead }
  96. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  97. procedure buildderef;override;
  98. procedure deref;override;
  99. end;
  100. tnamespacesymclass = class of tnamespacesym;
  101. terrorsym = class(Tsym)
  102. constructor create;
  103. end;
  104. { tprocsym }
  105. tprocsym = class(tstoredsym)
  106. protected
  107. FProcdefList : TFPObjectList;
  108. FProcdefDerefList : TFPList;
  109. public
  110. constructor create(const n : string);virtual;
  111. constructor ppuload(ppufile:tcompilerppufile);
  112. destructor destroy;override;
  113. { writes all declarations except the specified one }
  114. procedure write_parameter_lists(skipdef:tprocdef);
  115. { tests, if all procedures definitions are defined and not }
  116. { only forward }
  117. procedure check_forward; virtual;
  118. { do not override this routine in platform-specific subclasses,
  119. override ppuwrite_platform instead }
  120. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  121. procedure buildderef;override;
  122. procedure deref;override;
  123. function find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  124. function find_bytype_parameterless(pt:Tproctypeoption):Tprocdef;
  125. function find_procdef_bypara(para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  126. function find_procdef_bytype_and_para(pt:Tproctypeoption;para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  127. function find_procdef_byoptions(ops:tprocoptions): Tprocdef;
  128. function find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  129. function find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  130. function find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  131. property ProcdefList:TFPObjectList read FProcdefList;
  132. end;
  133. tprocsymclass = class of tprocsym;
  134. ttypesym = class(Tstoredsym)
  135. public
  136. typedef : tdef;
  137. typedefderef : tderef;
  138. fprettyname : ansistring;
  139. constructor create(const n : string;def:tdef);virtual;
  140. destructor destroy;override;
  141. constructor ppuload(ppufile:tcompilerppufile);
  142. { do not override this routine in platform-specific subclasses,
  143. override ppuwrite_platform instead }
  144. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  145. procedure buildderef;override;
  146. procedure deref;override;
  147. function prettyname : string;override;
  148. end;
  149. ttypesymclass = class of ttypesym;
  150. tabstractvarsym = class(tstoredsym)
  151. varoptions : tvaroptions;
  152. varspez : tvarspez; { sets the type of access }
  153. varregable : tvarregable;
  154. varstate : tvarstate;
  155. { Has the address of this variable potentially escaped the }
  156. { block in which is was declared? }
  157. { could also be part of tabstractnormalvarsym, but there's }
  158. { one byte left here till the next 4 byte alignment }
  159. addr_taken : boolean;
  160. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  161. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  162. procedure ppuwrite(ppufile:tcompilerppufile);override;
  163. procedure buildderef;override;
  164. procedure deref;override;
  165. function getsize : asizeint;
  166. function getpackedbitsize : longint;
  167. function is_regvar(refpara: boolean):boolean;
  168. private
  169. _vardef : tdef;
  170. vardefderef : tderef;
  171. procedure setregable;
  172. procedure setvardef(const def: tdef);
  173. procedure setvardef_and_regable(def:tdef);
  174. public
  175. property vardef: tdef read _vardef write setvardef_and_regable;
  176. end;
  177. tfieldvarsym = class(tabstractvarsym)
  178. { offset in record/object, for bitpacked fields the offset is
  179. given in bit, else in bytes }
  180. fieldoffset : asizeint;
  181. externalname : pshortstring;
  182. {$ifdef symansistr}
  183. cachedmangledname: TSymStr; { mangled name for ObjC or Java }
  184. {$else symansistr}
  185. cachedmangledname: pshortstring; { mangled name for ObjC or Java }
  186. {$endif symansistr}
  187. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);virtual;
  188. constructor ppuload(ppufile:tcompilerppufile);
  189. { do not override this routine in platform-specific subclasses,
  190. override ppuwrite_platform instead }
  191. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  192. procedure set_externalname(const s:string);virtual;
  193. function mangledname:TSymStr;override;
  194. destructor destroy;override;
  195. end;
  196. tfieldvarsymclass = class of tfieldvarsym;
  197. tabstractnormalvarsym = class(tabstractvarsym)
  198. defaultconstsym : tsym;
  199. defaultconstsymderef : tderef;
  200. { register/reference for local var }
  201. localloc : TLocation;
  202. { initial location so it can still be initialized later after the location was changed by SSA }
  203. initialloc : TLocation;
  204. { current registers for register variables with moving register numbers }
  205. currentregloc : TLocation;
  206. { migrated to a parentfpstruct because of nested access (not written to ppu, because not important and would change interface crc) }
  207. inparentfpstruct : boolean;
  208. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  209. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  210. function globalasmsym: boolean;
  211. procedure ppuwrite(ppufile:tcompilerppufile);override;
  212. procedure buildderef;override;
  213. procedure deref;override;
  214. end;
  215. tlocalvarsym = class(tabstractnormalvarsym)
  216. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);virtual;
  217. constructor ppuload(ppufile:tcompilerppufile);
  218. { do not override this routine in platform-specific subclasses,
  219. override ppuwrite_platform instead }
  220. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  221. end;
  222. tlocalvarsymclass = class of tlocalvarsym;
  223. tparavarsym = class(tabstractnormalvarsym)
  224. paraloc : array[tcallercallee] of TCGPara;
  225. paranr : word; { position of this parameter }
  226. { in MacPas mode, "univ" parameters mean that type checking should
  227. be disabled, except that the size of the passed parameter must
  228. match the size of the formal parameter }
  229. univpara : boolean;
  230. {$ifdef EXTDEBUG}
  231. eqval : tequaltype;
  232. {$endif EXTDEBUG}
  233. constructor create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);virtual;
  234. constructor ppuload(ppufile:tcompilerppufile);
  235. destructor destroy;override;
  236. { do not override this routine in platform-specific subclasses,
  237. override ppuwrite_platform instead }
  238. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  239. function needs_finalization: boolean;
  240. end;
  241. tparavarsymclass = class of tparavarsym;
  242. tstaticvarsym = class(tabstractnormalvarsym)
  243. protected
  244. {$ifdef symansistr}
  245. _mangledbasename,
  246. _mangledname : TSymStr;
  247. {$else symansistr}
  248. _mangledbasename,
  249. _mangledname : pshortstring;
  250. {$endif symansistr}
  251. public
  252. section : ansistring;
  253. { if a text buffer has been defined as being initialized from command line
  254. parameters as it is done by iso pascal with the program symbols,
  255. isoindex contains the parameter number }
  256. isoindex : dword;
  257. { if this static variable was created based on a class field variable then this is set
  258. to the symbol of the corresponding class field }
  259. fieldvarsym : tfieldvarsym;
  260. fieldvarsymderef : tderef;
  261. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);virtual;
  262. constructor create_dll(const n : string;vsp:tvarspez;def:tdef);virtual;
  263. constructor create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);virtual;
  264. constructor create_from_fieldvar(const n:string;fieldvar:tfieldvarsym);virtual;
  265. constructor ppuload(ppufile:tcompilerppufile);
  266. destructor destroy;override;
  267. { do not override this routine in platform-specific subclasses,
  268. override ppuwrite_platform instead }
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  270. procedure buildderef;override;
  271. procedure deref;override;
  272. function mangledname:TSymStr;override;
  273. procedure set_mangledbasename(const s: TSymStr);
  274. function mangledbasename: TSymStr;
  275. procedure set_mangledname(const s:TSymStr);virtual;
  276. procedure set_raw_mangledname(const s:TSymStr);
  277. end;
  278. tstaticvarsymclass = class of tstaticvarsym;
  279. tabsolutevarsym = class(tabstractvarsym)
  280. public
  281. abstyp : absolutetyp;
  282. asmname : pshortstring;
  283. addroffset : aword;
  284. ref : tpropaccesslist;
  285. constructor create(const n : string;def:tdef);virtual;
  286. constructor create_ref(const n : string;def:tdef;_ref:tpropaccesslist);virtual;
  287. destructor destroy;override;
  288. constructor ppuload(ppufile:tcompilerppufile);
  289. procedure buildderef;override;
  290. procedure deref;override;
  291. function mangledname : TSymStr;override;
  292. { do not override this routine in platform-specific subclasses,
  293. override ppuwrite_platform instead }
  294. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  295. end;
  296. tabsolutevarsymclass = class of tabsolutevarsym;
  297. tpropaccesslisttypes=(palt_none,palt_read,palt_write,palt_stored);
  298. tpropertysym = class(Tstoredsym)
  299. protected
  300. procedure finalize_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef); virtual;
  301. public
  302. propoptions : tpropertyoptions;
  303. overriddenpropsym : tpropertysym;
  304. overriddenpropsymderef : tderef;
  305. propdef : tdef;
  306. propdefderef : tderef;
  307. indexdef : tdef;
  308. indexdefderef : tderef;
  309. index,
  310. default : longint;
  311. dispid : longint;
  312. propaccesslist: array[tpropaccesslisttypes] of tpropaccesslist;
  313. parast : tsymtable;
  314. constructor create(const n : string);virtual;
  315. destructor destroy;override;
  316. constructor ppuload(ppufile:tcompilerppufile);
  317. function getsize : asizeint;
  318. { do not override this routine in platform-specific subclasses,
  319. override ppuwrite_platform instead }
  320. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  321. procedure buildderef;override;
  322. procedure deref;override;
  323. function getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  324. { copies the settings of the current propertysym to p; a bit like
  325. a form of getcopy, but without the name }
  326. procedure makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  327. procedure add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  328. procedure add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  329. { set up the accessors for this property }
  330. procedure add_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  331. procedure register_override(overriddenprop: tpropertysym);
  332. { inherit the read/write property }
  333. procedure inherit_accessor(getset: tpropaccesslisttypes); virtual;
  334. end;
  335. tpropertysymclass = class of tpropertysym;
  336. tconstvalue = record
  337. case integer of
  338. 0: (valueord : tconstexprint);
  339. 1: (valueordptr : tconstptruint);
  340. 2: (valueptr : pointer; len : longint);
  341. end;
  342. tconstsym = class(tstoredsym)
  343. constdef : tdef;
  344. constdefderef : tderef;
  345. consttyp : tconsttyp;
  346. value : tconstvalue;
  347. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);virtual;
  348. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);virtual;
  349. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);virtual;
  350. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint;def:tdef);virtual;
  351. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);virtual;
  352. constructor ppuload(ppufile:tcompilerppufile);
  353. destructor destroy;override;
  354. procedure buildderef;override;
  355. procedure deref;override;
  356. { do not override this routine in platform-specific subclasses,
  357. override ppuwrite_platform instead }
  358. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  359. end;
  360. tconstsymclass = class of tconstsym;
  361. tenumsym = class(Tstoredsym)
  362. value : longint;
  363. definition : tenumdef;
  364. definitionderef : tderef;
  365. constructor create(const n : string;def : tenumdef;v : longint);virtual;
  366. constructor ppuload(ppufile:tcompilerppufile);
  367. { do not override this routine in platform-specific subclasses,
  368. override ppuwrite_platform instead }
  369. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  370. procedure buildderef;override;
  371. procedure deref;override;
  372. end;
  373. tenumsymclass = class of tenumsym;
  374. tsyssym = class(Tstoredsym)
  375. number : longint;
  376. constructor create(const n : string;l : longint);virtual;
  377. constructor ppuload(ppufile:tcompilerppufile);
  378. destructor destroy;override;
  379. { do not override this routine in platform-specific subclasses,
  380. override ppuwrite_platform instead }
  381. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  382. end;
  383. tsyssymclass = class of tsyssym;
  384. const
  385. maxmacrolen=16*1024;
  386. type
  387. pmacrobuffer = ^tmacrobuffer;
  388. tmacrobuffer = array[0..maxmacrolen-1] of char;
  389. tmacro = class(tstoredsym)
  390. {Normally true, but false when a previously defined macro is undef-ed}
  391. defined : boolean;
  392. {True if this is a mac style compiler variable, in which case no macro
  393. substitutions shall be done.}
  394. is_compiler_var : boolean;
  395. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  396. {e. g. an IFDEF which returns false, will not be registered as used,}
  397. {since there is no place to register its use. }
  398. is_used : boolean;
  399. buftext : pchar;
  400. buflen : longint;
  401. constructor create(const n : string);
  402. constructor ppuload(ppufile:tcompilerppufile);
  403. { do not override this routine in platform-specific subclasses,
  404. override ppuwrite_platform instead }
  405. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  406. destructor destroy;override;
  407. function GetCopy:tmacro;
  408. end;
  409. { tPtrDefHashSet }
  410. tPtrDefHashSet = class(THashSet)
  411. public
  412. constructor Create;virtual;
  413. end;
  414. tPtrDefHashSetClass = class of tPtrDefHashSet;
  415. var
  416. generrorsym : tsym;
  417. clabelsym: tlabelsymclass;
  418. cunitsym: tunitsymclass;
  419. cprogramparasym: tprogramparasymclass;
  420. cnamespacesym: tnamespacesymclass;
  421. cprocsym: tprocsymclass;
  422. ctypesym: ttypesymclass;
  423. cfieldvarsym: tfieldvarsymclass;
  424. clocalvarsym: tlocalvarsymclass;
  425. cparavarsym: tparavarsymclass;
  426. cstaticvarsym: tstaticvarsymclass;
  427. cabsolutevarsym: tabsolutevarsymclass;
  428. cpropertysym: tpropertysymclass;
  429. cconstsym: tconstsymclass;
  430. cenumsym: tenumsymclass;
  431. csyssym: tsyssymclass;
  432. cPtrDefHashSet : tPtrDefHashSetClass = tPtrDefHashSet;
  433. { generate internal static field name based on regular field name }
  434. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  435. function get_high_value_sym(vs: tparavarsym):tsym; { marking it as inline causes IE 200311075 during loading from ppu file }
  436. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  437. implementation
  438. uses
  439. { global }
  440. verbose,
  441. { target }
  442. systems,
  443. { symtable }
  444. defutil,symtable,
  445. fmodule,
  446. { tree }
  447. node,
  448. { aasm }
  449. aasmtai,aasmdata,
  450. { codegen }
  451. paramgr,
  452. procinfo
  453. ;
  454. {****************************************************************************
  455. Helpers
  456. ****************************************************************************}
  457. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  458. begin
  459. result:='$_static_'+fieldname;
  460. end;
  461. function get_high_value_sym(vs: tparavarsym):tsym;
  462. begin
  463. result := tsym(vs.owner.Find('high'+vs.name));
  464. end;
  465. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  466. begin
  467. if not assigned(srsym) then
  468. internalerror(200602051);
  469. if sp_hint_deprecated in symoptions then
  470. if (sp_has_deprecated_msg in symoptions) and (deprecatedmsg <> nil) then
  471. Message2(sym_w_deprecated_symbol_with_msg,srsym.realname,deprecatedmsg^)
  472. else
  473. Message1(sym_w_deprecated_symbol,srsym.realname);
  474. if sp_hint_experimental in symoptions then
  475. Message1(sym_w_experimental_symbol,srsym.realname);
  476. if sp_hint_platform in symoptions then
  477. Message1(sym_w_non_portable_symbol,srsym.realname);
  478. if sp_hint_library in symoptions then
  479. Message1(sym_w_library_symbol,srsym.realname);
  480. if sp_hint_unimplemented in symoptions then
  481. Message1(sym_w_non_implemented_symbol,srsym.realname);
  482. end;
  483. {****************************************************************************
  484. TSYM (base for all symtypes)
  485. ****************************************************************************}
  486. constructor tstoredsym.create(st:tsymtyp;const n : string);
  487. begin
  488. inherited create(st,n);
  489. { Register in current_module }
  490. if assigned(current_module) then
  491. begin
  492. current_module.symlist.Add(self);
  493. SymId:=current_module.symlist.Count-1;
  494. end;
  495. end;
  496. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  497. begin
  498. SymId:=ppufile.getlongint;
  499. inherited Create(st,ppufile.getstring);
  500. { Register symbol }
  501. current_module.symlist[SymId]:=self;
  502. ppufile.getposinfo(fileinfo);
  503. visibility:=tvisibility(ppufile.getbyte);
  504. ppufile.getsmallset(symoptions);
  505. if sp_has_deprecated_msg in symoptions then
  506. deprecatedmsg:=stringdup(ppufile.getstring)
  507. else
  508. deprecatedmsg:=nil;
  509. end;
  510. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  511. var
  512. oldintfcrc : boolean;
  513. begin
  514. ppufile.putlongint(SymId);
  515. ppufile.putstring(realname);
  516. ppufile.putposinfo(fileinfo);
  517. ppufile.putbyte(byte(visibility));
  518. { symoptions can differ between interface and implementation, except
  519. for overload (this is checked in pdecsub.proc_add_definition() )
  520. These differences can lead to compiler crashes, so ignore them.
  521. This does mean that changing e.g. the "deprecated" state of a symbol
  522. by itself will not trigger a recompilation of dependent units.
  523. }
  524. oldintfcrc:=ppufile.do_interface_crc;
  525. ppufile.do_interface_crc:=false;
  526. ppufile.putsmallset(symoptions);
  527. if sp_has_deprecated_msg in symoptions then
  528. ppufile.putstring(deprecatedmsg^);
  529. ppufile.do_interface_crc:=oldintfcrc;
  530. end;
  531. procedure tstoredsym.writeentry(ppufile: tcompilerppufile; ibnr: byte);
  532. begin
  533. ppuwrite_platform(ppufile);
  534. ppufile.writeentry(ibnr);
  535. end;
  536. procedure tstoredsym.ppuwrite_platform(ppufile: tcompilerppufile);
  537. begin
  538. { by default: do nothing }
  539. end;
  540. procedure tstoredsym.ppuload_platform(ppufile: tcompilerppufile);
  541. begin
  542. { by default: do nothing }
  543. end;
  544. destructor tstoredsym.destroy;
  545. begin
  546. inherited destroy;
  547. end;
  548. {****************************************************************************
  549. TLABELSYM
  550. ****************************************************************************}
  551. constructor tlabelsym.create(const n : string);
  552. begin
  553. inherited create(labelsym,n);
  554. used:=false;
  555. defined:=false;
  556. nonlocal:=false;
  557. code:=nil;
  558. end;
  559. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  560. begin
  561. inherited ppuload(labelsym,ppufile);
  562. code:=nil;
  563. used:=false;
  564. nonlocal:=false;
  565. defined:=true;
  566. ppuload_platform(ppufile);
  567. end;
  568. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  569. begin
  570. if owner.symtabletype=globalsymtable then
  571. Message(sym_e_ill_label_decl)
  572. else
  573. begin
  574. inherited ppuwrite(ppufile);
  575. writeentry(ppufile,iblabelsym);
  576. end;
  577. end;
  578. function tlabelsym.mangledname:TSymStr;
  579. begin
  580. if (asmblocklabel=nil) then
  581. begin
  582. if nonlocal then
  583. current_asmdata.getglobaljumplabel(asmblocklabel)
  584. else
  585. current_asmdata.getjumplabel(asmblocklabel);
  586. end;
  587. result:=asmblocklabel.name;
  588. end;
  589. {****************************************************************************
  590. TUNITSYM
  591. ****************************************************************************}
  592. constructor tunitsym.create(const n : string;amodule : tobject);
  593. begin
  594. inherited create(unitsym,n);
  595. module:=amodule;
  596. end;
  597. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  598. begin
  599. inherited ppuload(unitsym,ppufile);
  600. module:=nil;
  601. ppuload_platform(ppufile);
  602. end;
  603. destructor tunitsym.destroy;
  604. begin
  605. inherited destroy;
  606. end;
  607. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  608. begin
  609. inherited ppuwrite(ppufile);
  610. writeentry(ppufile,ibunitsym);
  611. end;
  612. {****************************************************************************
  613. TPROGRAMPARASYM
  614. ****************************************************************************}
  615. constructor tprogramparasym.create(const n : string; i : dword);
  616. begin
  617. inherited create(programparasym,n);
  618. isoindex:=i;
  619. end;
  620. constructor tprogramparasym.ppuload(ppufile : tcompilerppufile);
  621. begin
  622. { program parameter syms (iso pascal style) might be never written to a ppu }
  623. internalerror(2015050102);
  624. end;
  625. destructor tprogramparasym.destroy;
  626. begin
  627. inherited destroy;
  628. end;
  629. procedure tprogramparasym.ppuwrite(ppufile : tcompilerppufile);
  630. begin
  631. { program parameter syms (iso pascal style) might be never written to a ppu }
  632. internalerror(2015050101);
  633. end;
  634. {****************************************************************************
  635. TNAMESPACESYM
  636. ****************************************************************************}
  637. constructor tnamespacesym.create(const n : string);
  638. begin
  639. inherited create(namespacesym,n);
  640. unitsym:=nil;
  641. end;
  642. constructor tnamespacesym.ppuload(ppufile:tcompilerppufile);
  643. begin
  644. inherited ppuload(namespacesym,ppufile);
  645. ppufile.getderef(unitsymderef);
  646. ppuload_platform(ppufile);
  647. end;
  648. procedure tnamespacesym.ppuwrite(ppufile:tcompilerppufile);
  649. begin
  650. inherited ppuwrite(ppufile);
  651. ppufile.putderef(unitsymderef);
  652. writeentry(ppufile,ibnamespacesym);
  653. end;
  654. procedure tnamespacesym.buildderef;
  655. begin
  656. inherited buildderef;
  657. unitsymderef.build(unitsym);
  658. end;
  659. procedure tnamespacesym.deref;
  660. begin
  661. inherited deref;
  662. unitsym:=tsym(unitsymderef.resolve);
  663. end;
  664. {****************************************************************************
  665. TPROCSYM
  666. ****************************************************************************}
  667. constructor tprocsym.create(const n : string);
  668. var
  669. i: longint;
  670. begin
  671. if not(ts_lowercase_proc_start in current_settings.targetswitches) or
  672. (n='') then
  673. inherited create(procsym,n)
  674. else
  675. begin
  676. { YToX -> yToX
  677. RC64Encode -> rc64Encode
  678. Test -> test
  679. }
  680. i:=2;
  681. while i<=length(n) do
  682. begin
  683. if not(n[i] in ['A'..'Z']) then
  684. begin
  685. if (i>2) and
  686. (n[i] in ['a'..'z']) then
  687. dec(i);
  688. break;
  689. end;
  690. inc(i);
  691. end;
  692. inherited create(procsym,lower(copy(n,1,i-1))+copy(n,i,length(n)));
  693. end;
  694. FProcdefList:=TFPObjectList.Create(false);
  695. FProcdefderefList:=nil;
  696. { the tprocdef have their own symoptions, make the procsym
  697. always visible }
  698. visibility:=vis_public;
  699. end;
  700. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  701. var
  702. pdderef : tderef;
  703. i,
  704. pdcnt : longint;
  705. begin
  706. inherited ppuload(procsym,ppufile);
  707. FProcdefList:=TFPObjectList.Create(false);
  708. FProcdefDerefList:=TFPList.Create;
  709. pdcnt:=ppufile.getword;
  710. for i:=1 to pdcnt do
  711. begin
  712. ppufile.getderef(pdderef);
  713. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  714. end;
  715. ppuload_platform(ppufile);
  716. end;
  717. destructor tprocsym.destroy;
  718. begin
  719. FProcdefList.Free;
  720. if assigned(FProcdefDerefList) then
  721. FProcdefDerefList.Free;
  722. inherited destroy;
  723. end;
  724. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  725. var
  726. i : longint;
  727. d : tderef;
  728. begin
  729. inherited ppuwrite(ppufile);
  730. if fprocdefdereflist=nil then
  731. internalerror(2013121801);
  732. ppufile.putword(FProcdefDerefList.Count);
  733. for i:=0 to FProcdefDerefList.Count-1 do
  734. begin
  735. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  736. ppufile.putderef(d);
  737. end;
  738. writeentry(ppufile,ibprocsym);
  739. end;
  740. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  741. var
  742. i : longint;
  743. pd : tprocdef;
  744. begin
  745. for i:=0 to ProcdefList.Count-1 do
  746. begin
  747. pd:=tprocdef(ProcdefList[i]);
  748. if pd<>skipdef then
  749. MessagePos1(pd.fileinfo,sym_e_param_list,pd.fullprocname(false));
  750. end;
  751. end;
  752. procedure tprocsym.check_forward;
  753. var
  754. i : longint;
  755. pd : tprocdef;
  756. begin
  757. for i:=0 to ProcdefList.Count-1 do
  758. begin
  759. pd:=tprocdef(ProcdefList[i]);
  760. if (pd.owner=owner) and (pd.forwarddef) then
  761. begin
  762. { For mode macpas. Make implicit externals (procedures declared in the interface
  763. section which do not have a counterpart in the implementation)
  764. to be an imported procedure }
  765. if (m_mac in current_settings.modeswitches) and
  766. (pd.interfacedef) then
  767. begin
  768. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  769. if (not current_module.interface_only) then
  770. MessagePos1(pd.fileinfo,sym_w_forward_not_resolved,pd.fullprocname(false));
  771. end
  772. else
  773. begin
  774. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  775. end;
  776. { Turn further error messages off }
  777. pd.forwarddef:=false;
  778. end;
  779. end;
  780. end;
  781. procedure tprocsym.buildderef;
  782. var
  783. i : longint;
  784. pd : tprocdef;
  785. d : tderef;
  786. begin
  787. if not assigned(FProcdefDerefList) then
  788. FProcdefDerefList:=TFPList.Create
  789. else
  790. FProcdefDerefList.Clear;
  791. for i:=0 to ProcdefList.Count-1 do
  792. begin
  793. pd:=tprocdef(ProcdefList[i]);
  794. { only write the proc definitions that belong
  795. to this procsym and are in the global symtable }
  796. if pd.owner=owner then
  797. begin
  798. d.build(pd);
  799. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  800. end;
  801. end;
  802. end;
  803. procedure tprocsym.deref;
  804. var
  805. i : longint;
  806. pd : tprocdef;
  807. d : tderef;
  808. begin
  809. { Clear all procdefs }
  810. ProcdefList.Clear;
  811. if not assigned(FProcdefDerefList) then
  812. internalerror(200611031);
  813. for i:=0 to FProcdefDerefList.Count-1 do
  814. begin
  815. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  816. pd:=tprocdef(d.resolve);
  817. ProcdefList.Add(pd);
  818. end;
  819. end;
  820. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  821. var
  822. i : longint;
  823. pd : tprocdef;
  824. begin
  825. result:=nil;
  826. for i:=0 to ProcdefList.Count-1 do
  827. begin
  828. pd:=tprocdef(ProcdefList[i]);
  829. if pd.proctypeoption=pt then
  830. begin
  831. result:=pd;
  832. exit;
  833. end;
  834. end;
  835. end;
  836. function tprocsym.find_bytype_parameterless(pt: Tproctypeoption): Tprocdef;
  837. var
  838. i,j : longint;
  839. pd : tprocdef;
  840. found : boolean;
  841. begin
  842. result:=nil;
  843. for i:=0 to ProcdefList.Count-1 do
  844. begin
  845. pd:=tprocdef(ProcdefList[i]);
  846. if (pd.proctypeoption=pt) then
  847. begin
  848. found:=true;
  849. for j:=0 to pd.paras.count-1 do
  850. begin
  851. if not(vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  852. begin
  853. found:=false;
  854. break;
  855. end;
  856. end;
  857. if found then
  858. begin
  859. result:=pd;
  860. exit;
  861. end;
  862. end;
  863. end;
  864. end;
  865. function check_procdef_paras(pd:tprocdef;para:TFPObjectList;retdef:tdef;
  866. cpoptions:tcompare_paras_options): tprocdef;
  867. var
  868. eq: tequaltype;
  869. begin
  870. result:=nil;
  871. if assigned(retdef) then
  872. eq:=compare_defs(retdef,pd.returndef,nothingn)
  873. else
  874. eq:=te_equal;
  875. if (eq>=te_equal) or
  876. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  877. begin
  878. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  879. if (eq>=te_equal) or
  880. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  881. begin
  882. result:=pd;
  883. exit;
  884. end;
  885. end;
  886. end;
  887. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  888. cpoptions:tcompare_paras_options):Tprocdef;
  889. var
  890. i : longint;
  891. pd : tprocdef;
  892. begin
  893. result:=nil;
  894. for i:=0 to ProcdefList.Count-1 do
  895. begin
  896. pd:=tprocdef(ProcdefList[i]);
  897. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  898. if assigned(result) then
  899. exit;
  900. end;
  901. end;
  902. function Tprocsym.find_procdef_bytype_and_para(pt:Tproctypeoption;
  903. para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  904. var
  905. i : longint;
  906. pd : tprocdef;
  907. begin
  908. result:=nil;
  909. for i:=0 to ProcdefList.Count-1 do
  910. begin
  911. pd:=tprocdef(ProcdefList[i]);
  912. if pd.proctypeoption=pt then
  913. begin
  914. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  915. if assigned(result) then
  916. exit;
  917. end;
  918. end;
  919. end;
  920. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  921. var
  922. i : longint;
  923. pd : tprocdef;
  924. begin
  925. result:=nil;
  926. for i:=0 to ProcdefList.Count-1 do
  927. begin
  928. pd:=tprocdef(ProcdefList[i]);
  929. if ops * pd.procoptions = ops then
  930. begin
  931. result:=pd;
  932. exit;
  933. end;
  934. end;
  935. end;
  936. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  937. var
  938. i : longint;
  939. bestpd,
  940. pd : tprocdef;
  941. eq,besteq : tequaltype;
  942. sym: tsym;
  943. ps: tprocsym;
  944. begin
  945. { This function will return the pprocdef of pprocsym that
  946. is the best match for procvardef. When there are multiple
  947. matches it returns nil.}
  948. result:=nil;
  949. bestpd:=nil;
  950. besteq:=te_incompatible;
  951. ps:=self;
  952. repeat
  953. for i:=0 to ps.ProcdefList.Count-1 do
  954. begin
  955. pd:=tprocdef(ps.ProcdefList[i]);
  956. eq:=proc_to_procvar_equal(pd,d,false);
  957. if eq>=te_convert_l1 then
  958. begin
  959. { multiple procvars with the same equal level }
  960. if assigned(bestpd) and
  961. (besteq=eq) then
  962. exit;
  963. if eq>besteq then
  964. begin
  965. besteq:=eq;
  966. bestpd:=pd;
  967. end;
  968. end;
  969. end;
  970. { maybe TODO: also search class helpers? -- this code is similar to
  971. what happens in htypechk in
  972. tcallcandidates.collect_overloads_in_struct: keep searching in
  973. parent types in case the currently found procdef is marked as
  974. "overload" and we haven't found a proper match yet }
  975. if assigned(ps.owner.defowner) and
  976. (ps.owner.defowner.typ=objectdef) and
  977. assigned(tobjectdef(ps.owner.defowner).childof) and
  978. (not assigned(bestpd) or
  979. (po_overload in bestpd.procoptions)) then
  980. begin
  981. sym:=tsym(tobjectdef(ps.owner.defowner).childof.symtable.find(ps.name));
  982. if assigned(sym) and
  983. (sym.typ=procsym) then
  984. ps:=tprocsym(sym)
  985. else
  986. ps:=nil;
  987. end
  988. else
  989. ps:=nil;
  990. until (besteq>=te_equal) or
  991. not assigned(ps);
  992. result:=bestpd;
  993. end;
  994. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  995. var
  996. paraidx, realparamcount,
  997. i, j : longint;
  998. bestpd,
  999. hpd,
  1000. pd : tprocdef;
  1001. convtyp : tconverttype;
  1002. eq : tequaltype;
  1003. begin
  1004. { This function will return the pprocdef of pprocsym that
  1005. is the best match for fromdef and todef. }
  1006. result:=nil;
  1007. bestpd:=nil;
  1008. besteq:=te_incompatible;
  1009. for i:=0 to ProcdefList.Count-1 do
  1010. begin
  1011. pd:=tprocdef(ProcdefList[i]);
  1012. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  1013. continue;
  1014. if (equal_defs(todef,pd.returndef) or
  1015. { shortstrings of different lengths are ok as result }
  1016. (is_shortstring(todef) and is_shortstring(pd.returndef))) and
  1017. { the result type must be always really equal and not an alias,
  1018. if you mess with this code, check tw4093 }
  1019. ((todef=pd.returndef) or
  1020. (
  1021. not(df_unique in todef.defoptions) and
  1022. not(df_unique in pd.returndef.defoptions)
  1023. )
  1024. ) then
  1025. begin
  1026. paraidx:=0;
  1027. { ignore vs_hidden parameters }
  1028. while (paraidx<pd.paras.count) and
  1029. assigned(pd.paras[paraidx]) and
  1030. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  1031. inc(paraidx);
  1032. realparamcount:=0;
  1033. for j := 0 to pd.paras.Count-1 do
  1034. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  1035. inc(realparamcount);
  1036. if (paraidx<pd.paras.count) and
  1037. assigned(pd.paras[paraidx]) and
  1038. (realparamcount = 1) then
  1039. begin
  1040. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  1041. { alias? if yes, only l1 choice,
  1042. if you mess with this code, check tw4093 }
  1043. if (eq=te_exact) and
  1044. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  1045. ((df_unique in fromdef.defoptions) or
  1046. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  1047. eq:=te_convert_l1;
  1048. if eq=te_exact then
  1049. begin
  1050. besteq:=eq;
  1051. result:=pd;
  1052. exit;
  1053. end;
  1054. if eq>besteq then
  1055. begin
  1056. bestpd:=pd;
  1057. besteq:=eq;
  1058. end;
  1059. end;
  1060. end;
  1061. end;
  1062. result:=bestpd;
  1063. end;
  1064. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  1065. var
  1066. paraidx, realparamcount,
  1067. i, j : longint;
  1068. bestpd,
  1069. hpd,
  1070. pd : tprocdef;
  1071. current : tpropertysym;
  1072. convtyp : tconverttype;
  1073. eq : tequaltype;
  1074. begin
  1075. { This function will return the pprocdef of pprocsym that
  1076. is the best match for fromdef and todef. }
  1077. result:=nil;
  1078. bestpd:=nil;
  1079. besteq:=te_incompatible;
  1080. for i:=0 to ProcdefList.Count-1 do
  1081. begin
  1082. pd:=tprocdef(ProcdefList[i]);
  1083. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  1084. continue;
  1085. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  1086. continue;
  1087. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  1088. if (current = nil) then
  1089. continue;
  1090. // compare current result def with the todef
  1091. if (equal_defs(todef, current.propdef) or
  1092. { shortstrings of different lengths are ok as result }
  1093. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  1094. { the result type must be always really equal and not an alias,
  1095. if you mess with this code, check tw4093 }
  1096. ((todef=current.propdef) or
  1097. (
  1098. not(df_unique in todef.defoptions) and
  1099. not(df_unique in current.propdef.defoptions)
  1100. )
  1101. ) then
  1102. begin
  1103. paraidx:=0;
  1104. { ignore vs_hidden parameters }
  1105. while (paraidx<pd.paras.count) and
  1106. assigned(pd.paras[paraidx]) and
  1107. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  1108. inc(paraidx);
  1109. realparamcount:=0;
  1110. for j := 0 to pd.paras.Count-1 do
  1111. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  1112. inc(realparamcount);
  1113. if (paraidx<pd.paras.count) and
  1114. assigned(pd.paras[paraidx]) and
  1115. (realparamcount = 1) then
  1116. begin
  1117. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  1118. { alias? if yes, only l1 choice,
  1119. if you mess with this code, check tw4093 }
  1120. if (eq=te_exact) and
  1121. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  1122. ((df_unique in fromdef.defoptions) or
  1123. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  1124. eq:=te_convert_l1;
  1125. if eq=te_exact then
  1126. begin
  1127. besteq:=eq;
  1128. result:=pd;
  1129. exit;
  1130. end;
  1131. if eq>besteq then
  1132. begin
  1133. bestpd:=pd;
  1134. besteq:=eq;
  1135. end;
  1136. end;
  1137. end;
  1138. end;
  1139. result:=bestpd;
  1140. end;
  1141. {****************************************************************************
  1142. TERRORSYM
  1143. ****************************************************************************}
  1144. constructor terrorsym.create;
  1145. begin
  1146. inherited create(errorsym,'');
  1147. end;
  1148. {****************************************************************************
  1149. TPROPERTYSYM
  1150. ****************************************************************************}
  1151. procedure tpropertysym.finalize_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  1152. begin
  1153. { do nothing by default }
  1154. end;
  1155. constructor tpropertysym.create(const n : string);
  1156. var
  1157. pap : tpropaccesslisttypes;
  1158. begin
  1159. inherited create(propertysym,n);
  1160. propoptions:=[];
  1161. index:=0;
  1162. default:=0;
  1163. propdef:=nil;
  1164. indexdef:=nil;
  1165. parast:=nil;
  1166. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1167. propaccesslist[pap]:=tpropaccesslist.create;
  1168. end;
  1169. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1170. var
  1171. pap : tpropaccesslisttypes;
  1172. begin
  1173. inherited ppuload(propertysym,ppufile);
  1174. ppufile.getsmallset(propoptions);
  1175. if ppo_overrides in propoptions then
  1176. ppufile.getderef(overriddenpropsymderef);
  1177. ppufile.getderef(propdefderef);
  1178. index:=ppufile.getlongint;
  1179. default:=ppufile.getlongint;
  1180. ppufile.getderef(indexdefderef);
  1181. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1182. propaccesslist[pap]:=ppufile.getpropaccesslist;
  1183. ppuload_platform(ppufile);
  1184. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1185. begin
  1186. parast:=tparasymtable.create(nil,0);
  1187. tparasymtable(parast).ppuload(ppufile);
  1188. end
  1189. else
  1190. parast:=nil;
  1191. end;
  1192. destructor tpropertysym.destroy;
  1193. var
  1194. pap : tpropaccesslisttypes;
  1195. begin
  1196. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1197. propaccesslist[pap].free;
  1198. parast.free;
  1199. inherited destroy;
  1200. end;
  1201. procedure tpropertysym.buildderef;
  1202. var
  1203. pap : tpropaccesslisttypes;
  1204. begin
  1205. propdefderef.build(propdef);
  1206. indexdefderef.build(indexdef);
  1207. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1208. propaccesslist[pap].buildderef;
  1209. if ppo_overrides in propoptions then
  1210. overriddenpropsymderef.build(overriddenpropsym)
  1211. else
  1212. if ppo_hasparameters in propoptions then
  1213. tparasymtable(parast).buildderef;
  1214. end;
  1215. procedure tpropertysym.deref;
  1216. var
  1217. pap : tpropaccesslisttypes;
  1218. begin
  1219. indexdef:=tdef(indexdefderef.resolve);
  1220. propdef:=tdef(propdefderef.resolve);
  1221. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1222. propaccesslist[pap].resolve;
  1223. if ppo_overrides in propoptions then
  1224. begin
  1225. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  1226. if ppo_hasparameters in propoptions then
  1227. parast:=overriddenpropsym.parast.getcopy;
  1228. end
  1229. else
  1230. if ppo_hasparameters in propoptions then
  1231. tparasymtable(parast).deref
  1232. end;
  1233. function tpropertysym.getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  1234. var
  1235. hpropsym : tpropertysym;
  1236. begin
  1237. result:=false;
  1238. { find property in the overridden list }
  1239. hpropsym:=self;
  1240. repeat
  1241. plist:=hpropsym.propaccesslist[pap];
  1242. if not plist.empty then
  1243. begin
  1244. result:=true;
  1245. exit;
  1246. end;
  1247. hpropsym:=hpropsym.overriddenpropsym;
  1248. until not assigned(hpropsym);
  1249. end;
  1250. procedure tpropertysym.add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  1251. var
  1252. i: integer;
  1253. orig, hparavs: tparavarsym;
  1254. begin
  1255. for i := 0 to parast.SymList.Count - 1 do
  1256. begin
  1257. orig:=tparavarsym(parast.SymList[i]);
  1258. if assigned(readprocdef) then
  1259. begin
  1260. hparavs:=cparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1261. readprocdef.parast.insert(hparavs);
  1262. end;
  1263. if assigned(writeprocdef) then
  1264. begin
  1265. hparavs:=cparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1266. writeprocdef.parast.insert(hparavs);
  1267. end;
  1268. end;
  1269. end;
  1270. procedure tpropertysym.add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  1271. var
  1272. hparavs: tparavarsym;
  1273. begin
  1274. inc(paranr);
  1275. if assigned(readprocdef) then
  1276. begin
  1277. hparavs:=cparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1278. readprocdef.parast.insert(hparavs);
  1279. end;
  1280. if assigned(writeprocdef) then
  1281. begin
  1282. hparavs:=cparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1283. writeprocdef.parast.insert(hparavs);
  1284. end;
  1285. end;
  1286. procedure tpropertysym.add_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  1287. var
  1288. cpo: tcompare_paras_options;
  1289. begin
  1290. case sym.typ of
  1291. procsym :
  1292. begin
  1293. { search procdefs matching accessordef }
  1294. { we ignore hidden stuff here because the property access symbol might have
  1295. non default calling conventions which might change the hidden stuff;
  1296. see tw3216.pp (FK) }
  1297. cpo:=[cpo_allowdefaults,cpo_ignorehidden];
  1298. { allow var-parameters for setters in case of VARPROPSETTER+ }
  1299. if (getset=palt_write) and
  1300. (cs_varpropsetter in current_settings.localswitches) then
  1301. include(cpo,cpo_ignorevarspez);
  1302. propaccesslist[getset].procdef:=tprocsym(sym).find_procdef_bypara(accessordef.paras,accessordef.returndef,cpo);
  1303. if not assigned(propaccesslist[getset].procdef) or
  1304. { because of cpo_ignorehidden we need to compare if it is a static class method and we have a class property }
  1305. ((sp_static in symoptions)<>tprocdef(propaccesslist[getset].procdef).no_self_node) then
  1306. Message(parser_e_ill_property_access_sym)
  1307. else
  1308. finalize_getter_or_setter_for_sym(getset,sym,fielddef,accessordef);
  1309. end;
  1310. fieldvarsym :
  1311. begin
  1312. if not assigned(fielddef) then
  1313. internalerror(200310071);
  1314. if compare_defs(fielddef,propdef,nothingn)>=te_equal then
  1315. begin
  1316. { property parameters are allowed if this is
  1317. an indexed property, because the index is then
  1318. the parameter.
  1319. Note: In the help of Kylix it is written
  1320. that it isn't allowed, but the compiler accepts it (PFV) }
  1321. if (ppo_hasparameters in propoptions) or
  1322. ((sp_static in symoptions) <> (sp_static in sym.symoptions)) then
  1323. Message(parser_e_ill_property_access_sym)
  1324. else
  1325. finalize_getter_or_setter_for_sym(getset,sym,fielddef,accessordef);
  1326. end
  1327. else
  1328. IncompatibleTypes(fielddef,propdef);
  1329. end;
  1330. else
  1331. Message(parser_e_ill_property_access_sym);
  1332. end;
  1333. end;
  1334. procedure tpropertysym.register_override(overriddenprop: tpropertysym);
  1335. begin
  1336. overriddenpropsym:=tpropertysym(overriddenprop);
  1337. include(propoptions,ppo_overrides);
  1338. end;
  1339. procedure tpropertysym.inherit_accessor(getset: tpropaccesslisttypes);
  1340. begin
  1341. { nothing to do by default }
  1342. end;
  1343. procedure tpropertysym.makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  1344. begin
  1345. { inherit all type related entries }
  1346. p.indexdef:=indexdef;
  1347. p.propdef:=propdef;
  1348. p.index:=index;
  1349. p.default:=default;
  1350. p.propoptions:=propoptions;
  1351. paranr:=0;
  1352. if ppo_hasparameters in propoptions then
  1353. begin
  1354. p.parast:=parast.getcopy;
  1355. p.add_accessor_parameters(readprocdef,writeprocdef);
  1356. paranr:=p.parast.SymList.Count;
  1357. end;
  1358. if ppo_indexed in p.propoptions then
  1359. p.add_index_parameter(paranr,readprocdef,writeprocdef);
  1360. end;
  1361. function tpropertysym.getsize : asizeint;
  1362. begin
  1363. getsize:=0;
  1364. end;
  1365. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1366. var
  1367. pap : tpropaccesslisttypes;
  1368. begin
  1369. inherited ppuwrite(ppufile);
  1370. ppufile.putsmallset(propoptions);
  1371. if ppo_overrides in propoptions then
  1372. ppufile.putderef(overriddenpropsymderef);
  1373. ppufile.putderef(propdefderef);
  1374. ppufile.putlongint(index);
  1375. ppufile.putlongint(default);
  1376. ppufile.putderef(indexdefderef);
  1377. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1378. ppufile.putpropaccesslist(propaccesslist[pap]);
  1379. writeentry(ppufile,ibpropertysym);
  1380. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1381. tparasymtable(parast).ppuwrite(ppufile);
  1382. end;
  1383. {****************************************************************************
  1384. TABSTRACTVARSYM
  1385. ****************************************************************************}
  1386. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1387. begin
  1388. inherited create(st,n);
  1389. vardef:=def;
  1390. varspez:=vsp;
  1391. varstate:=vs_declared;
  1392. varoptions:=vopts;
  1393. end;
  1394. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1395. begin
  1396. inherited ppuload(st,ppufile);
  1397. varstate:=vs_readwritten;
  1398. varspez:=tvarspez(ppufile.getbyte);
  1399. varregable:=tvarregable(ppufile.getbyte);
  1400. addr_taken:=boolean(ppufile.getbyte);
  1401. ppufile.getderef(vardefderef);
  1402. ppufile.getsmallset(varoptions);
  1403. end;
  1404. procedure tabstractvarsym.buildderef;
  1405. begin
  1406. vardefderef.build(vardef);
  1407. end;
  1408. procedure tabstractvarsym.deref;
  1409. begin
  1410. { assigning vardef also updates varregable. We just loaded this }
  1411. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  1412. { tw7817b.pp: the address is taken of a local variable in an }
  1413. { inlined procedure -> must remain non-regable when inlining) }
  1414. setvardef(tdef(vardefderef.resolve));
  1415. end;
  1416. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1417. var
  1418. oldintfcrc : boolean;
  1419. begin
  1420. inherited ppuwrite(ppufile);
  1421. ppufile.putbyte(byte(varspez));
  1422. oldintfcrc:=ppufile.do_crc;
  1423. ppufile.do_crc:=false;
  1424. ppufile.putbyte(byte(varregable));
  1425. ppufile.putbyte(byte(addr_taken));
  1426. ppufile.do_crc:=oldintfcrc;
  1427. ppufile.putderef(vardefderef);
  1428. ppufile.putsmallset(varoptions);
  1429. end;
  1430. function tabstractvarsym.getsize : asizeint;
  1431. begin
  1432. if assigned(vardef) and
  1433. ((vardef.typ<>arraydef) or
  1434. is_dynamic_array(vardef) or
  1435. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1436. result:=vardef.size
  1437. else
  1438. result:=0;
  1439. end;
  1440. function tabstractvarsym.getpackedbitsize : longint;
  1441. begin
  1442. { bitpacking is only done for ordinals }
  1443. if not is_ordinal(vardef) then
  1444. internalerror(2006082010);
  1445. result:=vardef.packedbitsize;
  1446. end;
  1447. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1448. begin
  1449. { Register variables are not allowed in the following cases:
  1450. - regvars are disabled
  1451. - exceptions are used (after an exception is raised the contents of the
  1452. registers is not valid anymore)
  1453. - it has a local copy
  1454. - the value needs to be in memory (i.e. reference counted) }
  1455. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1456. not(pi_has_assembler_block in current_procinfo.flags) and
  1457. not(pi_uses_exceptions in current_procinfo.flags) and
  1458. not(pi_has_interproclabel in current_procinfo.flags) and
  1459. not(vo_has_local_copy in varoptions) and
  1460. ((refpara and
  1461. (varregable <> vr_none)) or
  1462. (not refpara and
  1463. not(varregable in [vr_none,vr_addr])))
  1464. {$if not defined(powerpc) and not defined(powerpc64)}
  1465. and ((vardef.typ <> recorddef) or
  1466. (varregable = vr_addr) or
  1467. not(varstate in [vs_written,vs_readwritten]));
  1468. {$endif}
  1469. end;
  1470. procedure tabstractvarsym.setvardef_and_regable(def:tdef);
  1471. begin
  1472. setvardef(def);
  1473. setregable;
  1474. end;
  1475. procedure tabstractvarsym.setregable;
  1476. begin
  1477. { can we load the value into a register ? }
  1478. if not assigned(owner) or
  1479. (owner.symtabletype in [localsymtable, parasymtable]) or
  1480. (
  1481. (owner.symtabletype=staticsymtable) and
  1482. not(cs_create_pic in current_settings.moduleswitches)
  1483. ) then
  1484. begin
  1485. if (tstoreddef(vardef).is_intregable and
  1486. { we could keep all aint*2 records in registers, but this causes
  1487. too much spilling for CPUs with 8-16 registers so keep only
  1488. parameters and function results of this type in register because they are normally
  1489. passed by register anyways
  1490. This can be changed, as soon as we have full ssa (FK) }
  1491. ((typ=paravarsym) or
  1492. (vo_is_funcret in varoptions) or
  1493. (tstoreddef(vardef).typ<>recorddef) or
  1494. (tstoreddef(vardef).size<=sizeof(aint)))) or
  1495. { const parameters can be put into registers if the def fits into a register }
  1496. (tstoreddef(vardef).is_const_intregable and
  1497. (typ=paravarsym) and
  1498. (varspez=vs_const)) then
  1499. varregable:=vr_intreg
  1500. else if tstoreddef(vardef).is_fpuregable then
  1501. begin
  1502. if use_vectorfpu(vardef) then
  1503. varregable:=vr_mmreg
  1504. else
  1505. varregable:=vr_fpureg;
  1506. end;
  1507. end;
  1508. end;
  1509. procedure tabstractvarsym.setvardef(const def: tdef);
  1510. begin
  1511. _vardef := def;
  1512. end;
  1513. {****************************************************************************
  1514. TFIELDVARSYM
  1515. ****************************************************************************}
  1516. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1517. begin
  1518. inherited create(fieldvarsym,n,vsp,def,vopts);
  1519. fieldoffset:=-1;
  1520. end;
  1521. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1522. begin
  1523. inherited ppuload(fieldvarsym,ppufile);
  1524. fieldoffset:=ppufile.getaint;
  1525. if (vo_has_mangledname in varoptions) then
  1526. externalname:=stringdup(ppufile.getstring)
  1527. else
  1528. externalname:=nil;
  1529. ppuload_platform(ppufile);
  1530. end;
  1531. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1532. begin
  1533. inherited ppuwrite(ppufile);
  1534. ppufile.putaint(fieldoffset);
  1535. if (vo_has_mangledname in varoptions) then
  1536. ppufile.putstring(externalname^);
  1537. writeentry(ppufile,ibfieldvarsym);
  1538. end;
  1539. procedure tfieldvarsym.set_externalname(const s: string);
  1540. begin
  1541. internalerror(2014033001);
  1542. end;
  1543. function tfieldvarsym.mangledname:TSymStr;
  1544. var
  1545. srsym : tsym;
  1546. srsymtable : tsymtable;
  1547. begin
  1548. if sp_static in symoptions then
  1549. begin
  1550. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1551. result:=srsym.mangledname
  1552. { when generating the debug info for the module in which the }
  1553. { symbol is defined, the localsymtable of that module is }
  1554. { already popped from the symtablestack }
  1555. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1556. result:=srsym.mangledname
  1557. else
  1558. internalerror(2007012501);
  1559. end
  1560. else if is_objcclass(tdef(owner.defowner)) then
  1561. begin
  1562. {$ifdef symansistr}
  1563. if cachedmangledname<>'' then
  1564. result:=cachedmangledname
  1565. {$else symansistr}
  1566. if assigned(cachedmangledname) then
  1567. result:=cachedmangledname^
  1568. {$endif symansistr}
  1569. else
  1570. begin
  1571. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1572. {$ifdef symansistr}
  1573. cachedmangledname:=result;
  1574. {$else symansistr}
  1575. cachedmangledname:=stringdup(result);
  1576. {$endif symansistr}
  1577. end;
  1578. end
  1579. else
  1580. result:=inherited mangledname;
  1581. end;
  1582. destructor tfieldvarsym.destroy;
  1583. begin
  1584. {$ifndef symansistr}
  1585. stringdispose(cachedmangledname);
  1586. {$endif symansistr}
  1587. stringdispose(externalname);
  1588. inherited destroy;
  1589. end;
  1590. {****************************************************************************
  1591. TABSTRACTNORMALVARSYM
  1592. ****************************************************************************}
  1593. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1594. begin
  1595. inherited create(st,n,vsp,def,vopts);
  1596. fillchar(localloc,sizeof(localloc),0);
  1597. fillchar(currentregloc,sizeof(localloc),0);
  1598. fillchar(initialloc,sizeof(initialloc),0);
  1599. defaultconstsym:=nil;
  1600. end;
  1601. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1602. begin
  1603. inherited ppuload(st,ppufile);
  1604. fillchar(localloc,sizeof(localloc),0);
  1605. fillchar(currentregloc,sizeof(localloc),0);
  1606. fillchar(initialloc,sizeof(initialloc),0);
  1607. ppufile.getderef(defaultconstsymderef);
  1608. end;
  1609. function tabstractnormalvarsym.globalasmsym: boolean;
  1610. begin
  1611. result:=
  1612. (owner.symtabletype=globalsymtable) or
  1613. (create_smartlink and
  1614. not(tf_smartlink_sections in target_info.flags)) or
  1615. DLLSource or
  1616. (assigned(current_procinfo) and
  1617. ((po_inline in current_procinfo.procdef.procoptions) or
  1618. { globalasmsym is called normally before the body of a subroutine is parsed
  1619. so we cannot know if it will be auto inlined, so make all symbols of it
  1620. global if asked }
  1621. (cs_opt_autoinline in current_settings.optimizerswitches))
  1622. ) or
  1623. (vo_is_public in varoptions);
  1624. end;
  1625. procedure tabstractnormalvarsym.buildderef;
  1626. begin
  1627. inherited buildderef;
  1628. defaultconstsymderef.build(defaultconstsym);
  1629. end;
  1630. procedure tabstractnormalvarsym.deref;
  1631. begin
  1632. inherited deref;
  1633. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1634. end;
  1635. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1636. begin
  1637. inherited ppuwrite(ppufile);
  1638. ppufile.putderef(defaultconstsymderef);
  1639. end;
  1640. {****************************************************************************
  1641. Tstaticvarsym
  1642. ****************************************************************************}
  1643. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1644. begin
  1645. inherited create(staticvarsym,n,vsp,def,vopts);
  1646. {$ifdef symansistr}
  1647. _mangledname:='';
  1648. {$else symansistr}
  1649. _mangledname:=nil;
  1650. {$endif symansistr}
  1651. end;
  1652. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1653. begin
  1654. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1655. end;
  1656. constructor tstaticvarsym.create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  1657. begin
  1658. tstaticvarsym(self).create(n,vsp,def,[]);
  1659. set_mangledname(mangled);
  1660. end;
  1661. constructor tstaticvarsym.create_from_fieldvar(const n: string;fieldvar:tfieldvarsym);
  1662. begin
  1663. create(internal_static_field_name(n),vs_value,fieldvar.vardef,[]);
  1664. fieldvarsym:=fieldvar;
  1665. end;
  1666. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1667. begin
  1668. inherited ppuload(staticvarsym,ppufile);
  1669. {$ifdef symansistr}
  1670. if vo_has_mangledname in varoptions then
  1671. _mangledname:=ppufile.getansistring
  1672. else
  1673. _mangledname:='';
  1674. {$else symansistr}
  1675. if vo_has_mangledname in varoptions then
  1676. _mangledname:=stringdup(ppufile.getstring)
  1677. else
  1678. _mangledname:=nil;
  1679. {$endif symansistr}
  1680. if vo_has_section in varoptions then
  1681. section:=ppufile.getansistring;
  1682. ppufile.getderef(fieldvarsymderef);
  1683. ppuload_platform(ppufile);
  1684. end;
  1685. destructor tstaticvarsym.destroy;
  1686. begin
  1687. {$ifndef symansistr}
  1688. if assigned(_mangledname) then
  1689. begin
  1690. {$ifdef MEMDEBUG}
  1691. memmanglednames.start;
  1692. {$endif MEMDEBUG}
  1693. stringdispose(_mangledname);
  1694. {$ifdef MEMDEBUG}
  1695. memmanglednames.stop;
  1696. {$endif MEMDEBUG}
  1697. end;
  1698. stringdispose(_mangledbasename);
  1699. {$endif}
  1700. inherited destroy;
  1701. end;
  1702. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1703. begin
  1704. inherited ppuwrite(ppufile);
  1705. { write mangledname rather than _mangledname in case the mangledname
  1706. has not been calculated yet (can happen in case only the
  1707. mangledbasename has been set) }
  1708. if vo_has_mangledname in varoptions then
  1709. {$ifdef symansistr}
  1710. ppufile.putansistring(mangledname);
  1711. {$else symansistr}
  1712. ppufile.putstring(mangledname);
  1713. {$endif symansistr}
  1714. if vo_has_section in varoptions then
  1715. ppufile.putansistring(section);
  1716. ppufile.putderef(fieldvarsymderef);
  1717. writeentry(ppufile,ibstaticvarsym);
  1718. end;
  1719. procedure tstaticvarsym.buildderef;
  1720. begin
  1721. inherited buildderef;
  1722. fieldvarsymderef.build(fieldvarsym);
  1723. end;
  1724. procedure tstaticvarsym.deref;
  1725. begin
  1726. inherited deref;
  1727. fieldvarsym:=tfieldvarsym(fieldvarsymderef.resolve);
  1728. end;
  1729. function tstaticvarsym.mangledname:TSymStr;
  1730. var
  1731. usename,
  1732. prefix : TSymStr;
  1733. begin
  1734. {$ifdef symansistr}
  1735. if _mangledname='' then
  1736. {$else symansistr}
  1737. if not assigned(_mangledname) then
  1738. {$endif symansistr}
  1739. begin
  1740. if (vo_is_typed_const in varoptions) then
  1741. prefix:='TC'
  1742. else
  1743. prefix:='U';
  1744. {$ifdef symansistr}
  1745. if _mangledbasename='' then
  1746. usename:=name
  1747. else
  1748. usename:=_mangledbasename;
  1749. _mangledname:=make_mangledname(prefix,owner,usename);
  1750. {$else symansistr}
  1751. if not assigned(_mangledbasename) then
  1752. usename:=name
  1753. else
  1754. usename:=_mangledbasename^;
  1755. _mangledname:=stringdup(make_mangledname(prefix,owner,usename));
  1756. {$endif symansistr}
  1757. end;
  1758. {$ifdef symansistr}
  1759. result:=_mangledname;
  1760. {$else symansistr}
  1761. result:=_mangledname^;
  1762. {$endif symansistr}
  1763. end;
  1764. procedure tstaticvarsym.set_mangledbasename(const s: TSymStr);
  1765. begin
  1766. {$ifdef symansistr}
  1767. _mangledbasename:=s;
  1768. _mangledname:='';
  1769. {$else symansistr}
  1770. stringdispose(_mangledname);
  1771. stringdispose(_mangledbasename);
  1772. _mangledbasename:=stringdup(s);
  1773. {$endif symansistr}
  1774. include(varoptions,vo_has_mangledname);
  1775. end;
  1776. function tstaticvarsym.mangledbasename: TSymStr;
  1777. begin
  1778. {$ifdef symansistr}
  1779. result:=_mangledbasename;
  1780. {$else symansistr}
  1781. if assigned(_mangledbasename) then
  1782. result:=_mangledbasename^
  1783. else
  1784. result:='';
  1785. {$endif symansistr}
  1786. end;
  1787. procedure tstaticvarsym.set_mangledname(const s:TSymStr);
  1788. begin
  1789. {$ifdef symansistr}
  1790. _mangledname:=s;
  1791. {$else symansistr}
  1792. stringdispose(_mangledname);
  1793. _mangledname:=stringdup(s);
  1794. {$endif symansistr}
  1795. include(varoptions,vo_has_mangledname);
  1796. end;
  1797. procedure tstaticvarsym.set_raw_mangledname(const s: TSymStr);
  1798. begin
  1799. {$ifndef symansistr}
  1800. stringdispose(_mangledname);
  1801. _mangledname:=stringdup(s);
  1802. {$else}
  1803. _mangledname:=s;
  1804. {$endif}
  1805. include(varoptions,vo_has_mangledname);
  1806. end;
  1807. {****************************************************************************
  1808. TLOCALVARSYM
  1809. ****************************************************************************}
  1810. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1811. begin
  1812. inherited create(localvarsym,n,vsp,def,vopts);
  1813. end;
  1814. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1815. begin
  1816. inherited ppuload(localvarsym,ppufile);
  1817. ppuload_platform(ppufile);
  1818. end;
  1819. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1820. begin
  1821. inherited ppuwrite(ppufile);
  1822. writeentry(ppufile,iblocalvarsym);
  1823. end;
  1824. {****************************************************************************
  1825. TPARAVARSYM
  1826. ****************************************************************************}
  1827. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1828. begin
  1829. inherited create(paravarsym,n,vsp,def,vopts);
  1830. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) and
  1831. not(vo_is_funcret in vopts) then
  1832. varstate := vs_initialised;
  1833. paranr:=nr;
  1834. paraloc[calleeside].init;
  1835. paraloc[callerside].init;
  1836. end;
  1837. destructor tparavarsym.destroy;
  1838. begin
  1839. paraloc[calleeside].done;
  1840. paraloc[callerside].done;
  1841. inherited destroy;
  1842. end;
  1843. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1844. var
  1845. b : byte;
  1846. begin
  1847. inherited ppuload(paravarsym,ppufile);
  1848. paranr:=ppufile.getword;
  1849. univpara:=boolean(ppufile.getbyte);
  1850. { The var state of parameter symbols is fixed after writing them so
  1851. we write them to the unit file.
  1852. This enables constant folding for inline procedures loaded from units
  1853. }
  1854. varstate:=tvarstate(ppufile.getbyte);
  1855. { read usage info }
  1856. refs:=ppufile.getbyte;
  1857. paraloc[calleeside].init;
  1858. paraloc[callerside].init;
  1859. if vo_has_explicit_paraloc in varoptions then
  1860. paraloc[callerside].ppuload(ppufile);
  1861. ppuload_platform(ppufile);
  1862. end;
  1863. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1864. var
  1865. oldintfcrc : boolean;
  1866. begin
  1867. inherited ppuwrite(ppufile);
  1868. ppufile.putword(paranr);
  1869. ppufile.putbyte(byte(univpara));
  1870. { The var state of parameter symbols is fixed after writing them so
  1871. we write them to the unit file.
  1872. This enables constant folding for inline procedures loaded from units
  1873. }
  1874. oldintfcrc:=ppufile.do_crc;
  1875. ppufile.do_crc:=false;
  1876. ppufile.putbyte(ord(varstate));
  1877. { write also info about the usage of parameters,
  1878. the absolute usage does not matter }
  1879. ppufile.putbyte(min(1,refs));
  1880. ppufile.do_crc:=oldintfcrc;
  1881. if vo_has_explicit_paraloc in varoptions then
  1882. begin
  1883. paraloc[callerside].check_simple_location;
  1884. paraloc[callerside].ppuwrite(ppufile);
  1885. end;
  1886. writeentry(ppufile,ibparavarsym);
  1887. end;
  1888. function tparavarsym.needs_finalization:boolean;
  1889. begin
  1890. result:=(varspez=vs_value) and
  1891. (is_managed_type(vardef) or
  1892. (
  1893. (not (tabstractprocdef(owner.defowner).proccalloption in cdecl_pocalls)) and
  1894. (not paramanager.use_stackalloc) and
  1895. (is_open_array(vardef) or is_array_of_const(vardef))
  1896. )
  1897. );
  1898. end;
  1899. {****************************************************************************
  1900. TABSOLUTEVARSYM
  1901. ****************************************************************************}
  1902. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1903. begin
  1904. inherited create(absolutevarsym,n,vs_value,def,[]);
  1905. ref:=nil;
  1906. end;
  1907. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1908. begin
  1909. inherited create(absolutevarsym,n,vs_value,def,[]);
  1910. ref:=_ref;
  1911. end;
  1912. destructor tabsolutevarsym.destroy;
  1913. begin
  1914. if assigned(ref) then
  1915. ref.free;
  1916. inherited destroy;
  1917. end;
  1918. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1919. begin
  1920. inherited ppuload(absolutevarsym,ppufile);
  1921. ref:=nil;
  1922. asmname:=nil;
  1923. abstyp:=absolutetyp(ppufile.getbyte);
  1924. case abstyp of
  1925. tovar :
  1926. ref:=ppufile.getpropaccesslist;
  1927. toasm :
  1928. asmname:=stringdup(ppufile.getstring);
  1929. toaddr :
  1930. addroffset:=ppufile.getaword;
  1931. end;
  1932. ppuload_platform(ppufile);
  1933. end;
  1934. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1935. begin
  1936. inherited ppuwrite(ppufile);
  1937. ppufile.putbyte(byte(abstyp));
  1938. case abstyp of
  1939. tovar :
  1940. ppufile.putpropaccesslist(ref);
  1941. toasm :
  1942. ppufile.putstring(asmname^);
  1943. toaddr :
  1944. ppufile.putaword(addroffset);
  1945. end;
  1946. writeentry(ppufile,ibabsolutevarsym);
  1947. end;
  1948. procedure tabsolutevarsym.buildderef;
  1949. begin
  1950. inherited buildderef;
  1951. if (abstyp=tovar) then
  1952. ref.buildderef;
  1953. end;
  1954. procedure tabsolutevarsym.deref;
  1955. begin
  1956. inherited deref;
  1957. { own absolute deref }
  1958. if (abstyp=tovar) then
  1959. ref.resolve;
  1960. end;
  1961. function tabsolutevarsym.mangledname : TSymStr;
  1962. begin
  1963. case abstyp of
  1964. toasm :
  1965. mangledname:=asmname^;
  1966. toaddr :
  1967. mangledname:='$'+tostr(addroffset);
  1968. else
  1969. internalerror(200411062);
  1970. end;
  1971. end;
  1972. {****************************************************************************
  1973. TCONSTSYM
  1974. ****************************************************************************}
  1975. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1976. begin
  1977. inherited create(constsym,n);
  1978. fillchar(value, sizeof(value), #0);
  1979. consttyp:=t;
  1980. value.valueord:=v;
  1981. constdef:=def;
  1982. end;
  1983. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1984. begin
  1985. inherited create(constsym,n);
  1986. fillchar(value, sizeof(value), #0);
  1987. consttyp:=t;
  1988. value.valueordptr:=v;
  1989. constdef:=def;
  1990. end;
  1991. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1992. begin
  1993. inherited create(constsym,n);
  1994. fillchar(value, sizeof(value), #0);
  1995. consttyp:=t;
  1996. value.valueptr:=v;
  1997. constdef:=def;
  1998. end;
  1999. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint;def: tdef);
  2000. begin
  2001. inherited create(constsym,n);
  2002. fillchar(value, sizeof(value), #0);
  2003. consttyp:=t;
  2004. value.valueptr:=str;
  2005. if assigned(def) then
  2006. constdef:=def
  2007. else
  2008. constdef:=getarraydef(cansichartype,l);
  2009. value.len:=l;
  2010. end;
  2011. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  2012. begin
  2013. inherited create(constsym,n);
  2014. fillchar(value, sizeof(value), #0);
  2015. consttyp:=t;
  2016. pcompilerwidestring(value.valueptr):=pw;
  2017. constdef:=getarraydef(cwidechartype,getlengthwidestring(pw));
  2018. value.len:=getlengthwidestring(pw);
  2019. end;
  2020. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  2021. var
  2022. pd : pbestreal;
  2023. ps : pnormalset;
  2024. pc : pchar;
  2025. pw : pcompilerwidestring;
  2026. i : longint;
  2027. begin
  2028. inherited ppuload(constsym,ppufile);
  2029. constdef:=nil;
  2030. consttyp:=tconsttyp(ppufile.getbyte);
  2031. fillchar(value, sizeof(value), #0);
  2032. case consttyp of
  2033. constord :
  2034. begin
  2035. ppufile.getderef(constdefderef);
  2036. value.valueord:=ppufile.getexprint;
  2037. end;
  2038. constpointer :
  2039. begin
  2040. ppufile.getderef(constdefderef);
  2041. value.valueordptr:=ppufile.getptruint;
  2042. end;
  2043. constwstring :
  2044. begin
  2045. initwidestring(pw);
  2046. setlengthwidestring(pw,ppufile.getlongint);
  2047. { don't use getdata, because the compilerwidechars may have to
  2048. be byteswapped
  2049. }
  2050. {$if sizeof(tcompilerwidechar) = 2}
  2051. for i:=0 to pw^.len-1 do
  2052. pw^.data[i]:=ppufile.getword;
  2053. {$elseif sizeof(tcompilerwidechar) = 4}
  2054. for i:=0 to pw^.len-1 do
  2055. pw^.data[i]:=cardinal(ppufile.getlongint);
  2056. {$else}
  2057. {$error Unsupported tcompilerwidechar size}
  2058. {$endif}
  2059. pcompilerwidestring(value.valueptr):=pw;
  2060. end;
  2061. conststring,
  2062. constresourcestring :
  2063. begin
  2064. ppufile.getderef(constdefderef);
  2065. value.len:=ppufile.getlongint;
  2066. getmem(pc,value.len+1);
  2067. ppufile.getdata(pc^,value.len);
  2068. pc[value.len]:=#0;
  2069. value.valueptr:=pc;
  2070. end;
  2071. constreal :
  2072. begin
  2073. ppufile.getderef(constdefderef);
  2074. new(pd);
  2075. pd^:=ppufile.getreal;
  2076. value.valueptr:=pd;
  2077. end;
  2078. constset :
  2079. begin
  2080. ppufile.getderef(constdefderef);
  2081. new(ps);
  2082. ppufile.getnormalset(ps^);
  2083. value.valueptr:=ps;
  2084. end;
  2085. constguid :
  2086. begin
  2087. ppufile.getderef(constdefderef);
  2088. new(pguid(value.valueptr));
  2089. ppufile.getdata(value.valueptr^,sizeof(tguid));
  2090. end;
  2091. constnil :
  2092. ppufile.getderef(constdefderef);
  2093. else
  2094. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  2095. end;
  2096. ppuload_platform(ppufile);
  2097. end;
  2098. destructor tconstsym.destroy;
  2099. begin
  2100. case consttyp of
  2101. conststring,
  2102. constresourcestring :
  2103. freemem(pchar(value.valueptr),value.len+1);
  2104. constwstring :
  2105. donewidestring(pcompilerwidestring(value.valueptr));
  2106. constreal :
  2107. dispose(pbestreal(value.valueptr));
  2108. constset :
  2109. dispose(pnormalset(value.valueptr));
  2110. constguid :
  2111. dispose(pguid(value.valueptr));
  2112. end;
  2113. inherited destroy;
  2114. end;
  2115. procedure tconstsym.buildderef;
  2116. begin
  2117. case consttyp of
  2118. constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constguid:
  2119. constdefderef.build(constdef);
  2120. constwstring:
  2121. ;
  2122. else
  2123. internalerror(2015120802);
  2124. end;
  2125. end;
  2126. procedure tconstsym.deref;
  2127. begin
  2128. case consttyp of
  2129. constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constguid:
  2130. constdef:=tdef(constdefderef.resolve);
  2131. constwstring:
  2132. constdef:=getarraydef(cwidechartype,getlengthwidestring(pcompilerwidestring(value.valueptr)));
  2133. else
  2134. internalerror(2015120801);
  2135. end
  2136. end;
  2137. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  2138. begin
  2139. inherited ppuwrite(ppufile);
  2140. ppufile.putbyte(byte(consttyp));
  2141. case consttyp of
  2142. constnil :
  2143. ppufile.putderef(constdefderef);
  2144. constord :
  2145. begin
  2146. ppufile.putderef(constdefderef);
  2147. ppufile.putexprint(value.valueord);
  2148. end;
  2149. constpointer :
  2150. begin
  2151. ppufile.putderef(constdefderef);
  2152. ppufile.putptruint(value.valueordptr);
  2153. end;
  2154. constwstring :
  2155. begin
  2156. { no need to store the def, we can reconstruct it }
  2157. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  2158. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  2159. end;
  2160. conststring,
  2161. constresourcestring :
  2162. begin
  2163. ppufile.putderef(constdefderef);
  2164. ppufile.putlongint(value.len);
  2165. ppufile.putdata(pchar(value.valueptr)^,value.len);
  2166. end;
  2167. constreal :
  2168. begin
  2169. ppufile.putderef(constdefderef);
  2170. ppufile.putreal(pbestreal(value.valueptr)^);
  2171. end;
  2172. constset :
  2173. begin
  2174. ppufile.putderef(constdefderef);
  2175. ppufile.putnormalset(value.valueptr^);
  2176. end;
  2177. constguid :
  2178. begin
  2179. ppufile.putderef(constdefderef);
  2180. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2181. end;
  2182. else
  2183. internalerror(13);
  2184. end;
  2185. writeentry(ppufile,ibconstsym);
  2186. end;
  2187. {****************************************************************************
  2188. TENUMSYM
  2189. ****************************************************************************}
  2190. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2191. begin
  2192. inherited create(enumsym,n);
  2193. definition:=def;
  2194. value:=v;
  2195. end;
  2196. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2197. begin
  2198. inherited ppuload(enumsym,ppufile);
  2199. ppufile.getderef(definitionderef);
  2200. value:=ppufile.getlongint;
  2201. ppuload_platform(ppufile);
  2202. end;
  2203. procedure tenumsym.buildderef;
  2204. begin
  2205. definitionderef.build(definition);
  2206. end;
  2207. procedure tenumsym.deref;
  2208. begin
  2209. definition:=tenumdef(definitionderef.resolve);
  2210. end;
  2211. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2212. begin
  2213. inherited ppuwrite(ppufile);
  2214. ppufile.putderef(definitionderef);
  2215. ppufile.putlongint(value);
  2216. writeentry(ppufile,ibenumsym);
  2217. end;
  2218. {****************************************************************************
  2219. TTYPESYM
  2220. ****************************************************************************}
  2221. constructor ttypesym.create(const n : string;def:tdef);
  2222. begin
  2223. inherited create(typesym,n);
  2224. typedef:=def;
  2225. { register the typesym for the definition }
  2226. if assigned(typedef) and
  2227. (typedef.typ<>errordef) and
  2228. not(assigned(typedef.typesym)) then
  2229. typedef.typesym:=self;
  2230. end;
  2231. destructor ttypesym.destroy;
  2232. begin
  2233. inherited destroy;
  2234. end;
  2235. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2236. begin
  2237. inherited ppuload(typesym,ppufile);
  2238. ppufile.getderef(typedefderef);
  2239. fprettyname:=ppufile.getansistring;
  2240. ppuload_platform(ppufile);
  2241. end;
  2242. procedure ttypesym.buildderef;
  2243. begin
  2244. typedefderef.build(typedef);
  2245. end;
  2246. procedure ttypesym.deref;
  2247. begin
  2248. typedef:=tdef(typedefderef.resolve);
  2249. end;
  2250. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2251. begin
  2252. inherited ppuwrite(ppufile);
  2253. ppufile.putderef(typedefderef);
  2254. ppufile.putansistring(fprettyname);
  2255. writeentry(ppufile,ibtypesym);
  2256. end;
  2257. function ttypesym.prettyname : string;
  2258. begin
  2259. if fprettyname<>'' then
  2260. result:=fprettyname
  2261. else
  2262. result:=inherited prettyname;
  2263. end;
  2264. {****************************************************************************
  2265. TSYSSYM
  2266. ****************************************************************************}
  2267. constructor tsyssym.create(const n : string;l : longint);
  2268. begin
  2269. inherited create(syssym,n);
  2270. number:=l;
  2271. end;
  2272. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2273. begin
  2274. inherited ppuload(syssym,ppufile);
  2275. number:=ppufile.getlongint;
  2276. ppuload_platform(ppufile);
  2277. end;
  2278. destructor tsyssym.destroy;
  2279. begin
  2280. inherited destroy;
  2281. end;
  2282. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2283. begin
  2284. inherited ppuwrite(ppufile);
  2285. ppufile.putlongint(number);
  2286. writeentry(ppufile,ibsyssym);
  2287. end;
  2288. {*****************************************************************************
  2289. TMacro
  2290. *****************************************************************************}
  2291. constructor tmacro.create(const n : string);
  2292. begin
  2293. inherited create(macrosym,n);
  2294. owner:=nil;
  2295. defined:=false;
  2296. is_used:=false;
  2297. is_compiler_var:=false;
  2298. buftext:=nil;
  2299. buflen:=0;
  2300. end;
  2301. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2302. begin
  2303. inherited ppuload(macrosym,ppufile);
  2304. defined:=boolean(ppufile.getbyte);
  2305. is_compiler_var:=boolean(ppufile.getbyte);
  2306. is_used:=false;
  2307. buflen:= ppufile.getlongint;
  2308. if buflen > 0 then
  2309. begin
  2310. getmem(buftext, buflen);
  2311. ppufile.getdata(buftext^, buflen)
  2312. end
  2313. else
  2314. buftext:=nil;
  2315. end;
  2316. destructor tmacro.destroy;
  2317. begin
  2318. if assigned(buftext) then
  2319. freemem(buftext);
  2320. inherited destroy;
  2321. end;
  2322. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2323. begin
  2324. inherited ppuwrite(ppufile);
  2325. ppufile.putbyte(byte(defined));
  2326. ppufile.putbyte(byte(is_compiler_var));
  2327. ppufile.putlongint(buflen);
  2328. if buflen > 0 then
  2329. ppufile.putdata(buftext^,buflen);
  2330. writeentry(ppufile,ibmacrosym);
  2331. end;
  2332. function tmacro.GetCopy:tmacro;
  2333. var
  2334. p : tmacro;
  2335. begin
  2336. p:=tmacro.create(realname);
  2337. p.defined:=defined;
  2338. p.is_used:=is_used;
  2339. p.is_compiler_var:=is_compiler_var;
  2340. p.buflen:=buflen;
  2341. if assigned(buftext) then
  2342. begin
  2343. getmem(p.buftext,buflen);
  2344. move(buftext^,p.buftext^,buflen);
  2345. end;
  2346. Result:=p;
  2347. end;
  2348. {****************************************************************************
  2349. tPtrDefHashSet
  2350. ****************************************************************************}
  2351. constructor tPtrDefHashSet.Create;
  2352. begin
  2353. inherited Create(64,true,false);
  2354. end;
  2355. end.