symsym.pas 92 KB

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