symsym.pas 90 KB

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