symsym.pas 90 KB

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