symsym.pas 107 KB

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