symsym.inc 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186
  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 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. procedure tfuncretsym.insert_in_data;
  667. var
  668. l : longint;
  669. begin
  670. { allocate space in local if ret in acc or in fpu }
  671. if ret_in_acc(procinfo.retdef) or (procinfo.retdef^.deftype=floatdef) then
  672. begin
  673. l:=funcretdef^.size;
  674. inc(owner^.datasize,l);
  675. {$ifdef m68k}
  676. { word alignment required for motorola }
  677. if (l=1) then
  678. inc(owner^.datasize,1)
  679. else
  680. {$endif}
  681. if (l>=4) and ((owner^.datasize and 3)<>0) then
  682. inc(owner^.datasize,4-(owner^.datasize and 3))
  683. else if (l>=2) and ((owner^.datasize and 1)<>0) then
  684. inc(owner^.datasize,2-(owner^.datasize and 1));
  685. address:=owner^.datasize;
  686. procinfo.retoffset:=-owner^.datasize;
  687. end;
  688. end;
  689. {****************************************************************************
  690. TABSOLUTESYM
  691. ****************************************************************************}
  692. constructor tabsolutesym.init(const n : string;p : pdef);
  693. begin
  694. inherited init(n,p);
  695. typ:=absolutesym;
  696. end;
  697. constructor tabsolutesym.load;
  698. begin
  699. tvarsym.load;
  700. typ:=absolutesym;
  701. ref:=nil;
  702. address:=0;
  703. asmname:=nil;
  704. abstyp:=absolutetyp(readbyte);
  705. absseg:=false;
  706. case abstyp of
  707. tovar :
  708. begin
  709. asmname:=stringdup(readstring);
  710. ref:=srsym;
  711. end;
  712. toasm :
  713. asmname:=stringdup(readstring);
  714. toaddr :
  715. begin
  716. address:=readlong;
  717. absseg:=boolean(readbyte);
  718. end;
  719. end;
  720. end;
  721. procedure tabsolutesym.write;
  722. begin
  723. tsym.write;
  724. writebyte(byte(varspez));
  725. if read_member then
  726. writelong(address);
  727. writedefref(definition);
  728. writebyte(var_options and (not vo_regable));
  729. writebyte(byte(abstyp));
  730. case abstyp of
  731. tovar :
  732. writestring(ref^.name);
  733. toasm :
  734. writestring(asmname^);
  735. toaddr :
  736. begin
  737. writelong(address);
  738. writebyte(byte(absseg));
  739. end;
  740. end;
  741. current_ppu^.writeentry(ibabsolutesym);
  742. end;
  743. procedure tabsolutesym.deref;
  744. begin
  745. resolvedef(definition);
  746. if (abstyp=tovar) and (asmname<>nil) then
  747. begin
  748. { search previous loaded symtables }
  749. getsym(asmname^,false);
  750. if not(assigned(srsym)) then
  751. getsymonlyin(owner,asmname^);
  752. if not(assigned(srsym)) then
  753. srsym:=generrorsym;
  754. ref:=srsym;
  755. stringdispose(asmname);
  756. end;
  757. end;
  758. function tabsolutesym.mangledname : string;
  759. begin
  760. case abstyp of
  761. tovar :
  762. mangledname:=ref^.mangledname;
  763. toasm :
  764. mangledname:=asmname^;
  765. toaddr :
  766. mangledname:='$'+tostr(address);
  767. else
  768. internalerror(10002);
  769. end;
  770. end;
  771. procedure tabsolutesym.insert_in_data;
  772. begin
  773. end;
  774. {$ifdef GDB}
  775. procedure tabsolutesym.concatstabto(asmlist : paasmoutput);
  776. begin
  777. { I don't know how to handle this !! }
  778. end;
  779. {$endif GDB}
  780. {****************************************************************************
  781. TVARSYM
  782. ****************************************************************************}
  783. constructor tvarsym.init(const n : string;p : pdef);
  784. begin
  785. tsym.init(n);
  786. typ:=varsym;
  787. definition:=p;
  788. _mangledname:=nil;
  789. varspez:=vs_value;
  790. address:=0;
  791. islocalcopy:=false;
  792. localvarsym:=nil;
  793. refs:=0;
  794. is_valid := 1;
  795. var_options:=0;
  796. { can we load the value into a register ? }
  797. case p^.deftype of
  798. pointerdef,
  799. enumdef,
  800. procvardef :
  801. var_options:=var_options or vo_regable;
  802. orddef :
  803. case porddef(p)^.typ of
  804. bool8bit,bool16bit,bool32bit,
  805. u8bit,u16bit,u32bit,
  806. s8bit,s16bit,s32bit :
  807. var_options:=var_options or vo_regable;
  808. else
  809. var_options:=var_options and not vo_regable;
  810. end;
  811. setdef:
  812. if psetdef(p)^.settype=smallset then
  813. var_options:=var_options or vo_regable;
  814. else
  815. var_options:=var_options and not vo_regable;
  816. end;
  817. reg:=R_NO;
  818. end;
  819. constructor tvarsym.init_dll(const n : string;p : pdef);
  820. begin
  821. { The tvarsym is necessary for 0.99.5 (PFV) }
  822. tvarsym.init(n,p);
  823. var_options:=var_options or vo_is_dll_var;
  824. end;
  825. constructor tvarsym.init_C(const n,mangled : string;p : pdef);
  826. begin
  827. { The tvarsym is necessary for 0.99.5 (PFV) }
  828. tvarsym.init(n,p);
  829. var_options:=var_options or vo_is_C_var;
  830. setmangledname(mangled);
  831. end;
  832. constructor tvarsym.load;
  833. begin
  834. tsym.load;
  835. typ:=varsym;
  836. _mangledname:=nil;
  837. reg:=R_NO;
  838. refs := 0;
  839. is_valid := 1;
  840. varspez:=tvarspez(readbyte);
  841. if read_member then
  842. address:=readlong
  843. else
  844. address:=0;
  845. islocalcopy:=false;
  846. localvarsym:=nil;
  847. definition:=readdefref;
  848. var_options:=readbyte;
  849. if (var_options and vo_is_C_var)<>0 then
  850. setmangledname(readstring);
  851. end;
  852. procedure tvarsym.deref;
  853. begin
  854. resolvedef(definition);
  855. end;
  856. procedure tvarsym.write;
  857. begin
  858. tsym.write;
  859. writebyte(byte(varspez));
  860. if read_member then
  861. writelong(address);
  862. writedefref(definition);
  863. { symbols which are load are never candidates for a register,
  864. turn of the regable }
  865. writebyte(var_options and (not vo_regable));
  866. if (var_options and vo_is_C_var)<>0 then
  867. writestring(mangledname);
  868. current_ppu^.writeentry(ibvarsym);
  869. end;
  870. procedure tvarsym.setmangledname(const s : string);
  871. begin
  872. _mangledname:=strpnew(s);
  873. end;
  874. function tvarsym.mangledname : string;
  875. var
  876. prefix : string;
  877. begin
  878. if assigned(_mangledname) then
  879. begin
  880. mangledname:=strpas(_mangledname);
  881. exit;
  882. end;
  883. case owner^.symtabletype of
  884. staticsymtable :
  885. if (cs_smartlink in aktmoduleswitches) then
  886. prefix:='_'+owner^.name^+'$$$_'
  887. else
  888. prefix:='_';
  889. unitsymtable,
  890. globalsymtable :
  891. prefix:='U_'+owner^.name^+'_';
  892. else
  893. Message(sym_e_invalid_call_tvarsymmangledname);
  894. end;
  895. mangledname:=prefix+name;
  896. end;
  897. function tvarsym.getsize : longint;
  898. begin
  899. if assigned(definition) and (varspez=vs_value) then
  900. getsize:=definition^.size
  901. else
  902. getsize:=0;
  903. end;
  904. function tvarsym.getpushsize : longint;
  905. begin
  906. if assigned(definition) then
  907. begin
  908. case varspez of
  909. vs_var :
  910. getpushsize:=target_os.size_of_pointer;
  911. vs_value,
  912. vs_const :
  913. begin
  914. case definition^.deftype of
  915. arraydef,
  916. setdef,
  917. stringdef,
  918. recorddef,
  919. objectdef :
  920. getpushsize:=target_os.size_of_pointer;
  921. else
  922. getpushsize:=definition^.size;
  923. end;
  924. end;
  925. end;
  926. end
  927. else
  928. getpushsize:=0;
  929. end;
  930. procedure tvarsym.insert_in_data;
  931. var
  932. l,modulo : longint;
  933. begin
  934. if (var_options and vo_is_external)<>0 then
  935. exit;
  936. { handle static variables of objects especially }
  937. if read_member and (owner^.symtabletype=objectsymtable) and
  938. ((properties and sp_static)<>0) then
  939. begin
  940. { the data filed is generated in parser.pas
  941. with a tobject_FIELDNAME variable }
  942. { this symbol can't be loaded to a register }
  943. var_options:=var_options and not vo_regable;
  944. end
  945. else
  946. if not(read_member) then
  947. begin
  948. { made problems with parameters etc. ! (FK) }
  949. { check for instance of an abstract object or class }
  950. {
  951. if (pvarsym(sym)^.definition^.deftype=objectdef) and
  952. ((pobjectdef(pvarsym(sym)^.definition)^.options and oo_is_abstract)<>0) then
  953. Message(sym_e_no_instance_of_abstract_object);
  954. }
  955. l:=getsize;
  956. case owner^.symtabletype of
  957. stt_exceptsymtable:
  958. { can contain only one symbol, address calculated later }
  959. ;
  960. localsymtable :
  961. begin
  962. is_valid := 0;
  963. modulo:=owner^.datasize and 3;
  964. {$ifdef m68k}
  965. { word alignment required for motorola }
  966. if (l=1) then
  967. l:=2
  968. else
  969. {$endif}
  970. if (l>=4) and (modulo<>0) then
  971. inc(l,4-modulo)
  972. else
  973. if (l>=2) and ((modulo and 1)<>0) then
  974. inc(l,2-(modulo and 1));
  975. inc(owner^.datasize,l);
  976. address:=owner^.datasize;
  977. end;
  978. staticsymtable :
  979. begin
  980. if (cs_smartlink in aktmoduleswitches) then
  981. bsssegment^.concat(new(pai_cut,init));
  982. {$ifdef GDB}
  983. if cs_debuginfo in aktmoduleswitches then
  984. concatstabto(bsssegment);
  985. {$endif GDB}
  986. if (cs_smartlink in aktmoduleswitches) or
  987. ((var_options and vo_is_c_var)<>0) then
  988. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)))
  989. else
  990. bsssegment^.concat(new(pai_datablock,init(mangledname,l)));
  991. { increase datasize }
  992. inc(owner^.datasize,l);
  993. { this symbol can't be loaded to a register }
  994. var_options:=var_options and not vo_regable;
  995. end;
  996. globalsymtable :
  997. begin
  998. if (cs_smartlink in aktmoduleswitches) then
  999. bsssegment^.concat(new(pai_cut,init));
  1000. {$ifdef GDB}
  1001. if cs_debuginfo in aktmoduleswitches then
  1002. concatstabto(bsssegment);
  1003. {$endif GDB}
  1004. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)));
  1005. inc(owner^.datasize,l);
  1006. { this symbol can't be loaded to a register }
  1007. var_options:=var_options and not vo_regable;
  1008. end;
  1009. recordsymtable,
  1010. objectsymtable :
  1011. begin
  1012. { this symbol can't be loaded to a register }
  1013. var_options:=var_options and not vo_regable;
  1014. { align record and object fields }
  1015. if (l=1) or (aktpackrecords=1) then
  1016. begin
  1017. address:=owner^.datasize;
  1018. inc(owner^.datasize,l)
  1019. end
  1020. else
  1021. if (l=2) or (aktpackrecords=2) then
  1022. begin
  1023. owner^.datasize:=(owner^.datasize+1) and (not 1);
  1024. address:=owner^.datasize;
  1025. inc(owner^.datasize,l)
  1026. end
  1027. else
  1028. if (l<=4) or (aktpackrecords=4) then
  1029. begin
  1030. owner^.datasize:=(owner^.datasize+3) and (not 3);
  1031. address:=owner^.datasize;
  1032. inc(owner^.datasize,l);
  1033. end
  1034. else
  1035. if (l<=8) or (aktpackrecords=8) then
  1036. begin
  1037. owner^.datasize:=(owner^.datasize+7) and (not 7);
  1038. address:=owner^.datasize;
  1039. inc(owner^.datasize,l);
  1040. end
  1041. else
  1042. if (l<=16) or (aktpackrecords=16) then
  1043. begin
  1044. owner^.datasize:=(owner^.datasize+15) and (not 15);
  1045. address:=owner^.datasize;
  1046. inc(owner^.datasize,l);
  1047. end
  1048. else
  1049. if (l<=32) or (aktpackrecords=32) then
  1050. begin
  1051. owner^.datasize:=(owner^.datasize+31) and (not 31);
  1052. address:=owner^.datasize;
  1053. inc(owner^.datasize,l);
  1054. end;
  1055. end;
  1056. parasymtable :
  1057. begin
  1058. { here we need the size of a push instead of the
  1059. size of the data }
  1060. l:=getpushsize;
  1061. address:=owner^.datasize;
  1062. owner^.datasize:=align(owner^.datasize+l,target_os.stackalignment);
  1063. end
  1064. else
  1065. begin
  1066. modulo:=owner^.datasize and 3 ;
  1067. if (l>=4) and (modulo<>0) then
  1068. inc(owner^.datasize,4-modulo)
  1069. else
  1070. if (l>=2) and ((modulo and 1)<>0) then
  1071. inc(owner^.datasize);
  1072. address:=owner^.datasize;
  1073. inc(owner^.datasize,l);
  1074. end;
  1075. end;
  1076. end;
  1077. end;
  1078. {$ifdef GDB}
  1079. function tvarsym.stabstring : pchar;
  1080. var
  1081. st : char;
  1082. begin
  1083. if (owner^.symtabletype = objectsymtable) and
  1084. ((properties and sp_static)<>0) then
  1085. begin
  1086. if (cs_gdb_gsym in aktglobalswitches) then st := 'G' else st := 'S';
  1087. stabstring := strpnew('"'+owner^.name^+'__'+name+':'+
  1088. +definition^.numberstring+'",'+
  1089. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1090. end
  1091. else if (owner^.symtabletype = globalsymtable) or
  1092. (owner^.symtabletype = unitsymtable) then
  1093. begin
  1094. { Here we used S instead of
  1095. because with G GDB doesn't look at the address field
  1096. but searches the same name or with a leading underscore
  1097. but these names don't exist in pascal !}
  1098. if (cs_gdb_gsym in aktglobalswitches) then st := 'G' else st := 'S';
  1099. stabstring := strpnew('"'+name+':'+st
  1100. +definition^.numberstring+'",'+
  1101. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1102. end
  1103. else if owner^.symtabletype = staticsymtable then
  1104. begin
  1105. stabstring := strpnew('"'+name+':S'
  1106. +definition^.numberstring+'",'+
  1107. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1108. end
  1109. else if (owner^.symtabletype=parasymtable) then
  1110. begin
  1111. case varspez of
  1112. vs_var : st := 'v';
  1113. vs_value,
  1114. vs_const : if push_addr_param(definition) then
  1115. st := 'v' { should be 'i' but 'i' doesn't work }
  1116. else
  1117. st := 'p';
  1118. end;
  1119. stabstring := strpnew('"'+name+':'+st
  1120. +definition^.numberstring+'",'+
  1121. tostr(N_PSYM)+',0,'+tostr(fileinfo.line)+','+
  1122. tostr(address+owner^.address_fixup));
  1123. {offset to ebp => will not work if the framepointer is esp
  1124. so some optimizing will make things harder to debug }
  1125. end
  1126. else if (owner^.symtabletype=localsymtable) then
  1127. {$ifdef i386}
  1128. if reg<>R_NO then
  1129. begin
  1130. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1131. { this is the register order for GDB}
  1132. stabstring:=strpnew('"'+name+':r'
  1133. +definition^.numberstring+'",'+
  1134. tostr(N_RSYM)+',0,'+
  1135. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1136. end
  1137. else
  1138. {$endif i386}
  1139. stabstring := strpnew('"'+name+':'
  1140. +definition^.numberstring+'",'+
  1141. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address))
  1142. else
  1143. stabstring := inherited stabstring;
  1144. end;
  1145. procedure tvarsym.concatstabto(asmlist : paasmoutput);
  1146. {$ifdef i386}
  1147. var stab_str : pchar;
  1148. {$endif i386}
  1149. begin
  1150. inherited concatstabto(asmlist);
  1151. {$ifdef i386}
  1152. if (owner^.symtabletype=parasymtable) and
  1153. (reg<>R_NO) then
  1154. begin
  1155. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1156. { this is the register order for GDB}
  1157. stab_str:=strpnew('"'+name+':r'
  1158. +definition^.numberstring+'",'+
  1159. tostr(N_RSYM)+',0,'+
  1160. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1161. asmlist^.concat(new(pai_stabs,init(stab_str)));
  1162. end;
  1163. {$endif i386}
  1164. end;
  1165. {$endif GDB}
  1166. destructor tvarsym.done;
  1167. begin
  1168. strdispose(_mangledname);
  1169. inherited done;
  1170. end;
  1171. {****************************************************************************
  1172. TTYPEDCONSTSYM
  1173. *****************************************************************************}
  1174. constructor ttypedconstsym.init(const n : string;p : pdef);
  1175. begin
  1176. tsym.init(n);
  1177. typ:=typedconstsym;
  1178. definition:=p;
  1179. prefix:=stringdup(procprefix);
  1180. end;
  1181. constructor ttypedconstsym.load;
  1182. begin
  1183. tsym.load;
  1184. typ:=typedconstsym;
  1185. definition:=readdefref;
  1186. prefix:=stringdup(readstring);
  1187. end;
  1188. destructor ttypedconstsym.done;
  1189. begin
  1190. stringdispose(prefix);
  1191. tsym.done;
  1192. end;
  1193. function ttypedconstsym.mangledname : string;
  1194. begin
  1195. mangledname:='TC_'+prefix^+'_'+name;
  1196. end;
  1197. function ttypedconstsym.getsize : longint;
  1198. begin
  1199. if assigned(definition) then
  1200. getsize:=definition^.size
  1201. else
  1202. getsize:=0;
  1203. end;
  1204. procedure ttypedconstsym.deref;
  1205. begin
  1206. resolvedef(definition);
  1207. end;
  1208. procedure ttypedconstsym.write;
  1209. begin
  1210. tsym.write;
  1211. writedefref(definition);
  1212. writestring(prefix^);
  1213. current_ppu^.writeentry(ibtypedconstsym);
  1214. end;
  1215. { for most symbol types ther is nothing to do at all }
  1216. procedure ttypedconstsym.insert_in_data;
  1217. begin
  1218. { here there is a problem for ansistrings !! }
  1219. { we must write the label only after the 12 header bytes (PM)
  1220. if not is_ansistring(definition) then
  1221. }
  1222. { solved, the ansis string is moved to consts (FK) }
  1223. really_insert_in_data;
  1224. end;
  1225. procedure ttypedconstsym.really_insert_in_data;
  1226. begin
  1227. if owner^.symtabletype=globalsymtable then
  1228. begin
  1229. if (cs_smartlink in aktmoduleswitches) then
  1230. datasegment^.concat(new(pai_cut,init));
  1231. {$ifdef GDB}
  1232. if cs_debuginfo in aktmoduleswitches then
  1233. concatstabto(datasegment);
  1234. {$endif GDB}
  1235. datasegment^.concat(new(pai_symbol,init_global(mangledname)));
  1236. end
  1237. else
  1238. if owner^.symtabletype<>unitsymtable then
  1239. begin
  1240. if (cs_smartlink in aktmoduleswitches) then
  1241. datasegment^.concat(new(pai_cut,init));
  1242. {$ifdef GDB}
  1243. if cs_debuginfo in aktmoduleswitches then
  1244. concatstabto(datasegment);
  1245. {$endif GDB}
  1246. if (cs_smartlink in aktmoduleswitches) then
  1247. datasegment^.concat(new(pai_symbol,init_global(mangledname)))
  1248. else
  1249. datasegment^.concat(new(pai_symbol,init(mangledname)));
  1250. end;
  1251. end;
  1252. {$ifdef GDB}
  1253. function ttypedconstsym.stabstring : pchar;
  1254. var
  1255. st : char;
  1256. begin
  1257. if (cs_gdb_gsym in aktglobalswitches) and (owner^.symtabletype in [unitsymtable,globalsymtable]) then
  1258. st := 'G'
  1259. else
  1260. st := 'S';
  1261. stabstring := strpnew('"'+name+':'+st+
  1262. definition^.numberstring+'",'+tostr(n_STSYM)+',0,'+
  1263. tostr(fileinfo.line)+','+mangledname);
  1264. end;
  1265. {$endif GDB}
  1266. {****************************************************************************
  1267. TCONSTSYM
  1268. ****************************************************************************}
  1269. constructor tconstsym.init(const n : string;t : tconsttype;v : longint);
  1270. begin
  1271. inherited init(n);
  1272. typ:=constsym;
  1273. consttype:=t;
  1274. value:=v;
  1275. definition:=nil;
  1276. len:=0;
  1277. end;
  1278. constructor tconstsym.init_def(const n : string;t : tconsttype;v : longint;def : pdef);
  1279. begin
  1280. inherited init(n);
  1281. typ:=constsym;
  1282. consttype:=t;
  1283. value:=v;
  1284. definition:=def;
  1285. len:=0;
  1286. end;
  1287. constructor tconstsym.init_string(const n : string;t : tconsttype;str:pchar;l:longint);
  1288. begin
  1289. inherited init(n);
  1290. typ:=constsym;
  1291. consttype:=t;
  1292. value:=longint(str);
  1293. definition:=nil;
  1294. len:=l;
  1295. end;
  1296. constructor tconstsym.load;
  1297. var
  1298. pd : pbestreal;
  1299. ps : pnormalset;
  1300. begin
  1301. tsym.load;
  1302. typ:=constsym;
  1303. consttype:=tconsttype(readbyte);
  1304. case consttype of
  1305. constint,
  1306. constbool,
  1307. constchar : value:=readlong;
  1308. constord :
  1309. begin
  1310. definition:=readdefref;
  1311. value:=readlong;
  1312. end;
  1313. conststring :
  1314. begin
  1315. len:=readlong;
  1316. getmem(pchar(value),len+1);
  1317. current_ppu^.getdata(pchar(value)^,len);
  1318. end;
  1319. constreal :
  1320. begin
  1321. new(pd);
  1322. pd^:=readreal;
  1323. value:=longint(pd);
  1324. end;
  1325. constset :
  1326. begin
  1327. definition:=readdefref;
  1328. new(ps);
  1329. readnormalset(ps^);
  1330. value:=longint(ps);
  1331. end;
  1332. constnil : ;
  1333. else
  1334. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttype)));
  1335. end;
  1336. end;
  1337. destructor tconstsym.done;
  1338. begin
  1339. case consttype of
  1340. conststring :
  1341. freemem(pchar(value),len+1);
  1342. constreal :
  1343. dispose(pbestreal(value));
  1344. constset :
  1345. dispose(pnormalset(value));
  1346. end;
  1347. inherited done;
  1348. end;
  1349. function tconstsym.mangledname : string;
  1350. begin
  1351. mangledname:=name;
  1352. end;
  1353. procedure tconstsym.deref;
  1354. begin
  1355. if consttype in [constord,constset] then
  1356. resolvedef(pdef(definition));
  1357. end;
  1358. procedure tconstsym.write;
  1359. begin
  1360. tsym.write;
  1361. writebyte(byte(consttype));
  1362. case consttype of
  1363. constnil : ;
  1364. constint,
  1365. constbool,
  1366. constchar :
  1367. writelong(value);
  1368. constord :
  1369. begin
  1370. writedefref(definition);
  1371. writelong(value);
  1372. end;
  1373. conststring :
  1374. begin
  1375. writelong(len);
  1376. current_ppu^.putdata(pchar(value)^,len);
  1377. end;
  1378. constreal :
  1379. writereal(pbestreal(value)^);
  1380. constset :
  1381. begin
  1382. writedefref(definition);
  1383. writenormalset(pointer(value)^);
  1384. end;
  1385. else
  1386. internalerror(13);
  1387. end;
  1388. current_ppu^.writeentry(ibconstsym);
  1389. end;
  1390. {$ifdef GDB}
  1391. function tconstsym.stabstring : pchar;
  1392. var st : string;
  1393. begin
  1394. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1395. case consttype of
  1396. conststring : begin
  1397. { I had to remove ibm2ascii !! }
  1398. st := pstring(value)^;
  1399. {st := ibm2ascii(pstring(value)^);}
  1400. st := 's'''+st+'''';
  1401. end;
  1402. constbool, constint, constord, constchar : st := 'i'+tostr(value);
  1403. constreal : begin
  1404. system.str(pbestreal(value)^,st);
  1405. st := 'r'+st;
  1406. end;
  1407. { if we don't know just put zero !! }
  1408. else st:='i0';
  1409. {***SETCONST}
  1410. {constset:;} {*** I don't know what to do with a set.}
  1411. { sets are not recognized by GDB}
  1412. {***}
  1413. end;
  1414. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1415. tostr(fileinfo.line)+',0');
  1416. end;
  1417. procedure tconstsym.concatstabto(asmlist : paasmoutput);
  1418. begin
  1419. if consttype <> conststring then
  1420. inherited concatstabto(asmlist);
  1421. end;
  1422. {$endif GDB}
  1423. {****************************************************************************
  1424. TENUMSYM
  1425. ****************************************************************************}
  1426. constructor tenumsym.init(const n : string;def : penumdef;v : longint);
  1427. begin
  1428. tsym.init(n);
  1429. typ:=enumsym;
  1430. definition:=def;
  1431. value:=v;
  1432. if def^.min>v then
  1433. def^.setmin(v);
  1434. if def^.max<v then
  1435. def^.setmax(v);
  1436. order;
  1437. end;
  1438. constructor tenumsym.load;
  1439. begin
  1440. tsym.load;
  1441. typ:=enumsym;
  1442. definition:=penumdef(readdefref);
  1443. value:=readlong;
  1444. next := Nil;
  1445. end;
  1446. procedure tenumsym.deref;
  1447. begin
  1448. resolvedef(pdef(definition));
  1449. order;
  1450. end;
  1451. procedure tenumsym.order;
  1452. var
  1453. sym : penumsym;
  1454. begin
  1455. sym := definition^.first;
  1456. if sym = nil then
  1457. begin
  1458. definition^.first := @self;
  1459. next := nil;
  1460. exit;
  1461. end;
  1462. { reorder the symbols in increasing value }
  1463. if value < sym^.value then
  1464. begin
  1465. next := sym;
  1466. definition^.first := @self;
  1467. end
  1468. else
  1469. begin
  1470. while (sym^.value <= value) and assigned(sym^.next) do
  1471. sym := sym^.next;
  1472. next := sym^.next;
  1473. sym^.next := @self;
  1474. end;
  1475. end;
  1476. procedure tenumsym.write;
  1477. begin
  1478. tsym.write;
  1479. writedefref(definition);
  1480. writelong(value);
  1481. current_ppu^.writeentry(ibenumsym);
  1482. end;
  1483. {$ifdef GDB}
  1484. procedure tenumsym.concatstabto(asmlist : paasmoutput);
  1485. begin
  1486. {enum elements have no stab !}
  1487. end;
  1488. {$EndIf GDB}
  1489. {****************************************************************************
  1490. TTYPESYM
  1491. ****************************************************************************}
  1492. constructor ttypesym.init(const n : string;d : pdef);
  1493. begin
  1494. tsym.init(n);
  1495. typ:=typesym;
  1496. definition:=d;
  1497. {$ifdef GDB}
  1498. isusedinstab := false;
  1499. {$endif GDB}
  1500. forwardpointer:=nil;
  1501. { this allows to link definitions with the type with declares }
  1502. { them }
  1503. if assigned(definition) then
  1504. if definition^.sym=nil then
  1505. definition^.sym:=@self;
  1506. end;
  1507. constructor ttypesym.load;
  1508. begin
  1509. tsym.load;
  1510. typ:=typesym;
  1511. forwardpointer:=nil;
  1512. {$ifdef GDB}
  1513. isusedinstab := false;
  1514. {$endif GDB}
  1515. definition:=readdefref;
  1516. end;
  1517. destructor ttypesym.done;
  1518. begin
  1519. if assigned(definition) then
  1520. if definition^.sym=@self then
  1521. definition^.sym:=nil;
  1522. inherited done;
  1523. end;
  1524. procedure ttypesym.deref;
  1525. begin
  1526. resolvedef(definition);
  1527. if assigned(definition) then
  1528. begin
  1529. if definition^.sym=nil then
  1530. definition^.sym:=@self;
  1531. if (definition^.deftype=recorddef) and assigned(precdef(definition)^.symtable) and
  1532. (definition^.sym=@self) then
  1533. precdef(definition)^.symtable^.name:=stringdup('record '+name);
  1534. end;
  1535. end;
  1536. procedure ttypesym.write;
  1537. begin
  1538. tsym.write;
  1539. writedefref(definition);
  1540. current_ppu^.writeentry(ibtypesym);
  1541. end;
  1542. procedure ttypesym.load_references;
  1543. begin
  1544. inherited load_references;
  1545. if (definition^.deftype=recorddef) then
  1546. precdef(definition)^.symtable^.load_browser;
  1547. if (definition^.deftype=objectdef) then
  1548. pobjectdef(definition)^.publicsyms^.load_browser;
  1549. end;
  1550. function ttypesym.write_references : boolean;
  1551. begin
  1552. if not inherited write_references then
  1553. { write address of this symbol if record or object
  1554. even if no real refs are there
  1555. because we need it for the symtable }
  1556. if (definition^.deftype=recorddef) or
  1557. (definition^.deftype=objectdef) then
  1558. begin
  1559. writesymref(@self);
  1560. current_ppu^.writeentry(ibsymref);
  1561. end;
  1562. write_references:=true;
  1563. if (definition^.deftype=recorddef) then
  1564. precdef(definition)^.symtable^.write_browser;
  1565. if (definition^.deftype=objectdef) then
  1566. pobjectdef(definition)^.publicsyms^.write_browser;
  1567. end;
  1568. {$ifdef BrowserLog}
  1569. procedure ttypesym.add_to_browserlog;
  1570. begin
  1571. inherited add_to_browserlog;
  1572. if (definition^.deftype=recorddef) then
  1573. precdef(definition)^.symtable^.writebrowserlog;
  1574. if (definition^.deftype=objectdef) then
  1575. pobjectdef(definition)^.publicsyms^.writebrowserlog;
  1576. end;
  1577. {$endif BrowserLog}
  1578. {$ifdef GDB}
  1579. function ttypesym.stabstring : pchar;
  1580. var stabchar : string[2];
  1581. short : string;
  1582. begin
  1583. if definition^.deftype in tagtypes then
  1584. stabchar := 'Tt'
  1585. else
  1586. stabchar := 't';
  1587. short := '"'+name+':'+stabchar+definition^.numberstring
  1588. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  1589. stabstring := strpnew(short);
  1590. end;
  1591. procedure ttypesym.concatstabto(asmlist : paasmoutput);
  1592. begin
  1593. {not stabs for forward defs }
  1594. if assigned(definition) then
  1595. if (definition^.sym = @self) then
  1596. definition^.concatstabto(asmlist)
  1597. else
  1598. inherited concatstabto(asmlist);
  1599. end;
  1600. {$endif GDB}
  1601. {****************************************************************************
  1602. TSYSSYM
  1603. ****************************************************************************}
  1604. constructor tsyssym.init(const n : string;l : longint);
  1605. begin
  1606. inherited init(n);
  1607. typ:=syssym;
  1608. number:=l;
  1609. end;
  1610. procedure tsyssym.write;
  1611. begin
  1612. end;
  1613. {$ifdef GDB}
  1614. procedure tsyssym.concatstabto(asmlist : paasmoutput);
  1615. begin
  1616. end;
  1617. {$endif GDB}
  1618. {****************************************************************************
  1619. TMACROSYM
  1620. ****************************************************************************}
  1621. constructor tmacrosym.init(const n : string);
  1622. begin
  1623. inherited init(n);
  1624. typ:=macrosym;
  1625. defined:=true;
  1626. buftext:=nil;
  1627. buflen:=0;
  1628. end;
  1629. destructor tmacrosym.done;
  1630. begin
  1631. if assigned(buftext) then
  1632. freemem(buftext,buflen);
  1633. inherited done;
  1634. end;
  1635. {
  1636. $Log$
  1637. Revision 1.76 1999-03-31 13:55:21 peter
  1638. * assembler inlining working for ag386bin
  1639. Revision 1.75 1999/03/24 23:17:27 peter
  1640. * fixed bugs 212,222,225,227,229,231,233
  1641. Revision 1.74 1999/02/23 18:29:27 pierre
  1642. * win32 compilation error fix
  1643. + some work for local browser (not cl=omplete yet)
  1644. Revision 1.73 1999/02/22 13:07:09 pierre
  1645. + -b and -bl options work !
  1646. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  1647. is not enabled when quitting global section
  1648. * local vars and procedures are not yet stored into PPU
  1649. Revision 1.72 1999/02/08 09:51:22 pierre
  1650. * gdb info for local functions was wrong
  1651. Revision 1.71 1999/01/23 23:29:41 florian
  1652. * first running version of the new code generator
  1653. * when compiling exceptions under Linux fixed
  1654. Revision 1.70 1999/01/21 22:10:48 peter
  1655. * fixed array of const
  1656. * generic platform independent high() support
  1657. Revision 1.69 1999/01/20 10:20:20 peter
  1658. * don't make localvar copies for assembler procedures
  1659. Revision 1.68 1999/01/12 14:25:36 peter
  1660. + BrowserLog for browser.log generation
  1661. + BrowserCol for browser info in TCollections
  1662. * released all other UseBrowser
  1663. Revision 1.67 1998/12/30 22:15:54 peter
  1664. + farpointer type
  1665. * absolutesym now also stores if its far
  1666. Revision 1.66 1998/12/30 13:41:14 peter
  1667. * released valuepara
  1668. Revision 1.65 1998/12/26 15:35:44 peter
  1669. + read/write of constnil
  1670. Revision 1.64 1998/12/08 10:18:15 peter
  1671. + -gh for heaptrc unit
  1672. Revision 1.63 1998/11/28 16:20:56 peter
  1673. + support for dll variables
  1674. Revision 1.62 1998/11/27 14:50:48 peter
  1675. + open strings, $P switch support
  1676. Revision 1.61 1998/11/18 15:44:18 peter
  1677. * VALUEPARA for tp7 compatible value parameters
  1678. Revision 1.60 1998/11/16 10:13:51 peter
  1679. * label defines are checked at the end of the proc
  1680. Revision 1.59 1998/11/13 12:09:11 peter
  1681. * unused label is now a warning
  1682. Revision 1.58 1998/11/10 10:50:57 pierre
  1683. * temporary fix for long mangled procsym names
  1684. Revision 1.57 1998/11/05 23:39:31 peter
  1685. + typedconst.getsize
  1686. Revision 1.56 1998/10/28 18:26:18 pierre
  1687. * removed some erros after other errors (introduced by useexcept)
  1688. * stabs works again correctly (for how long !)
  1689. Revision 1.55 1998/10/20 08:07:00 pierre
  1690. * several memory corruptions due to double freemem solved
  1691. => never use p^.loc.location:=p^.left^.loc.location;
  1692. + finally I added now by default
  1693. that ra386dir translates global and unit symbols
  1694. + added a first field in tsymtable and
  1695. a nextsym field in tsym
  1696. (this allows to obtain ordered type info for
  1697. records and objects in gdb !)
  1698. Revision 1.54 1998/10/19 08:55:07 pierre
  1699. * wrong stabs info corrected once again !!
  1700. + variable vmt offset with vmt field only if required
  1701. implemented now !!!
  1702. Revision 1.53 1998/10/16 08:51:53 peter
  1703. + target_os.stackalignment
  1704. + stack can be aligned at 2 or 4 byte boundaries
  1705. Revision 1.52 1998/10/08 17:17:32 pierre
  1706. * current_module old scanner tagged as invalid if unit is recompiled
  1707. + added ppheap for better info on tracegetmem of heaptrc
  1708. (adds line column and file index)
  1709. * several memory leaks removed ith help of heaptrc !!
  1710. Revision 1.51 1998/10/08 13:48:50 peter
  1711. * fixed memory leaks for do nothing source
  1712. * fixed unit interdependency
  1713. Revision 1.50 1998/10/06 17:16:56 pierre
  1714. * some memory leaks fixed (thanks to Peter for heaptrc !)
  1715. Revision 1.49 1998/10/01 09:22:55 peter
  1716. * fixed value openarray
  1717. * ungettemp of arrayconstruct
  1718. Revision 1.48 1998/09/26 17:45:44 peter
  1719. + idtoken and only one token table
  1720. Revision 1.47 1998/09/24 15:11:17 peter
  1721. * fixed enum for not GDB
  1722. Revision 1.46 1998/09/23 15:39:13 pierre
  1723. * browser bugfixes
  1724. was adding a reference when looking for the symbol
  1725. if -bSYM_NAME was used
  1726. Revision 1.45 1998/09/21 08:45:24 pierre
  1727. + added vmt_offset in tobjectdef.write for fututre use
  1728. (first steps to have objects without vmt if no virtual !!)
  1729. + added fpu_used field for tabstractprocdef :
  1730. sets this level to 2 if the functions return with value in FPU
  1731. (is then set to correct value at parsing of implementation)
  1732. THIS MIGHT refuse some code with FPU expression too complex
  1733. that were accepted before and even in some cases
  1734. that don't overflow in fact
  1735. ( like if f : float; is a forward that finally in implementation
  1736. only uses one fpu register !!)
  1737. Nevertheless I think that it will improve security on
  1738. FPU operations !!
  1739. * most other changes only for UseBrowser code
  1740. (added symtable references for record and objects)
  1741. local switch for refs to args and local of each function
  1742. (static symtable still missing)
  1743. UseBrowser still not stable and probably broken by
  1744. the definition hash array !!
  1745. Revision 1.44 1998/09/18 16:03:47 florian
  1746. * some changes to compile with Delphi
  1747. Revision 1.43 1998/09/18 08:01:38 pierre
  1748. + improvement on the usebrowser part
  1749. (does not work correctly for now)
  1750. Revision 1.42 1998/09/07 19:33:25 florian
  1751. + some stuff for property rtti added:
  1752. - NameIndex of the TPropInfo record is now written correctly
  1753. - the DEFAULT/NODEFAULT keyword is supported now
  1754. - the default value and the storedsym/def are now written to
  1755. the PPU fiel
  1756. Revision 1.41 1998/09/07 18:46:12 peter
  1757. * update smartlinking, uses getdatalabel
  1758. * renamed ptree.value vars to value_str,value_real,value_set
  1759. Revision 1.40 1998/09/07 17:37:04 florian
  1760. * first fixes for published properties
  1761. Revision 1.39 1998/09/05 22:11:02 florian
  1762. + switch -vb
  1763. * while/repeat loops accept now also word/longbool conditions
  1764. * makebooltojump did an invalid ungetregister32, fixed
  1765. Revision 1.38 1998/09/01 12:53:26 peter
  1766. + aktpackenum
  1767. Revision 1.37 1998/09/01 07:54:25 pierre
  1768. * UseBrowser a little updated (might still be buggy !!)
  1769. * bug in psub.pas in function specifier removed
  1770. * stdcall allowed in interface and in implementation
  1771. (FPC will not yet complain if it is missing in either part
  1772. because stdcall is only a dummy !!)
  1773. Revision 1.36 1998/08/25 13:09:26 pierre
  1774. * corrected mangling sheme :
  1775. cvar add Cprefix to the mixed case name whereas
  1776. export or public use direct name
  1777. Revision 1.35 1998/08/25 12:42:46 pierre
  1778. * CDECL changed to CVAR for variables
  1779. specifications are read in structures also
  1780. + started adding GPC compatibility mode ( option -Sp)
  1781. * names changed to lowercase
  1782. Revision 1.34 1998/08/21 14:08:53 pierre
  1783. + TEST_FUNCRET now default (old code removed)
  1784. works also for m68k (at least compiles)
  1785. Revision 1.33 1998/08/20 12:53:27 peter
  1786. * object_options are always written for object syms
  1787. Revision 1.32 1998/08/20 09:26:46 pierre
  1788. + funcret setting in underproc testing
  1789. compile with _dTEST_FUNCRET
  1790. Revision 1.31 1998/08/17 10:10:12 peter
  1791. - removed OLDPPU
  1792. Revision 1.30 1998/08/13 10:57:29 peter
  1793. * constant sets are now written correctly to the ppufile
  1794. Revision 1.29 1998/08/11 15:31:42 peter
  1795. * write extended to ppu file
  1796. * new version 0.99.7
  1797. Revision 1.28 1998/08/11 14:07:27 peter
  1798. * fixed pushing of high value for openarray
  1799. Revision 1.27 1998/08/10 14:50:31 peter
  1800. + localswitches, moduleswitches, globalswitches splitting
  1801. Revision 1.26 1998/08/10 10:18:35 peter
  1802. + Compiler,Comphook unit which are the new interface units to the
  1803. compiler
  1804. Revision 1.25 1998/07/30 11:18:19 florian
  1805. + first implementation of try ... except on .. do end;
  1806. * limitiation of 65535 bytes parameters for cdecl removed
  1807. Revision 1.24 1998/07/20 18:40:16 florian
  1808. * handling of ansi string constants should now work
  1809. Revision 1.23 1998/07/14 21:37:24 peter
  1810. * fixed packrecords as discussed at the alias
  1811. Revision 1.22 1998/07/14 14:47:08 peter
  1812. * released NEWINPUT
  1813. Revision 1.21 1998/07/13 21:17:38 florian
  1814. * changed to compile with TP
  1815. Revision 1.20 1998/07/10 00:00:05 peter
  1816. * fixed ttypesym bug finally
  1817. * fileinfo in the symtable and better using for unused vars
  1818. Revision 1.19 1998/07/07 17:40:39 peter
  1819. * packrecords 4 works
  1820. * word aligning of parameters
  1821. Revision 1.18 1998/07/07 11:20:15 peter
  1822. + NEWINPUT for a better inputfile and scanner object
  1823. Revision 1.17 1998/06/24 14:48:40 peter
  1824. * ifdef newppu -> ifndef oldppu
  1825. Revision 1.16 1998/06/19 15:40:42 peter
  1826. * removed cosntructor/constructor warning and 0.99.5 recompiles it again
  1827. Revision 1.15 1998/06/17 14:10:18 peter
  1828. * small os2 fixes
  1829. * fixed interdependent units with newppu (remake3 under linux works now)
  1830. Revision 1.14 1998/06/16 08:56:34 peter
  1831. + targetcpu
  1832. * cleaner pmodules for newppu
  1833. Revision 1.13 1998/06/15 15:38:10 pierre
  1834. * small bug in systems.pas corrected
  1835. + operators in different units better hanlded
  1836. Revision 1.12 1998/06/15 14:23:44 daniel
  1837. * Reverted my changes.
  1838. Revision 1.10 1998/06/13 00:10:18 peter
  1839. * working browser and newppu
  1840. * some small fixes against crashes which occured in bp7 (but not in
  1841. fpc?!)
  1842. Revision 1.9 1998/06/12 16:15:35 pierre
  1843. * external name 'C_var';
  1844. export name 'intern_C_var';
  1845. cdecl;
  1846. cdecl;external;
  1847. are now supported only with -Sv switch
  1848. Revision 1.8 1998/06/11 10:11:59 peter
  1849. * -gb works again
  1850. Revision 1.7 1998/06/09 16:01:51 pierre
  1851. + added procedure directive parsing for procvars
  1852. (accepted are popstack cdecl and pascal)
  1853. + added C vars with the following syntax
  1854. var C calias 'true_c_name';(can be followed by external)
  1855. reason is that you must add the Cprefix
  1856. which is target dependent
  1857. Revision 1.6 1998/06/08 22:59:53 peter
  1858. * smartlinking works for win32
  1859. * some defines to exclude some compiler parts
  1860. Revision 1.5 1998/06/04 23:52:02 peter
  1861. * m68k compiles
  1862. + .def file creation moved to gendef.pas so it could also be used
  1863. for win32
  1864. Revision 1.4 1998/06/04 09:55:46 pierre
  1865. * demangled name of procsym reworked to become independant of the mangling scheme
  1866. Revision 1.3 1998/06/03 22:14:20 florian
  1867. * problem with sizes of classes fixed (if the anchestor was declared
  1868. forward, the compiler doesn't update the child classes size)
  1869. Revision 1.2 1998/05/28 14:40:29 peter
  1870. * fixes for newppu, remake3 works now with it
  1871. Revision 1.1 1998/05/27 19:45:09 peter
  1872. * symtable.pas splitted into includefiles
  1873. * symtable adapted for $ifndef OLDPPU
  1874. }