symsym.pas 64 KB

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