symsym.pas 83 KB

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