browcol.pas 48 KB

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