browcol.pas 57 KB

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