2
0

symsym.pas 64 KB

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