browcol.pas 47 KB

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