browcol.pas 51 KB

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