browcol.pas 58 KB

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