browcol.pas 58 KB

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