symsym.pas 66 KB

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