symsym.pas 64 KB

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