browcol.pas 56 KB

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