browcol.pas 58 KB

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