symsym.inc 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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. {****************************************************************************
  19. TSYM (base for all symtypes)
  20. ****************************************************************************}
  21. constructor tsym.init(const n : string);
  22. begin
  23. left:=nil;
  24. right:=nil;
  25. setname(n);
  26. typ:=abstractsym;
  27. properties:=current_object_option;
  28. {$ifdef GDB}
  29. isstabwritten := false;
  30. {$endif GDB}
  31. if assigned(current_module) and assigned(current_module^.current_inputfile) then
  32. line_no:=current_module^.current_inputfile^.line_no
  33. else
  34. line_no:=0;
  35. {$ifdef UseBrowser}
  36. defref:=nil;
  37. lastwritten:=nil;
  38. if make_ref then
  39. add_new_ref(defref,@tokenpos);
  40. lastref:=defref;
  41. refcount:=1;
  42. {$endif UseBrowser}
  43. end;
  44. constructor tsym.load;
  45. begin
  46. left:=nil;
  47. right:=nil;
  48. setname(readstring);
  49. typ:=abstractsym;
  50. if object_options then
  51. properties:=symprop(readbyte)
  52. else
  53. properties:=sp_public;
  54. {$ifdef UseBrowser}
  55. lastref:=nil;
  56. defref:=nil;
  57. lastwritten:=nil;
  58. refcount:=0;
  59. if (current_module^.flags and uf_uses_browser)<>0 then
  60. { references do not change the ppu caracteristics }
  61. { this only save the references to variables/functions }
  62. { defined in the unit what about the others }
  63. load_references;
  64. {$endif UseBrowser}
  65. {$ifdef GDB}
  66. isstabwritten := false;
  67. {$endif GDB}
  68. line_no:=0;
  69. end;
  70. {$ifdef UseBrowser}
  71. {$ifdef NEWPPU}
  72. procedure tsym.load_references;
  73. var
  74. fileindex : word;
  75. b : byte;
  76. l,c : longint;
  77. begin
  78. b:=readentry;
  79. if b=ibref then
  80. begin
  81. while (not ppufile^.endofentry) do
  82. begin
  83. fileindex:=readword;
  84. l:=readlong;
  85. c:=readword;
  86. inc(refcount);
  87. lastref:=new(pref,load(lastref,fileindex,l,c));
  88. if refcount=1 then
  89. defref:=lastref;
  90. end;
  91. end
  92. else
  93. Message(unit_f_ppu_read_error);
  94. lastwritten:=lastref;
  95. end;
  96. procedure tsym.write_references;
  97. var
  98. ref : pref;
  99. begin
  100. { references do not change the ppu caracteristics }
  101. { this only save the references to variables/functions }
  102. { defined in the unit what about the others }
  103. ppufile^.do_crc:=false;
  104. if assigned(lastwritten) then
  105. ref:=lastwritten
  106. else
  107. ref:=defref;
  108. while assigned(ref) do
  109. begin
  110. writeposinfo(ref^.posinfo);
  111. ref:=ref^.nextref;
  112. end;
  113. lastwritten:=lastref;
  114. ppufile^.writeentry(ibref);
  115. ppufile^.do_crc:=true;
  116. end;
  117. procedure load_external_references;
  118. var b : byte;
  119. sym : psym;
  120. prdef : pdef;
  121. begin
  122. b:=readentry;
  123. if b=ibextsymref then
  124. begin
  125. sym:=readsymref;
  126. resolvesym(sym);
  127. sym^.load_references;
  128. end;
  129. ibextdefref : begin
  130. prdef:=readdefref;
  131. resolvedef(prdef);
  132. if prdef^.deftype<>procdef then
  133. Message(unit_f_ppu_read_error);
  134. pprocdef(prdef)^.load_references;
  135. end;
  136. else
  137. Message(unit_f_ppu_read_error);
  138. end;
  139. end;
  140. procedure tsym.write_external_references;
  141. var ref : pref;
  142. prdef : pdef;
  143. begin
  144. ppufile^.do_crc:=false;
  145. if lastwritten=lastref then
  146. exit;
  147. writesymref(@self);
  148. writeentry(ibextsymref);
  149. write_references;
  150. if typ=procsym then
  151. begin
  152. prdef:=pprocsym(@self)^.definition;
  153. while assigned(prdef) do
  154. begin
  155. pprocdef(prdef)^.write_external_references;
  156. prdef:=pprocdef(prdef)^.nextoverloaded;
  157. end;
  158. end;
  159. ppufile^.do_crc:=true;
  160. end;
  161. {$else NEWPPU}
  162. procedure tsym.load_references;
  163. var fileindex : word;
  164. b : byte;
  165. l,c : longint;
  166. begin
  167. b:=readbyte;
  168. while b=ibref do
  169. begin
  170. fileindex:=readword;
  171. l:=readlong;
  172. c:=readword;
  173. inc(refcount);
  174. lastref:=new(pref,load(lastref,fileindex,l,c));
  175. if refcount=1 then defref:=lastref;
  176. b:=readbyte;
  177. end;
  178. lastwritten:=lastref;
  179. if b <> ibend then
  180. Message(unit_f_ppu_read_error);
  181. end;
  182. procedure tsym.write_references;
  183. var ref : pref;
  184. begin
  185. { references do not change the ppu caracteristics }
  186. { this only save the references to variables/functions }
  187. { defined in the unit what about the others }
  188. ppufile^.do_crc:=false;
  189. if assigned(lastwritten) then
  190. ref:=lastwritten
  191. else
  192. ref:=defref;
  193. while assigned(ref) do
  194. begin
  195. writebyte(ibref);
  196. writeword(ref^.posinfo.fileindex);
  197. writelong(ref^.posinfo.line);
  198. writeword(ref^.posinfo.column);
  199. ref:=ref^.nextref;
  200. end;
  201. lastwritten:=lastref;
  202. writebyte(ibend);
  203. ppufile^.do_crc:=true;
  204. end;
  205. procedure load_external_references;
  206. var b : byte;
  207. sym : psym;
  208. prdef : pdef;
  209. begin
  210. b:=readbyte;
  211. while (b=ibextsymref) or (b=ibextdefref) do
  212. begin
  213. if b=ibextsymref then
  214. begin
  215. sym:=readsymref;
  216. resolvesym(sym);
  217. sym^.load_references;
  218. b:=readbyte;
  219. end
  220. else
  221. if b=ibextdefref then
  222. begin
  223. prdef:=readdefref;
  224. resolvedef(prdef);
  225. if prdef^.deftype<>procdef then
  226. Message(unit_f_ppu_read_error);
  227. pprocdef(prdef)^.load_references;
  228. b:=readbyte;
  229. end;
  230. end;
  231. if b <> ibend then
  232. Message(unit_f_ppu_read_error);
  233. end;
  234. procedure tsym.write_external_references;
  235. var ref : pref;
  236. prdef : pdef;
  237. begin
  238. ppufile^.do_crc:=false;
  239. if lastwritten=lastref then
  240. exit;
  241. writebyte(ibextsymref);
  242. writesymref(@self);
  243. if assigned(lastwritten) then
  244. ref:=lastwritten
  245. else
  246. ref:=defref;
  247. while assigned(ref) do
  248. begin
  249. writebyte(ibref);
  250. writeword(ref^.posinfo.fileindex);
  251. writelong(ref^.posinfo.line);
  252. writeword(ref^.posinfo.column);
  253. ref:=ref^.nextref;
  254. end;
  255. lastwritten:=lastref;
  256. writebyte(ibend);
  257. if typ=procsym then
  258. begin
  259. prdef:=pprocsym(@self)^.definition;
  260. while assigned(prdef) do
  261. begin
  262. pprocdef(prdef)^.write_external_references;
  263. prdef:=pprocdef(prdef)^.nextoverloaded;
  264. end;
  265. end;
  266. ppufile^.do_crc:=true;
  267. end;
  268. {$endif NEWPPU}
  269. procedure tsym.write_ref_to_file(var f : text);
  270. var ref : pref;
  271. i : longint;
  272. begin
  273. ref:=defref;
  274. if assigned(ref) then
  275. begin
  276. for i:=1 to reffile_indent do
  277. system.write(f,' ');
  278. writeln(f,'***',name,'***');
  279. end;
  280. inc(reffile_indent,2);
  281. while assigned(ref) do
  282. begin
  283. for i:=1 to reffile_indent do
  284. system.write(f,' ');
  285. writeln(f,ref^.get_file_line);
  286. ref:=ref^.nextref;
  287. end;
  288. dec(reffile_indent,2);
  289. end;
  290. {$endif UseBrowser}
  291. destructor tsym.done;
  292. begin
  293. {$ifdef tp}
  294. if not(use_big) then
  295. {$endif tp}
  296. strdispose(_name);
  297. if assigned(left) then dispose(left,done);
  298. if assigned(right) then dispose(right,done);
  299. end;
  300. destructor tsym.single_done;
  301. begin
  302. {$ifdef tp}
  303. if not(use_big) then
  304. {$endif tp}
  305. strdispose(_name);
  306. end;
  307. procedure tsym.write;
  308. begin
  309. writestring(name);
  310. if object_options then
  311. writebyte(byte(properties));
  312. {$ifdef UseBrowser}
  313. if (current_module^.flags and uf_uses_browser)<>0 then
  314. write_references;
  315. {$endif UseBrowser}
  316. end;
  317. procedure tsym.deref;
  318. begin
  319. end;
  320. function tsym.name : string;
  321. {$ifdef tp}
  322. var
  323. s : string;
  324. b : byte;
  325. {$endif}
  326. begin
  327. {$ifdef tp}
  328. if use_big then
  329. begin
  330. symbolstream.seek(longint(_name));
  331. symbolstream.read(b,1);
  332. symbolstream.read(s[1],b);
  333. s[0]:=chr(b);
  334. name:=s;
  335. end
  336. else
  337. {$endif}
  338. if assigned(_name) then
  339. name:=strpas(_name)
  340. else
  341. name:='';
  342. end;
  343. function tsym.mangledname : string;
  344. begin
  345. mangledname:=name;
  346. end;
  347. procedure tsym.setname(const s : string);
  348. begin
  349. setstring(_name,s);
  350. end;
  351. { for most symbol types ther is nothing to do at all }
  352. procedure tsym.insert_in_data;
  353. begin
  354. end;
  355. {$ifdef GDB}
  356. function tsym.stabstring : pchar;
  357. begin
  358. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+tostr(line_no)+',0');
  359. end;
  360. procedure tsym.concatstabto(asmlist : paasmoutput);
  361. var stab_str : pchar;
  362. begin
  363. if not isstabwritten then
  364. begin
  365. stab_str := stabstring;
  366. if asmlist = debuglist then do_count_dbx := true;
  367. { count_dbx(stab_str); moved to GDB.PAS }
  368. asmlist^.concat(new(pai_stabs,init(stab_str)));
  369. isstabwritten:=true;
  370. end;
  371. end;
  372. {$endif GDB}
  373. {****************************************************************************
  374. TLABELSYM
  375. ****************************************************************************}
  376. constructor tlabelsym.init(const n : string; l : plabel);
  377. begin
  378. inherited init(n);
  379. typ:=labelsym;
  380. number:=l;
  381. number^.is_used:=false;
  382. number^.is_set:=true;
  383. number^.refcount:=0;
  384. defined:=false;
  385. end;
  386. destructor tlabelsym.done;
  387. begin
  388. if not(defined) then
  389. Message1(sym_e_label_not_defined,name);
  390. inherited done;
  391. end;
  392. function tlabelsym.mangledname : string;
  393. begin
  394. { this also sets the is_used field }
  395. mangledname:=lab2str(number);
  396. end;
  397. procedure tlabelsym.write;
  398. begin
  399. Message(sym_e_ill_label_decl);
  400. end;
  401. {****************************************************************************
  402. TUNITSYM
  403. ****************************************************************************}
  404. constructor tunitsym.init(const n : string;ref : punitsymtable);
  405. begin
  406. tsym.init(n);
  407. typ:=unitsym;
  408. unitsymtable:=ref;
  409. prevsym:=ref^.unitsym;
  410. ref^.unitsym:=@self;
  411. refs:=0;
  412. end;
  413. destructor tunitsym.done;
  414. begin
  415. if assigned(unitsymtable) and (unitsymtable^.unitsym=@self) then
  416. unitsymtable^.unitsym:=prevsym;
  417. inherited done;
  418. end;
  419. procedure tunitsym.write;
  420. begin
  421. end;
  422. {$ifdef GDB}
  423. procedure tunitsym.concatstabto(asmlist : paasmoutput);
  424. begin
  425. {Nothing to write to stabs !}
  426. end;
  427. {$endif GDB}
  428. {****************************************************************************
  429. TPROCSYM
  430. ****************************************************************************}
  431. constructor tprocsym.init(const n : string);
  432. begin
  433. tsym.init(n);
  434. typ:=procsym;
  435. definition:=nil;
  436. owner:=nil;
  437. {$ifdef GDB}
  438. is_global := false;
  439. {$endif GDB}
  440. end;
  441. constructor tprocsym.load;
  442. begin
  443. tsym.load;
  444. typ:=procsym;
  445. definition:=pprocdef(readdefref);
  446. {$ifdef GDB}
  447. is_global := false;
  448. {$endif GDB}
  449. end;
  450. destructor tprocsym.done;
  451. begin
  452. check_forward;
  453. tsym.done;
  454. end;
  455. function tprocsym.mangledname : string;
  456. begin
  457. mangledname:=definition^.mangledname;
  458. end;
  459. function tprocsym.demangledname:string;
  460. begin
  461. demangledname:=name+definition^.demangled_paras;
  462. end;
  463. procedure tprocsym.check_forward;
  464. var
  465. pd : pprocdef;
  466. begin
  467. pd:=definition;
  468. while assigned(pd) do
  469. begin
  470. if pd^.forwarddef then
  471. begin
  472. {$ifdef GDB}
  473. if assigned(pd^._class) then
  474. Message1(sym_e_forward_not_resolved,pd^._class^.name^+'.'+name+demangledparas(pd^.demangled_paras))
  475. else
  476. {$endif GDB}
  477. Message1(sym_e_forward_not_resolved,name+pd^.demangled_paras)
  478. end;
  479. pd:=pd^.nextoverloaded;
  480. end;
  481. end;
  482. procedure tprocsym.deref;
  483. var t : ttoken;
  484. begin
  485. resolvedef(pdef(definition));
  486. for t:=PLUS to last_overloaded do
  487. if (overloaded_operators[t]=nil) and
  488. (name=overloaded_names[t]) then
  489. overloaded_operators[t]:=@self;
  490. end;
  491. procedure tprocsym.write;
  492. begin
  493. {$ifndef NEWPPU}
  494. writebyte(ibprocsym);
  495. {$endif}
  496. tsym.write;
  497. writedefref(pdef(definition));
  498. {$ifdef NEWPPU}
  499. ppufile^.writeentry(ibprocsym);
  500. {$endif}
  501. end;
  502. {$ifdef GDB}
  503. function tprocsym.stabstring : pchar;
  504. Var RetType : Char;
  505. Obj,Info : String;
  506. begin
  507. obj := name;
  508. info := '';
  509. if is_global then
  510. RetType := 'F'
  511. else
  512. RetType := 'f';
  513. if assigned(owner) then
  514. begin
  515. if (owner^.symtabletype = objectsymtable) then
  516. obj := owner^.name^+'__'+name;
  517. if (owner^.symtabletype=localsymtable) and assigned(owner^.name) then
  518. info := ','+name+','+owner^.name^;
  519. end;
  520. stabstring :=strpnew('"'+obj+':'+RetType
  521. +definition^.retdef^.numberstring+info+'",'+tostr(n_function)
  522. +',0,'+tostr(current_module^.current_inputfile^.line_no)
  523. +','+definition^.mangledname);
  524. end;
  525. procedure tprocsym.concatstabto(asmlist : paasmoutput);
  526. begin
  527. if (definition^.options and pointernproc) <> 0 then exit;
  528. if not isstabwritten then
  529. asmlist^.concat(new(pai_stabs,init(stabstring)));
  530. isstabwritten := true;
  531. if assigned(definition^.parast) then
  532. definition^.parast^.concatstabto(asmlist);
  533. if assigned(definition^.localst) then
  534. definition^.localst^.concatstabto(asmlist);
  535. definition^.is_def_stab_written := true;
  536. end;
  537. {$endif GDB}
  538. {****************************************************************************
  539. TPROGRAMSYM
  540. ****************************************************************************}
  541. constructor tprogramsym.init(const n : string);
  542. begin
  543. tsym.init(n);
  544. typ:=programsym;
  545. end;
  546. {****************************************************************************
  547. TERRORSYM
  548. ****************************************************************************}
  549. constructor terrorsym.init;
  550. begin
  551. tsym.init('');
  552. typ:=errorsym;
  553. end;
  554. {****************************************************************************
  555. TPROPERTYSYM
  556. ****************************************************************************}
  557. constructor tpropertysym.init(const n : string);
  558. begin
  559. inherited init(n);
  560. typ:=propertysym;
  561. options:=0;
  562. proptype:=nil;
  563. readaccessdef:=nil;
  564. writeaccessdef:=nil;
  565. readaccesssym:=nil;
  566. writeaccesssym:=nil;
  567. index:=$0;
  568. end;
  569. destructor tpropertysym.done;
  570. begin
  571. inherited done;
  572. end;
  573. constructor tpropertysym.load;
  574. begin
  575. inherited load;
  576. typ:=propertysym;
  577. proptype:=readdefref;
  578. options:=readlong;
  579. index:=readlong;
  580. { it's hack ... }
  581. readaccesssym:=psym(stringdup(readstring));
  582. writeaccesssym:=psym(stringdup(readstring));
  583. { now the defs: }
  584. readaccessdef:=readdefref;
  585. writeaccessdef:=readdefref;
  586. end;
  587. procedure tpropertysym.deref;
  588. begin
  589. resolvedef(proptype);
  590. resolvedef(readaccessdef);
  591. resolvedef(writeaccessdef);
  592. { solve the hack we did in load: }
  593. if pstring(readaccesssym)^<>'' then
  594. begin
  595. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(readaccesssym)^);
  596. if not(assigned(srsym)) then
  597. srsym:=generrorsym;
  598. end
  599. else
  600. srsym:=nil;
  601. stringdispose(pstring(readaccesssym));
  602. readaccesssym:=srsym;
  603. if pstring(writeaccesssym)^<>'' then
  604. begin
  605. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(writeaccesssym)^);
  606. if not(assigned(srsym)) then
  607. srsym:=generrorsym;
  608. end
  609. else
  610. srsym:=nil;
  611. stringdispose(pstring(writeaccesssym));
  612. writeaccesssym:=srsym;
  613. end;
  614. function tpropertysym.getsize : longint;
  615. begin
  616. getsize:=0;
  617. end;
  618. procedure tpropertysym.write;
  619. begin
  620. {$ifndef NEWPPU}
  621. writebyte(ibpropertysym);
  622. {$endif}
  623. tsym.write;
  624. writedefref(proptype);
  625. writelong(options);
  626. writelong(index);
  627. if assigned(readaccesssym) then
  628. writestring(readaccesssym^.name)
  629. else
  630. writestring('');
  631. if assigned(writeaccesssym) then
  632. writestring(writeaccesssym^.name)
  633. else
  634. writestring('');
  635. writedefref(readaccessdef);
  636. writedefref(writeaccessdef);
  637. {$ifdef NEWPPU}
  638. ppufile^.writeentry(ibpropertysym);
  639. {$endif}
  640. end;
  641. {$ifdef GDB}
  642. function tpropertysym.stabstring : pchar;
  643. begin
  644. { !!!! don't know how to handle }
  645. stabstring:=strpnew('');
  646. end;
  647. procedure tpropertysym.concatstabto(asmlist : paasmoutput);
  648. begin
  649. { !!!! don't know how to handle }
  650. end;
  651. {$endif GDB}
  652. {****************************************************************************
  653. TFUNCRETSYM
  654. ****************************************************************************}
  655. {$ifdef TEST_FUNCRET}
  656. constructor tfuncretsym.init(const n : string;approcinfo : pointer{pprocinfo});
  657. begin
  658. tsym.init(n);
  659. funcretprocinfo:=approcinfo;
  660. funcretdef:=pprocinfo(approcinfo)^.retdef;
  661. { address valid for ret in param only }
  662. { otherwise set by insert }
  663. address:=pprocinfo(approcinfo)^.retoffset;
  664. end;
  665. {$endif TEST_FUNCRET}
  666. {****************************************************************************
  667. TABSOLUTESYM
  668. ****************************************************************************}
  669. { constructor tabsolutesym.init(const s : string;p : pdef;newref : psym);
  670. begin
  671. inherited init(s,p);
  672. ref:=newref;
  673. typ:=absolutesym;
  674. end; }
  675. constructor tabsolutesym.load;
  676. begin
  677. tvarsym.load;
  678. typ:=absolutesym;
  679. ref:=nil;
  680. address:=0;
  681. asmname:=nil;
  682. abstyp:=absolutetyp(readbyte);
  683. absseg:=false;
  684. case abstyp of
  685. tovar : begin
  686. asmname:=stringdup(readstring);
  687. ref:=srsym;
  688. end;
  689. toasm : asmname:=stringdup(readstring);
  690. toaddr : address:=readlong;
  691. end;
  692. end;
  693. procedure tabsolutesym.write;
  694. begin
  695. {$ifndef NEWPPU}
  696. writebyte(ibabsolutesym);
  697. {$endif}
  698. tsym.write;
  699. writebyte(byte(varspez));
  700. if read_member then
  701. writelong(address);
  702. writedefref(definition);
  703. writebyte(byte(abstyp));
  704. case abstyp of
  705. tovar : writestring(ref^.name);
  706. toasm : writestring(asmname^);
  707. toaddr : writelong(address);
  708. end;
  709. {$ifdef NEWPPU}
  710. ppufile^.writeentry(ibabsolutesym);
  711. {$endif}
  712. end;
  713. procedure tabsolutesym.deref;
  714. begin
  715. resolvedef(definition);
  716. if (abstyp=tovar) and (asmname<>nil) then
  717. begin
  718. { search previous loaded symtables }
  719. getsym(asmname^,false);
  720. if not(assigned(srsym)) then
  721. getsymonlyin(owner,asmname^);
  722. if not(assigned(srsym)) then
  723. srsym:=generrorsym;
  724. ref:=srsym;
  725. stringdispose(asmname);
  726. end;
  727. end;
  728. function tabsolutesym.mangledname : string;
  729. begin
  730. case abstyp of
  731. tovar : mangledname:=ref^.mangledname;
  732. toasm : mangledname:=asmname^;
  733. toaddr : mangledname:='$'+tostr(address);
  734. else
  735. internalerror(10002);
  736. end;
  737. end;
  738. procedure tabsolutesym.insert_in_data;
  739. begin
  740. end;
  741. {$ifdef GDB}
  742. procedure tabsolutesym.concatstabto(asmlist : paasmoutput);
  743. begin
  744. { I don't know how to handle this !! }
  745. end;
  746. {$endif GDB}
  747. {****************************************************************************
  748. TVARSYM
  749. ****************************************************************************}
  750. constructor tvarsym.init(const n : string;p : pdef);
  751. begin
  752. tsym.init(n);
  753. typ:=varsym;
  754. definition:=p;
  755. varspez:=vs_value;
  756. address:=0;
  757. refs:=0;
  758. is_valid := 1;
  759. { can we load the value into a register ? }
  760. case p^.deftype of
  761. pointerdef,
  762. enumdef,
  763. procvardef : regable:=true;
  764. orddef : case porddef(p)^.typ of
  765. u8bit,s32bit,
  766. bool8bit,uchar,
  767. s8bit,s16bit,
  768. u16bit,u32bit : regable:=true;
  769. else
  770. regable:=false;
  771. end;
  772. else
  773. regable:=false;
  774. end;
  775. reg:=R_NO;
  776. end;
  777. constructor tvarsym.load;
  778. begin
  779. tsym.load;
  780. typ:=varsym;
  781. varspez:=tvarspez(readbyte);
  782. if read_member then
  783. address:=readlong
  784. else address:=0;
  785. definition:=readdefref;
  786. refs := 0;
  787. is_valid := 1;
  788. { symbols which are load are never candidates for a register }
  789. regable:=false;
  790. reg:=R_NO;
  791. end;
  792. procedure tvarsym.deref;
  793. begin
  794. resolvedef(definition);
  795. end;
  796. procedure tvarsym.write;
  797. begin
  798. {$ifndef NEWPPU}
  799. writebyte(ibvarsym);
  800. {$endif}
  801. tsym.write;
  802. writebyte(byte(varspez));
  803. if read_member then
  804. writelong(address);
  805. writedefref(definition);
  806. {$ifdef NEWPPU}
  807. ppufile^.writeentry(ibvarsym);
  808. {$endif}
  809. end;
  810. function tvarsym.mangledname : string;
  811. var
  812. prefix : string;
  813. begin
  814. case owner^.symtabletype of
  815. staticsymtable : if (cs_smartlink in aktswitches) then
  816. prefix:='_'+owner^.name^+'$$$_'
  817. else
  818. prefix:='_';
  819. unitsymtable,
  820. globalsymtable : prefix:='U_'+owner^.name^+'_';
  821. else
  822. Message(sym_e_invalid_call_tvarsymmangledname);
  823. end;
  824. mangledname:=prefix+name;
  825. end;
  826. function tvarsym.getsize : longint;
  827. begin
  828. { only if the definition is set, we could determine the }
  829. { size, this is if an error occurs while reading the type }
  830. { also used for operator, this allows not to allocate the }
  831. { return size twice }
  832. if assigned(definition) then
  833. begin
  834. case varspez of
  835. vs_value : getsize:=definition^.size;
  836. vs_var : getsize:=sizeof(pointer);
  837. vs_const : begin
  838. if (definition^.deftype in [stringdef,arraydef,
  839. recorddef,objectdef,setdef]) then
  840. getsize:=sizeof(pointer)
  841. else
  842. getsize:=definition^.size;
  843. end;
  844. end;
  845. end
  846. else
  847. getsize:=0;
  848. end;
  849. procedure tvarsym.insert_in_data;
  850. var
  851. l,modulo : longint;
  852. begin
  853. { handle static variables of objects especially }
  854. if read_member and (owner^.symtabletype=objectsymtable) and
  855. ((properties and sp_static)<>0) then
  856. begin
  857. { the data filed is generated in parser.pas
  858. with a tobject_FIELDNAME variable }
  859. { this symbol can't be loaded to a register }
  860. regable:=false;
  861. end
  862. else if not(read_member) then
  863. begin
  864. { made problems with parameters etc. ! (FK) }
  865. { check for instance of an abstract object or class }
  866. {
  867. if (pvarsym(sym)^.definition^.deftype=objectdef) and
  868. ((pobjectdef(pvarsym(sym)^.definition)^.options and oois_abstract)<>0) then
  869. Message(sym_e_no_instance_of_abstract_object);
  870. }
  871. { bei einer lokalen Symboltabelle erst! erh”hen, da der }
  872. { Wert in codegen.secondload dann mit minus verwendet }
  873. { wird }
  874. l:=getsize;
  875. if owner^.symtabletype=localsymtable then
  876. begin
  877. is_valid := 0;
  878. modulo:=owner^.datasize and 3;
  879. {$ifdef m68k}
  880. { word alignment required for motorola }
  881. if (l=1) then
  882. l:=2
  883. else
  884. {$endif}
  885. if (l>=4) and (modulo<>0) then
  886. inc(l,4-modulo)
  887. else if (l>=2) and ((modulo and 1)<>0) then
  888. inc(l,2-(modulo and 1));
  889. inc(owner^.datasize,l);
  890. address:=owner^.datasize;
  891. end
  892. else if owner^.symtabletype=staticsymtable then
  893. begin
  894. if (cs_smartlink in aktswitches) then
  895. bsssegment^.concat(new(pai_cut,init));
  896. {$ifdef GDB}
  897. if cs_debuginfo in aktswitches then
  898. concatstabto(bsssegment);
  899. {$endif GDB}
  900. if (cs_smartlink in aktswitches) then
  901. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)))
  902. else
  903. bsssegment^.concat(new(pai_datablock,init(mangledname,l)));
  904. inc(owner^.datasize,l);
  905. { this symbol can't be loaded to a register }
  906. regable:=false;
  907. end
  908. else if owner^.symtabletype=globalsymtable then
  909. begin
  910. if (cs_smartlink in aktswitches) then
  911. bsssegment^.concat(new(pai_cut,init));
  912. {$ifdef GDB}
  913. if cs_debuginfo in aktswitches then
  914. begin
  915. concatstabto(bsssegment);
  916. { this has to be added so that the debugger knows where to find
  917. the global variable
  918. Doesn't work !!
  919. bsssegment^.concat(new(pai_symbol,init('_'+name))); }
  920. end;
  921. {$endif GDB}
  922. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)));
  923. inc(owner^.datasize,l);
  924. { this symbol can't be loaded to a register }
  925. regable:=false;
  926. end
  927. else if owner^.symtabletype in [recordsymtable,objectsymtable] then
  928. begin
  929. { align record and object fields }
  930. if aktpackrecords=2 then
  931. begin
  932. { align to word }
  933. modulo:=owner^.datasize and 3;
  934. if (l>=2) and ((modulo and 1)<>0) then
  935. inc(owner^.datasize);
  936. end
  937. else if aktpackrecords=4 then
  938. begin
  939. { align to dword }
  940. if (l>=3) and (modulo<>0) then
  941. inc(owner^.datasize,4-modulo)
  942. { or word }
  943. else if (l=2) and ((modulo and 1)<>0) then
  944. inc(owner^.datasize)
  945. end;
  946. address:=owner^.datasize;
  947. inc(owner^.datasize,l);
  948. { this symbol can't be loaded to a register }
  949. regable:=false;
  950. end
  951. else if owner^.symtabletype=parasymtable then
  952. begin
  953. address:=owner^.datasize;
  954. { intel processors don't know a byte push, }
  955. { so is always a word pushed }
  956. { so it must allways be even }
  957. if (l and 1)<>0 then
  958. inc(l);
  959. inc(owner^.datasize,l);
  960. end
  961. else
  962. begin
  963. modulo:=owner^.datasize and 3 ;
  964. if (l>=4) and (modulo<>0) then
  965. inc(owner^.datasize,4-modulo)
  966. else if (l>=2) and ((modulo and 1)<>0) then
  967. { nice piece of code !!
  968. inc(owner^.datasize,2-(datasize and 1));
  969. 2 - (datasize and 1) is allways 1 in this case
  970. Florian when will your global stream analyser
  971. find this out ?? }
  972. inc(owner^.datasize);
  973. address:=owner^.datasize;
  974. inc(owner^.datasize,l);
  975. end;
  976. end
  977. end;
  978. {$ifdef GDB}
  979. function tvarsym.stabstring : pchar;
  980. var
  981. st : char;
  982. begin
  983. if (owner^.symtabletype = objectsymtable) and
  984. ((properties and sp_static)<>0) then
  985. begin
  986. if use_gsym then st := 'G' else st := 'S';
  987. stabstring := strpnew('"'+owner^.name^+'__'+name+':'+
  988. +definition^.numberstring+'",'+
  989. tostr(N_LCSYM)+',0,'+tostr(line_no)+','+mangledname);
  990. end
  991. else if (owner^.symtabletype = globalsymtable) or
  992. (owner^.symtabletype = unitsymtable) then
  993. begin
  994. { Here we used S instead of
  995. because with G GDB doesn't look at the address field
  996. but searches the same name or with a leading underscore
  997. but these names don't exist in pascal !}
  998. if use_gsym then st := 'G' else st := 'S';
  999. stabstring := strpnew('"'+name+':'+st
  1000. +definition^.numberstring+'",'+
  1001. tostr(N_LCSYM)+',0,'+tostr(line_no)+','+mangledname);
  1002. end
  1003. else if owner^.symtabletype = staticsymtable then
  1004. begin
  1005. stabstring := strpnew('"'+name+':S'
  1006. +definition^.numberstring+'",'+
  1007. tostr(N_LCSYM)+',0,'+tostr(line_no)+','+mangledname);
  1008. end
  1009. else if (owner^.symtabletype=parasymtable) then
  1010. begin
  1011. case varspez of
  1012. vs_value : st := 'p';
  1013. vs_var : st := 'v';
  1014. vs_const : if dont_copy_const_param(definition) then
  1015. st := 'v'{ should be 'i' but 'i' doesn't work }
  1016. else
  1017. st := 'p';
  1018. end;
  1019. stabstring := strpnew('"'+name+':'+st
  1020. +definition^.numberstring+'",'+
  1021. tostr(N_PSYM)+',0,'+tostr(line_no)+','+tostr(address+owner^.call_offset))
  1022. {offset to ebp => will not work if the framepointer is esp
  1023. so some optimizing will make things harder to debug }
  1024. end
  1025. else if (owner^.symtabletype=localsymtable) then
  1026. {$ifdef i386}
  1027. if reg<>R_NO then
  1028. begin
  1029. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1030. { this is the register order for GDB}
  1031. stabstring:=strpnew('"'+name+':r'
  1032. +definition^.numberstring+'",'+
  1033. tostr(N_RSYM)+',0,'+tostr(line_no)+','+tostr(GDB_i386index[reg]));
  1034. end
  1035. else
  1036. {$endif i386}
  1037. stabstring := strpnew('"'+name+':'
  1038. +definition^.numberstring+'",'+
  1039. tostr(N_LSYM)+',0,'+tostr(line_no)+',-'+tostr(address))
  1040. else
  1041. stabstring := inherited stabstring;
  1042. end;
  1043. procedure tvarsym.concatstabto(asmlist : paasmoutput);
  1044. {$ifdef i386}
  1045. var stab_str : pchar;
  1046. {$endif i386}
  1047. begin
  1048. inherited concatstabto(asmlist);
  1049. {$ifdef i386}
  1050. if (owner^.symtabletype=parasymtable) and
  1051. (reg<>R_NO) then
  1052. begin
  1053. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1054. { this is the register order for GDB}
  1055. stab_str:=strpnew('"'+name+':r'
  1056. +definition^.numberstring+'",'+
  1057. tostr(N_RSYM)+',0,'+tostr(line_no)+','+tostr(GDB_i386index[reg]));
  1058. asmlist^.concat(new(pai_stabs,init(stab_str)));
  1059. end;
  1060. {$endif i386}
  1061. end;
  1062. {$endif GDB}
  1063. {****************************************************************************
  1064. TTYPEDCONSTSYM
  1065. *****************************************************************************}
  1066. constructor ttypedconstsym.init(const n : string;p : pdef);
  1067. begin
  1068. tsym.init(n);
  1069. typ:=typedconstsym;
  1070. definition:=p;
  1071. prefix:=stringdup(procprefix);
  1072. end;
  1073. constructor ttypedconstsym.load;
  1074. begin
  1075. tsym.load;
  1076. typ:=typedconstsym;
  1077. definition:=readdefref;
  1078. prefix:=stringdup(readstring);
  1079. end;
  1080. destructor ttypedconstsym.done;
  1081. begin
  1082. stringdispose(prefix);
  1083. tsym.done;
  1084. end;
  1085. function ttypedconstsym.mangledname : string;
  1086. begin
  1087. mangledname:='TC_'+prefix^+'_'+name;
  1088. end;
  1089. procedure ttypedconstsym.deref;
  1090. begin
  1091. resolvedef(definition);
  1092. end;
  1093. procedure ttypedconstsym.write;
  1094. begin
  1095. {$ifndef NEWPPU}
  1096. writebyte(ibtypedconstsym);
  1097. {$endif}
  1098. tsym.write;
  1099. writedefref(definition);
  1100. writestring(prefix^);
  1101. {$ifdef NEWPPU}
  1102. ppufile^.writeentry(ibtypedconstsym);
  1103. {$endif}
  1104. end;
  1105. { for most symbol types ther is nothing to do at all }
  1106. procedure ttypedconstsym.insert_in_data;
  1107. begin
  1108. { here there is a problem for ansistrings !! }
  1109. { we must write the label only after the 12 header bytes (PM) }
  1110. if not is_ansistring(definition) then
  1111. really_insert_in_data;
  1112. end;
  1113. procedure ttypedconstsym.really_insert_in_data;
  1114. begin
  1115. if (cs_smartlink in aktswitches) then
  1116. datasegment^.concat(new(pai_cut,init));
  1117. if owner^.symtabletype=globalsymtable then
  1118. begin
  1119. {$ifdef GDB}
  1120. if cs_debuginfo in aktswitches then
  1121. concatstabto(datasegment);
  1122. {$endif GDB}
  1123. datasegment^.concat(new(pai_symbol,init_global(mangledname)));
  1124. end
  1125. else
  1126. if owner^.symtabletype<>unitsymtable then
  1127. begin
  1128. {$ifdef GDB}
  1129. if cs_debuginfo in aktswitches then
  1130. concatstabto(datasegment);
  1131. {$endif GDB}
  1132. if (cs_smartlink in aktswitches) then
  1133. datasegment^.concat(new(pai_symbol,init_global(mangledname)))
  1134. else
  1135. datasegment^.concat(new(pai_symbol,init(mangledname)));
  1136. end;
  1137. end;
  1138. {$ifdef GDB}
  1139. function ttypedconstsym.stabstring : pchar;
  1140. var
  1141. st : char;
  1142. begin
  1143. if use_gsym and (owner^.symtabletype in [unitsymtable,globalsymtable]) then
  1144. st := 'G'
  1145. else
  1146. st := 'S';
  1147. stabstring := strpnew('"'+name+':'+st
  1148. +definition^.numberstring+'",'+tostr(n_STSYM)+',0,'+tostr(line_no)+','+mangledname);
  1149. end;
  1150. {$endif GDB}
  1151. {****************************************************************************
  1152. TCONSTSYM
  1153. ****************************************************************************}
  1154. constructor tconstsym.init(const n : string;t : tconsttype;v : longint;def : pdef);
  1155. begin
  1156. tsym.init(n);
  1157. typ:=constsym;
  1158. definition:=def;
  1159. consttype:=t;
  1160. value:=v;
  1161. end;
  1162. constructor tconstsym.load;
  1163. var
  1164. pd : pdouble;
  1165. ps : pointer; {***SETCONST}
  1166. begin
  1167. tsym.load;
  1168. typ:=constsym;
  1169. consttype:=tconsttype(readbyte);
  1170. case consttype of
  1171. constint,
  1172. constbool,
  1173. constchar : value:=readlong;
  1174. constord : begin
  1175. definition:=readdefref;
  1176. value:=readlong;
  1177. end;
  1178. conststring : value:=longint(stringdup(readstring));
  1179. constreal : begin
  1180. new(pd);
  1181. pd^:=readdouble;
  1182. value:=longint(pd);
  1183. end;
  1184. {***SETCONST}
  1185. constseta : begin
  1186. getmem(ps,32);
  1187. readset(ps^);
  1188. value:=longint(ps);
  1189. end;
  1190. {***}
  1191. else Message1(unit_f_ppu_invalid_entry,tostr(ord(consttype)));
  1192. end;
  1193. end;
  1194. destructor tconstsym.done;
  1195. begin
  1196. if consttype = conststring then stringdispose(pstring(value));
  1197. inherited done;
  1198. end;
  1199. function tconstsym.mangledname : string;
  1200. begin
  1201. mangledname:=name;
  1202. end;
  1203. procedure tconstsym.deref;
  1204. begin
  1205. if consttype=constord then
  1206. resolvedef(pdef(definition));
  1207. end;
  1208. procedure tconstsym.write;
  1209. begin
  1210. {$ifndef NEWPPU}
  1211. writebyte(ibconstsym);
  1212. {$endif}
  1213. tsym.write;
  1214. writebyte(byte(consttype));
  1215. case consttype of
  1216. constint,
  1217. constbool,
  1218. constchar : writelong(value);
  1219. constord : begin
  1220. writedefref(definition);
  1221. writelong(value);
  1222. end;
  1223. conststring : writestring(pstring(value)^);
  1224. constreal : writedouble(pdouble(value)^);
  1225. {***SETCONST}
  1226. constseta: writeset(pointer(value)^);
  1227. {***}
  1228. else internalerror(13);
  1229. end;
  1230. {$ifdef NEWPPU}
  1231. ppufile^.writeentry(ibconstsym);
  1232. {$endif}
  1233. end;
  1234. {$ifdef GDB}
  1235. function tconstsym.stabstring : pchar;
  1236. var st : string;
  1237. begin
  1238. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1239. case consttype of
  1240. conststring : begin
  1241. { I had to remove ibm2ascii !! }
  1242. st := pstring(value)^;
  1243. {st := ibm2ascii(pstring(value)^);}
  1244. st := 's'''+st+'''';
  1245. end;
  1246. constbool, constint, constord, constchar : st := 'i'+tostr(value);
  1247. constreal : begin
  1248. system.str(pdouble(value)^,st);
  1249. st := 'r'+st;
  1250. end;
  1251. { if we don't know just put zero !! }
  1252. else st:='i0';
  1253. {***SETCONST}
  1254. {constset:;} {*** I don't know what to do with a set.}
  1255. { sets are not recognized by GDB}
  1256. {***}
  1257. end;
  1258. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+tostr(line_no)+',0');
  1259. end;
  1260. procedure tconstsym.concatstabto(asmlist : paasmoutput);
  1261. begin
  1262. if consttype <> conststring then
  1263. inherited concatstabto(asmlist);
  1264. end;
  1265. {$endif GDB}
  1266. {****************************************************************************
  1267. TENUMSYM
  1268. ****************************************************************************}
  1269. constructor tenumsym.init(const n : string;def : penumdef;v : longint);
  1270. begin
  1271. tsym.init(n);
  1272. typ:=enumsym;
  1273. definition:=def;
  1274. value:=v;
  1275. {$ifdef GDB}
  1276. order;
  1277. {$endif GDB}
  1278. end;
  1279. constructor tenumsym.load;
  1280. begin
  1281. tsym.load;
  1282. typ:=enumsym;
  1283. definition:=penumdef(readdefref);
  1284. value:=readlong;
  1285. {$ifdef GDB}
  1286. next := Nil;
  1287. {$endif GDB}
  1288. end;
  1289. procedure tenumsym.deref;
  1290. begin
  1291. resolvedef(pdef(definition));
  1292. {$ifdef GDB}
  1293. order;
  1294. {$endif}
  1295. end;
  1296. {$ifdef GDB}
  1297. procedure tenumsym.order;
  1298. var sym : penumsym;
  1299. begin
  1300. sym := definition^.first;
  1301. if sym = nil then
  1302. begin
  1303. definition^.first := @self;
  1304. next := nil;
  1305. exit;
  1306. end;
  1307. {reorder the symbols in increasing value }
  1308. if value < sym^.value then
  1309. begin
  1310. next := sym;
  1311. definition^.first := @self;
  1312. end else
  1313. begin
  1314. while (sym^.value <= value) and assigned(sym^.next) do
  1315. sym := sym^.next;
  1316. next := sym^.next;
  1317. sym^.next := @self;
  1318. end;
  1319. end;
  1320. {$endif GDB}
  1321. procedure tenumsym.write;
  1322. begin
  1323. {$ifndef NEWPPU}
  1324. writebyte(ibenumsym);
  1325. {$endif}
  1326. tsym.write;
  1327. writedefref(definition);
  1328. writelong(value);
  1329. {$ifdef NEWPPU}
  1330. ppufile^.writeentry(ibenumsym);
  1331. {$endif}
  1332. end;
  1333. {$ifdef GDB}
  1334. procedure tenumsym.concatstabto(asmlist : paasmoutput);
  1335. begin
  1336. {enum elements have no stab !}
  1337. end;
  1338. {$EndIf GDB}
  1339. {****************************************************************************
  1340. TTYPESYM
  1341. ****************************************************************************}
  1342. constructor ttypesym.init(const n : string;d : pdef);
  1343. begin
  1344. tsym.init(n);
  1345. typ:=typesym;
  1346. definition:=d;
  1347. {$ifdef GDB}
  1348. isusedinstab := false;
  1349. {$endif GDB}
  1350. forwardpointer:=nil;
  1351. { this allows to link definitions with the type with declares }
  1352. { them }
  1353. if assigned(definition) then
  1354. if definition^.sym=nil then
  1355. definition^.sym:=@self;
  1356. end;
  1357. constructor ttypesym.load;
  1358. begin
  1359. tsym.load;
  1360. typ:=typesym;
  1361. forwardpointer:=nil;
  1362. {$ifdef GDB}
  1363. isusedinstab := false;
  1364. {$endif GDB}
  1365. definition:=readdefref;
  1366. end;
  1367. destructor ttypesym.done;
  1368. begin
  1369. if assigned(definition) then
  1370. if definition^.sym=@self then
  1371. definition^.sym:=nil;
  1372. inherited done;
  1373. end;
  1374. procedure ttypesym.deref;
  1375. begin
  1376. resolvedef(definition);
  1377. if assigned(definition) then
  1378. if definition^.sym=nil then
  1379. definition^.sym:=@self;
  1380. if definition^.deftype=recorddef then
  1381. precdef(definition)^.symtable^.name:=stringdup('record '+name);
  1382. {if definition^.deftype=objectdef then
  1383. pobjectdef(definition)^.publicsyms^.name:=stringdup('object '+name);
  1384. done in tobjectdef.load }
  1385. end;
  1386. procedure ttypesym.write;
  1387. begin
  1388. {$ifndef NEWPPU}
  1389. writebyte(ibtypesym);
  1390. {$endif}
  1391. tsym.write;
  1392. writedefref(definition);
  1393. {$ifdef NEWPPU}
  1394. ppufile^.writeentry(ibtypesym);
  1395. {$endif}
  1396. end;
  1397. {$ifdef GDB}
  1398. function ttypesym.stabstring : pchar;
  1399. var stabchar : string[2];
  1400. short : string;
  1401. begin
  1402. if definition^.deftype in tagtypes then
  1403. stabchar := 'Tt'
  1404. else
  1405. stabchar := 't';
  1406. short := '"'+name+':'+stabchar+definition^.numberstring
  1407. +'",'+tostr(N_LSYM)+',0,'+tostr(line_no)+',0';
  1408. stabstring := strpnew(short);
  1409. end;
  1410. procedure ttypesym.concatstabto(asmlist : paasmoutput);
  1411. begin
  1412. {not stabs for forward defs }
  1413. if assigned(definition) then
  1414. if (definition^.sym = @self) then
  1415. definition^.concatstabto(asmlist)
  1416. else
  1417. inherited concatstabto(asmlist);
  1418. end;
  1419. {$endif GDB}
  1420. {****************************************************************************
  1421. TSYSSYM
  1422. ****************************************************************************}
  1423. constructor tsyssym.init(const n : string;l : longint);
  1424. begin
  1425. inherited init(n);
  1426. typ:=syssym;
  1427. number:=l;
  1428. end;
  1429. procedure tsyssym.write;
  1430. begin
  1431. end;
  1432. {$ifdef GDB}
  1433. procedure tsyssym.concatstabto(asmlist : paasmoutput);
  1434. begin
  1435. end;
  1436. {$endif GDB}
  1437. {****************************************************************************
  1438. TMACROSYM
  1439. ****************************************************************************}
  1440. constructor tmacrosym.init(const n : string);
  1441. begin
  1442. inherited init(n);
  1443. defined:=true;
  1444. buftext:=nil;
  1445. buflen:=0;
  1446. end;
  1447. destructor tmacrosym.done;
  1448. begin
  1449. if assigned(buftext) then
  1450. freemem(buftext,buflen);
  1451. inherited done;
  1452. end;
  1453. {$ifdef GDB}
  1454. function typeglobalnumber(const s : string) : string;
  1455. var st : string;
  1456. symt : psymtable;
  1457. old_make_ref : boolean;
  1458. begin
  1459. old_make_ref:=make_ref;
  1460. make_ref:=false;
  1461. typeglobalnumber := '0';
  1462. srsym := nil;
  1463. if pos('.',s) > 0 then
  1464. begin
  1465. st := copy(s,1,pos('.',s)-1);
  1466. getsym(st,false);
  1467. st := copy(s,pos('.',s)+1,255);
  1468. if assigned(srsym) then
  1469. begin
  1470. if srsym^.typ = unitsym then
  1471. begin
  1472. symt := punitsym(srsym)^.unitsymtable;
  1473. srsym := symt^.search(st);
  1474. end else srsym := nil;
  1475. end;
  1476. end else st := s;
  1477. if srsym = nil then getsym(st,true);
  1478. if srsym^.typ<>typesym then
  1479. begin
  1480. Message(sym_e_type_id_expected);
  1481. exit;
  1482. end;
  1483. typeglobalnumber := ptypesym(srsym)^.definition^.numberstring;
  1484. make_ref:=old_make_ref;
  1485. end;
  1486. {$endif GDB}
  1487. {
  1488. $Log$
  1489. Revision 1.5 1998-06-04 23:52:02 peter
  1490. * m68k compiles
  1491. + .def file creation moved to gendef.pas so it could also be used
  1492. for win32
  1493. Revision 1.4 1998/06/04 09:55:46 pierre
  1494. * demangled name of procsym reworked to become independant of the mangling scheme
  1495. Come test_funcret improvements (not yet working)S: ----------------------------------------------------------------------
  1496. Revision 1.3 1998/06/03 22:14:20 florian
  1497. * problem with sizes of classes fixed (if the anchestor was declared
  1498. forward, the compiler doesn't update the child classes size)
  1499. Revision 1.2 1998/05/28 14:40:29 peter
  1500. * fixes for newppu, remake3 works now with it
  1501. Revision 1.1 1998/05/27 19:45:09 peter
  1502. * symtable.pas splitted into includefiles
  1503. * symtable adapted for $ifdef NEWPPU
  1504. }