browcol.pas 59 KB

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