browcol.pas 57 KB

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