symsym.pas 69 KB

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