symsym.pas 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336
  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,
  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 : boolean;
  46. { points to the matching node, only valid resulttype pass is run and
  47. the goto<->label relation in the node tree is created, should
  48. be a tnode }
  49. code : pointer;
  50. { when the label is defined in an asm block, this points to the
  51. generated asmlabel }
  52. asmblocklabel : tasmlabel;
  53. constructor create(const n : string);
  54. constructor ppuload(ppufile:tcompilerppufile);
  55. procedure ppuwrite(ppufile:tcompilerppufile);override;
  56. end;
  57. tunitsym = class(Tstoredsym)
  58. module : tobject; { tmodule }
  59. constructor create(const n : string;amodule : tobject);
  60. constructor ppuload(ppufile:tcompilerppufile);
  61. destructor destroy;override;
  62. procedure ppuwrite(ppufile:tcompilerppufile);override;
  63. end;
  64. terrorsym = class(Tsym)
  65. constructor create;
  66. end;
  67. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  68. tprocsym = class(tstoredsym)
  69. protected
  70. pdlistfirst,
  71. pdlistlast : pprocdeflist; { linked list of overloaded procdefs }
  72. function getprocdef(nr:cardinal):Tprocdef;
  73. public
  74. procdef_count : byte;
  75. overloadchecked : boolean;
  76. property procdef[nr:cardinal]:Tprocdef read getprocdef;
  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 unchain_overload;
  86. procedure ppuwrite(ppufile:tcompilerppufile);override;
  87. procedure buildderef;override;
  88. procedure deref;override;
  89. procedure addprocdef(p:tprocdef);
  90. procedure addprocdef_deref(const d:tderef);
  91. procedure add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  92. procedure concat_procdefs_to(s:Tprocsym);
  93. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  94. function first_procdef:Tprocdef;
  95. function last_procdef:Tprocdef;
  96. function search_procdef_nopara_boolret:Tprocdef;
  97. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  98. function search_procdef_bypara(para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  99. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  100. function search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  101. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  102. { currobjdef is the object def to assume, this is necessary for protected and
  103. private,
  104. context is the object def we're really in, this is for the strict stuff
  105. }
  106. function is_visible_for_object(currobjdef:tdef;context:tdef):boolean;override;
  107. end;
  108. ttypesym = class(Tstoredsym)
  109. restype : ttype;
  110. constructor create(const n : string;const tt : ttype);
  111. constructor ppuload(ppufile:tcompilerppufile);
  112. procedure ppuwrite(ppufile:tcompilerppufile);override;
  113. procedure buildderef;override;
  114. procedure deref;override;
  115. function gettypedef:tdef;override;
  116. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  117. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  118. end;
  119. tabstractvarsym = class(tstoredsym)
  120. varoptions : tvaroptions;
  121. varspez : tvarspez; { sets the type of access }
  122. varregable : tvarregable;
  123. varstate : tvarstate;
  124. notifications : Tlinkedlist;
  125. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  126. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  127. destructor destroy;override;
  128. procedure ppuwrite(ppufile:tcompilerppufile);override;
  129. procedure buildderef;override;
  130. procedure deref;override;
  131. function getsize : longint;
  132. function is_regvar:boolean;
  133. procedure trigger_notifications(what:Tnotification_flag);
  134. function register_notification(flags:Tnotification_flags;
  135. callback:Tnotification_callback):cardinal;
  136. procedure unregister_notification(id:cardinal);
  137. private
  138. procedure setvartype(const newtype: ttype);
  139. _vartype : ttype;
  140. public
  141. property vartype: ttype read _vartype write setvartype;
  142. end;
  143. tfieldvarsym = class(tabstractvarsym)
  144. fieldoffset : aint; { offset in record/object }
  145. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  146. constructor ppuload(ppufile:tcompilerppufile);
  147. procedure ppuwrite(ppufile:tcompilerppufile);override;
  148. end;
  149. tabstractnormalvarsym = class(tabstractvarsym)
  150. defaultconstsym : tsym;
  151. defaultconstsymderef : tderef;
  152. localloc : TLocation; { register/reference for local var }
  153. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  154. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  155. procedure ppuwrite(ppufile:tcompilerppufile);override;
  156. procedure buildderef;override;
  157. procedure deref;override;
  158. end;
  159. tlocalvarsym = class(tabstractnormalvarsym)
  160. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  161. constructor ppuload(ppufile:tcompilerppufile);
  162. procedure ppuwrite(ppufile:tcompilerppufile);override;
  163. end;
  164. tparavarsym = class(tabstractnormalvarsym)
  165. paraloc : array[tcallercallee] of TCGPara;
  166. paranr : word; { position of this parameter }
  167. {$ifdef EXTDEBUG}
  168. eqval : tequaltype;
  169. {$endif EXTDEBUG}
  170. constructor create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  171. constructor ppuload(ppufile:tcompilerppufile);
  172. destructor destroy;override;
  173. procedure ppuwrite(ppufile:tcompilerppufile);override;
  174. end;
  175. tglobalvarsym = class(tabstractnormalvarsym)
  176. private
  177. _mangledname : pstring;
  178. public
  179. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  180. constructor create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  181. constructor create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  182. constructor ppuload(ppufile:tcompilerppufile);
  183. destructor destroy;override;
  184. procedure ppuwrite(ppufile:tcompilerppufile);override;
  185. function mangledname:string;override;
  186. procedure set_mangledname(const s:string);
  187. end;
  188. tabsolutevarsym = class(tabstractvarsym)
  189. public
  190. abstyp : absolutetyp;
  191. {$ifdef i386}
  192. absseg : boolean;
  193. {$endif i386}
  194. asmname : pstring;
  195. addroffset : aint;
  196. ref : tsymlist;
  197. constructor create(const n : string;const tt : ttype);
  198. constructor create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  199. destructor destroy;override;
  200. constructor ppuload(ppufile:tcompilerppufile);
  201. procedure buildderef;override;
  202. procedure deref;override;
  203. function mangledname : string;override;
  204. procedure ppuwrite(ppufile:tcompilerppufile);override;
  205. end;
  206. tpropertysym = class(Tstoredsym)
  207. propoptions : tpropertyoptions;
  208. propoverriden : tpropertysym;
  209. propoverridenderef : tderef;
  210. proptype,
  211. indextype : ttype;
  212. index,
  213. default : longint;
  214. readaccess,
  215. writeaccess,
  216. storedaccess : tsymlist;
  217. constructor create(const n : string);
  218. destructor destroy;override;
  219. constructor ppuload(ppufile:tcompilerppufile);
  220. function getsize : longint;
  221. procedure ppuwrite(ppufile:tcompilerppufile);override;
  222. function gettypedef:tdef;override;
  223. procedure buildderef;override;
  224. procedure deref;override;
  225. procedure derefimpl;override;
  226. procedure dooverride(overriden:tpropertysym);
  227. end;
  228. ttypedconstsym = class(tstoredsym)
  229. private
  230. _mangledname : pstring;
  231. public
  232. typedconsttype : ttype;
  233. is_writable : boolean;
  234. constructor create(const n : string;p : tdef;writable : boolean);
  235. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  236. constructor ppuload(ppufile:tcompilerppufile);
  237. destructor destroy;override;
  238. function mangledname : string;override;
  239. procedure ppuwrite(ppufile:tcompilerppufile);override;
  240. procedure buildderef;override;
  241. procedure deref;override;
  242. function getsize:longint;
  243. end;
  244. tconstvalue = record
  245. case integer of
  246. 0: (valueord : tconstexprint);
  247. 1: (valueordptr : tconstptruint);
  248. 2: (valueptr : pointer; len : longint);
  249. end;
  250. tconstsym = class(tstoredsym)
  251. consttype : ttype;
  252. consttyp : tconsttyp;
  253. value : tconstvalue;
  254. resstrindex : longint; { needed for resource strings }
  255. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  256. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  257. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  258. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  259. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  260. constructor ppuload(ppufile:tcompilerppufile);
  261. destructor destroy;override;
  262. procedure buildderef;override;
  263. procedure deref;override;
  264. procedure ppuwrite(ppufile:tcompilerppufile);override;
  265. end;
  266. tenumsym = class(Tstoredsym)
  267. value : longint;
  268. definition : tenumdef;
  269. definitionderef : tderef;
  270. nextenum : tenumsym;
  271. constructor create(const n : string;def : tenumdef;v : longint);
  272. constructor ppuload(ppufile:tcompilerppufile);
  273. procedure ppuwrite(ppufile:tcompilerppufile);override;
  274. procedure buildderef;override;
  275. procedure deref;override;
  276. procedure order;
  277. end;
  278. tsyssym = class(Tstoredsym)
  279. number : longint;
  280. constructor create(const n : string;l : longint);
  281. constructor ppuload(ppufile:tcompilerppufile);
  282. destructor destroy;override;
  283. procedure ppuwrite(ppufile:tcompilerppufile);override;
  284. end;
  285. const
  286. maxmacrolen=16*1024;
  287. type
  288. pmacrobuffer = ^tmacrobuffer;
  289. tmacrobuffer = array[0..maxmacrolen-1] of char;
  290. tmacro = class(tstoredsym)
  291. {Normally true, but false when a previously defined macro is undef-ed}
  292. defined : boolean;
  293. {True if this is a mac style compiler variable, in which case no macro
  294. substitutions shall be done.}
  295. is_compiler_var : boolean;
  296. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  297. {e. g. an IFDEF which returns false, will not be registered as used,}
  298. {since there is no place to register its use. }
  299. is_used : boolean;
  300. buftext : pchar;
  301. buflen : longint;
  302. constructor create(const n : string);
  303. constructor ppuload(ppufile:tcompilerppufile);
  304. procedure ppuwrite(ppufile:tcompilerppufile);override;
  305. destructor destroy;override;
  306. function GetCopy:tmacro;
  307. end;
  308. { compiler generated symbol to point to rtti and init/finalize tables }
  309. trttisym = class(tstoredsym)
  310. private
  311. _mangledname : pstring;
  312. public
  313. lab : tasmsymbol;
  314. rttityp : trttitype;
  315. constructor create(const n:string;rt:trttitype);
  316. constructor ppuload(ppufile:tcompilerppufile);
  317. destructor destroy;override;
  318. procedure ppuwrite(ppufile:tcompilerppufile);override;
  319. function mangledname:string;override;
  320. function get_label:tasmsymbol;
  321. end;
  322. var
  323. generrorsym : tsym;
  324. implementation
  325. uses
  326. { global }
  327. verbose,
  328. { target }
  329. systems,
  330. { symtable }
  331. defutil,symtable,
  332. { tree }
  333. node,
  334. { aasm }
  335. aasmtai,aasmdata,
  336. { codegen }
  337. paramgr,cresstr,
  338. procinfo
  339. ;
  340. {****************************************************************************
  341. Helpers
  342. ****************************************************************************}
  343. {****************************************************************************
  344. TSYM (base for all symtypes)
  345. ****************************************************************************}
  346. constructor tstoredsym.create(st:tsymtyp;const n : string);
  347. begin
  348. inherited create(st,n);
  349. end;
  350. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  351. var
  352. nr : word;
  353. s : string;
  354. begin
  355. nr:=ppufile.getword;
  356. s:=ppufile.getstring;
  357. if s[1]='$' then
  358. inherited createname(copy(s,2,255))
  359. else
  360. inherited createname(upper(s));
  361. _realname:=stringdup(s);
  362. typ:=st;
  363. { force the correct indexnr. must be after create! }
  364. indexnr:=nr;
  365. ppufile.getposinfo(fileinfo);
  366. ppufile.getsmallset(symoptions);
  367. lastref:=nil;
  368. defref:=nil;
  369. refs:=0;
  370. lastwritten:=nil;
  371. refcount:=0;
  372. isstabwritten := false;
  373. end;
  374. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  375. begin
  376. ppufile.putword(indexnr);
  377. ppufile.putstring(_realname^);
  378. ppufile.putposinfo(fileinfo);
  379. ppufile.putsmallset(symoptions);
  380. end;
  381. destructor tstoredsym.destroy;
  382. begin
  383. if assigned(defref) then
  384. begin
  385. {$ifdef MEMDEBUG}
  386. membrowser.start;
  387. {$endif MEMDEBUG}
  388. defref.freechain;
  389. defref.free;
  390. {$ifdef MEMDEBUG}
  391. membrowser.stop;
  392. {$endif MEMDEBUG}
  393. end;
  394. inherited destroy;
  395. end;
  396. {****************************************************************************
  397. TLABELSYM
  398. ****************************************************************************}
  399. constructor tlabelsym.create(const n : string);
  400. begin
  401. inherited create(labelsym,n);
  402. used:=false;
  403. defined:=false;
  404. code:=nil;
  405. end;
  406. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  407. begin
  408. inherited ppuload(labelsym,ppufile);
  409. code:=nil;
  410. used:=false;
  411. defined:=true;
  412. end;
  413. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  414. begin
  415. if owner.symtabletype=globalsymtable then
  416. Message(sym_e_ill_label_decl)
  417. else
  418. begin
  419. inherited ppuwrite(ppufile);
  420. ppufile.writeentry(iblabelsym);
  421. end;
  422. end;
  423. {****************************************************************************
  424. TUNITSYM
  425. ****************************************************************************}
  426. constructor tunitsym.create(const n : string;amodule : tobject);
  427. var
  428. old_make_ref : boolean;
  429. begin
  430. old_make_ref:=make_ref;
  431. make_ref:=false;
  432. inherited create(unitsym,n);
  433. make_ref:=old_make_ref;
  434. module:=amodule;
  435. end;
  436. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  437. begin
  438. inherited ppuload(unitsym,ppufile);
  439. module:=nil;
  440. end;
  441. destructor tunitsym.destroy;
  442. begin
  443. inherited destroy;
  444. end;
  445. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  446. begin
  447. inherited ppuwrite(ppufile);
  448. ppufile.writeentry(ibunitsym);
  449. end;
  450. {****************************************************************************
  451. TPROCSYM
  452. ****************************************************************************}
  453. constructor tprocsym.create(const n : string);
  454. begin
  455. inherited create(procsym,n);
  456. pdlistfirst:=nil;
  457. pdlistlast:=nil;
  458. { the tprocdef have their own symoptions, make the procsym
  459. always visible }
  460. symoptions:=[sp_public];
  461. overloadchecked:=false;
  462. procdef_count:=0;
  463. end;
  464. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  465. var
  466. pdderef : tderef;
  467. i,n : longint;
  468. begin
  469. inherited ppuload(procsym,ppufile);
  470. pdlistfirst:=nil;
  471. pdlistlast:=nil;
  472. procdef_count:=0;
  473. n:=ppufile.getword;
  474. for i:=1to n do
  475. begin
  476. ppufile.getderef(pdderef);
  477. addprocdef_deref(pdderef);
  478. end;
  479. overloadchecked:=false;
  480. end;
  481. destructor tprocsym.destroy;
  482. var
  483. hp,p : pprocdeflist;
  484. begin
  485. p:=pdlistfirst;
  486. while assigned(p) do
  487. begin
  488. hp:=p^.next;
  489. dispose(p);
  490. p:=hp;
  491. end;
  492. inherited destroy;
  493. end;
  494. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  495. var
  496. p : pprocdeflist;
  497. n : word;
  498. begin
  499. inherited ppuwrite(ppufile);
  500. { count procdefs }
  501. n:=0;
  502. p:=pdlistfirst;
  503. while assigned(p) do
  504. begin
  505. { only write the proc definitions that belong
  506. to this procsym and are in the global symtable }
  507. if p^.def.owner=owner then
  508. inc(n);
  509. p:=p^.next;
  510. end;
  511. ppufile.putword(n);
  512. { write procdefs }
  513. p:=pdlistfirst;
  514. while assigned(p) do
  515. begin
  516. { only write the proc definitions that belong
  517. to this procsym and are in the global symtable }
  518. if p^.def.owner=owner then
  519. ppufile.putderef(p^.defderef);
  520. p:=p^.next;
  521. end;
  522. ppufile.writeentry(ibprocsym);
  523. end;
  524. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  525. var
  526. p : pprocdeflist;
  527. begin
  528. p:=pdlistfirst;
  529. while assigned(p) do
  530. begin
  531. if p^.def<>skipdef then
  532. MessagePos1(p^.def.fileinfo,sym_h_param_list,p^.def.fullprocname(false));
  533. p:=p^.next;
  534. end;
  535. end;
  536. {Makes implicit externals (procedures declared in the interface
  537. section which do not have a counterpart in the implementation)
  538. to be an imported procedure. For mode macpas.}
  539. procedure import_implict_external(pd:tabstractprocdef);
  540. begin
  541. tprocdef(pd).forwarddef:=false;
  542. tprocdef(pd).setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  543. end;
  544. procedure tprocsym.check_forward;
  545. var
  546. p : pprocdeflist;
  547. begin
  548. p:=pdlistfirst;
  549. while assigned(p) do
  550. begin
  551. if (p^.def.owner=owner) and (p^.def.forwarddef) then
  552. begin
  553. if (m_mac in aktmodeswitches) and (p^.def.interfacedef) then
  554. import_implict_external(p^.def)
  555. else
  556. begin
  557. MessagePos1(p^.def.fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname(false));
  558. { Turn further error messages off }
  559. p^.def.forwarddef:=false;
  560. end
  561. end;
  562. p:=p^.next;
  563. end;
  564. end;
  565. procedure tprocsym.buildderef;
  566. var
  567. p : pprocdeflist;
  568. begin
  569. p:=pdlistfirst;
  570. while assigned(p) do
  571. begin
  572. if p^.def.owner=owner then
  573. p^.defderef.build(p^.def);
  574. p:=p^.next;
  575. end;
  576. end;
  577. procedure tprocsym.deref;
  578. var
  579. p : pprocdeflist;
  580. begin
  581. { We have removed the overloaded entries, because they
  582. are not valid anymore and we can't deref them because
  583. the unit were they come from is not necessary in
  584. our uses clause (PFV) }
  585. unchain_overload;
  586. { Deref our own procdefs }
  587. p:=pdlistfirst;
  588. while assigned(p) do
  589. begin
  590. if not(
  591. (p^.def=nil) or
  592. (p^.def.owner=owner)
  593. ) then
  594. internalerror(200310291);
  595. p^.def:=tprocdef(p^.defderef.resolve);
  596. p:=p^.next;
  597. end;
  598. end;
  599. procedure tprocsym.addprocdef(p:tprocdef);
  600. var
  601. pd : pprocdeflist;
  602. begin
  603. new(pd);
  604. pd^.def:=p;
  605. pd^.defderef.reset;
  606. pd^.next:=nil;
  607. { Add at end of list to keep always
  608. a correct order, also after loading from ppu }
  609. if assigned(pdlistlast) then
  610. begin
  611. pdlistlast^.next:=pd;
  612. pdlistlast:=pd;
  613. end
  614. else
  615. begin
  616. pdlistfirst:=pd;
  617. pdlistlast:=pd;
  618. end;
  619. inc(procdef_count);
  620. end;
  621. procedure tprocsym.addprocdef_deref(const d:tderef);
  622. var
  623. pd : pprocdeflist;
  624. begin
  625. new(pd);
  626. pd^.def:=nil;
  627. pd^.defderef:=d;
  628. pd^.next:=nil;
  629. { Add at end of list to keep always
  630. a correct order, also after loading from ppu }
  631. if assigned(pdlistlast) then
  632. begin
  633. pdlistlast^.next:=pd;
  634. pdlistlast:=pd;
  635. end
  636. else
  637. begin
  638. pdlistfirst:=pd;
  639. pdlistlast:=pd;
  640. end;
  641. inc(procdef_count);
  642. end;
  643. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  644. var
  645. i : cardinal;
  646. pd : pprocdeflist;
  647. begin
  648. pd:=pdlistfirst;
  649. for i:=2 to nr do
  650. begin
  651. if not assigned(pd) then
  652. internalerror(200209051);
  653. pd:=pd^.next;
  654. end;
  655. getprocdef:=pd^.def;
  656. end;
  657. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  658. var
  659. pd:pprocdeflist;
  660. begin
  661. pd:=pdlistfirst;
  662. while assigned(pd) do
  663. begin
  664. if Aprocsym.search_procdef_bypara(pd^.def.paras,nil,cpoptions)=nil then
  665. Aprocsym.addprocdef(pd^.def);
  666. pd:=pd^.next;
  667. end;
  668. end;
  669. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  670. var
  671. pd : pprocdeflist;
  672. begin
  673. pd:=pdlistfirst;
  674. while assigned(pd) do
  675. begin
  676. s.addprocdef(pd^.def);
  677. pd:=pd^.next;
  678. end;
  679. end;
  680. function Tprocsym.first_procdef:Tprocdef;
  681. begin
  682. if assigned(pdlistfirst) then
  683. first_procdef:=pdlistfirst^.def
  684. else
  685. first_procdef:=nil;
  686. end;
  687. function Tprocsym.last_procdef:Tprocdef;
  688. begin
  689. if assigned(pdlistlast) then
  690. last_procdef:=pdlistlast^.def
  691. else
  692. last_procdef:=nil;
  693. end;
  694. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  695. var
  696. p : pprocdeflist;
  697. begin
  698. p:=pdlistfirst;
  699. while assigned(p) do
  700. begin
  701. proc2call(p^.def,arg);
  702. p:=p^.next;
  703. end;
  704. end;
  705. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  706. var
  707. p : pprocdeflist;
  708. begin
  709. search_procdef_nopara_boolret:=nil;
  710. p:=pdlistfirst;
  711. while p<>nil do
  712. begin
  713. if (p^.def.maxparacount=0) and
  714. is_boolean(p^.def.rettype.def) then
  715. begin
  716. search_procdef_nopara_boolret:=p^.def;
  717. break;
  718. end;
  719. p:=p^.next;
  720. end;
  721. end;
  722. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  723. var
  724. p : pprocdeflist;
  725. begin
  726. search_procdef_bytype:=nil;
  727. p:=pdlistfirst;
  728. while p<>nil do
  729. begin
  730. if p^.def.proctypeoption=pt then
  731. begin
  732. search_procdef_bytype:=p^.def;
  733. break;
  734. end;
  735. p:=p^.next;
  736. end;
  737. end;
  738. function Tprocsym.search_procdef_bypara(para:TFPObjectList;retdef:tdef;
  739. cpoptions:tcompare_paras_options):Tprocdef;
  740. var
  741. pd : pprocdeflist;
  742. eq : tequaltype;
  743. begin
  744. search_procdef_bypara:=nil;
  745. pd:=pdlistfirst;
  746. while assigned(pd) do
  747. begin
  748. if assigned(retdef) then
  749. eq:=compare_defs(retdef,pd^.def.rettype.def,nothingn)
  750. else
  751. eq:=te_equal;
  752. if (eq>=te_equal) or
  753. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  754. begin
  755. eq:=compare_paras(para,pd^.def.paras,cp_value_equal_const,cpoptions);
  756. if (eq>=te_equal) or
  757. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  758. begin
  759. search_procdef_bypara:=pd^.def;
  760. break;
  761. end;
  762. end;
  763. pd:=pd^.next;
  764. end;
  765. end;
  766. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  767. var
  768. pd : pprocdeflist;
  769. eq,besteq : tequaltype;
  770. bestpd : tprocdef;
  771. begin
  772. { This function will return the pprocdef of pprocsym that
  773. is the best match for procvardef. When there are multiple
  774. matches it returns nil.}
  775. search_procdef_byprocvardef:=nil;
  776. bestpd:=nil;
  777. besteq:=te_incompatible;
  778. pd:=pdlistfirst;
  779. while assigned(pd) do
  780. begin
  781. eq:=proc_to_procvar_equal(pd^.def,d);
  782. if eq>=te_equal then
  783. begin
  784. { multiple procvars with the same equal level }
  785. if assigned(bestpd) and
  786. (besteq=eq) then
  787. exit;
  788. if eq>besteq then
  789. begin
  790. besteq:=eq;
  791. bestpd:=pd^.def;
  792. end;
  793. end;
  794. pd:=pd^.next;
  795. end;
  796. search_procdef_byprocvardef:=bestpd;
  797. end;
  798. function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  799. var
  800. convtyp : tconverttype;
  801. pd : pprocdeflist;
  802. bestpd : tprocdef;
  803. eq : tequaltype;
  804. hpd : tprocdef;
  805. i : byte;
  806. begin
  807. result:=nil;
  808. bestpd:=nil;
  809. besteq:=te_incompatible;
  810. pd:=pdlistfirst;
  811. while assigned(pd) do
  812. begin
  813. if equal_defs(todef,pd^.def.rettype.def) and
  814. { the result type must be always really equal and not an alias,
  815. if you mess with this code, check tw4093 }
  816. ((todef=pd^.def.rettype.def) or
  817. (
  818. not(df_unique in todef.defoptions) and
  819. not(df_unique in pd^.def.rettype.def.defoptions)
  820. )
  821. ) then
  822. begin
  823. i:=0;
  824. { ignore vs_hidden parameters }
  825. while (i<pd^.def.paras.count) and
  826. assigned(pd^.def.paras[i]) and
  827. (vo_is_hidden_para in tparavarsym(pd^.def.paras[i]).varoptions) do
  828. inc(i);
  829. if (i<pd^.def.paras.count) and
  830. assigned(pd^.def.paras[i]) then
  831. begin
  832. eq:=compare_defs_ext(fromdef,tparavarsym(pd^.def.paras[i]).vartype.def,nothingn,convtyp,hpd,[]);
  833. { alias? if yes, only l1 choice,
  834. if you mess with this code, check tw4093 }
  835. if (eq=te_exact) and
  836. (fromdef<>tparavarsym(pd^.def.paras[i]).vartype.def) and
  837. ((df_unique in fromdef.defoptions) or
  838. (df_unique in tparavarsym(pd^.def.paras[i]).vartype.def.defoptions)) then
  839. eq:=te_convert_l1;
  840. if eq=te_exact then
  841. begin
  842. besteq:=eq;
  843. result:=pd^.def;
  844. exit;
  845. end;
  846. if eq>besteq then
  847. begin
  848. bestpd:=pd^.def;
  849. besteq:=eq;
  850. end;
  851. end;
  852. end;
  853. pd:=pd^.next;
  854. end;
  855. result:=bestpd;
  856. end;
  857. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  858. var
  859. p : pprocdeflist;
  860. begin
  861. write_references:=false;
  862. if not inherited write_references(ppufile,locals) then
  863. exit;
  864. write_references:=true;
  865. p:=pdlistfirst;
  866. while assigned(p) do
  867. begin
  868. if p^.def.owner=owner then
  869. p^.def.write_references(ppufile,locals);
  870. p:=p^.next;
  871. end;
  872. end;
  873. procedure tprocsym.unchain_overload;
  874. var
  875. p,hp : pprocdeflist;
  876. begin
  877. { remove all overloaded procdefs from the
  878. procdeflist that are not in the current symtable }
  879. overloadchecked:=false;
  880. p:=pdlistfirst;
  881. { reset new lists }
  882. pdlistfirst:=nil;
  883. pdlistlast:=nil;
  884. while assigned(p) do
  885. begin
  886. hp:=p^.next;
  887. { only keep the proc definitions:
  888. - are not deref'd (def=nil)
  889. - are in the same symtable as the procsym (for example both
  890. are in the staticsymtable) }
  891. if (p^.def=nil) or
  892. (p^.def.owner=owner) then
  893. begin
  894. { keep, add to list }
  895. if assigned(pdlistlast) then
  896. begin
  897. pdlistlast^.next:=p;
  898. pdlistlast:=p;
  899. end
  900. else
  901. begin
  902. pdlistfirst:=p;
  903. pdlistlast:=p;
  904. end;
  905. p^.next:=nil;
  906. end
  907. else
  908. begin
  909. { remove }
  910. dispose(p);
  911. dec(procdef_count);
  912. end;
  913. p:=hp;
  914. end;
  915. end;
  916. function tprocsym.is_visible_for_object(currobjdef:tdef;context:tdef):boolean;
  917. var
  918. p : pprocdeflist;
  919. begin
  920. { This procsym is visible, when there is at least
  921. one of the procdefs visible }
  922. result:=false;
  923. p:=pdlistfirst;
  924. while assigned(p) do
  925. begin
  926. if (p^.def.owner=owner) and
  927. p^.def.is_visible_for_object(tobjectdef(currobjdef)) then
  928. begin
  929. result:=true;
  930. exit;
  931. end;
  932. p:=p^.next;
  933. end;
  934. end;
  935. {****************************************************************************
  936. TERRORSYM
  937. ****************************************************************************}
  938. constructor terrorsym.create;
  939. begin
  940. inherited create(errorsym,'');
  941. end;
  942. {****************************************************************************
  943. TPROPERTYSYM
  944. ****************************************************************************}
  945. constructor tpropertysym.create(const n : string);
  946. begin
  947. inherited create(propertysym,n);
  948. propoptions:=[];
  949. index:=0;
  950. default:=0;
  951. proptype.reset;
  952. indextype.reset;
  953. readaccess:=tsymlist.create;
  954. writeaccess:=tsymlist.create;
  955. storedaccess:=tsymlist.create;
  956. end;
  957. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  958. begin
  959. inherited ppuload(propertysym,ppufile);
  960. ppufile.getsmallset(propoptions);
  961. if (ppo_is_override in propoptions) then
  962. begin
  963. ppufile.getderef(propoverridenderef);
  964. { we need to have these objects initialized }
  965. readaccess:=tsymlist.create;
  966. writeaccess:=tsymlist.create;
  967. storedaccess:=tsymlist.create;
  968. end
  969. else
  970. begin
  971. ppufile.gettype(proptype);
  972. index:=ppufile.getlongint;
  973. default:=ppufile.getlongint;
  974. ppufile.gettype(indextype);
  975. readaccess:=ppufile.getsymlist;
  976. writeaccess:=ppufile.getsymlist;
  977. storedaccess:=ppufile.getsymlist;
  978. end;
  979. end;
  980. destructor tpropertysym.destroy;
  981. begin
  982. readaccess.free;
  983. writeaccess.free;
  984. storedaccess.free;
  985. inherited destroy;
  986. end;
  987. function tpropertysym.gettypedef:tdef;
  988. begin
  989. gettypedef:=proptype.def;
  990. end;
  991. procedure tpropertysym.buildderef;
  992. begin
  993. if (ppo_is_override in propoptions) then
  994. begin
  995. propoverridenderef.build(propoverriden);
  996. end
  997. else
  998. begin
  999. proptype.buildderef;
  1000. indextype.buildderef;
  1001. readaccess.buildderef;
  1002. writeaccess.buildderef;
  1003. storedaccess.buildderef;
  1004. end;
  1005. end;
  1006. procedure tpropertysym.deref;
  1007. begin
  1008. if not(ppo_is_override in propoptions) then
  1009. begin
  1010. proptype.resolve;
  1011. indextype.resolve;
  1012. readaccess.resolve;
  1013. writeaccess.resolve;
  1014. storedaccess.resolve;
  1015. end;
  1016. end;
  1017. procedure tpropertysym.derefimpl;
  1018. begin
  1019. if (ppo_is_override in propoptions) then
  1020. begin
  1021. propoverriden:=tpropertysym(propoverridenderef.resolve);
  1022. dooverride(propoverriden);
  1023. end
  1024. end;
  1025. function tpropertysym.getsize : longint;
  1026. begin
  1027. getsize:=0;
  1028. end;
  1029. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1030. begin
  1031. inherited ppuwrite(ppufile);
  1032. ppufile.putsmallset(propoptions);
  1033. if (ppo_is_override in propoptions) then
  1034. ppufile.putderef(propoverridenderef)
  1035. else
  1036. begin
  1037. ppufile.puttype(proptype);
  1038. ppufile.putlongint(index);
  1039. ppufile.putlongint(default);
  1040. ppufile.puttype(indextype);
  1041. ppufile.putsymlist(readaccess);
  1042. ppufile.putsymlist(writeaccess);
  1043. ppufile.putsymlist(storedaccess);
  1044. end;
  1045. ppufile.writeentry(ibpropertysym);
  1046. end;
  1047. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1048. begin
  1049. propoverriden:=overriden;
  1050. proptype:=overriden.proptype;
  1051. propoptions:=overriden.propoptions+[ppo_is_override];
  1052. index:=overriden.index;
  1053. default:=overriden.default;
  1054. indextype:=overriden.indextype;
  1055. readaccess.free;
  1056. readaccess:=overriden.readaccess.getcopy;
  1057. writeaccess.free;
  1058. writeaccess:=overriden.writeaccess.getcopy;
  1059. storedaccess.free;
  1060. storedaccess:=overriden.storedaccess.getcopy;
  1061. end;
  1062. {****************************************************************************
  1063. TABSTRACTVARSYM
  1064. ****************************************************************************}
  1065. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1066. begin
  1067. inherited create(st,n);
  1068. vartype:=tt;
  1069. varspez:=vsp;
  1070. varstate:=vs_declared;
  1071. varoptions:=vopts;
  1072. end;
  1073. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1074. begin
  1075. inherited ppuload(st,ppufile);
  1076. varstate:=vs_readwritten;
  1077. varspez:=tvarspez(ppufile.getbyte);
  1078. varregable:=tvarregable(ppufile.getbyte);
  1079. ppufile.gettype(_vartype);
  1080. ppufile.getsmallset(varoptions);
  1081. end;
  1082. destructor tabstractvarsym.destroy;
  1083. begin
  1084. if assigned(notifications) then
  1085. notifications.destroy;
  1086. inherited destroy;
  1087. end;
  1088. procedure tabstractvarsym.buildderef;
  1089. begin
  1090. vartype.buildderef;
  1091. end;
  1092. procedure tabstractvarsym.deref;
  1093. begin
  1094. vartype.resolve;
  1095. end;
  1096. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1097. var
  1098. oldintfcrc : boolean;
  1099. begin
  1100. inherited ppuwrite(ppufile);
  1101. ppufile.putbyte(byte(varspez));
  1102. oldintfcrc:=ppufile.do_crc;
  1103. ppufile.do_crc:=false;
  1104. ppufile.putbyte(byte(varregable));
  1105. ppufile.do_crc:=oldintfcrc;
  1106. ppufile.puttype(vartype);
  1107. ppufile.putsmallset(varoptions);
  1108. end;
  1109. function tabstractvarsym.getsize : longint;
  1110. begin
  1111. if assigned(vartype.def) and
  1112. ((vartype.def.deftype<>arraydef) or
  1113. tarraydef(vartype.def).isDynamicArray or
  1114. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1115. result:=vartype.def.size
  1116. else
  1117. result:=0;
  1118. end;
  1119. function tabstractvarsym.is_regvar:boolean;
  1120. begin
  1121. { Register variables are not allowed in the following cases:
  1122. - regvars are disabled
  1123. - exceptions are used (after an exception is raised the contents of the
  1124. registers is not valid anymore)
  1125. - it has a local copy
  1126. - the value needs to be in memory (i.e. reference counted) }
  1127. result:=(cs_opt_regvar in aktoptimizerswitches) and
  1128. not(pi_has_assembler_block in current_procinfo.flags) and
  1129. not(pi_uses_exceptions in current_procinfo.flags) and
  1130. not(vo_has_local_copy in varoptions) and
  1131. (varregable<>vr_none);
  1132. end;
  1133. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1134. var n:Tnotification;
  1135. begin
  1136. if assigned(notifications) then
  1137. begin
  1138. n:=Tnotification(notifications.first);
  1139. while assigned(n) do
  1140. begin
  1141. if what in n.flags then
  1142. n.callback(what,self);
  1143. n:=Tnotification(n.next);
  1144. end;
  1145. end;
  1146. end;
  1147. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1148. Tnotification_callback):cardinal;
  1149. var n:Tnotification;
  1150. begin
  1151. if not assigned(notifications) then
  1152. notifications:=Tlinkedlist.create;
  1153. n:=Tnotification.create(flags,callback);
  1154. register_notification:=n.id;
  1155. notifications.concat(n);
  1156. end;
  1157. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1158. var n:Tnotification;
  1159. begin
  1160. if not assigned(notifications) then
  1161. internalerror(200212311)
  1162. else
  1163. begin
  1164. n:=Tnotification(notifications.first);
  1165. while assigned(n) do
  1166. begin
  1167. if n.id=id then
  1168. begin
  1169. notifications.remove(n);
  1170. n.destroy;
  1171. exit;
  1172. end;
  1173. n:=Tnotification(n.next);
  1174. end;
  1175. internalerror(200212311)
  1176. end;
  1177. end;
  1178. procedure tabstractvarsym.setvartype(const newtype: ttype);
  1179. begin
  1180. _vartype := newtype;
  1181. { can we load the value into a register ? }
  1182. if not assigned(owner) or
  1183. (owner.symtabletype in [localsymtable,parasymtable]) or
  1184. (
  1185. (owner.symtabletype=staticsymtable) and
  1186. not(cs_create_pic in aktmoduleswitches)
  1187. ) then
  1188. begin
  1189. if tstoreddef(vartype.def).is_intregable then
  1190. varregable:=vr_intreg
  1191. else
  1192. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1193. if {(
  1194. not assigned(owner) or
  1195. (owner.symtabletype<>staticsymtable)
  1196. ) and }
  1197. tstoreddef(vartype.def).is_fpuregable then
  1198. begin
  1199. {$ifdef x86}
  1200. if use_sse(vartype.def) then
  1201. varregable:=vr_mmreg
  1202. else
  1203. {$else x86}
  1204. varregable:=vr_fpureg;
  1205. {$endif x86}
  1206. end;
  1207. end;
  1208. end;
  1209. {****************************************************************************
  1210. TFIELDVARSYM
  1211. ****************************************************************************}
  1212. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1213. begin
  1214. inherited create(fieldvarsym,n,vsp,tt,vopts);
  1215. fieldoffset:=-1;
  1216. end;
  1217. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1218. begin
  1219. inherited ppuload(fieldvarsym,ppufile);
  1220. fieldoffset:=ppufile.getaint;
  1221. end;
  1222. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1223. begin
  1224. inherited ppuwrite(ppufile);
  1225. ppufile.putaint(fieldoffset);
  1226. ppufile.writeentry(ibfieldvarsym);
  1227. end;
  1228. {****************************************************************************
  1229. TABSTRACTNORMALVARSYM
  1230. ****************************************************************************}
  1231. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1232. begin
  1233. inherited create(st,n,vsp,tt,vopts);
  1234. fillchar(localloc,sizeof(localloc),0);
  1235. defaultconstsym:=nil;
  1236. end;
  1237. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1238. begin
  1239. inherited ppuload(st,ppufile);
  1240. fillchar(localloc,sizeof(localloc),0);
  1241. ppufile.getderef(defaultconstsymderef);
  1242. end;
  1243. procedure tabstractnormalvarsym.buildderef;
  1244. begin
  1245. inherited buildderef;
  1246. defaultconstsymderef.build(defaultconstsym);
  1247. end;
  1248. procedure tabstractnormalvarsym.deref;
  1249. begin
  1250. inherited deref;
  1251. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1252. end;
  1253. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1254. begin
  1255. inherited ppuwrite(ppufile);
  1256. ppufile.putderef(defaultconstsymderef);
  1257. end;
  1258. {****************************************************************************
  1259. TGLOBALVARSYM
  1260. ****************************************************************************}
  1261. constructor tglobalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1262. begin
  1263. inherited create(globalvarsym,n,vsp,tt,vopts);
  1264. _mangledname:=nil;
  1265. end;
  1266. constructor tglobalvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1267. begin
  1268. tglobalvarsym(self).create(n,vsp,tt,[vo_is_dll_var]);
  1269. end;
  1270. constructor tglobalvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1271. begin
  1272. tglobalvarsym(self).create(n,vsp,tt,[]);
  1273. set_mangledname(mangled);
  1274. end;
  1275. constructor tglobalvarsym.ppuload(ppufile:tcompilerppufile);
  1276. begin
  1277. inherited ppuload(globalvarsym,ppufile);
  1278. if vo_has_mangledname in varoptions then
  1279. _mangledname:=stringdup(ppufile.getstring)
  1280. else
  1281. _mangledname:=nil;
  1282. end;
  1283. destructor tglobalvarsym.destroy;
  1284. begin
  1285. if assigned(_mangledname) then
  1286. begin
  1287. {$ifdef MEMDEBUG}
  1288. memmanglednames.start;
  1289. {$endif MEMDEBUG}
  1290. stringdispose(_mangledname);
  1291. {$ifdef MEMDEBUG}
  1292. memmanglednames.stop;
  1293. {$endif MEMDEBUG}
  1294. end;
  1295. inherited destroy;
  1296. end;
  1297. procedure tglobalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1298. begin
  1299. inherited ppuwrite(ppufile);
  1300. if vo_has_mangledname in varoptions then
  1301. ppufile.putstring(_mangledname^);
  1302. ppufile.writeentry(ibglobalvarsym);
  1303. end;
  1304. function tglobalvarsym.mangledname:string;
  1305. begin
  1306. if not assigned(_mangledname) then
  1307. begin
  1308. {$ifdef compress}
  1309. _mangledname:=stringdup(minilzw_encode(make_mangledname('U',owner,name)));
  1310. {$else}
  1311. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1312. {$endif}
  1313. end;
  1314. result:=_mangledname^;
  1315. end;
  1316. procedure tglobalvarsym.set_mangledname(const s:string);
  1317. begin
  1318. stringdispose(_mangledname);
  1319. {$ifdef compress}
  1320. _mangledname:=stringdup(minilzw_encode(s));
  1321. {$else}
  1322. _mangledname:=stringdup(s);
  1323. {$endif}
  1324. include(varoptions,vo_has_mangledname);
  1325. end;
  1326. {****************************************************************************
  1327. TLOCALVARSYM
  1328. ****************************************************************************}
  1329. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1330. begin
  1331. inherited create(localvarsym,n,vsp,tt,vopts);
  1332. end;
  1333. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1334. begin
  1335. inherited ppuload(localvarsym,ppufile);
  1336. end;
  1337. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1338. begin
  1339. inherited ppuwrite(ppufile);
  1340. ppufile.writeentry(iblocalvarsym);
  1341. end;
  1342. {****************************************************************************
  1343. TPARAVARSYM
  1344. ****************************************************************************}
  1345. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1346. begin
  1347. inherited create(paravarsym,n,vsp,tt,vopts);
  1348. if (vsp in [vs_var,vs_value,vs_const]) then
  1349. varstate := vs_initialised;
  1350. paranr:=nr;
  1351. paraloc[calleeside].init;
  1352. paraloc[callerside].init;
  1353. end;
  1354. destructor tparavarsym.destroy;
  1355. begin
  1356. paraloc[calleeside].done;
  1357. paraloc[callerside].done;
  1358. inherited destroy;
  1359. end;
  1360. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1361. var
  1362. b : byte;
  1363. begin
  1364. inherited ppuload(paravarsym,ppufile);
  1365. paranr:=ppufile.getword;
  1366. paraloc[calleeside].init;
  1367. paraloc[callerside].init;
  1368. if vo_has_explicit_paraloc in varoptions then
  1369. begin
  1370. b:=ppufile.getbyte;
  1371. if b<>sizeof(paraloc[callerside].location^) then
  1372. internalerror(200411154);
  1373. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1374. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1375. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1376. end;
  1377. end;
  1378. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1379. begin
  1380. inherited ppuwrite(ppufile);
  1381. ppufile.putword(paranr);
  1382. if vo_has_explicit_paraloc in varoptions then
  1383. begin
  1384. paraloc[callerside].check_simple_location;
  1385. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1386. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1387. end;
  1388. ppufile.writeentry(ibparavarsym);
  1389. end;
  1390. {****************************************************************************
  1391. TABSOLUTEVARSYM
  1392. ****************************************************************************}
  1393. constructor tabsolutevarsym.create(const n : string;const tt : ttype);
  1394. begin
  1395. inherited create(absolutevarsym,n,vs_value,tt,[]);
  1396. ref:=nil;
  1397. end;
  1398. constructor tabsolutevarsym.create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  1399. begin
  1400. inherited create(absolutevarsym,n,vs_value,tt,[]);
  1401. ref:=_ref;
  1402. end;
  1403. destructor tabsolutevarsym.destroy;
  1404. begin
  1405. if assigned(ref) then
  1406. ref.free;
  1407. inherited destroy;
  1408. end;
  1409. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1410. begin
  1411. inherited ppuload(absolutevarsym,ppufile);
  1412. ref:=nil;
  1413. asmname:=nil;
  1414. abstyp:=absolutetyp(ppufile.getbyte);
  1415. {$ifdef i386}
  1416. absseg:=false;
  1417. {$endif i386}
  1418. case abstyp of
  1419. tovar :
  1420. ref:=ppufile.getsymlist;
  1421. toasm :
  1422. asmname:=stringdup(ppufile.getstring);
  1423. toaddr :
  1424. begin
  1425. addroffset:=ppufile.getaint;
  1426. {$ifdef i386}
  1427. absseg:=boolean(ppufile.getbyte);
  1428. {$endif i386}
  1429. end;
  1430. end;
  1431. end;
  1432. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1433. begin
  1434. inherited ppuwrite(ppufile);
  1435. ppufile.putbyte(byte(abstyp));
  1436. case abstyp of
  1437. tovar :
  1438. ppufile.putsymlist(ref);
  1439. toasm :
  1440. ppufile.putstring(asmname^);
  1441. toaddr :
  1442. begin
  1443. ppufile.putaint(addroffset);
  1444. {$ifdef i386}
  1445. ppufile.putbyte(byte(absseg));
  1446. {$endif i386}
  1447. end;
  1448. end;
  1449. ppufile.writeentry(ibabsolutevarsym);
  1450. end;
  1451. procedure tabsolutevarsym.buildderef;
  1452. begin
  1453. inherited buildderef;
  1454. if (abstyp=tovar) then
  1455. ref.buildderef;
  1456. end;
  1457. procedure tabsolutevarsym.deref;
  1458. begin
  1459. inherited deref;
  1460. { own absolute deref }
  1461. if (abstyp=tovar) then
  1462. ref.resolve;
  1463. end;
  1464. function tabsolutevarsym.mangledname : string;
  1465. begin
  1466. case abstyp of
  1467. toasm :
  1468. mangledname:=asmname^;
  1469. toaddr :
  1470. mangledname:='$'+tostr(addroffset);
  1471. else
  1472. internalerror(200411061);
  1473. end;
  1474. end;
  1475. {****************************************************************************
  1476. TTYPEDCONSTSYM
  1477. *****************************************************************************}
  1478. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1479. begin
  1480. inherited create(typedconstsym,n);
  1481. typedconsttype.setdef(p);
  1482. is_writable:=writable;
  1483. end;
  1484. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1485. begin
  1486. inherited create(typedconstsym,n);
  1487. typedconsttype:=tt;
  1488. is_writable:=writable;
  1489. end;
  1490. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1491. begin
  1492. inherited ppuload(typedconstsym,ppufile);
  1493. ppufile.gettype(typedconsttype);
  1494. is_writable:=boolean(ppufile.getbyte);
  1495. end;
  1496. destructor ttypedconstsym.destroy;
  1497. begin
  1498. if assigned(_mangledname) then
  1499. begin
  1500. {$ifdef MEMDEBUG}
  1501. memmanglednames.start;
  1502. {$endif MEMDEBUG}
  1503. stringdispose(_mangledname);
  1504. {$ifdef MEMDEBUG}
  1505. memmanglednames.stop;
  1506. {$endif MEMDEBUG}
  1507. end;
  1508. inherited destroy;
  1509. end;
  1510. function ttypedconstsym.mangledname:string;
  1511. begin
  1512. if not assigned(_mangledname) then
  1513. begin
  1514. {$ifdef compress}
  1515. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1516. {$else}
  1517. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1518. {$endif}
  1519. end;
  1520. result:=_mangledname^;
  1521. end;
  1522. function ttypedconstsym.getsize : longint;
  1523. begin
  1524. if assigned(typedconsttype.def) then
  1525. getsize:=typedconsttype.def.size
  1526. else
  1527. getsize:=0;
  1528. end;
  1529. procedure ttypedconstsym.buildderef;
  1530. begin
  1531. typedconsttype.buildderef;
  1532. end;
  1533. procedure ttypedconstsym.deref;
  1534. begin
  1535. typedconsttype.resolve;
  1536. end;
  1537. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1538. begin
  1539. inherited ppuwrite(ppufile);
  1540. ppufile.puttype(typedconsttype);
  1541. ppufile.putbyte(byte(is_writable));
  1542. ppufile.writeentry(ibtypedconstsym);
  1543. end;
  1544. {****************************************************************************
  1545. TCONSTSYM
  1546. ****************************************************************************}
  1547. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1548. begin
  1549. inherited create(constsym,n);
  1550. fillchar(value, sizeof(value), #0);
  1551. consttyp:=t;
  1552. value.valueord:=v;
  1553. ResStrIndex:=0;
  1554. consttype:=tt;
  1555. end;
  1556. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1557. begin
  1558. inherited create(constsym,n);
  1559. fillchar(value, sizeof(value), #0);
  1560. consttyp:=t;
  1561. value.valueordptr:=v;
  1562. ResStrIndex:=0;
  1563. consttype:=tt;
  1564. end;
  1565. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1566. begin
  1567. inherited create(constsym,n);
  1568. fillchar(value, sizeof(value), #0);
  1569. consttyp:=t;
  1570. value.valueptr:=v;
  1571. ResStrIndex:=0;
  1572. consttype:=tt;
  1573. end;
  1574. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1575. begin
  1576. inherited create(constsym,n);
  1577. fillchar(value, sizeof(value), #0);
  1578. consttyp:=t;
  1579. value.valueptr:=str;
  1580. consttype.reset;
  1581. value.len:=l;
  1582. if t=constresourcestring then
  1583. ResStrIndex:=resourcestrings.Register(name,pchar(value.valueptr),value.len);
  1584. end;
  1585. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1586. begin
  1587. inherited create(constsym,n);
  1588. fillchar(value, sizeof(value), #0);
  1589. consttyp:=t;
  1590. pcompilerwidestring(value.valueptr):=pw;
  1591. consttype.reset;
  1592. value.len:=getlengthwidestring(pw);
  1593. end;
  1594. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1595. var
  1596. pd : pbestreal;
  1597. ps : pnormalset;
  1598. pc : pchar;
  1599. pw : pcompilerwidestring;
  1600. begin
  1601. inherited ppuload(constsym,ppufile);
  1602. consttype.reset;
  1603. consttyp:=tconsttyp(ppufile.getbyte);
  1604. fillchar(value, sizeof(value), #0);
  1605. case consttyp of
  1606. constord :
  1607. begin
  1608. ppufile.gettype(consttype);
  1609. value.valueord:=ppufile.getexprint;
  1610. end;
  1611. constpointer :
  1612. begin
  1613. ppufile.gettype(consttype);
  1614. value.valueordptr:=ppufile.getptruint;
  1615. end;
  1616. constwstring :
  1617. begin
  1618. initwidestring(pw);
  1619. setlengthwidestring(pw,ppufile.getlongint);
  1620. ppufile.getdata(pw^.data,pw^.len*sizeof(tcompilerwidechar));
  1621. pcompilerwidestring(value.valueptr):=pw;
  1622. end;
  1623. conststring,
  1624. constresourcestring :
  1625. begin
  1626. value.len:=ppufile.getlongint;
  1627. getmem(pc,value.len+1);
  1628. ppufile.getdata(pc^,value.len);
  1629. if consttyp=constresourcestring then
  1630. ResStrIndex:=ppufile.getlongint;
  1631. value.valueptr:=pc;
  1632. end;
  1633. constreal :
  1634. begin
  1635. new(pd);
  1636. pd^:=ppufile.getreal;
  1637. value.valueptr:=pd;
  1638. end;
  1639. constset :
  1640. begin
  1641. ppufile.gettype(consttype);
  1642. new(ps);
  1643. ppufile.getnormalset(ps^);
  1644. value.valueptr:=ps;
  1645. end;
  1646. constguid :
  1647. begin
  1648. new(pguid(value.valueptr));
  1649. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1650. end;
  1651. constnil : ;
  1652. else
  1653. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1654. end;
  1655. end;
  1656. destructor tconstsym.destroy;
  1657. begin
  1658. case consttyp of
  1659. conststring,
  1660. constresourcestring :
  1661. freemem(pchar(value.valueptr),value.len+1);
  1662. constwstring :
  1663. donewidestring(pcompilerwidestring(value.valueptr));
  1664. constreal :
  1665. dispose(pbestreal(value.valueptr));
  1666. constset :
  1667. dispose(pnormalset(value.valueptr));
  1668. constguid :
  1669. dispose(pguid(value.valueptr));
  1670. end;
  1671. inherited destroy;
  1672. end;
  1673. procedure tconstsym.buildderef;
  1674. begin
  1675. if consttyp in [constord,constpointer,constset] then
  1676. consttype.buildderef;
  1677. end;
  1678. procedure tconstsym.deref;
  1679. begin
  1680. if consttyp in [constord,constpointer,constset] then
  1681. consttype.resolve;
  1682. end;
  1683. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1684. begin
  1685. inherited ppuwrite(ppufile);
  1686. ppufile.putbyte(byte(consttyp));
  1687. case consttyp of
  1688. constnil : ;
  1689. constord :
  1690. begin
  1691. ppufile.puttype(consttype);
  1692. ppufile.putexprint(value.valueord);
  1693. end;
  1694. constpointer :
  1695. begin
  1696. ppufile.puttype(consttype);
  1697. ppufile.putptruint(value.valueordptr);
  1698. end;
  1699. constwstring :
  1700. begin
  1701. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  1702. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  1703. end;
  1704. conststring,
  1705. constresourcestring :
  1706. begin
  1707. ppufile.putlongint(value.len);
  1708. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1709. if consttyp=constresourcestring then
  1710. ppufile.putlongint(ResStrIndex);
  1711. end;
  1712. constreal :
  1713. ppufile.putreal(pbestreal(value.valueptr)^);
  1714. constset :
  1715. begin
  1716. ppufile.puttype(consttype);
  1717. ppufile.putnormalset(value.valueptr^);
  1718. end;
  1719. constguid :
  1720. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1721. else
  1722. internalerror(13);
  1723. end;
  1724. ppufile.writeentry(ibconstsym);
  1725. end;
  1726. {****************************************************************************
  1727. TENUMSYM
  1728. ****************************************************************************}
  1729. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1730. begin
  1731. inherited create(enumsym,n);
  1732. definition:=def;
  1733. value:=v;
  1734. { First entry? Then we need to set the minval }
  1735. if def.firstenum=nil then
  1736. begin
  1737. if v>0 then
  1738. def.has_jumps:=true;
  1739. def.setmin(v);
  1740. def.setmax(v);
  1741. end
  1742. else
  1743. begin
  1744. { check for jumps }
  1745. if v>def.max+1 then
  1746. def.has_jumps:=true;
  1747. { update low and high }
  1748. if def.min>v then
  1749. def.setmin(v);
  1750. if def.max<v then
  1751. def.setmax(v);
  1752. end;
  1753. order;
  1754. end;
  1755. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1756. begin
  1757. inherited ppuload(enumsym,ppufile);
  1758. ppufile.getderef(definitionderef);
  1759. value:=ppufile.getlongint;
  1760. nextenum := Nil;
  1761. end;
  1762. procedure tenumsym.buildderef;
  1763. begin
  1764. definitionderef.build(definition);
  1765. end;
  1766. procedure tenumsym.deref;
  1767. begin
  1768. definition:=tenumdef(definitionderef.resolve);
  1769. order;
  1770. end;
  1771. procedure tenumsym.order;
  1772. var
  1773. sym : tenumsym;
  1774. begin
  1775. sym := tenumsym(definition.firstenum);
  1776. if sym = nil then
  1777. begin
  1778. definition.firstenum := self;
  1779. nextenum := nil;
  1780. exit;
  1781. end;
  1782. { reorder the symbols in increasing value }
  1783. if value < sym.value then
  1784. begin
  1785. nextenum := sym;
  1786. definition.firstenum := self;
  1787. end
  1788. else
  1789. begin
  1790. while (sym.value <= value) and assigned(sym.nextenum) do
  1791. sym := sym.nextenum;
  1792. nextenum := sym.nextenum;
  1793. sym.nextenum := self;
  1794. end;
  1795. end;
  1796. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1797. begin
  1798. inherited ppuwrite(ppufile);
  1799. ppufile.putderef(definitionderef);
  1800. ppufile.putlongint(value);
  1801. ppufile.writeentry(ibenumsym);
  1802. end;
  1803. {****************************************************************************
  1804. TTYPESYM
  1805. ****************************************************************************}
  1806. constructor ttypesym.create(const n : string;const tt : ttype);
  1807. begin
  1808. inherited create(typesym,n);
  1809. restype:=tt;
  1810. { register the typesym for the definition }
  1811. if assigned(restype.def) and
  1812. (restype.def.deftype<>errordef) and
  1813. not(assigned(restype.def.typesym)) then
  1814. restype.def.typesym:=self;
  1815. end;
  1816. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1817. begin
  1818. inherited ppuload(typesym,ppufile);
  1819. ppufile.gettype(restype);
  1820. end;
  1821. function ttypesym.gettypedef:tdef;
  1822. begin
  1823. gettypedef:=restype.def;
  1824. end;
  1825. procedure ttypesym.buildderef;
  1826. begin
  1827. restype.buildderef;
  1828. end;
  1829. procedure ttypesym.deref;
  1830. begin
  1831. restype.resolve;
  1832. end;
  1833. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1834. begin
  1835. inherited ppuwrite(ppufile);
  1836. ppufile.puttype(restype);
  1837. ppufile.writeentry(ibtypesym);
  1838. end;
  1839. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1840. begin
  1841. inherited load_references(ppufile,locals);
  1842. if (restype.def.deftype=recorddef) then
  1843. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1844. if (restype.def.deftype=objectdef) then
  1845. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1846. end;
  1847. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1848. var
  1849. d : tderef;
  1850. begin
  1851. d.reset;
  1852. if not inherited write_references(ppufile,locals) then
  1853. begin
  1854. { write address of this symbol if record or object
  1855. even if no real refs are there
  1856. because we need it for the symtable }
  1857. if (restype.def.deftype in [recorddef,objectdef]) then
  1858. begin
  1859. d.build(self);
  1860. ppufile.putderef(d);
  1861. ppufile.writeentry(ibsymref);
  1862. end;
  1863. end;
  1864. write_references:=true;
  1865. if (restype.def.deftype=recorddef) then
  1866. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  1867. if (restype.def.deftype=objectdef) then
  1868. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  1869. end;
  1870. {****************************************************************************
  1871. TSYSSYM
  1872. ****************************************************************************}
  1873. constructor tsyssym.create(const n : string;l : longint);
  1874. begin
  1875. inherited create(syssym,n);
  1876. number:=l;
  1877. end;
  1878. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1879. begin
  1880. inherited ppuload(syssym,ppufile);
  1881. number:=ppufile.getlongint;
  1882. end;
  1883. destructor tsyssym.destroy;
  1884. begin
  1885. inherited destroy;
  1886. end;
  1887. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1888. begin
  1889. inherited ppuwrite(ppufile);
  1890. ppufile.putlongint(number);
  1891. ppufile.writeentry(ibsyssym);
  1892. end;
  1893. {*****************************************************************************
  1894. TMacro
  1895. *****************************************************************************}
  1896. constructor tmacro.create(const n : string);
  1897. begin
  1898. inherited create(macrosym,n);
  1899. owner:=nil;
  1900. defined:=false;
  1901. is_used:=false;
  1902. is_compiler_var:=false;
  1903. buftext:=nil;
  1904. buflen:=0;
  1905. end;
  1906. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  1907. begin
  1908. inherited ppuload(macrosym,ppufile);
  1909. name:=ppufile.getstring;
  1910. defined:=boolean(ppufile.getbyte);
  1911. is_compiler_var:=boolean(ppufile.getbyte);
  1912. is_used:=false;
  1913. buflen:= ppufile.getlongint;
  1914. if buflen > 0 then
  1915. begin
  1916. getmem(buftext, buflen);
  1917. ppufile.getdata(buftext^, buflen)
  1918. end
  1919. else
  1920. buftext:=nil;
  1921. end;
  1922. destructor tmacro.destroy;
  1923. begin
  1924. if assigned(buftext) then
  1925. freemem(buftext);
  1926. inherited destroy;
  1927. end;
  1928. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  1929. begin
  1930. inherited ppuwrite(ppufile);
  1931. ppufile.putstring(name);
  1932. ppufile.putbyte(byte(defined));
  1933. ppufile.putbyte(byte(is_compiler_var));
  1934. ppufile.putlongint(buflen);
  1935. if buflen > 0 then
  1936. ppufile.putdata(buftext^,buflen);
  1937. ppufile.writeentry(ibmacrosym);
  1938. end;
  1939. function tmacro.GetCopy:tmacro;
  1940. var
  1941. p : tmacro;
  1942. begin
  1943. p:=tmacro.create(realname);
  1944. p.defined:=defined;
  1945. p.is_used:=is_used;
  1946. p.is_compiler_var:=is_compiler_var;
  1947. p.buflen:=buflen;
  1948. if assigned(buftext) then
  1949. begin
  1950. getmem(p.buftext,buflen);
  1951. move(buftext^,p.buftext^,buflen);
  1952. end;
  1953. Result:=p;
  1954. end;
  1955. {****************************************************************************
  1956. TRTTISYM
  1957. ****************************************************************************}
  1958. constructor trttisym.create(const n:string;rt:trttitype);
  1959. const
  1960. prefix : array[trttitype] of string[5]=('$rtti','$init');
  1961. begin
  1962. inherited create(rttisym,prefix[rt]+n);
  1963. include(symoptions,sp_internal);
  1964. lab:=nil;
  1965. rttityp:=rt;
  1966. end;
  1967. destructor trttisym.destroy;
  1968. begin
  1969. if assigned(_mangledname) then
  1970. begin
  1971. {$ifdef MEMDEBUG}
  1972. memmanglednames.start;
  1973. {$endif MEMDEBUG}
  1974. stringdispose(_mangledname);
  1975. {$ifdef MEMDEBUG}
  1976. memmanglednames.stop;
  1977. {$endif MEMDEBUG}
  1978. end;
  1979. inherited destroy;
  1980. end;
  1981. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  1982. begin
  1983. inherited ppuload(rttisym,ppufile);
  1984. lab:=nil;
  1985. rttityp:=trttitype(ppufile.getbyte);
  1986. end;
  1987. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  1988. begin
  1989. inherited ppuwrite(ppufile);
  1990. ppufile.putbyte(byte(rttityp));
  1991. ppufile.writeentry(ibrttisym);
  1992. end;
  1993. function trttisym.mangledname : string;
  1994. const
  1995. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  1996. begin
  1997. if not assigned(_mangledname) then
  1998. _mangledname:=stringdup(make_mangledname(prefix[rttityp],owner,Copy(name,5,255)));
  1999. result:=_mangledname^;
  2000. end;
  2001. function trttisym.get_label:tasmsymbol;
  2002. begin
  2003. { the label is always a global label }
  2004. if not assigned(lab) then
  2005. lab:=current_asmdata.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA);
  2006. get_label:=lab;
  2007. end;
  2008. end.