symsym.pas 67 KB

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