symsym.inc 49 KB

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