browcol.pas 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by the FPC development team
  4. Support routines for getting browser info in collections
  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. {$ifdef TP}
  19. {$N+,E+}
  20. {$endif}
  21. unit browcol;
  22. interface
  23. uses
  24. cobjects,objects,symconst,symtable;
  25. const
  26. SymbolTypLen : integer = 6;
  27. RecordTypes : set of tsymtyp =
  28. ([typesym,unitsym,programsym]);
  29. sfRecord = $00000001;
  30. sfObject = $00000002;
  31. sfClass = $00000004;
  32. sfHasMemInfo = $80000000;
  33. type
  34. TStoreCollection = object(TStringCollection)
  35. function Add(const S: string): PString;
  36. end;
  37. PModuleNameCollection = ^TModuleNameCollection;
  38. TModuleNameCollection = object(TStoreCollection)
  39. end;
  40. PTypeNameCollection = ^TTypeNameCollection;
  41. TTypeNameCollection = object(TStoreCollection)
  42. end;
  43. PSymbolCollection = ^TSymbolCollection;
  44. PSortedSymbolCollection = ^TSortedSymbolCollection;
  45. PReferenceCollection = ^TReferenceCollection;
  46. PReference = ^TReference;
  47. TReference = object(TObject)
  48. FileName : PString;
  49. Position : TPoint;
  50. constructor Init(AFileName: PString; ALine, AColumn: Sw_integer);
  51. function GetFileName: string;
  52. destructor Done; virtual;
  53. constructor Load(var S: TStream);
  54. procedure Store(var S: TStream);
  55. end;
  56. PSymbolMemInfo = ^TSymbolMemInfo;
  57. TSymbolMemInfo = record
  58. Addr : longint;
  59. LocalAddr : longint;
  60. Size : longint;
  61. PushSize : longint;
  62. end;
  63. PSymbol = ^TSymbol;
  64. TSymbol = object(TObject)
  65. Name : PString;
  66. Typ : tsymtyp;
  67. Params : PString;
  68. References : PReferenceCollection;
  69. Items : PSymbolCollection;
  70. DType : PString;
  71. VType : PString;
  72. ObjectID : longint;
  73. AncestorID : longint;
  74. Ancestor : PSymbol;
  75. Flags : longint;
  76. MemInfo : PSymbolMemInfo;
  77. constructor Init(const AName: string; ATyp: tsymtyp; AParams: string; AMemInfo: PSymbolMemInfo);
  78. procedure SetMemInfo(const AMemInfo: TSymbolMemInfo);
  79. function GetReferenceCount: Sw_integer;
  80. function GetReference(Index: Sw_integer): PReference;
  81. function GetItemCount: Sw_integer;
  82. function GetItem(Index: Sw_integer): PSymbol;
  83. function GetName: string;
  84. function GetText: string;
  85. function GetTypeName: string;
  86. destructor Done; virtual;
  87. constructor Load(var S: TStream);
  88. procedure Store(var S: TStream);
  89. end;
  90. PObjectSymbolCollection = ^TObjectSymbolCollection;
  91. PObjectSymbol = ^TObjectSymbol;
  92. TObjectSymbol = object(TObject)
  93. Parent : PObjectSymbol;
  94. Symbol : PSymbol;
  95. Expanded : boolean;
  96. constructor Init(AParent: PObjectSymbol; ASymbol: PSymbol);
  97. constructor InitName(const AName: string);
  98. function GetName: string;
  99. function GetDescendantCount: sw_integer;
  100. function GetDescendant(Index: sw_integer): PObjectSymbol;
  101. procedure AddDescendant(P: PObjectSymbol);
  102. destructor Done; virtual;
  103. constructor Load(var S: TStream);
  104. procedure Store(S: TStream);
  105. private
  106. Name: PString;
  107. Descendants: PObjectSymbolCollection;
  108. end;
  109. TSymbolCollection = object(TSortedCollection)
  110. function At(Index: Sw_Integer): PSymbol;
  111. procedure Insert(Item: Pointer); virtual;
  112. function LookUp(const S: string; var Idx: sw_integer): string; virtual;
  113. end;
  114. TSortedSymbolCollection = object(TSymbolCollection)
  115. function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
  116. procedure Insert(Item: Pointer); virtual;
  117. function LookUp(const S: string; var Idx: sw_integer): string; virtual;
  118. end;
  119. PIDSortedSymbolCollection = ^TIDSortedSymbolCollection;
  120. TIDSortedSymbolCollection = object(TSymbolCollection)
  121. function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
  122. procedure Insert(Item: Pointer); virtual;
  123. function SearchSymbolByID(AID: longint): PSymbol;
  124. end;
  125. TObjectSymbolCollection = object(TSortedCollection)
  126. function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
  127. function LookUp(const S: string; var Idx: sw_integer): string; virtual;
  128. function At(Index: Sw_Integer): PObjectSymbol;
  129. end;
  130. TReferenceCollection = object(TCollection)
  131. function At(Index: Sw_Integer): PReference;
  132. end;
  133. PSourceFile = ^TSourceFile;
  134. TSourceFile = object(TObject)
  135. SourceFileName: PString;
  136. ObjFileName: PString;
  137. PPUFileName: PString;
  138. constructor Init(ASourceFileName, AObjFileName, APPUFileName: string);
  139. destructor Done; virtual;
  140. function GetSourceFilename: string;
  141. function GetObjFileName: string;
  142. function GetPPUFileName: string;
  143. end;
  144. PSourceFileCollection = ^TSourceFileCollection;
  145. TSourceFileCollection = object(TCollection)
  146. function At(Index: sw_Integer): PSourceFile;
  147. end;
  148. const
  149. Modules : PSymbolCollection = nil;
  150. ModuleNames : PModuleNameCollection = nil;
  151. TypeNames : PTypeNameCollection = nil;
  152. ObjectTree : PObjectSymbol = nil;
  153. SourceFiles : PSourceFileCollection = nil;
  154. procedure DisposeBrowserCol;
  155. procedure NewBrowserCol;
  156. procedure CreateBrowserCol;
  157. procedure InitBrowserCol;
  158. procedure DoneBrowserCol;
  159. function LoadBrowserCol(S: PStream): boolean;
  160. procedure StoreBrowserCol(S: PStream);
  161. procedure BuildObjectInfo;
  162. procedure BuildSourceList;
  163. function SearchObjectForSymbol(O: PSymbol): PObjectSymbol;
  164. procedure RegisterSymbols;
  165. implementation
  166. uses
  167. Dos,Drivers,Views,App,
  168. aasm,globtype,globals,files,comphook;
  169. const
  170. RModuleNameCollection: TStreamRec = (
  171. ObjType: 3001;
  172. VmtLink: Ofs(TypeOf(TModuleNameCollection)^);
  173. Load: @TModuleNameCollection.Load;
  174. Store: @TModuleNameCollection.Store
  175. );
  176. RTypeNameCollection: TStreamRec = (
  177. ObjType: 3002;
  178. VmtLink: Ofs(TypeOf(TTypeNameCollection)^);
  179. Load: @TTypeNameCollection.Load;
  180. Store: @TTypeNameCollection.Store
  181. );
  182. RReference: TStreamRec = (
  183. ObjType: 3003;
  184. VmtLink: Ofs(TypeOf(TReference)^);
  185. Load: @TReference.Load;
  186. Store: @TReference.Store
  187. );
  188. RSymbol: TStreamRec = (
  189. ObjType: 3004;
  190. VmtLink: Ofs(TypeOf(TSymbol)^);
  191. Load: @TSymbol.Load;
  192. Store: @TSymbol.Store
  193. );
  194. RObjectSymbol: TStreamRec = (
  195. ObjType: 3005;
  196. VmtLink: Ofs(TypeOf(TObjectSymbol)^);
  197. Load: @TObjectSymbol.Load;
  198. Store: @TObjectSymbol.Store
  199. );
  200. RSymbolCollection: TStreamRec = (
  201. ObjType: 3006;
  202. VmtLink: Ofs(TypeOf(TSymbolCollection)^);
  203. Load: @TSymbolCollection.Load;
  204. Store: @TSymbolCollection.Store
  205. );
  206. RSortedSymbolCollection: TStreamRec = (
  207. ObjType: 3007;
  208. VmtLink: Ofs(TypeOf(TSortedSymbolCollection)^);
  209. Load: @TSortedSymbolCollection.Load;
  210. Store: @TSortedSymbolCollection.Store
  211. );
  212. RIDSortedSymbolCollection: TStreamRec = (
  213. ObjType: 3008;
  214. VmtLink: Ofs(TypeOf(TIDSortedSymbolCollection)^);
  215. Load: @TIDSortedSymbolCollection.Load;
  216. Store: @TIDSortedSymbolCollection.Store
  217. );
  218. RObjectSymbolCollection: TStreamRec = (
  219. ObjType: 3009;
  220. VmtLink: Ofs(TypeOf(TObjectSymbolCollection)^);
  221. Load: @TObjectSymbolCollection.Load;
  222. Store: @TObjectSymbolCollection.Store
  223. );
  224. RReferenceCollection: TStreamRec = (
  225. ObjType: 3010;
  226. VmtLink: Ofs(TypeOf(TReferenceCollection)^);
  227. Load: @TReferenceCollection.Load;
  228. Store: @TReferenceCollection.Store
  229. );
  230. {****************************************************************************
  231. Helpers
  232. ****************************************************************************}
  233. function GetStr(P: PString): string;
  234. begin
  235. if P=nil then
  236. GetStr:=''
  237. else
  238. GetStr:=P^;
  239. end;
  240. function IntToStr(L: longint): string;
  241. var S: string;
  242. begin
  243. Str(L,S);
  244. IntToStr:=S;
  245. end;
  246. function UpcaseStr(S: string): string;
  247. var I: integer;
  248. begin
  249. for I:=1 to length(S) do
  250. S[I]:=Upcase(S[I]);
  251. UpcaseStr:=S;
  252. end;
  253. function FloatToStr(E: extended): string;
  254. var S: string;
  255. begin
  256. Str(E:0:24,S);
  257. if Pos('.',S)>0 then
  258. begin
  259. while (length(S)>0) and (S[length(S)]='0') do
  260. Delete(S,length(S),1);
  261. if (length(S)>0) and (S[length(S)]='.') then
  262. Delete(S,length(S),1);
  263. end;
  264. if S='' then S:='0';
  265. FloatToStr:=S;
  266. end;
  267. {****************************************************************************
  268. TStoreCollection
  269. ****************************************************************************}
  270. function TStoreCollection.Add(const S: string): PString;
  271. var P: PString;
  272. Index: Sw_integer;
  273. begin
  274. if S='' then P:=nil else
  275. if Search(@S,Index) then P:=At(Index) else
  276. begin
  277. P:=NewStr(S);
  278. Insert(P);
  279. end;
  280. Add:=P;
  281. end;
  282. {****************************************************************************
  283. TSymbolCollection
  284. ****************************************************************************}
  285. function TSymbolCollection.At(Index: Sw_Integer): PSymbol;
  286. begin
  287. At:=inherited At(Index);
  288. end;
  289. procedure TSymbolCollection.Insert(Item: Pointer);
  290. begin
  291. TCollection.Insert(Item);
  292. end;
  293. function TSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  294. begin
  295. Idx:=-1;
  296. LookUp:='';
  297. end;
  298. {****************************************************************************
  299. TReferenceCollection
  300. ****************************************************************************}
  301. function TReferenceCollection.At(Index: Sw_Integer): PReference;
  302. begin
  303. At:=inherited At(Index);
  304. end;
  305. {****************************************************************************
  306. TSortedSymbolCollection
  307. ****************************************************************************}
  308. function TSortedSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  309. var K1: PSymbol absolute Key1;
  310. K2: PSymbol absolute Key2;
  311. R: Sw_integer;
  312. S1,S2: string;
  313. begin
  314. S1:=Upper(K1^.GetName);
  315. S2:=Upper(K2^.GetName);
  316. if S1<S2 then R:=-1 else
  317. if S1>S2 then R:=1 else
  318. R:=0;
  319. Compare:=R;
  320. end;
  321. procedure TSortedSymbolCollection.Insert(Item: Pointer);
  322. begin
  323. TSortedCollection.Insert(Item);
  324. end;
  325. function TSortedSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  326. var OLI,ORI,Left,Right,Mid: integer;
  327. LeftP,RightP,MidP: PSymbol;
  328. RL: integer;
  329. LeftS,MidS,RightS: string;
  330. FoundS: string;
  331. UpS : string;
  332. begin
  333. Idx:=-1; FoundS:='';
  334. Left:=0; Right:=Count-1;
  335. UpS:=Upper(S);
  336. if Left<Right then
  337. begin
  338. while (Left<Right) do
  339. begin
  340. OLI:=Left; ORI:=Right;
  341. Mid:=Left+(Right-Left) div 2;
  342. LeftP:=At(Left); RightP:=At(Right); MidP:=At(Mid);
  343. LeftS:=Upper(LeftP^.GetName); MidS:=Upper(MidP^.GetName);
  344. RightS:=Upper(RightP^.GetName);
  345. if copy(MidS,1,length(UpS))=UpS then
  346. begin
  347. Idx:=Mid; FoundS:=copy(MidS,1,length(S));
  348. end;
  349. { else}
  350. if UpS<MidS then
  351. Right:=Mid
  352. else
  353. Left:=Mid;
  354. if (OLI=Left) and (ORI=Right) then
  355. Break;
  356. end;
  357. end;
  358. LookUp:=FoundS;
  359. end;
  360. {****************************************************************************
  361. TIDSortedSymbolCollection
  362. ****************************************************************************}
  363. function TIDSortedSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  364. var K1: PSymbol absolute Key1;
  365. K2: PSymbol absolute Key2;
  366. R: Sw_integer;
  367. begin
  368. if K1^.ObjectID<K2^.ObjectID then R:=-1 else
  369. if K1^.ObjectID>K2^.ObjectID then R:=1 else
  370. R:=0;
  371. Compare:=R;
  372. end;
  373. procedure TIDSortedSymbolCollection.Insert(Item: Pointer);
  374. begin
  375. TSortedCollection.Insert(Item);
  376. end;
  377. function TIDSortedSymbolCollection.SearchSymbolByID(AID: longint): PSymbol;
  378. var S: TSymbol;
  379. Index: sw_integer;
  380. P: PSymbol;
  381. begin
  382. S.ObjectID:=AID;
  383. if Search(@S,Index)=false then P:=nil else
  384. P:=At(Index);
  385. SearchSymbolByID:=P;
  386. end;
  387. {****************************************************************************
  388. TObjectSymbolCollection
  389. ****************************************************************************}
  390. function TObjectSymbolCollection.At(Index: Sw_Integer): PObjectSymbol;
  391. begin
  392. At:=inherited At(Index);
  393. end;
  394. function TObjectSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  395. var K1: PObjectSymbol absolute Key1;
  396. K2: PObjectSymbol absolute Key2;
  397. R: Sw_integer;
  398. S1,S2: string;
  399. begin
  400. S1:=Upper(K1^.GetName);
  401. S2:=Upper(K2^.GetName);
  402. if S1<S2 then R:=-1 else
  403. if S1>S2 then R:=1 else
  404. R:=0;
  405. Compare:=R;
  406. end;
  407. function TObjectSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  408. var OLI,ORI,Left,Right,Mid: integer;
  409. LeftP,RightP,MidP: PObjectSymbol;
  410. RL: integer;
  411. LeftS,MidS,RightS: string;
  412. FoundS: string;
  413. UpS : string;
  414. begin
  415. Idx:=-1; FoundS:='';
  416. Left:=0; Right:=Count-1;
  417. UpS:=Upper(S);
  418. if Left<Right then
  419. begin
  420. while (Left<Right) do
  421. begin
  422. OLI:=Left; ORI:=Right;
  423. Mid:=Left+(Right-Left) div 2;
  424. LeftP:=At(Left); RightP:=At(Right); MidP:=At(Mid);
  425. LeftS:=Upper(LeftP^.GetName); MidS:=Upper(MidP^.GetName);
  426. RightS:=Upper(RightP^.GetName);
  427. if copy(MidS,1,length(UpS))=UpS then
  428. begin
  429. Idx:=Mid; FoundS:=copy(MidS,1,length(S));
  430. end;
  431. { else}
  432. if UpS<MidS then
  433. Right:=Mid
  434. else
  435. Left:=Mid;
  436. if (OLI=Left) and (ORI=Right) then
  437. Break;
  438. end;
  439. end;
  440. LookUp:=FoundS;
  441. end;
  442. {****************************************************************************
  443. TReference
  444. ****************************************************************************}
  445. constructor TReference.Init(AFileName: PString; ALine, AColumn: Sw_integer);
  446. begin
  447. inherited Init;
  448. FileName:=AFileName;
  449. Position.X:=AColumn;
  450. Position.Y:=ALine;
  451. end;
  452. function TReference.GetFileName: string;
  453. begin
  454. GetFileName:=GetStr(FileName);
  455. end;
  456. destructor TReference.Done;
  457. begin
  458. inherited Done;
  459. end;
  460. constructor TReference.Load(var S: TStream);
  461. begin
  462. S.Read(Position, SizeOf(Position));
  463. { --- items needing fixup --- }
  464. S.Read(FileName, SizeOf(FileName)); { ->ModulesNames^.Item }
  465. end;
  466. procedure TReference.Store(var S: TStream);
  467. begin
  468. S.Write(Position, SizeOf(Position));
  469. { --- items needing fixup --- }
  470. S.Write(FileName, SizeOf(FileName));
  471. end;
  472. {****************************************************************************
  473. TSymbol
  474. ****************************************************************************}
  475. constructor TSymbol.Init(const AName: string; ATyp: tsymtyp; AParams: string; AMemInfo: PSymbolMemInfo);
  476. begin
  477. inherited Init;
  478. Name:=NewStr(AName); Typ:=ATyp;
  479. if AMemInfo<>nil then
  480. SetMemInfo(AMemInfo^);
  481. New(References, Init(20,50));
  482. if ATyp in RecordTypes then
  483. begin
  484. Items:=New(PSortedSymbolCollection, Init(50,100));
  485. end;
  486. end;
  487. procedure TSymbol.SetMemInfo(const AMemInfo: TSymbolMemInfo);
  488. begin
  489. if MemInfo=nil then New(MemInfo);
  490. Move(AMemInfo,MemInfo^,SizeOf(MemInfo^));
  491. Flags:=Flags or sfHasMemInfo;
  492. end;
  493. function TSymbol.GetReferenceCount: Sw_integer;
  494. var Count: Sw_integer;
  495. begin
  496. if References=nil then Count:=0 else
  497. Count:=References^.Count;
  498. GetReferenceCount:=Count;
  499. end;
  500. function TSymbol.GetReference(Index: Sw_integer): PReference;
  501. begin
  502. GetReference:=References^.At(Index);
  503. end;
  504. function TSymbol.GetItemCount: Sw_integer;
  505. var Count: Sw_integer;
  506. begin
  507. if Items=nil then Count:=0 else
  508. Count:=Items^.Count;
  509. GetItemCount:=Count;
  510. end;
  511. function TSymbol.GetItem(Index: Sw_integer): PSymbol;
  512. begin
  513. GetItem:=Items^.At(Index);
  514. end;
  515. function TSymbol.GetName: string;
  516. begin
  517. GetName:=GetStr(Name);
  518. end;
  519. function TSymbol.GetText: string;
  520. var S: string;
  521. I: Sw_integer;
  522. begin
  523. S:=GetTypeName;
  524. if length(S)>SymbolTypLen then
  525. S:=Copy(S,1,SymbolTypLen)
  526. else
  527. begin
  528. while length(S)<SymbolTypLen do
  529. S:=S+' ';
  530. end;
  531. S:=S+' '+GetName;
  532. if (Flags and sfRecord)<>0 then
  533. S:=S+' = record'
  534. else
  535. if (Flags and sfObject)<>0 then
  536. begin
  537. S:=S+' = ';
  538. if (Flags and sfClass)<>0 then
  539. S:=S+'class'
  540. else
  541. S:=S+'object';
  542. if Ancestor<>nil then
  543. S:=S+'('+Ancestor^.GetName+')';
  544. end
  545. else
  546. begin
  547. if Assigned(DType) then
  548. S:=S+' = '+DType^;
  549. if Assigned(Params) then
  550. S:=S+'('+Params^+')';
  551. if Assigned(VType) then
  552. S:=S+': '+VType^;
  553. end;
  554. GetText:=S;
  555. end;
  556. function TSymbol.GetTypeName: string;
  557. var S: string;
  558. begin
  559. case Typ of
  560. abstractsym : S:='abst';
  561. varsym : S:='var';
  562. typesym : S:='type';
  563. procsym : if VType=nil then
  564. S:='proc'
  565. else
  566. S:='func';
  567. unitsym : S:='unit';
  568. programsym : S:='prog';
  569. constsym : S:='const';
  570. enumsym : S:='enum';
  571. typedconstsym: S:='const';
  572. errorsym : S:='error';
  573. syssym : S:='sys';
  574. labelsym : S:='label';
  575. absolutesym : S:='abs';
  576. propertysym : S:='prop';
  577. funcretsym : S:='res';
  578. macrosym : S:='macro';
  579. else S:='';
  580. end;
  581. GetTypeName:=S;
  582. end;
  583. destructor TSymbol.Done;
  584. begin
  585. inherited Done;
  586. if assigned(MemInfo) then
  587. Dispose(MemInfo);
  588. if assigned(References) then
  589. Dispose(References, Done);
  590. if assigned(Items) then
  591. Dispose(Items, Done);
  592. if assigned(Name) then
  593. DisposeStr(Name);
  594. { if assigned(Params) then
  595. DisposeStr(Params);
  596. if assigned(VType) then
  597. DisposeStr(VType);
  598. if assigned(DType) then
  599. DisposeStr(DType);
  600. if assigned(Ancestor) then
  601. DisposeStr(Ancestor);}
  602. end;
  603. constructor TSymbol.Load(var S: TStream);
  604. var MI: TSymbolMemInfo;
  605. W: word;
  606. begin
  607. TObject.Init;
  608. S.Read(Typ,SizeOf(Typ));
  609. S.Read(ObjectID, SizeOf(ObjectID));
  610. S.Read(AncestorID, SizeOf(AncestorID));
  611. S.Read(Flags, SizeOf(Flags));
  612. Name:=S.ReadStr;
  613. Params:=S.ReadStr;
  614. if (Flags and sfHasMemInfo)<>0 then
  615. begin
  616. S.Read(MI,SizeOf(MI));
  617. SetMemInfo(MI);
  618. end;
  619. W:=0;
  620. S.Read(W,SizeOf(W));
  621. if (W and 1)<>0 then
  622. New(References, Load(S));
  623. if (W and 2)<>0 then
  624. New(Items, Load(S));
  625. { --- items needing fixup --- }
  626. S.Read(DType, SizeOf(DType));
  627. S.Read(VType, SizeOf(VType));
  628. S.Read(Ancestor, SizeOf(Ancestor));
  629. end;
  630. procedure TSymbol.Store(var S: TStream);
  631. var W: word;
  632. begin
  633. S.Write(Typ,SizeOf(Typ));
  634. S.Write(ObjectID, SizeOf(ObjectID));
  635. S.Write(AncestorID, SizeOf(AncestorID));
  636. S.Write(Flags, SizeOf(Flags));
  637. S.WriteStr(Name);
  638. S.WriteStr(Params);
  639. if (Flags and sfHasMemInfo)<>0 then
  640. S.Write(MemInfo^,SizeOf(MemInfo^));
  641. W:=0;
  642. if Assigned(References) then W:=W or 1;
  643. if Assigned(Items) then W:=W or 2;
  644. S.Write(W,SizeOf(W));
  645. if Assigned(References) then References^.Store(S);
  646. if Assigned(Items) then Items^.Store(S);
  647. { --- items needing fixup --- }
  648. S.Write(DType, SizeOf(DType));
  649. S.Write(VType, SizeOf(VType));
  650. S.Write(Ancestor, SizeOf(Ancestor));
  651. end;
  652. constructor TObjectSymbol.Init(AParent: PObjectSymbol; ASymbol: PSymbol);
  653. begin
  654. inherited Init;
  655. Parent:=AParent;
  656. Symbol:=ASymbol;
  657. end;
  658. constructor TObjectSymbol.InitName(const AName: string);
  659. begin
  660. inherited Init;
  661. Name:=NewStr(AName);
  662. end;
  663. function TObjectSymbol.GetName: string;
  664. begin
  665. if Name<>nil then
  666. GetName:=Name^
  667. else
  668. GetName:=Symbol^.GetName;
  669. end;
  670. function TObjectSymbol.GetDescendantCount: sw_integer;
  671. var Count: sw_integer;
  672. begin
  673. if Descendants=nil then Count:=0 else
  674. Count:=Descendants^.Count;
  675. GetDescendantCount:=Count;
  676. end;
  677. function TObjectSymbol.GetDescendant(Index: sw_integer): PObjectSymbol;
  678. begin
  679. GetDescendant:=Descendants^.At(Index);
  680. end;
  681. procedure TObjectSymbol.AddDescendant(P: PObjectSymbol);
  682. begin
  683. if Descendants=nil then
  684. New(Descendants, Init(50,10));
  685. Descendants^.Insert(P);
  686. end;
  687. destructor TObjectSymbol.Done;
  688. begin
  689. if Assigned(Name) then DisposeStr(Name); Name:=nil;
  690. if Assigned(Descendants) then Dispose(Descendants, Done); Descendants:=nil;
  691. inherited Done;
  692. end;
  693. constructor TObjectSymbol.Load(var S: TStream);
  694. begin
  695. end;
  696. procedure TObjectSymbol.Store(S: TStream);
  697. begin
  698. end;
  699. {****************************************************************************
  700. TSourceFile
  701. ****************************************************************************}
  702. constructor TSourceFile.Init(ASourceFileName, AObjFileName, APPUFileName: string);
  703. begin
  704. inherited Init;
  705. SourceFileName:=NewStr(ASourceFileName);
  706. ObjFileName:=NewStr(AObjFileName);
  707. PPUFileName:=NewStr(APPUFileName);
  708. end;
  709. destructor TSourceFile.Done;
  710. begin
  711. inherited Done;
  712. if assigned(SourceFileName) then DisposeStr(SourceFileName);
  713. if assigned(ObjFileName) then DisposeStr(ObjFileName);
  714. if assigned(PPUFileName) then DisposeStr(PPUFileName);
  715. end;
  716. function TSourceFile.GetSourceFilename: string;
  717. begin
  718. GetSourceFilename:=GetStr(SourceFileName);
  719. end;
  720. function TSourceFile.GetObjFileName: string;
  721. begin
  722. GetObjFilename:=GetStr(ObjFileName);
  723. end;
  724. function TSourceFile.GetPPUFileName: string;
  725. begin
  726. GetPPUFilename:=GetStr(PPUFileName);
  727. end;
  728. function TSourceFileCollection.At(Index: sw_Integer): PSourceFile;
  729. begin
  730. At:=inherited At(Index);
  731. end;
  732. {*****************************************************************************
  733. Main Routines
  734. *****************************************************************************}
  735. procedure DisposeBrowserCol;
  736. begin
  737. if assigned(Modules) then
  738. begin
  739. dispose(Modules,Done);
  740. Modules:=nil;
  741. end;
  742. if assigned(ModuleNames) then
  743. begin
  744. dispose(ModuleNames,Done);
  745. ModuleNames:=nil;
  746. end;
  747. if assigned(TypeNames) then
  748. begin
  749. dispose(TypeNames,Done);
  750. TypeNames:=nil;
  751. end;
  752. if assigned(ObjectTree) then
  753. begin
  754. Dispose(ObjectTree, Done);
  755. ObjectTree:=nil;
  756. end;
  757. end;
  758. procedure NewBrowserCol;
  759. begin
  760. New(Modules, Init(50,50));
  761. New(ModuleNames, Init(50,50));
  762. New(TypeNames, Init(1000,5000));
  763. end;
  764. procedure CreateBrowserCol;
  765. procedure ProcessSymTable(OwnerSym: PSymbol; var Owner: PSymbolCollection; Table: PSymTable);
  766. var I,J,defcount,symcount: longint;
  767. Ref: PRef;
  768. Sym,ParSym: PSym;
  769. Symbol: PSymbol;
  770. Reference: PReference;
  771. ParamCount: Sw_integer;
  772. Params: array[0..20] of PString;
  773. inputfile : pinputfile;
  774. Idx: sw_integer;
  775. S: string;
  776. procedure SetVType(Symbol: PSymbol; VType: string);
  777. begin
  778. Symbol^.VType:=TypeNames^.Add(VType);
  779. end;
  780. procedure SetDType(Symbol: PSymbol; DType: string);
  781. begin
  782. Symbol^.DType:=TypeNames^.Add(DType);
  783. end;
  784. function GetDefinitionStr(def: pdef): string; forward;
  785. function GetEnumDefStr(def: penumdef): string;
  786. var Name: string;
  787. esym: penumsym;
  788. Count: integer;
  789. begin
  790. Name:='(';
  791. esym:=def^.Firstenum; Count:=0;
  792. while (esym<>nil) do
  793. begin
  794. if Count>0 then
  795. Name:=Name+', ';
  796. Name:=Name+esym^.name;
  797. esym:=esym^.nextenum;
  798. Inc(Count);
  799. end;
  800. Name:=Name+')';
  801. GetEnumDefStr:=Name;
  802. end;
  803. function GetArrayDefStr(def: parraydef): string;
  804. var Name: string;
  805. begin
  806. Name:='array ['+IntToStr(def^.lowrange)+'..'+IntToStr(def^.highrange)+'] of ';
  807. if assigned(def^.definition) then
  808. Name:=Name+GetDefinitionStr(def^.definition);
  809. GetArrayDefStr:=Name;
  810. end;
  811. function GetFileDefStr(def: pfiledef): string;
  812. var Name: string;
  813. begin
  814. Name:='';
  815. case def^.filetype of
  816. ft_text : Name:='text';
  817. ft_untyped : Name:='file';
  818. ft_typed : Name:='file of '+GetDefinitionStr(def^.typed_as);
  819. end;
  820. GetFileDefStr:=Name;
  821. end;
  822. function GetStringDefStr(def: pstringdef): string;
  823. var Name: string;
  824. begin
  825. Name:='';
  826. case def^.string_typ of
  827. st_shortstring :
  828. if def^.len=255 then
  829. Name:='shortstring'
  830. else
  831. Name:='string['+IntToStr(def^.len)+']';
  832. st_longstring :
  833. Name:='longstring';
  834. st_ansistring :
  835. Name:='ansistring';
  836. st_widestring :
  837. Name:='widestring';
  838. else ;
  839. end;
  840. GetStringDefStr:=Name;
  841. end;
  842. function retdefassigned(def: pabstractprocdef): boolean;
  843. var OK: boolean;
  844. begin
  845. OK:=false;
  846. if assigned(def^.retdef) then
  847. if UpcaseStr(GetDefinitionStr(def^.retdef))<>'VOID' then
  848. OK:=true;
  849. retdefassigned:=OK;
  850. end;
  851. function GetAbsProcParmDefStr(def: pabstractprocdef): string;
  852. var Name: string;
  853. dc: pdefcoll;
  854. Count: integer;
  855. CurName: string;
  856. begin
  857. Name:='';
  858. dc:=def^.para1; Count:=0;
  859. while dc<>nil do
  860. begin
  861. CurName:='';
  862. case dc^.paratyp of
  863. vs_Value : ;
  864. vs_Const : CurName:=CurName+'const ';
  865. vs_Var : CurName:=CurName+'var ';
  866. end;
  867. if assigned(dc^.data) then
  868. CurName:=CurName+GetDefinitionStr(dc^.data);
  869. if dc^.next<>nil then
  870. CurName:=', '+CurName;
  871. Name:=CurName+Name;
  872. dc:=dc^.next; Inc(Count);
  873. end;
  874. GetAbsProcParmDefStr:=Name;
  875. end;
  876. function GetAbsProcDefStr(def: pabstractprocdef): string;
  877. var Name: string;
  878. begin
  879. Name:=GetAbsProcParmDefStr(def);
  880. if Name<>'' then Name:='('+Name+')';
  881. if retdefassigned(def) then
  882. Name:='function'+Name+': '+GetDefinitionStr(def^.retdef)
  883. else
  884. Name:='procedure'+Name;
  885. GetAbsProcDefStr:=Name;
  886. end;
  887. function GetProcDefStr(def: pprocdef): string;
  888. var DName: string;
  889. J: integer;
  890. begin
  891. { DName:='';
  892. if assigned(def) then
  893. begin
  894. if assigned(def^.parast) then
  895. begin
  896. with def^.parast^ do
  897. for J:=1 to number_symbols do
  898. begin
  899. if J<>1 then DName:=DName+', ';
  900. ParSym:=GetsymNr(J);
  901. if ParSym=nil then Break;
  902. DName:=DName+ParSym^.Name;
  903. end;
  904. end
  905. end;}
  906. DName:=GetAbsProcDefStr(def);
  907. GetProcDefStr:=DName;
  908. end;
  909. function GetProcVarDefStr(def: pprocvardef): string;
  910. begin
  911. GetProcVarDefStr:=GetAbsProcDefStr(def);
  912. end;
  913. function GetSetDefStr(def: psetdef): string;
  914. var Name: string;
  915. begin
  916. Name:='';
  917. case def^.settype of
  918. normset : Name:='set';
  919. smallset : Name:='set';
  920. varset : Name:='varset';
  921. end;
  922. Name:=Name+' of ';
  923. Name:=Name+GetDefinitionStr(def^.setof);
  924. GetSetDefStr:=Name;
  925. end;
  926. function GetDefinitionStr(def: pdef): string;
  927. var Name: string;
  928. sym: psym;
  929. begin
  930. Name:='';
  931. if def<>nil then
  932. begin
  933. if assigned(def^.sym) then
  934. Name:=def^.sym^.name;
  935. if Name='' then
  936. case def^.deftype of
  937. arraydef :
  938. Name:=GetArrayDefStr(parraydef(def));
  939. stringdef :
  940. Name:=GetStringDefStr(pstringdef(def));
  941. enumdef :
  942. Name:=GetEnumDefStr(penumdef(def));
  943. procdef :
  944. Name:=GetProcDefStr(pprocdef(def));
  945. procvardef :
  946. Name:=GetProcVarDefStr(pprocvardef(def));
  947. filedef :
  948. Name:=GetFileDefStr(pfiledef(def));
  949. setdef :
  950. Name:=GetSetDefStr(psetdef(def));
  951. end;
  952. end;
  953. GetDefinitionStr:=Name;
  954. end;
  955. function GetEnumItemName(Sym: penumsym): string;
  956. var Name: string;
  957. ES: penumsym;
  958. begin
  959. Name:='';
  960. if assigned(sym) and assigned(sym^.definition) then
  961. if assigned(sym^.definition^.sym) then
  962. begin
  963. { ES:=sym^.definition^.First;
  964. while (ES<>nil) and (ES^.Value<>sym^.Value) do
  965. ES:=ES^.next;
  966. if assigned(es) and (es^.value=sym^.value) then
  967. Name:=}
  968. Name:=sym^.definition^.sym^.name;
  969. if Name<>'' then
  970. Name:=Name+'('+IntToStr(sym^.value)+')';
  971. end;
  972. GetEnumItemName:=Name;
  973. end;
  974. function GetConstValueName(sym: pconstsym): string;
  975. var Name: string;
  976. begin
  977. Name:='';
  978. { if assigned(sym^.definition) then
  979. if assigned(sym^.definition^.sym) then
  980. Name:=sym^.definition^.sym^.name;}
  981. if Name='' then
  982. case sym^.consttype of
  983. constord :
  984. Name:=sym^.definition^.sym^.name+'('+IntToStr(sym^.value)+')';
  985. conststring :
  986. Name:=''''+GetStr(PString(sym^.Value))+'''';
  987. constreal:
  988. Name:=FloatToStr(PBestReal(sym^.Value)^);
  989. constbool:
  990. { if boolean(sym^.Value)=true then
  991. Name:='TRUE'
  992. else
  993. Name:='FALSE';}
  994. Name:='Longbool('+IntToStr(sym^.Value)+')';
  995. constint:
  996. Name:=IntToStr(sym^.value);
  997. constchar:
  998. Name:=''''+chr(sym^.Value)+'''';
  999. constset:
  1000. { Name:=SetToStr(pnormalset(sym^.Value))};
  1001. constnil: ;
  1002. end;
  1003. GetConstValueName:=Name;
  1004. end;
  1005. procedure ProcessDefIfStruct(definition: pdef);
  1006. begin
  1007. if assigned(definition) then
  1008. begin
  1009. case definition^.deftype of
  1010. recorddef :
  1011. if precorddef(definition)^.symtable<>Table then
  1012. ProcessSymTable(Symbol,Symbol^.Items,precorddef(definition)^.symtable);
  1013. objectdef :
  1014. if pobjectdef(definition)^.symtable<>Table then
  1015. ProcessSymTable(Symbol,Symbol^.Items,pobjectdef(definition)^.symtable);
  1016. { leads to infinite loops !!
  1017. pointerdef :
  1018. with ppointerdef(definition)^ do
  1019. if assigned(definition) then
  1020. if assigned(definition^.sym) then
  1021. ProcessDefIfStruct(definition^.sym^.definition);}
  1022. end;
  1023. end;
  1024. end;
  1025. var MemInfo: TSymbolMemInfo;
  1026. ObjDef: pobjectdef;
  1027. begin
  1028. if not Assigned(Table) then
  1029. Exit;
  1030. if Owner=nil then
  1031. Owner:=New(PSortedSymbolCollection, Init(10,50));
  1032. sym:=psym(Table^.symindex^.first);
  1033. while assigned(sym) do
  1034. begin
  1035. ParamCount:=0;
  1036. New(Symbol, Init(Sym^.Name,Sym^.Typ,'',nil));
  1037. case Sym^.Typ of
  1038. varsym :
  1039. with pvarsym(sym)^ do
  1040. begin
  1041. if assigned(definition) then
  1042. if assigned(definition^.sym) then
  1043. SetVType(Symbol,definition^.sym^.name)
  1044. else
  1045. SetVType(Symbol,GetDefinitionStr(definition));
  1046. ProcessDefIfStruct(definition);
  1047. MemInfo.Addr:=address;
  1048. if assigned(localvarsym) then
  1049. MemInfo.LocalAddr:=localvarsym^.address
  1050. else
  1051. MemInfo.LocalAddr:=0;
  1052. MemInfo.Size:=getsize;
  1053. MemInfo.PushSize:=getpushsize;
  1054. Symbol^.SetMemInfo(MemInfo);
  1055. end;
  1056. constsym :
  1057. SetDType(Symbol,GetConstValueName(pconstsym(sym)));
  1058. enumsym :
  1059. if assigned(penumsym(sym)^.definition) then
  1060. SetDType(Symbol,GetEnumItemName(penumsym(sym)));
  1061. unitsym :
  1062. begin
  1063. { ProcessSymTable(Symbol^.Items,punitsym(sym)^.unitsymtable);}
  1064. end;
  1065. syssym :
  1066. { if assigned(Table^.Name) then
  1067. if Table^.Name^='SYSTEM' then}
  1068. begin
  1069. Symbol^.Params:=TypeNames^.Add('...');
  1070. end;
  1071. funcretsym :
  1072. if Assigned(OwnerSym) then
  1073. with pfuncretsym(sym)^ do
  1074. if assigned(funcretdef) then
  1075. if assigned(funcretdef^.sym) then
  1076. SetVType(OwnerSym,funcretdef^.sym^.name);
  1077. procsym :
  1078. begin
  1079. with pprocsym(sym)^ do
  1080. if assigned(definition) then
  1081. begin
  1082. if cs_local_browser in aktmoduleswitches then
  1083. ProcessSymTable(Symbol,Symbol^.Items,definition^.parast);
  1084. if assigned(definition^.parast) then
  1085. begin
  1086. Symbol^.Params:=TypeNames^.Add(GetAbsProcParmDefStr(definition));
  1087. end
  1088. else { param-definition is NOT assigned }
  1089. if assigned(Table^.Name) then
  1090. if Table^.Name^='SYSTEM' then
  1091. begin
  1092. Symbol^.Params:=TypeNames^.Add('...');
  1093. end;
  1094. if cs_local_browser in aktmoduleswitches then
  1095. begin
  1096. if assigned(definition^.localst) and
  1097. (definition^.localst^.symtabletype<>staticsymtable) then
  1098. ProcessSymTable(Symbol,Symbol^.Items,definition^.localst);
  1099. end;
  1100. end;
  1101. end;
  1102. typesym :
  1103. begin
  1104. with ptypesym(sym)^ do
  1105. if assigned(definition) then
  1106. case definition^.deftype of
  1107. arraydef :
  1108. SetDType(Symbol,GetArrayDefStr(parraydef(definition)));
  1109. enumdef :
  1110. SetDType(Symbol,GetEnumDefStr(penumdef(definition)));
  1111. procdef :
  1112. SetDType(Symbol,GetProcDefStr(pprocdef(definition)));
  1113. procvardef :
  1114. SetDType(Symbol,GetProcVarDefStr(pprocvardef(definition)));
  1115. objectdef :
  1116. with pobjectdef(definition)^ do
  1117. begin
  1118. ObjDef:=childof;
  1119. Symbol^.ObjectID:=longint(definition);
  1120. if ObjDef<>nil then
  1121. Symbol^.AncestorID:=longint(ObjDef);{TypeNames^.Add(S);}
  1122. Symbol^.Flags:=(Symbol^.Flags or sfObject);
  1123. if is_class then
  1124. Symbol^.Flags:=(Symbol^.Flags or sfClass);
  1125. ProcessSymTable(Symbol,Symbol^.Items,pobjectdef(definition)^.symtable);
  1126. end;
  1127. recorddef :
  1128. begin
  1129. Symbol^.Flags:=(Symbol^.Flags or sfRecord);
  1130. ProcessSymTable(Symbol,Symbol^.Items,precorddef(definition)^.symtable);
  1131. end;
  1132. filedef :
  1133. SetDType(Symbol,GetFileDefStr(pfiledef(definition)));
  1134. setdef :
  1135. SetDType(Symbol,GetSetDefStr(psetdef(definition)));
  1136. end;
  1137. end;
  1138. end;
  1139. Ref:=Sym^.defref;
  1140. while Assigned(Symbol) and assigned(Ref) do
  1141. begin
  1142. inputfile:=get_source_file(ref^.moduleindex,ref^.posinfo.fileindex);
  1143. if Assigned(inputfile) and Assigned(inputfile^.name) then
  1144. begin
  1145. New(Reference, Init(ModuleNames^.Add(inputfile^.name^),
  1146. ref^.posinfo.line,ref^.posinfo.column));
  1147. Symbol^.References^.Insert(Reference);
  1148. end;
  1149. Ref:=Ref^.nextref;
  1150. end;
  1151. if Assigned(Symbol) then
  1152. Owner^.Insert(Symbol);
  1153. sym:=psym(sym^.next);
  1154. end;
  1155. end;
  1156. var
  1157. T: PSymTable;
  1158. UnitS: PSymbol;
  1159. hp : pmodule;
  1160. begin
  1161. DisposeBrowserCol;
  1162. NewBrowserCol;
  1163. hp:=pmodule(loaded_units.first);
  1164. while assigned(hp) do
  1165. begin
  1166. t:=psymtable(hp^.globalsymtable);
  1167. if assigned(t) then
  1168. begin
  1169. New(UnitS, Init(T^.Name^,unitsym,'',nil));
  1170. Modules^.Insert(UnitS);
  1171. ProcessSymTable(UnitS,UnitS^.Items,T);
  1172. if cs_local_browser in aktmoduleswitches then
  1173. begin
  1174. t:=psymtable(hp^.localsymtable);
  1175. if assigned(t) then
  1176. ProcessSymTable(UnitS,UnitS^.Items,T);
  1177. end;
  1178. end;
  1179. hp:=pmodule(hp^.next);
  1180. end;
  1181. BuildObjectInfo;
  1182. BuildSourceList;
  1183. end;
  1184. procedure BuildObjectInfo;
  1185. var C: PIDSortedSymbolCollection;
  1186. ObjectC: PObjectSymbolCollection;
  1187. ObjectsSymbol: PObjectSymbol;
  1188. procedure InsertSymbolCollection(Symbols: PSymbolCollection);
  1189. var I: sw_integer;
  1190. P: PSymbol;
  1191. begin
  1192. for I:=0 to Symbols^.Count-1 do
  1193. begin
  1194. P:=Symbols^.At(I);
  1195. if (P^.Flags and sfObject)<>0 then
  1196. C^.Insert(P);
  1197. if P^.Items<>nil then
  1198. InsertSymbolCollection(P^.Items);
  1199. end;
  1200. end;
  1201. function SearchObjectForSym(O: PSymbol): PObjectSymbol;
  1202. var I,Idx: sw_integer;
  1203. OS,P: PObjectSymbol;
  1204. begin
  1205. P:=nil;
  1206. for I:=0 to ObjectC^.Count-1 do
  1207. begin
  1208. OS:=ObjectC^.At(I);
  1209. if OS^.Symbol=O then
  1210. begin P:=OS; Break; end;
  1211. end;
  1212. SearchObjectForSym:=P;
  1213. end;
  1214. procedure BuildTree;
  1215. var I: sw_integer;
  1216. Symbol: PSymbol;
  1217. Parent,OS: PObjectSymbol;
  1218. begin
  1219. I:=0;
  1220. while (I<C^.Count) do
  1221. begin
  1222. Symbol:=C^.At(I);
  1223. if Symbol^.Ancestor=nil then
  1224. Parent:=ObjectsSymbol
  1225. else
  1226. Parent:=SearchObjectForSym(Symbol^.Ancestor);
  1227. if Parent<>nil then
  1228. begin
  1229. New(OS, Init(Parent, Symbol));
  1230. Parent^.AddDescendant(OS);
  1231. ObjectC^.Insert(OS);
  1232. C^.AtDelete(I);
  1233. end
  1234. else
  1235. Inc(I);
  1236. end;
  1237. end;
  1238. var Pass: integer;
  1239. I: sw_integer;
  1240. P: PSymbol;
  1241. begin
  1242. New(C, Init(1000,5000));
  1243. InsertSymbolCollection(Modules);
  1244. { --- Resolve ancestor<->descendant references --- }
  1245. for I:=0 to C^.Count-1 do
  1246. begin
  1247. P:=C^.At(I);
  1248. if P^.AncestorID<>0 then
  1249. P^.Ancestor:=C^.SearchSymbolByID(P^.AncestorID);
  1250. end;
  1251. { --- Build object tree --- }
  1252. if assigned(ObjectTree) then Dispose(ObjectTree, Done);
  1253. New(ObjectsSymbol, InitName('Objects'));
  1254. ObjectTree:=ObjectsSymbol;
  1255. New(ObjectC, Init(C^.Count,100));
  1256. Pass:=0;
  1257. if C^.Count>0 then
  1258. repeat
  1259. BuildTree;
  1260. Inc(Pass);
  1261. until (C^.Count=0) or (Pass>20); { more than 20 levels ? - then there must be a bug }
  1262. ObjectC^.DeleteAll; Dispose(ObjectC, Done);
  1263. C^.DeleteAll; Dispose(C, Done);
  1264. end;
  1265. function SearchObjectForSymbol(O: PSymbol): PObjectSymbol;
  1266. function ScanObjectCollection(Parent: PObjectSymbol): PObjectSymbol;
  1267. var I: sw_integer;
  1268. OS,P: PObjectSymbol;
  1269. ObjectC: PObjectSymbolCollection;
  1270. begin
  1271. P:=nil;
  1272. if Parent<>nil then
  1273. if Parent^.Descendants<>nil then
  1274. begin
  1275. ObjectC:=Parent^.Descendants;
  1276. for I:=0 to ObjectC^.Count-1 do
  1277. begin
  1278. OS:=ObjectC^.At(I);
  1279. if OS^.Symbol=O then
  1280. begin P:=OS; Break; end;
  1281. if OS^.Descendants<>nil then
  1282. begin
  1283. P:=ScanObjectCollection(OS);
  1284. if P<>nil then Break;
  1285. end;
  1286. end;
  1287. end;
  1288. ScanObjectCollection:=P;
  1289. end;
  1290. begin
  1291. SearchObjectForSymbol:=ScanObjectCollection(ObjectTree);
  1292. end;
  1293. procedure BuildSourceList;
  1294. var m: pmodule;
  1295. s: pinputfile;
  1296. p: cobjects.pstring;
  1297. ppu,obj: string;
  1298. source: string;
  1299. begin
  1300. if Assigned(SourceFiles) then
  1301. begin Dispose(SourceFiles, Done); SourceFiles:=nil; end;
  1302. if assigned(loaded_units.first) then
  1303. begin
  1304. New(SourceFiles, Init(50,10));
  1305. m:=pmodule(loaded_units.first);
  1306. while assigned(m) do
  1307. begin
  1308. obj:=fexpand(m^.objfilename^);
  1309. ppu:=''; source:='';
  1310. if m^.is_unit then
  1311. ppu:=fexpand(m^.ppufilename^);
  1312. if (m^.is_unit=false) and (m^.islibrary=false) then
  1313. ppu:=fexpand(m^.exefilename^);
  1314. if assigned(p) then
  1315. begin
  1316. if assigned(m^.sourcefiles) then
  1317. begin
  1318. s:=m^.sourcefiles^.files;
  1319. while assigned(s) do
  1320. begin
  1321. source:='';
  1322. p:=s^.path;
  1323. if assigned(p) then
  1324. source:=source+p^;
  1325. p:=s^.name;
  1326. if assigned(p) then
  1327. source:=source+p^;
  1328. source:=fexpand(source);
  1329. SourceFiles^.Insert(New(PSourceFile, Init(source,obj,ppu)));
  1330. s:=s^.next;
  1331. end;
  1332. end;
  1333. end;
  1334. m:=pmodule(m^.next);
  1335. end;
  1336. end;
  1337. end;
  1338. {*****************************************************************************
  1339. Initialize
  1340. *****************************************************************************}
  1341. var
  1342. oldexit : pointer;
  1343. procedure browcol_exit;{$ifndef FPC}far;{$endif}
  1344. begin
  1345. exitproc:=oldexit;
  1346. DisposeBrowserCol;
  1347. end;
  1348. procedure InitBrowserCol;
  1349. begin
  1350. end;
  1351. procedure DoneBrowserCol;
  1352. begin
  1353. { nothing, the collections are freed in the exitproc - ??? }
  1354. { nothing? then why do we've this routine for ? IMHO, either we should
  1355. remove this, or it should destroy the browser info when it's called. - BG }
  1356. end;
  1357. type
  1358. PPointerXRef = ^TPointerXRef;
  1359. TPointerXRef = record
  1360. PtrValue : pointer;
  1361. DataPtr : pointer;
  1362. end;
  1363. PPointerDictionary = ^TPointerDictionary;
  1364. TPointerDictionary = object(TSortedCollection)
  1365. function At(Index: sw_Integer): PPointerXRef;
  1366. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  1367. procedure FreeItem(Item: Pointer); virtual;
  1368. function SearchXRef(PtrValue: pointer): PPointerXRef;
  1369. function AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1370. procedure Resolve(var P);
  1371. end;
  1372. function NewPointerXRef(APtrValue, ADataPtr: pointer): PPointerXRef;
  1373. var P: PPointerXRef;
  1374. begin
  1375. New(P); FillChar(P^,SizeOf(P^),0);
  1376. with P^ do begin PtrValue:=APtrValue; DataPtr:=ADataPtr; end;
  1377. NewPointerXRef:=P;
  1378. end;
  1379. procedure DisposePointerXRef(P: PPointerXRef);
  1380. begin
  1381. if Assigned(P) then Dispose(P);
  1382. end;
  1383. function TPointerDictionary.At(Index: sw_Integer): PPointerXRef;
  1384. begin
  1385. At:=inherited At(Index);
  1386. end;
  1387. function TPointerDictionary.Compare(Key1, Key2: Pointer): sw_Integer;
  1388. var K1: PPointerXRef absolute Key1;
  1389. K2: PPointerXRef absolute Key2;
  1390. R: integer;
  1391. begin
  1392. if longint(K1^.PtrValue)<longint(K2^.PtrValue) then R:=-1 else
  1393. if longint(K1^.PtrValue)>longint(K2^.PtrValue) then R:= 1 else
  1394. R:=0;
  1395. Compare:=R;
  1396. end;
  1397. procedure TPointerDictionary.FreeItem(Item: Pointer);
  1398. begin
  1399. if Assigned(Item) then DisposePointerXRef(Item);
  1400. end;
  1401. function TPointerDictionary.SearchXRef(PtrValue: pointer): PPointerXRef;
  1402. var P: PPointerXRef;
  1403. T: TPointerXRef;
  1404. Index: sw_integer;
  1405. begin
  1406. T.PtrValue:=PtrValue;
  1407. if Search(@T,Index)=false then P:=nil else
  1408. P:=At(Index);
  1409. SearchXRef:=P;
  1410. end;
  1411. function TPointerDictionary.AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1412. var P: PPointerXRef;
  1413. begin
  1414. P:=NewPointerXRef(PtrValue,DataPtr);
  1415. Insert(P);
  1416. AddPtr:=P;
  1417. end;
  1418. procedure TPointerDictionary.Resolve(var P);
  1419. var X: PPointerXRef;
  1420. V: pointer;
  1421. begin
  1422. Move(P,V,SizeOf(V));
  1423. X:=SearchXRef(V);
  1424. if X=nil then V:=nil else
  1425. V:=X^.DataPtr;
  1426. Move(V,P,SizeOf(V));
  1427. end;
  1428. procedure ReadPointers(S: PStream; C: PCollection; D: PPointerDictionary);
  1429. var W,I: sw_integer;
  1430. P: pointer;
  1431. begin
  1432. S^.Read(W,SizeOf(W));
  1433. for I:=0 to W-1 do
  1434. begin
  1435. S^.Read(P,SizeOf(P));
  1436. D^.AddPtr(P,C^.At(I));
  1437. end;
  1438. end;
  1439. function LoadBrowserCol(S: PStream): boolean;
  1440. var PD: PPointerDictionary;
  1441. procedure FixupPointers;
  1442. procedure FixupReference(P: PReference); {$ifndef FPC}far;{$endif}
  1443. begin
  1444. PD^.Resolve(P^.FileName);
  1445. end;
  1446. procedure FixupSymbol(P: PSymbol); {$ifndef FPC}far;{$endif}
  1447. var I: sw_integer;
  1448. begin
  1449. PD^.Resolve(P^.DType);
  1450. PD^.Resolve(P^.VType);
  1451. PD^.Resolve(P^.Ancestor);
  1452. if Assigned(P^.References) then
  1453. with P^.References^ do
  1454. for I:=0 to Count-1 do
  1455. FixupReference(At(I));
  1456. if Assigned(P^.Items) then
  1457. with P^.Items^ do
  1458. for I:=0 to Count-1 do
  1459. FixupSymbol(At(I));
  1460. end;
  1461. begin
  1462. Modules^.ForEach(@FixupSymbol);
  1463. end;
  1464. procedure ReadSymbolPointers(P: PSymbol); {$ifndef FPC}far;{$endif}
  1465. var I: sw_integer;
  1466. PV: pointer;
  1467. begin
  1468. S^.Read(PV, SizeOf(PV));
  1469. PD^.AddPtr(PV,P);
  1470. if Assigned(P^.Items) then
  1471. with P^.Items^ do
  1472. for I:=0 to Count-1 do
  1473. ReadSymbolPointers(At(I));
  1474. end;
  1475. begin
  1476. DisposeBrowserCol;
  1477. New(ModuleNames, Load(S^));
  1478. New(TypeNames, Load(S^));
  1479. New(Modules, Load(S^));
  1480. New(PD, Init(4000,1000));
  1481. ReadPointers(S,ModuleNames,PD);
  1482. ReadPointers(S,TypeNames,PD);
  1483. ReadPointers(S,Modules,PD);
  1484. Modules^.ForEach(@ReadSymbolPointers);
  1485. FixupPointers;
  1486. Dispose(PD, Done);
  1487. BuildObjectInfo;
  1488. end;
  1489. procedure StorePointers(S: PStream; C: PCollection);
  1490. var W,I: sw_integer;
  1491. P: pointer;
  1492. begin
  1493. W:=C^.Count;
  1494. S^.Write(W,SizeOf(W));
  1495. for I:=0 to W-1 do
  1496. begin
  1497. P:=C^.At(I);
  1498. S^.Write(P,SizeOf(P));
  1499. end;
  1500. end;
  1501. procedure StoreBrowserCol(S: PStream);
  1502. procedure WriteSymbolPointers(P: PSymbol); {$ifndef FPC}far;{$endif}
  1503. var I: sw_integer;
  1504. begin
  1505. S^.Write(P, SizeOf(P));
  1506. if Assigned(P^.Items) then
  1507. with P^.Items^ do
  1508. for I:=0 to Count-1 do
  1509. WriteSymbolPointers(At(I));
  1510. end;
  1511. var W: sw_integer;
  1512. begin
  1513. ModuleNames^.Store(S^);
  1514. TypeNames^.Store(S^);
  1515. Modules^.Store(S^);
  1516. StorePointers(S,ModuleNames);
  1517. StorePointers(S,TypeNames);
  1518. StorePointers(S,Modules);
  1519. Modules^.ForEach(@WriteSymbolPointers);
  1520. end;
  1521. procedure RegisterSymbols;
  1522. begin
  1523. RegisterType(RModuleNameCollection);
  1524. RegisterType(RTypeNameCollection);
  1525. RegisterType(RReference);
  1526. RegisterType(RSymbol);
  1527. RegisterType(RObjectSymbol);
  1528. RegisterType(RSymbolCollection);
  1529. RegisterType(RSortedSymbolCollection);
  1530. RegisterType(RIDSortedSymbolCollection);
  1531. RegisterType(RObjectSymbolCollection);
  1532. RegisterType(RReferenceCollection);
  1533. end;
  1534. begin
  1535. oldexit:=exitproc;
  1536. exitproc:=@browcol_exit;
  1537. end.
  1538. {
  1539. $Log$
  1540. Revision 1.22 1999-08-16 18:25:49 peter
  1541. * fixes from gabor
  1542. Revision 1.21 1999/08/09 14:09:04 peter
  1543. * updated for symtable updates
  1544. Revision 1.20 1999/08/03 22:02:29 peter
  1545. * moved bitmask constants to sets
  1546. * some other type/const renamings
  1547. Revision 1.17 1999/06/22 16:24:39 pierre
  1548. * local browser stuff corrected
  1549. Revision 1.16 1999/05/13 21:59:20 peter
  1550. * removed oldppu code
  1551. * warning if objpas is loaded from uses
  1552. * first things for new deref writing
  1553. Revision 1.15 1999/04/29 09:36:55 peter
  1554. * fixed crash
  1555. * check if localbrowser is set
  1556. Revision 1.14 1999/04/15 09:01:32 peter
  1557. * fixed set loading
  1558. * object inheritance support for browser
  1559. Revision 1.13 1999/04/14 18:59:52 peter
  1560. * fixed wrong variable names
  1561. Revision 1.12 1999/04/10 16:15:00 peter
  1562. * fixed browcol
  1563. + -ar to show regalloc info in .s file
  1564. Revision 1.11 1999/04/08 10:17:42 peter
  1565. + objects support
  1566. Revision 1.8 1999/03/03 01:38:11 pierre
  1567. * avoid infinite recursion in ProcessDefIfStruct
  1568. Revision 1.7 1999/02/22 11:51:32 peter
  1569. * browser updates from gabor
  1570. Revision 1.6 1999/02/04 09:31:59 pierre
  1571. + added objects and records symbol tables
  1572. Revision 1.5 1999/02/03 09:44:32 pierre
  1573. * symbol nubering begins with 1 in number_symbols
  1574. * program tmodule has globalsymtable for its staticsymtable
  1575. (to get it displayed in IDE globals list)
  1576. + list of symbol (browcol) greatly improved for IDE
  1577. Revision 1.4 1999/02/02 16:38:38 peter
  1578. * no endless loop with localst=staticsymtable
  1579. Revision 1.3 1999/01/22 10:19:43 peter
  1580. * fixed typo
  1581. Revision 1.2 1999/01/21 11:49:14 peter
  1582. * updates from gabor
  1583. Revision 1.1 1999/01/12 14:25:24 peter
  1584. + BrowserLog for browser.log generation
  1585. + BrowserCol for browser info in TCollections
  1586. * released all other UseBrowser
  1587. }