browcol.pas 50 KB

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