symsym.pas 90 KB

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