symsym.pas 81 KB

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