symsym.pas 70 KB

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