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