symsym.pas 89 KB

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