browcol.pas 61 KB

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