symsym.pas 71 KB

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