symsym.pas 68 KB

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