symsym.inc 54 KB

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