2
0

symsym.pas 67 KB

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