symsym.pas 67 KB

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