symsym.pas 86 KB

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