symsym.pas 105 KB

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