symsym.pas 91 KB

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