symsym.inc 62 KB

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