browcol.pas 60 KB

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