browcol.pas 61 KB

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