symsym.pas 77 KB

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