browcol.pas 61 KB

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