symsym.inc 49 KB

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