symsym.pas 106 KB

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