symsym.pas 91 KB

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