symsym.pas 83 KB

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