browcol.pas 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Berczi Gabor
  4. Modifications Copyright (c) 1999-2002 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,aasmbase,aasmtai,paramgr,
  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 Name='' then
  1236. case sym.consttyp of
  1237. constord :
  1238. Name:=sym.consttype.def.typesym.name+'('+IntToStr(sym.value.valueord)+')';
  1239. constresourcestring,
  1240. conststring :
  1241. Name:=''''+StrPas(pchar(sym.value.valueptr))+'''';
  1242. constreal:
  1243. Name:=FloatToStr(PBestReal(sym.value.valueptr)^);
  1244. constbool:
  1245. Name:='Longbool('+IntToStr(sym.value.valueord)+')';
  1246. constint:
  1247. Name:=IntToStr(sym.value.valueord);
  1248. constchar:
  1249. Name:=''''+chr(sym.value.valueord)+'''';
  1250. constset:
  1251. { Name:=SetToStr(pnormalset(sym.value.valueptr)) };
  1252. constnil: ;
  1253. end;
  1254. GetConstValueName:=Name;
  1255. end;
  1256. procedure ProcessDefIfStruct(definition: tdef);
  1257. begin
  1258. { still led to infinite recursions
  1259. only usefull for unamed types PM }
  1260. if assigned(definition) and not assigned(definition.typesym) then
  1261. begin
  1262. case definition.deftype of
  1263. recorddef :
  1264. if trecorddef(definition).symtable<>Table then
  1265. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(definition).symtable);
  1266. objectdef :
  1267. if tobjectdef(definition).symtable<>Table then
  1268. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(definition).symtable);
  1269. { leads to infinite loops !!
  1270. pointerdef :
  1271. with tpointerdef(definition)^ do
  1272. if assigned(definition) then
  1273. if assigned(definition.sym) then
  1274. ProcessDefIfStruct(definition.sym.definition);}
  1275. end;
  1276. end;
  1277. end;
  1278. var MemInfo: TSymbolMemInfo;
  1279. ObjDef: tobjectdef;
  1280. begin
  1281. if not Assigned(Table) then
  1282. Exit;
  1283. if Owner=nil then
  1284. Owner:=New(PSortedSymbolCollection, Init(10,50));
  1285. sym:=tsym(Table.symindex.first);
  1286. while assigned(sym) do
  1287. begin
  1288. New(Symbol, Init(Sym.Name,Sym.Typ,'',nil));
  1289. case Sym.Typ of
  1290. varsym :
  1291. with tvarsym(sym) do
  1292. begin
  1293. if assigned(vartype.def) then
  1294. if assigned(vartype.def.typesym) then
  1295. SetVType(Symbol,vartype.def.typesym.name)
  1296. else
  1297. SetVType(Symbol,GetDefinitionStr(vartype.def));
  1298. ProcessDefIfStruct(vartype.def);
  1299. if assigned(vartype.def) then
  1300. if (vartype.def.deftype=pointerdef) and
  1301. assigned(tpointerdef(vartype.def).pointertype.def) then
  1302. begin
  1303. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1304. Symbol^.RelatedTypeID:=longint(tpointerdef(vartype.def).pointertype.def);
  1305. end;
  1306. MemInfo.Addr:=address;
  1307. if assigned(localvarsym) then
  1308. MemInfo.LocalAddr:=localvarsym.address
  1309. else
  1310. MemInfo.LocalAddr:=0;
  1311. if assigned(vartype.def) and (vartype.def.deftype=arraydef) then
  1312. begin
  1313. if tarraydef(vartype.def).highrange<tarraydef(vartype.def).lowrange then
  1314. MemInfo.Size:=-1
  1315. else
  1316. MemInfo.Size:=getsize;
  1317. end
  1318. else
  1319. MemInfo.Size:=getsize;
  1320. { this is not completely correct... }
  1321. MemInfo.PushSize:=paramanager.push_size(varspez,vartype.def,pocall_none);
  1322. Symbol^.SetMemInfo(MemInfo);
  1323. end;
  1324. constsym :
  1325. SetDType(Symbol,GetConstValueName(tconstsym(sym)));
  1326. enumsym :
  1327. if assigned(tenumsym(sym).definition) then
  1328. SetDType(Symbol,GetEnumItemName(tenumsym(sym)));
  1329. unitsym :
  1330. begin
  1331. { ProcessSymTable(Symbol^.Items,tunitsym(sym).unitsymtable);}
  1332. end;
  1333. syssym :
  1334. { if assigned(Table.Name) then
  1335. if Table.Name^='SYSTEM' then}
  1336. begin
  1337. Symbol^.Params:=TypeNames^.Add('...');
  1338. end;
  1339. funcretsym :
  1340. if Assigned(OwnerSym) then
  1341. with tfuncretsym(sym) do
  1342. if assigned(returntype.def) then
  1343. if assigned(returntype.def.typesym) then
  1344. SetVType(OwnerSym,returntype.def.typesym.name);
  1345. procsym :
  1346. begin
  1347. with tprocsym(sym) do
  1348. if assigned(first_procdef) then
  1349. begin
  1350. if cs_local_browser in aktmoduleswitches then
  1351. ProcessSymTable(Symbol,Symbol^.Items,first_procdef.parast);
  1352. if assigned(first_procdef.parast) then
  1353. begin
  1354. Symbol^.Params:=TypeNames^.Add(GetAbsProcParmDefStr(first_procdef));
  1355. end
  1356. else { param-definition is NOT assigned }
  1357. if assigned(Table.Name) then
  1358. if Table.Name^='SYSTEM' then
  1359. begin
  1360. Symbol^.Params:=TypeNames^.Add('...');
  1361. end;
  1362. if cs_local_browser in aktmoduleswitches then
  1363. begin
  1364. if assigned(first_procdef.localst) and
  1365. (first_procdef.localst.symtabletype<>staticsymtable) then
  1366. ProcessSymTable(Symbol,Symbol^.Items,first_procdef.localst);
  1367. end;
  1368. end;
  1369. end;
  1370. typesym :
  1371. begin
  1372. with ttypesym(sym) do
  1373. if assigned(restype.def) then
  1374. begin
  1375. Symbol^.TypeID:=longint(restype.def);
  1376. case restype.def.deftype of
  1377. arraydef :
  1378. SetDType(Symbol,GetArrayDefStr(tarraydef(restype.def)));
  1379. enumdef :
  1380. SetDType(Symbol,GetEnumDefStr(tenumdef(restype.def)));
  1381. procdef :
  1382. SetDType(Symbol,GetProcDefStr(tprocdef(restype.def)));
  1383. procvardef :
  1384. SetDType(Symbol,GetProcVarDefStr(tprocvardef(restype.def)));
  1385. objectdef :
  1386. with tobjectdef(restype.def) do
  1387. begin
  1388. ObjDef:=childof;
  1389. if ObjDef<>nil then
  1390. Symbol^.RelatedTypeID:=longint(ObjDef);{TypeNames^.Add(S);}
  1391. Symbol^.Flags:=(Symbol^.Flags or sfObject);
  1392. if tobjectdef(restype.def).objecttype=odt_class then
  1393. Symbol^.Flags:=(Symbol^.Flags or sfClass);
  1394. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(restype.def).symtable);
  1395. end;
  1396. recorddef :
  1397. begin
  1398. Symbol^.Flags:=(Symbol^.Flags or sfRecord);
  1399. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(restype.def).symtable);
  1400. end;
  1401. pointerdef :
  1402. begin
  1403. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1404. Symbol^.RelatedTypeID:=longint(tpointerdef(restype.def).pointertype.def);{TypeNames^.Add(S);}
  1405. SetDType(Symbol,GetPointerDefStr(tpointerdef(restype.def)));
  1406. end;
  1407. filedef :
  1408. SetDType(Symbol,GetFileDefStr(tfiledef(restype.def)));
  1409. setdef :
  1410. SetDType(Symbol,GetSetDefStr(tsetdef(restype.def)));
  1411. end;
  1412. end;
  1413. end;
  1414. end;
  1415. Ref:=tstoredsym(sym).defref;
  1416. while Assigned(Symbol) and assigned(Ref) do
  1417. begin
  1418. inputfile:=get_source_file(ref.moduleindex,ref.posinfo.fileindex);
  1419. if Assigned(inputfile) and Assigned(inputfile.name) then
  1420. begin
  1421. New(Reference, Init(ModuleNames^.Add(inputfile.name^),
  1422. ref.posinfo.line,ref.posinfo.column));
  1423. Symbol^.References^.Insert(Reference);
  1424. end;
  1425. Ref:=Ref.nextref;
  1426. end;
  1427. if Assigned(Symbol) then
  1428. begin
  1429. if not Owner^.Search(Symbol,J) then
  1430. Owner^.Insert(Symbol)
  1431. else
  1432. begin
  1433. Dispose(Symbol,done);
  1434. Symbol:=nil;
  1435. end;
  1436. end;
  1437. sym:=tsym(sym.indexnext);
  1438. end;
  1439. end;
  1440. function SearchModule(const Name: string): PModuleSymbol;
  1441. function Match(P: PModuleSymbol): boolean; {$ifndef FPC}far;{$endif}
  1442. begin
  1443. Match:=CompareText(P^.GetName,Name)=0;
  1444. end;
  1445. var P: PModuleSymbol;
  1446. begin
  1447. P:=nil;
  1448. if Assigned(Modules) then
  1449. P:=Modules^.FirstThat(@Match);
  1450. SearchModule:=P;
  1451. end;
  1452. procedure CreateBrowserCol;
  1453. var
  1454. T: TSymTable;
  1455. UnitS,PM: PModuleSymbol;
  1456. hp : tmodule;
  1457. puu: tused_unit;
  1458. pdu: tdependent_unit;
  1459. pif: tinputfile;
  1460. begin
  1461. DisposeBrowserCol;
  1462. if (cs_browser in aktmoduleswitches) then
  1463. NewBrowserCol;
  1464. hp:=tmodule(loaded_units.first);
  1465. if (cs_browser in aktmoduleswitches) then
  1466. while assigned(hp) do
  1467. begin
  1468. t:=tsymtable(hp.globalsymtable);
  1469. if assigned(t) then
  1470. begin
  1471. New(UnitS, Init(T.Name^,hp.mainsource^));
  1472. if Assigned(hp.loaded_from) then
  1473. if assigned(hp.loaded_from.globalsymtable) then
  1474. UnitS^.SetLoadedFrom(tsymtable(hp.loaded_from.globalsymtable).name^);
  1475. { pimportlist(current_module^.imports^.first);}
  1476. if assigned(hp.sourcefiles) then
  1477. begin
  1478. pif:=hp.sourcefiles.files;
  1479. while (pif<>nil) do
  1480. begin
  1481. UnitS^.AddSourceFile(pif.path^+pif.name^);
  1482. pif:=pif.next;
  1483. end;
  1484. end;
  1485. Modules^.Insert(UnitS);
  1486. ProcessSymTable(UnitS,UnitS^.Items,T);
  1487. if cs_local_browser in aktmoduleswitches then
  1488. begin
  1489. t:=tsymtable(hp.localsymtable);
  1490. if assigned(t) then
  1491. ProcessSymTable(UnitS,UnitS^.Items,T);
  1492. end;
  1493. end;
  1494. hp:=tmodule(hp.next);
  1495. end;
  1496. hp:=tmodule(loaded_units.first);
  1497. if (cs_browser in aktmoduleswitches) then
  1498. while assigned(hp) do
  1499. begin
  1500. t:=tsymtable(hp.globalsymtable);
  1501. if assigned(t) then
  1502. begin
  1503. UnitS:=SearchModule(T.Name^);
  1504. puu:=tused_unit(hp.used_units.first);
  1505. while (puu<>nil) do
  1506. begin
  1507. PM:=SearchModule(puu.name^);
  1508. if Assigned(PM) then
  1509. UnitS^.AddUsedUnit(PM);
  1510. puu:=tused_unit(puu.next);
  1511. end;
  1512. pdu:=tdependent_unit(hp.dependent_units.first);
  1513. while (pdu<>nil) do
  1514. begin
  1515. PM:=SearchModule(tsymtable(pdu.u.globalsymtable).name^);
  1516. if Assigned(PM) then
  1517. UnitS^.AddDependentUnit(PM);
  1518. pdu:=tdependent_unit(pdu.next);
  1519. end;
  1520. end;
  1521. hp:=tmodule(hp.next);
  1522. end;
  1523. if (cs_browser in aktmoduleswitches) then
  1524. BuildObjectInfo;
  1525. { can allways be done
  1526. needed to know when recompilation of sources is necessary }
  1527. BuildSourceList;
  1528. end;
  1529. procedure BuildObjectInfo;
  1530. var C,D: PIDSortedSymbolCollection;
  1531. E : PCollection;
  1532. ObjectC: PObjectSymbolCollection;
  1533. ObjectsSymbol: PObjectSymbol;
  1534. procedure InsertSymbolCollection(Symbols: PSymbolCollection);
  1535. var I: sw_integer;
  1536. P: PSymbol;
  1537. begin
  1538. for I:=0 to Symbols^.Count-1 do
  1539. begin
  1540. P:=Symbols^.At(I);
  1541. if (P^.Flags and sfObject)<>0 then
  1542. C^.Insert(P);
  1543. if (P^.typ=typesym) then
  1544. D^.Insert(P);
  1545. if (P^.typ=varsym) and ((P^.flags and sfPointer)<>0) then
  1546. E^.Insert(P);
  1547. if P^.Items<>nil then
  1548. InsertSymbolCollection(P^.Items);
  1549. end;
  1550. end;
  1551. function SearchObjectForSym(O: PSymbol): PObjectSymbol;
  1552. var I: sw_integer;
  1553. OS,P: PObjectSymbol;
  1554. begin
  1555. P:=nil;
  1556. for I:=0 to ObjectC^.Count-1 do
  1557. begin
  1558. OS:=ObjectC^.At(I);
  1559. if OS^.Symbol=O then
  1560. begin P:=OS; Break; end;
  1561. end;
  1562. SearchObjectForSym:=P;
  1563. end;
  1564. procedure BuildTree;
  1565. var I: sw_integer;
  1566. Symbol: PSymbol;
  1567. Parent,OS: PObjectSymbol;
  1568. begin
  1569. I:=0;
  1570. while (I<C^.Count) do
  1571. begin
  1572. Symbol:=C^.At(I);
  1573. if Symbol^.Ancestor=nil then
  1574. Parent:=ObjectsSymbol
  1575. else
  1576. Parent:=SearchObjectForSym(Symbol^.Ancestor);
  1577. if Parent<>nil then
  1578. begin
  1579. New(OS, Init(Parent, Symbol));
  1580. Parent^.AddDescendant(OS);
  1581. ObjectC^.Insert(OS);
  1582. C^.AtDelete(I);
  1583. end
  1584. else
  1585. Inc(I);
  1586. end;
  1587. end;
  1588. var Pass: integer;
  1589. I: sw_integer;
  1590. P: PSymbol;
  1591. begin
  1592. New(C, Init(1000,5000));
  1593. New(D, Init(1000,5000));
  1594. New(E, Init(1000,5000));
  1595. InsertSymbolCollection(Modules);
  1596. { --- Resolve ancestor<->descendant references --- }
  1597. for I:=0 to C^.Count-1 do
  1598. begin
  1599. P:=C^.At(I);
  1600. if P^.RelatedTypeID<>0 then
  1601. P^.Ancestor:=C^.SearchSymbolByID(P^.RelatedTypeID);
  1602. end;
  1603. { --- Resolve pointer definition references --- }
  1604. for I:=0 to D^.Count-1 do
  1605. begin
  1606. P:=D^.At(I);
  1607. if P^.RelatedTypeID<>0 then
  1608. P^.Ancestor:=D^.SearchSymbolByID(P^.RelatedTypeID);
  1609. end;
  1610. { --- Resolve pointer var definition references --- }
  1611. for I:=0 to E^.Count-1 do
  1612. begin
  1613. P:=PSymbol(E^.At(I));
  1614. if P^.RelatedTypeID<>0 then
  1615. P^.Ancestor:=D^.SearchSymbolByID(P^.RelatedTypeID);
  1616. end;
  1617. { E is not needed anymore }
  1618. E^.DeleteAll;
  1619. Dispose(E,Done);
  1620. { D is not needed anymore }
  1621. D^.DeleteAll;
  1622. Dispose(D,Done);
  1623. { --- Build object tree --- }
  1624. if assigned(ObjectTree) then
  1625. Dispose(ObjectTree, Done);
  1626. New(ObjectsSymbol, InitName('Objects'));
  1627. ObjectTree:=ObjectsSymbol;
  1628. New(ObjectC, Init(C^.Count,100));
  1629. Pass:=0;
  1630. if C^.Count>0 then
  1631. repeat
  1632. BuildTree;
  1633. Inc(Pass);
  1634. until (C^.Count=0) or (Pass>20); { more than 20 levels ? - then there must be a bug }
  1635. ObjectC^.DeleteAll; Dispose(ObjectC, Done);
  1636. C^.DeleteAll; Dispose(C, Done);
  1637. end;
  1638. function SearchObjectForSymbol(O: PSymbol): PObjectSymbol;
  1639. function ScanObjectCollection(Parent: PObjectSymbol): PObjectSymbol;
  1640. var I: sw_integer;
  1641. OS,P: PObjectSymbol;
  1642. ObjectC: PObjectSymbolCollection;
  1643. begin
  1644. P:=nil;
  1645. if Parent<>nil then
  1646. if Parent^.Descendants<>nil then
  1647. begin
  1648. ObjectC:=Parent^.Descendants;
  1649. for I:=0 to ObjectC^.Count-1 do
  1650. begin
  1651. OS:=ObjectC^.At(I);
  1652. if OS^.Symbol=O then
  1653. begin P:=OS; Break; end;
  1654. if OS^.Descendants<>nil then
  1655. begin
  1656. P:=ScanObjectCollection(OS);
  1657. if P<>nil then Break;
  1658. end;
  1659. end;
  1660. end;
  1661. ScanObjectCollection:=P;
  1662. end;
  1663. begin
  1664. SearchObjectForSymbol:=ScanObjectCollection(ObjectTree);
  1665. end;
  1666. procedure BuildSourceList;
  1667. var m: tmodule;
  1668. s: tinputfile;
  1669. p: cutils.pstring;
  1670. ppu,obj: string;
  1671. source: string;
  1672. begin
  1673. if Assigned(SourceFiles) then
  1674. begin
  1675. Dispose(SourceFiles, Done);
  1676. SourceFiles:=nil;
  1677. end;
  1678. if assigned(loaded_units.first) then
  1679. begin
  1680. New(SourceFiles, Init(50,10));
  1681. m:=tmodule(loaded_units.first);
  1682. while assigned(m) do
  1683. begin
  1684. obj:=fexpand(m.objfilename^);
  1685. ppu:=''; source:='';
  1686. if m.is_unit then
  1687. ppu:=fexpand(m.ppufilename^);
  1688. if (m.is_unit=false) and (m.islibrary=false) then
  1689. ppu:=fexpand(m.exefilename^);
  1690. if assigned(m.sourcefiles) then
  1691. begin
  1692. s:=m.sourcefiles.files;
  1693. while assigned(s) do
  1694. begin
  1695. source:='';
  1696. p:=s.path;
  1697. if assigned(p) then
  1698. source:=source+p^;
  1699. p:=s.name;
  1700. if assigned(p) then
  1701. source:=source+p^;
  1702. source:=fexpand(source);
  1703. sourcefiles^.Insert(New(PSourceFile, Init(source,obj,ppu)));
  1704. s:=s.ref_next;
  1705. end;
  1706. end;
  1707. m:=tmodule(m.next);
  1708. end;
  1709. end;
  1710. end;
  1711. {*****************************************************************************
  1712. Initialize
  1713. *****************************************************************************}
  1714. var
  1715. oldexit : pointer;
  1716. procedure browcol_exit;{$ifndef FPC}far;{$endif}
  1717. begin
  1718. exitproc:=oldexit;
  1719. DisposeBrowserCol;
  1720. if Assigned(SourceFiles) then
  1721. begin
  1722. Dispose(SourceFiles, Done);
  1723. SourceFiles:=nil;
  1724. end;
  1725. if assigned(ObjectTree) then
  1726. begin
  1727. Dispose(ObjectTree, Done);
  1728. ObjectTree:=nil;
  1729. end;
  1730. end;
  1731. procedure InitBrowserCol;
  1732. begin
  1733. end;
  1734. procedure DoneBrowserCol;
  1735. begin
  1736. { nothing, the collections are freed in the exitproc - ??? }
  1737. { nothing? then why do we've this routine for ? IMHO, either we should
  1738. remove this, or it should destroy the browser info when it's called. - BG }
  1739. end;
  1740. type
  1741. PPointerXRef = ^TPointerXRef;
  1742. TPointerXRef = record
  1743. PtrValue : pointer;
  1744. DataPtr : pointer;
  1745. end;
  1746. PPointerDictionary = ^TPointerDictionary;
  1747. TPointerDictionary = object(TSortedCollection)
  1748. function At(Index: sw_Integer): PPointerXRef;
  1749. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  1750. procedure FreeItem(Item: Pointer); virtual;
  1751. function SearchXRef(PtrValue: pointer): PPointerXRef;
  1752. function AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1753. procedure Resolve(var P);
  1754. end;
  1755. function NewPointerXRef(APtrValue, ADataPtr: pointer): PPointerXRef;
  1756. var P: PPointerXRef;
  1757. begin
  1758. New(P); FillChar(P^,SizeOf(P^),0);
  1759. with P^ do begin PtrValue:=APtrValue; DataPtr:=ADataPtr; end;
  1760. NewPointerXRef:=P;
  1761. end;
  1762. procedure DisposePointerXRef(P: PPointerXRef);
  1763. begin
  1764. if Assigned(P) then Dispose(P);
  1765. end;
  1766. function TPointerDictionary.At(Index: sw_Integer): PPointerXRef;
  1767. begin
  1768. At:=inherited At(Index);
  1769. end;
  1770. function TPointerDictionary.Compare(Key1, Key2: Pointer): sw_Integer;
  1771. var K1: PPointerXRef absolute Key1;
  1772. K2: PPointerXRef absolute Key2;
  1773. R: integer;
  1774. begin
  1775. if longint(K1^.PtrValue)<longint(K2^.PtrValue) then R:=-1 else
  1776. if longint(K1^.PtrValue)>longint(K2^.PtrValue) then R:= 1 else
  1777. R:=0;
  1778. Compare:=R;
  1779. end;
  1780. procedure TPointerDictionary.FreeItem(Item: Pointer);
  1781. begin
  1782. if Assigned(Item) then DisposePointerXRef(Item);
  1783. end;
  1784. function TPointerDictionary.SearchXRef(PtrValue: pointer): PPointerXRef;
  1785. var P: PPointerXRef;
  1786. T: TPointerXRef;
  1787. Index: sw_integer;
  1788. begin
  1789. T.PtrValue:=PtrValue;
  1790. if Search(@T,Index)=false then P:=nil else
  1791. P:=At(Index);
  1792. SearchXRef:=P;
  1793. end;
  1794. function TPointerDictionary.AddPtr(PtrValue, DataPtr: pointer): PPointerXRef;
  1795. var P: PPointerXRef;
  1796. begin
  1797. P:=SearchXRef(PtrValue);
  1798. if P=nil then
  1799. begin
  1800. P:=NewPointerXRef(PtrValue,DataPtr);
  1801. Insert(P);
  1802. {$ifdef DEBUG}
  1803. end
  1804. else
  1805. begin
  1806. if P^.DataPtr<>DataPtr then
  1807. InternalError(987654);
  1808. {$endif DEBUG}
  1809. end;
  1810. AddPtr:=P;
  1811. end;
  1812. procedure TPointerDictionary.Resolve(var P);
  1813. var X: PPointerXRef;
  1814. V: pointer;
  1815. begin
  1816. Move(P,V,SizeOf(V));
  1817. X:=SearchXRef(V);
  1818. if X=nil then V:=nil else
  1819. V:=X^.DataPtr;
  1820. Move(V,P,SizeOf(V));
  1821. end;
  1822. procedure ReadPointers(S: PStream; C: PCollection; D: PPointerDictionary);
  1823. var W,I: sw_integer;
  1824. P: pointer;
  1825. begin
  1826. S^.Read(W,SizeOf(W));
  1827. for I:=0 to W-1 do
  1828. begin
  1829. S^.Read(P,SizeOf(P));
  1830. D^.AddPtr(P,C^.At(I));
  1831. end;
  1832. end;
  1833. function LoadBrowserCol(S: PStream): boolean;
  1834. var PD: PPointerDictionary;
  1835. procedure FixupPointers;
  1836. procedure FixupReference(P: PReference); {$ifndef FPC}far;{$endif}
  1837. begin
  1838. PD^.Resolve(P^.FileName);
  1839. end;
  1840. procedure FixupSymbol(P: PSymbol); {$ifndef FPC}far;{$endif}
  1841. var I: sw_integer;
  1842. begin
  1843. PD^.Resolve(P^.DType);
  1844. PD^.Resolve(P^.VType);
  1845. PD^.Resolve(P^.Params);
  1846. if Assigned(P^.References) then
  1847. with P^.References^ do
  1848. for I:=0 to Count-1 do
  1849. FixupReference(At(I));
  1850. if Assigned(P^.Items) then
  1851. with P^.Items^ do
  1852. for I:=0 to Count-1 do
  1853. FixupSymbol(At(I));
  1854. end;
  1855. begin
  1856. Modules^.ForEach(@FixupSymbol);
  1857. end;
  1858. procedure ReadSymbolPointers(P: PSymbol); {$ifndef FPC}far;{$endif}
  1859. var I: sw_integer;
  1860. PV: pointer;
  1861. begin
  1862. S^.Read(PV, SizeOf(PV));
  1863. PD^.AddPtr(PV,P);
  1864. if Assigned(P^.Items) then
  1865. with P^.Items^ do
  1866. for I:=0 to Count-1 do
  1867. ReadSymbolPointers(At(I));
  1868. end;
  1869. begin
  1870. DisposeBrowserCol;
  1871. New(ModuleNames, Load(S^));
  1872. New(TypeNames, Load(S^));
  1873. New(Modules, Load(S^));
  1874. New(PD, Init(4000,1000));
  1875. ReadPointers(S,ModuleNames,PD);
  1876. ReadPointers(S,TypeNames,PD);
  1877. ReadPointers(S,Modules,PD);
  1878. Modules^.ForEach(@ReadSymbolPointers);
  1879. FixupPointers;
  1880. Dispose(PD, Done);
  1881. BuildObjectInfo;
  1882. LoadBrowserCol:=(S^.Status=stOK);
  1883. end;
  1884. procedure StorePointers(S: PStream; C: PCollection);
  1885. var W,I: sw_integer;
  1886. P: pointer;
  1887. begin
  1888. W:=C^.Count;
  1889. S^.Write(W,SizeOf(W));
  1890. for I:=0 to W-1 do
  1891. begin
  1892. P:=C^.At(I);
  1893. S^.Write(P,SizeOf(P));
  1894. end;
  1895. end;
  1896. function StoreBrowserCol(S: PStream) : boolean;
  1897. procedure WriteSymbolPointers(P: PSymbol); {$ifndef FPC}far;{$endif}
  1898. var I: sw_integer;
  1899. begin
  1900. S^.Write(P, SizeOf(P));
  1901. if Assigned(P^.Items) then
  1902. with P^.Items^ do
  1903. for I:=0 to Count-1 do
  1904. WriteSymbolPointers(At(I));
  1905. end;
  1906. begin
  1907. ModuleNames^.Store(S^);
  1908. TypeNames^.Store(S^);
  1909. Modules^.Store(S^);
  1910. StorePointers(S,ModuleNames);
  1911. StorePointers(S,TypeNames);
  1912. StorePointers(S,Modules);
  1913. Modules^.ForEach(@WriteSymbolPointers);
  1914. StoreBrowserCol:=(S^.Status=stOK);
  1915. end;
  1916. procedure RegisterSymbols;
  1917. begin
  1918. RegisterType(RModuleNameCollection);
  1919. RegisterType(RTypeNameCollection);
  1920. RegisterType(RReference);
  1921. RegisterType(RSymbol);
  1922. RegisterType(RObjectSymbol);
  1923. RegisterType(RSymbolCollection);
  1924. RegisterType(RSortedSymbolCollection);
  1925. RegisterType(RIDSortedSymbolCollection);
  1926. RegisterType(RObjectSymbolCollection);
  1927. RegisterType(RReferenceCollection);
  1928. RegisterType(RModuleSymbol);
  1929. end;
  1930. begin
  1931. oldexit:=exitproc;
  1932. exitproc:=@browcol_exit;
  1933. end.
  1934. {
  1935. $Log$
  1936. Revision 1.31 2002-11-27 20:04:10 peter
  1937. * tvarsym.get_push_size replaced by paramanager.push_size
  1938. Revision 1.30 2002/11/24 18:17:29 carl
  1939. * fix compilation problems after my changes to tcontsym
  1940. Revision 1.29 2002/11/20 22:48:42 pierre
  1941. * fix compilation failure for IDE
  1942. Revision 1.28 2002/09/07 14:13:40 peter
  1943. * fixed procdef access
  1944. Revision 1.27 2002/08/25 19:25:18 peter
  1945. * sym.insert_in_data removed
  1946. * symtable.insertvardata/insertconstdata added
  1947. * removed insert_in_data call from symtable.insert, it needs to be
  1948. called separatly. This allows to deref the address calculation
  1949. * procedures now calculate the parast addresses after the procedure
  1950. directives are parsed. This fixes the cdecl parast problem
  1951. * push_addr_param has an extra argument that specifies if cdecl is used
  1952. or not
  1953. Revision 1.26 2002/07/02 06:09:08 michael
  1954. + Patch from peter to fix snapshots
  1955. Revision 1.25 2002/05/18 13:34:05 peter
  1956. * readded missing revisions
  1957. Revision 1.24 2002/05/16 19:46:35 carl
  1958. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1959. + try to fix temp allocation (still in ifdef)
  1960. + generic constructor calls
  1961. + start of tassembler / tmodulebase class cleanup
  1962. }