browcol.pas 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156
  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,paramgr,
  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. macrosym : S:='macro';
  699. else S:='';
  700. end;
  701. GetTypeName:=S;
  702. end;
  703. destructor TSymbol.Done;
  704. begin
  705. inherited Done;
  706. if assigned(MemInfo) then
  707. Dispose(MemInfo);
  708. if assigned(References) then
  709. Dispose(References, Done);
  710. if assigned(Items) then
  711. Dispose(Items, Done);
  712. if assigned(Name) then
  713. DisposeStr(Name);
  714. { if assigned(Params) then
  715. DisposeStr(Params); in TypeNames
  716. if assigned(VType) then
  717. DisposeStr(VType);
  718. if assigned(DType) then
  719. DisposeStr(DType);
  720. if assigned(Ancestor) then
  721. DisposeStr(Ancestor);}
  722. end;
  723. constructor TSymbol.Load(var S: TStream);
  724. var MI: TSymbolMemInfo;
  725. W: word;
  726. begin
  727. TObject.Init;
  728. S.Read(Typ,SizeOf(Typ));
  729. S.Read(TypeID, SizeOf(TypeID));
  730. S.Read(RelatedTypeID, SizeOf(RelatedTypeID));
  731. S.Read(Flags, SizeOf(Flags));
  732. Name:=S.ReadStr;
  733. if (Flags and sfHasMemInfo)<>0 then
  734. begin
  735. S.Read(MI,SizeOf(MI));
  736. SetMemInfo(MI);
  737. end;
  738. W:=0;
  739. S.Read(W,SizeOf(W));
  740. if (W and 1)<>0 then
  741. New(References, Load(S));
  742. if (W and 2)<>0 then
  743. New(Items, Load(S));
  744. { --- items needing fixup --- }
  745. S.Read(DType, SizeOf(DType));
  746. S.Read(VType, SizeOf(VType));
  747. S.Read(Params, SizeOf(Params));
  748. end;
  749. procedure TSymbol.Store(var S: TStream);
  750. var W: word;
  751. begin
  752. S.Write(Typ,SizeOf(Typ));
  753. S.Write(TypeID, SizeOf(TypeID));
  754. S.Write(RelatedTypeID, SizeOf(RelatedTypeID));
  755. S.Write(Flags, SizeOf(Flags));
  756. S.WriteStr(Name);
  757. if (Flags and sfHasMemInfo)<>0 then
  758. S.Write(MemInfo^,SizeOf(MemInfo^));
  759. W:=0;
  760. if Assigned(References) then W:=W or 1;
  761. if Assigned(Items) then W:=W or 2;
  762. S.Write(W,SizeOf(W));
  763. if Assigned(References) then References^.Store(S);
  764. if Assigned(Items) then Items^.Store(S);
  765. { --- items needing fixup --- }
  766. S.Write(DType, SizeOf(DType));
  767. S.Write(VType, SizeOf(VType));
  768. S.Write(Params, SizeOf(Params));
  769. end;
  770. constructor TExport.Init(const AName: string; AIndex: longint; ASymbol: PSymbol);
  771. begin
  772. inherited Init;
  773. Name:=NewStr(AName); Index:=AIndex;
  774. Symbol:=ASymbol;
  775. end;
  776. function TExport.GetDisplayText: string;
  777. var S: string;
  778. begin
  779. S:=GetStr(Name)+' '+IntToStr(Index);
  780. if Assigned(Symbol) and (UpcaseStr(Symbol^.GetName)<>UpcaseStr(GetStr(Name))) then
  781. S:=S+' ('+Symbol^.GetName+')';
  782. GetDisplayText:=S;
  783. end;
  784. destructor TExport.Done;
  785. begin
  786. if Assigned(Name) then DisposeStr(Name);
  787. inherited Done;
  788. end;
  789. constructor TImport.Init(const ALibName, AFuncName,ARealName: string; AIndex: longint);
  790. begin
  791. inherited Init;
  792. LibName:=NewStr(ALibName);
  793. FuncName:=NewStr(AFuncName); RealName:=NewStr(ARealName);
  794. Index:=AIndex;
  795. end;
  796. function TImport.GetDisplayText: string;
  797. var S: string;
  798. begin
  799. S:=GetStr(RealName);
  800. if Assigned(FuncName) then S:=GetStr(FuncName)+' ('+S+')';
  801. if S='' then S:=IntToStr(Index);
  802. S:=GetStr(LibName)+' '+S;
  803. GetDisplayText:=S;
  804. end;
  805. destructor TImport.Done;
  806. begin
  807. if Assigned(LibName) then DisposeStr(LibName);
  808. if Assigned(FuncName) then DisposeStr(FuncName);
  809. if Assigned(RealName) then DisposeStr(RealName);
  810. inherited Done;
  811. end;
  812. function TImportCollection.At(Index: sw_Integer): PImport;
  813. begin
  814. At:=inherited At(Index);
  815. end;
  816. function TImportCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  817. var K1: PImport absolute Key1;
  818. K2: PImport absolute Key2;
  819. S1: string;
  820. S2: string;
  821. R: sw_integer;
  822. begin
  823. if (K1^.RealName=nil) and (K2^.RealName<>nil) then R:= 1 else
  824. if (K1^.RealName<>nil) and (K2^.RealName=nil) then R:=-1 else
  825. if (K1^.RealName=nil) and (K2^.RealName=nil) then
  826. begin
  827. if K1^.Index<K2^.Index then R:=-1 else
  828. if K1^.Index>K2^.Index then R:= 1 else
  829. R:=0;
  830. end
  831. else
  832. begin
  833. if K1^.FuncName=nil then S1:=GetStr(K1^.RealName) else S1:=GetStr(K1^.FuncName);
  834. if K2^.FuncName=nil then S2:=GetStr(K2^.RealName) else S2:=GetStr(K2^.FuncName);
  835. S1:=UpcaseStr(S1); S2:=UpcaseStr(S2);
  836. if S1<S2 then R:=-1 else
  837. if S1>S2 then R:= 1 else
  838. R:=0;
  839. end;
  840. Compare:=R;
  841. end;
  842. function TExportCollection.At(Index: sw_Integer): PExport;
  843. begin
  844. At:=inherited At(Index);
  845. end;
  846. function TExportCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  847. var K1: PExport absolute Key1;
  848. K2: PExport absolute Key2;
  849. S1: string;
  850. S2: string;
  851. R: sw_integer;
  852. begin
  853. S1:=UpcaseStr(GetStr(K1^.Name)); S2:=UpcaseStr(GetStr(K2^.Name));
  854. if S1<S2 then R:=-1 else
  855. if S1>S2 then R:= 1 else
  856. R:=0;
  857. Compare:=R;
  858. end;
  859. constructor TModuleSymbol.Init(const AName, AMainSource: string);
  860. begin
  861. inherited Init(AName,unitsym,'',nil);
  862. MainSource:=NewStr(AMainSource);
  863. end;
  864. procedure TModuleSymbol.SetLoadedFrom(const AModuleName: string);
  865. begin
  866. SetStr(LoadedFrom,AModuleName);
  867. end;
  868. procedure TModuleSymbol.AddUsedUnit(P: PSymbol);
  869. begin
  870. if Assigned(UsedUnits)=false then
  871. New(UsedUnits, Init(10,10));
  872. UsedUnits^.Insert(P);
  873. end;
  874. procedure TModuleSymbol.AddDependentUnit(P: PSymbol);
  875. begin
  876. if Assigned(DependentUnits)=false then
  877. New(DependentUnits, Init(10,10));
  878. DependentUnits^.Insert(P);
  879. end;
  880. procedure TModuleSymbol.AddSourceFile(const Path: string);
  881. begin
  882. if Assigned(SourceFiles)=false then
  883. New(SourceFiles, Init(10,10));
  884. sourcefiles^.Insert(NewStr(Path));
  885. end;
  886. destructor TModuleSymbol.Done;
  887. begin
  888. inherited Done;
  889. if Assigned(MainSource) then DisposeStr(MainSource);
  890. if assigned(Exports_) then
  891. Dispose(Exports_, Done);
  892. if Assigned(Imports) then
  893. Dispose(Imports, Done);
  894. if Assigned(LoadedFrom) then
  895. DisposeStr(LoadedFrom);
  896. if Assigned(UsedUnits) then
  897. begin
  898. UsedUnits^.DeleteAll;
  899. Dispose(UsedUnits, Done);
  900. end;
  901. if Assigned(DependentUnits) then
  902. begin
  903. DependentUnits^.DeleteAll;
  904. Dispose(DependentUnits, Done);
  905. end;
  906. if Assigned(SourceFiles) then Dispose(SourceFiles, Done);
  907. end;
  908. constructor TObjectSymbol.Init(AParent: PObjectSymbol; ASymbol: PSymbol);
  909. begin
  910. inherited Init;
  911. Parent:=AParent;
  912. Symbol:=ASymbol;
  913. end;
  914. constructor TObjectSymbol.InitName(const AName: string);
  915. begin
  916. inherited Init;
  917. Name:=NewStr(AName);
  918. end;
  919. function TObjectSymbol.GetName: string;
  920. begin
  921. if Name<>nil then
  922. GetName:=Name^
  923. else
  924. GetName:=Symbol^.GetName;
  925. end;
  926. function TObjectSymbol.GetDescendantCount: sw_integer;
  927. var Count: sw_integer;
  928. begin
  929. if Descendants=nil then Count:=0 else
  930. Count:=Descendants^.Count;
  931. GetDescendantCount:=Count;
  932. end;
  933. function TObjectSymbol.GetDescendant(Index: sw_integer): PObjectSymbol;
  934. begin
  935. GetDescendant:=Descendants^.At(Index);
  936. end;
  937. procedure TObjectSymbol.AddDescendant(P: PObjectSymbol);
  938. begin
  939. if Descendants=nil then
  940. New(Descendants, Init(50,10));
  941. Descendants^.Insert(P);
  942. end;
  943. destructor TObjectSymbol.Done;
  944. begin
  945. if Assigned(Name) then DisposeStr(Name); Name:=nil;
  946. if Assigned(Descendants) then Dispose(Descendants, Done); Descendants:=nil;
  947. inherited Done;
  948. end;
  949. constructor TObjectSymbol.Load(var S: TStream);
  950. begin
  951. end;
  952. procedure TObjectSymbol.Store(S: TStream);
  953. begin
  954. end;
  955. {****************************************************************************
  956. TSourceFile
  957. ****************************************************************************}
  958. constructor TSourceFile.Init(ASourceFileName, AObjFileName, APPUFileName: string);
  959. begin
  960. inherited Init;
  961. SourceFileName:=NewStr(ASourceFileName);
  962. ObjFileName:=NewStr(AObjFileName);
  963. PPUFileName:=NewStr(APPUFileName);
  964. end;
  965. destructor TSourceFile.Done;
  966. begin
  967. if assigned(SourceFileName) then DisposeStr(SourceFileName);
  968. if assigned(ObjFileName) then DisposeStr(ObjFileName);
  969. if assigned(PPUFileName) then DisposeStr(PPUFileName);
  970. inherited Done;
  971. end;
  972. function TSourceFile.GetSourceFilename: string;
  973. begin
  974. GetSourceFilename:=GetStr(SourceFileName);
  975. end;
  976. function TSourceFile.GetObjFileName: string;
  977. begin
  978. GetObjFilename:=GetStr(ObjFileName);
  979. end;
  980. function TSourceFile.GetPPUFileName: string;
  981. begin
  982. GetPPUFilename:=GetStr(PPUFileName);
  983. end;
  984. function TSourceFileCollection.At(Index: sw_Integer): PSourceFile;
  985. begin
  986. At:=inherited At(Index);
  987. end;
  988. {*****************************************************************************
  989. Main Routines
  990. *****************************************************************************}
  991. procedure DisposeBrowserCol;
  992. begin
  993. if assigned(Modules) then
  994. begin
  995. dispose(Modules,Done);
  996. Modules:=nil;
  997. end;
  998. if assigned(ModuleNames) then
  999. begin
  1000. dispose(ModuleNames,Done);
  1001. ModuleNames:=nil;
  1002. end;
  1003. if assigned(TypeNames) then
  1004. begin
  1005. dispose(TypeNames,Done);
  1006. TypeNames:=nil;
  1007. end;
  1008. if assigned(ObjectTree) then
  1009. begin
  1010. Dispose(ObjectTree, Done);
  1011. ObjectTree:=nil;
  1012. end;
  1013. end;
  1014. procedure NewBrowserCol;
  1015. begin
  1016. New(Modules, Init(50,50));
  1017. New(ModuleNames, Init(50,50));
  1018. New(TypeNames, Init(1000,5000));
  1019. end;
  1020. procedure ProcessSymTable(OwnerSym: PSymbol; var Owner: PSymbolCollection; Table: TSymTable);
  1021. var J: longint;
  1022. Ref: TRef;
  1023. Sym: TSym;
  1024. Symbol: PSymbol;
  1025. Reference: PReference;
  1026. inputfile : Tinputfile;
  1027. procedure SetVType(Symbol: PSymbol; VType: string);
  1028. begin
  1029. Symbol^.VType:=TypeNames^.Add(VType);
  1030. end;
  1031. procedure SetDType(Symbol: PSymbol; DType: string);
  1032. begin
  1033. Symbol^.DType:=TypeNames^.Add(DType);
  1034. end;
  1035. function GetDefinitionStr(def: tdef): string; forward;
  1036. function GetEnumDefStr(def: tenumdef): string;
  1037. var Name: string;
  1038. esym: tenumsym;
  1039. Count: integer;
  1040. begin
  1041. Name:='(';
  1042. esym:=tenumsym(def.Firstenum); Count:=0;
  1043. while (esym<>nil) do
  1044. begin
  1045. if Count>0 then
  1046. Name:=Name+', ';
  1047. Name:=Name+esym.name;
  1048. esym:=esym.nextenum;
  1049. Inc(Count);
  1050. end;
  1051. Name:=Name+')';
  1052. GetEnumDefStr:=Name;
  1053. end;
  1054. function GetArrayDefStr(def: tarraydef): string;
  1055. var Name: string;
  1056. begin
  1057. Name:='array ['+IntToStr(def.lowrange)+'..'+IntToStr(def.highrange)+'] of ';
  1058. if assigned(def.elementtype.def) then
  1059. Name:=Name+GetDefinitionStr(def.elementtype.def);
  1060. GetArrayDefStr:=Name;
  1061. end;
  1062. function GetFileDefStr(def: tfiledef): string;
  1063. var Name: string;
  1064. begin
  1065. Name:='';
  1066. case def.filetyp of
  1067. ft_text : Name:='text';
  1068. ft_untyped : Name:='file';
  1069. ft_typed : Name:='file of '+GetDefinitionStr(def.typedfiletype.def);
  1070. end;
  1071. GetFileDefStr:=Name;
  1072. end;
  1073. function GetStringDefStr(def: tstringdef): string;
  1074. var Name: string;
  1075. begin
  1076. Name:='';
  1077. case def.string_typ of
  1078. st_shortstring :
  1079. if def.len=255 then
  1080. Name:='shortstring'
  1081. else
  1082. Name:='string['+IntToStr(def.len)+']';
  1083. st_longstring :
  1084. Name:='longstring';
  1085. st_ansistring :
  1086. Name:='ansistring';
  1087. st_widestring :
  1088. Name:='widestring';
  1089. else ;
  1090. end;
  1091. GetStringDefStr:=Name;
  1092. end;
  1093. function retdefassigned(def: tabstractprocdef): boolean;
  1094. var OK: boolean;
  1095. begin
  1096. OK:=false;
  1097. if assigned(def.rettype.def) then
  1098. if UpcaseStr(GetDefinitionStr(def.rettype.def))<>'VOID' then
  1099. OK:=true;
  1100. retdefassigned:=OK;
  1101. end;
  1102. function GetAbsProcParmDefStr(def: tabstractprocdef): string;
  1103. var Name: string;
  1104. dc: tparaitem;
  1105. Count: integer;
  1106. CurName: string;
  1107. begin
  1108. Name:='';
  1109. dc:=tparaitem(def.para.first);
  1110. Count:=0;
  1111. while assigned(dc) do
  1112. begin
  1113. CurName:='';
  1114. case dc.paratyp of
  1115. vs_Value : ;
  1116. vs_Const : CurName:=CurName+'const ';
  1117. vs_Var : CurName:=CurName+'var ';
  1118. end;
  1119. if assigned(dc.paratype.def) then
  1120. CurName:=CurName+GetDefinitionStr(dc.paratype.def);
  1121. if dc.next<>nil then
  1122. CurName:=', '+CurName;
  1123. Name:=CurName+Name;
  1124. dc:=tparaitem(dc.next);
  1125. Inc(Count);
  1126. end;
  1127. GetAbsProcParmDefStr:=Name;
  1128. end;
  1129. function GetAbsProcDefStr(def: tabstractprocdef): string;
  1130. var Name: string;
  1131. begin
  1132. Name:=GetAbsProcParmDefStr(def);
  1133. if Name<>'' then Name:='('+Name+')';
  1134. if retdefassigned(def) then
  1135. Name:='function'+Name+': '+GetDefinitionStr(def.rettype.def)
  1136. else
  1137. Name:='procedure'+Name;
  1138. GetAbsProcDefStr:=Name;
  1139. end;
  1140. function GetProcDefStr(def: tprocdef): string;
  1141. var DName: string;
  1142. {J: integer;}
  1143. begin
  1144. { DName:='';
  1145. if assigned(def) then
  1146. begin
  1147. if assigned(def.parast) then
  1148. begin
  1149. with def.parast^ do
  1150. for J:=1 to number_symbols do
  1151. begin
  1152. if J<>1 then DName:=DName+', ';
  1153. ParSym:=GetsymNr(J);
  1154. if ParSym=nil then Break;
  1155. DName:=DName+ParSym^.Name;
  1156. end;
  1157. end
  1158. end;}
  1159. DName:=GetAbsProcDefStr(def);
  1160. GetProcDefStr:=DName;
  1161. end;
  1162. function GetProcVarDefStr(def: tprocvardef): string;
  1163. begin
  1164. GetProcVarDefStr:=GetAbsProcDefStr(def);
  1165. end;
  1166. function GetSetDefStr(def: tsetdef): string;
  1167. var Name: string;
  1168. begin
  1169. Name:='';
  1170. case def.settype of
  1171. normset : Name:='set';
  1172. smallset : Name:='set';
  1173. varset : Name:='varset';
  1174. end;
  1175. Name:=Name+' of ';
  1176. Name:=Name+GetDefinitionStr(def.elementtype.def);
  1177. GetSetDefStr:=Name;
  1178. end;
  1179. function GetPointerDefStr(def: tpointerdef): string;
  1180. begin
  1181. GetPointerDefStr:='^'+GetDefinitionStr(def.pointertype.def);
  1182. end;
  1183. function GetDefinitionStr(def: tdef): string;
  1184. var Name: string;
  1185. begin
  1186. Name:='';
  1187. if def<>nil then
  1188. begin
  1189. if assigned(def.typesym) then
  1190. Name:=def.typesym.name;
  1191. if Name='' then
  1192. case def.deftype of
  1193. arraydef :
  1194. Name:=GetArrayDefStr(tarraydef(def));
  1195. stringdef :
  1196. Name:=GetStringDefStr(tstringdef(def));
  1197. enumdef :
  1198. Name:=GetEnumDefStr(tenumdef(def));
  1199. procdef :
  1200. Name:=GetProcDefStr(tprocdef(def));
  1201. procvardef :
  1202. Name:=GetProcVarDefStr(tprocvardef(def));
  1203. filedef :
  1204. Name:=GetFileDefStr(tfiledef(def));
  1205. setdef :
  1206. Name:=GetSetDefStr(tsetdef(def));
  1207. end;
  1208. end;
  1209. GetDefinitionStr:=Name;
  1210. end;
  1211. function GetEnumItemName(Sym: tenumsym): string;
  1212. var Name: string;
  1213. {ES: tenumsym;}
  1214. begin
  1215. Name:='';
  1216. if assigned(sym) and assigned(sym.definition) then
  1217. if assigned(sym.definition.typesym) then
  1218. begin
  1219. { ES:=sym.definition.First;
  1220. while (ES<>nil) and (ES^.Value<>sym.value) do
  1221. ES:=ES^.next;
  1222. if assigned(es) and (es^.value=sym.value) then
  1223. Name:=}
  1224. Name:=sym.definition.typesym.name;
  1225. if Name<>'' then
  1226. Name:=Name+'('+IntToStr(sym.value)+')';
  1227. end;
  1228. GetEnumItemName:=Name;
  1229. end;
  1230. function GetConstValueName(sym: tconstsym): string;
  1231. var Name: string;
  1232. begin
  1233. Name:='';
  1234. if Name='' then
  1235. case sym.consttyp of
  1236. constord :
  1237. Name:=sym.consttype.def.typesym.name+'('+IntToStr(sym.value.valueord)+')';
  1238. constresourcestring,
  1239. conststring :
  1240. Name:=''''+StrPas(pchar(sym.value.valueptr))+'''';
  1241. constreal:
  1242. Name:=FloatToStr(PBestReal(sym.value.valueptr)^);
  1243. constbool:
  1244. Name:='Longbool('+IntToStr(sym.value.valueord)+')';
  1245. constint:
  1246. Name:=IntToStr(sym.value.valueord);
  1247. constchar:
  1248. Name:=''''+chr(sym.value.valueord)+'''';
  1249. constset:
  1250. { Name:=SetToStr(pnormalset(sym.value.valueptr)) };
  1251. constnil: ;
  1252. end;
  1253. GetConstValueName:=Name;
  1254. end;
  1255. procedure ProcessDefIfStruct(definition: tdef);
  1256. begin
  1257. { still led to infinite recursions
  1258. only usefull for unamed types PM }
  1259. if assigned(definition) and not assigned(definition.typesym) then
  1260. begin
  1261. case definition.deftype of
  1262. recorddef :
  1263. if trecorddef(definition).symtable<>Table then
  1264. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(definition).symtable);
  1265. objectdef :
  1266. if tobjectdef(definition).symtable<>Table then
  1267. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(definition).symtable);
  1268. { leads to infinite loops !!
  1269. pointerdef :
  1270. with tpointerdef(definition)^ do
  1271. if assigned(definition) then
  1272. if assigned(definition.sym) then
  1273. ProcessDefIfStruct(definition.sym.definition);}
  1274. end;
  1275. end;
  1276. end;
  1277. var MemInfo: TSymbolMemInfo;
  1278. ObjDef: tobjectdef;
  1279. begin
  1280. if not Assigned(Table) then
  1281. Exit;
  1282. if Owner=nil then
  1283. Owner:=New(PSortedSymbolCollection, Init(10,50));
  1284. sym:=tsym(Table.symindex.first);
  1285. while assigned(sym) do
  1286. begin
  1287. New(Symbol, Init(Sym.Name,Sym.Typ,'',nil));
  1288. case Sym.Typ of
  1289. varsym :
  1290. with tvarsym(sym) do
  1291. begin
  1292. if assigned(vartype.def) then
  1293. if assigned(vartype.def.typesym) then
  1294. SetVType(Symbol,vartype.def.typesym.name)
  1295. else
  1296. SetVType(Symbol,GetDefinitionStr(vartype.def));
  1297. ProcessDefIfStruct(vartype.def);
  1298. if assigned(vartype.def) then
  1299. if (vartype.def.deftype=pointerdef) and
  1300. assigned(tpointerdef(vartype.def).pointertype.def) then
  1301. begin
  1302. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1303. Symbol^.RelatedTypeID:=longint(tpointerdef(vartype.def).pointertype.def);
  1304. end;
  1305. MemInfo.Addr:=address;
  1306. if assigned(localvarsym) then
  1307. MemInfo.LocalAddr:=localvarsym.address
  1308. else
  1309. MemInfo.LocalAddr:=0;
  1310. if assigned(vartype.def) and (vartype.def.deftype=arraydef) then
  1311. begin
  1312. if tarraydef(vartype.def).highrange<tarraydef(vartype.def).lowrange then
  1313. MemInfo.Size:=-1
  1314. else
  1315. MemInfo.Size:=getsize;
  1316. end
  1317. else
  1318. MemInfo.Size:=getsize;
  1319. { this is not completely correct... }
  1320. MemInfo.PushSize:=paramanager.push_size(varspez,vartype.def,pocall_none);
  1321. Symbol^.SetMemInfo(MemInfo);
  1322. end;
  1323. constsym :
  1324. SetDType(Symbol,GetConstValueName(tconstsym(sym)));
  1325. enumsym :
  1326. if assigned(tenumsym(sym).definition) then
  1327. SetDType(Symbol,GetEnumItemName(tenumsym(sym)));
  1328. unitsym :
  1329. begin
  1330. { ProcessSymTable(Symbol^.Items,tunitsym(sym).unitsymtable);}
  1331. end;
  1332. syssym :
  1333. { if assigned(Table.Name) then
  1334. if Table.Name^='SYSTEM' then}
  1335. begin
  1336. Symbol^.Params:=TypeNames^.Add('...');
  1337. end;
  1338. procsym :
  1339. begin
  1340. with tprocsym(sym) do
  1341. if assigned(first_procdef) then
  1342. begin
  1343. if cs_local_browser in aktmoduleswitches then
  1344. ProcessSymTable(Symbol,Symbol^.Items,first_procdef.parast);
  1345. if assigned(first_procdef.parast) then
  1346. begin
  1347. Symbol^.Params:=TypeNames^.Add(GetAbsProcParmDefStr(first_procdef));
  1348. end
  1349. else { param-definition is NOT assigned }
  1350. if assigned(Table.Name) then
  1351. if Table.Name^='SYSTEM' then
  1352. begin
  1353. Symbol^.Params:=TypeNames^.Add('...');
  1354. end;
  1355. if cs_local_browser in aktmoduleswitches then
  1356. begin
  1357. if assigned(first_procdef.localst) and
  1358. (first_procdef.localst.symtabletype<>staticsymtable) then
  1359. ProcessSymTable(Symbol,Symbol^.Items,first_procdef.localst);
  1360. end;
  1361. end;
  1362. end;
  1363. typesym :
  1364. begin
  1365. with ttypesym(sym) do
  1366. if assigned(restype.def) then
  1367. begin
  1368. Symbol^.TypeID:=longint(restype.def);
  1369. case restype.def.deftype of
  1370. arraydef :
  1371. SetDType(Symbol,GetArrayDefStr(tarraydef(restype.def)));
  1372. enumdef :
  1373. SetDType(Symbol,GetEnumDefStr(tenumdef(restype.def)));
  1374. procdef :
  1375. SetDType(Symbol,GetProcDefStr(tprocdef(restype.def)));
  1376. procvardef :
  1377. SetDType(Symbol,GetProcVarDefStr(tprocvardef(restype.def)));
  1378. objectdef :
  1379. with tobjectdef(restype.def) do
  1380. begin
  1381. ObjDef:=childof;
  1382. if ObjDef<>nil then
  1383. Symbol^.RelatedTypeID:=longint(ObjDef);{TypeNames^.Add(S);}
  1384. Symbol^.Flags:=(Symbol^.Flags or sfObject);
  1385. if tobjectdef(restype.def).objecttype=odt_class then
  1386. Symbol^.Flags:=(Symbol^.Flags or sfClass);
  1387. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(restype.def).symtable);
  1388. end;
  1389. recorddef :
  1390. begin
  1391. Symbol^.Flags:=(Symbol^.Flags or sfRecord);
  1392. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(restype.def).symtable);
  1393. end;
  1394. pointerdef :
  1395. begin
  1396. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1397. Symbol^.RelatedTypeID:=longint(tpointerdef(restype.def).pointertype.def);{TypeNames^.Add(S);}
  1398. SetDType(Symbol,GetPointerDefStr(tpointerdef(restype.def)));
  1399. end;
  1400. filedef :
  1401. SetDType(Symbol,GetFileDefStr(tfiledef(restype.def)));
  1402. setdef :
  1403. SetDType(Symbol,GetSetDefStr(tsetdef(restype.def)));
  1404. end;
  1405. end;
  1406. end;
  1407. end;
  1408. Ref:=tstoredsym(sym).defref;
  1409. while Assigned(Symbol) and assigned(Ref) do
  1410. begin
  1411. inputfile:=get_source_file(ref.moduleindex,ref.posinfo.fileindex);
  1412. if Assigned(inputfile) and Assigned(inputfile.name) then
  1413. begin
  1414. New(Reference, Init(ModuleNames^.Add(inputfile.name^),
  1415. ref.posinfo.line,ref.posinfo.column));
  1416. Symbol^.References^.Insert(Reference);
  1417. end;
  1418. Ref:=Ref.nextref;
  1419. end;
  1420. if Assigned(Symbol) then
  1421. begin
  1422. if not Owner^.Search(Symbol,J) then
  1423. Owner^.Insert(Symbol)
  1424. else
  1425. begin
  1426. Dispose(Symbol,done);
  1427. Symbol:=nil;
  1428. end;
  1429. end;
  1430. sym:=tsym(sym.indexnext);
  1431. end;
  1432. end;
  1433. function SearchModule(const Name: string): PModuleSymbol;
  1434. function Match(P: PModuleSymbol): boolean; {$ifndef FPC}far;{$endif}
  1435. begin
  1436. Match:=CompareText(P^.GetName,Name)=0;
  1437. end;
  1438. var P: PModuleSymbol;
  1439. begin
  1440. P:=nil;
  1441. if Assigned(Modules) then
  1442. P:=Modules^.FirstThat(@Match);
  1443. SearchModule:=P;
  1444. end;
  1445. procedure CreateBrowserCol;
  1446. var
  1447. T: TSymTable;
  1448. UnitS,PM: PModuleSymbol;
  1449. hp : tmodule;
  1450. puu: tused_unit;
  1451. pdu: tdependent_unit;
  1452. pif: tinputfile;
  1453. begin
  1454. DisposeBrowserCol;
  1455. if (cs_browser in aktmoduleswitches) then
  1456. NewBrowserCol;
  1457. hp:=tmodule(loaded_units.first);
  1458. if (cs_browser in aktmoduleswitches) then
  1459. while assigned(hp) do
  1460. begin
  1461. t:=tsymtable(hp.globalsymtable);
  1462. if assigned(t) then
  1463. begin
  1464. New(UnitS, Init(T.Name^,hp.mainsource^));
  1465. if Assigned(hp.loaded_from) then
  1466. if assigned(hp.loaded_from.globalsymtable) then
  1467. UnitS^.SetLoadedFrom(tsymtable(hp.loaded_from.globalsymtable).name^);
  1468. { pimportlist(current_module^.imports^.first);}
  1469. if assigned(hp.sourcefiles) then
  1470. begin
  1471. pif:=hp.sourcefiles.files;
  1472. while (pif<>nil) do
  1473. begin
  1474. UnitS^.AddSourceFile(pif.path^+pif.name^);
  1475. pif:=pif.next;
  1476. end;
  1477. end;
  1478. Modules^.Insert(UnitS);
  1479. ProcessSymTable(UnitS,UnitS^.Items,T);
  1480. if cs_local_browser in aktmoduleswitches then
  1481. begin
  1482. t:=tsymtable(hp.localsymtable);
  1483. if assigned(t) then
  1484. ProcessSymTable(UnitS,UnitS^.Items,T);
  1485. end;
  1486. end;
  1487. hp:=tmodule(hp.next);
  1488. end;
  1489. hp:=tmodule(loaded_units.first);
  1490. if (cs_browser in aktmoduleswitches) then
  1491. while assigned(hp) do
  1492. begin
  1493. t:=tsymtable(hp.globalsymtable);
  1494. if assigned(t) then
  1495. begin
  1496. UnitS:=SearchModule(T.Name^);
  1497. puu:=tused_unit(hp.used_units.first);
  1498. while (puu<>nil) do
  1499. begin
  1500. PM:=SearchModule(puu.u.modulename^);
  1501. if Assigned(PM) then
  1502. UnitS^.AddUsedUnit(PM);
  1503. puu:=tused_unit(puu.next);
  1504. end;
  1505. pdu:=tdependent_unit(hp.dependent_units.first);
  1506. while (pdu<>nil) do
  1507. begin
  1508. PM:=SearchModule(tsymtable(pdu.u.globalsymtable).name^);
  1509. if Assigned(PM) then
  1510. UnitS^.AddDependentUnit(PM);
  1511. pdu:=tdependent_unit(pdu.next);
  1512. end;
  1513. end;
  1514. hp:=tmodule(hp.next);
  1515. end;
  1516. if (cs_browser in aktmoduleswitches) then
  1517. BuildObjectInfo;
  1518. { can allways be done
  1519. needed to know when recompilation of sources is necessary }
  1520. BuildSourceList;
  1521. end;
  1522. procedure BuildObjectInfo;
  1523. var C,D: PIDSortedSymbolCollection;
  1524. E : PCollection;
  1525. ObjectC: PObjectSymbolCollection;
  1526. ObjectsSymbol: PObjectSymbol;
  1527. procedure InsertSymbolCollection(Symbols: PSymbolCollection);
  1528. var I: sw_integer;
  1529. P: PSymbol;
  1530. begin
  1531. for I:=0 to Symbols^.Count-1 do
  1532. begin
  1533. P:=Symbols^.At(I);
  1534. if (P^.Flags and sfObject)<>0 then
  1535. C^.Insert(P);
  1536. if (P^.typ=typesym) then
  1537. D^.Insert(P);
  1538. if (P^.typ=varsym) and ((P^.flags and sfPointer)<>0) then
  1539. E^.Insert(P);
  1540. if P^.Items<>nil then
  1541. InsertSymbolCollection(P^.Items);
  1542. end;
  1543. end;
  1544. function SearchObjectForSym(O: PSymbol): PObjectSymbol;
  1545. var I: sw_integer;
  1546. OS,P: PObjectSymbol;
  1547. begin
  1548. P:=nil;
  1549. for I:=0 to ObjectC^.Count-1 do
  1550. begin
  1551. OS:=ObjectC^.At(I);
  1552. if OS^.Symbol=O then
  1553. begin P:=OS; Break; end;
  1554. end;
  1555. SearchObjectForSym:=P;
  1556. end;
  1557. procedure BuildTree;
  1558. var I: sw_integer;
  1559. Symbol: PSymbol;
  1560. Parent,OS: PObjectSymbol;
  1561. begin
  1562. I:=0;
  1563. while (I<C^.Count) do
  1564. begin
  1565. Symbol:=C^.At(I);
  1566. if Symbol^.Ancestor=nil then
  1567. Parent:=ObjectsSymbol
  1568. else
  1569. Parent:=SearchObjectForSym(Symbol^.Ancestor);
  1570. if Parent<>nil then
  1571. begin
  1572. New(OS, Init(Parent, Symbol));
  1573. Parent^.AddDescendant(OS);
  1574. ObjectC^.Insert(OS);
  1575. C^.AtDelete(I);
  1576. end
  1577. else
  1578. Inc(I);
  1579. end;
  1580. end;
  1581. var Pass: integer;
  1582. I: sw_integer;
  1583. P: PSymbol;
  1584. begin
  1585. New(C, Init(1000,5000));
  1586. New(D, Init(1000,5000));
  1587. New(E, Init(1000,5000));
  1588. InsertSymbolCollection(Modules);
  1589. { --- Resolve ancestor<->descendant references --- }
  1590. for I:=0 to C^.Count-1 do
  1591. begin
  1592. P:=C^.At(I);
  1593. if P^.RelatedTypeID<>0 then
  1594. P^.Ancestor:=C^.SearchSymbolByID(P^.RelatedTypeID);
  1595. end;
  1596. { --- Resolve pointer definition references --- }
  1597. for I:=0 to D^.Count-1 do
  1598. begin
  1599. P:=D^.At(I);
  1600. if P^.RelatedTypeID<>0 then
  1601. P^.Ancestor:=D^.SearchSymbolByID(P^.RelatedTypeID);
  1602. end;
  1603. { --- Resolve pointer var definition references --- }
  1604. for I:=0 to E^.Count-1 do
  1605. begin
  1606. P:=PSymbol(E^.At(I));
  1607. if P^.RelatedTypeID<>0 then
  1608. P^.Ancestor:=D^.SearchSymbolByID(P^.RelatedTypeID);
  1609. end;
  1610. { E is not needed anymore }
  1611. E^.DeleteAll;
  1612. Dispose(E,Done);
  1613. { D is not needed anymore }
  1614. D^.DeleteAll;
  1615. Dispose(D,Done);
  1616. { --- Build object tree --- }
  1617. if assigned(ObjectTree) then
  1618. Dispose(ObjectTree, Done);
  1619. New(ObjectsSymbol, InitName('Objects'));
  1620. ObjectTree:=ObjectsSymbol;
  1621. New(ObjectC, Init(C^.Count,100));
  1622. Pass:=0;
  1623. if C^.Count>0 then
  1624. repeat
  1625. BuildTree;
  1626. Inc(Pass);
  1627. until (C^.Count=0) or (Pass>20); { more than 20 levels ? - then there must be a bug }
  1628. ObjectC^.DeleteAll; Dispose(ObjectC, Done);
  1629. C^.DeleteAll; Dispose(C, Done);
  1630. end;
  1631. function SearchObjectForSymbol(O: PSymbol): PObjectSymbol;
  1632. function ScanObjectCollection(Parent: PObjectSymbol): PObjectSymbol;
  1633. var I: sw_integer;
  1634. OS,P: PObjectSymbol;
  1635. ObjectC: PObjectSymbolCollection;
  1636. begin
  1637. P:=nil;
  1638. if Parent<>nil then
  1639. if Parent^.Descendants<>nil then
  1640. begin
  1641. ObjectC:=Parent^.Descendants;
  1642. for I:=0 to ObjectC^.Count-1 do
  1643. begin
  1644. OS:=ObjectC^.At(I);
  1645. if OS^.Symbol=O then
  1646. begin P:=OS; Break; end;
  1647. if OS^.Descendants<>nil then
  1648. begin
  1649. P:=ScanObjectCollection(OS);
  1650. if P<>nil then Break;
  1651. end;
  1652. end;
  1653. end;
  1654. ScanObjectCollection:=P;
  1655. end;
  1656. begin
  1657. SearchObjectForSymbol:=ScanObjectCollection(ObjectTree);
  1658. end;
  1659. procedure BuildSourceList;
  1660. var m: tmodule;
  1661. s: tinputfile;
  1662. p: cutils.pstring;
  1663. ppu,obj: string;
  1664. source: string;
  1665. begin
  1666. if Assigned(SourceFiles) then
  1667. begin
  1668. Dispose(SourceFiles, Done);
  1669. SourceFiles:=nil;
  1670. end;
  1671. if assigned(loaded_units.first) then
  1672. begin
  1673. New(SourceFiles, Init(50,10));
  1674. m:=tmodule(loaded_units.first);
  1675. while assigned(m) do
  1676. begin
  1677. obj:=fexpand(m.objfilename^);
  1678. ppu:=''; source:='';
  1679. if m.is_unit then
  1680. ppu:=fexpand(m.ppufilename^);
  1681. if (m.is_unit=false) and (m.islibrary=false) then
  1682. ppu:=fexpand(m.exefilename^);
  1683. if assigned(m.sourcefiles) then
  1684. begin
  1685. s:=m.sourcefiles.files;
  1686. while assigned(s) do
  1687. begin
  1688. source:='';
  1689. p:=s.path;
  1690. if assigned(p) then
  1691. source:=source+p^;
  1692. p:=s.name;
  1693. if assigned(p) then
  1694. source:=source+p^;
  1695. source:=fexpand(source);
  1696. sourcefiles^.Insert(New(PSourceFile, Init(source,obj,ppu)));
  1697. s:=s.ref_next;
  1698. end;
  1699. end;
  1700. m:=tmodule(m.next);
  1701. end;
  1702. end;
  1703. end;
  1704. {*****************************************************************************
  1705. Initialize
  1706. *****************************************************************************}
  1707. var
  1708. oldexit : pointer;
  1709. procedure browcol_exit;{$ifndef FPC}far;{$endif}
  1710. begin
  1711. exitproc:=oldexit;
  1712. DisposeBrowserCol;
  1713. if Assigned(SourceFiles) then
  1714. begin
  1715. Dispose(SourceFiles, Done);
  1716. SourceFiles:=nil;
  1717. end;
  1718. if assigned(ObjectTree) then
  1719. begin
  1720. Dispose(ObjectTree, Done);
  1721. ObjectTree:=nil;
  1722. end;
  1723. end;
  1724. procedure InitBrowserCol;
  1725. begin
  1726. end;
  1727. procedure DoneBrowserCol;
  1728. begin
  1729. { nothing, the collections are freed in the exitproc - ??? }
  1730. { nothing? then why do we've this routine for ? IMHO, either we should
  1731. remove this, or it should destroy the browser info when it's called. - BG }
  1732. end;
  1733. type
  1734. PPointerXRef = ^TPointerXRef;
  1735. TPointerXRef = record
  1736. PtrValue : pointer;
  1737. DataPtr : pointer;
  1738. end;
  1739. PPointerDictionary = ^TPointerDictionary;
  1740. TPointerDictionary = object(TSortedCollection)
  1741. function At(Index: sw_Integer): PPointerXRef;
  1742. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  1743. procedure FreeItem(Item: Pointer); virtual;
  1744. function SearchXRef(PtrValue: pointer): PPointerXRef;
  1745. function AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1746. procedure Resolve(var P);
  1747. end;
  1748. function NewPointerXRef(APtrValue, ADataPtr: pointer): PPointerXRef;
  1749. var P: PPointerXRef;
  1750. begin
  1751. New(P); FillChar(P^,SizeOf(P^),0);
  1752. with P^ do begin PtrValue:=APtrValue; DataPtr:=ADataPtr; end;
  1753. NewPointerXRef:=P;
  1754. end;
  1755. procedure DisposePointerXRef(P: PPointerXRef);
  1756. begin
  1757. if Assigned(P) then Dispose(P);
  1758. end;
  1759. function TPointerDictionary.At(Index: sw_Integer): PPointerXRef;
  1760. begin
  1761. At:=inherited At(Index);
  1762. end;
  1763. function TPointerDictionary.Compare(Key1, Key2: Pointer): sw_Integer;
  1764. var K1: PPointerXRef absolute Key1;
  1765. K2: PPointerXRef absolute Key2;
  1766. R: integer;
  1767. begin
  1768. if longint(K1^.PtrValue)<longint(K2^.PtrValue) then R:=-1 else
  1769. if longint(K1^.PtrValue)>longint(K2^.PtrValue) then R:= 1 else
  1770. R:=0;
  1771. Compare:=R;
  1772. end;
  1773. procedure TPointerDictionary.FreeItem(Item: Pointer);
  1774. begin
  1775. if Assigned(Item) then DisposePointerXRef(Item);
  1776. end;
  1777. function TPointerDictionary.SearchXRef(PtrValue: pointer): PPointerXRef;
  1778. var P: PPointerXRef;
  1779. T: TPointerXRef;
  1780. Index: sw_integer;
  1781. begin
  1782. T.PtrValue:=PtrValue;
  1783. if Search(@T,Index)=false then P:=nil else
  1784. P:=At(Index);
  1785. SearchXRef:=P;
  1786. end;
  1787. function TPointerDictionary.AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1788. var P: PPointerXRef;
  1789. begin
  1790. P:=SearchXRef(PtrValue);
  1791. if P=nil then
  1792. begin
  1793. P:=NewPointerXRef(PtrValue,DataPtr);
  1794. Insert(P);
  1795. {$ifdef DEBUG}
  1796. end
  1797. else
  1798. begin
  1799. if P^.DataPtr<>DataPtr then
  1800. InternalError(987654);
  1801. {$endif DEBUG}
  1802. end;
  1803. AddPtr:=P;
  1804. end;
  1805. procedure TPointerDictionary.Resolve(var P);
  1806. var X: PPointerXRef;
  1807. V: pointer;
  1808. begin
  1809. Move(P,V,SizeOf(V));
  1810. X:=SearchXRef(V);
  1811. if X=nil then V:=nil else
  1812. V:=X^.DataPtr;
  1813. Move(V,P,SizeOf(V));
  1814. end;
  1815. procedure ReadPointers(S: PStream; C: PCollection; D: PPointerDictionary);
  1816. var W,I: sw_integer;
  1817. P: pointer;
  1818. begin
  1819. S^.Read(W,SizeOf(W));
  1820. for I:=0 to W-1 do
  1821. begin
  1822. S^.Read(P,SizeOf(P));
  1823. D^.AddPtr(P,C^.At(I));
  1824. end;
  1825. end;
  1826. function LoadBrowserCol(S: PStream): boolean;
  1827. var PD: PPointerDictionary;
  1828. procedure FixupPointers;
  1829. procedure FixupReference(P: PReference); {$ifndef FPC}far;{$endif}
  1830. begin
  1831. PD^.Resolve(P^.FileName);
  1832. end;
  1833. procedure FixupSymbol(P: PSymbol); {$ifndef FPC}far;{$endif}
  1834. var I: sw_integer;
  1835. begin
  1836. PD^.Resolve(P^.DType);
  1837. PD^.Resolve(P^.VType);
  1838. PD^.Resolve(P^.Params);
  1839. if Assigned(P^.References) then
  1840. with P^.References^ do
  1841. for I:=0 to Count-1 do
  1842. FixupReference(At(I));
  1843. if Assigned(P^.Items) then
  1844. with P^.Items^ do
  1845. for I:=0 to Count-1 do
  1846. FixupSymbol(At(I));
  1847. end;
  1848. begin
  1849. Modules^.ForEach(@FixupSymbol);
  1850. end;
  1851. procedure ReadSymbolPointers(P: PSymbol); {$ifndef FPC}far;{$endif}
  1852. var I: sw_integer;
  1853. PV: pointer;
  1854. begin
  1855. S^.Read(PV, SizeOf(PV));
  1856. PD^.AddPtr(PV,P);
  1857. if Assigned(P^.Items) then
  1858. with P^.Items^ do
  1859. for I:=0 to Count-1 do
  1860. ReadSymbolPointers(At(I));
  1861. end;
  1862. begin
  1863. DisposeBrowserCol;
  1864. New(ModuleNames, Load(S^));
  1865. New(TypeNames, Load(S^));
  1866. New(Modules, Load(S^));
  1867. New(PD, Init(4000,1000));
  1868. ReadPointers(S,ModuleNames,PD);
  1869. ReadPointers(S,TypeNames,PD);
  1870. ReadPointers(S,Modules,PD);
  1871. Modules^.ForEach(@ReadSymbolPointers);
  1872. FixupPointers;
  1873. Dispose(PD, Done);
  1874. BuildObjectInfo;
  1875. LoadBrowserCol:=(S^.Status=stOK);
  1876. end;
  1877. procedure StorePointers(S: PStream; C: PCollection);
  1878. var W,I: sw_integer;
  1879. P: pointer;
  1880. begin
  1881. W:=C^.Count;
  1882. S^.Write(W,SizeOf(W));
  1883. for I:=0 to W-1 do
  1884. begin
  1885. P:=C^.At(I);
  1886. S^.Write(P,SizeOf(P));
  1887. end;
  1888. end;
  1889. function StoreBrowserCol(S: PStream) : boolean;
  1890. procedure WriteSymbolPointers(P: PSymbol); {$ifndef FPC}far;{$endif}
  1891. var I: sw_integer;
  1892. begin
  1893. S^.Write(P, SizeOf(P));
  1894. if Assigned(P^.Items) then
  1895. with P^.Items^ do
  1896. for I:=0 to Count-1 do
  1897. WriteSymbolPointers(At(I));
  1898. end;
  1899. begin
  1900. ModuleNames^.Store(S^);
  1901. TypeNames^.Store(S^);
  1902. Modules^.Store(S^);
  1903. StorePointers(S,ModuleNames);
  1904. StorePointers(S,TypeNames);
  1905. StorePointers(S,Modules);
  1906. Modules^.ForEach(@WriteSymbolPointers);
  1907. StoreBrowserCol:=(S^.Status=stOK);
  1908. end;
  1909. procedure RegisterSymbols;
  1910. begin
  1911. RegisterType(RModuleNameCollection);
  1912. RegisterType(RTypeNameCollection);
  1913. RegisterType(RReference);
  1914. RegisterType(RSymbol);
  1915. RegisterType(RObjectSymbol);
  1916. RegisterType(RSymbolCollection);
  1917. RegisterType(RSortedSymbolCollection);
  1918. RegisterType(RIDSortedSymbolCollection);
  1919. RegisterType(RObjectSymbolCollection);
  1920. RegisterType(RReferenceCollection);
  1921. RegisterType(RModuleSymbol);
  1922. end;
  1923. begin
  1924. oldexit:=exitproc;
  1925. exitproc:=@browcol_exit;
  1926. end.
  1927. {
  1928. $Log$
  1929. Revision 1.33 2003-04-26 00:29:17 peter
  1930. * adapted for removed funcretsym
  1931. Revision 1.32 2002/12/29 14:57:50 peter
  1932. * unit loading changed to first register units and load them
  1933. afterwards. This is needed to support uses xxx in yyy correctly
  1934. * unit dependency check fixed
  1935. Revision 1.31 2002/11/27 20:04:10 peter
  1936. * tvarsym.get_push_size replaced by paramanager.push_size
  1937. Revision 1.30 2002/11/24 18:17:29 carl
  1938. * fix compilation problems after my changes to tcontsym
  1939. Revision 1.29 2002/11/20 22:48:42 pierre
  1940. * fix compilation failure for IDE
  1941. Revision 1.28 2002/09/07 14:13:40 peter
  1942. * fixed procdef access
  1943. Revision 1.27 2002/08/25 19:25:18 peter
  1944. * sym.insert_in_data removed
  1945. * symtable.insertvardata/insertconstdata added
  1946. * removed insert_in_data call from symtable.insert, it needs to be
  1947. called separatly. This allows to deref the address calculation
  1948. * procedures now calculate the parast addresses after the procedure
  1949. directives are parsed. This fixes the cdecl parast problem
  1950. * push_addr_param has an extra argument that specifies if cdecl is used
  1951. or not
  1952. Revision 1.26 2002/07/02 06:09:08 michael
  1953. + Patch from peter to fix snapshots
  1954. Revision 1.25 2002/05/18 13:34:05 peter
  1955. * readded missing revisions
  1956. Revision 1.24 2002/05/16 19:46:35 carl
  1957. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1958. + try to fix temp allocation (still in ifdef)
  1959. + generic constructor calls
  1960. + start of tassembler / tmodulebase class cleanup
  1961. }