symsym.pas 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120
  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(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. inparentfpstruct : boolean; { migrated to a parentfpstruct because of nested access (not written to ppu, because not important and would change interface crc) }
  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): tprocdef;
  606. var
  607. eq: tequaltype;
  608. begin
  609. result:=nil;
  610. if assigned(retdef) then
  611. eq:=compare_defs(retdef,pd.returndef,nothingn)
  612. else
  613. eq:=te_equal;
  614. if (eq>=te_equal) or
  615. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  616. begin
  617. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  618. if (eq>=te_equal) or
  619. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  620. begin
  621. result:=pd;
  622. exit;
  623. end;
  624. end;
  625. end;
  626. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  627. cpoptions:tcompare_paras_options):Tprocdef;
  628. var
  629. i : longint;
  630. pd : tprocdef;
  631. begin
  632. result:=nil;
  633. for i:=0 to ProcdefList.Count-1 do
  634. begin
  635. pd:=tprocdef(ProcdefList[i]);
  636. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  637. if assigned(result) then
  638. exit;
  639. end;
  640. end;
  641. function Tprocsym.find_procdef_bytype_and_para(pt:Tproctypeoption;
  642. para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  643. var
  644. i : longint;
  645. pd : tprocdef;
  646. begin
  647. result:=nil;
  648. for i:=0 to ProcdefList.Count-1 do
  649. begin
  650. pd:=tprocdef(ProcdefList[i]);
  651. if pd.proctypeoption=pt then
  652. begin
  653. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  654. if assigned(result) then
  655. exit;
  656. end;
  657. end;
  658. end;
  659. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  660. var
  661. i : longint;
  662. pd : tprocdef;
  663. begin
  664. result:=nil;
  665. for i:=0 to ProcdefList.Count-1 do
  666. begin
  667. pd:=tprocdef(ProcdefList[i]);
  668. if ops * pd.procoptions = ops then
  669. begin
  670. result:=pd;
  671. exit;
  672. end;
  673. end;
  674. end;
  675. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  676. var
  677. i : longint;
  678. bestpd,
  679. pd : tprocdef;
  680. eq,besteq : tequaltype;
  681. begin
  682. { This function will return the pprocdef of pprocsym that
  683. is the best match for procvardef. When there are multiple
  684. matches it returns nil.}
  685. result:=nil;
  686. bestpd:=nil;
  687. besteq:=te_incompatible;
  688. for i:=0 to ProcdefList.Count-1 do
  689. begin
  690. pd:=tprocdef(ProcdefList[i]);
  691. eq:=proc_to_procvar_equal(pd,d,false);
  692. if eq>=te_convert_l1 then
  693. begin
  694. { multiple procvars with the same equal level }
  695. if assigned(bestpd) and
  696. (besteq=eq) then
  697. exit;
  698. if eq>besteq then
  699. begin
  700. besteq:=eq;
  701. bestpd:=pd;
  702. end;
  703. end;
  704. end;
  705. result:=bestpd;
  706. end;
  707. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  708. var
  709. paraidx, realparamcount,
  710. i, j : longint;
  711. bestpd,
  712. hpd,
  713. pd : tprocdef;
  714. convtyp : tconverttype;
  715. eq : tequaltype;
  716. begin
  717. { This function will return the pprocdef of pprocsym that
  718. is the best match for fromdef and todef. }
  719. result:=nil;
  720. bestpd:=nil;
  721. besteq:=te_incompatible;
  722. for i:=0 to ProcdefList.Count-1 do
  723. begin
  724. pd:=tprocdef(ProcdefList[i]);
  725. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  726. continue;
  727. if (equal_defs(todef,pd.returndef) or
  728. { shortstrings of different lengths are ok as result }
  729. (is_shortstring(todef) and is_shortstring(pd.returndef))) and
  730. { the result type must be always really equal and not an alias,
  731. if you mess with this code, check tw4093 }
  732. ((todef=pd.returndef) or
  733. (
  734. not(df_unique in todef.defoptions) and
  735. not(df_unique in pd.returndef.defoptions)
  736. )
  737. ) then
  738. begin
  739. paraidx:=0;
  740. { ignore vs_hidden parameters }
  741. while (paraidx<pd.paras.count) and
  742. assigned(pd.paras[paraidx]) and
  743. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  744. inc(paraidx);
  745. realparamcount:=0;
  746. for j := 0 to pd.paras.Count-1 do
  747. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  748. inc(realparamcount);
  749. if (paraidx<pd.paras.count) and
  750. assigned(pd.paras[paraidx]) and
  751. (realparamcount = 1) then
  752. begin
  753. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  754. { alias? if yes, only l1 choice,
  755. if you mess with this code, check tw4093 }
  756. if (eq=te_exact) and
  757. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  758. ((df_unique in fromdef.defoptions) or
  759. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  760. eq:=te_convert_l1;
  761. if eq=te_exact then
  762. begin
  763. besteq:=eq;
  764. result:=pd;
  765. exit;
  766. end;
  767. if eq>besteq then
  768. begin
  769. bestpd:=pd;
  770. besteq:=eq;
  771. end;
  772. end;
  773. end;
  774. end;
  775. result:=bestpd;
  776. end;
  777. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  778. var
  779. paraidx, realparamcount,
  780. i, j : longint;
  781. bestpd,
  782. hpd,
  783. pd : tprocdef;
  784. current : tpropertysym;
  785. convtyp : tconverttype;
  786. eq : tequaltype;
  787. begin
  788. { This function will return the pprocdef of pprocsym that
  789. is the best match for fromdef and todef. }
  790. result:=nil;
  791. bestpd:=nil;
  792. besteq:=te_incompatible;
  793. for i:=0 to ProcdefList.Count-1 do
  794. begin
  795. pd:=tprocdef(ProcdefList[i]);
  796. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  797. continue;
  798. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  799. continue;
  800. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  801. if (current = nil) then
  802. continue;
  803. // compare current result def with the todef
  804. if (equal_defs(todef, current.propdef) or
  805. { shortstrings of different lengths are ok as result }
  806. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  807. { the result type must be always really equal and not an alias,
  808. if you mess with this code, check tw4093 }
  809. ((todef=current.propdef) or
  810. (
  811. not(df_unique in todef.defoptions) and
  812. not(df_unique in current.propdef.defoptions)
  813. )
  814. ) then
  815. begin
  816. paraidx:=0;
  817. { ignore vs_hidden parameters }
  818. while (paraidx<pd.paras.count) and
  819. assigned(pd.paras[paraidx]) and
  820. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  821. inc(paraidx);
  822. realparamcount:=0;
  823. for j := 0 to pd.paras.Count-1 do
  824. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  825. inc(realparamcount);
  826. if (paraidx<pd.paras.count) and
  827. assigned(pd.paras[paraidx]) and
  828. (realparamcount = 1) then
  829. begin
  830. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  831. { alias? if yes, only l1 choice,
  832. if you mess with this code, check tw4093 }
  833. if (eq=te_exact) and
  834. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  835. ((df_unique in fromdef.defoptions) or
  836. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  837. eq:=te_convert_l1;
  838. if eq=te_exact then
  839. begin
  840. besteq:=eq;
  841. result:=pd;
  842. exit;
  843. end;
  844. if eq>besteq then
  845. begin
  846. bestpd:=pd;
  847. besteq:=eq;
  848. end;
  849. end;
  850. end;
  851. end;
  852. result:=bestpd;
  853. end;
  854. {****************************************************************************
  855. TERRORSYM
  856. ****************************************************************************}
  857. constructor terrorsym.create;
  858. begin
  859. inherited create(errorsym,'');
  860. end;
  861. {****************************************************************************
  862. TPROPERTYSYM
  863. ****************************************************************************}
  864. constructor tpropertysym.create(const n : string);
  865. var
  866. pap : tpropaccesslisttypes;
  867. begin
  868. inherited create(propertysym,n);
  869. propoptions:=[];
  870. index:=0;
  871. default:=0;
  872. propdef:=nil;
  873. indexdef:=nil;
  874. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  875. propaccesslist[pap]:=tpropaccesslist.create;
  876. end;
  877. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  878. var
  879. pap : tpropaccesslisttypes;
  880. begin
  881. inherited ppuload(propertysym,ppufile);
  882. ppufile.getsmallset(propoptions);
  883. ppufile.getderef(overriddenpropsymderef);
  884. ppufile.getderef(propdefderef);
  885. index:=ppufile.getlongint;
  886. default:=ppufile.getlongint;
  887. ppufile.getderef(indexdefderef);
  888. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  889. propaccesslist[pap]:=ppufile.getpropaccesslist;
  890. end;
  891. destructor tpropertysym.destroy;
  892. var
  893. pap : tpropaccesslisttypes;
  894. begin
  895. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  896. propaccesslist[pap].free;
  897. inherited destroy;
  898. end;
  899. procedure tpropertysym.buildderef;
  900. var
  901. pap : tpropaccesslisttypes;
  902. begin
  903. overriddenpropsymderef.build(overriddenpropsym);
  904. propdefderef.build(propdef);
  905. indexdefderef.build(indexdef);
  906. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  907. propaccesslist[pap].buildderef;
  908. end;
  909. procedure tpropertysym.deref;
  910. var
  911. pap : tpropaccesslisttypes;
  912. begin
  913. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  914. indexdef:=tdef(indexdefderef.resolve);
  915. propdef:=tdef(propdefderef.resolve);
  916. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  917. propaccesslist[pap].resolve;
  918. end;
  919. function tpropertysym.getsize : asizeint;
  920. begin
  921. getsize:=0;
  922. end;
  923. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  924. var
  925. pap : tpropaccesslisttypes;
  926. begin
  927. inherited ppuwrite(ppufile);
  928. ppufile.putsmallset(propoptions);
  929. ppufile.putderef(overriddenpropsymderef);
  930. ppufile.putderef(propdefderef);
  931. ppufile.putlongint(index);
  932. ppufile.putlongint(default);
  933. ppufile.putderef(indexdefderef);
  934. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  935. ppufile.putpropaccesslist(propaccesslist[pap]);
  936. ppufile.writeentry(ibpropertysym);
  937. end;
  938. {****************************************************************************
  939. TABSTRACTVARSYM
  940. ****************************************************************************}
  941. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  942. begin
  943. inherited create(st,n);
  944. vardef:=def;
  945. varspez:=vsp;
  946. varstate:=vs_declared;
  947. varoptions:=vopts;
  948. end;
  949. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  950. begin
  951. inherited ppuload(st,ppufile);
  952. varstate:=vs_readwritten;
  953. varspez:=tvarspez(ppufile.getbyte);
  954. varregable:=tvarregable(ppufile.getbyte);
  955. addr_taken:=boolean(ppufile.getbyte);
  956. ppufile.getderef(vardefderef);
  957. ppufile.getsmallset(varoptions);
  958. end;
  959. destructor tabstractvarsym.destroy;
  960. begin
  961. if assigned(notifications) then
  962. notifications.destroy;
  963. inherited destroy;
  964. end;
  965. procedure tabstractvarsym.buildderef;
  966. begin
  967. vardefderef.build(vardef);
  968. end;
  969. procedure tabstractvarsym.deref;
  970. var
  971. oldvarregable: tvarregable;
  972. begin
  973. { setting the vardef also updates varregable. We just loaded this }
  974. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  975. { tw7817b.pp: the address is taken of a local variable in an }
  976. { inlined procedure -> must remain non-regable when inlining) }
  977. oldvarregable:=varregable;
  978. vardef:=tdef(vardefderef.resolve);
  979. varregable:=oldvarregable;
  980. end;
  981. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  982. var
  983. oldintfcrc : boolean;
  984. begin
  985. inherited ppuwrite(ppufile);
  986. ppufile.putbyte(byte(varspez));
  987. oldintfcrc:=ppufile.do_crc;
  988. ppufile.do_crc:=false;
  989. ppufile.putbyte(byte(varregable));
  990. ppufile.putbyte(byte(addr_taken));
  991. ppufile.do_crc:=oldintfcrc;
  992. ppufile.putderef(vardefderef);
  993. ppufile.putsmallset(varoptions);
  994. end;
  995. function tabstractvarsym.getsize : asizeint;
  996. begin
  997. if assigned(vardef) and
  998. ((vardef.typ<>arraydef) or
  999. is_dynamic_array(vardef) or
  1000. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1001. result:=vardef.size
  1002. else
  1003. result:=0;
  1004. end;
  1005. function tabstractvarsym.getpackedbitsize : longint;
  1006. begin
  1007. { bitpacking is only done for ordinals }
  1008. if not is_ordinal(vardef) then
  1009. internalerror(2006082010);
  1010. result:=vardef.packedbitsize;
  1011. end;
  1012. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1013. begin
  1014. { Register variables are not allowed in the following cases:
  1015. - regvars are disabled
  1016. - exceptions are used (after an exception is raised the contents of the
  1017. registers is not valid anymore)
  1018. - it has a local copy
  1019. - the value needs to be in memory (i.e. reference counted) }
  1020. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1021. not(pi_has_assembler_block in current_procinfo.flags) and
  1022. not(pi_uses_exceptions in current_procinfo.flags) and
  1023. not(pi_has_interproclabel in current_procinfo.flags) and
  1024. not(vo_has_local_copy in varoptions) and
  1025. ((refpara and
  1026. (varregable <> vr_none)) or
  1027. (not refpara and
  1028. not(varregable in [vr_none,vr_addr])))
  1029. {$if not defined(powerpc) and not defined(powerpc64)}
  1030. and ((vardef.typ <> recorddef) or
  1031. (varregable = vr_addr) or
  1032. not(varstate in [vs_written,vs_readwritten]));
  1033. {$endif}
  1034. end;
  1035. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1036. var n:Tnotification;
  1037. begin
  1038. if assigned(notifications) then
  1039. begin
  1040. n:=Tnotification(notifications.first);
  1041. while assigned(n) do
  1042. begin
  1043. if what in n.flags then
  1044. n.callback(what,self);
  1045. n:=Tnotification(n.next);
  1046. end;
  1047. end;
  1048. end;
  1049. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1050. Tnotification_callback):cardinal;
  1051. var n:Tnotification;
  1052. begin
  1053. if not assigned(notifications) then
  1054. notifications:=Tlinkedlist.create;
  1055. n:=Tnotification.create(flags,callback);
  1056. register_notification:=n.id;
  1057. notifications.concat(n);
  1058. end;
  1059. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1060. var n:Tnotification;
  1061. begin
  1062. if not assigned(notifications) then
  1063. internalerror(200212311)
  1064. else
  1065. begin
  1066. n:=Tnotification(notifications.first);
  1067. while assigned(n) do
  1068. begin
  1069. if n.id=id then
  1070. begin
  1071. notifications.remove(n);
  1072. n.destroy;
  1073. exit;
  1074. end;
  1075. n:=Tnotification(n.next);
  1076. end;
  1077. internalerror(200212311)
  1078. end;
  1079. end;
  1080. procedure tabstractvarsym.setvardef(def:tdef);
  1081. begin
  1082. _vardef := def;
  1083. { can we load the value into a register ? }
  1084. if not assigned(owner) or
  1085. (owner.symtabletype in [localsymtable,parasymtable]) or
  1086. (
  1087. (owner.symtabletype=staticsymtable) and
  1088. not(cs_create_pic in current_settings.moduleswitches)
  1089. ) then
  1090. begin
  1091. if tstoreddef(vardef).is_intregable then
  1092. varregable:=vr_intreg
  1093. else
  1094. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1095. if {(
  1096. not assigned(owner) or
  1097. (owner.symtabletype<>staticsymtable)
  1098. ) and }
  1099. tstoreddef(vardef).is_fpuregable then
  1100. begin
  1101. if use_vectorfpu(vardef) then
  1102. varregable:=vr_mmreg
  1103. else
  1104. varregable:=vr_fpureg;
  1105. end;
  1106. end;
  1107. end;
  1108. {****************************************************************************
  1109. TFIELDVARSYM
  1110. ****************************************************************************}
  1111. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1112. begin
  1113. inherited create(fieldvarsym,n,vsp,def,vopts);
  1114. fieldoffset:=-1;
  1115. end;
  1116. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1117. begin
  1118. inherited ppuload(fieldvarsym,ppufile);
  1119. fieldoffset:=ppufile.getaint;
  1120. if (vo_has_mangledname in varoptions) then
  1121. externalname:=stringdup(ppufile.getstring)
  1122. else
  1123. externalname:=nil;
  1124. end;
  1125. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1126. begin
  1127. inherited ppuwrite(ppufile);
  1128. ppufile.putaint(fieldoffset);
  1129. if (vo_has_mangledname in varoptions) then
  1130. ppufile.putstring(externalname^);
  1131. ppufile.writeentry(ibfieldvarsym);
  1132. end;
  1133. procedure tfieldvarsym.set_externalname(const s: string);
  1134. var
  1135. tmp: string;
  1136. begin
  1137. { make sure it is recalculated }
  1138. stringdispose(cachedmangledname);
  1139. {$ifdef jvm}
  1140. if is_java_class_or_interface(tdef(owner.defowner)) then
  1141. begin
  1142. externalname:=stringdup(s);
  1143. include(varoptions,vo_has_mangledname);
  1144. end
  1145. else
  1146. {$endif jvm}
  1147. internalerror(2011031201);
  1148. end;
  1149. function tfieldvarsym.mangledname:string;
  1150. var
  1151. srsym : tsym;
  1152. srsymtable : tsymtable;
  1153. begin
  1154. {$ifdef jvm}
  1155. if is_java_class_or_interface(tdef(owner.defowner)) or
  1156. (tdef(owner.defowner).typ=recorddef) then
  1157. begin
  1158. if assigned(cachedmangledname) then
  1159. result:=cachedmangledname^
  1160. else
  1161. begin
  1162. result:=jvmmangledbasename(self,false);
  1163. jvmaddtypeownerprefix(owner,result);
  1164. cachedmangledname:=stringdup(result);
  1165. end;
  1166. end
  1167. else
  1168. {$endif jvm}
  1169. if sp_static in symoptions then
  1170. begin
  1171. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1172. result:=srsym.mangledname
  1173. { when generating the debug info for the module in which the }
  1174. { symbol is defined, the localsymtable of that module is }
  1175. { already popped from the symtablestack }
  1176. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1177. result:=srsym.mangledname
  1178. else
  1179. internalerror(2007012501);
  1180. end
  1181. else if is_objcclass(tdef(owner.defowner)) then
  1182. begin
  1183. if assigned(cachedmangledname) then
  1184. result:=cachedmangledname^
  1185. else
  1186. begin
  1187. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1188. cachedmangledname:=stringdup(result);
  1189. end;
  1190. end
  1191. else
  1192. result:=inherited mangledname;
  1193. end;
  1194. destructor tfieldvarsym.destroy;
  1195. begin
  1196. stringdispose(cachedmangledname);
  1197. inherited destroy;
  1198. end;
  1199. {****************************************************************************
  1200. TABSTRACTNORMALVARSYM
  1201. ****************************************************************************}
  1202. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1203. begin
  1204. inherited create(st,n,vsp,def,vopts);
  1205. fillchar(localloc,sizeof(localloc),0);
  1206. fillchar(initialloc,sizeof(initialloc),0);
  1207. defaultconstsym:=nil;
  1208. end;
  1209. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1210. begin
  1211. inherited ppuload(st,ppufile);
  1212. fillchar(localloc,sizeof(localloc),0);
  1213. fillchar(initialloc,sizeof(initialloc),0);
  1214. ppufile.getderef(defaultconstsymderef);
  1215. end;
  1216. procedure tabstractnormalvarsym.buildderef;
  1217. begin
  1218. inherited buildderef;
  1219. defaultconstsymderef.build(defaultconstsym);
  1220. end;
  1221. procedure tabstractnormalvarsym.deref;
  1222. begin
  1223. inherited deref;
  1224. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1225. end;
  1226. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1227. begin
  1228. inherited ppuwrite(ppufile);
  1229. ppufile.putderef(defaultconstsymderef);
  1230. end;
  1231. {****************************************************************************
  1232. Tstaticvarsym
  1233. ****************************************************************************}
  1234. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1235. begin
  1236. inherited create(staticvarsym,n,vsp,def,vopts);
  1237. _mangledname:=nil;
  1238. end;
  1239. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1240. begin
  1241. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1242. end;
  1243. constructor tstaticvarsym.create_C(const n,mangled : string;vsp:tvarspez;def:tdef);
  1244. begin
  1245. tstaticvarsym(self).create(n,vsp,def,[]);
  1246. set_mangledname(mangled);
  1247. end;
  1248. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1249. begin
  1250. inherited ppuload(staticvarsym,ppufile);
  1251. if vo_has_mangledname in varoptions then
  1252. _mangledname:=stringdup(ppufile.getstring)
  1253. else
  1254. _mangledname:=nil;
  1255. if vo_has_section in varoptions then
  1256. section:=ppufile.getansistring;
  1257. end;
  1258. destructor tstaticvarsym.destroy;
  1259. begin
  1260. if assigned(_mangledname) then
  1261. begin
  1262. {$ifdef MEMDEBUG}
  1263. memmanglednames.start;
  1264. {$endif MEMDEBUG}
  1265. stringdispose(_mangledname);
  1266. {$ifdef MEMDEBUG}
  1267. memmanglednames.stop;
  1268. {$endif MEMDEBUG}
  1269. end;
  1270. inherited destroy;
  1271. end;
  1272. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1273. begin
  1274. inherited ppuwrite(ppufile);
  1275. if vo_has_mangledname in varoptions then
  1276. ppufile.putstring(_mangledname^);
  1277. if vo_has_section in varoptions then
  1278. ppufile.putansistring(section);
  1279. ppufile.writeentry(ibstaticvarsym);
  1280. end;
  1281. function tstaticvarsym.mangledname:string;
  1282. var
  1283. {$ifdef jvm}
  1284. tmpname: string;
  1285. {$else jvm}
  1286. prefix : string[2];
  1287. {$endif jvm}
  1288. begin
  1289. if not assigned(_mangledname) then
  1290. begin
  1291. {$ifdef jvm}
  1292. tmpname:=jvmmangledbasename(self,false);
  1293. jvmaddtypeownerprefix(owner,tmpname);
  1294. _mangledname:=stringdup(tmpname);
  1295. {$else jvm}
  1296. if (vo_is_typed_const in varoptions) then
  1297. prefix:='TC'
  1298. else
  1299. prefix:='U';
  1300. {$ifdef compress}
  1301. _mangledname:=stringdup(minilzw_encode(make_mangledname(prefix,owner,name)));
  1302. {$else compress}
  1303. _mangledname:=stringdup(make_mangledname(prefix,owner,name));
  1304. {$endif compress}
  1305. {$endif jvm}
  1306. end;
  1307. result:=_mangledname^;
  1308. end;
  1309. procedure tstaticvarsym.set_mangledname(const s:string);
  1310. {$ifdef jvm}
  1311. var
  1312. tmpname: string;
  1313. {$endif}
  1314. begin
  1315. stringdispose(_mangledname);
  1316. {$if defined(jvm)}
  1317. tmpname:=jvmmangledbasename(self,s,false);
  1318. jvmaddtypeownerprefix(owner,tmpname);
  1319. _mangledname:=stringdup(tmpname);
  1320. {$elseif defined(compress)}
  1321. _mangledname:=stringdup(minilzw_encode(s));
  1322. {$else}
  1323. _mangledname:=stringdup(s);
  1324. {$endif}
  1325. include(varoptions,vo_has_mangledname);
  1326. end;
  1327. {****************************************************************************
  1328. TLOCALVARSYM
  1329. ****************************************************************************}
  1330. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1331. begin
  1332. inherited create(localvarsym,n,vsp,def,vopts);
  1333. end;
  1334. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1335. begin
  1336. inherited ppuload(localvarsym,ppufile);
  1337. end;
  1338. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1339. begin
  1340. inherited ppuwrite(ppufile);
  1341. ppufile.writeentry(iblocalvarsym);
  1342. end;
  1343. {****************************************************************************
  1344. TPARAVARSYM
  1345. ****************************************************************************}
  1346. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1347. begin
  1348. inherited create(paravarsym,n,vsp,def,vopts);
  1349. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) then
  1350. varstate := vs_initialised;
  1351. paranr:=nr;
  1352. paraloc[calleeside].init;
  1353. paraloc[callerside].init;
  1354. end;
  1355. destructor tparavarsym.destroy;
  1356. begin
  1357. paraloc[calleeside].done;
  1358. paraloc[callerside].done;
  1359. inherited destroy;
  1360. end;
  1361. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1362. var
  1363. b : byte;
  1364. begin
  1365. inherited ppuload(paravarsym,ppufile);
  1366. paranr:=ppufile.getword;
  1367. univpara:=boolean(ppufile.getbyte);
  1368. { The var state of parameter symbols is fixed after writing them so
  1369. we write them to the unit file.
  1370. This enables constant folding for inline procedures loaded from units
  1371. }
  1372. varstate:=tvarstate(ppufile.getbyte);
  1373. paraloc[calleeside].init;
  1374. paraloc[callerside].init;
  1375. if vo_has_explicit_paraloc in varoptions then
  1376. begin
  1377. paraloc[callerside].alignment:=ppufile.getbyte;
  1378. b:=ppufile.getbyte;
  1379. if b<>sizeof(paraloc[callerside].location^) then
  1380. internalerror(200411154);
  1381. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1382. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1383. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1384. end;
  1385. end;
  1386. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1387. var
  1388. oldintfcrc : boolean;
  1389. begin
  1390. inherited ppuwrite(ppufile);
  1391. ppufile.putword(paranr);
  1392. ppufile.putbyte(byte(univpara));
  1393. { The var state of parameter symbols is fixed after writing them so
  1394. we write them to the unit file.
  1395. This enables constant folding for inline procedures loaded from units
  1396. }
  1397. oldintfcrc:=ppufile.do_crc;
  1398. ppufile.do_crc:=false;
  1399. ppufile.putbyte(ord(varstate));
  1400. ppufile.do_crc:=oldintfcrc;
  1401. if vo_has_explicit_paraloc in varoptions then
  1402. begin
  1403. paraloc[callerside].check_simple_location;
  1404. ppufile.putbyte(sizeof(paraloc[callerside].alignment));
  1405. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1406. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1407. end;
  1408. ppufile.writeentry(ibparavarsym);
  1409. end;
  1410. {****************************************************************************
  1411. TABSOLUTEVARSYM
  1412. ****************************************************************************}
  1413. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1414. begin
  1415. inherited create(absolutevarsym,n,vs_value,def,[]);
  1416. ref:=nil;
  1417. end;
  1418. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1419. begin
  1420. inherited create(absolutevarsym,n,vs_value,def,[]);
  1421. ref:=_ref;
  1422. end;
  1423. destructor tabsolutevarsym.destroy;
  1424. begin
  1425. if assigned(ref) then
  1426. ref.free;
  1427. inherited destroy;
  1428. end;
  1429. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1430. begin
  1431. inherited ppuload(absolutevarsym,ppufile);
  1432. ref:=nil;
  1433. asmname:=nil;
  1434. abstyp:=absolutetyp(ppufile.getbyte);
  1435. {$ifdef i386}
  1436. absseg:=false;
  1437. {$endif i386}
  1438. case abstyp of
  1439. tovar :
  1440. ref:=ppufile.getpropaccesslist;
  1441. toasm :
  1442. asmname:=stringdup(ppufile.getstring);
  1443. toaddr :
  1444. begin
  1445. addroffset:=ppufile.getaword;
  1446. {$ifdef i386}
  1447. absseg:=boolean(ppufile.getbyte);
  1448. {$endif i386}
  1449. end;
  1450. end;
  1451. end;
  1452. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1453. begin
  1454. inherited ppuwrite(ppufile);
  1455. ppufile.putbyte(byte(abstyp));
  1456. case abstyp of
  1457. tovar :
  1458. ppufile.putpropaccesslist(ref);
  1459. toasm :
  1460. ppufile.putstring(asmname^);
  1461. toaddr :
  1462. begin
  1463. ppufile.putaword(addroffset);
  1464. {$ifdef i386}
  1465. ppufile.putbyte(byte(absseg));
  1466. {$endif i386}
  1467. end;
  1468. end;
  1469. ppufile.writeentry(ibabsolutevarsym);
  1470. end;
  1471. procedure tabsolutevarsym.buildderef;
  1472. begin
  1473. inherited buildderef;
  1474. if (abstyp=tovar) then
  1475. ref.buildderef;
  1476. end;
  1477. procedure tabsolutevarsym.deref;
  1478. begin
  1479. inherited deref;
  1480. { own absolute deref }
  1481. if (abstyp=tovar) then
  1482. ref.resolve;
  1483. end;
  1484. function tabsolutevarsym.mangledname : string;
  1485. begin
  1486. case abstyp of
  1487. toasm :
  1488. mangledname:=asmname^;
  1489. toaddr :
  1490. mangledname:='$'+tostr(addroffset);
  1491. else
  1492. internalerror(200411062);
  1493. end;
  1494. end;
  1495. {****************************************************************************
  1496. TCONSTSYM
  1497. ****************************************************************************}
  1498. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1499. begin
  1500. inherited create(constsym,n);
  1501. fillchar(value, sizeof(value), #0);
  1502. consttyp:=t;
  1503. value.valueord:=v;
  1504. constdef:=def;
  1505. end;
  1506. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1507. begin
  1508. inherited create(constsym,n);
  1509. fillchar(value, sizeof(value), #0);
  1510. consttyp:=t;
  1511. value.valueordptr:=v;
  1512. constdef:=def;
  1513. end;
  1514. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1515. begin
  1516. inherited create(constsym,n);
  1517. fillchar(value, sizeof(value), #0);
  1518. consttyp:=t;
  1519. value.valueptr:=v;
  1520. constdef:=def;
  1521. end;
  1522. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1523. begin
  1524. inherited create(constsym,n);
  1525. fillchar(value, sizeof(value), #0);
  1526. consttyp:=t;
  1527. value.valueptr:=str;
  1528. constdef:=nil;
  1529. value.len:=l;
  1530. end;
  1531. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1532. begin
  1533. inherited create(constsym,n);
  1534. fillchar(value, sizeof(value), #0);
  1535. consttyp:=t;
  1536. pcompilerwidestring(value.valueptr):=pw;
  1537. constdef:=nil;
  1538. value.len:=getlengthwidestring(pw);
  1539. end;
  1540. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1541. var
  1542. pd : pbestreal;
  1543. ps : pnormalset;
  1544. pc : pchar;
  1545. pw : pcompilerwidestring;
  1546. i : longint;
  1547. begin
  1548. inherited ppuload(constsym,ppufile);
  1549. constdef:=nil;
  1550. consttyp:=tconsttyp(ppufile.getbyte);
  1551. fillchar(value, sizeof(value), #0);
  1552. case consttyp of
  1553. constord :
  1554. begin
  1555. ppufile.getderef(constdefderef);
  1556. value.valueord:=ppufile.getexprint;
  1557. end;
  1558. constpointer :
  1559. begin
  1560. ppufile.getderef(constdefderef);
  1561. value.valueordptr:=ppufile.getptruint;
  1562. end;
  1563. constwstring :
  1564. begin
  1565. initwidestring(pw);
  1566. setlengthwidestring(pw,ppufile.getlongint);
  1567. { don't use getdata, because the compilerwidechars may have to
  1568. be byteswapped
  1569. }
  1570. {$if sizeof(tcompilerwidechar) = 2}
  1571. for i:=0 to pw^.len-1 do
  1572. pw^.data[i]:=ppufile.getword;
  1573. {$elseif sizeof(tcompilerwidechar) = 4}
  1574. for i:=0 to pw^.len-1 do
  1575. pw^.data[i]:=cardinal(ppufile.getlongint);
  1576. {$else}
  1577. {$error Unsupported tcompilerwidechar size}
  1578. {$endif}
  1579. pcompilerwidestring(value.valueptr):=pw;
  1580. end;
  1581. conststring,
  1582. constresourcestring :
  1583. begin
  1584. value.len:=ppufile.getlongint;
  1585. getmem(pc,value.len+1);
  1586. ppufile.getdata(pc^,value.len);
  1587. pc[value.len]:=#0;
  1588. value.valueptr:=pc;
  1589. end;
  1590. constreal :
  1591. begin
  1592. new(pd);
  1593. pd^:=ppufile.getreal;
  1594. value.valueptr:=pd;
  1595. end;
  1596. constset :
  1597. begin
  1598. ppufile.getderef(constdefderef);
  1599. new(ps);
  1600. ppufile.getnormalset(ps^);
  1601. value.valueptr:=ps;
  1602. end;
  1603. constguid :
  1604. begin
  1605. new(pguid(value.valueptr));
  1606. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1607. end;
  1608. constnil : ;
  1609. else
  1610. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1611. end;
  1612. end;
  1613. destructor tconstsym.destroy;
  1614. begin
  1615. case consttyp of
  1616. conststring,
  1617. constresourcestring :
  1618. freemem(pchar(value.valueptr),value.len+1);
  1619. constwstring :
  1620. donewidestring(pcompilerwidestring(value.valueptr));
  1621. constreal :
  1622. dispose(pbestreal(value.valueptr));
  1623. constset :
  1624. dispose(pnormalset(value.valueptr));
  1625. constguid :
  1626. dispose(pguid(value.valueptr));
  1627. end;
  1628. inherited destroy;
  1629. end;
  1630. procedure tconstsym.buildderef;
  1631. begin
  1632. if consttyp in [constord,constpointer,constset] then
  1633. constdefderef.build(constdef);
  1634. end;
  1635. procedure tconstsym.deref;
  1636. begin
  1637. if consttyp in [constord,constpointer,constset] then
  1638. constdef:=tdef(constdefderef.resolve);
  1639. end;
  1640. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1641. begin
  1642. inherited ppuwrite(ppufile);
  1643. ppufile.putbyte(byte(consttyp));
  1644. case consttyp of
  1645. constnil : ;
  1646. constord :
  1647. begin
  1648. ppufile.putderef(constdefderef);
  1649. ppufile.putexprint(value.valueord);
  1650. end;
  1651. constpointer :
  1652. begin
  1653. ppufile.putderef(constdefderef);
  1654. ppufile.putptruint(value.valueordptr);
  1655. end;
  1656. constwstring :
  1657. begin
  1658. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  1659. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  1660. end;
  1661. conststring,
  1662. constresourcestring :
  1663. begin
  1664. ppufile.putlongint(value.len);
  1665. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1666. end;
  1667. constreal :
  1668. ppufile.putreal(pbestreal(value.valueptr)^);
  1669. constset :
  1670. begin
  1671. ppufile.putderef(constdefderef);
  1672. ppufile.putnormalset(value.valueptr^);
  1673. end;
  1674. constguid :
  1675. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1676. else
  1677. internalerror(13);
  1678. end;
  1679. ppufile.writeentry(ibconstsym);
  1680. end;
  1681. {****************************************************************************
  1682. TENUMSYM
  1683. ****************************************************************************}
  1684. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1685. begin
  1686. inherited create(enumsym,n);
  1687. definition:=def;
  1688. value:=v;
  1689. end;
  1690. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1691. begin
  1692. inherited ppuload(enumsym,ppufile);
  1693. ppufile.getderef(definitionderef);
  1694. value:=ppufile.getlongint;
  1695. end;
  1696. procedure tenumsym.buildderef;
  1697. begin
  1698. definitionderef.build(definition);
  1699. end;
  1700. procedure tenumsym.deref;
  1701. begin
  1702. definition:=tenumdef(definitionderef.resolve);
  1703. end;
  1704. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1705. begin
  1706. inherited ppuwrite(ppufile);
  1707. ppufile.putderef(definitionderef);
  1708. ppufile.putlongint(value);
  1709. ppufile.writeentry(ibenumsym);
  1710. end;
  1711. {****************************************************************************
  1712. TTYPESYM
  1713. ****************************************************************************}
  1714. constructor ttypesym.create(const n : string;def:tdef);
  1715. begin
  1716. inherited create(typesym,n);
  1717. typedef:=def;
  1718. { register the typesym for the definition }
  1719. if assigned(typedef) and
  1720. (typedef.typ<>errordef) and
  1721. not(assigned(typedef.typesym)) then
  1722. typedef.typesym:=self;
  1723. end;
  1724. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1725. begin
  1726. inherited ppuload(typesym,ppufile);
  1727. ppufile.getderef(typedefderef);
  1728. fprettyname:=ppufile.getansistring;
  1729. end;
  1730. procedure ttypesym.buildderef;
  1731. begin
  1732. typedefderef.build(typedef);
  1733. end;
  1734. procedure ttypesym.deref;
  1735. begin
  1736. typedef:=tdef(typedefderef.resolve);
  1737. end;
  1738. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1739. begin
  1740. inherited ppuwrite(ppufile);
  1741. ppufile.putderef(typedefderef);
  1742. ppufile.putansistring(fprettyname);
  1743. ppufile.writeentry(ibtypesym);
  1744. end;
  1745. function ttypesym.prettyname : string;
  1746. begin
  1747. if fprettyname<>'' then
  1748. result:=fprettyname
  1749. else
  1750. result:=inherited prettyname;
  1751. end;
  1752. {****************************************************************************
  1753. TSYSSYM
  1754. ****************************************************************************}
  1755. constructor tsyssym.create(const n : string;l : longint);
  1756. begin
  1757. inherited create(syssym,n);
  1758. number:=l;
  1759. end;
  1760. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1761. begin
  1762. inherited ppuload(syssym,ppufile);
  1763. number:=ppufile.getlongint;
  1764. end;
  1765. destructor tsyssym.destroy;
  1766. begin
  1767. inherited destroy;
  1768. end;
  1769. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1770. begin
  1771. inherited ppuwrite(ppufile);
  1772. ppufile.putlongint(number);
  1773. ppufile.writeentry(ibsyssym);
  1774. end;
  1775. {*****************************************************************************
  1776. TMacro
  1777. *****************************************************************************}
  1778. constructor tmacro.create(const n : string);
  1779. begin
  1780. inherited create(macrosym,n);
  1781. owner:=nil;
  1782. defined:=false;
  1783. is_used:=false;
  1784. is_compiler_var:=false;
  1785. buftext:=nil;
  1786. buflen:=0;
  1787. end;
  1788. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  1789. begin
  1790. inherited ppuload(macrosym,ppufile);
  1791. defined:=boolean(ppufile.getbyte);
  1792. is_compiler_var:=boolean(ppufile.getbyte);
  1793. is_used:=false;
  1794. buflen:= ppufile.getlongint;
  1795. if buflen > 0 then
  1796. begin
  1797. getmem(buftext, buflen);
  1798. ppufile.getdata(buftext^, buflen)
  1799. end
  1800. else
  1801. buftext:=nil;
  1802. end;
  1803. destructor tmacro.destroy;
  1804. begin
  1805. if assigned(buftext) then
  1806. freemem(buftext);
  1807. inherited destroy;
  1808. end;
  1809. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  1810. begin
  1811. inherited ppuwrite(ppufile);
  1812. ppufile.putbyte(byte(defined));
  1813. ppufile.putbyte(byte(is_compiler_var));
  1814. ppufile.putlongint(buflen);
  1815. if buflen > 0 then
  1816. ppufile.putdata(buftext^,buflen);
  1817. ppufile.writeentry(ibmacrosym);
  1818. end;
  1819. function tmacro.GetCopy:tmacro;
  1820. var
  1821. p : tmacro;
  1822. begin
  1823. p:=tmacro.create(realname);
  1824. p.defined:=defined;
  1825. p.is_used:=is_used;
  1826. p.is_compiler_var:=is_compiler_var;
  1827. p.buflen:=buflen;
  1828. if assigned(buftext) then
  1829. begin
  1830. getmem(p.buftext,buflen);
  1831. move(buftext^,p.buftext^,buflen);
  1832. end;
  1833. Result:=p;
  1834. end;
  1835. end.