symsym.pas 65 KB

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