browcol.pas 43 KB

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