symsym.pas 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769
  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;doregister:boolean);
  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;doregister:boolean);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;doregister:boolean);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;doregister:boolean);
  164. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  165. procedure ppuwrite(ppufile:tcompilerppufile);override;
  166. procedure buildderef;override;
  167. procedure deref;override;
  168. function getsize : asizeint;
  169. function getpackedbitsize : longint;
  170. function is_regvar(refpara: boolean):boolean;
  171. private
  172. _vardef : tdef;
  173. vardefderef : tderef;
  174. procedure 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;doregister:boolean);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;doregister:boolean);
  222. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  223. function globalasmsym: boolean;
  224. procedure ppuwrite(ppufile:tcompilerppufile);override;
  225. procedure buildderef;override;
  226. procedure deref;override;
  227. end;
  228. tlocalvarsym = class(tabstractnormalvarsym)
  229. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions;doregister:boolean);virtual;
  230. constructor ppuload(ppufile:tcompilerppufile);
  231. { do not override this routine in platform-specific subclasses,
  232. override ppuwrite_platform instead }
  233. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  234. end;
  235. tlocalvarsymclass = class of tlocalvarsym;
  236. tparavarsym = class(tabstractnormalvarsym)
  237. paraloc : array[callerside..calleeside] of TCGPara;
  238. paranr : word; { position of this parameter }
  239. { in MacPas mode, "univ" parameters mean that type checking should
  240. be disabled, except that the size of the passed parameter must
  241. match the size of the formal parameter }
  242. univpara : boolean;
  243. {$ifdef EXTDEBUG}
  244. eqval : tequaltype;
  245. {$endif EXTDEBUG}
  246. constructor create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);virtual;
  247. constructor ppuload(ppufile:tcompilerppufile);
  248. destructor destroy;override;
  249. { do not override this routine in platform-specific subclasses,
  250. override ppuwrite_platform instead }
  251. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  252. function needs_finalization: boolean;
  253. end;
  254. tparavarsymclass = class of tparavarsym;
  255. tstaticvarsym = class(tabstractnormalvarsym)
  256. protected
  257. {$ifdef symansistr}
  258. _mangledbasename,
  259. _mangledname : TSymStr;
  260. {$else symansistr}
  261. _mangledbasename,
  262. _mangledname : pshortstring;
  263. {$endif symansistr}
  264. public
  265. section : ansistring;
  266. { if a text buffer has been defined as being initialized from command line
  267. parameters as it is done by iso pascal with the program symbols,
  268. isoindex contains the parameter number }
  269. isoindex : dword;
  270. { if this static variable was created based on a class field variable then this is set
  271. to the symbol of the corresponding class field }
  272. fieldvarsym : tfieldvarsym;
  273. fieldvarsymderef : tderef;
  274. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions;doregister:boolean);virtual;
  275. constructor create_dll(const n : string;vsp:tvarspez;def:tdef);virtual;
  276. constructor create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);virtual;
  277. constructor create_from_fieldvar(const n:string;fieldvar:tfieldvarsym);virtual;
  278. constructor ppuload(ppufile:tcompilerppufile);
  279. destructor destroy;override;
  280. { do not override this routine in platform-specific subclasses,
  281. override ppuwrite_platform instead }
  282. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  283. procedure buildderef;override;
  284. procedure deref;override;
  285. function mangledname:TSymStr;override;
  286. procedure set_mangledbasename(const s: TSymStr);
  287. function mangledbasename: TSymStr;
  288. procedure set_mangledname(const s:TSymStr);virtual;
  289. procedure set_raw_mangledname(const s:TSymStr);
  290. end;
  291. tstaticvarsymclass = class of tstaticvarsym;
  292. tabsolutevarsym = class(tabstractvarsym)
  293. public
  294. abstyp : absolutetyp;
  295. asmname : pshortstring;
  296. addroffset : PUint;
  297. ref : tpropaccesslist;
  298. constructor create(const n : string;def:tdef);virtual;
  299. constructor create_ref(const n : string;def:tdef;_ref:tpropaccesslist);virtual;
  300. destructor destroy;override;
  301. constructor ppuload(ppufile:tcompilerppufile);
  302. procedure buildderef;override;
  303. procedure deref;override;
  304. function mangledname : TSymStr;override;
  305. { do not override this routine in platform-specific subclasses,
  306. override ppuwrite_platform instead }
  307. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  308. end;
  309. tabsolutevarsymclass = class of tabsolutevarsym;
  310. tpropaccesslisttypes=(palt_none,palt_read,palt_write,palt_stored);
  311. tpropertysym = class(Tstoredsym)
  312. protected
  313. procedure finalize_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef); virtual;
  314. public
  315. propoptions : tpropertyoptions;
  316. overriddenpropsym : tpropertysym;
  317. overriddenpropsymderef : tderef;
  318. propdef : tdef;
  319. propdefderef : tderef;
  320. indexdef : tdef;
  321. indexdefderef : tderef;
  322. index,
  323. default : longint;
  324. dispid : longint;
  325. propaccesslist: array[tpropaccesslisttypes] of tpropaccesslist;
  326. parast : tsymtable;
  327. constructor create(const n : string);virtual;
  328. destructor destroy;override;
  329. constructor ppuload(ppufile:tcompilerppufile);
  330. function getsize : asizeint;
  331. { do not override this routine in platform-specific subclasses,
  332. override ppuwrite_platform instead }
  333. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  334. procedure buildderef;override;
  335. procedure deref;override;
  336. function getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  337. { copies the settings of the current propertysym to p; a bit like
  338. a form of getcopy, but without the name }
  339. procedure makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  340. procedure add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  341. procedure add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  342. { set up the accessors for this property }
  343. procedure add_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  344. procedure register_override(overriddenprop: tpropertysym);
  345. { inherit the read/write property }
  346. procedure inherit_accessor(getset: tpropaccesslisttypes); virtual;
  347. end;
  348. tpropertysymclass = class of tpropertysym;
  349. tconstvalue = record
  350. case integer of
  351. 0: (valueord : tconstexprint);
  352. 1: (valueordptr : tconstptruint);
  353. 2: (valueptr : pointer; len : longint);
  354. end;
  355. tconstsym = class(tstoredsym)
  356. constdef : tdef;
  357. constdefderef : tderef;
  358. consttyp : tconsttyp;
  359. value : tconstvalue;
  360. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);virtual;
  361. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);virtual;
  362. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);virtual;
  363. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint;def:tdef);virtual;
  364. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);virtual;
  365. constructor ppuload(ppufile:tcompilerppufile);
  366. destructor destroy;override;
  367. procedure buildderef;override;
  368. procedure deref;override;
  369. { do not override this routine in platform-specific subclasses,
  370. override ppuwrite_platform instead }
  371. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  372. end;
  373. tconstsymclass = class of tconstsym;
  374. tenumsym = class(Tstoredsym)
  375. value : longint;
  376. definition : tenumdef;
  377. definitionderef : tderef;
  378. constructor create(const n : string;def : tenumdef;v : longint);virtual;
  379. constructor ppuload(ppufile:tcompilerppufile);
  380. { do not override this routine in platform-specific subclasses,
  381. override ppuwrite_platform instead }
  382. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  383. procedure buildderef;override;
  384. procedure deref;override;
  385. end;
  386. tenumsymclass = class of tenumsym;
  387. tsyssym = class(Tstoredsym)
  388. number : 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;doregister:boolean);
  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,true);
  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;doregister:boolean);
  619. begin
  620. inherited create(unitsym,n,doregister);
  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,true);
  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,true);
  666. unitsym:=nil;
  667. end;
  668. constructor tnamespacesym.ppuload(ppufile:tcompilerppufile);
  669. begin
  670. inherited ppuload(namespacesym,ppufile);
  671. ppufile.getderef(unitsymderef);
  672. ppuload_platform(ppufile);
  673. end;
  674. procedure tnamespacesym.ppuwrite(ppufile:tcompilerppufile);
  675. begin
  676. inherited ppuwrite(ppufile);
  677. ppufile.putderef(unitsymderef);
  678. writeentry(ppufile,ibnamespacesym);
  679. end;
  680. procedure tnamespacesym.buildderef;
  681. begin
  682. inherited buildderef;
  683. unitsymderef.build(unitsym);
  684. end;
  685. procedure tnamespacesym.deref;
  686. begin
  687. inherited deref;
  688. unitsym:=tsym(unitsymderef.resolve);
  689. end;
  690. {****************************************************************************
  691. TPROCSYM
  692. ****************************************************************************}
  693. constructor tprocsym.create(const n : string);
  694. var
  695. i: longint;
  696. begin
  697. if not(ts_lowercase_proc_start in current_settings.targetswitches) or
  698. (n='') then
  699. inherited create(procsym,n,true)
  700. else
  701. begin
  702. { YToX -> yToX
  703. RC64Encode -> rc64Encode
  704. Test -> test
  705. }
  706. i:=2;
  707. while i<=length(n) do
  708. begin
  709. if not(n[i] in ['A'..'Z']) then
  710. begin
  711. if (i>2) and
  712. (n[i] in ['a'..'z']) then
  713. dec(i);
  714. break;
  715. end;
  716. inc(i);
  717. end;
  718. inherited create(procsym,lower(copy(n,1,i-1))+copy(n,i,length(n)),true);
  719. end;
  720. FProcdefList:=TFPObjectList.Create(false);
  721. FProcdefderefList:=nil;
  722. { the tprocdef have their own symoptions, make the procsym
  723. always visible }
  724. visibility:=vis_public;
  725. end;
  726. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  727. var
  728. pdderef : tderef;
  729. i,
  730. pdcnt : longint;
  731. begin
  732. inherited ppuload(procsym,ppufile);
  733. FProcdefList:=TFPObjectList.Create(false);
  734. FProcdefDerefList:=TFPList.Create;
  735. pdcnt:=ppufile.getword;
  736. for i:=1 to pdcnt do
  737. begin
  738. ppufile.getderef(pdderef);
  739. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  740. end;
  741. ppuload_platform(ppufile);
  742. end;
  743. destructor tprocsym.destroy;
  744. begin
  745. FProcdefList.Free;
  746. if assigned(FProcdefDerefList) then
  747. FProcdefDerefList.Free;
  748. inherited destroy;
  749. end;
  750. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  751. var
  752. i : longint;
  753. d : tderef;
  754. begin
  755. inherited ppuwrite(ppufile);
  756. if fprocdefdereflist=nil then
  757. internalerror(2013121801);
  758. ppufile.putword(FProcdefDerefList.Count);
  759. for i:=0 to FProcdefDerefList.Count-1 do
  760. begin
  761. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  762. ppufile.putderef(d);
  763. end;
  764. writeentry(ppufile,ibprocsym);
  765. end;
  766. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  767. var
  768. i : longint;
  769. pd : tprocdef;
  770. begin
  771. for i:=0 to ProcdefList.Count-1 do
  772. begin
  773. pd:=tprocdef(ProcdefList[i]);
  774. if pd<>skipdef then
  775. MessagePos1(pd.fileinfo,sym_e_param_list,pd.fullprocname(false));
  776. end;
  777. end;
  778. procedure tprocsym.check_forward;
  779. var
  780. i : longint;
  781. pd : tprocdef;
  782. begin
  783. for i:=0 to ProcdefList.Count-1 do
  784. begin
  785. pd:=tprocdef(ProcdefList[i]);
  786. if (pd.owner=owner) and (pd.forwarddef) then
  787. begin
  788. { For mode macpas. Make implicit externals (procedures declared in the interface
  789. section which do not have a counterpart in the implementation)
  790. to be an imported procedure }
  791. if (m_mac in current_settings.modeswitches) and
  792. (pd.interfacedef) then
  793. begin
  794. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  795. if (not current_module.interface_only) then
  796. MessagePos1(pd.fileinfo,sym_w_forward_not_resolved,pd.fullprocname(false));
  797. end
  798. else
  799. begin
  800. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  801. end;
  802. { Turn further error messages off }
  803. pd.forwarddef:=false;
  804. end;
  805. end;
  806. end;
  807. procedure tprocsym.buildderef;
  808. var
  809. i : longint;
  810. pd : tprocdef;
  811. d : tderef;
  812. begin
  813. inherited;
  814. if not assigned(FProcdefDerefList) then
  815. FProcdefDerefList:=TFPList.Create
  816. else
  817. FProcdefDerefList.Clear;
  818. for i:=0 to ProcdefList.Count-1 do
  819. begin
  820. pd:=tprocdef(ProcdefList[i]);
  821. { only write the proc definitions that belong
  822. to this procsym and are in the global symtable }
  823. if pd.owner=owner then
  824. begin
  825. d.build(pd);
  826. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  827. end;
  828. end;
  829. end;
  830. procedure tprocsym.deref;
  831. var
  832. i : longint;
  833. pd : tprocdef;
  834. d : tderef;
  835. begin
  836. { Clear all procdefs }
  837. ProcdefList.Clear;
  838. if not assigned(FProcdefDerefList) then
  839. internalerror(200611031);
  840. for i:=0 to FProcdefDerefList.Count-1 do
  841. begin
  842. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  843. pd:=tprocdef(d.resolve);
  844. ProcdefList.Add(pd);
  845. end;
  846. end;
  847. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  848. var
  849. i : longint;
  850. pd : tprocdef;
  851. begin
  852. result:=nil;
  853. for i:=0 to ProcdefList.Count-1 do
  854. begin
  855. pd:=tprocdef(ProcdefList[i]);
  856. if pd.proctypeoption=pt then
  857. begin
  858. result:=pd;
  859. exit;
  860. end;
  861. end;
  862. end;
  863. function tprocsym.find_bytype_parameterless(pt: Tproctypeoption): Tprocdef;
  864. var
  865. i,j : longint;
  866. pd : tprocdef;
  867. found : boolean;
  868. begin
  869. result:=nil;
  870. for i:=0 to ProcdefList.Count-1 do
  871. begin
  872. pd:=tprocdef(ProcdefList[i]);
  873. if (pd.proctypeoption=pt) then
  874. begin
  875. found:=true;
  876. for j:=0 to pd.paras.count-1 do
  877. begin
  878. if not(vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  879. begin
  880. found:=false;
  881. break;
  882. end;
  883. end;
  884. if found then
  885. begin
  886. result:=pd;
  887. exit;
  888. end;
  889. end;
  890. end;
  891. end;
  892. function check_procdef_paras(pd:tprocdef;para:TFPObjectList;retdef:tdef;
  893. cpoptions:tcompare_paras_options): tprocdef;
  894. var
  895. eq: tequaltype;
  896. begin
  897. result:=nil;
  898. if assigned(retdef) then
  899. eq:=compare_defs(retdef,pd.returndef,nothingn)
  900. else
  901. eq:=te_equal;
  902. if (eq>=te_equal) or
  903. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  904. begin
  905. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  906. if (eq>=te_equal) or
  907. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  908. begin
  909. result:=pd;
  910. exit;
  911. end;
  912. end;
  913. end;
  914. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  915. cpoptions:tcompare_paras_options):Tprocdef;
  916. var
  917. i : longint;
  918. pd : tprocdef;
  919. begin
  920. result:=nil;
  921. for i:=0 to ProcdefList.Count-1 do
  922. begin
  923. pd:=tprocdef(ProcdefList[i]);
  924. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  925. if assigned(result) then
  926. exit;
  927. end;
  928. end;
  929. function Tprocsym.find_procdef_bytype_and_para(pt:Tproctypeoption;
  930. para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  931. var
  932. i : longint;
  933. pd : tprocdef;
  934. begin
  935. result:=nil;
  936. for i:=0 to ProcdefList.Count-1 do
  937. begin
  938. pd:=tprocdef(ProcdefList[i]);
  939. if pd.proctypeoption=pt then
  940. begin
  941. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  942. if assigned(result) then
  943. exit;
  944. end;
  945. end;
  946. end;
  947. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  948. var
  949. i : longint;
  950. pd : tprocdef;
  951. begin
  952. result:=nil;
  953. for i:=0 to ProcdefList.Count-1 do
  954. begin
  955. pd:=tprocdef(ProcdefList[i]);
  956. if ops * pd.procoptions = ops then
  957. begin
  958. result:=pd;
  959. exit;
  960. end;
  961. end;
  962. end;
  963. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  964. var
  965. i : longint;
  966. bestpd,
  967. pd : tprocdef;
  968. eq,besteq : tequaltype;
  969. sym: tsym;
  970. ps: tprocsym;
  971. begin
  972. { This function will return the pprocdef of pprocsym that
  973. is the best match for procvardef. When there are multiple
  974. matches it returns nil.}
  975. result:=nil;
  976. bestpd:=nil;
  977. besteq:=te_incompatible;
  978. ps:=self;
  979. repeat
  980. for i:=0 to ps.ProcdefList.Count-1 do
  981. begin
  982. pd:=tprocdef(ps.ProcdefList[i]);
  983. eq:=proc_to_procvar_equal(pd,d,false);
  984. if eq>=te_convert_l1 then
  985. begin
  986. { multiple procvars with the same equal level }
  987. if assigned(bestpd) and
  988. (besteq=eq) then
  989. exit;
  990. if eq>besteq then
  991. begin
  992. besteq:=eq;
  993. bestpd:=pd;
  994. end;
  995. end;
  996. end;
  997. { maybe TODO: also search class helpers? -- this code is similar to
  998. what happens in htypechk in
  999. tcallcandidates.collect_overloads_in_struct: keep searching in
  1000. parent types in case the currently found procdef is marked as
  1001. "overload" and we haven't found a proper match yet }
  1002. if assigned(ps.owner.defowner) and
  1003. (ps.owner.defowner.typ=objectdef) and
  1004. assigned(tobjectdef(ps.owner.defowner).childof) and
  1005. (not assigned(bestpd) or
  1006. (po_overload in bestpd.procoptions)) then
  1007. begin
  1008. sym:=tsym(tobjectdef(ps.owner.defowner).childof.symtable.find(ps.name));
  1009. if assigned(sym) and
  1010. (sym.typ=procsym) then
  1011. ps:=tprocsym(sym)
  1012. else
  1013. ps:=nil;
  1014. end
  1015. else
  1016. ps:=nil;
  1017. until (besteq>=te_equal) or
  1018. not assigned(ps);
  1019. result:=bestpd;
  1020. end;
  1021. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  1022. var
  1023. paraidx, realparamcount,
  1024. i, j : longint;
  1025. bestpd,
  1026. hpd,
  1027. pd : tprocdef;
  1028. convtyp : tconverttype;
  1029. eq : tequaltype;
  1030. begin
  1031. { This function will return the pprocdef of pprocsym that
  1032. is the best match for fromdef and todef. }
  1033. result:=nil;
  1034. bestpd:=nil;
  1035. besteq:=te_incompatible;
  1036. for i:=0 to ProcdefList.Count-1 do
  1037. begin
  1038. pd:=tprocdef(ProcdefList[i]);
  1039. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  1040. continue;
  1041. if (equal_defs(todef,pd.returndef) or
  1042. { shortstrings of different lengths are ok as result }
  1043. (is_shortstring(todef) and is_shortstring(pd.returndef))) and
  1044. { the result type must be always really equal and not an alias,
  1045. if you mess with this code, check tw4093 }
  1046. ((todef=pd.returndef) or
  1047. (
  1048. not(df_unique in todef.defoptions) and
  1049. not(df_unique in pd.returndef.defoptions)
  1050. )
  1051. ) then
  1052. begin
  1053. paraidx:=0;
  1054. { ignore vs_hidden parameters }
  1055. while (paraidx<pd.paras.count) and
  1056. assigned(pd.paras[paraidx]) and
  1057. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  1058. inc(paraidx);
  1059. realparamcount:=0;
  1060. for j := 0 to pd.paras.Count-1 do
  1061. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  1062. inc(realparamcount);
  1063. if (paraidx<pd.paras.count) and
  1064. assigned(pd.paras[paraidx]) and
  1065. (realparamcount = 1) then
  1066. begin
  1067. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  1068. { alias? if yes, only l1 choice,
  1069. if you mess with this code, check tw4093 }
  1070. if (eq=te_exact) and
  1071. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  1072. ((df_unique in fromdef.defoptions) or
  1073. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  1074. eq:=te_convert_l1;
  1075. if eq=te_exact then
  1076. begin
  1077. besteq:=eq;
  1078. result:=pd;
  1079. exit;
  1080. end;
  1081. if eq>besteq then
  1082. begin
  1083. bestpd:=pd;
  1084. besteq:=eq;
  1085. end;
  1086. end;
  1087. end;
  1088. end;
  1089. result:=bestpd;
  1090. end;
  1091. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  1092. var
  1093. paraidx, realparamcount,
  1094. i, j : longint;
  1095. bestpd,
  1096. hpd,
  1097. pd : tprocdef;
  1098. current : tpropertysym;
  1099. convtyp : tconverttype;
  1100. eq : tequaltype;
  1101. begin
  1102. { This function will return the pprocdef of pprocsym that
  1103. is the best match for fromdef and todef. }
  1104. result:=nil;
  1105. bestpd:=nil;
  1106. besteq:=te_incompatible;
  1107. for i:=0 to ProcdefList.Count-1 do
  1108. begin
  1109. pd:=tprocdef(ProcdefList[i]);
  1110. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  1111. continue;
  1112. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  1113. continue;
  1114. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  1115. if (current = nil) then
  1116. continue;
  1117. // compare current result def with the todef
  1118. if (equal_defs(todef, current.propdef) or
  1119. { shortstrings of different lengths are ok as result }
  1120. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  1121. { the result type must be always really equal and not an alias,
  1122. if you mess with this code, check tw4093 }
  1123. ((todef=current.propdef) or
  1124. (
  1125. not(df_unique in todef.defoptions) and
  1126. not(df_unique in current.propdef.defoptions)
  1127. )
  1128. ) then
  1129. begin
  1130. paraidx:=0;
  1131. { ignore vs_hidden parameters }
  1132. while (paraidx<pd.paras.count) and
  1133. assigned(pd.paras[paraidx]) and
  1134. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  1135. inc(paraidx);
  1136. realparamcount:=0;
  1137. for j := 0 to pd.paras.Count-1 do
  1138. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  1139. inc(realparamcount);
  1140. if (paraidx<pd.paras.count) and
  1141. assigned(pd.paras[paraidx]) and
  1142. (realparamcount = 1) then
  1143. begin
  1144. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  1145. { alias? if yes, only l1 choice,
  1146. if you mess with this code, check tw4093 }
  1147. if (eq=te_exact) and
  1148. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  1149. ((df_unique in fromdef.defoptions) or
  1150. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  1151. eq:=te_convert_l1;
  1152. if eq=te_exact then
  1153. begin
  1154. besteq:=eq;
  1155. result:=pd;
  1156. exit;
  1157. end;
  1158. if eq>besteq then
  1159. begin
  1160. bestpd:=pd;
  1161. besteq:=eq;
  1162. end;
  1163. end;
  1164. end;
  1165. end;
  1166. result:=bestpd;
  1167. end;
  1168. {****************************************************************************
  1169. TERRORSYM
  1170. ****************************************************************************}
  1171. constructor terrorsym.create;
  1172. begin
  1173. inherited create(errorsym,'');
  1174. end;
  1175. procedure terrorsym.register_sym;
  1176. begin
  1177. { these should never be written to a ppu file, since they don't
  1178. derive from tstoredsym }
  1179. Internalerror(2015101801);
  1180. end;
  1181. {****************************************************************************
  1182. TPROPERTYSYM
  1183. ****************************************************************************}
  1184. procedure tpropertysym.finalize_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  1185. begin
  1186. { do nothing by default }
  1187. end;
  1188. constructor tpropertysym.create(const n : string);
  1189. var
  1190. pap : tpropaccesslisttypes;
  1191. begin
  1192. inherited create(propertysym,n,true);
  1193. propoptions:=[];
  1194. index:=0;
  1195. default:=0;
  1196. propdef:=nil;
  1197. indexdef:=nil;
  1198. parast:=nil;
  1199. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1200. propaccesslist[pap]:=tpropaccesslist.create;
  1201. end;
  1202. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1203. var
  1204. pap : tpropaccesslisttypes;
  1205. begin
  1206. inherited ppuload(propertysym,ppufile);
  1207. ppufile.getsmallset(propoptions);
  1208. if ppo_overrides in propoptions then
  1209. ppufile.getderef(overriddenpropsymderef);
  1210. ppufile.getderef(propdefderef);
  1211. index:=ppufile.getlongint;
  1212. default:=ppufile.getlongint;
  1213. ppufile.getderef(indexdefderef);
  1214. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1215. propaccesslist[pap]:=ppufile.getpropaccesslist;
  1216. ppuload_platform(ppufile);
  1217. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1218. begin
  1219. parast:=tparasymtable.create(nil,0);
  1220. tparasymtable(parast).ppuload(ppufile);
  1221. end
  1222. else
  1223. parast:=nil;
  1224. end;
  1225. destructor tpropertysym.destroy;
  1226. var
  1227. pap : tpropaccesslisttypes;
  1228. begin
  1229. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1230. propaccesslist[pap].free;
  1231. parast.free;
  1232. inherited destroy;
  1233. end;
  1234. procedure tpropertysym.buildderef;
  1235. var
  1236. pap : tpropaccesslisttypes;
  1237. begin
  1238. inherited;
  1239. propdefderef.build(propdef);
  1240. indexdefderef.build(indexdef);
  1241. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1242. propaccesslist[pap].buildderef;
  1243. if ppo_overrides in propoptions then
  1244. overriddenpropsymderef.build(overriddenpropsym)
  1245. else
  1246. if ppo_hasparameters in propoptions then
  1247. tparasymtable(parast).buildderef;
  1248. end;
  1249. procedure tpropertysym.deref;
  1250. var
  1251. pap : tpropaccesslisttypes;
  1252. begin
  1253. indexdef:=tdef(indexdefderef.resolve);
  1254. propdef:=tdef(propdefderef.resolve);
  1255. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1256. propaccesslist[pap].resolve;
  1257. if ppo_overrides in propoptions then
  1258. begin
  1259. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  1260. if ppo_hasparameters in propoptions then
  1261. parast:=overriddenpropsym.parast.getcopy;
  1262. end
  1263. else
  1264. if ppo_hasparameters in propoptions then
  1265. tparasymtable(parast).deref(false)
  1266. end;
  1267. function tpropertysym.getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  1268. var
  1269. hpropsym : tpropertysym;
  1270. begin
  1271. result:=false;
  1272. { find property in the overridden list }
  1273. hpropsym:=self;
  1274. repeat
  1275. plist:=hpropsym.propaccesslist[pap];
  1276. if not plist.empty then
  1277. begin
  1278. result:=true;
  1279. exit;
  1280. end;
  1281. hpropsym:=hpropsym.overriddenpropsym;
  1282. until not assigned(hpropsym);
  1283. end;
  1284. procedure tpropertysym.add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  1285. var
  1286. i: integer;
  1287. orig, hparavs: tparavarsym;
  1288. begin
  1289. for i := 0 to parast.SymList.Count - 1 do
  1290. begin
  1291. orig:=tparavarsym(parast.SymList[i]);
  1292. if assigned(readprocdef) then
  1293. begin
  1294. hparavs:=cparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1295. readprocdef.parast.insert(hparavs);
  1296. end;
  1297. if assigned(writeprocdef) then
  1298. begin
  1299. hparavs:=cparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1300. writeprocdef.parast.insert(hparavs);
  1301. end;
  1302. end;
  1303. end;
  1304. procedure tpropertysym.add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  1305. var
  1306. hparavs: tparavarsym;
  1307. begin
  1308. inc(paranr);
  1309. if assigned(readprocdef) then
  1310. begin
  1311. hparavs:=cparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1312. readprocdef.parast.insert(hparavs);
  1313. end;
  1314. if assigned(writeprocdef) then
  1315. begin
  1316. hparavs:=cparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1317. writeprocdef.parast.insert(hparavs);
  1318. end;
  1319. end;
  1320. procedure tpropertysym.add_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  1321. var
  1322. cpo: tcompare_paras_options;
  1323. begin
  1324. case sym.typ of
  1325. procsym :
  1326. begin
  1327. { search procdefs matching accessordef }
  1328. { we ignore hidden stuff here because the property access symbol might have
  1329. non default calling conventions which might change the hidden stuff;
  1330. see tw3216.pp (FK) }
  1331. cpo:=[cpo_allowdefaults,cpo_ignorehidden];
  1332. { allow var-parameters for setters in case of VARPROPSETTER+ }
  1333. if (getset=palt_write) and
  1334. (cs_varpropsetter in current_settings.localswitches) then
  1335. include(cpo,cpo_ignorevarspez);
  1336. propaccesslist[getset].procdef:=tprocsym(sym).find_procdef_bypara(accessordef.paras,accessordef.returndef,cpo);
  1337. if not assigned(propaccesslist[getset].procdef) or
  1338. { because of cpo_ignorehidden we need to compare if it is a static class method and we have a class property }
  1339. ((sp_static in symoptions)<>tprocdef(propaccesslist[getset].procdef).no_self_node) then
  1340. Message(parser_e_ill_property_access_sym)
  1341. else
  1342. finalize_getter_or_setter_for_sym(getset,sym,fielddef,accessordef);
  1343. end;
  1344. fieldvarsym :
  1345. begin
  1346. if not assigned(fielddef) then
  1347. internalerror(200310071);
  1348. if compare_defs(fielddef,propdef,nothingn)>=te_equal then
  1349. begin
  1350. { property parameters are allowed if this is
  1351. an indexed property, because the index is then
  1352. the parameter.
  1353. Note: In the help of Kylix it is written
  1354. that it isn't allowed, but the compiler accepts it (PFV) }
  1355. if (ppo_hasparameters in propoptions) or
  1356. ((sp_static in symoptions) <> (sp_static in sym.symoptions)) then
  1357. Message(parser_e_ill_property_access_sym)
  1358. else
  1359. finalize_getter_or_setter_for_sym(getset,sym,fielddef,accessordef);
  1360. end
  1361. else
  1362. IncompatibleTypes(fielddef,propdef);
  1363. end;
  1364. else
  1365. Message(parser_e_ill_property_access_sym);
  1366. end;
  1367. end;
  1368. procedure tpropertysym.register_override(overriddenprop: tpropertysym);
  1369. begin
  1370. overriddenpropsym:=tpropertysym(overriddenprop);
  1371. include(propoptions,ppo_overrides);
  1372. end;
  1373. procedure tpropertysym.inherit_accessor(getset: tpropaccesslisttypes);
  1374. begin
  1375. { nothing to do by default }
  1376. end;
  1377. procedure tpropertysym.makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  1378. begin
  1379. { inherit all type related entries }
  1380. p.indexdef:=indexdef;
  1381. p.propdef:=propdef;
  1382. p.index:=index;
  1383. p.default:=default;
  1384. p.propoptions:=propoptions;
  1385. paranr:=0;
  1386. if ppo_hasparameters in propoptions then
  1387. begin
  1388. p.parast:=parast.getcopy;
  1389. p.add_accessor_parameters(readprocdef,writeprocdef);
  1390. paranr:=p.parast.SymList.Count;
  1391. end;
  1392. if ppo_indexed in p.propoptions then
  1393. p.add_index_parameter(paranr,readprocdef,writeprocdef);
  1394. end;
  1395. function tpropertysym.getsize : asizeint;
  1396. begin
  1397. getsize:=0;
  1398. end;
  1399. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1400. var
  1401. pap : tpropaccesslisttypes;
  1402. begin
  1403. inherited ppuwrite(ppufile);
  1404. ppufile.putsmallset(propoptions);
  1405. if ppo_overrides in propoptions then
  1406. ppufile.putderef(overriddenpropsymderef);
  1407. ppufile.putderef(propdefderef);
  1408. ppufile.putlongint(index);
  1409. ppufile.putlongint(default);
  1410. ppufile.putderef(indexdefderef);
  1411. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1412. ppufile.putpropaccesslist(propaccesslist[pap]);
  1413. writeentry(ppufile,ibpropertysym);
  1414. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1415. tparasymtable(parast).ppuwrite(ppufile);
  1416. end;
  1417. {****************************************************************************
  1418. TABSTRACTVARSYM
  1419. ****************************************************************************}
  1420. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions;doregister:boolean);
  1421. begin
  1422. inherited create(st,n,doregister);
  1423. vardef:=def;
  1424. varspez:=vsp;
  1425. varstate:=vs_declared;
  1426. varoptions:=vopts;
  1427. end;
  1428. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1429. begin
  1430. inherited ppuload(st,ppufile);
  1431. varstate:=vs_readwritten;
  1432. varspez:=tvarspez(ppufile.getbyte);
  1433. varregable:=tvarregable(ppufile.getbyte);
  1434. addr_taken:=ppufile.getboolean;
  1435. different_scope:=ppufile.getboolean;
  1436. ppufile.getderef(vardefderef);
  1437. ppufile.getsmallset(varoptions);
  1438. end;
  1439. procedure tabstractvarsym.buildderef;
  1440. begin
  1441. inherited;
  1442. vardefderef.build(vardef);
  1443. end;
  1444. procedure tabstractvarsym.deref;
  1445. begin
  1446. { assigning vardef also updates varregable. We just loaded this }
  1447. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  1448. { tw7817b.pp: the address is taken of a local variable in an }
  1449. { inlined procedure -> must remain non-regable when inlining) }
  1450. setvardef(tdef(vardefderef.resolve));
  1451. end;
  1452. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1453. var
  1454. oldintfcrc : boolean;
  1455. begin
  1456. inherited ppuwrite(ppufile);
  1457. ppufile.putbyte(byte(varspez));
  1458. oldintfcrc:=ppufile.do_crc;
  1459. ppufile.do_crc:=false;
  1460. ppufile.putbyte(byte(varregable));
  1461. ppufile.putboolean(addr_taken);
  1462. ppufile.putboolean(different_scope);
  1463. ppufile.do_crc:=oldintfcrc;
  1464. ppufile.putderef(vardefderef);
  1465. ppufile.putsmallset(varoptions);
  1466. end;
  1467. function tabstractvarsym.getsize : asizeint;
  1468. begin
  1469. if assigned(vardef) and
  1470. ((vardef.typ<>arraydef) or
  1471. is_dynamic_array(vardef) or
  1472. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1473. result:=vardef.size
  1474. else
  1475. result:=0;
  1476. end;
  1477. function tabstractvarsym.getpackedbitsize : longint;
  1478. begin
  1479. { bitpacking is only done for ordinals }
  1480. if not is_ordinal(vardef) then
  1481. internalerror(2006082010);
  1482. result:=vardef.packedbitsize;
  1483. end;
  1484. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1485. begin
  1486. { Register variables are not allowed in the following cases:
  1487. - regvars are disabled
  1488. - exceptions are used (after an exception is raised the contents of the
  1489. registers is not valid anymore)
  1490. - it has a local copy
  1491. - the value needs to be in memory (i.e. reference counted) }
  1492. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1493. not(pi_has_assembler_block in current_procinfo.flags) and
  1494. not(pi_uses_exceptions in current_procinfo.flags) and
  1495. not(pi_has_interproclabel in current_procinfo.flags) and
  1496. ((refpara and
  1497. (varregable <> vr_none)) or
  1498. (not refpara and
  1499. not(varregable in [vr_none,vr_addr])))
  1500. {$if not defined(powerpc) and not defined(powerpc64)}
  1501. and ((vardef.typ <> recorddef) or
  1502. (varregable = vr_addr) or
  1503. not(varstate in [vs_written,vs_readwritten]));
  1504. {$endif}
  1505. end;
  1506. procedure tabstractvarsym.setvardef_and_regable(def:tdef);
  1507. begin
  1508. setvardef(def);
  1509. setregable;
  1510. end;
  1511. procedure tabstractvarsym.setregable;
  1512. begin
  1513. { can we load the value into a register ? }
  1514. if not assigned(owner) or
  1515. (owner.symtabletype in [localsymtable, parasymtable]) or
  1516. (
  1517. (owner.symtabletype=staticsymtable) and
  1518. not(cs_create_pic in current_settings.moduleswitches)
  1519. ) then
  1520. begin
  1521. if (tstoreddef(vardef).is_intregable and
  1522. { we could keep all aint*2 records in registers, but this causes
  1523. too much spilling for CPUs with 8-16 registers so keep only
  1524. parameters and function results of this type in register because they are normally
  1525. passed by register anyways
  1526. This can be changed, as soon as we have full ssa (FK) }
  1527. ((typ=paravarsym) or
  1528. (vo_is_funcret in varoptions) or
  1529. (tstoreddef(vardef).typ<>recorddef) or
  1530. (tstoreddef(vardef).size<=sizeof(aint)))) or
  1531. { const parameters can be put into registers if the def fits into a register }
  1532. (tstoreddef(vardef).is_const_intregable and
  1533. (typ=paravarsym) and
  1534. (varspez=vs_const)) then
  1535. varregable:=vr_intreg
  1536. else if tstoreddef(vardef).is_fpuregable then
  1537. begin
  1538. if use_vectorfpu(vardef) then
  1539. varregable:=vr_mmreg
  1540. else
  1541. varregable:=vr_fpureg;
  1542. end;
  1543. end;
  1544. end;
  1545. procedure tabstractvarsym.setvardef(const def: tdef);
  1546. begin
  1547. _vardef := def;
  1548. end;
  1549. {****************************************************************************
  1550. TFIELDVARSYM
  1551. ****************************************************************************}
  1552. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions;doregister:boolean);
  1553. begin
  1554. inherited create(fieldvarsym,n,vsp,def,vopts,doregister);
  1555. fieldoffset:=-1;
  1556. end;
  1557. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1558. begin
  1559. inherited ppuload(fieldvarsym,ppufile);
  1560. fieldoffset:=ppufile.getasizeint;
  1561. if (vo_has_mangledname in varoptions) then
  1562. externalname:=ppufile.getpshortstring
  1563. else
  1564. externalname:=nil;
  1565. ppuload_platform(ppufile);
  1566. end;
  1567. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1568. begin
  1569. inherited ppuwrite(ppufile);
  1570. ppufile.putasizeint(fieldoffset);
  1571. if (vo_has_mangledname in varoptions) then
  1572. ppufile.putstring(externalname^);
  1573. writeentry(ppufile,ibfieldvarsym);
  1574. end;
  1575. procedure tfieldvarsym.set_externalname(const s: string);
  1576. begin
  1577. internalerror(2014033001);
  1578. end;
  1579. function tfieldvarsym.mangledname:TSymStr;
  1580. var
  1581. srsym : tsym;
  1582. srsymtable : tsymtable;
  1583. begin
  1584. if sp_static in symoptions then
  1585. begin
  1586. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1587. result:=srsym.mangledname
  1588. { when generating the debug info for the module in which the }
  1589. { symbol is defined, the localsymtable of that module is }
  1590. { already popped from the symtablestack }
  1591. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1592. result:=srsym.mangledname
  1593. else
  1594. internalerror(2007012501);
  1595. end
  1596. else if is_objcclass(tdef(owner.defowner)) then
  1597. begin
  1598. {$ifdef symansistr}
  1599. if cachedmangledname<>'' then
  1600. result:=cachedmangledname
  1601. {$else symansistr}
  1602. if assigned(cachedmangledname) then
  1603. result:=cachedmangledname^
  1604. {$endif symansistr}
  1605. else
  1606. begin
  1607. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1608. {$ifdef symansistr}
  1609. cachedmangledname:=result;
  1610. {$else symansistr}
  1611. cachedmangledname:=stringdup(result);
  1612. {$endif symansistr}
  1613. end;
  1614. end
  1615. else
  1616. result:=inherited mangledname;
  1617. end;
  1618. destructor tfieldvarsym.destroy;
  1619. begin
  1620. {$ifndef symansistr}
  1621. stringdispose(cachedmangledname);
  1622. {$endif symansistr}
  1623. stringdispose(externalname);
  1624. inherited destroy;
  1625. end;
  1626. {****************************************************************************
  1627. TABSTRACTNORMALVARSYM
  1628. ****************************************************************************}
  1629. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions;doregister:boolean);
  1630. begin
  1631. inherited create(st,n,vsp,def,vopts,doregister);
  1632. fillchar(localloc,sizeof(localloc),0);
  1633. fillchar(initialloc,sizeof(initialloc),0);
  1634. defaultconstsym:=nil;
  1635. end;
  1636. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1637. begin
  1638. inherited ppuload(st,ppufile);
  1639. fillchar(localloc,sizeof(localloc),0);
  1640. fillchar(initialloc,sizeof(initialloc),0);
  1641. ppufile.getderef(defaultconstsymderef);
  1642. end;
  1643. function tabstractnormalvarsym.globalasmsym: boolean;
  1644. begin
  1645. result:=
  1646. (owner.symtabletype=globalsymtable) or
  1647. (create_smartlink and
  1648. not(tf_smartlink_sections in target_info.flags)) or
  1649. current_module.islibrary or
  1650. (assigned(current_procinfo) and
  1651. ((po_inline in current_procinfo.procdef.procoptions) or
  1652. { globalasmsym is called normally before the body of a subroutine is parsed
  1653. so we cannot know if it will be auto inlined, so make all symbols of it
  1654. global if asked }
  1655. (not(po_noinline in current_procinfo.procdef.procoptions) and
  1656. (cs_opt_autoinline in current_settings.optimizerswitches)))
  1657. ) or
  1658. (vo_is_public in varoptions);
  1659. end;
  1660. procedure tabstractnormalvarsym.buildderef;
  1661. begin
  1662. inherited buildderef;
  1663. defaultconstsymderef.build(defaultconstsym);
  1664. end;
  1665. procedure tabstractnormalvarsym.deref;
  1666. begin
  1667. inherited deref;
  1668. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1669. end;
  1670. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1671. begin
  1672. inherited ppuwrite(ppufile);
  1673. ppufile.putderef(defaultconstsymderef);
  1674. end;
  1675. {****************************************************************************
  1676. Tstaticvarsym
  1677. ****************************************************************************}
  1678. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions;doregister:boolean);
  1679. begin
  1680. inherited create(staticvarsym,n,vsp,def,vopts,doregister);
  1681. {$ifdef symansistr}
  1682. _mangledname:='';
  1683. {$else symansistr}
  1684. _mangledname:=nil;
  1685. {$endif symansistr}
  1686. end;
  1687. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1688. begin
  1689. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var],true);
  1690. end;
  1691. constructor tstaticvarsym.create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  1692. begin
  1693. tstaticvarsym(self).create(n,vsp,def,[],true);
  1694. set_mangledname(mangled);
  1695. end;
  1696. constructor tstaticvarsym.create_from_fieldvar(const n: string;fieldvar:tfieldvarsym);
  1697. begin
  1698. create(internal_static_field_name(n),vs_value,fieldvar.vardef,[],true);
  1699. fieldvarsym:=fieldvar;
  1700. end;
  1701. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1702. begin
  1703. inherited ppuload(staticvarsym,ppufile);
  1704. {$ifdef symansistr}
  1705. if vo_has_mangledname in varoptions then
  1706. _mangledname:=ppufile.getansistring
  1707. else
  1708. _mangledname:='';
  1709. {$else symansistr}
  1710. if vo_has_mangledname in varoptions then
  1711. _mangledname:=ppufile.getpshortstring
  1712. else
  1713. _mangledname:=nil;
  1714. {$endif symansistr}
  1715. if vo_has_section in varoptions then
  1716. section:=ppufile.getansistring;
  1717. ppufile.getderef(fieldvarsymderef);
  1718. ppuload_platform(ppufile);
  1719. end;
  1720. destructor tstaticvarsym.destroy;
  1721. begin
  1722. {$ifndef symansistr}
  1723. if assigned(_mangledname) then
  1724. begin
  1725. {$ifdef MEMDEBUG}
  1726. memmanglednames.start;
  1727. {$endif MEMDEBUG}
  1728. stringdispose(_mangledname);
  1729. {$ifdef MEMDEBUG}
  1730. memmanglednames.stop;
  1731. {$endif MEMDEBUG}
  1732. end;
  1733. stringdispose(_mangledbasename);
  1734. {$endif}
  1735. inherited destroy;
  1736. end;
  1737. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1738. begin
  1739. inherited ppuwrite(ppufile);
  1740. { write mangledname rather than _mangledname in case the mangledname
  1741. has not been calculated yet (can happen in case only the
  1742. mangledbasename has been set) }
  1743. if vo_has_mangledname in varoptions then
  1744. {$ifdef symansistr}
  1745. ppufile.putansistring(mangledname);
  1746. {$else symansistr}
  1747. ppufile.putstring(mangledname);
  1748. {$endif symansistr}
  1749. if vo_has_section in varoptions then
  1750. ppufile.putansistring(section);
  1751. ppufile.putderef(fieldvarsymderef);
  1752. writeentry(ppufile,ibstaticvarsym);
  1753. end;
  1754. procedure tstaticvarsym.buildderef;
  1755. begin
  1756. inherited buildderef;
  1757. fieldvarsymderef.build(fieldvarsym);
  1758. end;
  1759. procedure tstaticvarsym.deref;
  1760. begin
  1761. inherited deref;
  1762. fieldvarsym:=tfieldvarsym(fieldvarsymderef.resolve);
  1763. end;
  1764. function tstaticvarsym.mangledname:TSymStr;
  1765. var
  1766. usename,
  1767. prefix : TSymStr;
  1768. begin
  1769. {$ifdef symansistr}
  1770. if _mangledname='' then
  1771. {$else symansistr}
  1772. if not assigned(_mangledname) then
  1773. {$endif symansistr}
  1774. begin
  1775. if (vo_is_typed_const in varoptions) then
  1776. prefix:='TC'
  1777. else
  1778. prefix:='U';
  1779. {$ifdef symansistr}
  1780. if _mangledbasename='' then
  1781. usename:=name
  1782. else
  1783. usename:=_mangledbasename;
  1784. _mangledname:=make_mangledname(prefix,owner,usename);
  1785. {$else symansistr}
  1786. if not assigned(_mangledbasename) then
  1787. usename:=name
  1788. else
  1789. usename:=_mangledbasename^;
  1790. _mangledname:=stringdup(make_mangledname(prefix,owner,usename));
  1791. {$endif symansistr}
  1792. end;
  1793. {$ifdef symansistr}
  1794. result:=_mangledname;
  1795. {$else symansistr}
  1796. result:=_mangledname^;
  1797. {$endif symansistr}
  1798. end;
  1799. procedure tstaticvarsym.set_mangledbasename(const s: TSymStr);
  1800. begin
  1801. {$ifdef symansistr}
  1802. _mangledbasename:=s;
  1803. _mangledname:='';
  1804. {$else symansistr}
  1805. stringdispose(_mangledname);
  1806. stringdispose(_mangledbasename);
  1807. _mangledbasename:=stringdup(s);
  1808. {$endif symansistr}
  1809. include(varoptions,vo_has_mangledname);
  1810. end;
  1811. function tstaticvarsym.mangledbasename: TSymStr;
  1812. begin
  1813. {$ifdef symansistr}
  1814. result:=_mangledbasename;
  1815. {$else symansistr}
  1816. if assigned(_mangledbasename) then
  1817. result:=_mangledbasename^
  1818. else
  1819. result:='';
  1820. {$endif symansistr}
  1821. end;
  1822. procedure tstaticvarsym.set_mangledname(const s:TSymStr);
  1823. begin
  1824. {$ifdef symansistr}
  1825. _mangledname:=s;
  1826. {$else symansistr}
  1827. stringdispose(_mangledname);
  1828. _mangledname:=stringdup(s);
  1829. {$endif symansistr}
  1830. include(varoptions,vo_has_mangledname);
  1831. end;
  1832. procedure tstaticvarsym.set_raw_mangledname(const s: TSymStr);
  1833. begin
  1834. {$ifndef symansistr}
  1835. stringdispose(_mangledname);
  1836. _mangledname:=stringdup(s);
  1837. {$else}
  1838. _mangledname:=s;
  1839. {$endif}
  1840. include(varoptions,vo_has_mangledname);
  1841. end;
  1842. {****************************************************************************
  1843. TLOCALVARSYM
  1844. ****************************************************************************}
  1845. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions;doregister:boolean);
  1846. begin
  1847. inherited create(localvarsym,n,vsp,def,vopts,doregister);
  1848. end;
  1849. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1850. begin
  1851. inherited ppuload(localvarsym,ppufile);
  1852. ppuload_platform(ppufile);
  1853. end;
  1854. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1855. begin
  1856. inherited ppuwrite(ppufile);
  1857. writeentry(ppufile,iblocalvarsym);
  1858. end;
  1859. {****************************************************************************
  1860. TPARAVARSYM
  1861. ****************************************************************************}
  1862. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1863. begin
  1864. inherited create(paravarsym,n,vsp,def,vopts,true);
  1865. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) and
  1866. not(vo_is_funcret in vopts) then
  1867. varstate := vs_initialised;
  1868. paranr:=nr;
  1869. paraloc[calleeside].init;
  1870. paraloc[callerside].init;
  1871. end;
  1872. destructor tparavarsym.destroy;
  1873. begin
  1874. paraloc[calleeside].done;
  1875. paraloc[callerside].done;
  1876. inherited destroy;
  1877. end;
  1878. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1879. begin
  1880. inherited ppuload(paravarsym,ppufile);
  1881. paranr:=ppufile.getword;
  1882. univpara:=ppufile.getboolean;
  1883. { The var state of parameter symbols is fixed after writing them so
  1884. we write them to the unit file.
  1885. This enables constant folding for inline procedures loaded from units
  1886. }
  1887. varstate:=tvarstate(ppufile.getbyte);
  1888. { read usage info }
  1889. refs:=ppufile.getbyte;
  1890. paraloc[calleeside].init;
  1891. paraloc[callerside].init;
  1892. if vo_has_explicit_paraloc in varoptions then
  1893. paraloc[callerside].ppuload(ppufile);
  1894. ppuload_platform(ppufile);
  1895. end;
  1896. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1897. var
  1898. oldintfcrc : boolean;
  1899. begin
  1900. inherited ppuwrite(ppufile);
  1901. ppufile.putword(paranr);
  1902. ppufile.putboolean(univpara);
  1903. { The var state of parameter symbols is fixed after writing them so
  1904. we write them to the unit file.
  1905. This enables constant folding for inline procedures loaded from units
  1906. }
  1907. oldintfcrc:=ppufile.do_crc;
  1908. ppufile.do_crc:=false;
  1909. ppufile.putbyte(ord(varstate));
  1910. { write also info about the usage of parameters,
  1911. the absolute usage does not matter }
  1912. ppufile.putbyte(min(1,refs));
  1913. ppufile.do_crc:=oldintfcrc;
  1914. if vo_has_explicit_paraloc in varoptions then
  1915. begin
  1916. paraloc[callerside].check_simple_location;
  1917. paraloc[callerside].ppuwrite(ppufile);
  1918. end;
  1919. writeentry(ppufile,ibparavarsym);
  1920. end;
  1921. function tparavarsym.needs_finalization:boolean;
  1922. begin
  1923. result:=(varspez=vs_value) and
  1924. (is_managed_type(vardef) or
  1925. (
  1926. (not (tabstractprocdef(owner.defowner).proccalloption in cdecl_pocalls)) and
  1927. (not paramanager.use_stackalloc) and
  1928. (is_open_array(vardef) or is_array_of_const(vardef))
  1929. )
  1930. );
  1931. end;
  1932. {****************************************************************************
  1933. TABSOLUTEVARSYM
  1934. ****************************************************************************}
  1935. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1936. begin
  1937. inherited create(absolutevarsym,n,vs_value,def,[],true);
  1938. ref:=nil;
  1939. end;
  1940. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1941. begin
  1942. inherited create(absolutevarsym,n,vs_value,def,[],true);
  1943. ref:=_ref;
  1944. end;
  1945. destructor tabsolutevarsym.destroy;
  1946. begin
  1947. if assigned(ref) then
  1948. ref.free;
  1949. inherited destroy;
  1950. end;
  1951. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1952. begin
  1953. inherited ppuload(absolutevarsym,ppufile);
  1954. ref:=nil;
  1955. asmname:=nil;
  1956. abstyp:=absolutetyp(ppufile.getbyte);
  1957. case abstyp of
  1958. tovar :
  1959. ref:=ppufile.getpropaccesslist;
  1960. toasm :
  1961. asmname:=ppufile.getpshortstring;
  1962. toaddr :
  1963. addroffset:=ppufile.getpuint;
  1964. end;
  1965. ppuload_platform(ppufile);
  1966. end;
  1967. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1968. begin
  1969. inherited ppuwrite(ppufile);
  1970. ppufile.putbyte(byte(abstyp));
  1971. case abstyp of
  1972. tovar :
  1973. ppufile.putpropaccesslist(ref);
  1974. toasm :
  1975. ppufile.putstring(asmname^);
  1976. toaddr :
  1977. ppufile.putpuint(addroffset);
  1978. end;
  1979. writeentry(ppufile,ibabsolutevarsym);
  1980. end;
  1981. procedure tabsolutevarsym.buildderef;
  1982. begin
  1983. inherited buildderef;
  1984. if (abstyp=tovar) then
  1985. ref.buildderef;
  1986. end;
  1987. procedure tabsolutevarsym.deref;
  1988. begin
  1989. inherited deref;
  1990. { own absolute deref }
  1991. if (abstyp=tovar) then
  1992. ref.resolve;
  1993. end;
  1994. function tabsolutevarsym.mangledname : TSymStr;
  1995. begin
  1996. case abstyp of
  1997. toasm :
  1998. mangledname:=asmname^;
  1999. toaddr :
  2000. mangledname:='$'+tostr(addroffset);
  2001. else
  2002. internalerror(200411062);
  2003. end;
  2004. end;
  2005. {****************************************************************************
  2006. TCONSTSYM
  2007. ****************************************************************************}
  2008. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  2009. begin
  2010. inherited create(constsym,n,true);
  2011. fillchar(value, sizeof(value), #0);
  2012. consttyp:=t;
  2013. value.valueord:=v;
  2014. constdef:=def;
  2015. end;
  2016. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  2017. begin
  2018. inherited create(constsym,n,true);
  2019. fillchar(value, sizeof(value), #0);
  2020. consttyp:=t;
  2021. value.valueordptr:=v;
  2022. constdef:=def;
  2023. end;
  2024. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  2025. begin
  2026. inherited create(constsym,n,true);
  2027. fillchar(value, sizeof(value), #0);
  2028. consttyp:=t;
  2029. value.valueptr:=v;
  2030. constdef:=def;
  2031. end;
  2032. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint;def: tdef);
  2033. begin
  2034. inherited create(constsym,n,true);
  2035. fillchar(value, sizeof(value), #0);
  2036. consttyp:=t;
  2037. value.valueptr:=str;
  2038. if assigned(def) then
  2039. constdef:=def
  2040. else
  2041. constdef:=carraydef.getreusable(cansichartype,l);
  2042. value.len:=l;
  2043. end;
  2044. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  2045. begin
  2046. inherited create(constsym,n,true);
  2047. fillchar(value, sizeof(value), #0);
  2048. consttyp:=t;
  2049. pcompilerwidestring(value.valueptr):=pw;
  2050. constdef:=carraydef.getreusable(cwidechartype,getlengthwidestring(pw));
  2051. value.len:=getlengthwidestring(pw);
  2052. end;
  2053. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  2054. var
  2055. pd : pbestreal;
  2056. ps : pnormalset;
  2057. pc : pchar;
  2058. pw : pcompilerwidestring;
  2059. i : longint;
  2060. begin
  2061. inherited ppuload(constsym,ppufile);
  2062. constdef:=nil;
  2063. consttyp:=tconsttyp(ppufile.getbyte);
  2064. fillchar(value, sizeof(value), #0);
  2065. case consttyp of
  2066. constord :
  2067. begin
  2068. ppufile.getderef(constdefderef);
  2069. value.valueord:=ppufile.getexprint;
  2070. end;
  2071. constpointer :
  2072. begin
  2073. ppufile.getderef(constdefderef);
  2074. value.valueordptr:=ppufile.getptruint;
  2075. end;
  2076. constwstring :
  2077. begin
  2078. initwidestring(pw);
  2079. setlengthwidestring(pw,ppufile.getlongint);
  2080. { don't use getdata, because the compilerwidechars may have to
  2081. be byteswapped
  2082. }
  2083. {$if sizeof(tcompilerwidechar) = 2}
  2084. for i:=0 to pw^.len-1 do
  2085. pw^.data[i]:=ppufile.getword;
  2086. {$elseif sizeof(tcompilerwidechar) = 4}
  2087. for i:=0 to pw^.len-1 do
  2088. pw^.data[i]:=cardinal(ppufile.getlongint);
  2089. {$else}
  2090. {$error Unsupported tcompilerwidechar size}
  2091. {$endif}
  2092. pcompilerwidestring(value.valueptr):=pw;
  2093. end;
  2094. conststring,
  2095. constresourcestring :
  2096. begin
  2097. ppufile.getderef(constdefderef);
  2098. value.len:=ppufile.getlongint;
  2099. getmem(pc,value.len+1);
  2100. ppufile.getdata(pc^,value.len);
  2101. pc[value.len]:=#0;
  2102. value.valueptr:=pc;
  2103. end;
  2104. constreal :
  2105. begin
  2106. ppufile.getderef(constdefderef);
  2107. new(pd);
  2108. pd^:=ppufile.getreal;
  2109. value.valueptr:=pd;
  2110. end;
  2111. constset :
  2112. begin
  2113. ppufile.getderef(constdefderef);
  2114. new(ps);
  2115. ppufile.getnormalset(ps^);
  2116. value.valueptr:=ps;
  2117. end;
  2118. constguid :
  2119. begin
  2120. ppufile.getderef(constdefderef);
  2121. new(pguid(value.valueptr));
  2122. ppufile.getdata(value.valueptr^,sizeof(tguid));
  2123. end;
  2124. constnil :
  2125. ppufile.getderef(constdefderef);
  2126. else
  2127. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  2128. end;
  2129. ppuload_platform(ppufile);
  2130. end;
  2131. destructor tconstsym.destroy;
  2132. begin
  2133. case consttyp of
  2134. conststring,
  2135. constresourcestring :
  2136. freemem(pchar(value.valueptr),value.len+1);
  2137. constwstring :
  2138. donewidestring(pcompilerwidestring(value.valueptr));
  2139. constreal :
  2140. dispose(pbestreal(value.valueptr));
  2141. constset :
  2142. dispose(pnormalset(value.valueptr));
  2143. constguid :
  2144. dispose(pguid(value.valueptr));
  2145. end;
  2146. inherited destroy;
  2147. end;
  2148. procedure tconstsym.buildderef;
  2149. begin
  2150. inherited;
  2151. case consttyp of
  2152. constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constguid:
  2153. constdefderef.build(constdef);
  2154. constwstring:
  2155. ;
  2156. else
  2157. internalerror(2015120802);
  2158. end;
  2159. end;
  2160. procedure tconstsym.deref;
  2161. begin
  2162. case consttyp of
  2163. constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constguid:
  2164. constdef:=tdef(constdefderef.resolve);
  2165. constwstring:
  2166. constdef:=carraydef.getreusable(cwidechartype,getlengthwidestring(pcompilerwidestring(value.valueptr)));
  2167. else
  2168. internalerror(2015120801);
  2169. end
  2170. end;
  2171. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  2172. begin
  2173. inherited ppuwrite(ppufile);
  2174. ppufile.putbyte(byte(consttyp));
  2175. case consttyp of
  2176. constnil :
  2177. ppufile.putderef(constdefderef);
  2178. constord :
  2179. begin
  2180. ppufile.putderef(constdefderef);
  2181. ppufile.putexprint(value.valueord);
  2182. end;
  2183. constpointer :
  2184. begin
  2185. ppufile.putderef(constdefderef);
  2186. ppufile.putptruint(value.valueordptr);
  2187. end;
  2188. constwstring :
  2189. begin
  2190. { no need to store the def, we can reconstruct it }
  2191. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  2192. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  2193. end;
  2194. conststring,
  2195. constresourcestring :
  2196. begin
  2197. ppufile.putderef(constdefderef);
  2198. ppufile.putlongint(value.len);
  2199. ppufile.putdata(pchar(value.valueptr)^,value.len);
  2200. end;
  2201. constreal :
  2202. begin
  2203. ppufile.putderef(constdefderef);
  2204. ppufile.putreal(pbestreal(value.valueptr)^);
  2205. end;
  2206. constset :
  2207. begin
  2208. ppufile.putderef(constdefderef);
  2209. ppufile.putnormalset(value.valueptr^);
  2210. end;
  2211. constguid :
  2212. begin
  2213. ppufile.putderef(constdefderef);
  2214. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2215. end;
  2216. else
  2217. internalerror(13);
  2218. end;
  2219. writeentry(ppufile,ibconstsym);
  2220. end;
  2221. {****************************************************************************
  2222. TENUMSYM
  2223. ****************************************************************************}
  2224. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2225. begin
  2226. inherited create(enumsym,n,true);
  2227. definition:=def;
  2228. value:=v;
  2229. end;
  2230. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2231. begin
  2232. inherited ppuload(enumsym,ppufile);
  2233. ppufile.getderef(definitionderef);
  2234. value:=ppufile.getlongint;
  2235. ppuload_platform(ppufile);
  2236. end;
  2237. procedure tenumsym.buildderef;
  2238. begin
  2239. inherited;
  2240. definitionderef.build(definition);
  2241. end;
  2242. procedure tenumsym.deref;
  2243. begin
  2244. definition:=tenumdef(definitionderef.resolve);
  2245. end;
  2246. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2247. begin
  2248. inherited ppuwrite(ppufile);
  2249. ppufile.putderef(definitionderef);
  2250. ppufile.putlongint(value);
  2251. writeentry(ppufile,ibenumsym);
  2252. end;
  2253. {****************************************************************************
  2254. TTYPESYM
  2255. ****************************************************************************}
  2256. constructor ttypesym.create(const n : string;def:tdef;doregister:boolean);
  2257. begin
  2258. inherited create(typesym,n,doregister);
  2259. typedef:=def;
  2260. { register the typesym for the definition }
  2261. if assigned(typedef) and
  2262. (typedef.typ<>errordef) and
  2263. not(assigned(typedef.typesym)) then
  2264. typedef.typesym:=self;
  2265. end;
  2266. destructor ttypesym.destroy;
  2267. begin
  2268. inherited destroy;
  2269. end;
  2270. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2271. begin
  2272. inherited ppuload(typesym,ppufile);
  2273. ppufile.getderef(typedefderef);
  2274. fprettyname:=ppufile.getansistring;
  2275. ppuload_platform(ppufile);
  2276. end;
  2277. procedure ttypesym.buildderef;
  2278. begin
  2279. inherited;
  2280. typedefderef.build(typedef);
  2281. end;
  2282. procedure ttypesym.deref;
  2283. begin
  2284. typedef:=tdef(typedefderef.resolve);
  2285. end;
  2286. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2287. begin
  2288. inherited ppuwrite(ppufile);
  2289. ppufile.putderef(typedefderef);
  2290. ppufile.putansistring(fprettyname);
  2291. writeentry(ppufile,ibtypesym);
  2292. end;
  2293. function ttypesym.prettyname : string;
  2294. begin
  2295. if fprettyname<>'' then
  2296. result:=fprettyname
  2297. else
  2298. result:=inherited prettyname;
  2299. end;
  2300. {****************************************************************************
  2301. TSYSSYM
  2302. ****************************************************************************}
  2303. var
  2304. syssym_list : TFPHashObjectList;
  2305. constructor tsyssym.create(const n : string;l : tinlinenumber);
  2306. var
  2307. s : shortstring;
  2308. begin
  2309. inherited create(syssym,n,true);
  2310. number:=l;
  2311. str(longint(l),s);
  2312. if assigned(syssym_list.find(s)) then
  2313. internalerror(2016060303);
  2314. syssym_list.add(s,self);
  2315. end;
  2316. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2317. var
  2318. s : shortstring;
  2319. begin
  2320. inherited ppuload(syssym,ppufile);
  2321. number:=tinlinenumber(ppufile.getlongint);
  2322. ppuload_platform(ppufile);
  2323. str(longint(number),s);
  2324. if assigned(syssym_list.find(s)) then
  2325. internalerror(2016060304);
  2326. syssym_list.add(s,self);
  2327. end;
  2328. destructor tsyssym.destroy;
  2329. begin
  2330. inherited destroy;
  2331. end;
  2332. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2333. begin
  2334. inherited ppuwrite(ppufile);
  2335. ppufile.putlongint(longint(number));
  2336. writeentry(ppufile,ibsyssym);
  2337. end;
  2338. class function tsyssym.find_by_number(l:longint):tsyssym;
  2339. var
  2340. s : shortstring;
  2341. begin
  2342. str(l,s);
  2343. result:=tsyssym(syssym_list.find(s));
  2344. end;
  2345. {*****************************************************************************
  2346. TMacro
  2347. *****************************************************************************}
  2348. constructor tmacro.create(const n : string);
  2349. begin
  2350. inherited create(macrosym,n,true);
  2351. owner:=nil;
  2352. defined:=false;
  2353. is_used:=false;
  2354. is_compiler_var:=false;
  2355. buftext:=nil;
  2356. buflen:=0;
  2357. end;
  2358. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2359. begin
  2360. inherited ppuload(macrosym,ppufile);
  2361. defined:=ppufile.getboolean;
  2362. is_compiler_var:=ppufile.getboolean;
  2363. is_used:=false;
  2364. buflen:= ppufile.getlongint;
  2365. if buflen > 0 then
  2366. begin
  2367. getmem(buftext, buflen);
  2368. ppufile.getdata(buftext^, buflen)
  2369. end
  2370. else
  2371. buftext:=nil;
  2372. end;
  2373. destructor tmacro.destroy;
  2374. begin
  2375. if assigned(buftext) then
  2376. freemem(buftext);
  2377. inherited destroy;
  2378. end;
  2379. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2380. begin
  2381. inherited ppuwrite(ppufile);
  2382. ppufile.putboolean(defined);
  2383. ppufile.putboolean(is_compiler_var);
  2384. ppufile.putlongint(buflen);
  2385. if buflen > 0 then
  2386. ppufile.putdata(buftext^,buflen);
  2387. writeentry(ppufile,ibmacrosym);
  2388. end;
  2389. function tmacro.GetCopy:tmacro;
  2390. var
  2391. p : tmacro;
  2392. begin
  2393. p:=tmacro.create(realname);
  2394. p.defined:=defined;
  2395. p.is_used:=is_used;
  2396. p.is_compiler_var:=is_compiler_var;
  2397. p.buflen:=buflen;
  2398. if assigned(buftext) then
  2399. begin
  2400. getmem(p.buftext,buflen);
  2401. move(buftext^,p.buftext^,buflen);
  2402. end;
  2403. Result:=p;
  2404. end;
  2405. procedure init_symsym;
  2406. begin
  2407. syssym_list:=tfphashobjectlist.create(false);
  2408. end;
  2409. procedure done_symsym;
  2410. begin
  2411. syssym_list.free;
  2412. end;
  2413. initialization
  2414. register_initdone_proc(@init_symsym,@done_symsym);
  2415. end.