symsym.pas 89 KB

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