2
0

symsym.pas 77 KB

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