symsym.pas 86 KB

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