symsym.pas 105 KB

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