symsym.pas 91 KB

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