symsym.inc 49 KB

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