browcol.pas 50 KB

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