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