symsym.pas 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  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:=nil;
  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. if ppo_hasparameters in propoptions then
  875. begin
  876. parast:=tparasymtable.create(nil,0);
  877. tparasymtable(parast).ppuload(ppufile);
  878. end;
  879. end;
  880. destructor tpropertysym.destroy;
  881. var
  882. pap : tpropaccesslisttypes;
  883. begin
  884. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  885. propaccesslist[pap].free;
  886. parast.free;
  887. inherited destroy;
  888. end;
  889. procedure tpropertysym.buildderef;
  890. var
  891. pap : tpropaccesslisttypes;
  892. begin
  893. overriddenpropsymderef.build(overriddenpropsym);
  894. propdefderef.build(propdef);
  895. indexdefderef.build(indexdef);
  896. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  897. propaccesslist[pap].buildderef;
  898. if assigned(parast) then
  899. tparasymtable(parast).buildderef;
  900. end;
  901. procedure tpropertysym.deref;
  902. var
  903. pap : tpropaccesslisttypes;
  904. begin
  905. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  906. indexdef:=tdef(indexdefderef.resolve);
  907. propdef:=tdef(propdefderef.resolve);
  908. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  909. propaccesslist[pap].resolve;
  910. if assigned(parast) then
  911. tparasymtable(parast).deref;
  912. end;
  913. function tpropertysym.getsize : asizeint;
  914. begin
  915. getsize:=0;
  916. end;
  917. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  918. var
  919. pap : tpropaccesslisttypes;
  920. begin
  921. inherited ppuwrite(ppufile);
  922. ppufile.putsmallset(propoptions);
  923. ppufile.putderef(overriddenpropsymderef);
  924. ppufile.putderef(propdefderef);
  925. ppufile.putlongint(index);
  926. ppufile.putlongint(default);
  927. ppufile.putderef(indexdefderef);
  928. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  929. ppufile.putpropaccesslist(propaccesslist[pap]);
  930. ppufile.writeentry(ibpropertysym);
  931. if ppo_hasparameters in propoptions then
  932. tparasymtable(parast).ppuwrite(ppufile);
  933. end;
  934. {****************************************************************************
  935. TABSTRACTVARSYM
  936. ****************************************************************************}
  937. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  938. begin
  939. inherited create(st,n);
  940. vardef:=def;
  941. varspez:=vsp;
  942. varstate:=vs_declared;
  943. varoptions:=vopts;
  944. end;
  945. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  946. begin
  947. inherited ppuload(st,ppufile);
  948. varstate:=vs_readwritten;
  949. varspez:=tvarspez(ppufile.getbyte);
  950. varregable:=tvarregable(ppufile.getbyte);
  951. addr_taken:=boolean(ppufile.getbyte);
  952. ppufile.getderef(vardefderef);
  953. ppufile.getsmallset(varoptions);
  954. end;
  955. destructor tabstractvarsym.destroy;
  956. begin
  957. if assigned(notifications) then
  958. notifications.destroy;
  959. inherited destroy;
  960. end;
  961. procedure tabstractvarsym.buildderef;
  962. begin
  963. vardefderef.build(vardef);
  964. end;
  965. procedure tabstractvarsym.deref;
  966. var
  967. oldvarregable: tvarregable;
  968. begin
  969. { setting the vardef also updates varregable. We just loaded this }
  970. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  971. { tw7817b.pp: the address is taken of a local variable in an }
  972. { inlined procedure -> must remain non-regable when inlining) }
  973. oldvarregable:=varregable;
  974. vardef:=tdef(vardefderef.resolve);
  975. varregable:=oldvarregable;
  976. end;
  977. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  978. var
  979. oldintfcrc : boolean;
  980. begin
  981. inherited ppuwrite(ppufile);
  982. ppufile.putbyte(byte(varspez));
  983. oldintfcrc:=ppufile.do_crc;
  984. ppufile.do_crc:=false;
  985. ppufile.putbyte(byte(varregable));
  986. ppufile.putbyte(byte(addr_taken));
  987. ppufile.do_crc:=oldintfcrc;
  988. ppufile.putderef(vardefderef);
  989. ppufile.putsmallset(varoptions);
  990. end;
  991. function tabstractvarsym.getsize : asizeint;
  992. begin
  993. if assigned(vardef) and
  994. ((vardef.typ<>arraydef) or
  995. is_dynamic_array(vardef) or
  996. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  997. result:=vardef.size
  998. else
  999. result:=0;
  1000. end;
  1001. function tabstractvarsym.getpackedbitsize : longint;
  1002. begin
  1003. { bitpacking is only done for ordinals }
  1004. if not is_ordinal(vardef) then
  1005. internalerror(2006082010);
  1006. result:=vardef.packedbitsize;
  1007. end;
  1008. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1009. begin
  1010. { Register variables are not allowed in the following cases:
  1011. - regvars are disabled
  1012. - exceptions are used (after an exception is raised the contents of the
  1013. registers is not valid anymore)
  1014. - it has a local copy
  1015. - the value needs to be in memory (i.e. reference counted) }
  1016. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1017. not(pi_has_assembler_block in current_procinfo.flags) and
  1018. not(pi_uses_exceptions in current_procinfo.flags) and
  1019. not(pi_has_interproclabel in current_procinfo.flags) and
  1020. not(vo_has_local_copy in varoptions) and
  1021. ((refpara and
  1022. (varregable <> vr_none)) or
  1023. (not refpara and
  1024. not(varregable in [vr_none,vr_addr])))
  1025. {$if not defined(powerpc) and not defined(powerpc64)}
  1026. and ((vardef.typ <> recorddef) or
  1027. (varregable = vr_addr) or
  1028. not(varstate in [vs_written,vs_readwritten]));
  1029. {$endif}
  1030. end;
  1031. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1032. var n:Tnotification;
  1033. begin
  1034. if assigned(notifications) then
  1035. begin
  1036. n:=Tnotification(notifications.first);
  1037. while assigned(n) do
  1038. begin
  1039. if what in n.flags then
  1040. n.callback(what,self);
  1041. n:=Tnotification(n.next);
  1042. end;
  1043. end;
  1044. end;
  1045. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1046. Tnotification_callback):cardinal;
  1047. var n:Tnotification;
  1048. begin
  1049. if not assigned(notifications) then
  1050. notifications:=Tlinkedlist.create;
  1051. n:=Tnotification.create(flags,callback);
  1052. register_notification:=n.id;
  1053. notifications.concat(n);
  1054. end;
  1055. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1056. var n:Tnotification;
  1057. begin
  1058. if not assigned(notifications) then
  1059. internalerror(200212311)
  1060. else
  1061. begin
  1062. n:=Tnotification(notifications.first);
  1063. while assigned(n) do
  1064. begin
  1065. if n.id=id then
  1066. begin
  1067. notifications.remove(n);
  1068. n.destroy;
  1069. exit;
  1070. end;
  1071. n:=Tnotification(n.next);
  1072. end;
  1073. internalerror(200212311)
  1074. end;
  1075. end;
  1076. procedure tabstractvarsym.setvardef(def:tdef);
  1077. begin
  1078. _vardef := def;
  1079. { can we load the value into a register ? }
  1080. if not assigned(owner) or
  1081. (owner.symtabletype in [localsymtable,parasymtable]) or
  1082. (
  1083. (owner.symtabletype=staticsymtable) and
  1084. not(cs_create_pic in current_settings.moduleswitches)
  1085. ) then
  1086. begin
  1087. if tstoreddef(vardef).is_intregable then
  1088. varregable:=vr_intreg
  1089. else
  1090. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1091. if {(
  1092. not assigned(owner) or
  1093. (owner.symtabletype<>staticsymtable)
  1094. ) and }
  1095. tstoreddef(vardef).is_fpuregable then
  1096. begin
  1097. if use_vectorfpu(vardef) then
  1098. varregable:=vr_mmreg
  1099. else
  1100. varregable:=vr_fpureg;
  1101. end;
  1102. end;
  1103. end;
  1104. {****************************************************************************
  1105. TFIELDVARSYM
  1106. ****************************************************************************}
  1107. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1108. begin
  1109. inherited create(fieldvarsym,n,vsp,def,vopts);
  1110. fieldoffset:=-1;
  1111. end;
  1112. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1113. begin
  1114. inherited ppuload(fieldvarsym,ppufile);
  1115. fieldoffset:=ppufile.getaint;
  1116. end;
  1117. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1118. begin
  1119. inherited ppuwrite(ppufile);
  1120. ppufile.putaint(fieldoffset);
  1121. ppufile.writeentry(ibfieldvarsym);
  1122. end;
  1123. function tfieldvarsym.mangledname:string;
  1124. var
  1125. srsym : tsym;
  1126. srsymtable : tsymtable;
  1127. begin
  1128. if sp_static in symoptions then
  1129. begin
  1130. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1131. result:=srsym.mangledname
  1132. { when generating the debug info for the module in which the }
  1133. { symbol is defined, the localsymtable of that module is }
  1134. { already popped from the symtablestack }
  1135. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1136. result:=srsym.mangledname
  1137. else
  1138. internalerror(2007012501);
  1139. end
  1140. else if is_objcclass(tdef(owner.defowner)) then
  1141. begin
  1142. if assigned(objcoffsetmangledname) then
  1143. result:=objcoffsetmangledname^
  1144. else
  1145. begin
  1146. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1147. objcoffsetmangledname:=stringdup(result);
  1148. end;
  1149. end
  1150. else
  1151. result:=inherited mangledname;
  1152. end;
  1153. destructor tfieldvarsym.destroy;
  1154. begin
  1155. stringdispose(objcoffsetmangledname);
  1156. inherited destroy;
  1157. end;
  1158. {****************************************************************************
  1159. TABSTRACTNORMALVARSYM
  1160. ****************************************************************************}
  1161. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1162. begin
  1163. inherited create(st,n,vsp,def,vopts);
  1164. fillchar(localloc,sizeof(localloc),0);
  1165. fillchar(initialloc,sizeof(initialloc),0);
  1166. defaultconstsym:=nil;
  1167. end;
  1168. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1169. begin
  1170. inherited ppuload(st,ppufile);
  1171. fillchar(localloc,sizeof(localloc),0);
  1172. fillchar(initialloc,sizeof(initialloc),0);
  1173. ppufile.getderef(defaultconstsymderef);
  1174. end;
  1175. procedure tabstractnormalvarsym.buildderef;
  1176. begin
  1177. inherited buildderef;
  1178. defaultconstsymderef.build(defaultconstsym);
  1179. end;
  1180. procedure tabstractnormalvarsym.deref;
  1181. begin
  1182. inherited deref;
  1183. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1184. end;
  1185. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1186. begin
  1187. inherited ppuwrite(ppufile);
  1188. ppufile.putderef(defaultconstsymderef);
  1189. end;
  1190. {****************************************************************************
  1191. Tstaticvarsym
  1192. ****************************************************************************}
  1193. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1194. begin
  1195. inherited create(staticvarsym,n,vsp,def,vopts);
  1196. _mangledname:=nil;
  1197. end;
  1198. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1199. begin
  1200. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1201. end;
  1202. constructor tstaticvarsym.create_C(const n,mangled : string;vsp:tvarspez;def:tdef);
  1203. begin
  1204. tstaticvarsym(self).create(n,vsp,def,[]);
  1205. set_mangledname(mangled);
  1206. end;
  1207. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1208. begin
  1209. inherited ppuload(staticvarsym,ppufile);
  1210. if vo_has_mangledname in varoptions then
  1211. _mangledname:=stringdup(ppufile.getstring)
  1212. else
  1213. _mangledname:=nil;
  1214. if vo_has_section in varoptions then
  1215. section:=ppufile.getansistring;
  1216. end;
  1217. destructor tstaticvarsym.destroy;
  1218. begin
  1219. if assigned(_mangledname) then
  1220. begin
  1221. {$ifdef MEMDEBUG}
  1222. memmanglednames.start;
  1223. {$endif MEMDEBUG}
  1224. stringdispose(_mangledname);
  1225. {$ifdef MEMDEBUG}
  1226. memmanglednames.stop;
  1227. {$endif MEMDEBUG}
  1228. end;
  1229. inherited destroy;
  1230. end;
  1231. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1232. begin
  1233. inherited ppuwrite(ppufile);
  1234. if vo_has_mangledname in varoptions then
  1235. ppufile.putstring(_mangledname^);
  1236. if vo_has_section in varoptions then
  1237. ppufile.putansistring(section);
  1238. ppufile.writeentry(ibstaticvarsym);
  1239. end;
  1240. function tstaticvarsym.mangledname:string;
  1241. var
  1242. prefix : string[2];
  1243. begin
  1244. if not assigned(_mangledname) then
  1245. begin
  1246. if (vo_is_typed_const in varoptions) then
  1247. prefix:='TC'
  1248. else
  1249. prefix:='U';
  1250. {$ifdef compress}
  1251. _mangledname:=stringdup(minilzw_encode(make_mangledname(prefix,owner,name)));
  1252. {$else}
  1253. _mangledname:=stringdup(make_mangledname(prefix,owner,name));
  1254. {$endif}
  1255. end;
  1256. result:=_mangledname^;
  1257. end;
  1258. procedure tstaticvarsym.set_mangledname(const s:string);
  1259. begin
  1260. stringdispose(_mangledname);
  1261. {$ifdef compress}
  1262. _mangledname:=stringdup(minilzw_encode(s));
  1263. {$else}
  1264. _mangledname:=stringdup(s);
  1265. {$endif}
  1266. include(varoptions,vo_has_mangledname);
  1267. end;
  1268. {****************************************************************************
  1269. TLOCALVARSYM
  1270. ****************************************************************************}
  1271. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1272. begin
  1273. inherited create(localvarsym,n,vsp,def,vopts);
  1274. end;
  1275. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1276. begin
  1277. inherited ppuload(localvarsym,ppufile);
  1278. end;
  1279. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1280. begin
  1281. inherited ppuwrite(ppufile);
  1282. ppufile.writeentry(iblocalvarsym);
  1283. end;
  1284. {****************************************************************************
  1285. TPARAVARSYM
  1286. ****************************************************************************}
  1287. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1288. begin
  1289. inherited create(paravarsym,n,vsp,def,vopts);
  1290. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) then
  1291. varstate := vs_initialised;
  1292. paranr:=nr;
  1293. paraloc[calleeside].init;
  1294. paraloc[callerside].init;
  1295. end;
  1296. destructor tparavarsym.destroy;
  1297. begin
  1298. paraloc[calleeside].done;
  1299. paraloc[callerside].done;
  1300. inherited destroy;
  1301. end;
  1302. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1303. var
  1304. b : byte;
  1305. begin
  1306. inherited ppuload(paravarsym,ppufile);
  1307. paranr:=ppufile.getword;
  1308. univpara:=boolean(ppufile.getbyte);
  1309. { The var state of parameter symbols is fixed after writing them so
  1310. we write them to the unit file.
  1311. This enables constant folding for inline procedures loaded from units
  1312. }
  1313. varstate:=tvarstate(ppufile.getbyte);
  1314. paraloc[calleeside].init;
  1315. paraloc[callerside].init;
  1316. if vo_has_explicit_paraloc in varoptions then
  1317. begin
  1318. paraloc[callerside].alignment:=ppufile.getbyte;
  1319. b:=ppufile.getbyte;
  1320. if b<>sizeof(paraloc[callerside].location^) then
  1321. internalerror(200411154);
  1322. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1323. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1324. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1325. end;
  1326. end;
  1327. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1328. var
  1329. oldintfcrc : boolean;
  1330. begin
  1331. inherited ppuwrite(ppufile);
  1332. ppufile.putword(paranr);
  1333. ppufile.putbyte(byte(univpara));
  1334. { The var state of parameter symbols is fixed after writing them so
  1335. we write them to the unit file.
  1336. This enables constant folding for inline procedures loaded from units
  1337. }
  1338. oldintfcrc:=ppufile.do_crc;
  1339. ppufile.do_crc:=false;
  1340. ppufile.putbyte(ord(varstate));
  1341. ppufile.do_crc:=oldintfcrc;
  1342. if vo_has_explicit_paraloc in varoptions then
  1343. begin
  1344. paraloc[callerside].check_simple_location;
  1345. ppufile.putbyte(sizeof(paraloc[callerside].alignment));
  1346. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1347. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1348. end;
  1349. ppufile.writeentry(ibparavarsym);
  1350. end;
  1351. {****************************************************************************
  1352. TABSOLUTEVARSYM
  1353. ****************************************************************************}
  1354. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1355. begin
  1356. inherited create(absolutevarsym,n,vs_value,def,[]);
  1357. ref:=nil;
  1358. end;
  1359. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1360. begin
  1361. inherited create(absolutevarsym,n,vs_value,def,[]);
  1362. ref:=_ref;
  1363. end;
  1364. destructor tabsolutevarsym.destroy;
  1365. begin
  1366. if assigned(ref) then
  1367. ref.free;
  1368. inherited destroy;
  1369. end;
  1370. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1371. begin
  1372. inherited ppuload(absolutevarsym,ppufile);
  1373. ref:=nil;
  1374. asmname:=nil;
  1375. abstyp:=absolutetyp(ppufile.getbyte);
  1376. {$ifdef i386}
  1377. absseg:=false;
  1378. {$endif i386}
  1379. case abstyp of
  1380. tovar :
  1381. ref:=ppufile.getpropaccesslist;
  1382. toasm :
  1383. asmname:=stringdup(ppufile.getstring);
  1384. toaddr :
  1385. begin
  1386. addroffset:=ppufile.getaword;
  1387. {$ifdef i386}
  1388. absseg:=boolean(ppufile.getbyte);
  1389. {$endif i386}
  1390. end;
  1391. end;
  1392. end;
  1393. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1394. begin
  1395. inherited ppuwrite(ppufile);
  1396. ppufile.putbyte(byte(abstyp));
  1397. case abstyp of
  1398. tovar :
  1399. ppufile.putpropaccesslist(ref);
  1400. toasm :
  1401. ppufile.putstring(asmname^);
  1402. toaddr :
  1403. begin
  1404. ppufile.putaword(addroffset);
  1405. {$ifdef i386}
  1406. ppufile.putbyte(byte(absseg));
  1407. {$endif i386}
  1408. end;
  1409. end;
  1410. ppufile.writeentry(ibabsolutevarsym);
  1411. end;
  1412. procedure tabsolutevarsym.buildderef;
  1413. begin
  1414. inherited buildderef;
  1415. if (abstyp=tovar) then
  1416. ref.buildderef;
  1417. end;
  1418. procedure tabsolutevarsym.deref;
  1419. begin
  1420. inherited deref;
  1421. { own absolute deref }
  1422. if (abstyp=tovar) then
  1423. ref.resolve;
  1424. end;
  1425. function tabsolutevarsym.mangledname : string;
  1426. begin
  1427. case abstyp of
  1428. toasm :
  1429. mangledname:=asmname^;
  1430. toaddr :
  1431. mangledname:='$'+tostr(addroffset);
  1432. else
  1433. internalerror(200411062);
  1434. end;
  1435. end;
  1436. {****************************************************************************
  1437. TCONSTSYM
  1438. ****************************************************************************}
  1439. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1440. begin
  1441. inherited create(constsym,n);
  1442. fillchar(value, sizeof(value), #0);
  1443. consttyp:=t;
  1444. value.valueord:=v;
  1445. constdef:=def;
  1446. end;
  1447. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1448. begin
  1449. inherited create(constsym,n);
  1450. fillchar(value, sizeof(value), #0);
  1451. consttyp:=t;
  1452. value.valueordptr:=v;
  1453. constdef:=def;
  1454. end;
  1455. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1456. begin
  1457. inherited create(constsym,n);
  1458. fillchar(value, sizeof(value), #0);
  1459. consttyp:=t;
  1460. value.valueptr:=v;
  1461. constdef:=def;
  1462. end;
  1463. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1464. begin
  1465. inherited create(constsym,n);
  1466. fillchar(value, sizeof(value), #0);
  1467. consttyp:=t;
  1468. value.valueptr:=str;
  1469. constdef:=nil;
  1470. value.len:=l;
  1471. end;
  1472. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1473. begin
  1474. inherited create(constsym,n);
  1475. fillchar(value, sizeof(value), #0);
  1476. consttyp:=t;
  1477. pcompilerwidestring(value.valueptr):=pw;
  1478. constdef:=nil;
  1479. value.len:=getlengthwidestring(pw);
  1480. end;
  1481. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1482. var
  1483. pd : pbestreal;
  1484. ps : pnormalset;
  1485. pc : pchar;
  1486. pw : pcompilerwidestring;
  1487. i : longint;
  1488. begin
  1489. inherited ppuload(constsym,ppufile);
  1490. constdef:=nil;
  1491. consttyp:=tconsttyp(ppufile.getbyte);
  1492. fillchar(value, sizeof(value), #0);
  1493. case consttyp of
  1494. constord :
  1495. begin
  1496. ppufile.getderef(constdefderef);
  1497. value.valueord:=ppufile.getexprint;
  1498. end;
  1499. constpointer :
  1500. begin
  1501. ppufile.getderef(constdefderef);
  1502. value.valueordptr:=ppufile.getptruint;
  1503. end;
  1504. constwstring :
  1505. begin
  1506. initwidestring(pw);
  1507. setlengthwidestring(pw,ppufile.getlongint);
  1508. { don't use getdata, because the compilerwidechars may have to
  1509. be byteswapped
  1510. }
  1511. {$if sizeof(tcompilerwidechar) = 2}
  1512. for i:=0 to pw^.len-1 do
  1513. pw^.data[i]:=ppufile.getword;
  1514. {$elseif sizeof(tcompilerwidechar) = 4}
  1515. for i:=0 to pw^.len-1 do
  1516. pw^.data[i]:=cardinal(ppufile.getlongint);
  1517. {$else}
  1518. {$error Unsupported tcompilerwidechar size}
  1519. {$endif}
  1520. pcompilerwidestring(value.valueptr):=pw;
  1521. end;
  1522. conststring,
  1523. constresourcestring :
  1524. begin
  1525. value.len:=ppufile.getlongint;
  1526. getmem(pc,value.len+1);
  1527. ppufile.getdata(pc^,value.len);
  1528. pc[value.len]:=#0;
  1529. value.valueptr:=pc;
  1530. end;
  1531. constreal :
  1532. begin
  1533. new(pd);
  1534. pd^:=ppufile.getreal;
  1535. value.valueptr:=pd;
  1536. end;
  1537. constset :
  1538. begin
  1539. ppufile.getderef(constdefderef);
  1540. new(ps);
  1541. ppufile.getnormalset(ps^);
  1542. value.valueptr:=ps;
  1543. end;
  1544. constguid :
  1545. begin
  1546. new(pguid(value.valueptr));
  1547. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1548. end;
  1549. constnil : ;
  1550. else
  1551. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1552. end;
  1553. end;
  1554. destructor tconstsym.destroy;
  1555. begin
  1556. case consttyp of
  1557. conststring,
  1558. constresourcestring :
  1559. freemem(pchar(value.valueptr),value.len+1);
  1560. constwstring :
  1561. donewidestring(pcompilerwidestring(value.valueptr));
  1562. constreal :
  1563. dispose(pbestreal(value.valueptr));
  1564. constset :
  1565. dispose(pnormalset(value.valueptr));
  1566. constguid :
  1567. dispose(pguid(value.valueptr));
  1568. end;
  1569. inherited destroy;
  1570. end;
  1571. procedure tconstsym.buildderef;
  1572. begin
  1573. if consttyp in [constord,constpointer,constset] then
  1574. constdefderef.build(constdef);
  1575. end;
  1576. procedure tconstsym.deref;
  1577. begin
  1578. if consttyp in [constord,constpointer,constset] then
  1579. constdef:=tdef(constdefderef.resolve);
  1580. end;
  1581. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1582. begin
  1583. inherited ppuwrite(ppufile);
  1584. ppufile.putbyte(byte(consttyp));
  1585. case consttyp of
  1586. constnil : ;
  1587. constord :
  1588. begin
  1589. ppufile.putderef(constdefderef);
  1590. ppufile.putexprint(value.valueord);
  1591. end;
  1592. constpointer :
  1593. begin
  1594. ppufile.putderef(constdefderef);
  1595. ppufile.putptruint(value.valueordptr);
  1596. end;
  1597. constwstring :
  1598. begin
  1599. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  1600. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  1601. end;
  1602. conststring,
  1603. constresourcestring :
  1604. begin
  1605. ppufile.putlongint(value.len);
  1606. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1607. end;
  1608. constreal :
  1609. ppufile.putreal(pbestreal(value.valueptr)^);
  1610. constset :
  1611. begin
  1612. ppufile.putderef(constdefderef);
  1613. ppufile.putnormalset(value.valueptr^);
  1614. end;
  1615. constguid :
  1616. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1617. else
  1618. internalerror(13);
  1619. end;
  1620. ppufile.writeentry(ibconstsym);
  1621. end;
  1622. {****************************************************************************
  1623. TENUMSYM
  1624. ****************************************************************************}
  1625. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1626. begin
  1627. inherited create(enumsym,n);
  1628. definition:=def;
  1629. value:=v;
  1630. end;
  1631. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1632. begin
  1633. inherited ppuload(enumsym,ppufile);
  1634. ppufile.getderef(definitionderef);
  1635. value:=ppufile.getlongint;
  1636. end;
  1637. procedure tenumsym.buildderef;
  1638. begin
  1639. definitionderef.build(definition);
  1640. end;
  1641. procedure tenumsym.deref;
  1642. begin
  1643. definition:=tenumdef(definitionderef.resolve);
  1644. end;
  1645. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1646. begin
  1647. inherited ppuwrite(ppufile);
  1648. ppufile.putderef(definitionderef);
  1649. ppufile.putlongint(value);
  1650. ppufile.writeentry(ibenumsym);
  1651. end;
  1652. {****************************************************************************
  1653. TTYPESYM
  1654. ****************************************************************************}
  1655. constructor ttypesym.create(const n : string;def:tdef);
  1656. begin
  1657. inherited create(typesym,n);
  1658. typedef:=def;
  1659. { register the typesym for the definition }
  1660. if assigned(typedef) and
  1661. (typedef.typ<>errordef) and
  1662. not(assigned(typedef.typesym)) then
  1663. typedef.typesym:=self;
  1664. end;
  1665. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1666. begin
  1667. inherited ppuload(typesym,ppufile);
  1668. ppufile.getderef(typedefderef);
  1669. fprettyname:=ppufile.getansistring;
  1670. end;
  1671. procedure ttypesym.buildderef;
  1672. begin
  1673. typedefderef.build(typedef);
  1674. end;
  1675. procedure ttypesym.deref;
  1676. begin
  1677. typedef:=tdef(typedefderef.resolve);
  1678. end;
  1679. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1680. begin
  1681. inherited ppuwrite(ppufile);
  1682. ppufile.putderef(typedefderef);
  1683. ppufile.putansistring(fprettyname);
  1684. ppufile.writeentry(ibtypesym);
  1685. end;
  1686. function ttypesym.prettyname : string;
  1687. begin
  1688. if fprettyname<>'' then
  1689. result:=fprettyname
  1690. else
  1691. result:=inherited prettyname;
  1692. end;
  1693. {****************************************************************************
  1694. TSYSSYM
  1695. ****************************************************************************}
  1696. constructor tsyssym.create(const n : string;l : longint);
  1697. begin
  1698. inherited create(syssym,n);
  1699. number:=l;
  1700. end;
  1701. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1702. begin
  1703. inherited ppuload(syssym,ppufile);
  1704. number:=ppufile.getlongint;
  1705. end;
  1706. destructor tsyssym.destroy;
  1707. begin
  1708. inherited destroy;
  1709. end;
  1710. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1711. begin
  1712. inherited ppuwrite(ppufile);
  1713. ppufile.putlongint(number);
  1714. ppufile.writeentry(ibsyssym);
  1715. end;
  1716. {*****************************************************************************
  1717. TMacro
  1718. *****************************************************************************}
  1719. constructor tmacro.create(const n : string);
  1720. begin
  1721. inherited create(macrosym,n);
  1722. owner:=nil;
  1723. defined:=false;
  1724. is_used:=false;
  1725. is_compiler_var:=false;
  1726. buftext:=nil;
  1727. buflen:=0;
  1728. end;
  1729. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  1730. begin
  1731. inherited ppuload(macrosym,ppufile);
  1732. defined:=boolean(ppufile.getbyte);
  1733. is_compiler_var:=boolean(ppufile.getbyte);
  1734. is_used:=false;
  1735. buflen:= ppufile.getlongint;
  1736. if buflen > 0 then
  1737. begin
  1738. getmem(buftext, buflen);
  1739. ppufile.getdata(buftext^, buflen)
  1740. end
  1741. else
  1742. buftext:=nil;
  1743. end;
  1744. destructor tmacro.destroy;
  1745. begin
  1746. if assigned(buftext) then
  1747. freemem(buftext);
  1748. inherited destroy;
  1749. end;
  1750. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  1751. begin
  1752. inherited ppuwrite(ppufile);
  1753. ppufile.putbyte(byte(defined));
  1754. ppufile.putbyte(byte(is_compiler_var));
  1755. ppufile.putlongint(buflen);
  1756. if buflen > 0 then
  1757. ppufile.putdata(buftext^,buflen);
  1758. ppufile.writeentry(ibmacrosym);
  1759. end;
  1760. function tmacro.GetCopy:tmacro;
  1761. var
  1762. p : tmacro;
  1763. begin
  1764. p:=tmacro.create(realname);
  1765. p.defined:=defined;
  1766. p.is_used:=is_used;
  1767. p.is_compiler_var:=is_compiler_var;
  1768. p.buflen:=buflen;
  1769. if assigned(buftext) then
  1770. begin
  1771. getmem(p.buftext,buflen);
  1772. move(buftext^,p.buftext^,buflen);
  1773. end;
  1774. Result:=p;
  1775. end;
  1776. end.