browcol.pas 47 KB

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