symsym.pas 89 KB

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