browcol.pas 58 KB

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