2
0

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