symsym.pas 105 KB

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