symsym.pas 70 KB

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