browcol.pas 47 KB

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