browcol.pas 61 KB

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