symsym.pas 65 KB

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