symsym.inc 50 KB

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