symsym.pas 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618
  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:TSymStr;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_bytype_parameterless(pt:Tproctypeoption):Tprocdef;
  99. function find_procdef_bypara(para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  100. function find_procdef_bytype_and_para(pt:Tproctypeoption;para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  101. function find_procdef_byoptions(ops:tprocoptions): Tprocdef;
  102. function find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  103. function find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  104. function find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  105. property ProcdefList:TFPObjectList read FProcdefList;
  106. end;
  107. tgenericconstraintflag=(
  108. gcf_constructor,
  109. gcf_class,
  110. gcf_record
  111. );
  112. tgenericconstraintflags=set of tgenericconstraintflag;
  113. tgenericconstraintdata=class
  114. basedef : tdef;
  115. basedefderef : tderef;
  116. interfaces : tfpobjectlist;
  117. interfacesderef : tfplist;
  118. flags : tgenericconstraintflags;
  119. constructor create;
  120. destructor destroy;override;
  121. procedure ppuload(ppufile:tcompilerppufile);
  122. procedure ppuwrite(ppufile:tcompilerppufile);
  123. procedure buildderef;
  124. procedure deref;
  125. end;
  126. ttypesym = class(Tstoredsym)
  127. public
  128. genconstraintdata : tgenericconstraintdata;
  129. typedef : tdef;
  130. typedefderef : tderef;
  131. fprettyname : ansistring;
  132. constructor create(const n : string;def:tdef);
  133. destructor destroy;override;
  134. constructor ppuload(ppufile:tcompilerppufile);
  135. procedure ppuwrite(ppufile:tcompilerppufile);override;
  136. procedure buildderef;override;
  137. procedure deref;override;
  138. function prettyname : string;override;
  139. end;
  140. tabstractvarsym = class(tstoredsym)
  141. varoptions : tvaroptions;
  142. notifications : Tlinkedlist;
  143. varspez : tvarspez; { sets the type of access }
  144. varregable : tvarregable;
  145. varstate : tvarstate;
  146. { Has the address of this variable potentially escaped the }
  147. { block in which is was declared? }
  148. { could also be part of tabstractnormalvarsym, but there's }
  149. { one byte left here till the next 4 byte alignment }
  150. addr_taken : boolean;
  151. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  152. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  153. destructor destroy;override;
  154. procedure ppuwrite(ppufile:tcompilerppufile);override;
  155. procedure buildderef;override;
  156. procedure deref;override;
  157. function getsize : asizeint;
  158. function getpackedbitsize : longint;
  159. function is_regvar(refpara: boolean):boolean;
  160. procedure trigger_notifications(what:Tnotification_flag);
  161. function register_notification(flags:Tnotification_flags;
  162. callback:Tnotification_callback):cardinal;
  163. procedure unregister_notification(id:cardinal);
  164. private
  165. _vardef : tdef;
  166. vardefderef : tderef;
  167. procedure setvardef(def:tdef);
  168. public
  169. property vardef: tdef read _vardef write setvardef;
  170. end;
  171. tfieldvarsym = class(tabstractvarsym)
  172. fieldoffset : asizeint; { offset in record/object }
  173. externalname : pshortstring;
  174. {$ifdef symansistr}
  175. cachedmangledname: TSymStr; { mangled name for ObjC or Java }
  176. {$else symansistr}
  177. cachedmangledname: pshortstring; { mangled name for ObjC or Java }
  178. {$endif symansistr}
  179. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  180. constructor ppuload(ppufile:tcompilerppufile);
  181. procedure ppuwrite(ppufile:tcompilerppufile);override;
  182. procedure set_externalname(const s:string);
  183. function mangledname:TSymStr;override;
  184. destructor destroy;override;
  185. end;
  186. tabstractnormalvarsym = class(tabstractvarsym)
  187. defaultconstsym : tsym;
  188. defaultconstsymderef : tderef;
  189. localloc : TLocation; { register/reference for local var }
  190. initialloc : TLocation; { initial location so it can still be initialized later after the location was changed by SSA }
  191. currentregloc : TLocation; { current registers for register variables with moving register numbers }
  192. inparentfpstruct : boolean; { migrated to a parentfpstruct because of nested access (not written to ppu, because not important and would change interface crc) }
  193. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  194. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  195. function globalasmsym: boolean;
  196. procedure ppuwrite(ppufile:tcompilerppufile);override;
  197. procedure buildderef;override;
  198. procedure deref;override;
  199. end;
  200. tlocalvarsym = class(tabstractnormalvarsym)
  201. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  202. constructor ppuload(ppufile:tcompilerppufile);
  203. procedure ppuwrite(ppufile:tcompilerppufile);override;
  204. end;
  205. tparavarsym = class(tabstractnormalvarsym)
  206. paraloc : array[tcallercallee] of TCGPara;
  207. paranr : word; { position of this parameter }
  208. { in MacPas mode, "univ" parameters mean that type checking should
  209. be disabled, except that the size of the passed parameter must
  210. match the size of the formal parameter }
  211. univpara : boolean;
  212. {$ifdef EXTDEBUG}
  213. eqval : tequaltype;
  214. {$endif EXTDEBUG}
  215. constructor create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  216. constructor ppuload(ppufile:tcompilerppufile);
  217. destructor destroy;override;
  218. procedure ppuwrite(ppufile:tcompilerppufile);override;
  219. function needs_finalization: boolean;
  220. end;
  221. tstaticvarsym = class(tabstractnormalvarsym)
  222. private
  223. {$ifdef symansistr}
  224. _mangledbasename,
  225. _mangledname : TSymStr;
  226. {$else symansistr}
  227. _mangledbasename,
  228. _mangledname : pshortstring;
  229. {$endif symansistr}
  230. public
  231. section : ansistring;
  232. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  233. constructor create_dll(const n : string;vsp:tvarspez;def:tdef);
  234. constructor create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  235. constructor ppuload(ppufile:tcompilerppufile);
  236. destructor destroy;override;
  237. procedure ppuwrite(ppufile:tcompilerppufile);override;
  238. function mangledname:TSymStr;override;
  239. procedure set_mangledbasename(const s: TSymStr);
  240. function mangledbasename: TSymStr;
  241. procedure set_mangledname(const s:TSymStr);
  242. procedure set_raw_mangledname(const s:TSymStr);
  243. end;
  244. tabsolutevarsym = class(tabstractvarsym)
  245. public
  246. abstyp : absolutetyp;
  247. {$ifdef i386}
  248. absseg : boolean;
  249. {$endif i386}
  250. asmname : pshortstring;
  251. addroffset : aword;
  252. ref : tpropaccesslist;
  253. constructor create(const n : string;def:tdef);
  254. constructor create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  255. destructor destroy;override;
  256. constructor ppuload(ppufile:tcompilerppufile);
  257. procedure buildderef;override;
  258. procedure deref;override;
  259. function mangledname : TSymStr;override;
  260. procedure ppuwrite(ppufile:tcompilerppufile);override;
  261. end;
  262. tpropaccesslisttypes=(palt_none,palt_read,palt_write,palt_stored);
  263. tpropertysym = class(Tstoredsym)
  264. propoptions : tpropertyoptions;
  265. overriddenpropsym : tpropertysym;
  266. overriddenpropsymderef : tderef;
  267. propdef : tdef;
  268. propdefderef : tderef;
  269. indexdef : tdef;
  270. indexdefderef : tderef;
  271. index,
  272. default : longint;
  273. dispid : longint;
  274. propaccesslist: array[tpropaccesslisttypes] of tpropaccesslist;
  275. parast : tsymtable;
  276. constructor create(const n : string);
  277. destructor destroy;override;
  278. constructor ppuload(ppufile:tcompilerppufile);
  279. function getsize : asizeint;
  280. procedure ppuwrite(ppufile:tcompilerppufile);override;
  281. procedure buildderef;override;
  282. procedure deref;override;
  283. function getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  284. { copies the settings of the current propertysym to p; a bit like
  285. a form of getcopy, but without the name }
  286. procedure makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  287. procedure add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  288. procedure add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  289. end;
  290. tconstvalue = record
  291. case integer of
  292. 0: (valueord : tconstexprint);
  293. 1: (valueordptr : tconstptruint);
  294. 2: (valueptr : pointer; len : longint);
  295. end;
  296. tconstsym = class(tstoredsym)
  297. constdef : tdef;
  298. constdefderef : tderef;
  299. consttyp : tconsttyp;
  300. value : tconstvalue;
  301. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  302. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  303. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  304. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  305. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  306. constructor ppuload(ppufile:tcompilerppufile);
  307. destructor destroy;override;
  308. procedure buildderef;override;
  309. procedure deref;override;
  310. procedure ppuwrite(ppufile:tcompilerppufile);override;
  311. end;
  312. tenumsym = class(Tstoredsym)
  313. value : longint;
  314. definition : tenumdef;
  315. definitionderef : tderef;
  316. constructor create(const n : string;def : tenumdef;v : longint);
  317. constructor ppuload(ppufile:tcompilerppufile);
  318. procedure ppuwrite(ppufile:tcompilerppufile);override;
  319. procedure buildderef;override;
  320. procedure deref;override;
  321. end;
  322. tsyssym = class(Tstoredsym)
  323. number : longint;
  324. constructor create(const n : string;l : longint);
  325. constructor ppuload(ppufile:tcompilerppufile);
  326. destructor destroy;override;
  327. procedure ppuwrite(ppufile:tcompilerppufile);override;
  328. end;
  329. const
  330. maxmacrolen=16*1024;
  331. type
  332. pmacrobuffer = ^tmacrobuffer;
  333. tmacrobuffer = array[0..maxmacrolen-1] of char;
  334. tmacro = class(tstoredsym)
  335. {Normally true, but false when a previously defined macro is undef-ed}
  336. defined : boolean;
  337. {True if this is a mac style compiler variable, in which case no macro
  338. substitutions shall be done.}
  339. is_compiler_var : boolean;
  340. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  341. {e. g. an IFDEF which returns false, will not be registered as used,}
  342. {since there is no place to register its use. }
  343. is_used : boolean;
  344. buftext : pchar;
  345. buflen : longint;
  346. constructor create(const n : string);
  347. constructor ppuload(ppufile:tcompilerppufile);
  348. procedure ppuwrite(ppufile:tcompilerppufile);override;
  349. destructor destroy;override;
  350. function GetCopy:tmacro;
  351. end;
  352. var
  353. generrorsym : tsym;
  354. { generate internal static field name based on regular field name }
  355. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  356. function get_high_value_sym(vs: tparavarsym):tsym; { marking it as inline causes IE 200311075 during loading from ppu file }
  357. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  358. implementation
  359. uses
  360. { global }
  361. verbose,
  362. { target }
  363. systems,
  364. { symtable }
  365. defutil,symtable,
  366. {$ifdef jvm}
  367. jvmdef,
  368. {$endif}
  369. fmodule,
  370. { tree }
  371. node,
  372. { aasm }
  373. aasmtai,aasmdata,
  374. { codegen }
  375. paramgr,
  376. procinfo
  377. ;
  378. {****************************************************************************
  379. Helpers
  380. ****************************************************************************}
  381. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  382. begin
  383. result:='$_static_'+fieldname;
  384. end;
  385. function get_high_value_sym(vs: tparavarsym):tsym;
  386. begin
  387. result := tsym(vs.owner.Find('high'+vs.name));
  388. end;
  389. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  390. begin
  391. if not assigned(srsym) then
  392. internalerror(200602051);
  393. if sp_hint_deprecated in symoptions then
  394. if (sp_has_deprecated_msg in symoptions) and (deprecatedmsg <> nil) then
  395. Message2(sym_w_deprecated_symbol_with_msg,srsym.realname,deprecatedmsg^)
  396. else
  397. Message1(sym_w_deprecated_symbol,srsym.realname);
  398. if sp_hint_experimental in symoptions then
  399. Message1(sym_w_experimental_symbol,srsym.realname);
  400. if sp_hint_platform in symoptions then
  401. Message1(sym_w_non_portable_symbol,srsym.realname);
  402. if sp_hint_library in symoptions then
  403. Message1(sym_w_library_symbol,srsym.realname);
  404. if sp_hint_unimplemented in symoptions then
  405. Message1(sym_w_non_implemented_symbol,srsym.realname);
  406. end;
  407. {****************************************************************************
  408. TSYM (base for all symtypes)
  409. ****************************************************************************}
  410. constructor tstoredsym.create(st:tsymtyp;const n : string);
  411. begin
  412. inherited create(st,n);
  413. { Register in current_module }
  414. if assigned(current_module) then
  415. begin
  416. current_module.symlist.Add(self);
  417. SymId:=current_module.symlist.Count-1;
  418. end;
  419. end;
  420. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  421. begin
  422. SymId:=ppufile.getlongint;
  423. inherited Create(st,ppufile.getstring);
  424. { Register symbol }
  425. current_module.symlist[SymId]:=self;
  426. ppufile.getposinfo(fileinfo);
  427. visibility:=tvisibility(ppufile.getbyte);
  428. ppufile.getsmallset(symoptions);
  429. if sp_has_deprecated_msg in symoptions then
  430. deprecatedmsg:=stringdup(ppufile.getstring)
  431. else
  432. deprecatedmsg:=nil;
  433. end;
  434. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  435. var
  436. oldintfcrc : boolean;
  437. begin
  438. ppufile.putlongint(SymId);
  439. ppufile.putstring(realname);
  440. ppufile.putposinfo(fileinfo);
  441. ppufile.putbyte(byte(visibility));
  442. { symoptions can differ between interface and implementation, except
  443. for overload (this is checked in pdecsub.proc_add_definition() )
  444. These differences can lead to compiler crashes, so ignore them.
  445. This does mean that changing e.g. the "deprecated" state of a symbol
  446. by itself will not trigger a recompilation of dependent units.
  447. }
  448. oldintfcrc:=ppufile.do_interface_crc;
  449. ppufile.do_interface_crc:=false;
  450. ppufile.putsmallset(symoptions);
  451. if sp_has_deprecated_msg in symoptions then
  452. ppufile.putstring(deprecatedmsg^);
  453. ppufile.do_interface_crc:=oldintfcrc;
  454. end;
  455. destructor tstoredsym.destroy;
  456. begin
  457. inherited destroy;
  458. end;
  459. {****************************************************************************
  460. TLABELSYM
  461. ****************************************************************************}
  462. constructor tlabelsym.create(const n : string);
  463. begin
  464. inherited create(labelsym,n);
  465. used:=false;
  466. defined:=false;
  467. nonlocal:=false;
  468. code:=nil;
  469. end;
  470. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  471. begin
  472. inherited ppuload(labelsym,ppufile);
  473. code:=nil;
  474. used:=false;
  475. nonlocal:=false;
  476. defined:=true;
  477. end;
  478. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  479. begin
  480. if owner.symtabletype=globalsymtable then
  481. Message(sym_e_ill_label_decl)
  482. else
  483. begin
  484. inherited ppuwrite(ppufile);
  485. ppufile.writeentry(iblabelsym);
  486. end;
  487. end;
  488. function tlabelsym.mangledname:TSymStr;
  489. begin
  490. if not(defined) then
  491. begin
  492. defined:=true;
  493. if nonlocal then
  494. current_asmdata.getglobaljumplabel(asmblocklabel)
  495. else
  496. current_asmdata.getjumplabel(asmblocklabel);
  497. end;
  498. result:=asmblocklabel.name;
  499. end;
  500. {****************************************************************************
  501. TUNITSYM
  502. ****************************************************************************}
  503. constructor tunitsym.create(const n : string;amodule : tobject);
  504. begin
  505. inherited create(unitsym,n);
  506. module:=amodule;
  507. end;
  508. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  509. begin
  510. inherited ppuload(unitsym,ppufile);
  511. module:=nil;
  512. end;
  513. destructor tunitsym.destroy;
  514. begin
  515. inherited destroy;
  516. end;
  517. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  518. begin
  519. inherited ppuwrite(ppufile);
  520. ppufile.writeentry(ibunitsym);
  521. end;
  522. {****************************************************************************
  523. TNAMESPACESYM
  524. ****************************************************************************}
  525. constructor tnamespacesym.create(const n : string);
  526. begin
  527. inherited create(namespacesym,n);
  528. unitsym:=nil;
  529. end;
  530. constructor tnamespacesym.ppuload(ppufile:tcompilerppufile);
  531. begin
  532. inherited ppuload(namespacesym,ppufile);
  533. ppufile.getderef(unitsymderef);
  534. end;
  535. procedure tnamespacesym.ppuwrite(ppufile:tcompilerppufile);
  536. begin
  537. inherited ppuwrite(ppufile);
  538. ppufile.putderef(unitsymderef);
  539. ppufile.writeentry(ibnamespacesym);
  540. end;
  541. procedure tnamespacesym.buildderef;
  542. begin
  543. inherited buildderef;
  544. unitsymderef.build(unitsym);
  545. end;
  546. procedure tnamespacesym.deref;
  547. begin
  548. inherited deref;
  549. unitsym:=tsym(unitsymderef.resolve);
  550. end;
  551. {****************************************************************************
  552. TPROCSYM
  553. ****************************************************************************}
  554. constructor tprocsym.create(const n : string);
  555. begin
  556. inherited create(procsym,n);
  557. FProcdefList:=TFPObjectList.Create(false);
  558. FProcdefderefList:=nil;
  559. { the tprocdef have their own symoptions, make the procsym
  560. always visible }
  561. visibility:=vis_public;
  562. end;
  563. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  564. var
  565. pdderef : tderef;
  566. i,
  567. pdcnt : longint;
  568. begin
  569. inherited ppuload(procsym,ppufile);
  570. FProcdefList:=TFPObjectList.Create(false);
  571. FProcdefDerefList:=TFPList.Create;
  572. pdcnt:=ppufile.getword;
  573. for i:=1 to pdcnt do
  574. begin
  575. ppufile.getderef(pdderef);
  576. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  577. end;
  578. end;
  579. destructor tprocsym.destroy;
  580. begin
  581. FProcdefList.Free;
  582. if assigned(FProcdefDerefList) then
  583. FProcdefDerefList.Free;
  584. inherited destroy;
  585. end;
  586. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  587. var
  588. i : longint;
  589. d : tderef;
  590. begin
  591. inherited ppuwrite(ppufile);
  592. ppufile.putword(FProcdefDerefList.Count);
  593. for i:=0 to FProcdefDerefList.Count-1 do
  594. begin
  595. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  596. ppufile.putderef(d);
  597. end;
  598. ppufile.writeentry(ibprocsym);
  599. end;
  600. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  601. var
  602. i : longint;
  603. pd : tprocdef;
  604. begin
  605. for i:=0 to ProcdefList.Count-1 do
  606. begin
  607. pd:=tprocdef(ProcdefList[i]);
  608. if pd<>skipdef then
  609. MessagePos1(pd.fileinfo,sym_h_param_list,pd.fullprocname(false));
  610. end;
  611. end;
  612. procedure tprocsym.check_forward;
  613. var
  614. i : longint;
  615. pd : tprocdef;
  616. begin
  617. for i:=0 to ProcdefList.Count-1 do
  618. begin
  619. pd:=tprocdef(ProcdefList[i]);
  620. if (pd.owner=owner) and (pd.forwarddef) then
  621. begin
  622. { For mode macpas. Make implicit externals (procedures declared in the interface
  623. section which do not have a counterpart in the implementation)
  624. to be an imported procedure }
  625. if (m_mac in current_settings.modeswitches) and
  626. (pd.interfacedef) then
  627. begin
  628. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  629. if (not current_module.interface_only) then
  630. MessagePos1(pd.fileinfo,sym_w_forward_not_resolved,pd.fullprocname(false));
  631. end
  632. else
  633. begin
  634. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  635. end;
  636. { Turn further error messages off }
  637. pd.forwarddef:=false;
  638. end;
  639. end;
  640. end;
  641. procedure tprocsym.buildderef;
  642. var
  643. i : longint;
  644. pd : tprocdef;
  645. d : tderef;
  646. begin
  647. if not assigned(FProcdefDerefList) then
  648. FProcdefDerefList:=TFPList.Create
  649. else
  650. FProcdefDerefList.Clear;
  651. for i:=0 to ProcdefList.Count-1 do
  652. begin
  653. pd:=tprocdef(ProcdefList[i]);
  654. { only write the proc definitions that belong
  655. to this procsym and are in the global symtable }
  656. if pd.owner=owner then
  657. begin
  658. d.build(pd);
  659. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  660. end;
  661. end;
  662. end;
  663. procedure tprocsym.deref;
  664. var
  665. i : longint;
  666. pd : tprocdef;
  667. d : tderef;
  668. begin
  669. { Clear all procdefs }
  670. ProcdefList.Clear;
  671. if not assigned(FProcdefDerefList) then
  672. internalerror(200611031);
  673. for i:=0 to FProcdefDerefList.Count-1 do
  674. begin
  675. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  676. pd:=tprocdef(d.resolve);
  677. ProcdefList.Add(pd);
  678. end;
  679. end;
  680. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  681. var
  682. i : longint;
  683. pd : tprocdef;
  684. begin
  685. result:=nil;
  686. for i:=0 to ProcdefList.Count-1 do
  687. begin
  688. pd:=tprocdef(ProcdefList[i]);
  689. if pd.proctypeoption=pt then
  690. begin
  691. result:=pd;
  692. exit;
  693. end;
  694. end;
  695. end;
  696. function tprocsym.find_bytype_parameterless(pt: Tproctypeoption): Tprocdef;
  697. var
  698. i,j : longint;
  699. pd : tprocdef;
  700. found : boolean;
  701. begin
  702. result:=nil;
  703. for i:=0 to ProcdefList.Count-1 do
  704. begin
  705. pd:=tprocdef(ProcdefList[i]);
  706. if (pd.proctypeoption=pt) then
  707. begin
  708. found:=true;
  709. for j:=0 to pd.paras.count-1 do
  710. begin
  711. if not(vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  712. begin
  713. found:=false;
  714. break;
  715. end;
  716. end;
  717. if found then
  718. begin
  719. result:=pd;
  720. exit;
  721. end;
  722. end;
  723. end;
  724. end;
  725. function check_procdef_paras(pd:tprocdef;para:TFPObjectList;retdef:tdef;
  726. cpoptions:tcompare_paras_options): tprocdef;
  727. var
  728. eq: tequaltype;
  729. begin
  730. result:=nil;
  731. if assigned(retdef) then
  732. eq:=compare_defs(retdef,pd.returndef,nothingn)
  733. else
  734. eq:=te_equal;
  735. if (eq>=te_equal) or
  736. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  737. begin
  738. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  739. if (eq>=te_equal) or
  740. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  741. begin
  742. result:=pd;
  743. exit;
  744. end;
  745. end;
  746. end;
  747. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  748. cpoptions:tcompare_paras_options):Tprocdef;
  749. var
  750. i : longint;
  751. pd : tprocdef;
  752. begin
  753. result:=nil;
  754. for i:=0 to ProcdefList.Count-1 do
  755. begin
  756. pd:=tprocdef(ProcdefList[i]);
  757. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  758. if assigned(result) then
  759. exit;
  760. end;
  761. end;
  762. function Tprocsym.find_procdef_bytype_and_para(pt:Tproctypeoption;
  763. para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  764. var
  765. i : longint;
  766. pd : tprocdef;
  767. begin
  768. result:=nil;
  769. for i:=0 to ProcdefList.Count-1 do
  770. begin
  771. pd:=tprocdef(ProcdefList[i]);
  772. if pd.proctypeoption=pt then
  773. begin
  774. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  775. if assigned(result) then
  776. exit;
  777. end;
  778. end;
  779. end;
  780. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  781. var
  782. i : longint;
  783. pd : tprocdef;
  784. begin
  785. result:=nil;
  786. for i:=0 to ProcdefList.Count-1 do
  787. begin
  788. pd:=tprocdef(ProcdefList[i]);
  789. if ops * pd.procoptions = ops then
  790. begin
  791. result:=pd;
  792. exit;
  793. end;
  794. end;
  795. end;
  796. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  797. var
  798. i : longint;
  799. bestpd,
  800. pd : tprocdef;
  801. eq,besteq : tequaltype;
  802. sym: tsym;
  803. ps: tprocsym;
  804. begin
  805. { This function will return the pprocdef of pprocsym that
  806. is the best match for procvardef. When there are multiple
  807. matches it returns nil.}
  808. result:=nil;
  809. bestpd:=nil;
  810. besteq:=te_incompatible;
  811. ps:=self;
  812. repeat
  813. for i:=0 to ps.ProcdefList.Count-1 do
  814. begin
  815. pd:=tprocdef(ps.ProcdefList[i]);
  816. eq:=proc_to_procvar_equal(pd,d,false);
  817. if eq>=te_convert_l1 then
  818. begin
  819. { multiple procvars with the same equal level }
  820. if assigned(bestpd) and
  821. (besteq=eq) then
  822. exit;
  823. if eq>besteq then
  824. begin
  825. besteq:=eq;
  826. bestpd:=pd;
  827. end;
  828. end;
  829. end;
  830. { maybe TODO: also search class helpers? -- this code is similar to
  831. what happens in htypechk in
  832. tcallcandidates.collect_overloads_in_struct: keep searching in
  833. parent types in case the currently found procdef is marked as
  834. "overload" and we haven't found a proper match yet }
  835. if assigned(ps.owner.defowner) and
  836. (ps.owner.defowner.typ=objectdef) and
  837. assigned(tobjectdef(ps.owner.defowner).childof) and
  838. (not assigned(bestpd) or
  839. (po_overload in bestpd.procoptions)) then
  840. begin
  841. sym:=tsym(tobjectdef(ps.owner.defowner).childof.symtable.find(ps.name));
  842. if assigned(sym) and
  843. (sym.typ=procsym) then
  844. ps:=tprocsym(sym)
  845. else
  846. ps:=nil;
  847. end
  848. else
  849. ps:=nil;
  850. until (besteq>=te_equal) or
  851. not assigned(ps);
  852. result:=bestpd;
  853. end;
  854. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  855. var
  856. paraidx, realparamcount,
  857. i, j : longint;
  858. bestpd,
  859. hpd,
  860. pd : tprocdef;
  861. convtyp : tconverttype;
  862. eq : tequaltype;
  863. begin
  864. { This function will return the pprocdef of pprocsym that
  865. is the best match for fromdef and todef. }
  866. result:=nil;
  867. bestpd:=nil;
  868. besteq:=te_incompatible;
  869. for i:=0 to ProcdefList.Count-1 do
  870. begin
  871. pd:=tprocdef(ProcdefList[i]);
  872. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  873. continue;
  874. if (equal_defs(todef,pd.returndef) or
  875. { shortstrings of different lengths are ok as result }
  876. (is_shortstring(todef) and is_shortstring(pd.returndef))) and
  877. { the result type must be always really equal and not an alias,
  878. if you mess with this code, check tw4093 }
  879. ((todef=pd.returndef) or
  880. (
  881. not(df_unique in todef.defoptions) and
  882. not(df_unique in pd.returndef.defoptions)
  883. )
  884. ) then
  885. begin
  886. paraidx:=0;
  887. { ignore vs_hidden parameters }
  888. while (paraidx<pd.paras.count) and
  889. assigned(pd.paras[paraidx]) and
  890. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  891. inc(paraidx);
  892. realparamcount:=0;
  893. for j := 0 to pd.paras.Count-1 do
  894. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  895. inc(realparamcount);
  896. if (paraidx<pd.paras.count) and
  897. assigned(pd.paras[paraidx]) and
  898. (realparamcount = 1) then
  899. begin
  900. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  901. { alias? if yes, only l1 choice,
  902. if you mess with this code, check tw4093 }
  903. if (eq=te_exact) and
  904. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  905. ((df_unique in fromdef.defoptions) or
  906. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  907. eq:=te_convert_l1;
  908. if eq=te_exact then
  909. begin
  910. besteq:=eq;
  911. result:=pd;
  912. exit;
  913. end;
  914. if eq>besteq then
  915. begin
  916. bestpd:=pd;
  917. besteq:=eq;
  918. end;
  919. end;
  920. end;
  921. end;
  922. result:=bestpd;
  923. end;
  924. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  925. var
  926. paraidx, realparamcount,
  927. i, j : longint;
  928. bestpd,
  929. hpd,
  930. pd : tprocdef;
  931. current : tpropertysym;
  932. convtyp : tconverttype;
  933. eq : tequaltype;
  934. begin
  935. { This function will return the pprocdef of pprocsym that
  936. is the best match for fromdef and todef. }
  937. result:=nil;
  938. bestpd:=nil;
  939. besteq:=te_incompatible;
  940. for i:=0 to ProcdefList.Count-1 do
  941. begin
  942. pd:=tprocdef(ProcdefList[i]);
  943. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  944. continue;
  945. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  946. continue;
  947. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  948. if (current = nil) then
  949. continue;
  950. // compare current result def with the todef
  951. if (equal_defs(todef, current.propdef) or
  952. { shortstrings of different lengths are ok as result }
  953. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  954. { the result type must be always really equal and not an alias,
  955. if you mess with this code, check tw4093 }
  956. ((todef=current.propdef) or
  957. (
  958. not(df_unique in todef.defoptions) and
  959. not(df_unique in current.propdef.defoptions)
  960. )
  961. ) then
  962. begin
  963. paraidx:=0;
  964. { ignore vs_hidden parameters }
  965. while (paraidx<pd.paras.count) and
  966. assigned(pd.paras[paraidx]) and
  967. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  968. inc(paraidx);
  969. realparamcount:=0;
  970. for j := 0 to pd.paras.Count-1 do
  971. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  972. inc(realparamcount);
  973. if (paraidx<pd.paras.count) and
  974. assigned(pd.paras[paraidx]) and
  975. (realparamcount = 1) then
  976. begin
  977. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  978. { alias? if yes, only l1 choice,
  979. if you mess with this code, check tw4093 }
  980. if (eq=te_exact) and
  981. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  982. ((df_unique in fromdef.defoptions) or
  983. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  984. eq:=te_convert_l1;
  985. if eq=te_exact then
  986. begin
  987. besteq:=eq;
  988. result:=pd;
  989. exit;
  990. end;
  991. if eq>besteq then
  992. begin
  993. bestpd:=pd;
  994. besteq:=eq;
  995. end;
  996. end;
  997. end;
  998. end;
  999. result:=bestpd;
  1000. end;
  1001. {****************************************************************************
  1002. TERRORSYM
  1003. ****************************************************************************}
  1004. constructor terrorsym.create;
  1005. begin
  1006. inherited create(errorsym,'');
  1007. end;
  1008. {****************************************************************************
  1009. TPROPERTYSYM
  1010. ****************************************************************************}
  1011. constructor tpropertysym.create(const n : string);
  1012. var
  1013. pap : tpropaccesslisttypes;
  1014. begin
  1015. inherited create(propertysym,n);
  1016. propoptions:=[];
  1017. index:=0;
  1018. default:=0;
  1019. propdef:=nil;
  1020. indexdef:=nil;
  1021. parast:=nil;
  1022. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1023. propaccesslist[pap]:=tpropaccesslist.create;
  1024. end;
  1025. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1026. var
  1027. pap : tpropaccesslisttypes;
  1028. begin
  1029. inherited ppuload(propertysym,ppufile);
  1030. ppufile.getsmallset(propoptions);
  1031. if ppo_overrides in propoptions then
  1032. ppufile.getderef(overriddenpropsymderef);
  1033. ppufile.getderef(propdefderef);
  1034. index:=ppufile.getlongint;
  1035. default:=ppufile.getlongint;
  1036. ppufile.getderef(indexdefderef);
  1037. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1038. propaccesslist[pap]:=ppufile.getpropaccesslist;
  1039. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1040. begin
  1041. parast:=tparasymtable.create(nil,0);
  1042. tparasymtable(parast).ppuload(ppufile);
  1043. end
  1044. else
  1045. parast:=nil;
  1046. end;
  1047. destructor tpropertysym.destroy;
  1048. var
  1049. pap : tpropaccesslisttypes;
  1050. begin
  1051. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1052. propaccesslist[pap].free;
  1053. parast.free;
  1054. inherited destroy;
  1055. end;
  1056. procedure tpropertysym.buildderef;
  1057. var
  1058. pap : tpropaccesslisttypes;
  1059. begin
  1060. propdefderef.build(propdef);
  1061. indexdefderef.build(indexdef);
  1062. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1063. propaccesslist[pap].buildderef;
  1064. if ppo_overrides in propoptions then
  1065. overriddenpropsymderef.build(overriddenpropsym)
  1066. else
  1067. if ppo_hasparameters in propoptions then
  1068. tparasymtable(parast).buildderef;
  1069. end;
  1070. procedure tpropertysym.deref;
  1071. var
  1072. pap : tpropaccesslisttypes;
  1073. begin
  1074. indexdef:=tdef(indexdefderef.resolve);
  1075. propdef:=tdef(propdefderef.resolve);
  1076. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1077. propaccesslist[pap].resolve;
  1078. if ppo_overrides in propoptions then
  1079. begin
  1080. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  1081. if ppo_hasparameters in propoptions then
  1082. parast:=overriddenpropsym.parast.getcopy;
  1083. end
  1084. else
  1085. if ppo_hasparameters in propoptions then
  1086. tparasymtable(parast).deref
  1087. end;
  1088. function tpropertysym.getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  1089. var
  1090. hpropsym : tpropertysym;
  1091. begin
  1092. result:=false;
  1093. { find property in the overridden list }
  1094. hpropsym:=self;
  1095. repeat
  1096. plist:=hpropsym.propaccesslist[pap];
  1097. if not plist.empty then
  1098. begin
  1099. result:=true;
  1100. exit;
  1101. end;
  1102. hpropsym:=hpropsym.overriddenpropsym;
  1103. until not assigned(hpropsym);
  1104. end;
  1105. procedure tpropertysym.add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  1106. var
  1107. i: integer;
  1108. orig, hparavs: tparavarsym;
  1109. begin
  1110. for i := 0 to parast.SymList.Count - 1 do
  1111. begin
  1112. orig:=tparavarsym(parast.SymList[i]);
  1113. if assigned(readprocdef) then
  1114. begin
  1115. hparavs:=tparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1116. readprocdef.parast.insert(hparavs);
  1117. end;
  1118. if assigned(writeprocdef) then
  1119. begin
  1120. hparavs:=tparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1121. writeprocdef.parast.insert(hparavs);
  1122. end;
  1123. end;
  1124. end;
  1125. procedure tpropertysym.add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  1126. var
  1127. hparavs: tparavarsym;
  1128. begin
  1129. inc(paranr);
  1130. if assigned(readprocdef) then
  1131. begin
  1132. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1133. readprocdef.parast.insert(hparavs);
  1134. end;
  1135. if assigned(writeprocdef) then
  1136. begin
  1137. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1138. writeprocdef.parast.insert(hparavs);
  1139. end;
  1140. end;
  1141. procedure tpropertysym.makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  1142. begin
  1143. { inherit all type related entries }
  1144. p.indexdef:=indexdef;
  1145. p.propdef:=propdef;
  1146. p.index:=index;
  1147. p.default:=default;
  1148. p.propoptions:=propoptions;
  1149. paranr:=0;
  1150. if ppo_hasparameters in propoptions then
  1151. begin
  1152. p.parast:=parast.getcopy;
  1153. p.add_accessor_parameters(readprocdef,writeprocdef);
  1154. paranr:=p.parast.SymList.Count;
  1155. end;
  1156. if ppo_indexed in p.propoptions then
  1157. p.add_index_parameter(paranr,readprocdef,writeprocdef);
  1158. end;
  1159. function tpropertysym.getsize : asizeint;
  1160. begin
  1161. getsize:=0;
  1162. end;
  1163. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1164. var
  1165. pap : tpropaccesslisttypes;
  1166. begin
  1167. inherited ppuwrite(ppufile);
  1168. ppufile.putsmallset(propoptions);
  1169. if ppo_overrides in propoptions then
  1170. ppufile.putderef(overriddenpropsymderef);
  1171. ppufile.putderef(propdefderef);
  1172. ppufile.putlongint(index);
  1173. ppufile.putlongint(default);
  1174. ppufile.putderef(indexdefderef);
  1175. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1176. ppufile.putpropaccesslist(propaccesslist[pap]);
  1177. ppufile.writeentry(ibpropertysym);
  1178. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1179. tparasymtable(parast).ppuwrite(ppufile);
  1180. end;
  1181. {****************************************************************************
  1182. TABSTRACTVARSYM
  1183. ****************************************************************************}
  1184. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1185. begin
  1186. inherited create(st,n);
  1187. vardef:=def;
  1188. varspez:=vsp;
  1189. varstate:=vs_declared;
  1190. varoptions:=vopts;
  1191. end;
  1192. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1193. begin
  1194. inherited ppuload(st,ppufile);
  1195. varstate:=vs_readwritten;
  1196. varspez:=tvarspez(ppufile.getbyte);
  1197. varregable:=tvarregable(ppufile.getbyte);
  1198. addr_taken:=boolean(ppufile.getbyte);
  1199. ppufile.getderef(vardefderef);
  1200. ppufile.getsmallset(varoptions);
  1201. end;
  1202. destructor tabstractvarsym.destroy;
  1203. begin
  1204. if assigned(notifications) then
  1205. notifications.destroy;
  1206. inherited destroy;
  1207. end;
  1208. procedure tabstractvarsym.buildderef;
  1209. begin
  1210. vardefderef.build(vardef);
  1211. end;
  1212. procedure tabstractvarsym.deref;
  1213. var
  1214. oldvarregable: tvarregable;
  1215. begin
  1216. { setting the vardef also updates varregable. We just loaded this }
  1217. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  1218. { tw7817b.pp: the address is taken of a local variable in an }
  1219. { inlined procedure -> must remain non-regable when inlining) }
  1220. oldvarregable:=varregable;
  1221. vardef:=tdef(vardefderef.resolve);
  1222. varregable:=oldvarregable;
  1223. end;
  1224. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1225. var
  1226. oldintfcrc : boolean;
  1227. begin
  1228. inherited ppuwrite(ppufile);
  1229. ppufile.putbyte(byte(varspez));
  1230. oldintfcrc:=ppufile.do_crc;
  1231. ppufile.do_crc:=false;
  1232. ppufile.putbyte(byte(varregable));
  1233. ppufile.putbyte(byte(addr_taken));
  1234. ppufile.do_crc:=oldintfcrc;
  1235. ppufile.putderef(vardefderef);
  1236. ppufile.putsmallset(varoptions);
  1237. end;
  1238. function tabstractvarsym.getsize : asizeint;
  1239. begin
  1240. if assigned(vardef) and
  1241. ((vardef.typ<>arraydef) or
  1242. is_dynamic_array(vardef) or
  1243. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1244. result:=vardef.size
  1245. else
  1246. result:=0;
  1247. end;
  1248. function tabstractvarsym.getpackedbitsize : longint;
  1249. begin
  1250. { bitpacking is only done for ordinals }
  1251. if not is_ordinal(vardef) then
  1252. internalerror(2006082010);
  1253. result:=vardef.packedbitsize;
  1254. end;
  1255. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1256. begin
  1257. { Register variables are not allowed in the following cases:
  1258. - regvars are disabled
  1259. - exceptions are used (after an exception is raised the contents of the
  1260. registers is not valid anymore)
  1261. - it has a local copy
  1262. - the value needs to be in memory (i.e. reference counted) }
  1263. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1264. not(pi_has_assembler_block in current_procinfo.flags) and
  1265. not(pi_uses_exceptions in current_procinfo.flags) and
  1266. not(pi_has_interproclabel in current_procinfo.flags) and
  1267. not(vo_has_local_copy in varoptions) and
  1268. ((refpara and
  1269. (varregable <> vr_none)) or
  1270. (not refpara and
  1271. not(varregable in [vr_none,vr_addr])))
  1272. {$if not defined(powerpc) and not defined(powerpc64)}
  1273. and ((vardef.typ <> recorddef) or
  1274. (varregable = vr_addr) or
  1275. not(varstate in [vs_written,vs_readwritten]));
  1276. {$endif}
  1277. end;
  1278. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1279. var n:Tnotification;
  1280. begin
  1281. if assigned(notifications) then
  1282. begin
  1283. n:=Tnotification(notifications.first);
  1284. while assigned(n) do
  1285. begin
  1286. if what in n.flags then
  1287. n.callback(what,self);
  1288. n:=Tnotification(n.next);
  1289. end;
  1290. end;
  1291. end;
  1292. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1293. Tnotification_callback):cardinal;
  1294. var n:Tnotification;
  1295. begin
  1296. if not assigned(notifications) then
  1297. notifications:=Tlinkedlist.create;
  1298. n:=Tnotification.create(flags,callback);
  1299. register_notification:=n.id;
  1300. notifications.concat(n);
  1301. end;
  1302. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1303. var n:Tnotification;
  1304. begin
  1305. if not assigned(notifications) then
  1306. internalerror(200212311)
  1307. else
  1308. begin
  1309. n:=Tnotification(notifications.first);
  1310. while assigned(n) do
  1311. begin
  1312. if n.id=id then
  1313. begin
  1314. notifications.remove(n);
  1315. n.destroy;
  1316. exit;
  1317. end;
  1318. n:=Tnotification(n.next);
  1319. end;
  1320. internalerror(200212311)
  1321. end;
  1322. end;
  1323. procedure tabstractvarsym.setvardef(def:tdef);
  1324. begin
  1325. _vardef := def;
  1326. { can we load the value into a register ? }
  1327. if not assigned(owner) or
  1328. (owner.symtabletype in [localsymtable,parasymtable]) or
  1329. (
  1330. (owner.symtabletype=staticsymtable) and
  1331. not(cs_create_pic in current_settings.moduleswitches)
  1332. ) then
  1333. begin
  1334. if tstoreddef(vardef).is_intregable then
  1335. varregable:=vr_intreg
  1336. else
  1337. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1338. if {(
  1339. not assigned(owner) or
  1340. (owner.symtabletype<>staticsymtable)
  1341. ) and }
  1342. tstoreddef(vardef).is_fpuregable then
  1343. begin
  1344. if use_vectorfpu(vardef) then
  1345. varregable:=vr_mmreg
  1346. else
  1347. varregable:=vr_fpureg;
  1348. end;
  1349. end;
  1350. end;
  1351. {****************************************************************************
  1352. TFIELDVARSYM
  1353. ****************************************************************************}
  1354. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1355. begin
  1356. inherited create(fieldvarsym,n,vsp,def,vopts);
  1357. fieldoffset:=-1;
  1358. end;
  1359. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1360. begin
  1361. inherited ppuload(fieldvarsym,ppufile);
  1362. fieldoffset:=ppufile.getaint;
  1363. if (vo_has_mangledname in varoptions) then
  1364. externalname:=stringdup(ppufile.getstring)
  1365. else
  1366. externalname:=nil;
  1367. end;
  1368. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1369. begin
  1370. inherited ppuwrite(ppufile);
  1371. ppufile.putaint(fieldoffset);
  1372. if (vo_has_mangledname in varoptions) then
  1373. ppufile.putstring(externalname^);
  1374. ppufile.writeentry(ibfieldvarsym);
  1375. end;
  1376. procedure tfieldvarsym.set_externalname(const s: string);
  1377. begin
  1378. { make sure it is recalculated }
  1379. {$ifdef symansistr}
  1380. cachedmangledname:='';
  1381. {$else symansistr}
  1382. stringdispose(cachedmangledname);
  1383. {$endif symansistr}
  1384. {$ifdef jvm}
  1385. if is_java_class_or_interface(tdef(owner.defowner)) then
  1386. begin
  1387. externalname:=stringdup(s);
  1388. include(varoptions,vo_has_mangledname);
  1389. end
  1390. else
  1391. {$endif jvm}
  1392. internalerror(2011031201);
  1393. end;
  1394. function tfieldvarsym.mangledname:TSymStr;
  1395. var
  1396. srsym : tsym;
  1397. srsymtable : tsymtable;
  1398. begin
  1399. {$ifdef jvm}
  1400. if is_java_class_or_interface(tdef(owner.defowner)) or
  1401. (tdef(owner.defowner).typ=recorddef) then
  1402. begin
  1403. if cachedmangledname<>'' then
  1404. result:=cachedmangledname
  1405. else
  1406. begin
  1407. result:=jvmmangledbasename(self,false);
  1408. jvmaddtypeownerprefix(owner,result);
  1409. cachedmangledname:=result;
  1410. end;
  1411. end
  1412. else
  1413. {$endif jvm}
  1414. if sp_static in symoptions then
  1415. begin
  1416. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1417. result:=srsym.mangledname
  1418. { when generating the debug info for the module in which the }
  1419. { symbol is defined, the localsymtable of that module is }
  1420. { already popped from the symtablestack }
  1421. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1422. result:=srsym.mangledname
  1423. else
  1424. internalerror(2007012501);
  1425. end
  1426. else if is_objcclass(tdef(owner.defowner)) then
  1427. begin
  1428. {$ifdef symansistr}
  1429. if cachedmangledname<>'' then
  1430. result:=cachedmangledname
  1431. {$else symansistr}
  1432. if assigned(cachedmangledname) then
  1433. result:=cachedmangledname^
  1434. {$endif symansistr}
  1435. else
  1436. begin
  1437. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1438. {$ifdef symansistr}
  1439. cachedmangledname:=result;
  1440. {$else symansistr}
  1441. cachedmangledname:=stringdup(result);
  1442. {$endif symansistr}
  1443. end;
  1444. end
  1445. else
  1446. result:=inherited mangledname;
  1447. end;
  1448. destructor tfieldvarsym.destroy;
  1449. begin
  1450. {$ifndef symansistr}
  1451. stringdispose(cachedmangledname);
  1452. {$endif symansistr}
  1453. stringdispose(externalname);
  1454. inherited destroy;
  1455. end;
  1456. {****************************************************************************
  1457. TABSTRACTNORMALVARSYM
  1458. ****************************************************************************}
  1459. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1460. begin
  1461. inherited create(st,n,vsp,def,vopts);
  1462. fillchar(localloc,sizeof(localloc),0);
  1463. fillchar(currentregloc,sizeof(localloc),0);
  1464. fillchar(initialloc,sizeof(initialloc),0);
  1465. defaultconstsym:=nil;
  1466. end;
  1467. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1468. begin
  1469. inherited ppuload(st,ppufile);
  1470. fillchar(localloc,sizeof(localloc),0);
  1471. fillchar(currentregloc,sizeof(localloc),0);
  1472. fillchar(initialloc,sizeof(initialloc),0);
  1473. ppufile.getderef(defaultconstsymderef);
  1474. end;
  1475. function tabstractnormalvarsym.globalasmsym: boolean;
  1476. begin
  1477. result:=
  1478. (owner.symtabletype=globalsymtable) or
  1479. (create_smartlink and
  1480. not(tf_smartlink_sections in target_info.flags)) or
  1481. DLLSource or
  1482. (assigned(current_procinfo) and
  1483. (po_inline in current_procinfo.procdef.procoptions)) or
  1484. (vo_is_public in varoptions);
  1485. end;
  1486. procedure tabstractnormalvarsym.buildderef;
  1487. begin
  1488. inherited buildderef;
  1489. defaultconstsymderef.build(defaultconstsym);
  1490. end;
  1491. procedure tabstractnormalvarsym.deref;
  1492. begin
  1493. inherited deref;
  1494. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1495. end;
  1496. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1497. begin
  1498. inherited ppuwrite(ppufile);
  1499. ppufile.putderef(defaultconstsymderef);
  1500. end;
  1501. {****************************************************************************
  1502. Tstaticvarsym
  1503. ****************************************************************************}
  1504. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1505. begin
  1506. inherited create(staticvarsym,n,vsp,def,vopts);
  1507. {$ifdef symansistr}
  1508. _mangledname:='';
  1509. {$else symansistr}
  1510. _mangledname:=nil;
  1511. {$endif symansistr}
  1512. end;
  1513. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1514. begin
  1515. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1516. end;
  1517. constructor tstaticvarsym.create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  1518. begin
  1519. tstaticvarsym(self).create(n,vsp,def,[]);
  1520. set_mangledname(mangled);
  1521. end;
  1522. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1523. begin
  1524. inherited ppuload(staticvarsym,ppufile);
  1525. {$ifdef symansistr}
  1526. if vo_has_mangledname in varoptions then
  1527. _mangledname:=ppufile.getansistring
  1528. else
  1529. _mangledname:='';
  1530. {$else symansistr}
  1531. if vo_has_mangledname in varoptions then
  1532. _mangledname:=stringdup(ppufile.getstring)
  1533. else
  1534. _mangledname:=nil;
  1535. if vo_has_section in varoptions then
  1536. section:=ppufile.getansistring;
  1537. {$endif symansistr}
  1538. end;
  1539. destructor tstaticvarsym.destroy;
  1540. begin
  1541. {$ifndef symansistr}
  1542. if assigned(_mangledname) then
  1543. begin
  1544. {$ifdef MEMDEBUG}
  1545. memmanglednames.start;
  1546. {$endif MEMDEBUG}
  1547. stringdispose(_mangledname);
  1548. {$ifdef MEMDEBUG}
  1549. memmanglednames.stop;
  1550. {$endif MEMDEBUG}
  1551. end;
  1552. stringdispose(_mangledbasename);
  1553. {$endif}
  1554. inherited destroy;
  1555. end;
  1556. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1557. begin
  1558. inherited ppuwrite(ppufile);
  1559. { write mangledname rather than _mangledname in case the mangledname
  1560. has not been calculated yet (can happen in case only the
  1561. mangledbasename has been set) }
  1562. if vo_has_mangledname in varoptions then
  1563. {$ifdef symansistr}
  1564. ppufile.putansistring(mangledname);
  1565. {$else symansistr}
  1566. ppufile.putstring(mangledname);
  1567. {$endif symansistr}
  1568. if vo_has_section in varoptions then
  1569. ppufile.putansistring(section);
  1570. ppufile.writeentry(ibstaticvarsym);
  1571. end;
  1572. function tstaticvarsym.mangledname:TSymStr;
  1573. {$ifndef jvm}
  1574. var
  1575. usename,
  1576. prefix : TSymStr;
  1577. {$endif jvm}
  1578. begin
  1579. {$ifdef symansistr}
  1580. if _mangledname='' then
  1581. {$else symansistr}
  1582. if not assigned(_mangledname) then
  1583. {$endif symansistr}
  1584. begin
  1585. {$ifdef jvm}
  1586. if _mangledbasename='' then
  1587. _mangledname:=jvmmangledbasename(self,false)
  1588. else
  1589. _mangledname:=jvmmangledbasename(self,_mangledbasename,false);
  1590. jvmaddtypeownerprefix(owner,_mangledname);
  1591. {$else jvm}
  1592. if (vo_is_typed_const in varoptions) then
  1593. prefix:='TC'
  1594. else
  1595. prefix:='U';
  1596. {$ifdef symansistr}
  1597. if _mangledbasename='' then
  1598. usename:=name
  1599. else
  1600. usename:=_mangledbasename;
  1601. {$else symansistr}
  1602. if not assigned(_mangledbasename) then
  1603. usename:=name
  1604. else
  1605. usename:=_mangledbasename^;
  1606. {$endif symansistr}
  1607. {$ifdef compress}
  1608. {$error add ansistring support for symansistr}
  1609. _mangledname:=stringdup(minilzw_encode(make_mangledname(prefix,owner,usename)));
  1610. {$else compress}
  1611. {$ifdef symansistr}
  1612. _mangledname:=make_mangledname(prefix,owner,usename);
  1613. {$else symansistr}
  1614. _mangledname:=stringdup(make_mangledname(prefix,owner,usename));
  1615. {$endif symansistr}
  1616. {$endif compress}
  1617. {$endif jvm}
  1618. end;
  1619. {$ifdef symansistr}
  1620. result:=_mangledname;
  1621. {$else symansistr}
  1622. result:=_mangledname^;
  1623. {$endif symansistr}
  1624. end;
  1625. procedure tstaticvarsym.set_mangledbasename(const s: TSymStr);
  1626. begin
  1627. {$ifdef symansistr}
  1628. _mangledbasename:=s;
  1629. _mangledname:='';
  1630. {$else symansistr}
  1631. stringdispose(_mangledname);
  1632. stringdispose(_mangledbasename);
  1633. _mangledbasename:=stringdup(s);
  1634. {$endif symansistr}
  1635. include(varoptions,vo_has_mangledname);
  1636. end;
  1637. function tstaticvarsym.mangledbasename: TSymStr;
  1638. begin
  1639. {$ifdef symansistr}
  1640. result:=_mangledbasename;
  1641. {$else symansistr}
  1642. if assigned(_mangledbasename) then
  1643. result:=_mangledbasename^
  1644. else
  1645. result:='';
  1646. {$endif symansistr}
  1647. end;
  1648. procedure tstaticvarsym.set_mangledname(const s:TSymStr);
  1649. begin
  1650. {$ifndef symansistr}
  1651. stringdispose(_mangledname);
  1652. {$endif}
  1653. {$if defined(jvm)}
  1654. _mangledname:=jvmmangledbasename(self,s,false);
  1655. jvmaddtypeownerprefix(owner,_mangledname);
  1656. {$elseif defined(compress)}
  1657. _mangledname:=stringdup(minilzw_encode(s));
  1658. {$else}
  1659. {$ifdef symansistr}
  1660. _mangledname:=s;
  1661. {$else symansistr}
  1662. _mangledname:=stringdup(s);
  1663. {$endif symansistr}
  1664. {$endif}
  1665. include(varoptions,vo_has_mangledname);
  1666. end;
  1667. procedure tstaticvarsym.set_raw_mangledname(const s: TSymStr);
  1668. begin
  1669. {$ifndef symansistr}
  1670. stringdispose(_mangledname);
  1671. _mangledname:=stringdup(s);
  1672. {$else}
  1673. _mangledname:=s;
  1674. {$endif}
  1675. include(varoptions,vo_has_mangledname);
  1676. end;
  1677. {****************************************************************************
  1678. TLOCALVARSYM
  1679. ****************************************************************************}
  1680. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1681. begin
  1682. inherited create(localvarsym,n,vsp,def,vopts);
  1683. end;
  1684. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1685. begin
  1686. inherited ppuload(localvarsym,ppufile);
  1687. end;
  1688. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1689. begin
  1690. inherited ppuwrite(ppufile);
  1691. ppufile.writeentry(iblocalvarsym);
  1692. end;
  1693. {****************************************************************************
  1694. TPARAVARSYM
  1695. ****************************************************************************}
  1696. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1697. begin
  1698. inherited create(paravarsym,n,vsp,def,vopts);
  1699. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) and
  1700. not(vo_is_funcret in vopts) then
  1701. varstate := vs_initialised;
  1702. paranr:=nr;
  1703. paraloc[calleeside].init;
  1704. paraloc[callerside].init;
  1705. end;
  1706. destructor tparavarsym.destroy;
  1707. begin
  1708. paraloc[calleeside].done;
  1709. paraloc[callerside].done;
  1710. inherited destroy;
  1711. end;
  1712. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1713. var
  1714. b : byte;
  1715. begin
  1716. inherited ppuload(paravarsym,ppufile);
  1717. paranr:=ppufile.getword;
  1718. univpara:=boolean(ppufile.getbyte);
  1719. { The var state of parameter symbols is fixed after writing them so
  1720. we write them to the unit file.
  1721. This enables constant folding for inline procedures loaded from units
  1722. }
  1723. varstate:=tvarstate(ppufile.getbyte);
  1724. { read usage info }
  1725. refs:=ppufile.getbyte;
  1726. paraloc[calleeside].init;
  1727. paraloc[callerside].init;
  1728. if vo_has_explicit_paraloc in varoptions then
  1729. begin
  1730. paraloc[callerside].alignment:=ppufile.getbyte;
  1731. b:=ppufile.getbyte;
  1732. if b<>sizeof(paraloc[callerside].location^) then
  1733. internalerror(200411154);
  1734. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1735. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1736. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1737. end;
  1738. end;
  1739. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1740. var
  1741. oldintfcrc : boolean;
  1742. begin
  1743. inherited ppuwrite(ppufile);
  1744. ppufile.putword(paranr);
  1745. ppufile.putbyte(byte(univpara));
  1746. { The var state of parameter symbols is fixed after writing them so
  1747. we write them to the unit file.
  1748. This enables constant folding for inline procedures loaded from units
  1749. }
  1750. oldintfcrc:=ppufile.do_crc;
  1751. ppufile.do_crc:=false;
  1752. ppufile.putbyte(ord(varstate));
  1753. { write also info about the usage of parameters,
  1754. the absolute usage does not matter }
  1755. ppufile.putbyte(min(1,refs));
  1756. ppufile.do_crc:=oldintfcrc;
  1757. if vo_has_explicit_paraloc in varoptions then
  1758. begin
  1759. paraloc[callerside].check_simple_location;
  1760. ppufile.putbyte(sizeof(paraloc[callerside].alignment));
  1761. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1762. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1763. end;
  1764. ppufile.writeentry(ibparavarsym);
  1765. end;
  1766. function tparavarsym.needs_finalization:boolean;
  1767. begin
  1768. result:=(varspez=vs_value) and
  1769. (is_managed_type(vardef) or
  1770. (
  1771. (not (tabstractprocdef(owner.defowner).proccalloption in cdecl_pocalls)) and
  1772. (not paramanager.use_stackalloc) and
  1773. (is_open_array(vardef) or is_array_of_const(vardef))
  1774. )
  1775. );
  1776. end;
  1777. {****************************************************************************
  1778. TABSOLUTEVARSYM
  1779. ****************************************************************************}
  1780. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1781. begin
  1782. inherited create(absolutevarsym,n,vs_value,def,[]);
  1783. ref:=nil;
  1784. end;
  1785. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1786. begin
  1787. inherited create(absolutevarsym,n,vs_value,def,[]);
  1788. ref:=_ref;
  1789. end;
  1790. destructor tabsolutevarsym.destroy;
  1791. begin
  1792. if assigned(ref) then
  1793. ref.free;
  1794. inherited destroy;
  1795. end;
  1796. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1797. begin
  1798. inherited ppuload(absolutevarsym,ppufile);
  1799. ref:=nil;
  1800. asmname:=nil;
  1801. abstyp:=absolutetyp(ppufile.getbyte);
  1802. {$ifdef i386}
  1803. absseg:=false;
  1804. {$endif i386}
  1805. case abstyp of
  1806. tovar :
  1807. ref:=ppufile.getpropaccesslist;
  1808. toasm :
  1809. asmname:=stringdup(ppufile.getstring);
  1810. toaddr :
  1811. begin
  1812. addroffset:=ppufile.getaword;
  1813. {$ifdef i386}
  1814. absseg:=boolean(ppufile.getbyte);
  1815. {$endif i386}
  1816. end;
  1817. end;
  1818. end;
  1819. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1820. begin
  1821. inherited ppuwrite(ppufile);
  1822. ppufile.putbyte(byte(abstyp));
  1823. case abstyp of
  1824. tovar :
  1825. ppufile.putpropaccesslist(ref);
  1826. toasm :
  1827. ppufile.putstring(asmname^);
  1828. toaddr :
  1829. begin
  1830. ppufile.putaword(addroffset);
  1831. {$ifdef i386}
  1832. ppufile.putbyte(byte(absseg));
  1833. {$endif i386}
  1834. end;
  1835. end;
  1836. ppufile.writeentry(ibabsolutevarsym);
  1837. end;
  1838. procedure tabsolutevarsym.buildderef;
  1839. begin
  1840. inherited buildderef;
  1841. if (abstyp=tovar) then
  1842. ref.buildderef;
  1843. end;
  1844. procedure tabsolutevarsym.deref;
  1845. begin
  1846. inherited deref;
  1847. { own absolute deref }
  1848. if (abstyp=tovar) then
  1849. ref.resolve;
  1850. end;
  1851. function tabsolutevarsym.mangledname : TSymStr;
  1852. begin
  1853. case abstyp of
  1854. toasm :
  1855. mangledname:=asmname^;
  1856. toaddr :
  1857. mangledname:='$'+tostr(addroffset);
  1858. else
  1859. internalerror(200411062);
  1860. end;
  1861. end;
  1862. {****************************************************************************
  1863. TCONSTSYM
  1864. ****************************************************************************}
  1865. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1866. begin
  1867. inherited create(constsym,n);
  1868. fillchar(value, sizeof(value), #0);
  1869. consttyp:=t;
  1870. value.valueord:=v;
  1871. constdef:=def;
  1872. end;
  1873. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1874. begin
  1875. inherited create(constsym,n);
  1876. fillchar(value, sizeof(value), #0);
  1877. consttyp:=t;
  1878. value.valueordptr:=v;
  1879. constdef:=def;
  1880. end;
  1881. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1882. begin
  1883. inherited create(constsym,n);
  1884. fillchar(value, sizeof(value), #0);
  1885. consttyp:=t;
  1886. value.valueptr:=v;
  1887. constdef:=def;
  1888. end;
  1889. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1890. begin
  1891. inherited create(constsym,n);
  1892. fillchar(value, sizeof(value), #0);
  1893. consttyp:=t;
  1894. value.valueptr:=str;
  1895. constdef:=getarraydef(cansichartype,l);
  1896. value.len:=l;
  1897. end;
  1898. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1899. begin
  1900. inherited create(constsym,n);
  1901. fillchar(value, sizeof(value), #0);
  1902. consttyp:=t;
  1903. pcompilerwidestring(value.valueptr):=pw;
  1904. constdef:=getarraydef(cwidechartype,getlengthwidestring(pw));
  1905. value.len:=getlengthwidestring(pw);
  1906. end;
  1907. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1908. var
  1909. pd : pbestreal;
  1910. ps : pnormalset;
  1911. pc : pchar;
  1912. pw : pcompilerwidestring;
  1913. i : longint;
  1914. begin
  1915. inherited ppuload(constsym,ppufile);
  1916. constdef:=nil;
  1917. consttyp:=tconsttyp(ppufile.getbyte);
  1918. fillchar(value, sizeof(value), #0);
  1919. case consttyp of
  1920. constord :
  1921. begin
  1922. ppufile.getderef(constdefderef);
  1923. value.valueord:=ppufile.getexprint;
  1924. end;
  1925. constpointer :
  1926. begin
  1927. ppufile.getderef(constdefderef);
  1928. value.valueordptr:=ppufile.getptruint;
  1929. end;
  1930. constwstring :
  1931. begin
  1932. initwidestring(pw);
  1933. setlengthwidestring(pw,ppufile.getlongint);
  1934. { don't use getdata, because the compilerwidechars may have to
  1935. be byteswapped
  1936. }
  1937. {$if sizeof(tcompilerwidechar) = 2}
  1938. for i:=0 to pw^.len-1 do
  1939. pw^.data[i]:=ppufile.getword;
  1940. {$elseif sizeof(tcompilerwidechar) = 4}
  1941. for i:=0 to pw^.len-1 do
  1942. pw^.data[i]:=cardinal(ppufile.getlongint);
  1943. {$else}
  1944. {$error Unsupported tcompilerwidechar size}
  1945. {$endif}
  1946. pcompilerwidestring(value.valueptr):=pw;
  1947. end;
  1948. conststring,
  1949. constresourcestring :
  1950. begin
  1951. value.len:=ppufile.getlongint;
  1952. getmem(pc,value.len+1);
  1953. ppufile.getdata(pc^,value.len);
  1954. pc[value.len]:=#0;
  1955. value.valueptr:=pc;
  1956. end;
  1957. constreal :
  1958. begin
  1959. ppufile.getderef(constdefderef);
  1960. new(pd);
  1961. pd^:=ppufile.getreal;
  1962. value.valueptr:=pd;
  1963. end;
  1964. constset :
  1965. begin
  1966. ppufile.getderef(constdefderef);
  1967. new(ps);
  1968. ppufile.getnormalset(ps^);
  1969. value.valueptr:=ps;
  1970. end;
  1971. constguid :
  1972. begin
  1973. new(pguid(value.valueptr));
  1974. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1975. end;
  1976. constnil : ;
  1977. else
  1978. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1979. end;
  1980. end;
  1981. destructor tconstsym.destroy;
  1982. begin
  1983. case consttyp of
  1984. conststring,
  1985. constresourcestring :
  1986. freemem(pchar(value.valueptr),value.len+1);
  1987. constwstring :
  1988. donewidestring(pcompilerwidestring(value.valueptr));
  1989. constreal :
  1990. dispose(pbestreal(value.valueptr));
  1991. constset :
  1992. dispose(pnormalset(value.valueptr));
  1993. constguid :
  1994. dispose(pguid(value.valueptr));
  1995. end;
  1996. inherited destroy;
  1997. end;
  1998. procedure tconstsym.buildderef;
  1999. begin
  2000. if consttyp in [constord,constreal,constpointer,constset] then
  2001. constdefderef.build(constdef);
  2002. end;
  2003. procedure tconstsym.deref;
  2004. begin
  2005. if consttyp in [constord,constreal,constpointer,constset] then
  2006. constdef:=tdef(constdefderef.resolve);
  2007. end;
  2008. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  2009. begin
  2010. inherited ppuwrite(ppufile);
  2011. ppufile.putbyte(byte(consttyp));
  2012. case consttyp of
  2013. constnil : ;
  2014. constord :
  2015. begin
  2016. ppufile.putderef(constdefderef);
  2017. ppufile.putexprint(value.valueord);
  2018. end;
  2019. constpointer :
  2020. begin
  2021. ppufile.putderef(constdefderef);
  2022. ppufile.putptruint(value.valueordptr);
  2023. end;
  2024. constwstring :
  2025. begin
  2026. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  2027. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  2028. end;
  2029. conststring,
  2030. constresourcestring :
  2031. begin
  2032. ppufile.putlongint(value.len);
  2033. ppufile.putdata(pchar(value.valueptr)^,value.len);
  2034. end;
  2035. constreal :
  2036. begin
  2037. ppufile.putderef(constdefderef);
  2038. ppufile.putreal(pbestreal(value.valueptr)^);
  2039. end;
  2040. constset :
  2041. begin
  2042. ppufile.putderef(constdefderef);
  2043. ppufile.putnormalset(value.valueptr^);
  2044. end;
  2045. constguid :
  2046. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2047. else
  2048. internalerror(13);
  2049. end;
  2050. ppufile.writeentry(ibconstsym);
  2051. end;
  2052. {****************************************************************************
  2053. TENUMSYM
  2054. ****************************************************************************}
  2055. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2056. begin
  2057. inherited create(enumsym,n);
  2058. definition:=def;
  2059. value:=v;
  2060. end;
  2061. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2062. begin
  2063. inherited ppuload(enumsym,ppufile);
  2064. ppufile.getderef(definitionderef);
  2065. value:=ppufile.getlongint;
  2066. end;
  2067. procedure tenumsym.buildderef;
  2068. begin
  2069. definitionderef.build(definition);
  2070. end;
  2071. procedure tenumsym.deref;
  2072. begin
  2073. definition:=tenumdef(definitionderef.resolve);
  2074. end;
  2075. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2076. begin
  2077. inherited ppuwrite(ppufile);
  2078. ppufile.putderef(definitionderef);
  2079. ppufile.putlongint(value);
  2080. ppufile.writeentry(ibenumsym);
  2081. end;
  2082. {****************************************************************************
  2083. TTYPESYM
  2084. ****************************************************************************}
  2085. constructor tgenericconstraintdata.create;
  2086. begin
  2087. interfaces:=tfpobjectlist.create(false);
  2088. interfacesderef:=tfplist.create;
  2089. end;
  2090. destructor tgenericconstraintdata.destroy;
  2091. var
  2092. i : longint;
  2093. begin
  2094. for i:=0 to interfacesderef.count-1 do
  2095. dispose(pderef(interfacesderef[i]));
  2096. interfacesderef.free;
  2097. interfaces.free;
  2098. inherited destroy;
  2099. end;
  2100. procedure tgenericconstraintdata.ppuload(ppufile: tcompilerppufile);
  2101. var
  2102. cnt,i : longint;
  2103. intfderef : pderef;
  2104. begin
  2105. ppufile.getsmallset(flags);
  2106. ppufile.getderef(basedefderef);
  2107. cnt:=ppufile.getlongint;
  2108. for i:=0 to cnt-1 do
  2109. begin
  2110. new(intfderef);
  2111. ppufile.getderef(intfderef^);
  2112. interfacesderef.add(intfderef);
  2113. end;
  2114. end;
  2115. procedure tgenericconstraintdata.ppuwrite(ppufile: tcompilerppufile);
  2116. var
  2117. i : longint;
  2118. begin
  2119. ppufile.putsmallset(flags);
  2120. ppufile.putderef(basedefderef);
  2121. ppufile.putlongint(interfacesderef.count);
  2122. for i:=0 to interfacesderef.count-1 do
  2123. ppufile.putderef(pderef(interfacesderef[i])^);
  2124. end;
  2125. procedure tgenericconstraintdata.buildderef;
  2126. var
  2127. intfderef : pderef;
  2128. i : longint;
  2129. begin
  2130. basedefderef.build(basedef);
  2131. for i:=0 to interfaces.count-1 do
  2132. begin
  2133. new(intfderef);
  2134. intfderef^.build(tobjectdef(interfaces[i]));
  2135. interfacesderef.add(intfderef);
  2136. end;
  2137. end;
  2138. procedure tgenericconstraintdata.deref;
  2139. var
  2140. i : longint;
  2141. begin
  2142. basedef:=tdef(basedefderef.resolve);
  2143. for i:=0 to interfacesderef.count-1 do
  2144. interfaces.add(pderef(interfacesderef[i])^.resolve);
  2145. end;
  2146. constructor ttypesym.create(const n : string;def:tdef);
  2147. begin
  2148. inherited create(typesym,n);
  2149. typedef:=def;
  2150. { register the typesym for the definition }
  2151. if assigned(typedef) and
  2152. (typedef.typ<>errordef) and
  2153. not(assigned(typedef.typesym)) then
  2154. typedef.typesym:=self;
  2155. end;
  2156. destructor ttypesym.destroy;
  2157. begin
  2158. genconstraintdata.free;
  2159. inherited destroy;
  2160. end;
  2161. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2162. begin
  2163. inherited ppuload(typesym,ppufile);
  2164. ppufile.getderef(typedefderef);
  2165. fprettyname:=ppufile.getansistring;
  2166. if ppufile.getbyte<>0 then
  2167. begin
  2168. genconstraintdata:=tgenericconstraintdata.create;
  2169. genconstraintdata.ppuload(ppufile);
  2170. end;
  2171. end;
  2172. procedure ttypesym.buildderef;
  2173. begin
  2174. typedefderef.build(typedef);
  2175. if assigned(genconstraintdata) then
  2176. genconstraintdata.buildderef;
  2177. end;
  2178. procedure ttypesym.deref;
  2179. begin
  2180. typedef:=tdef(typedefderef.resolve);
  2181. if assigned(genconstraintdata) then
  2182. genconstraintdata.deref;
  2183. end;
  2184. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2185. begin
  2186. inherited ppuwrite(ppufile);
  2187. ppufile.putderef(typedefderef);
  2188. ppufile.putansistring(fprettyname);
  2189. if assigned(genconstraintdata) then
  2190. begin
  2191. ppufile.putbyte(1);
  2192. genconstraintdata.ppuwrite(ppufile);
  2193. end
  2194. else
  2195. ppufile.putbyte(0);
  2196. ppufile.writeentry(ibtypesym);
  2197. end;
  2198. function ttypesym.prettyname : string;
  2199. begin
  2200. if fprettyname<>'' then
  2201. result:=fprettyname
  2202. else
  2203. result:=inherited prettyname;
  2204. end;
  2205. {****************************************************************************
  2206. TSYSSYM
  2207. ****************************************************************************}
  2208. constructor tsyssym.create(const n : string;l : longint);
  2209. begin
  2210. inherited create(syssym,n);
  2211. number:=l;
  2212. end;
  2213. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2214. begin
  2215. inherited ppuload(syssym,ppufile);
  2216. number:=ppufile.getlongint;
  2217. end;
  2218. destructor tsyssym.destroy;
  2219. begin
  2220. inherited destroy;
  2221. end;
  2222. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2223. begin
  2224. inherited ppuwrite(ppufile);
  2225. ppufile.putlongint(number);
  2226. ppufile.writeentry(ibsyssym);
  2227. end;
  2228. {*****************************************************************************
  2229. TMacro
  2230. *****************************************************************************}
  2231. constructor tmacro.create(const n : string);
  2232. begin
  2233. inherited create(macrosym,n);
  2234. owner:=nil;
  2235. defined:=false;
  2236. is_used:=false;
  2237. is_compiler_var:=false;
  2238. buftext:=nil;
  2239. buflen:=0;
  2240. end;
  2241. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2242. begin
  2243. inherited ppuload(macrosym,ppufile);
  2244. defined:=boolean(ppufile.getbyte);
  2245. is_compiler_var:=boolean(ppufile.getbyte);
  2246. is_used:=false;
  2247. buflen:= ppufile.getlongint;
  2248. if buflen > 0 then
  2249. begin
  2250. getmem(buftext, buflen);
  2251. ppufile.getdata(buftext^, buflen)
  2252. end
  2253. else
  2254. buftext:=nil;
  2255. end;
  2256. destructor tmacro.destroy;
  2257. begin
  2258. if assigned(buftext) then
  2259. freemem(buftext);
  2260. inherited destroy;
  2261. end;
  2262. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2263. begin
  2264. inherited ppuwrite(ppufile);
  2265. ppufile.putbyte(byte(defined));
  2266. ppufile.putbyte(byte(is_compiler_var));
  2267. ppufile.putlongint(buflen);
  2268. if buflen > 0 then
  2269. ppufile.putdata(buftext^,buflen);
  2270. ppufile.writeentry(ibmacrosym);
  2271. end;
  2272. function tmacro.GetCopy:tmacro;
  2273. var
  2274. p : tmacro;
  2275. begin
  2276. p:=tmacro.create(realname);
  2277. p.defined:=defined;
  2278. p.is_used:=is_used;
  2279. p.is_compiler_var:=is_compiler_var;
  2280. p.buflen:=buflen;
  2281. if assigned(buftext) then
  2282. begin
  2283. getmem(p.buftext,buflen);
  2284. move(buftext^,p.buftext^,buflen);
  2285. end;
  2286. Result:=p;
  2287. end;
  2288. end.