browcol.pas 61 KB

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