browcol.pas 57 KB

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