symsym.inc 50 KB

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