browcol.pas 48 KB

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