browcol.pas 57 KB

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