symsym.pas 92 KB

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