browcol.pas 58 KB

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