browcol.pas 61 KB

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