browcol.pas 58 KB

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