symsym.pas 106 KB

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