browcol.pas 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139
  1. {
  2. Copyright (c) 1998-2002 by Berczi Gabor
  3. Modifications Copyright (c) 1999-2002 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. {$i fpcdefs.inc}
  23. {$H-}
  24. interface
  25. uses
  26. SysUtils,
  27. CUtils,
  28. objects,
  29. cclasses,
  30. symconst,symtable;
  31. const
  32. SymbolTypLen : integer = 6;
  33. RecordTypes : set of tsymtyp =
  34. ([typesym,unitsym]);
  35. sfRecord = $00000001;
  36. sfObject = $00000002;
  37. sfClass = $00000004;
  38. sfPointer = $00000008;
  39. sfHasMemInfo = $80000000;
  40. type
  41. TStoreCollection = object(TStringCollection)
  42. function Add(const S: string): PString;
  43. end;
  44. PModuleNameCollection = ^TModuleNameCollection;
  45. TModuleNameCollection = object(TStoreCollection)
  46. end;
  47. PTypeNameCollection = ^TTypeNameCollection;
  48. TTypeNameCollection = object(TStoreCollection)
  49. end;
  50. PSymbolCollection = ^TSymbolCollection;
  51. PSortedSymbolCollection = ^TSortedSymbolCollection;
  52. PReferenceCollection = ^TReferenceCollection;
  53. PReference = ^TReference;
  54. TReference = object(TObject)
  55. FileName : PString;
  56. Position : TPoint;
  57. constructor Init(AFileName: PString; ALine, AColumn: Sw_integer);
  58. function GetFileName: string;
  59. destructor Done; virtual;
  60. constructor Load(var S: TStream);
  61. procedure Store(var S: TStream);
  62. end;
  63. PSymbolMemInfo = ^TSymbolMemInfo;
  64. TSymbolMemInfo = record
  65. Addr : 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 : Ptrint;
  79. RelatedTypeID : Ptrint;
  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. PExport = ^TExport;
  98. TExport = object(TObject)
  99. constructor Init(const AName: string; AIndex: longint; ASymbol: PSymbol);
  100. function GetDisplayText: string;
  101. destructor Done; virtual;
  102. private
  103. Name: PString;
  104. Index: longint;
  105. Symbol: PSymbol;
  106. end;
  107. PExportCollection = ^TExportCollection;
  108. TExportCollection = object(TSortedCollection)
  109. function At(Index: sw_Integer): PExport;
  110. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  111. end;
  112. PImport = ^TImport;
  113. TImport = object(TObject)
  114. constructor Init(const ALibName, AFuncName,ARealName: string; AIndex: longint);
  115. function GetDisplayText: string;
  116. destructor Done; virtual;
  117. private
  118. LibName: PString;
  119. FuncName: PString;
  120. RealName: PString;
  121. Index: longint;
  122. end;
  123. PImportCollection = ^TImportCollection;
  124. TImportCollection = object(TSortedCollection)
  125. function At(Index: sw_Integer): PImport;
  126. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  127. end;
  128. PObjectSymbolCollection = ^TObjectSymbolCollection;
  129. PObjectSymbol = ^TObjectSymbol;
  130. TObjectSymbol = object(TObject)
  131. Parent : PObjectSymbol;
  132. Symbol : PSymbol;
  133. Expanded : boolean;
  134. constructor Init(AParent: PObjectSymbol; ASymbol: PSymbol);
  135. constructor InitName(const AName: string);
  136. function GetName: string;
  137. function GetDescendantCount: sw_integer;
  138. function GetDescendant(Index: sw_integer): PObjectSymbol;
  139. procedure AddDescendant(P: PObjectSymbol);
  140. destructor Done; virtual;
  141. constructor Load(var S: TStream);
  142. procedure Store(S: TStream);
  143. private
  144. Name: PString;
  145. Descendants: PObjectSymbolCollection;
  146. end;
  147. TSymbolCollection = object(TSortedCollection)
  148. constructor Init(ALimit, ADelta: Integer);
  149. function At(Index: Sw_Integer): PSymbol;
  150. procedure Insert(Item: Pointer); virtual;
  151. function LookUp(const S: string; var Idx: sw_integer): string; virtual;
  152. end;
  153. TSortedSymbolCollection = object(TSymbolCollection)
  154. function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
  155. procedure Insert(Item: Pointer); virtual;
  156. function LookUp(const S: string; var Idx: sw_integer): string; virtual;
  157. end;
  158. PIDSortedSymbolCollection = ^TIDSortedSymbolCollection;
  159. TIDSortedSymbolCollection = object(TSymbolCollection)
  160. function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
  161. procedure Insert(Item: Pointer); virtual;
  162. function SearchSymbolByID(AID: longint): PSymbol;
  163. end;
  164. TObjectSymbolCollection = object(TSortedCollection)
  165. constructor Init(ALimit, ADelta: Integer);
  166. function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
  167. function LookUp(const S: string; var Idx: sw_integer): string; virtual;
  168. function At(Index: Sw_Integer): PObjectSymbol;
  169. end;
  170. TReferenceCollection = object(TCollection)
  171. function At(Index: Sw_Integer): PReference;
  172. end;
  173. PSourceFile = ^TSourceFile;
  174. TSourceFile = object(TObject)
  175. SourceFileName: PString;
  176. ObjFileName: PString;
  177. PPUFileName: PString;
  178. constructor Init(ASourceFileName, AObjFileName, APPUFileName: string);
  179. destructor Done; virtual;
  180. function GetSourceFilename: string;
  181. function GetObjFileName: string;
  182. function GetPPUFileName: string;
  183. end;
  184. PSourceFileCollection = ^TSourceFileCollection;
  185. TSourceFileCollection = object(TCollection)
  186. function At(Index: sw_Integer): PSourceFile;
  187. end;
  188. PModuleSymbol = ^TModuleSymbol;
  189. TModuleSymbol = object(TSymbol)
  190. Exports_ : PExportCollection;
  191. Imports : PImportCollection;
  192. LoadedFrom : PString;
  193. UsedUnits : PSymbolCollection;
  194. DependentUnits: PSymbolCollection;
  195. MainSource: PString;
  196. SourceFiles: pstringCollection;
  197. constructor Init(const AName, AMainSource: string);
  198. procedure SetLoadedFrom(const AModuleName: string);
  199. procedure AddUsedUnit(P: PSymbol);
  200. procedure AddDependentUnit(P: PSymbol);
  201. procedure AddSourceFile(const Path: string);
  202. destructor Done; virtual;
  203. end;
  204. const
  205. Modules : PSymbolCollection = nil;
  206. ModuleNames : PModuleNameCollection = nil;
  207. TypeNames : PTypeNameCollection = nil;
  208. ObjectTree : PObjectSymbol = nil;
  209. SourceFiles : PSourceFileCollection = nil;
  210. procedure DisposeBrowserCol;
  211. procedure NewBrowserCol;
  212. procedure CreateBrowserCol;
  213. procedure InitBrowserCol;
  214. procedure DoneBrowserCol;
  215. function LoadBrowserCol(S: PStream): boolean;
  216. function StoreBrowserCol(S: PStream) : boolean;
  217. procedure BuildObjectInfo;
  218. procedure BuildSourceList;
  219. function SearchObjectForSymbol(O: PSymbol): PObjectSymbol;
  220. procedure RegisterSymbols;
  221. implementation
  222. uses
  223. globtype,globals,comphook,
  224. {$ifdef DEBUG}
  225. verbose,
  226. {$endif DEBUG}
  227. finput,fmodule,
  228. cpuinfo,cgbase,aasmbase,aasmtai,aasmdata,paramgr,
  229. symsym,symdef,symtype,symbase,defutil;
  230. const
  231. RModuleNameCollection: TStreamRec = (
  232. ObjType: 3001;
  233. VmtLink: Ofs(TypeOf(TModuleNameCollection)^);
  234. Load: @TModuleNameCollection.Load;
  235. Store: @TModuleNameCollection.Store
  236. );
  237. RTypeNameCollection: TStreamRec = (
  238. ObjType: 3002;
  239. VmtLink: Ofs(TypeOf(TTypeNameCollection)^);
  240. Load: @TTypeNameCollection.Load;
  241. Store: @TTypeNameCollection.Store
  242. );
  243. RReference: TStreamRec = (
  244. ObjType: 3003;
  245. VmtLink: Ofs(TypeOf(TReference)^);
  246. Load: @TReference.Load;
  247. Store: @TReference.Store
  248. );
  249. RSymbol: TStreamRec = (
  250. ObjType: 3004;
  251. VmtLink: Ofs(TypeOf(TSymbol)^);
  252. Load: @TSymbol.Load;
  253. Store: @TSymbol.Store
  254. );
  255. RObjectSymbol: TStreamRec = (
  256. ObjType: 3005;
  257. VmtLink: Ofs(TypeOf(TObjectSymbol)^);
  258. Load: @TObjectSymbol.Load;
  259. Store: @TObjectSymbol.Store
  260. );
  261. RSymbolCollection: TStreamRec = (
  262. ObjType: 3006;
  263. VmtLink: Ofs(TypeOf(TSymbolCollection)^);
  264. Load: @TSymbolCollection.Load;
  265. Store: @TSymbolCollection.Store
  266. );
  267. RSortedSymbolCollection: TStreamRec = (
  268. ObjType: 3007;
  269. VmtLink: Ofs(TypeOf(TSortedSymbolCollection)^);
  270. Load: @TSortedSymbolCollection.Load;
  271. Store: @TSortedSymbolCollection.Store
  272. );
  273. RIDSortedSymbolCollection: TStreamRec = (
  274. ObjType: 3008;
  275. VmtLink: Ofs(TypeOf(TIDSortedSymbolCollection)^);
  276. Load: @TIDSortedSymbolCollection.Load;
  277. Store: @TIDSortedSymbolCollection.Store
  278. );
  279. RObjectSymbolCollection: TStreamRec = (
  280. ObjType: 3009;
  281. VmtLink: Ofs(TypeOf(TObjectSymbolCollection)^);
  282. Load: @TObjectSymbolCollection.Load;
  283. Store: @TObjectSymbolCollection.Store
  284. );
  285. RReferenceCollection: TStreamRec = (
  286. ObjType: 3010;
  287. VmtLink: Ofs(TypeOf(TReferenceCollection)^);
  288. Load: @TReferenceCollection.Load;
  289. Store: @TReferenceCollection.Store
  290. );
  291. RModuleSymbol: TStreamRec = (
  292. ObjType: 3011;
  293. VmtLink: Ofs(TypeOf(TModuleSymbol)^);
  294. Load: @TModuleSymbol.Load;
  295. Store: @TModuleSymbol.Store
  296. );
  297. {****************************************************************************
  298. Helpers
  299. ****************************************************************************}
  300. function GetStr(P: PString): string;
  301. begin
  302. if P=nil then
  303. GetStr:=''
  304. else
  305. GetStr:=P^;
  306. end;
  307. function IntToStr(L: longint): string;
  308. var S: string;
  309. begin
  310. Str(L,S);
  311. IntToStr:=S;
  312. end;
  313. function UpcaseStr(S: string): string;
  314. var I: integer;
  315. begin
  316. for I:=1 to length(S) do
  317. S[I]:=Upcase(S[I]);
  318. UpcaseStr:=S;
  319. end;
  320. function FloatToStr(E: extended): string;
  321. var S: string;
  322. begin
  323. Str(E:0:24,S);
  324. if Pos('.',S)>0 then
  325. begin
  326. while (length(S)>0) and (S[length(S)]='0') do
  327. Delete(S,length(S),1);
  328. if (length(S)>0) and (S[length(S)]='.') then
  329. Delete(S,length(S),1);
  330. end;
  331. if S='' then S:='0';
  332. FloatToStr:=S;
  333. end;
  334. {****************************************************************************
  335. TStoreCollection
  336. ****************************************************************************}
  337. function TStoreCollection.Add(const S: string): PString;
  338. var P: PString;
  339. Index: Sw_integer;
  340. begin
  341. if S='' then P:=nil else
  342. if Search(@S,Index) then P:=At(Index) else
  343. begin
  344. P:=NewStr(S);
  345. Insert(P);
  346. end;
  347. Add:=P;
  348. end;
  349. {****************************************************************************
  350. TSymbolCollection
  351. ****************************************************************************}
  352. constructor TSymbolCollection.Init(ALimit, ADelta: Integer);
  353. begin
  354. inherited Init(ALimit,ADelta);
  355. { Duplicates:=true;}
  356. end;
  357. function TSymbolCollection.At(Index: Sw_Integer): PSymbol;
  358. begin
  359. At:=inherited At(Index);
  360. end;
  361. procedure TSymbolCollection.Insert(Item: Pointer);
  362. begin
  363. TCollection.Insert(Item);
  364. end;
  365. function TSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  366. begin
  367. Idx:=-1;
  368. LookUp:='';
  369. end;
  370. {****************************************************************************
  371. TReferenceCollection
  372. ****************************************************************************}
  373. function TReferenceCollection.At(Index: Sw_Integer): PReference;
  374. begin
  375. At:=inherited At(Index);
  376. end;
  377. {****************************************************************************
  378. TSortedSymbolCollection
  379. ****************************************************************************}
  380. function TSortedSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  381. var K1: PSymbol absolute Key1;
  382. K2: PSymbol absolute Key2;
  383. R: Sw_integer;
  384. S1,S2: string;
  385. begin
  386. S1:=Upper(K1^.GetName);
  387. S2:=Upper(K2^.GetName);
  388. if S1<S2 then R:=-1 else
  389. if S1>S2 then R:=1 else
  390. if K1^.TypeID=K2^.TypeID then R:=0 else
  391. begin
  392. S1:=K1^.GetName;
  393. S2:=K2^.GetName;
  394. if S1<S2 then R:=-1 else
  395. if S1>S2 then R:=1 else
  396. if K1^.TypeID<K2^.TypeID then R:=-1 else
  397. if K1^.TypeID>K2^.TypeID then R:= 1 else
  398. R:=0;
  399. end;
  400. Compare:=R;
  401. end;
  402. procedure TSortedSymbolCollection.Insert(Item: Pointer);
  403. begin
  404. TSortedCollection.Insert(Item);
  405. end;
  406. function TSortedSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  407. var OLI,ORI,Left,Right,Mid: integer;
  408. LeftP,RightP,MidP: PSymbol;
  409. LeftS,MidS,RightS: string;
  410. FoundS: string;
  411. UpS : string;
  412. begin
  413. Idx:=-1; FoundS:='';
  414. Left:=0; Right:=Count-1;
  415. UpS:=Upper(S);
  416. if Left<Right then
  417. begin
  418. while (Left<Right) do
  419. begin
  420. OLI:=Left; ORI:=Right;
  421. Mid:=Left+(Right-Left) div 2;
  422. MidP:=At(Mid);
  423. {$ifdef DEBUG}
  424. LeftP:=At(Left); RightP:=At(Right);
  425. LeftS:=Upper(LeftP^.GetName);
  426. RightS:=Upper(RightP^.GetName);
  427. {$endif DEBUG}
  428. MidS:=Upper(MidP^.GetName);
  429. if copy(MidS,1,length(UpS))=UpS then
  430. begin
  431. Idx:=Mid;
  432. FoundS:=MidS;
  433. end;
  434. { else}
  435. if UpS<MidS then
  436. Right:=Mid
  437. else
  438. Left:=Mid;
  439. if (OLI=Left) and (ORI=Right) then
  440. begin
  441. if idX<>-1 then
  442. break;
  443. if Mid=Left then
  444. begin
  445. RightP:=At(Right);
  446. RightS:=Upper(RightP^.GetName);
  447. if copy(RightS,1,length(UpS))=UpS then
  448. begin
  449. Idx:=Right;
  450. FoundS:=RightS;
  451. end;
  452. end;
  453. if Mid=Right then
  454. begin
  455. LeftP:=At(Left);
  456. LeftS:=Upper(LeftP^.GetName);
  457. if copy(LeftS,1,length(UpS))=UpS then
  458. begin
  459. Idx:=Left;
  460. FoundS:=LeftS;
  461. end;
  462. end;
  463. Break;
  464. end;
  465. end;
  466. end;
  467. LookUp:=FoundS;
  468. end;
  469. {****************************************************************************
  470. TIDSortedSymbolCollection
  471. ****************************************************************************}
  472. function TIDSortedSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  473. var K1: PSymbol absolute Key1;
  474. K2: PSymbol absolute Key2;
  475. R: Sw_integer;
  476. begin
  477. if K1^.TypeID<K2^.TypeID then R:=-1 else
  478. if K1^.TypeID>K2^.TypeID then R:= 1 else
  479. R:=0;
  480. Compare:=R;
  481. end;
  482. procedure TIDSortedSymbolCollection.Insert(Item: Pointer);
  483. begin
  484. TSortedCollection.Insert(Item);
  485. end;
  486. function TIDSortedSymbolCollection.SearchSymbolByID(AID: longint): PSymbol;
  487. var S: TSymbol;
  488. Index: sw_integer;
  489. P: PSymbol;
  490. begin
  491. S.TypeID:=AID;
  492. if Search(@S,Index)=false then P:=nil else
  493. P:=At(Index);
  494. SearchSymbolByID:=P;
  495. end;
  496. {****************************************************************************
  497. TObjectSymbolCollection
  498. ****************************************************************************}
  499. function TObjectSymbolCollection.At(Index: Sw_Integer): PObjectSymbol;
  500. begin
  501. At:=inherited At(Index);
  502. end;
  503. constructor TObjectSymbolCollection.Init(ALimit, ADelta: Integer);
  504. begin
  505. inherited Init(ALimit,ADelta);
  506. end;
  507. function TObjectSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  508. var K1: PObjectSymbol absolute Key1;
  509. K2: PObjectSymbol absolute Key2;
  510. R: Sw_integer;
  511. S1,S2: string;
  512. begin
  513. S1:=Upper(K1^.GetName);
  514. S2:=Upper(K2^.GetName);
  515. if S1<S2 then R:=-1 else
  516. if S1>S2 then R:=1 else
  517. { make sure that we distinguish between different objects with the same name }
  518. if Ptrint(K1^.Symbol)<Ptrint(K2^.Symbol) then R:=-1 else
  519. if Ptrint(K1^.Symbol)>Ptrint(K2^.Symbol) then R:= 1 else
  520. R:=0;
  521. Compare:=R;
  522. end;
  523. function TObjectSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  524. var OLI,ORI,Left,Right,Mid: integer;
  525. {LeftP,RightP,}MidP: PObjectSymbol;
  526. {LeftS,RightS,}MidS: string;
  527. FoundS: string;
  528. UpS : string;
  529. begin
  530. Idx:=-1; FoundS:='';
  531. Left:=0; Right:=Count-1;
  532. UpS:=Upper(S);
  533. if Left<Right then
  534. begin
  535. while (Left<Right) do
  536. begin
  537. OLI:=Left; ORI:=Right;
  538. Mid:=Left+(Right-Left) div 2;
  539. {LeftP:=At(Left);
  540. LeftS:=Upper(LeftP^.GetName);}
  541. MidP:=At(Mid);
  542. MidS:=Upper(MidP^.GetName);
  543. {RightP:=At(Right);
  544. RightS:=Upper(RightP^.GetName);}
  545. if copy(MidS,1,length(UpS))=UpS then
  546. begin
  547. Idx:=Mid;
  548. FoundS:=MidS;
  549. end;
  550. { else}
  551. if UpS<MidS then
  552. Right:=Mid
  553. else
  554. Left:=Mid;
  555. if (OLI=Left) and (ORI=Right) then
  556. Break;
  557. end;
  558. end;
  559. LookUp:=FoundS;
  560. end;
  561. {****************************************************************************
  562. TReference
  563. ****************************************************************************}
  564. constructor TReference.Init(AFileName: PString; ALine, AColumn: Sw_integer);
  565. begin
  566. inherited Init;
  567. FileName:=AFileName;
  568. Position.X:=AColumn;
  569. Position.Y:=ALine;
  570. end;
  571. function TReference.GetFileName: string;
  572. begin
  573. GetFileName:=GetStr(FileName);
  574. end;
  575. destructor TReference.Done;
  576. begin
  577. inherited Done;
  578. end;
  579. constructor TReference.Load(var S: TStream);
  580. begin
  581. S.Read(Position, SizeOf(Position));
  582. { --- items needing fixup --- }
  583. S.Read(FileName, SizeOf(FileName)); { ->ModulesNames^.Item }
  584. end;
  585. procedure TReference.Store(var S: TStream);
  586. begin
  587. S.Write(Position, SizeOf(Position));
  588. { --- items needing fixup --- }
  589. S.Write(FileName, SizeOf(FileName));
  590. end;
  591. {****************************************************************************
  592. TSymbol
  593. ****************************************************************************}
  594. constructor TSymbol.Init(const AName: string; ATyp: tsymtyp; AParams: string; AMemInfo: PSymbolMemInfo);
  595. begin
  596. inherited Init;
  597. Name:=NewStr(AName); Typ:=ATyp;
  598. if AMemInfo<>nil then
  599. SetMemInfo(AMemInfo^);
  600. New(References, Init(20,50));
  601. if ATyp in RecordTypes then
  602. begin
  603. Items:=New(PSortedSymbolCollection, Init(50,100));
  604. end;
  605. end;
  606. procedure TSymbol.SetMemInfo(const AMemInfo: TSymbolMemInfo);
  607. begin
  608. if MemInfo=nil then New(MemInfo);
  609. Move(AMemInfo,MemInfo^,SizeOf(MemInfo^));
  610. Flags:=Flags or sfHasMemInfo;
  611. end;
  612. function TSymbol.GetReferenceCount: Sw_integer;
  613. var Count: Sw_integer;
  614. begin
  615. if References=nil then Count:=0 else
  616. Count:=References^.Count;
  617. GetReferenceCount:=Count;
  618. end;
  619. function TSymbol.GetReference(Index: Sw_integer): PReference;
  620. begin
  621. GetReference:=References^.At(Index);
  622. end;
  623. function TSymbol.GetItemCount: Sw_integer;
  624. var Count: Sw_integer;
  625. begin
  626. if Items=nil then Count:=0 else
  627. Count:=Items^.Count;
  628. GetItemCount:=Count;
  629. end;
  630. function TSymbol.GetItem(Index: Sw_integer): PSymbol;
  631. begin
  632. GetItem:=Items^.At(Index);
  633. end;
  634. function TSymbol.GetName: string;
  635. begin
  636. GetName:=GetStr(Name);
  637. end;
  638. function TSymbol.GetText: string;
  639. var S: string;
  640. begin
  641. S:=GetTypeName;
  642. if length(S)>SymbolTypLen then
  643. S:=Copy(S,1,SymbolTypLen)
  644. else
  645. begin
  646. while length(S)<SymbolTypLen do
  647. S:=S+' ';
  648. end;
  649. S:=S+' '+GetName;
  650. if (Flags and sfRecord)<>0 then
  651. S:=S+' = record'
  652. else
  653. if (Flags and sfObject)<>0 then
  654. begin
  655. S:=S+' = ';
  656. if (Flags and sfClass)<>0 then
  657. S:=S+'class'
  658. else
  659. S:=S+'object';
  660. if Ancestor<>nil then
  661. S:=S+'('+Ancestor^.GetName+')';
  662. end
  663. else
  664. begin
  665. if Assigned(DType) then
  666. S:=S+' = '+DType^;
  667. if Assigned(Params) then
  668. S:=S+'('+Params^+')';
  669. if Assigned(VType) then
  670. S:=S+': '+VType^;
  671. end;
  672. GetText:=S;
  673. end;
  674. function TSymbol.GetTypeName: string;
  675. var S: string;
  676. begin
  677. case Typ of
  678. abstractsym : S:='abst';
  679. fieldvarsym : S:='member';
  680. globalvarsym,
  681. localvarsym,
  682. paravarsym : S:='var';
  683. typesym : S:='type';
  684. procsym : if VType=nil then
  685. S:='proc'
  686. else
  687. S:='func';
  688. unitsym : S:='unit';
  689. constsym : S:='const';
  690. enumsym : S:='enum';
  691. typedconstsym: S:='const';
  692. errorsym : S:='error';
  693. syssym : S:='sys';
  694. labelsym : S:='label';
  695. absolutevarsym : S:='abs';
  696. propertysym : S:='prop';
  697. macrosym : S:='macro';
  698. else S:='';
  699. end;
  700. GetTypeName:=S;
  701. end;
  702. destructor TSymbol.Done;
  703. begin
  704. inherited Done;
  705. if assigned(MemInfo) then
  706. Dispose(MemInfo);
  707. if assigned(References) then
  708. Dispose(References, Done);
  709. if assigned(Items) then
  710. Dispose(Items, Done);
  711. if assigned(Name) then
  712. DisposeStr(Name);
  713. { if assigned(Params) then
  714. DisposeStr(Params); in TypeNames
  715. if assigned(VType) then
  716. DisposeStr(VType);
  717. if assigned(DType) then
  718. DisposeStr(DType);
  719. if assigned(Ancestor) then
  720. DisposeStr(Ancestor);}
  721. end;
  722. constructor TSymbol.Load(var S: TStream);
  723. var MI: TSymbolMemInfo;
  724. W: word;
  725. begin
  726. TObject.Init;
  727. S.Read(Typ,SizeOf(Typ));
  728. S.Read(TypeID, SizeOf(TypeID));
  729. S.Read(RelatedTypeID, SizeOf(RelatedTypeID));
  730. S.Read(Flags, SizeOf(Flags));
  731. Name:=S.ReadStr;
  732. if (Flags and sfHasMemInfo)<>0 then
  733. begin
  734. S.Read(MI,SizeOf(MI));
  735. SetMemInfo(MI);
  736. end;
  737. W:=0;
  738. S.Read(W,SizeOf(W));
  739. if (W and 1)<>0 then
  740. New(References, Load(S));
  741. if (W and 2)<>0 then
  742. New(Items, Load(S));
  743. { --- items needing fixup --- }
  744. S.Read(DType, SizeOf(DType));
  745. S.Read(VType, SizeOf(VType));
  746. S.Read(Params, SizeOf(Params));
  747. end;
  748. procedure TSymbol.Store(var S: TStream);
  749. var W: word;
  750. begin
  751. S.Write(Typ,SizeOf(Typ));
  752. S.Write(TypeID, SizeOf(TypeID));
  753. S.Write(RelatedTypeID, SizeOf(RelatedTypeID));
  754. S.Write(Flags, SizeOf(Flags));
  755. S.WriteStr(Name);
  756. if (Flags and sfHasMemInfo)<>0 then
  757. S.Write(MemInfo^,SizeOf(MemInfo^));
  758. W:=0;
  759. if Assigned(References) then W:=W or 1;
  760. if Assigned(Items) then W:=W or 2;
  761. S.Write(W,SizeOf(W));
  762. if Assigned(References) then References^.Store(S);
  763. if Assigned(Items) then Items^.Store(S);
  764. { --- items needing fixup --- }
  765. S.Write(DType, SizeOf(DType));
  766. S.Write(VType, SizeOf(VType));
  767. S.Write(Params, SizeOf(Params));
  768. end;
  769. constructor TExport.Init(const AName: string; AIndex: longint; ASymbol: PSymbol);
  770. begin
  771. inherited Init;
  772. Name:=NewStr(AName); Index:=AIndex;
  773. Symbol:=ASymbol;
  774. end;
  775. function TExport.GetDisplayText: string;
  776. var S: string;
  777. begin
  778. S:=GetStr(Name)+' '+IntToStr(Index);
  779. if Assigned(Symbol) and (UpcaseStr(Symbol^.GetName)<>UpcaseStr(GetStr(Name))) then
  780. S:=S+' ('+Symbol^.GetName+')';
  781. GetDisplayText:=S;
  782. end;
  783. destructor TExport.Done;
  784. begin
  785. if Assigned(Name) then DisposeStr(Name);
  786. inherited Done;
  787. end;
  788. constructor TImport.Init(const ALibName, AFuncName,ARealName: string; AIndex: longint);
  789. begin
  790. inherited Init;
  791. LibName:=NewStr(ALibName);
  792. FuncName:=NewStr(AFuncName); RealName:=NewStr(ARealName);
  793. Index:=AIndex;
  794. end;
  795. function TImport.GetDisplayText: string;
  796. var S: string;
  797. begin
  798. S:=GetStr(RealName);
  799. if Assigned(FuncName) then S:=GetStr(FuncName)+' ('+S+')';
  800. if S='' then S:=IntToStr(Index);
  801. S:=GetStr(LibName)+' '+S;
  802. GetDisplayText:=S;
  803. end;
  804. destructor TImport.Done;
  805. begin
  806. if Assigned(LibName) then DisposeStr(LibName);
  807. if Assigned(FuncName) then DisposeStr(FuncName);
  808. if Assigned(RealName) then DisposeStr(RealName);
  809. inherited Done;
  810. end;
  811. function TImportCollection.At(Index: sw_Integer): PImport;
  812. begin
  813. At:=inherited At(Index);
  814. end;
  815. function TImportCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  816. var K1: PImport absolute Key1;
  817. K2: PImport absolute Key2;
  818. S1: string;
  819. S2: string;
  820. R: sw_integer;
  821. begin
  822. if (K1^.RealName=nil) and (K2^.RealName<>nil) then R:= 1 else
  823. if (K1^.RealName<>nil) and (K2^.RealName=nil) then R:=-1 else
  824. if (K1^.RealName=nil) and (K2^.RealName=nil) then
  825. begin
  826. if K1^.Index<K2^.Index then R:=-1 else
  827. if K1^.Index>K2^.Index then R:= 1 else
  828. R:=0;
  829. end
  830. else
  831. begin
  832. if K1^.FuncName=nil then S1:=GetStr(K1^.RealName) else S1:=GetStr(K1^.FuncName);
  833. if K2^.FuncName=nil then S2:=GetStr(K2^.RealName) else S2:=GetStr(K2^.FuncName);
  834. S1:=UpcaseStr(S1); S2:=UpcaseStr(S2);
  835. if S1<S2 then R:=-1 else
  836. if S1>S2 then R:= 1 else
  837. R:=0;
  838. end;
  839. Compare:=R;
  840. end;
  841. function TExportCollection.At(Index: sw_Integer): PExport;
  842. begin
  843. At:=inherited At(Index);
  844. end;
  845. function TExportCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  846. var K1: PExport absolute Key1;
  847. K2: PExport absolute Key2;
  848. S1: string;
  849. S2: string;
  850. R: sw_integer;
  851. begin
  852. S1:=UpcaseStr(GetStr(K1^.Name)); S2:=UpcaseStr(GetStr(K2^.Name));
  853. if S1<S2 then R:=-1 else
  854. if S1>S2 then R:= 1 else
  855. R:=0;
  856. Compare:=R;
  857. end;
  858. constructor TModuleSymbol.Init(const AName, AMainSource: string);
  859. begin
  860. inherited Init(AName,unitsym,'',nil);
  861. MainSource:=NewStr(AMainSource);
  862. end;
  863. procedure TModuleSymbol.SetLoadedFrom(const AModuleName: string);
  864. begin
  865. SetStr(LoadedFrom,AModuleName);
  866. end;
  867. procedure TModuleSymbol.AddUsedUnit(P: PSymbol);
  868. begin
  869. if Assigned(UsedUnits)=false then
  870. New(UsedUnits, Init(10,10));
  871. UsedUnits^.Insert(P);
  872. end;
  873. procedure TModuleSymbol.AddDependentUnit(P: PSymbol);
  874. begin
  875. if Assigned(DependentUnits)=false then
  876. New(DependentUnits, Init(10,10));
  877. DependentUnits^.Insert(P);
  878. end;
  879. procedure TModuleSymbol.AddSourceFile(const Path: string);
  880. begin
  881. if Assigned(SourceFiles)=false then
  882. New(SourceFiles, Init(10,10));
  883. sourcefiles^.Insert(NewStr(Path));
  884. end;
  885. destructor TModuleSymbol.Done;
  886. begin
  887. inherited Done;
  888. if Assigned(MainSource) then DisposeStr(MainSource);
  889. if assigned(Exports_) then
  890. Dispose(Exports_, Done);
  891. if Assigned(Imports) then
  892. Dispose(Imports, Done);
  893. if Assigned(LoadedFrom) then
  894. DisposeStr(LoadedFrom);
  895. if Assigned(UsedUnits) then
  896. begin
  897. UsedUnits^.DeleteAll;
  898. Dispose(UsedUnits, Done);
  899. end;
  900. if Assigned(DependentUnits) then
  901. begin
  902. DependentUnits^.DeleteAll;
  903. Dispose(DependentUnits, Done);
  904. end;
  905. if Assigned(SourceFiles) then Dispose(SourceFiles, Done);
  906. end;
  907. constructor TObjectSymbol.Init(AParent: PObjectSymbol; ASymbol: PSymbol);
  908. begin
  909. inherited Init;
  910. Parent:=AParent;
  911. Symbol:=ASymbol;
  912. end;
  913. constructor TObjectSymbol.InitName(const AName: string);
  914. begin
  915. inherited Init;
  916. Name:=NewStr(AName);
  917. end;
  918. function TObjectSymbol.GetName: string;
  919. begin
  920. if Name<>nil then
  921. GetName:=Name^
  922. else
  923. GetName:=Symbol^.GetName;
  924. end;
  925. function TObjectSymbol.GetDescendantCount: sw_integer;
  926. var Count: sw_integer;
  927. begin
  928. if Descendants=nil then Count:=0 else
  929. Count:=Descendants^.Count;
  930. GetDescendantCount:=Count;
  931. end;
  932. function TObjectSymbol.GetDescendant(Index: sw_integer): PObjectSymbol;
  933. begin
  934. GetDescendant:=Descendants^.At(Index);
  935. end;
  936. procedure TObjectSymbol.AddDescendant(P: PObjectSymbol);
  937. begin
  938. if Descendants=nil then
  939. New(Descendants, Init(50,10));
  940. Descendants^.Insert(P);
  941. end;
  942. destructor TObjectSymbol.Done;
  943. begin
  944. if Assigned(Name) then DisposeStr(Name); Name:=nil;
  945. if Assigned(Descendants) then Dispose(Descendants, Done); Descendants:=nil;
  946. inherited Done;
  947. end;
  948. constructor TObjectSymbol.Load(var S: TStream);
  949. begin
  950. end;
  951. procedure TObjectSymbol.Store(S: TStream);
  952. begin
  953. end;
  954. {****************************************************************************
  955. TSourceFile
  956. ****************************************************************************}
  957. constructor TSourceFile.Init(ASourceFileName, AObjFileName, APPUFileName: string);
  958. begin
  959. inherited Init;
  960. SourceFileName:=NewStr(ASourceFileName);
  961. ObjFileName:=NewStr(AObjFileName);
  962. PPUFileName:=NewStr(APPUFileName);
  963. end;
  964. destructor TSourceFile.Done;
  965. begin
  966. if assigned(SourceFileName) then DisposeStr(SourceFileName);
  967. if assigned(ObjFileName) then DisposeStr(ObjFileName);
  968. if assigned(PPUFileName) then DisposeStr(PPUFileName);
  969. inherited Done;
  970. end;
  971. function TSourceFile.GetSourceFilename: string;
  972. begin
  973. GetSourceFilename:=GetStr(SourceFileName);
  974. end;
  975. function TSourceFile.GetObjFileName: string;
  976. begin
  977. GetObjFilename:=GetStr(ObjFileName);
  978. end;
  979. function TSourceFile.GetPPUFileName: string;
  980. begin
  981. GetPPUFilename:=GetStr(PPUFileName);
  982. end;
  983. function TSourceFileCollection.At(Index: sw_Integer): PSourceFile;
  984. begin
  985. At:=inherited At(Index);
  986. end;
  987. {*****************************************************************************
  988. Main Routines
  989. *****************************************************************************}
  990. procedure DisposeBrowserCol;
  991. begin
  992. if assigned(Modules) then
  993. begin
  994. dispose(Modules,Done);
  995. Modules:=nil;
  996. end;
  997. if assigned(ModuleNames) then
  998. begin
  999. dispose(ModuleNames,Done);
  1000. ModuleNames:=nil;
  1001. end;
  1002. if assigned(TypeNames) then
  1003. begin
  1004. dispose(TypeNames,Done);
  1005. TypeNames:=nil;
  1006. end;
  1007. if assigned(ObjectTree) then
  1008. begin
  1009. Dispose(ObjectTree, Done);
  1010. ObjectTree:=nil;
  1011. end;
  1012. end;
  1013. procedure NewBrowserCol;
  1014. begin
  1015. New(Modules, Init(50,50));
  1016. New(ModuleNames, Init(50,50));
  1017. New(TypeNames, Init(1000,5000));
  1018. end;
  1019. procedure ProcessSymTable(OwnerSym: PSymbol; var Owner: PSymbolCollection; Table: TSymTable);
  1020. var J: longint;
  1021. Ref: TRef;
  1022. Sym: TSym;
  1023. Symbol: PSymbol;
  1024. Reference: PReference;
  1025. inputfile : Tinputfile;
  1026. procedure SetVType(Symbol: PSymbol; VType: string);
  1027. begin
  1028. Symbol^.VType:=TypeNames^.Add(VType);
  1029. end;
  1030. procedure SetDType(Symbol: PSymbol; DType: string);
  1031. begin
  1032. Symbol^.DType:=TypeNames^.Add(DType);
  1033. end;
  1034. function GetDefinitionStr(def: tdef): string; forward;
  1035. function GetEnumDefStr(def: tenumdef): string;
  1036. var Name: string;
  1037. esym: tenumsym;
  1038. Count: integer;
  1039. begin
  1040. Name:='(';
  1041. esym:=tenumsym(def.Firstenum); Count:=0;
  1042. while (esym<>nil) do
  1043. begin
  1044. if Count>0 then
  1045. Name:=Name+', ';
  1046. Name:=Name+esym.name;
  1047. esym:=esym.nextenum;
  1048. Inc(Count);
  1049. end;
  1050. Name:=Name+')';
  1051. GetEnumDefStr:=Name;
  1052. end;
  1053. function GetArrayDefStr(def: tarraydef): string;
  1054. var Name: string;
  1055. begin
  1056. Name:='array ['+IntToStr(def.lowrange)+'..'+IntToStr(def.highrange)+'] of ';
  1057. if assigned(def.elementdef) then
  1058. Name:=Name+GetDefinitionStr(def.elementdef);
  1059. GetArrayDefStr:=Name;
  1060. end;
  1061. function GetFileDefStr(def: tfiledef): string;
  1062. var Name: string;
  1063. begin
  1064. Name:='';
  1065. case def.filetyp of
  1066. ft_text : Name:='text';
  1067. ft_untyped : Name:='file';
  1068. ft_typed : Name:='file of '+GetDefinitionStr(def.typedfiledef);
  1069. end;
  1070. GetFileDefStr:=Name;
  1071. end;
  1072. function GetStringDefStr(def: tstringdef): string;
  1073. var Name: string;
  1074. begin
  1075. Name:='';
  1076. case def.string_typ of
  1077. st_shortstring :
  1078. if def.len=255 then
  1079. Name:='shortstring'
  1080. else
  1081. Name:='string['+IntToStr(def.len)+']';
  1082. st_longstring :
  1083. Name:='longstring';
  1084. st_ansistring :
  1085. Name:='ansistring';
  1086. st_widestring :
  1087. Name:='widestring';
  1088. else ;
  1089. end;
  1090. GetStringDefStr:=Name;
  1091. end;
  1092. function retdefassigned(def: tabstractprocdef): boolean;
  1093. var OK: boolean;
  1094. begin
  1095. OK:=false;
  1096. if assigned(def.returndef) then
  1097. if UpcaseStr(GetDefinitionStr(def.returndef))<>'VOID' then
  1098. OK:=true;
  1099. retdefassigned:=OK;
  1100. end;
  1101. function GetAbsProcParmDefStr(def: tabstractprocdef): string;
  1102. var Name: string;
  1103. dc: tparavarsym;
  1104. i,
  1105. Count: integer;
  1106. CurName: string;
  1107. begin
  1108. Name:='';
  1109. Count:=0;
  1110. for i:=0 to def.paras.count-1 do
  1111. begin
  1112. dc:=tparavarsym(def.paras[i]);
  1113. if i=0 then
  1114. CurName:=''
  1115. else
  1116. CurName:=', '+CurName;
  1117. case dc.varspez of
  1118. vs_Value : ;
  1119. vs_Const : CurName:=CurName+'const ';
  1120. vs_Var : CurName:=CurName+'var ';
  1121. end;
  1122. if assigned(dc.vardef) then
  1123. CurName:=CurName+GetDefinitionStr(dc.vardef);
  1124. Name:=CurName+Name;
  1125. Inc(Count);
  1126. end;
  1127. GetAbsProcParmDefStr:=Name;
  1128. end;
  1129. function GetAbsProcDefStr(def: tabstractprocdef): string;
  1130. var Name: string;
  1131. begin
  1132. Name:=GetAbsProcParmDefStr(def);
  1133. if Name<>'' then Name:='('+Name+')';
  1134. if retdefassigned(def) then
  1135. Name:='function'+Name+': '+GetDefinitionStr(def.returndef)
  1136. else
  1137. Name:='procedure'+Name;
  1138. GetAbsProcDefStr:=Name;
  1139. end;
  1140. function GetProcDefStr(def: tprocdef): string;
  1141. var DName: string;
  1142. {J: integer;}
  1143. begin
  1144. { DName:='';
  1145. if assigned(def) then
  1146. begin
  1147. if assigned(def.parast) then
  1148. begin
  1149. with def.parast^ do
  1150. for J:=1 to number_symbols do
  1151. begin
  1152. if J<>1 then DName:=DName+', ';
  1153. ParSym:=GetsymNr(J);
  1154. if ParSym=nil then Break;
  1155. DName:=DName+ParSym^.Name;
  1156. end;
  1157. end
  1158. end;}
  1159. DName:=GetAbsProcDefStr(def);
  1160. GetProcDefStr:=DName;
  1161. end;
  1162. function GetProcVarDefStr(def: tprocvardef): string;
  1163. begin
  1164. GetProcVarDefStr:=GetAbsProcDefStr(def);
  1165. end;
  1166. function GetSetDefStr(def: tsetdef): string;
  1167. var Name: string;
  1168. begin
  1169. Name:='';
  1170. case def.settype of
  1171. normset : Name:='set';
  1172. smallset : Name:='set';
  1173. varset : Name:='varset';
  1174. end;
  1175. Name:=Name+' of ';
  1176. Name:=Name+GetDefinitionStr(def.elementdef);
  1177. GetSetDefStr:=Name;
  1178. end;
  1179. function GetPointerDefStr(def: tpointerdef): string;
  1180. begin
  1181. GetPointerDefStr:='^'+GetDefinitionStr(def.pointeddef);
  1182. end;
  1183. function GetDefinitionStr(def: tdef): string;
  1184. var Name: string;
  1185. begin
  1186. Name:='';
  1187. if def<>nil then
  1188. begin
  1189. if assigned(def.typesym) then
  1190. Name:=def.typesym.name;
  1191. if Name='' then
  1192. case def.deftype of
  1193. arraydef :
  1194. Name:=GetArrayDefStr(tarraydef(def));
  1195. stringdef :
  1196. Name:=GetStringDefStr(tstringdef(def));
  1197. enumdef :
  1198. Name:=GetEnumDefStr(tenumdef(def));
  1199. procdef :
  1200. Name:=GetProcDefStr(tprocdef(def));
  1201. procvardef :
  1202. Name:=GetProcVarDefStr(tprocvardef(def));
  1203. filedef :
  1204. Name:=GetFileDefStr(tfiledef(def));
  1205. setdef :
  1206. Name:=GetSetDefStr(tsetdef(def));
  1207. end;
  1208. end;
  1209. GetDefinitionStr:=Name;
  1210. end;
  1211. function GetEnumItemName(Sym: tenumsym): string;
  1212. var Name: string;
  1213. {ES: tenumsym;}
  1214. begin
  1215. Name:='';
  1216. if assigned(sym) and assigned(sym.definition) then
  1217. if assigned(sym.definition.typesym) then
  1218. begin
  1219. { ES:=sym.definition.First;
  1220. while (ES<>nil) and (ES^.Value<>sym.value) do
  1221. ES:=ES^.next;
  1222. if assigned(es) and (es^.value=sym.value) then
  1223. Name:=}
  1224. Name:=sym.definition.typesym.name;
  1225. if Name<>'' then
  1226. Name:=Name+'('+IntToStr(sym.value)+')';
  1227. end;
  1228. GetEnumItemName:=Name;
  1229. end;
  1230. function GetConstValueName(sym: tconstsym): string;
  1231. var Name: string;
  1232. begin
  1233. Name:='';
  1234. if Name='' then
  1235. case sym.consttyp of
  1236. constord :
  1237. begin
  1238. if sym.constdef.deftype=enumdef then
  1239. Name:=sym.constdef.typesym.name+'('+IntToStr(sym.value.valueord)+')'
  1240. else
  1241. if is_boolean(sym.constdef) then
  1242. Name:='Longbool('+IntToStr(sym.value.valueord)+')'
  1243. else
  1244. if is_char(sym.constdef) or
  1245. is_widechar(sym.constdef) then
  1246. Name:=''''+chr(sym.value.valueord)+''''
  1247. else
  1248. Name:=IntToStr(sym.value.valueord);
  1249. end;
  1250. constresourcestring,
  1251. conststring :
  1252. Name:=''''+StrPas(pchar(sym.value.valueptr))+'''';
  1253. constreal:
  1254. Name:=FloatToStr(PBestReal(sym.value.valueptr)^);
  1255. constset:
  1256. { Name:=SetToStr(pnormalset(sym.value.valueptr)) };
  1257. constnil: ;
  1258. end;
  1259. GetConstValueName:=Name;
  1260. end;
  1261. procedure ProcessDefIfStruct(definition: tdef);
  1262. begin
  1263. { still led to infinite recursions
  1264. only usefull for unamed types PM }
  1265. if assigned(definition) and not assigned(definition.typesym) then
  1266. begin
  1267. case definition.deftype of
  1268. recorddef :
  1269. if trecorddef(definition).symtable<>Table then
  1270. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(definition).symtable);
  1271. objectdef :
  1272. if tobjectdef(definition).symtable<>Table then
  1273. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(definition).symtable);
  1274. { leads to infinite loops !!
  1275. pointerdef :
  1276. with tpointerdef(definition)^ do
  1277. if assigned(definition) then
  1278. if assigned(definition.sym) then
  1279. ProcessDefIfStruct(definition.sym.definition);}
  1280. end;
  1281. end;
  1282. end;
  1283. var MemInfo: TSymbolMemInfo;
  1284. ObjDef: tobjectdef;
  1285. begin
  1286. if not Assigned(Table) then
  1287. Exit;
  1288. if Owner=nil then
  1289. Owner:=New(PSortedSymbolCollection, Init(10,50));
  1290. sym:=tsym(Table.symindex.first);
  1291. while assigned(sym) do
  1292. begin
  1293. New(Symbol, Init(Sym.Name,Sym.Typ,'',nil));
  1294. case Sym.Typ of
  1295. globalvarsym,
  1296. localvarsym,
  1297. paravarsym :
  1298. with tabstractvarsym(sym) do
  1299. begin
  1300. if assigned(vardef) then
  1301. if assigned(vardef.typesym) then
  1302. SetVType(Symbol,vardef.typesym.name)
  1303. else
  1304. SetVType(Symbol,GetDefinitionStr(vardef));
  1305. ProcessDefIfStruct(vardef);
  1306. if assigned(vardef) then
  1307. if (vardef.deftype=pointerdef) and
  1308. assigned(tpointerdef(vardef).pointeddef) then
  1309. begin
  1310. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1311. Symbol^.RelatedTypeID:=Ptrint(tpointerdef(vardef).pointeddef);
  1312. end;
  1313. if typ=fieldvarsym then
  1314. MemInfo.Addr:=tfieldvarsym(sym).fieldoffset
  1315. else
  1316. begin
  1317. if tabstractnormalvarsym(sym).localloc.loc=LOC_REFERENCE then
  1318. MemInfo.Addr:=tabstractnormalvarsym(sym).localloc.reference.offset
  1319. else
  1320. MemInfo.Addr:=0;
  1321. end;
  1322. if assigned(vardef) and (vardef.deftype=arraydef) then
  1323. begin
  1324. if tarraydef(vardef).highrange<tarraydef(vardef).lowrange then
  1325. MemInfo.Size:=-1
  1326. else
  1327. MemInfo.Size:=getsize;
  1328. end
  1329. else
  1330. MemInfo.Size:=getsize;
  1331. { this is not completely correct... }
  1332. MemInfo.PushSize:=paramanager.push_size(varspez,vardef,pocall_default);
  1333. Symbol^.SetMemInfo(MemInfo);
  1334. end;
  1335. fieldvarsym :
  1336. with tfieldvarsym(sym) do
  1337. begin
  1338. if assigned(vardef) and (vardef.deftype=arraydef) then
  1339. begin
  1340. if tarraydef(vardef).highrange<tarraydef(vardef).lowrange then
  1341. MemInfo.Size:=-1
  1342. else
  1343. MemInfo.Size:=getsize;
  1344. end
  1345. else
  1346. MemInfo.Size:=getsize;
  1347. Symbol^.SetMemInfo(MemInfo);
  1348. end;
  1349. constsym :
  1350. SetDType(Symbol,GetConstValueName(tconstsym(sym)));
  1351. enumsym :
  1352. if assigned(tenumsym(sym).definition) then
  1353. SetDType(Symbol,GetEnumItemName(tenumsym(sym)));
  1354. unitsym :
  1355. begin
  1356. { ProcessSymTable(Symbol^.Items,tunitsym(sym).unitsymtable);}
  1357. end;
  1358. syssym :
  1359. { if assigned(Table.Name) then
  1360. if Table.Name^='SYSTEM' then}
  1361. begin
  1362. Symbol^.Params:=TypeNames^.Add('...');
  1363. end;
  1364. procsym :
  1365. begin
  1366. with tprocsym(sym) do
  1367. if assigned(first_procdef) then
  1368. begin
  1369. if cs_local_browser in current_settings.moduleswitches then
  1370. ProcessSymTable(Symbol,Symbol^.Items,first_procdef.parast);
  1371. if assigned(first_procdef.parast) then
  1372. begin
  1373. Symbol^.Params:=TypeNames^.Add(GetAbsProcParmDefStr(first_procdef));
  1374. end
  1375. else { param-definition is NOT assigned }
  1376. if assigned(Table.Name) then
  1377. if Table.Name^='SYSTEM' then
  1378. begin
  1379. Symbol^.Params:=TypeNames^.Add('...');
  1380. end;
  1381. if cs_local_browser in current_settings.moduleswitches then
  1382. begin
  1383. if assigned(first_procdef.localst) and
  1384. (first_procdef.localst.symtabletype<>staticsymtable) then
  1385. ProcessSymTable(Symbol,Symbol^.Items,first_procdef.localst);
  1386. end;
  1387. end;
  1388. end;
  1389. typesym :
  1390. begin
  1391. with ttypesym(sym) do
  1392. if assigned(typedef) then
  1393. begin
  1394. Symbol^.TypeID:=Ptrint(typedef);
  1395. case typedef.deftype of
  1396. arraydef :
  1397. SetDType(Symbol,GetArrayDefStr(tarraydef(typedef)));
  1398. enumdef :
  1399. SetDType(Symbol,GetEnumDefStr(tenumdef(typedef)));
  1400. procdef :
  1401. SetDType(Symbol,GetProcDefStr(tprocdef(typedef)));
  1402. procvardef :
  1403. SetDType(Symbol,GetProcVarDefStr(tprocvardef(typedef)));
  1404. objectdef :
  1405. with tobjectdef(typedef) do
  1406. begin
  1407. ObjDef:=childof;
  1408. if ObjDef<>nil then
  1409. Symbol^.RelatedTypeID:=Ptrint(ObjDef);{TypeNames^.Add(S);}
  1410. Symbol^.Flags:=(Symbol^.Flags or sfObject);
  1411. if tobjectdef(typedef).objecttype=odt_class then
  1412. Symbol^.Flags:=(Symbol^.Flags or sfClass);
  1413. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(typedef).symtable);
  1414. end;
  1415. recorddef :
  1416. begin
  1417. Symbol^.Flags:=(Symbol^.Flags or sfRecord);
  1418. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(typedef).symtable);
  1419. end;
  1420. pointerdef :
  1421. begin
  1422. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1423. Symbol^.RelatedTypeID:=Ptrint(tpointerdef(typedef).pointeddef);{TypeNames^.Add(S);}
  1424. SetDType(Symbol,GetPointerDefStr(tpointerdef(typedef)));
  1425. end;
  1426. filedef :
  1427. SetDType(Symbol,GetFileDefStr(tfiledef(typedef)));
  1428. setdef :
  1429. SetDType(Symbol,GetSetDefStr(tsetdef(typedef)));
  1430. end;
  1431. end;
  1432. end;
  1433. end;
  1434. Ref:=tstoredsym(sym).defref;
  1435. while Assigned(Symbol) and assigned(Ref) do
  1436. begin
  1437. inputfile:=get_source_file(ref.moduleindex,ref.posinfo.fileindex);
  1438. if Assigned(inputfile) and Assigned(inputfile.name) then
  1439. begin
  1440. New(Reference, Init(ModuleNames^.Add(inputfile.name^),
  1441. ref.posinfo.line,ref.posinfo.column));
  1442. Symbol^.References^.Insert(Reference);
  1443. end;
  1444. Ref:=Ref.nextref;
  1445. end;
  1446. if Assigned(Symbol) then
  1447. begin
  1448. if not Owner^.Search(Symbol,J) then
  1449. Owner^.Insert(Symbol)
  1450. else
  1451. begin
  1452. Dispose(Symbol,done);
  1453. Symbol:=nil;
  1454. end;
  1455. end;
  1456. sym:=tsym(sym.indexnext);
  1457. end;
  1458. end;
  1459. function SearchModule(const Name: string): PModuleSymbol;
  1460. function Match(P: PModuleSymbol): boolean;
  1461. begin
  1462. Match:=CompareText(P^.GetName,Name)=0;
  1463. end;
  1464. var P: PModuleSymbol;
  1465. begin
  1466. P:=nil;
  1467. if Assigned(Modules) then
  1468. P:=Modules^.FirstThat(@Match);
  1469. SearchModule:=P;
  1470. end;
  1471. procedure CreateBrowserCol;
  1472. var
  1473. T: TSymTable;
  1474. UnitS,PM: PModuleSymbol;
  1475. hp : tmodule;
  1476. puu: tused_unit;
  1477. pdu: tdependent_unit;
  1478. pif: tinputfile;
  1479. begin
  1480. DisposeBrowserCol;
  1481. if (cs_browser in current_settings.moduleswitches) then
  1482. NewBrowserCol;
  1483. hp:=tmodule(loaded_units.first);
  1484. if (cs_browser in current_settings.moduleswitches) then
  1485. while assigned(hp) do
  1486. begin
  1487. t:=tsymtable(hp.globalsymtable);
  1488. if assigned(t) then
  1489. begin
  1490. New(UnitS, Init(T.Name^,hp.mainsource^));
  1491. if Assigned(hp.loaded_from) then
  1492. if assigned(hp.loaded_from.globalsymtable) then
  1493. UnitS^.SetLoadedFrom(tsymtable(hp.loaded_from.globalsymtable).name^);
  1494. { pimportlist(current_module^.imports^.first);}
  1495. if assigned(hp.sourcefiles) then
  1496. begin
  1497. pif:=hp.sourcefiles.files;
  1498. while (pif<>nil) do
  1499. begin
  1500. UnitS^.AddSourceFile(pif.path^+pif.name^);
  1501. pif:=pif.next;
  1502. end;
  1503. end;
  1504. Modules^.Insert(UnitS);
  1505. ProcessSymTable(UnitS,UnitS^.Items,T);
  1506. if cs_local_browser in current_settings.moduleswitches then
  1507. begin
  1508. t:=tsymtable(hp.localsymtable);
  1509. if assigned(t) then
  1510. ProcessSymTable(UnitS,UnitS^.Items,T);
  1511. end;
  1512. end;
  1513. hp:=tmodule(hp.next);
  1514. end;
  1515. hp:=tmodule(loaded_units.first);
  1516. if (cs_browser in current_settings.moduleswitches) then
  1517. while assigned(hp) do
  1518. begin
  1519. t:=tsymtable(hp.globalsymtable);
  1520. if assigned(t) then
  1521. begin
  1522. UnitS:=SearchModule(T.Name^);
  1523. puu:=tused_unit(hp.used_units.first);
  1524. while (puu<>nil) do
  1525. begin
  1526. PM:=SearchModule(puu.u.modulename^);
  1527. if Assigned(PM) then
  1528. UnitS^.AddUsedUnit(PM);
  1529. puu:=tused_unit(puu.next);
  1530. end;
  1531. pdu:=tdependent_unit(hp.dependent_units.first);
  1532. while (pdu<>nil) do
  1533. begin
  1534. PM:=SearchModule(tsymtable(pdu.u.globalsymtable).name^);
  1535. if Assigned(PM) then
  1536. UnitS^.AddDependentUnit(PM);
  1537. pdu:=tdependent_unit(pdu.next);
  1538. end;
  1539. end;
  1540. hp:=tmodule(hp.next);
  1541. end;
  1542. if (cs_browser in current_settings.moduleswitches) then
  1543. BuildObjectInfo;
  1544. { can allways be done
  1545. needed to know when recompilation of sources is necessary }
  1546. BuildSourceList;
  1547. end;
  1548. procedure BuildObjectInfo;
  1549. var C,D: PIDSortedSymbolCollection;
  1550. E : PCollection;
  1551. ObjectC: PObjectSymbolCollection;
  1552. ObjectsSymbol: PObjectSymbol;
  1553. procedure InsertSymbolCollection(Symbols: PSymbolCollection);
  1554. var I: sw_integer;
  1555. P: PSymbol;
  1556. begin
  1557. for I:=0 to Symbols^.Count-1 do
  1558. begin
  1559. P:=Symbols^.At(I);
  1560. if (P^.Flags and sfObject)<>0 then
  1561. C^.Insert(P);
  1562. if (P^.typ=typesym) then
  1563. D^.Insert(P);
  1564. if (P^.typ in [globalvarsym,localvarsym,paravarsym]) and ((P^.flags and sfPointer)<>0) then
  1565. E^.Insert(P);
  1566. if P^.Items<>nil then
  1567. InsertSymbolCollection(P^.Items);
  1568. end;
  1569. end;
  1570. function SearchObjectForSym(O: PSymbol): PObjectSymbol;
  1571. var I: sw_integer;
  1572. OS,P: PObjectSymbol;
  1573. begin
  1574. P:=nil;
  1575. for I:=0 to ObjectC^.Count-1 do
  1576. begin
  1577. OS:=ObjectC^.At(I);
  1578. if OS^.Symbol=O then
  1579. begin P:=OS; Break; end;
  1580. end;
  1581. SearchObjectForSym:=P;
  1582. end;
  1583. procedure BuildTree;
  1584. var I: sw_integer;
  1585. Symbol: PSymbol;
  1586. Parent,OS: PObjectSymbol;
  1587. begin
  1588. I:=0;
  1589. while (I<C^.Count) do
  1590. begin
  1591. Symbol:=C^.At(I);
  1592. if Symbol^.Ancestor=nil then
  1593. Parent:=ObjectsSymbol
  1594. else
  1595. Parent:=SearchObjectForSym(Symbol^.Ancestor);
  1596. if Parent<>nil then
  1597. begin
  1598. New(OS, Init(Parent, Symbol));
  1599. Parent^.AddDescendant(OS);
  1600. ObjectC^.Insert(OS);
  1601. C^.AtDelete(I);
  1602. end
  1603. else
  1604. Inc(I);
  1605. end;
  1606. end;
  1607. var Pass: integer;
  1608. I: sw_integer;
  1609. P: PSymbol;
  1610. begin
  1611. New(C, Init(1000,5000));
  1612. New(D, Init(1000,5000));
  1613. New(E, Init(1000,5000));
  1614. InsertSymbolCollection(Modules);
  1615. { --- Resolve ancestor<->descendant references --- }
  1616. for I:=0 to C^.Count-1 do
  1617. begin
  1618. P:=C^.At(I);
  1619. if P^.RelatedTypeID<>0 then
  1620. P^.Ancestor:=C^.SearchSymbolByID(P^.RelatedTypeID);
  1621. end;
  1622. { --- Resolve pointer definition references --- }
  1623. for I:=0 to D^.Count-1 do
  1624. begin
  1625. P:=D^.At(I);
  1626. if P^.RelatedTypeID<>0 then
  1627. P^.Ancestor:=D^.SearchSymbolByID(P^.RelatedTypeID);
  1628. end;
  1629. { --- Resolve pointer var definition references --- }
  1630. for I:=0 to E^.Count-1 do
  1631. begin
  1632. P:=PSymbol(E^.At(I));
  1633. if P^.RelatedTypeID<>0 then
  1634. P^.Ancestor:=D^.SearchSymbolByID(P^.RelatedTypeID);
  1635. end;
  1636. { E is not needed anymore }
  1637. E^.DeleteAll;
  1638. Dispose(E,Done);
  1639. { D is not needed anymore }
  1640. D^.DeleteAll;
  1641. Dispose(D,Done);
  1642. { --- Build object tree --- }
  1643. if assigned(ObjectTree) then
  1644. Dispose(ObjectTree, Done);
  1645. New(ObjectsSymbol, InitName('Objects'));
  1646. ObjectTree:=ObjectsSymbol;
  1647. New(ObjectC, Init(C^.Count,100));
  1648. Pass:=0;
  1649. if C^.Count>0 then
  1650. repeat
  1651. BuildTree;
  1652. Inc(Pass);
  1653. until (C^.Count=0) or (Pass>20); { more than 20 levels ? - then there must be a bug }
  1654. ObjectC^.DeleteAll; Dispose(ObjectC, Done);
  1655. C^.DeleteAll; Dispose(C, Done);
  1656. end;
  1657. function SearchObjectForSymbol(O: PSymbol): PObjectSymbol;
  1658. function ScanObjectCollection(Parent: PObjectSymbol): PObjectSymbol;
  1659. var I: sw_integer;
  1660. OS,P: PObjectSymbol;
  1661. ObjectC: PObjectSymbolCollection;
  1662. begin
  1663. P:=nil;
  1664. if Parent<>nil then
  1665. if Parent^.Descendants<>nil then
  1666. begin
  1667. ObjectC:=Parent^.Descendants;
  1668. for I:=0 to ObjectC^.Count-1 do
  1669. begin
  1670. OS:=ObjectC^.At(I);
  1671. if OS^.Symbol=O then
  1672. begin P:=OS; Break; end;
  1673. if OS^.Descendants<>nil then
  1674. begin
  1675. P:=ScanObjectCollection(OS);
  1676. if P<>nil then Break;
  1677. end;
  1678. end;
  1679. end;
  1680. ScanObjectCollection:=P;
  1681. end;
  1682. begin
  1683. SearchObjectForSymbol:=ScanObjectCollection(ObjectTree);
  1684. end;
  1685. procedure BuildSourceList;
  1686. var m: tmodule;
  1687. s: tinputfile;
  1688. p: pstring;
  1689. ppu,obj: string;
  1690. source: string;
  1691. begin
  1692. if Assigned(SourceFiles) then
  1693. begin
  1694. Dispose(SourceFiles, Done);
  1695. SourceFiles:=nil;
  1696. end;
  1697. if assigned(loaded_units.first) then
  1698. begin
  1699. New(SourceFiles, Init(50,10));
  1700. m:=tmodule(loaded_units.first);
  1701. while assigned(m) do
  1702. begin
  1703. obj:=ExpandFileName(m.objfilename^);
  1704. ppu:=''; source:='';
  1705. if m.is_unit then
  1706. ppu:=ExpandFileName(m.ppufilename^);
  1707. if (m.is_unit=false) and (m.islibrary=false) then
  1708. ppu:=ExpandFileName(m.exefilename^);
  1709. if assigned(m.sourcefiles) then
  1710. begin
  1711. s:=m.sourcefiles.files;
  1712. while assigned(s) do
  1713. begin
  1714. source:='';
  1715. p:=s.path;
  1716. if assigned(p) then
  1717. source:=source+p^;
  1718. p:=s.name;
  1719. if assigned(p) then
  1720. source:=source+p^;
  1721. source:=ExpandFileName(source);
  1722. sourcefiles^.Insert(New(PSourceFile, Init(source,obj,ppu)));
  1723. s:=s.ref_next;
  1724. end;
  1725. end;
  1726. m:=tmodule(m.next);
  1727. end;
  1728. end;
  1729. end;
  1730. {*****************************************************************************
  1731. Initialize
  1732. *****************************************************************************}
  1733. var
  1734. oldexit : pointer;
  1735. procedure browcol_exit;
  1736. begin
  1737. exitproc:=oldexit;
  1738. DisposeBrowserCol;
  1739. if Assigned(SourceFiles) then
  1740. begin
  1741. Dispose(SourceFiles, Done);
  1742. SourceFiles:=nil;
  1743. end;
  1744. if assigned(ObjectTree) then
  1745. begin
  1746. Dispose(ObjectTree, Done);
  1747. ObjectTree:=nil;
  1748. end;
  1749. end;
  1750. procedure InitBrowserCol;
  1751. begin
  1752. end;
  1753. procedure DoneBrowserCol;
  1754. begin
  1755. { nothing, the collections are freed in the exitproc - ??? }
  1756. { nothing? then why do we've this routine for ? IMHO, either we should
  1757. remove this, or it should destroy the browser info when it's called. - BG }
  1758. end;
  1759. type
  1760. PPointerXRef = ^TPointerXRef;
  1761. TPointerXRef = record
  1762. PtrValue : pointer;
  1763. DataPtr : pointer;
  1764. end;
  1765. PPointerDictionary = ^TPointerDictionary;
  1766. TPointerDictionary = object(TSortedCollection)
  1767. function At(Index: sw_Integer): PPointerXRef;
  1768. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  1769. procedure FreeItem(Item: Pointer); virtual;
  1770. function SearchXRef(PtrValue: pointer): PPointerXRef;
  1771. function AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1772. procedure Resolve(var P);
  1773. end;
  1774. function NewPointerXRef(APtrValue, ADataPtr: pointer): PPointerXRef;
  1775. var P: PPointerXRef;
  1776. begin
  1777. New(P); FillChar(P^,SizeOf(P^),0);
  1778. with P^ do begin PtrValue:=APtrValue; DataPtr:=ADataPtr; end;
  1779. NewPointerXRef:=P;
  1780. end;
  1781. procedure DisposePointerXRef(P: PPointerXRef);
  1782. begin
  1783. if Assigned(P) then Dispose(P);
  1784. end;
  1785. function TPointerDictionary.At(Index: sw_Integer): PPointerXRef;
  1786. begin
  1787. At:=inherited At(Index);
  1788. end;
  1789. function TPointerDictionary.Compare(Key1, Key2: Pointer): sw_Integer;
  1790. var K1: PPointerXRef absolute Key1;
  1791. K2: PPointerXRef absolute Key2;
  1792. R: integer;
  1793. begin
  1794. if Ptrint(K1^.PtrValue)<Ptrint(K2^.PtrValue) then R:=-1 else
  1795. if Ptrint(K1^.PtrValue)>Ptrint(K2^.PtrValue) then R:= 1 else
  1796. R:=0;
  1797. Compare:=R;
  1798. end;
  1799. procedure TPointerDictionary.FreeItem(Item: Pointer);
  1800. begin
  1801. if Assigned(Item) then DisposePointerXRef(Item);
  1802. end;
  1803. function TPointerDictionary.SearchXRef(PtrValue: pointer): PPointerXRef;
  1804. var P: PPointerXRef;
  1805. T: TPointerXRef;
  1806. Index: sw_integer;
  1807. begin
  1808. T.PtrValue:=PtrValue;
  1809. if Search(@T,Index)=false then P:=nil else
  1810. P:=At(Index);
  1811. SearchXRef:=P;
  1812. end;
  1813. function TPointerDictionary.AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1814. var P: PPointerXRef;
  1815. begin
  1816. P:=SearchXRef(PtrValue);
  1817. if P=nil then
  1818. begin
  1819. P:=NewPointerXRef(PtrValue,DataPtr);
  1820. Insert(P);
  1821. {$ifdef DEBUG}
  1822. end
  1823. else
  1824. begin
  1825. if P^.DataPtr<>DataPtr then
  1826. InternalError(987654);
  1827. {$endif DEBUG}
  1828. end;
  1829. AddPtr:=P;
  1830. end;
  1831. procedure TPointerDictionary.Resolve(var P);
  1832. var X: PPointerXRef;
  1833. V: pointer;
  1834. begin
  1835. Move(P,V,SizeOf(V));
  1836. X:=SearchXRef(V);
  1837. if X=nil then V:=nil else
  1838. V:=X^.DataPtr;
  1839. Move(V,P,SizeOf(V));
  1840. end;
  1841. procedure ReadPointers(S: PStream; C: PCollection; D: PPointerDictionary);
  1842. var W,I: sw_integer;
  1843. P: pointer;
  1844. begin
  1845. S^.Read(W,SizeOf(W));
  1846. for I:=0 to W-1 do
  1847. begin
  1848. S^.Read(P,SizeOf(P));
  1849. D^.AddPtr(P,C^.At(I));
  1850. end;
  1851. end;
  1852. function LoadBrowserCol(S: PStream): boolean;
  1853. var PD: PPointerDictionary;
  1854. procedure FixupPointers;
  1855. procedure FixupReference(P: PReference);
  1856. begin
  1857. PD^.Resolve(P^.FileName);
  1858. end;
  1859. procedure FixupSymbol(P: PSymbol);
  1860. var I: sw_integer;
  1861. begin
  1862. PD^.Resolve(P^.DType);
  1863. PD^.Resolve(P^.VType);
  1864. PD^.Resolve(P^.Params);
  1865. if Assigned(P^.References) then
  1866. with P^.References^ do
  1867. for I:=0 to Count-1 do
  1868. FixupReference(At(I));
  1869. if Assigned(P^.Items) then
  1870. with P^.Items^ do
  1871. for I:=0 to Count-1 do
  1872. FixupSymbol(At(I));
  1873. end;
  1874. begin
  1875. Modules^.ForEach(@FixupSymbol);
  1876. end;
  1877. procedure ReadSymbolPointers(P: PSymbol);
  1878. var I: sw_integer;
  1879. PV: pointer;
  1880. begin
  1881. S^.Read(PV, SizeOf(PV));
  1882. PD^.AddPtr(PV,P);
  1883. if Assigned(P^.Items) then
  1884. with P^.Items^ do
  1885. for I:=0 to Count-1 do
  1886. ReadSymbolPointers(At(I));
  1887. end;
  1888. begin
  1889. DisposeBrowserCol;
  1890. New(ModuleNames, Load(S^));
  1891. New(TypeNames, Load(S^));
  1892. New(Modules, Load(S^));
  1893. New(PD, Init(4000,1000));
  1894. ReadPointers(S,ModuleNames,PD);
  1895. ReadPointers(S,TypeNames,PD);
  1896. ReadPointers(S,Modules,PD);
  1897. Modules^.ForEach(@ReadSymbolPointers);
  1898. FixupPointers;
  1899. Dispose(PD, Done);
  1900. BuildObjectInfo;
  1901. LoadBrowserCol:=(S^.Status=stOK);
  1902. end;
  1903. procedure StorePointers(S: PStream; C: PCollection);
  1904. var W,I: sw_integer;
  1905. P: pointer;
  1906. begin
  1907. W:=C^.Count;
  1908. S^.Write(W,SizeOf(W));
  1909. for I:=0 to W-1 do
  1910. begin
  1911. P:=C^.At(I);
  1912. S^.Write(P,SizeOf(P));
  1913. end;
  1914. end;
  1915. function StoreBrowserCol(S: PStream) : boolean;
  1916. procedure WriteSymbolPointers(P: PSymbol);
  1917. var I: sw_integer;
  1918. begin
  1919. S^.Write(P, SizeOf(P));
  1920. if Assigned(P^.Items) then
  1921. with P^.Items^ do
  1922. for I:=0 to Count-1 do
  1923. WriteSymbolPointers(At(I));
  1924. end;
  1925. begin
  1926. ModuleNames^.Store(S^);
  1927. TypeNames^.Store(S^);
  1928. Modules^.Store(S^);
  1929. StorePointers(S,ModuleNames);
  1930. StorePointers(S,TypeNames);
  1931. StorePointers(S,Modules);
  1932. Modules^.ForEach(@WriteSymbolPointers);
  1933. StoreBrowserCol:=(S^.Status=stOK);
  1934. end;
  1935. procedure RegisterSymbols;
  1936. begin
  1937. RegisterType(RModuleNameCollection);
  1938. RegisterType(RTypeNameCollection);
  1939. RegisterType(RReference);
  1940. RegisterType(RSymbol);
  1941. RegisterType(RObjectSymbol);
  1942. RegisterType(RSymbolCollection);
  1943. RegisterType(RSortedSymbolCollection);
  1944. RegisterType(RIDSortedSymbolCollection);
  1945. RegisterType(RObjectSymbolCollection);
  1946. RegisterType(RReferenceCollection);
  1947. RegisterType(RModuleSymbol);
  1948. end;
  1949. begin
  1950. oldexit:=exitproc;
  1951. exitproc:=@browcol_exit;
  1952. end.