symsym.inc 49 KB

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