browcol.pas 61 KB

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