browcol.pas 58 KB

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