symsym.pas 65 KB

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