symsym.inc 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225
  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. inherited initname(n);
  24. typ:=abstractsym;
  25. symoptions:=current_object_option;
  26. {$ifdef GDB}
  27. isstabwritten := false;
  28. {$endif GDB}
  29. fileinfo:=tokenpos;
  30. defref:=nil;
  31. lastwritten:=nil;
  32. refcount:=0;
  33. if (cs_browser in aktmoduleswitches) and make_ref then
  34. begin
  35. defref:=new(pref,init(defref,@tokenpos));
  36. inc(refcount);
  37. end;
  38. lastref:=defref;
  39. end;
  40. constructor tsym.load;
  41. begin
  42. inherited init;
  43. indexnr:=readword;
  44. setname(readstring);
  45. typ:=abstractsym;
  46. readsmallset(symoptions);
  47. readposinfo(fileinfo);
  48. lastref:=nil;
  49. defref:=nil;
  50. lastwritten:=nil;
  51. refcount:=0;
  52. {$ifdef GDB}
  53. isstabwritten := false;
  54. {$endif GDB}
  55. end;
  56. procedure tsym.load_references;
  57. var
  58. pos : tfileposinfo;
  59. move_last : boolean;
  60. begin
  61. move_last:=lastwritten=lastref;
  62. while (not current_ppu^.endofentry) do
  63. begin
  64. readposinfo(pos);
  65. inc(refcount);
  66. lastref:=new(pref,init(lastref,@pos));
  67. lastref^.is_written:=true;
  68. if refcount=1 then
  69. defref:=lastref;
  70. end;
  71. if move_last then
  72. lastwritten:=lastref;
  73. end;
  74. { big problem here :
  75. wrong refs were written because of
  76. interface parsing of other units PM
  77. moduleindex must be checked !! }
  78. function tsym.write_references : boolean;
  79. var
  80. ref : pref;
  81. symref_written,move_last : boolean;
  82. begin
  83. write_references:=false;
  84. if lastwritten=lastref then
  85. exit;
  86. { should we update lastref }
  87. move_last:=true;
  88. symref_written:=false;
  89. { write symbol refs }
  90. if assigned(lastwritten) then
  91. ref:=lastwritten
  92. else
  93. ref:=defref;
  94. while assigned(ref) do
  95. begin
  96. if ref^.moduleindex=current_module^.unit_index then
  97. begin
  98. { write address to this symbol }
  99. if not symref_written then
  100. begin
  101. writesymref(@self);
  102. symref_written:=true;
  103. end;
  104. writeposinfo(ref^.posinfo);
  105. ref^.is_written:=true;
  106. if move_last then
  107. lastwritten:=ref;
  108. end
  109. else if not ref^.is_written then
  110. move_last:=false
  111. else if move_last then
  112. lastwritten:=ref;
  113. ref:=ref^.nextref;
  114. end;
  115. if symref_written then
  116. current_ppu^.writeentry(ibsymref);
  117. write_references:=symref_written;
  118. end;
  119. {$ifdef BrowserLog}
  120. procedure tsym.add_to_browserlog;
  121. begin
  122. if assigned(defref) then
  123. begin
  124. browserlog.AddLog('***'+name+'***');
  125. browserlog.AddLogRefs(defref);
  126. end;
  127. end;
  128. {$endif BrowserLog}
  129. destructor tsym.done;
  130. begin
  131. if assigned(defref) then
  132. dispose(defref,done);
  133. inherited done;
  134. end;
  135. procedure tsym.write;
  136. begin
  137. writeword(indexnr);
  138. writestring(name);
  139. writesmallset(symoptions);
  140. writeposinfo(fileinfo);
  141. end;
  142. procedure tsym.deref;
  143. begin
  144. end;
  145. function tsym.mangledname : string;
  146. begin
  147. mangledname:=name;
  148. end;
  149. { for most symbol types there is nothing to do at all }
  150. procedure tsym.insert_in_data;
  151. begin
  152. end;
  153. {$ifdef GDB}
  154. function tsym.stabstring : pchar;
  155. begin
  156. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  157. tostr(fileinfo.line)+',0');
  158. end;
  159. procedure tsym.concatstabto(asmlist : paasmoutput);
  160. var stab_str : pchar;
  161. begin
  162. if not isstabwritten then
  163. begin
  164. stab_str := stabstring;
  165. { count_dbx(stab_str); moved to GDB.PAS }
  166. asmlist^.concat(new(pai_stabs,init(stab_str)));
  167. isstabwritten:=true;
  168. end;
  169. end;
  170. {$endif GDB}
  171. {****************************************************************************
  172. TLABELSYM
  173. ****************************************************************************}
  174. constructor tlabelsym.init(const n : string; l : pasmlabel);
  175. begin
  176. inherited init(n);
  177. typ:=labelsym;
  178. lab:=l;
  179. defined:=false;
  180. end;
  181. constructor tlabelsym.load;
  182. begin
  183. tsym.load;
  184. typ:=labelsym;
  185. { this is all dummy
  186. it is only used for local browsing }
  187. lab:=nil;
  188. defined:=true;
  189. end;
  190. destructor tlabelsym.done;
  191. begin
  192. inherited done;
  193. end;
  194. function tlabelsym.mangledname : string;
  195. begin
  196. mangledname:=lab^.name;
  197. end;
  198. procedure tlabelsym.write;
  199. begin
  200. if owner^.symtabletype in [unitsymtable,globalsymtable] then
  201. Message(sym_e_ill_label_decl)
  202. else
  203. begin
  204. tsym.write;
  205. current_ppu^.writeentry(iblabelsym);
  206. end;
  207. end;
  208. {****************************************************************************
  209. TUNITSYM
  210. ****************************************************************************}
  211. constructor tunitsym.init(const n : string;ref : punitsymtable);
  212. var
  213. old_make_ref : boolean;
  214. begin
  215. old_make_ref:=make_ref;
  216. make_ref:=false;
  217. inherited init(n);
  218. make_ref:=old_make_ref;
  219. typ:=unitsym;
  220. unitsymtable:=ref;
  221. prevsym:=ref^.unitsym;
  222. ref^.unitsym:=@self;
  223. refs:=0;
  224. end;
  225. constructor tunitsym.load;
  226. begin
  227. tsym.load;
  228. typ:=unitsym;
  229. unitsymtable:=punitsymtable(current_module^.globalsymtable);
  230. prevsym:=nil;
  231. end;
  232. { we need to remove it from the prevsym chain ! }
  233. destructor tunitsym.done;
  234. var pus,ppus : punitsym;
  235. begin
  236. if assigned(unitsymtable) then
  237. begin
  238. ppus:=nil;
  239. pus:=unitsymtable^.unitsym;
  240. if pus=@self then
  241. unitsymtable^.unitsym:=prevsym
  242. else while assigned(pus) do
  243. begin
  244. if pus=@self then
  245. begin
  246. ppus^.prevsym:=prevsym;
  247. break;
  248. end
  249. else
  250. begin
  251. ppus:=pus;
  252. pus:=ppus^.prevsym;
  253. end;
  254. end;
  255. end;
  256. prevsym:=nil;
  257. unitsymtable:=nil;
  258. inherited done;
  259. end;
  260. procedure tunitsym.write;
  261. begin
  262. tsym.write;
  263. current_ppu^.writeentry(ibunitsym);
  264. end;
  265. {$ifdef GDB}
  266. procedure tunitsym.concatstabto(asmlist : paasmoutput);
  267. begin
  268. {Nothing to write to stabs !}
  269. end;
  270. {$endif GDB}
  271. {****************************************************************************
  272. TPROCSYM
  273. ****************************************************************************}
  274. constructor tprocsym.init(const n : string);
  275. begin
  276. tsym.init(n);
  277. typ:=procsym;
  278. definition:=nil;
  279. owner:=nil;
  280. {$ifdef GDB}
  281. is_global := false;
  282. {$endif GDB}
  283. end;
  284. constructor tprocsym.load;
  285. begin
  286. tsym.load;
  287. typ:=procsym;
  288. definition:=pprocdef(readdefref);
  289. {$ifdef GDB}
  290. is_global := false;
  291. {$endif GDB}
  292. end;
  293. destructor tprocsym.done;
  294. begin
  295. { don't check if errors !! }
  296. if Errorcount=0 then
  297. check_forward;
  298. tsym.done;
  299. end;
  300. function tprocsym.mangledname : string;
  301. begin
  302. mangledname:=definition^.mangledname;
  303. end;
  304. function tprocsym.demangledname:string;
  305. begin
  306. demangledname:=name+definition^.demangled_paras;
  307. end;
  308. procedure tprocsym.write_parameter_lists;
  309. var
  310. p : pprocdef;
  311. begin
  312. p:=definition;
  313. while assigned(p) do
  314. begin
  315. { force the error to be printed }
  316. Verbose.Message1(sym_b_param_list,name+p^.demangled_paras);
  317. p:=p^.nextoverloaded;
  318. end;
  319. end;
  320. procedure tprocsym.check_forward;
  321. var
  322. pd : pprocdef;
  323. begin
  324. pd:=definition;
  325. while assigned(pd) do
  326. begin
  327. if pd^.forwarddef then
  328. begin
  329. if assigned(pd^._class) then
  330. MessagePos1(fileinfo,sym_e_forward_not_resolved,pd^._class^.objname^+'.'+demangledname)
  331. else
  332. MessagePos1(fileinfo,sym_e_forward_not_resolved,demangledname);
  333. { Turn futher error messages off }
  334. pd^.forwarddef:=false;
  335. end;
  336. pd:=pd^.nextoverloaded;
  337. end;
  338. end;
  339. procedure tprocsym.deref;
  340. var
  341. t : ttoken;
  342. last : pprocdef;
  343. begin
  344. resolvedef(pdef(definition));
  345. if (definition^.proctypeoption=potype_operator) then
  346. begin
  347. last:=definition;
  348. while assigned(last^.nextoverloaded) do
  349. last:=last^.nextoverloaded;
  350. for t:=first_overloaded to last_overloaded do
  351. if (name=overloaded_names[t]) then
  352. begin
  353. if assigned(overloaded_operators[t]) then
  354. last^.nextoverloaded:=overloaded_operators[t]^.definition;
  355. overloaded_operators[t]:=@self;
  356. end;
  357. end;
  358. end;
  359. procedure tprocsym.write;
  360. begin
  361. tsym.write;
  362. writedefref(pdef(definition));
  363. current_ppu^.writeentry(ibprocsym);
  364. end;
  365. procedure tprocsym.load_references;
  366. (*var
  367. prdef,prdef2 : pprocdef;
  368. b : byte; *)
  369. begin
  370. inherited load_references;
  371. (*prdef:=definition;
  372. done in tsymtable.load_browser (PM)
  373. { take care about operators !! }
  374. if (current_module^.flags and uf_has_browser) <>0 then
  375. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  376. begin
  377. b:=current_ppu^.readentry;
  378. if b<>ibdefref then
  379. Message(unit_f_ppu_read_error);
  380. prdef2:=pprocdef(readdefref);
  381. resolvedef(prdef2);
  382. if prdef<>prdef2 then
  383. Message(unit_f_ppu_read_error);
  384. prdef^.load_references;
  385. prdef:=prdef^.nextoverloaded;
  386. end; *)
  387. end;
  388. function tprocsym.write_references : boolean;
  389. var
  390. prdef : pprocdef;
  391. begin
  392. write_references:=false;
  393. if not inherited write_references then
  394. exit;
  395. write_references:=true;
  396. prdef:=definition;
  397. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  398. begin
  399. prdef^.write_references;
  400. prdef:=prdef^.nextoverloaded;
  401. end;
  402. end;
  403. {$ifdef BrowserLog}
  404. procedure tprocsym.add_to_browserlog;
  405. var
  406. prdef : pprocdef;
  407. begin
  408. inherited add_to_browserlog;
  409. prdef:=definition;
  410. while assigned(prdef) do
  411. begin
  412. pprocdef(prdef)^.add_to_browserlog;
  413. prdef:=pprocdef(prdef)^.nextoverloaded;
  414. end;
  415. end;
  416. {$endif BrowserLog}
  417. {$ifdef GDB}
  418. function tprocsym.stabstring : pchar;
  419. Var RetType : Char;
  420. Obj,Info : String;
  421. stabsstr : string;
  422. p : pchar;
  423. begin
  424. obj := name;
  425. info := '';
  426. if is_global then
  427. RetType := 'F'
  428. else
  429. RetType := 'f';
  430. if assigned(owner) then
  431. begin
  432. if (owner^.symtabletype = objectsymtable) then
  433. obj := owner^.name^+'__'+name;
  434. { this code was correct only as long as the local symboltable
  435. of the parent had the same name as the function
  436. but this is no true anymore !! PM
  437. if (owner^.symtabletype=localsymtable) and assigned(owner^.name) then
  438. info := ','+name+','+owner^.name^; }
  439. if (owner^.symtabletype=localsymtable) and assigned(owner^.defowner) and
  440. assigned(pprocdef(owner^.defowner)^.procsym) then
  441. info := ','+name+','+pprocdef(owner^.defowner)^.procsym^.name;
  442. end;
  443. stabsstr:=definition^.mangledname;
  444. getmem(p,length(stabsstr)+255);
  445. strpcopy(p,'"'+obj+':'+RetType
  446. +definition^.retdef^.numberstring+info+'",'+tostr(n_function)
  447. +',0,'+
  448. tostr(aktfilepos.line)
  449. +',');
  450. strpcopy(strend(p),stabsstr);
  451. stabstring:=strnew(p);
  452. freemem(p,length(stabsstr)+255);
  453. end;
  454. procedure tprocsym.concatstabto(asmlist : paasmoutput);
  455. begin
  456. if (pocall_internproc in definition^.proccalloptions) then exit;
  457. if not isstabwritten then
  458. asmlist^.concat(new(pai_stabs,init(stabstring)));
  459. isstabwritten := true;
  460. if assigned(definition^.parast) then
  461. definition^.parast^.concatstabto(asmlist);
  462. if assigned(definition^.localst) then
  463. definition^.localst^.concatstabto(asmlist);
  464. definition^.is_def_stab_written := true;
  465. end;
  466. {$endif GDB}
  467. {****************************************************************************
  468. TPROGRAMSYM
  469. ****************************************************************************}
  470. constructor tprogramsym.init(const n : string);
  471. begin
  472. inherited init(n);
  473. typ:=programsym;
  474. end;
  475. {****************************************************************************
  476. TERRORSYM
  477. ****************************************************************************}
  478. constructor terrorsym.init;
  479. begin
  480. inherited init('');
  481. typ:=errorsym;
  482. end;
  483. {****************************************************************************
  484. TPROPERTYSYM
  485. ****************************************************************************}
  486. constructor tpropertysym.init(const n : string);
  487. begin
  488. inherited init(n);
  489. typ:=propertysym;
  490. propoptions:=[];
  491. proptype:=nil;
  492. readaccessdef:=nil;
  493. writeaccessdef:=nil;
  494. readaccesssym:=nil;
  495. writeaccesssym:=nil;
  496. storedsym:=nil;
  497. storeddef:=nil;
  498. index:=0;
  499. default:=0;
  500. end;
  501. destructor tpropertysym.done;
  502. procedure disposepropsymlist(p:ppropsymlist);
  503. var
  504. hp : ppropsymlist;
  505. begin
  506. while assigned(p) do
  507. begin
  508. hp:=p;
  509. p:=p^.next;
  510. dispose(hp);
  511. end;
  512. end;
  513. begin
  514. disposepropsymlist(readaccesssym);
  515. disposepropsymlist(writeaccesssym);
  516. disposepropsymlist(storedsym);
  517. inherited done;
  518. end;
  519. constructor tpropertysym.load;
  520. function readpropsymlist:ppropsymlist;
  521. var
  522. root,last,p : ppropsymlist;
  523. sym : psym;
  524. begin
  525. root:=nil;
  526. last:=nil;
  527. repeat
  528. sym:=readsymref;
  529. if sym=nil then
  530. break;
  531. new(p);
  532. p^.sym:=sym;
  533. p^.next:=nil;
  534. if assigned(last) then
  535. last^.next:=p
  536. else
  537. root:=p;
  538. last:=p;
  539. until false;
  540. readpropsymlist:=root;
  541. end;
  542. begin
  543. inherited load;
  544. typ:=propertysym;
  545. proptype:=readdefref;
  546. readsmallset(propoptions);
  547. index:=readlong;
  548. default:=readlong;
  549. { the syms }
  550. readaccesssym:=readpropsymlist;
  551. writeaccesssym:=readpropsymlist;
  552. storedsym:=readpropsymlist;
  553. { now the defs }
  554. readaccessdef:=readdefref;
  555. writeaccessdef:=readdefref;
  556. storeddef:=readdefref;
  557. end;
  558. procedure tpropertysym.deref;
  559. procedure resolvepropsymlist(p:ppropsymlist);
  560. begin
  561. while assigned(p) do
  562. begin
  563. resolvesym(p^.sym);
  564. p:=p^.next;
  565. end;
  566. end;
  567. begin
  568. resolvedef(proptype);
  569. resolvedef(readaccessdef);
  570. resolvedef(writeaccessdef);
  571. resolvedef(storeddef);
  572. resolvepropsymlist(readaccesssym);
  573. resolvepropsymlist(writeaccesssym);
  574. resolvepropsymlist(storedsym);
  575. end;
  576. function tpropertysym.getsize : longint;
  577. begin
  578. getsize:=0;
  579. end;
  580. procedure tpropertysym.write;
  581. procedure writepropsymlist(p:ppropsymlist);
  582. begin
  583. while assigned(p) do
  584. begin
  585. writesymref(p^.sym);
  586. p:=p^.next;
  587. end;
  588. writesymref(nil);
  589. end;
  590. begin
  591. tsym.write;
  592. writedefref(proptype);
  593. writesmallset(propoptions);
  594. writelong(index);
  595. writelong(default);
  596. writepropsymlist(readaccesssym);
  597. writepropsymlist(writeaccesssym);
  598. writepropsymlist(storedsym);
  599. writedefref(readaccessdef);
  600. writedefref(writeaccessdef);
  601. writedefref(storeddef);
  602. current_ppu^.writeentry(ibpropertysym);
  603. end;
  604. {$ifdef GDB}
  605. function tpropertysym.stabstring : pchar;
  606. begin
  607. { !!!! don't know how to handle }
  608. stabstring:=strpnew('');
  609. end;
  610. procedure tpropertysym.concatstabto(asmlist : paasmoutput);
  611. begin
  612. { !!!! don't know how to handle }
  613. end;
  614. {$endif GDB}
  615. {****************************************************************************
  616. TFUNCRETSYM
  617. ****************************************************************************}
  618. constructor tfuncretsym.init(const n : string;approcinfo : pointer{pprocinfo});
  619. begin
  620. tsym.init(n);
  621. typ:=funcretsym;
  622. funcretprocinfo:=approcinfo;
  623. funcretdef:=pprocinfo(approcinfo)^.retdef;
  624. { address valid for ret in param only }
  625. { otherwise set by insert }
  626. address:=pprocinfo(approcinfo)^.retoffset;
  627. end;
  628. constructor tfuncretsym.load;
  629. begin
  630. tsym.load;
  631. funcretdef:=readdefref;
  632. address:=readlong;
  633. funcretprocinfo:=nil;
  634. typ:=funcretsym;
  635. end;
  636. procedure tfuncretsym.write;
  637. begin
  638. tsym.write;
  639. writedefref(funcretdef);
  640. writelong(address);
  641. current_ppu^.writeentry(ibfuncretsym);
  642. end;
  643. procedure tfuncretsym.deref;
  644. begin
  645. resolvedef(funcretdef);
  646. end;
  647. {$ifdef GDB}
  648. procedure tfuncretsym.concatstabto(asmlist : paasmoutput);
  649. begin
  650. { Nothing to do here, it is done in genexitcode }
  651. end;
  652. {$endif GDB}
  653. procedure tfuncretsym.insert_in_data;
  654. var
  655. l : longint;
  656. begin
  657. { if retoffset is already set then reuse it, this is needed
  658. when inserting the result variable }
  659. if procinfo^.retoffset<>0 then
  660. address:=procinfo^.retoffset
  661. else
  662. begin
  663. { allocate space in local if ret in acc or in fpu }
  664. if ret_in_acc(procinfo^.retdef) or (procinfo^.retdef^.deftype=floatdef) then
  665. begin
  666. l:=funcretdef^.size;
  667. inc(owner^.datasize,l);
  668. {$ifdef m68k}
  669. { word alignment required for motorola }
  670. if (l=1) then
  671. inc(owner^.datasize,1)
  672. else
  673. {$endif}
  674. if (l>=4) and ((owner^.datasize and 3)<>0) then
  675. inc(owner^.datasize,4-(owner^.datasize and 3))
  676. else if (l>=2) and ((owner^.datasize and 1)<>0) then
  677. inc(owner^.datasize,2-(owner^.datasize and 1));
  678. address:=owner^.datasize;
  679. procinfo^.retoffset:=-owner^.datasize;
  680. end;
  681. end;
  682. end;
  683. {****************************************************************************
  684. TABSOLUTESYM
  685. ****************************************************************************}
  686. constructor tabsolutesym.init(const n : string;p : pdef);
  687. begin
  688. inherited init(n,p);
  689. typ:=absolutesym;
  690. end;
  691. constructor tabsolutesym.load;
  692. begin
  693. tvarsym.load;
  694. typ:=absolutesym;
  695. ref:=nil;
  696. address:=0;
  697. asmname:=nil;
  698. abstyp:=absolutetyp(readbyte);
  699. absseg:=false;
  700. case abstyp of
  701. tovar :
  702. begin
  703. asmname:=stringdup(readstring);
  704. ref:=srsym;
  705. end;
  706. toasm :
  707. asmname:=stringdup(readstring);
  708. toaddr :
  709. begin
  710. address:=readlong;
  711. absseg:=boolean(readbyte);
  712. end;
  713. end;
  714. end;
  715. procedure tabsolutesym.write;
  716. var
  717. hvo : tvaroptions;
  718. begin
  719. { Note: This needs to write everything of tvarsym.write }
  720. tsym.write;
  721. writebyte(byte(varspez));
  722. if read_member then
  723. writelong(address);
  724. { write only definition or definitionsym }
  725. if assigned(definitionsym) then
  726. begin
  727. writedefref(nil);
  728. writesymref(definitionsym);
  729. end
  730. else
  731. begin
  732. writedefref(definition);
  733. writesymref(nil);
  734. end;
  735. hvo:=varoptions-[vo_regable];
  736. writesmallset(hvo);
  737. writebyte(byte(abstyp));
  738. case abstyp of
  739. tovar :
  740. writestring(ref^.name);
  741. toasm :
  742. writestring(asmname^);
  743. toaddr :
  744. begin
  745. writelong(address);
  746. writebyte(byte(absseg));
  747. end;
  748. end;
  749. current_ppu^.writeentry(ibabsolutesym);
  750. end;
  751. procedure tabsolutesym.deref;
  752. begin
  753. tvarsym.deref;
  754. if (abstyp=tovar) and (asmname<>nil) then
  755. begin
  756. { search previous loaded symtables }
  757. getsym(asmname^,false);
  758. if not(assigned(srsym)) then
  759. getsymonlyin(owner,asmname^);
  760. if not(assigned(srsym)) then
  761. srsym:=generrorsym;
  762. ref:=srsym;
  763. stringdispose(asmname);
  764. end;
  765. end;
  766. function tabsolutesym.mangledname : string;
  767. begin
  768. case abstyp of
  769. tovar :
  770. mangledname:=ref^.mangledname;
  771. toasm :
  772. mangledname:=asmname^;
  773. toaddr :
  774. mangledname:='$'+tostr(address);
  775. else
  776. internalerror(10002);
  777. end;
  778. end;
  779. procedure tabsolutesym.insert_in_data;
  780. begin
  781. end;
  782. {$ifdef GDB}
  783. procedure tabsolutesym.concatstabto(asmlist : paasmoutput);
  784. begin
  785. { I don't know how to handle this !! }
  786. end;
  787. {$endif GDB}
  788. {****************************************************************************
  789. TVARSYM
  790. ****************************************************************************}
  791. constructor tvarsym.init(const n : string;p : pdef);
  792. begin
  793. tsym.init(n);
  794. typ:=varsym;
  795. definition:=p;
  796. definitionsym:=nil;
  797. _mangledname:=nil;
  798. varspez:=vs_value;
  799. address:=0;
  800. islocalcopy:=false;
  801. localvarsym:=nil;
  802. refs:=0;
  803. varstate:=vs_used;
  804. varoptions:=[];
  805. { can we load the value into a register ? }
  806. if p^.is_intregable then
  807. {$ifdef INCLUDEOK}
  808. include(varoptions,vo_regable)
  809. {$else}
  810. varoptions:=varoptions+[vo_regable]
  811. {$endif}
  812. else
  813. {$ifdef INCLUDEOK}
  814. exclude(varoptions,vo_regable);
  815. {$else}
  816. varoptions:=varoptions-[vo_regable];
  817. {$endif}
  818. if p^.is_fpuregable then
  819. {$ifdef INCLUDEOK}
  820. include(varoptions,vo_fpuregable)
  821. {$else}
  822. varoptions:=varoptions+[vo_fpuregable]
  823. {$endif}
  824. else
  825. {$ifdef INCLUDEOK}
  826. exclude(varoptions,vo_regable);
  827. {$else}
  828. varoptions:=varoptions-[vo_fpuregable];
  829. {$endif}
  830. reg:=R_NO;
  831. end;
  832. constructor tvarsym.init_dll(const n : string;p : pdef);
  833. begin
  834. { The tvarsym is necessary for 0.99.5 (PFV) }
  835. tvarsym.init(n,p);
  836. {$ifdef INCLUDEOK}
  837. include(varoptions,vo_is_dll_var);
  838. {$else}
  839. varoptions:=varoptions+[vo_is_dll_var];
  840. {$endif}
  841. end;
  842. constructor tvarsym.init_C(const n,mangled : string;p : pdef);
  843. begin
  844. { The tvarsym is necessary for 0.99.5 (PFV) }
  845. tvarsym.init(n,p);
  846. {$ifdef INCLUDEOK}
  847. include(varoptions,vo_is_C_var);
  848. {$else}
  849. varoptions:=varoptions+[vo_is_C_var];
  850. {$endif}
  851. setmangledname(mangled);
  852. end;
  853. constructor tvarsym.initsym(const n : string;p : ptypesym);
  854. begin
  855. tvarsym.init(n,p^.definition);
  856. definitionsym:=p;
  857. end;
  858. constructor tvarsym.initsym_dll(const n : string;p : ptypesym);
  859. begin
  860. tvarsym.init_dll(n,p^.definition);
  861. definitionsym:=p;
  862. end;
  863. constructor tvarsym.initsym_C(const n,mangled : string;p : ptypesym);
  864. begin
  865. tvarsym.init_C(n,mangled,p^.definition);
  866. definitionsym:=p;
  867. end;
  868. constructor tvarsym.load;
  869. begin
  870. tsym.load;
  871. typ:=varsym;
  872. _mangledname:=nil;
  873. reg:=R_NO;
  874. refs := 0;
  875. varstate:=vs_used;
  876. varspez:=tvarspez(readbyte);
  877. if read_member then
  878. address:=readlong
  879. else
  880. address:=0;
  881. islocalcopy:=false;
  882. localvarsym:=nil;
  883. definition:=readdefref;
  884. definitionsym:=ptypesym(readsymref);
  885. readsmallset(varoptions);
  886. if (vo_is_C_var in varoptions) then
  887. setmangledname(readstring);
  888. end;
  889. destructor tvarsym.done;
  890. begin
  891. strdispose(_mangledname);
  892. inherited done;
  893. end;
  894. procedure tvarsym.deref;
  895. begin
  896. if assigned(definitionsym) then
  897. begin
  898. resolvesym(psym(definitionsym));
  899. definition:=definitionsym^.definition;
  900. end
  901. else
  902. resolvedef(definition);
  903. end;
  904. procedure tvarsym.write;
  905. var
  906. hvo : tvaroptions;
  907. begin
  908. tsym.write;
  909. writebyte(byte(varspez));
  910. if read_member then
  911. writelong(address);
  912. { write only definition or definitionsym }
  913. if assigned(definitionsym) then
  914. begin
  915. writedefref(nil);
  916. writesymref(definitionsym);
  917. end
  918. else
  919. begin
  920. writedefref(definition);
  921. writesymref(nil);
  922. end;
  923. { symbols which are load are never candidates for a register,
  924. turn off the regable }
  925. hvo:=varoptions-[vo_regable];
  926. writesmallset(hvo);
  927. if (vo_is_C_var in varoptions) then
  928. writestring(mangledname);
  929. current_ppu^.writeentry(ibvarsym);
  930. end;
  931. procedure tvarsym.setmangledname(const s : string);
  932. begin
  933. _mangledname:=strpnew(s);
  934. end;
  935. function tvarsym.mangledname : string;
  936. var
  937. prefix : string;
  938. begin
  939. if assigned(_mangledname) then
  940. begin
  941. mangledname:=strpas(_mangledname);
  942. exit;
  943. end;
  944. case owner^.symtabletype of
  945. staticsymtable :
  946. if (cs_create_smart in aktmoduleswitches) then
  947. prefix:='_'+owner^.name^+'$$$_'
  948. else
  949. prefix:='_';
  950. unitsymtable,
  951. globalsymtable :
  952. prefix:='U_'+owner^.name^+'_';
  953. else
  954. Message(sym_e_invalid_call_tvarsymmangledname);
  955. end;
  956. mangledname:=prefix+name;
  957. end;
  958. function tvarsym.getsize : longint;
  959. begin
  960. if assigned(definition) and (varspez=vs_value) and
  961. ((definition^.deftype<>arraydef) or (Parraydef(definition)^.highrange>=
  962. Parraydef(definition)^.lowrange)) then
  963. getsize:=definition^.size
  964. else
  965. getsize:=0;
  966. end;
  967. function tvarsym.getpushsize : longint;
  968. begin
  969. if assigned(definition) then
  970. begin
  971. case varspez of
  972. vs_var :
  973. getpushsize:=target_os.size_of_pointer;
  974. vs_value,
  975. vs_const :
  976. begin
  977. if push_addr_param(definition) then
  978. getpushsize:=target_os.size_of_pointer
  979. else
  980. getpushsize:=definition^.size;
  981. end;
  982. end;
  983. end
  984. else
  985. getpushsize:=0;
  986. end;
  987. function data_align(length : longint) : longint;
  988. begin
  989. (* this is useless under go32v2 at least
  990. because the section are only align to dword
  991. if length>8 then
  992. data_align:=16
  993. else if length>4 then
  994. data_align:=8
  995. else *)
  996. if length>2 then
  997. data_align:=4
  998. else
  999. if length>1 then
  1000. data_align:=2
  1001. else
  1002. data_align:=1;
  1003. end;
  1004. procedure tvarsym.insert_in_data;
  1005. var
  1006. varalign,
  1007. l,ali,modulo : longint;
  1008. storefilepos : tfileposinfo;
  1009. begin
  1010. if (vo_is_external in varoptions) then
  1011. exit;
  1012. { handle static variables of objects especially }
  1013. if read_member and (owner^.symtabletype=objectsymtable) and
  1014. (sp_static in symoptions) then
  1015. begin
  1016. { the data filed is generated in parser.pas
  1017. with a tobject_FIELDNAME variable }
  1018. { this symbol can't be loaded to a register }
  1019. {$ifdef INCLUDEOK}
  1020. exclude(varoptions,vo_regable);
  1021. exclude(varoptions,vo_fpuregable);
  1022. {$else}
  1023. varoptions:=varoptions-[vo_regable,vo_fpuregable];
  1024. {$endif}
  1025. end
  1026. else
  1027. if not(read_member) then
  1028. begin
  1029. { made problems with parameters etc. ! (FK) }
  1030. { check for instance of an abstract object or class }
  1031. {
  1032. if (pvarsym(sym)^.definition^.deftype=objectdef) and
  1033. ((pobjectdef(pvarsym(sym)^.definition)^.options and oo_is_abstract)<>0) then
  1034. Message(sym_e_no_instance_of_abstract_object);
  1035. }
  1036. storefilepos:=aktfilepos;
  1037. aktfilepos:=tokenpos;
  1038. if (vo_is_thread_var in varoptions) then
  1039. l:=4
  1040. else
  1041. l:=getsize;
  1042. case owner^.symtabletype of
  1043. stt_exceptsymtable:
  1044. { can contain only one symbol, address calculated later }
  1045. ;
  1046. localsymtable :
  1047. begin
  1048. varstate:=vs_declared;
  1049. modulo:=owner^.datasize and 3;
  1050. {$ifdef m68k}
  1051. { word alignment required for motorola }
  1052. if (l=1) then
  1053. l:=2
  1054. else
  1055. {$endif}
  1056. {
  1057. if (cs_optimize in aktglobalswitches) and
  1058. (aktoptprocessor in [classp5,classp6]) and
  1059. (l>=8) and ((owner^.datasize and 7)<>0) then
  1060. inc(owner^.datasize,8-(owner^.datasize and 7))
  1061. else
  1062. }
  1063. begin
  1064. if (l>=4) and (modulo<>0) then
  1065. inc(l,4-modulo)
  1066. else
  1067. if (l>=2) and ((modulo and 1)<>0) then
  1068. inc(l,2-(modulo and 1));
  1069. end;
  1070. inc(owner^.datasize,l);
  1071. address:=owner^.datasize;
  1072. end;
  1073. staticsymtable :
  1074. begin
  1075. { enable unitialized warning for local symbols }
  1076. varstate:=vs_declared;
  1077. if (cs_create_smart in aktmoduleswitches) then
  1078. bsssegment^.concat(new(pai_cut,init));
  1079. ali:=data_align(l);
  1080. if ali>1 then
  1081. begin
  1082. modulo:=owner^.datasize mod ali;
  1083. if modulo>0 then
  1084. inc(owner^.datasize,ali-modulo);
  1085. end;
  1086. {$ifdef GDB}
  1087. if cs_debuginfo in aktmoduleswitches then
  1088. concatstabto(bsssegment);
  1089. {$endif GDB}
  1090. if (cs_create_smart in aktmoduleswitches) or
  1091. DLLSource or
  1092. (vo_is_C_var in varoptions) then
  1093. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)))
  1094. else
  1095. bsssegment^.concat(new(pai_datablock,init(mangledname,l)));
  1096. { increase datasize }
  1097. inc(owner^.datasize,l);
  1098. { this symbol can't be loaded to a register }
  1099. {$ifdef INCLUDEOK}
  1100. exclude(varoptions,vo_regable);
  1101. exclude(varoptions,vo_fpuregable);
  1102. {$else}
  1103. varoptions:=varoptions-[vo_regable,vo_fpuregable];
  1104. {$endif}
  1105. end;
  1106. globalsymtable :
  1107. begin
  1108. if (cs_create_smart in aktmoduleswitches) then
  1109. bsssegment^.concat(new(pai_cut,init));
  1110. ali:=data_align(l);
  1111. if ali>1 then
  1112. begin
  1113. modulo:=owner^.datasize mod ali;
  1114. if modulo>0 then
  1115. inc(owner^.datasize,ali-modulo);
  1116. end;
  1117. {$ifdef GDB}
  1118. if cs_debuginfo in aktmoduleswitches then
  1119. concatstabto(bsssegment);
  1120. {$endif GDB}
  1121. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)));
  1122. inc(owner^.datasize,l);
  1123. { this symbol can't be loaded to a register }
  1124. {$ifdef INCLUDEOK}
  1125. exclude(varoptions,vo_regable);
  1126. exclude(varoptions,vo_fpuregable);
  1127. {$else}
  1128. varoptions:=varoptions-[vo_regable,vo_fpuregable];
  1129. {$endif}
  1130. end;
  1131. recordsymtable,
  1132. objectsymtable :
  1133. begin
  1134. { this symbol can't be loaded to a register }
  1135. {$ifdef INCLUDEOK}
  1136. exclude(varoptions,vo_regable);
  1137. exclude(varoptions,vo_fpuregable);
  1138. {$else}
  1139. varoptions:=varoptions-[vo_regable,vo_fpuregable];
  1140. {$endif}
  1141. { get the alignment size }
  1142. if (aktpackrecords=packrecord_C) then
  1143. begin
  1144. varalign:=definition^.alignment;
  1145. if varalign=0 then
  1146. begin
  1147. if (owner^.dataalignment<4) then
  1148. begin
  1149. if (l>=4) then
  1150. owner^.dataalignment:=4
  1151. else
  1152. if (owner^.dataalignment<2) and (l>=2) then
  1153. owner^.dataalignment:=2;
  1154. end;
  1155. end;
  1156. end
  1157. else
  1158. varalign:=0;
  1159. { align record and object fields }
  1160. if (l=1) or (varalign=1) or (owner^.dataalignment=1) then
  1161. begin
  1162. address:=owner^.datasize;
  1163. inc(owner^.datasize,l)
  1164. end
  1165. else
  1166. if (l=2) or (varalign=2) or (owner^.dataalignment=2) then
  1167. begin
  1168. owner^.datasize:=(owner^.datasize+1) and (not 1);
  1169. address:=owner^.datasize;
  1170. inc(owner^.datasize,l)
  1171. end
  1172. else
  1173. if (l<=4) or (varalign=4) or (owner^.dataalignment=4) then
  1174. begin
  1175. owner^.datasize:=(owner^.datasize+3) and (not 3);
  1176. address:=owner^.datasize;
  1177. inc(owner^.datasize,l);
  1178. end
  1179. else
  1180. if (l<=8) or (owner^.dataalignment=8) then
  1181. begin
  1182. owner^.datasize:=(owner^.datasize+7) and (not 7);
  1183. address:=owner^.datasize;
  1184. inc(owner^.datasize,l);
  1185. end
  1186. else
  1187. if (l<=16) or (owner^.dataalignment=16) then
  1188. begin
  1189. owner^.datasize:=(owner^.datasize+15) and (not 15);
  1190. address:=owner^.datasize;
  1191. inc(owner^.datasize,l);
  1192. end
  1193. else
  1194. if (l<=32) or (owner^.dataalignment=32) then
  1195. begin
  1196. owner^.datasize:=(owner^.datasize+31) and (not 31);
  1197. address:=owner^.datasize;
  1198. inc(owner^.datasize,l);
  1199. end;
  1200. end;
  1201. parasymtable :
  1202. begin
  1203. { here we need the size of a push instead of the
  1204. size of the data }
  1205. l:=getpushsize;
  1206. address:=owner^.datasize;
  1207. owner^.datasize:=align(owner^.datasize+l,target_os.stackalignment);
  1208. end
  1209. else
  1210. begin
  1211. modulo:=owner^.datasize and 3;
  1212. if (l>=4) and (modulo<>0) then
  1213. inc(owner^.datasize,4-modulo)
  1214. else
  1215. if (l>=2) and ((modulo and 1)<>0) then
  1216. inc(owner^.datasize);
  1217. address:=owner^.datasize;
  1218. inc(owner^.datasize,l);
  1219. end;
  1220. end;
  1221. aktfilepos:=storefilepos;
  1222. end;
  1223. end;
  1224. {$ifdef GDB}
  1225. function tvarsym.stabstring : pchar;
  1226. var
  1227. st : string[2];
  1228. begin
  1229. if (definition^.deftype=objectdef) and
  1230. pobjectdef(definition)^.is_class then
  1231. st:='*'
  1232. else
  1233. st:='';
  1234. if (owner^.symtabletype = objectsymtable) and
  1235. (sp_static in symoptions) then
  1236. begin
  1237. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1238. {$ifndef Delphi}
  1239. stabstring := strpnew('"'+owner^.name^+'__'+name+':'+st+
  1240. +definition^.numberstring+'",'+
  1241. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1242. {$endif}
  1243. end
  1244. else if (owner^.symtabletype = globalsymtable) or
  1245. (owner^.symtabletype = unitsymtable) then
  1246. begin
  1247. { Here we used S instead of
  1248. because with G GDB doesn't look at the address field
  1249. but searches the same name or with a leading underscore
  1250. but these names don't exist in pascal !}
  1251. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1252. stabstring := strpnew('"'+name+':'+st
  1253. +definition^.numberstring+'",'+
  1254. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1255. end
  1256. else if owner^.symtabletype = staticsymtable then
  1257. begin
  1258. stabstring := strpnew('"'+name+':S'+st
  1259. +definition^.numberstring+'",'+
  1260. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1261. end
  1262. else if (owner^.symtabletype=parasymtable) then
  1263. begin
  1264. case varspez of
  1265. vs_var : st := 'v'+st;
  1266. vs_value,
  1267. vs_const : if push_addr_param(definition) then
  1268. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1269. else
  1270. st := 'p'+st;
  1271. end;
  1272. stabstring := strpnew('"'+name+':'+st
  1273. +definition^.numberstring+'",'+
  1274. tostr(N_PSYM)+',0,'+tostr(fileinfo.line)+','+
  1275. tostr(address+owner^.address_fixup));
  1276. {offset to ebp => will not work if the framepointer is esp
  1277. so some optimizing will make things harder to debug }
  1278. end
  1279. else if (owner^.symtabletype=localsymtable) then
  1280. {$ifdef i386}
  1281. if reg<>R_NO then
  1282. begin
  1283. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1284. { this is the register order for GDB}
  1285. stabstring:=strpnew('"'+name+':r'+st
  1286. +definition^.numberstring+'",'+
  1287. tostr(N_RSYM)+',0,'+
  1288. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1289. end
  1290. else
  1291. {$endif i386}
  1292. { I don't know if this will work (PM) }
  1293. if (vo_is_C_var in varoptions) then
  1294. stabstring := strpnew('"'+name+':S'+st
  1295. +definition^.numberstring+'",'+
  1296. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1297. else
  1298. stabstring := strpnew('"'+name+':'+st
  1299. +definition^.numberstring+'",'+
  1300. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address))
  1301. else
  1302. stabstring := inherited stabstring;
  1303. end;
  1304. procedure tvarsym.concatstabto(asmlist : paasmoutput);
  1305. {$ifdef i386}
  1306. var stab_str : pchar;
  1307. {$endif i386}
  1308. begin
  1309. inherited concatstabto(asmlist);
  1310. {$ifdef i386}
  1311. if (owner^.symtabletype=parasymtable) and
  1312. (reg<>R_NO) then
  1313. begin
  1314. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1315. { this is the register order for GDB}
  1316. stab_str:=strpnew('"'+name+':r'
  1317. +definition^.numberstring+'",'+
  1318. tostr(N_RSYM)+',0,'+
  1319. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1320. asmlist^.concat(new(pai_stabs,init(stab_str)));
  1321. end;
  1322. {$endif i386}
  1323. end;
  1324. {$endif GDB}
  1325. {****************************************************************************
  1326. TTYPEDCONSTSYM
  1327. *****************************************************************************}
  1328. constructor ttypedconstsym.init(const n : string;p : pdef;really_const : boolean);
  1329. begin
  1330. tsym.init(n);
  1331. typ:=typedconstsym;
  1332. definition:=p;
  1333. definitionsym:=nil;
  1334. is_really_const:=really_const;
  1335. prefix:=stringdup(procprefix);
  1336. end;
  1337. constructor ttypedconstsym.initsym(const n : string;p : ptypesym;really_const : boolean);
  1338. begin
  1339. ttypedconstsym.init(n,p^.definition,really_const);
  1340. definitionsym:=p;
  1341. end;
  1342. constructor ttypedconstsym.load;
  1343. begin
  1344. tsym.load;
  1345. typ:=typedconstsym;
  1346. definition:=readdefref;
  1347. definitionsym:=ptypesym(readsymref);
  1348. prefix:=stringdup(readstring);
  1349. is_really_const:=boolean(readbyte);
  1350. end;
  1351. destructor ttypedconstsym.done;
  1352. begin
  1353. stringdispose(prefix);
  1354. tsym.done;
  1355. end;
  1356. function ttypedconstsym.mangledname : string;
  1357. begin
  1358. mangledname:='TC_'+prefix^+'_'+name;
  1359. end;
  1360. function ttypedconstsym.getsize : longint;
  1361. begin
  1362. if assigned(definition) then
  1363. getsize:=definition^.size
  1364. else
  1365. getsize:=0;
  1366. end;
  1367. procedure ttypedconstsym.deref;
  1368. begin
  1369. if assigned(definitionsym) then
  1370. begin
  1371. resolvesym(psym(definitionsym));
  1372. definition:=definitionsym^.definition;
  1373. end
  1374. else
  1375. resolvedef(definition);
  1376. end;
  1377. procedure ttypedconstsym.write;
  1378. begin
  1379. tsym.write;
  1380. { write only definition or definitionsym }
  1381. if assigned(definitionsym) then
  1382. begin
  1383. writedefref(nil);
  1384. writesymref(definitionsym);
  1385. end
  1386. else
  1387. begin
  1388. writedefref(definition);
  1389. writesymref(nil);
  1390. end;
  1391. writestring(prefix^);
  1392. writebyte(byte(is_really_const));
  1393. current_ppu^.writeentry(ibtypedconstsym);
  1394. end;
  1395. procedure ttypedconstsym.insert_in_data;
  1396. var
  1397. curconstsegment : paasmoutput;
  1398. l,ali,modulo : longint;
  1399. storefilepos : tfileposinfo;
  1400. begin
  1401. storefilepos:=aktfilepos;
  1402. aktfilepos:=tokenpos;
  1403. if is_really_const then
  1404. curconstsegment:=consts
  1405. else
  1406. curconstsegment:=datasegment;
  1407. if (cs_create_smart in aktmoduleswitches) then
  1408. curconstsegment^.concat(new(pai_cut,init));
  1409. l:=getsize;
  1410. ali:=data_align(l);
  1411. if ali>1 then
  1412. begin
  1413. curconstsegment^.concat(new(pai_align,init(ali)));
  1414. modulo:=owner^.datasize mod ali;
  1415. if modulo>0 then
  1416. inc(owner^.datasize,ali-modulo);
  1417. end;
  1418. { Why was there no owner size update here ??? }
  1419. inc(owner^.datasize,l);
  1420. {$ifdef GDB}
  1421. if cs_debuginfo in aktmoduleswitches then
  1422. concatstabto(curconstsegment);
  1423. {$endif GDB}
  1424. if owner^.symtabletype=globalsymtable then
  1425. begin
  1426. curconstsegment^.concat(new(pai_symbol,initname_global(mangledname,getsize)));
  1427. end
  1428. else
  1429. if owner^.symtabletype<>unitsymtable then
  1430. begin
  1431. if (cs_create_smart in aktmoduleswitches) or
  1432. DLLSource then
  1433. curconstsegment^.concat(new(pai_symbol,initname_global(mangledname,getsize)))
  1434. else
  1435. curconstsegment^.concat(new(pai_symbol,initname(mangledname,getsize)));
  1436. end;
  1437. aktfilepos:=storefilepos;
  1438. end;
  1439. {$ifdef GDB}
  1440. function ttypedconstsym.stabstring : pchar;
  1441. var
  1442. st : char;
  1443. begin
  1444. if (cs_gdb_gsym in aktglobalswitches) and (owner^.symtabletype in [unitsymtable,globalsymtable]) then
  1445. st := 'G'
  1446. else
  1447. st := 'S';
  1448. stabstring := strpnew('"'+name+':'+st+
  1449. definition^.numberstring+'",'+tostr(n_STSYM)+',0,'+
  1450. tostr(fileinfo.line)+','+mangledname);
  1451. end;
  1452. {$endif GDB}
  1453. {****************************************************************************
  1454. TCONSTSYM
  1455. ****************************************************************************}
  1456. constructor tconstsym.init(const n : string;t : tconsttype;v : longint);
  1457. begin
  1458. inherited init(n);
  1459. typ:=constsym;
  1460. consttype:=t;
  1461. value:=v;
  1462. ResStrIndex:=0;
  1463. definition:=nil;
  1464. len:=0;
  1465. end;
  1466. constructor tconstsym.init_def(const n : string;t : tconsttype;v : longint;def : pdef);
  1467. begin
  1468. inherited init(n);
  1469. typ:=constsym;
  1470. consttype:=t;
  1471. value:=v;
  1472. definition:=def;
  1473. len:=0;
  1474. end;
  1475. constructor tconstsym.init_string(const n : string;t : tconsttype;str:pchar;l:longint);
  1476. begin
  1477. inherited init(n);
  1478. typ:=constsym;
  1479. consttype:=t;
  1480. value:=longint(str);
  1481. definition:=nil;
  1482. len:=l;
  1483. if t=constresourcestring then
  1484. ResStrIndex:=registerresourcestring(name,pchar(value),len);
  1485. end;
  1486. constructor tconstsym.load;
  1487. var
  1488. pd : pbestreal;
  1489. ps : pnormalset;
  1490. begin
  1491. tsym.load;
  1492. typ:=constsym;
  1493. consttype:=tconsttype(readbyte);
  1494. case consttype of
  1495. constint,
  1496. constbool,
  1497. constchar :
  1498. value:=readlong;
  1499. constpointer,
  1500. constord :
  1501. begin
  1502. definition:=readdefref;
  1503. value:=readlong;
  1504. end;
  1505. conststring,constresourcestring :
  1506. begin
  1507. len:=readlong;
  1508. getmem(pchar(value),len+1);
  1509. current_ppu^.getdata(pchar(value)^,len);
  1510. if consttype=constresourcestring then
  1511. ResStrIndex:=readlong;
  1512. end;
  1513. constreal :
  1514. begin
  1515. new(pd);
  1516. pd^:=readreal;
  1517. value:=longint(pd);
  1518. end;
  1519. constset :
  1520. begin
  1521. definition:=readdefref;
  1522. new(ps);
  1523. readnormalset(ps^);
  1524. value:=longint(ps);
  1525. end;
  1526. constnil : ;
  1527. else
  1528. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttype)));
  1529. end;
  1530. end;
  1531. destructor tconstsym.done;
  1532. begin
  1533. case consttype of
  1534. conststring :
  1535. freemem(pchar(value),len+1);
  1536. constreal :
  1537. dispose(pbestreal(value));
  1538. constset :
  1539. dispose(pnormalset(value));
  1540. end;
  1541. inherited done;
  1542. end;
  1543. function tconstsym.mangledname : string;
  1544. begin
  1545. mangledname:=name;
  1546. end;
  1547. procedure tconstsym.deref;
  1548. begin
  1549. if consttype in [constord,constpointer,constset] then
  1550. resolvedef(pdef(definition));
  1551. end;
  1552. procedure tconstsym.write;
  1553. begin
  1554. tsym.write;
  1555. writebyte(byte(consttype));
  1556. case consttype of
  1557. constnil : ;
  1558. constint,
  1559. constbool,
  1560. constchar :
  1561. writelong(value);
  1562. constpointer,
  1563. constord :
  1564. begin
  1565. writedefref(definition);
  1566. writelong(value);
  1567. end;
  1568. conststring,constresourcestring :
  1569. begin
  1570. writelong(len);
  1571. current_ppu^.putdata(pchar(value)^,len);
  1572. if consttype=constresourcestring then
  1573. writelong(ResStrIndex);
  1574. end;
  1575. constreal :
  1576. writereal(pbestreal(value)^);
  1577. constset :
  1578. begin
  1579. writedefref(definition);
  1580. writenormalset(pointer(value)^);
  1581. end;
  1582. else
  1583. internalerror(13);
  1584. end;
  1585. current_ppu^.writeentry(ibconstsym);
  1586. end;
  1587. {$ifdef GDB}
  1588. function tconstsym.stabstring : pchar;
  1589. var st : string;
  1590. begin
  1591. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1592. case consttype of
  1593. conststring : begin
  1594. { I had to remove ibm2ascii !! }
  1595. st := pstring(value)^;
  1596. {st := ibm2ascii(pstring(value)^);}
  1597. st := 's'''+st+'''';
  1598. end;
  1599. constbool,
  1600. constint,
  1601. constpointer,
  1602. constord,
  1603. constchar : st := 'i'+tostr(value);
  1604. constreal : begin
  1605. system.str(pbestreal(value)^,st);
  1606. st := 'r'+st;
  1607. end;
  1608. { if we don't know just put zero !! }
  1609. else st:='i0';
  1610. {***SETCONST}
  1611. {constset:;} {*** I don't know what to do with a set.}
  1612. { sets are not recognized by GDB}
  1613. {***}
  1614. end;
  1615. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1616. tostr(fileinfo.line)+',0');
  1617. end;
  1618. procedure tconstsym.concatstabto(asmlist : paasmoutput);
  1619. begin
  1620. if consttype <> conststring then
  1621. inherited concatstabto(asmlist);
  1622. end;
  1623. {$endif GDB}
  1624. {****************************************************************************
  1625. TENUMSYM
  1626. ****************************************************************************}
  1627. constructor tenumsym.init(const n : string;def : penumdef;v : longint);
  1628. begin
  1629. tsym.init(n);
  1630. typ:=enumsym;
  1631. definition:=def;
  1632. value:=v;
  1633. if def^.min>v then
  1634. def^.setmin(v);
  1635. if def^.max<v then
  1636. def^.setmax(v);
  1637. order;
  1638. end;
  1639. constructor tenumsym.load;
  1640. begin
  1641. tsym.load;
  1642. typ:=enumsym;
  1643. definition:=penumdef(readdefref);
  1644. value:=readlong;
  1645. nextenum := Nil;
  1646. end;
  1647. procedure tenumsym.deref;
  1648. begin
  1649. resolvedef(pdef(definition));
  1650. order;
  1651. end;
  1652. procedure tenumsym.order;
  1653. var
  1654. sym : penumsym;
  1655. begin
  1656. sym := definition^.firstenum;
  1657. if sym = nil then
  1658. begin
  1659. definition^.firstenum := @self;
  1660. nextenum := nil;
  1661. exit;
  1662. end;
  1663. { reorder the symbols in increasing value }
  1664. if value < sym^.value then
  1665. begin
  1666. nextenum := sym;
  1667. definition^.firstenum := @self;
  1668. end
  1669. else
  1670. begin
  1671. while (sym^.value <= value) and assigned(sym^.nextenum) do
  1672. sym := sym^.nextenum;
  1673. nextenum := sym^.nextenum;
  1674. sym^.nextenum := @self;
  1675. end;
  1676. end;
  1677. procedure tenumsym.write;
  1678. begin
  1679. tsym.write;
  1680. writedefref(definition);
  1681. writelong(value);
  1682. current_ppu^.writeentry(ibenumsym);
  1683. end;
  1684. {$ifdef GDB}
  1685. procedure tenumsym.concatstabto(asmlist : paasmoutput);
  1686. begin
  1687. {enum elements have no stab !}
  1688. end;
  1689. {$EndIf GDB}
  1690. {****************************************************************************
  1691. TTYPESYM
  1692. ****************************************************************************}
  1693. constructor ttypesym.init(const n : string;d : pdef);
  1694. begin
  1695. tsym.init(n);
  1696. typ:=typesym;
  1697. definition:=d;
  1698. {$ifdef GDB}
  1699. isusedinstab := false;
  1700. {$endif GDB}
  1701. if assigned(definition) then
  1702. begin
  1703. if not(assigned(definition^.sym)) then
  1704. begin
  1705. definition^.sym:=@self;
  1706. synonym:=nil;
  1707. {$ifdef INCLUDEOK}
  1708. include(symoptions,sp_primary_typesym);
  1709. {$else}
  1710. symoptions:=symoptions+[sp_primary_typesym];
  1711. {$endif}
  1712. end
  1713. else
  1714. begin
  1715. synonym:=definition^.sym^.synonym;
  1716. definition^.sym^.synonym:=@self;
  1717. end;
  1718. end;
  1719. end;
  1720. constructor ttypesym.load;
  1721. begin
  1722. tsym.load;
  1723. typ:=typesym;
  1724. synonym:=nil;
  1725. {$ifdef GDB}
  1726. isusedinstab := false;
  1727. {$endif GDB}
  1728. definition:=readdefref;
  1729. end;
  1730. destructor ttypesym.done;
  1731. var prevsym : ptypesym;
  1732. begin
  1733. if assigned(definition) then
  1734. begin
  1735. prevsym:=definition^.sym;
  1736. if prevsym=@self then
  1737. definition^.sym:=synonym;
  1738. while assigned(prevsym) do
  1739. begin
  1740. if (prevsym^.synonym=@self) then
  1741. begin
  1742. prevsym^.synonym:=synonym;
  1743. break;
  1744. end;
  1745. prevsym:=prevsym^.synonym;
  1746. end;
  1747. end;
  1748. synonym:=nil;
  1749. definition:=nil;
  1750. inherited done;
  1751. end;
  1752. procedure ttypesym.deref;
  1753. begin
  1754. resolvedef(definition);
  1755. if assigned(definition) then
  1756. begin
  1757. if (sp_primary_typesym in symoptions) then
  1758. begin
  1759. if definition^.sym<>@self then
  1760. synonym:=definition^.sym;
  1761. definition^.sym:=@self;
  1762. end
  1763. else
  1764. begin
  1765. if assigned(definition^.sym) then
  1766. begin
  1767. synonym:=definition^.sym^.synonym;
  1768. if definition^.sym<>@self then
  1769. definition^.sym^.synonym:=@self;
  1770. end
  1771. else
  1772. definition^.sym:=@self;
  1773. end;
  1774. if (definition^.deftype=recorddef) and assigned(precorddef(definition)^.symtable) and
  1775. (definition^.sym=@self) then
  1776. precorddef(definition)^.symtable^.name:=stringdup('record '+name);
  1777. end;
  1778. end;
  1779. procedure ttypesym.write;
  1780. begin
  1781. tsym.write;
  1782. writedefref(definition);
  1783. current_ppu^.writeentry(ibtypesym);
  1784. end;
  1785. procedure ttypesym.load_references;
  1786. begin
  1787. inherited load_references;
  1788. if (definition^.deftype=recorddef) then
  1789. precorddef(definition)^.symtable^.load_browser;
  1790. if (definition^.deftype=objectdef) then
  1791. pobjectdef(definition)^.symtable^.load_browser;
  1792. end;
  1793. function ttypesym.write_references : boolean;
  1794. begin
  1795. if not inherited write_references then
  1796. { write address of this symbol if record or object
  1797. even if no real refs are there
  1798. because we need it for the symtable }
  1799. if (definition^.deftype=recorddef) or
  1800. (definition^.deftype=objectdef) then
  1801. begin
  1802. writesymref(@self);
  1803. current_ppu^.writeentry(ibsymref);
  1804. end;
  1805. write_references:=true;
  1806. if (definition^.deftype=recorddef) then
  1807. precorddef(definition)^.symtable^.write_browser;
  1808. if (definition^.deftype=objectdef) then
  1809. pobjectdef(definition)^.symtable^.write_browser;
  1810. end;
  1811. {$ifdef BrowserLog}
  1812. procedure ttypesym.add_to_browserlog;
  1813. begin
  1814. inherited add_to_browserlog;
  1815. if (definition^.deftype=recorddef) then
  1816. precorddef(definition)^.symtable^.writebrowserlog;
  1817. if (definition^.deftype=objectdef) then
  1818. pobjectdef(definition)^.symtable^.writebrowserlog;
  1819. end;
  1820. {$endif BrowserLog}
  1821. {$ifdef GDB}
  1822. function ttypesym.stabstring : pchar;
  1823. var stabchar : string[2];
  1824. short : string;
  1825. begin
  1826. if definition^.deftype in tagtypes then
  1827. stabchar := 'Tt'
  1828. else
  1829. stabchar := 't';
  1830. short := '"'+name+':'+stabchar+definition^.numberstring
  1831. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  1832. stabstring := strpnew(short);
  1833. end;
  1834. procedure ttypesym.concatstabto(asmlist : paasmoutput);
  1835. begin
  1836. {not stabs for forward defs }
  1837. if assigned(definition) then
  1838. if (definition^.sym = @self) then
  1839. definition^.concatstabto(asmlist)
  1840. else
  1841. inherited concatstabto(asmlist);
  1842. end;
  1843. {$endif GDB}
  1844. {****************************************************************************
  1845. TSYSSYM
  1846. ****************************************************************************}
  1847. constructor tsyssym.init(const n : string;l : longint);
  1848. begin
  1849. inherited init(n);
  1850. typ:=syssym;
  1851. number:=l;
  1852. end;
  1853. constructor tsyssym.load;
  1854. begin
  1855. tsym.load;
  1856. typ:=syssym;
  1857. number:=readlong;
  1858. end;
  1859. destructor tsyssym.done;
  1860. begin
  1861. inherited done;
  1862. end;
  1863. procedure tsyssym.write;
  1864. begin
  1865. tsym.write;
  1866. writelong(number);
  1867. current_ppu^.writeentry(ibsyssym);
  1868. end;
  1869. {$ifdef GDB}
  1870. procedure tsyssym.concatstabto(asmlist : paasmoutput);
  1871. begin
  1872. end;
  1873. {$endif GDB}
  1874. {****************************************************************************
  1875. TMACROSYM
  1876. ****************************************************************************}
  1877. constructor tmacrosym.init(const n : string);
  1878. begin
  1879. inherited init(n);
  1880. typ:=macrosym;
  1881. defined:=true;
  1882. defined_at_startup:=false;
  1883. is_used:=false;
  1884. buftext:=nil;
  1885. buflen:=0;
  1886. end;
  1887. destructor tmacrosym.done;
  1888. begin
  1889. if assigned(buftext) then
  1890. freemem(buftext,buflen);
  1891. inherited done;
  1892. end;
  1893. {
  1894. $Log$
  1895. Revision 1.124 1999-11-06 14:34:27 peter
  1896. * truncated log to 20 revs
  1897. Revision 1.123 1999/11/05 17:18:03 pierre
  1898. * local browsing works at first level
  1899. ie for function defined in interface or implementation
  1900. not yet for functions inside other functions
  1901. Revision 1.122 1999/10/21 16:41:41 florian
  1902. * problems with readln fixed: esi wasn't restored correctly when
  1903. reading ordinal fields of objects futher the register allocation
  1904. didn't take care of the extra register when reading ordinal values
  1905. * enumerations can now be used in constant indexes of properties
  1906. Revision 1.121 1999/10/01 08:02:48 peter
  1907. * forward type declaration rewritten
  1908. Revision 1.120 1999/09/27 23:44:58 peter
  1909. * procinfo is now a pointer
  1910. * support for result setting in sub procedure
  1911. Revision 1.119 1999/09/26 21:30:22 peter
  1912. + constant pointer support which can happend with typecasting like
  1913. const p=pointer(1)
  1914. * better procvar parsing in typed consts
  1915. Revision 1.118 1999/09/20 16:39:03 peter
  1916. * cs_create_smart instead of cs_smartlink
  1917. * -CX is create smartlink
  1918. * -CD is create dynamic, but does nothing atm.
  1919. Revision 1.117 1999/08/31 15:42:24 pierre
  1920. + tmacrosym is_used and defined_at_startup boolean fields added
  1921. Revision 1.116 1999/08/24 22:38:55 michael
  1922. * more resourcestring changes
  1923. Revision 1.115 1999/08/23 11:45:42 michael
  1924. * Hopefully final attempt at resourcestrings
  1925. Revision 1.114 1999/08/15 21:57:58 michael
  1926. Changes for resource strings
  1927. Revision 1.113 1999/08/14 00:39:00 peter
  1928. * hack to support property with record fields
  1929. Revision 1.112 1999/08/13 14:24:20 pierre
  1930. + stabs for classes and classref working,
  1931. a class still needs an ^ to get that content of it,
  1932. but the class fields inside a class don't result into an
  1933. infinite loop anymore!
  1934. Revision 1.111 1999/08/10 12:36:31 pierre
  1935. * use of procsym field for correct gdb info in local procedures
  1936. * exported DLL vars made global to be able to use DLLTOOL with themz
  1937. Revision 1.110 1999/08/07 14:21:03 florian
  1938. * some small problems fixed
  1939. Revision 1.109 1999/08/07 13:24:34 daniel
  1940. * Fixed open arrays
  1941. Revision 1.108 1999/08/05 16:53:17 peter
  1942. * V_Fatal=1, all other V_ are also increased
  1943. * Check for local procedure when assigning procvar
  1944. * fixed comment parsing because directives
  1945. * oldtp mode directives better supported
  1946. * added some messages to errore.msg
  1947. Revision 1.107 1999/08/04 13:45:30 florian
  1948. + floating point register variables !!
  1949. * pairegalloc is now generated for register variables
  1950. Revision 1.106 1999/08/03 22:03:19 peter
  1951. * moved bitmask constants to sets
  1952. * some other type/const renamings
  1953. Revision 1.105 1999/07/29 20:54:10 peter
  1954. * write .size also
  1955. Revision 1.104 1999/07/27 23:42:21 peter
  1956. * indirect type referencing is now allowed
  1957. }