browcol.pas 57 KB

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