symsym.pas 91 KB

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