symsym.inc 49 KB

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