symsym.pas 65 KB

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