symsym.inc 51 KB

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