symsym.pas 90 KB

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