symsym.pas 105 KB

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