symsym.pas 67 KB

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