symsym.pas 84 KB

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