browcol.pas 49 KB

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