browcol.pas 61 KB

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