symsym.pas 90 KB

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