browcol.pas 57 KB

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