browcol.pas 58 KB

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