browcol.pas 58 KB

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