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