symsym.pas 66 KB

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