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. );
  243. RTypeNameCollection: TStreamRec = (
  244. ObjType: 3002;
  245. VmtLink: Ofs(TypeOf(TTypeNameCollection)^);
  246. Load: @TTypeNameCollection.Load;
  247. Store: @TTypeNameCollection.Store
  248. );
  249. RReference: TStreamRec = (
  250. ObjType: 3003;
  251. VmtLink: Ofs(TypeOf(TReference)^);
  252. Load: @TReference.Load;
  253. Store: @TReference.Store
  254. );
  255. RSymbol: TStreamRec = (
  256. ObjType: 3004;
  257. VmtLink: Ofs(TypeOf(TSymbol)^);
  258. Load: @TSymbol.Load;
  259. Store: @TSymbol.Store
  260. );
  261. RObjectSymbol: TStreamRec = (
  262. ObjType: 3005;
  263. VmtLink: Ofs(TypeOf(TObjectSymbol)^);
  264. Load: @TObjectSymbol.Load;
  265. Store: @TObjectSymbol.Store
  266. );
  267. RSymbolCollection: TStreamRec = (
  268. ObjType: 3006;
  269. VmtLink: Ofs(TypeOf(TSymbolCollection)^);
  270. Load: @TSymbolCollection.Load;
  271. Store: @TSymbolCollection.Store
  272. );
  273. RSortedSymbolCollection: TStreamRec = (
  274. ObjType: 3007;
  275. VmtLink: Ofs(TypeOf(TSortedSymbolCollection)^);
  276. Load: @TSortedSymbolCollection.Load;
  277. Store: @TSortedSymbolCollection.Store
  278. );
  279. RIDSortedSymbolCollection: TStreamRec = (
  280. ObjType: 3008;
  281. VmtLink: Ofs(TypeOf(TIDSortedSymbolCollection)^);
  282. Load: @TIDSortedSymbolCollection.Load;
  283. Store: @TIDSortedSymbolCollection.Store
  284. );
  285. RObjectSymbolCollection: TStreamRec = (
  286. ObjType: 3009;
  287. VmtLink: Ofs(TypeOf(TObjectSymbolCollection)^);
  288. Load: @TObjectSymbolCollection.Load;
  289. Store: @TObjectSymbolCollection.Store
  290. );
  291. RReferenceCollection: TStreamRec = (
  292. ObjType: 3010;
  293. VmtLink: Ofs(TypeOf(TReferenceCollection)^);
  294. Load: @TReferenceCollection.Load;
  295. Store: @TReferenceCollection.Store
  296. );
  297. RModuleSymbol: TStreamRec = (
  298. ObjType: 3011;
  299. VmtLink: Ofs(TypeOf(TModuleSymbol)^);
  300. Load: @TModuleSymbol.Load;
  301. Store: @TModuleSymbol.Store
  302. );
  303. SymbolCount : longint = 0;
  304. Current_moduleIndex : longint = 0;
  305. {****************************************************************************
  306. Helpers
  307. ****************************************************************************}
  308. function GetStr(P: PString): string;
  309. begin
  310. if P=nil then
  311. GetStr:=''
  312. else
  313. GetStr:=P^;
  314. end;
  315. function IntToStr(L: longint): string;
  316. var S: string;
  317. begin
  318. Str(L,S);
  319. IntToStr:=S;
  320. end;
  321. function UpcaseStr(S: string): string;
  322. var I: integer;
  323. begin
  324. for I:=1 to length(S) do
  325. S[I]:=Upcase(S[I]);
  326. UpcaseStr:=S;
  327. end;
  328. function FloatToStr(E: extended): string;
  329. var S: string;
  330. begin
  331. Str(E:0:24,S);
  332. if Pos('.',S)>0 then
  333. begin
  334. while (length(S)>0) and (S[length(S)]='0') do
  335. Delete(S,length(S),1);
  336. if (length(S)>0) and (S[length(S)]='.') then
  337. Delete(S,length(S),1);
  338. end;
  339. if S='' then S:='0';
  340. FloatToStr:=S;
  341. end;
  342. {****************************************************************************
  343. TStoreCollection
  344. ****************************************************************************}
  345. function TStoreCollection.Add(const S: string): PString;
  346. var P: PString;
  347. Index: Sw_integer;
  348. begin
  349. if S='' then P:=nil else
  350. if Search(@S,Index) then P:=At(Index) else
  351. begin
  352. P:=NewStr(S);
  353. Insert(P);
  354. end;
  355. Add:=P;
  356. end;
  357. {****************************************************************************
  358. TSymbolCollection
  359. ****************************************************************************}
  360. constructor TSymbolCollection.Init(ALimit, ADelta: Integer);
  361. begin
  362. inherited Init(ALimit,ADelta);
  363. Duplicates:=true;
  364. end;
  365. function TSymbolCollection.At(Index: Sw_Integer): PSymbol;
  366. begin
  367. At:=inherited At(Index);
  368. end;
  369. procedure TSymbolCollection.Insert(Item: Pointer);
  370. begin
  371. TCollection.Insert(Item);
  372. end;
  373. function TSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  374. begin
  375. Idx:=-1;
  376. LookUp:='';
  377. end;
  378. {****************************************************************************
  379. TReferenceCollection
  380. ****************************************************************************}
  381. function TReferenceCollection.At(Index: Sw_Integer): PReference;
  382. begin
  383. At:=inherited At(Index);
  384. end;
  385. {****************************************************************************
  386. TSortedSymbolCollection
  387. ****************************************************************************}
  388. function TSortedSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  389. var K1: PSymbol absolute Key1;
  390. K2: PSymbol absolute Key2;
  391. R: Sw_integer;
  392. S1,S2: string;
  393. begin
  394. S1:=Upper(K1^.GetName);
  395. S2:=Upper(K2^.GetName);
  396. if S1<S2 then R:=-1 else
  397. if S1>S2 then R:=1 else
  398. if K1^.TypeID=K2^.TypeID then
  399. R:=0
  400. else
  401. begin
  402. S1:=K1^.GetName;
  403. S2:=K2^.GetName;
  404. if S1<S2 then R:=-1 else
  405. if S1>S2 then R:=1 else
  406. if K1^.TypeID<K2^.TypeID then R:=-1 else
  407. if K1^.TypeID>K2^.TypeID then R:= 1 else
  408. begin
  409. { Handle overloaded functions }
  410. if (K1^.Typ=procsym) then
  411. begin
  412. S1:=K1^.GetText;
  413. S2:=K2^.GetText;
  414. if S1<S2 then R:=-1 else
  415. if S1>S2 then R:=1 else
  416. R:=0;
  417. end
  418. else
  419. R:=0;
  420. end
  421. end;
  422. Compare:=R;
  423. end;
  424. procedure TSortedSymbolCollection.Insert(Item: Pointer);
  425. begin
  426. TSortedCollection.Insert(Item);
  427. end;
  428. function TSortedSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  429. var OLI,ORI,Left,Right,Mid: integer;
  430. LeftP,RightP,MidP: PSymbol;
  431. LeftS,MidS,RightS: string;
  432. FoundS: string;
  433. UpS : string;
  434. begin
  435. Idx:=-1; FoundS:='';
  436. Left:=0; Right:=Count-1;
  437. UpS:=Upper(S);
  438. if Left<Right then
  439. begin
  440. while (Left<Right) do
  441. begin
  442. OLI:=Left; ORI:=Right;
  443. Mid:=Left+(Right-Left) div 2;
  444. MidP:=At(Mid);
  445. {$ifdef DEBUG}
  446. LeftP:=At(Left); RightP:=At(Right);
  447. LeftS:=Upper(LeftP^.GetName);
  448. RightS:=Upper(RightP^.GetName);
  449. {$endif DEBUG}
  450. MidS:=Upper(MidP^.GetName);
  451. if copy(MidS,1,length(UpS))=UpS then
  452. begin
  453. Idx:=Mid;
  454. FoundS:=MidS;
  455. end;
  456. { else}
  457. if UpS<MidS then
  458. Right:=Mid
  459. else
  460. Left:=Mid;
  461. if (OLI=Left) and (ORI=Right) then
  462. begin
  463. if idX<>-1 then
  464. break;
  465. if Mid=Left then
  466. begin
  467. RightP:=At(Right);
  468. RightS:=Upper(RightP^.GetName);
  469. if copy(RightS,1,length(UpS))=UpS then
  470. begin
  471. Idx:=Right;
  472. FoundS:=RightS;
  473. end;
  474. end;
  475. if Mid=Right then
  476. begin
  477. LeftP:=At(Left);
  478. LeftS:=Upper(LeftP^.GetName);
  479. if copy(LeftS,1,length(UpS))=UpS then
  480. begin
  481. Idx:=Left;
  482. FoundS:=LeftS;
  483. end;
  484. end;
  485. Break;
  486. end;
  487. end;
  488. end;
  489. LookUp:=FoundS;
  490. end;
  491. {****************************************************************************
  492. TIDSortedSymbolCollection
  493. ****************************************************************************}
  494. function TIDSortedSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  495. var K1: PSymbol absolute Key1;
  496. K2: PSymbol absolute Key2;
  497. R: Sw_integer;
  498. begin
  499. if K1^.TypeID<K2^.TypeID then R:=-1 else
  500. if K1^.TypeID>K2^.TypeID then R:= 1 else
  501. R:=0;
  502. Compare:=R;
  503. end;
  504. procedure TIDSortedSymbolCollection.Insert(Item: Pointer);
  505. begin
  506. TSortedCollection.Insert(Item);
  507. end;
  508. function TIDSortedSymbolCollection.SearchSymbolByID(AID: longint): PSymbol;
  509. var S: TSymbol;
  510. Index: sw_integer;
  511. P: PSymbol;
  512. begin
  513. S.TypeID:=AID;
  514. if Search(@S,Index)=false then P:=nil else
  515. P:=At(Index);
  516. SearchSymbolByID:=P;
  517. end;
  518. {****************************************************************************
  519. TObjectSymbolCollection
  520. ****************************************************************************}
  521. function TObjectSymbolCollection.At(Index: Sw_Integer): PObjectSymbol;
  522. begin
  523. At:=inherited At(Index);
  524. end;
  525. constructor TObjectSymbolCollection.Init(ALimit, ADelta: Integer);
  526. begin
  527. inherited Init(ALimit,ADelta);
  528. end;
  529. function TObjectSymbolCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  530. var K1: PObjectSymbol absolute Key1;
  531. K2: PObjectSymbol absolute Key2;
  532. R: Sw_integer;
  533. S1,S2: string;
  534. begin
  535. S1:=Upper(K1^.GetName);
  536. S2:=Upper(K2^.GetName);
  537. if S1<S2 then R:=-1 else
  538. if S1>S2 then R:=1 else
  539. { make sure that we distinguish between different objects with the same name }
  540. if Ptrint(K1^.Symbol)<Ptrint(K2^.Symbol) then R:=-1 else
  541. if Ptrint(K1^.Symbol)>Ptrint(K2^.Symbol) then R:= 1 else
  542. R:=0;
  543. Compare:=R;
  544. end;
  545. function TObjectSymbolCollection.LookUp(const S: string; var Idx: sw_integer): string;
  546. var OLI,ORI,Left,Right,Mid: integer;
  547. {LeftP,RightP,}MidP: PObjectSymbol;
  548. {LeftS,RightS,}MidS: string;
  549. FoundS: string;
  550. UpS : string;
  551. begin
  552. Idx:=-1; FoundS:='';
  553. Left:=0; Right:=Count-1;
  554. UpS:=Upper(S);
  555. if Left<Right then
  556. begin
  557. while (Left<Right) do
  558. begin
  559. OLI:=Left; ORI:=Right;
  560. Mid:=Left+(Right-Left) div 2;
  561. {LeftP:=At(Left);
  562. LeftS:=Upper(LeftP^.GetName);}
  563. MidP:=At(Mid);
  564. MidS:=Upper(MidP^.GetName);
  565. {RightP:=At(Right);
  566. RightS:=Upper(RightP^.GetName);}
  567. if copy(MidS,1,length(UpS))=UpS then
  568. begin
  569. Idx:=Mid;
  570. FoundS:=MidS;
  571. end;
  572. { else}
  573. if UpS<MidS then
  574. Right:=Mid
  575. else
  576. Left:=Mid;
  577. if (OLI=Left) and (ORI=Right) then
  578. Break;
  579. end;
  580. end;
  581. LookUp:=FoundS;
  582. end;
  583. {****************************************************************************
  584. TReference
  585. ****************************************************************************}
  586. constructor TReference.Init(AFileName: PString; ALine, AColumn: Sw_integer);
  587. begin
  588. inherited Init;
  589. FileName:=AFileName;
  590. Position.X:=AColumn;
  591. Position.Y:=ALine;
  592. end;
  593. function TReference.GetFileName: string;
  594. begin
  595. GetFileName:=GetStr(FileName);
  596. end;
  597. destructor TReference.Done;
  598. begin
  599. inherited Done;
  600. end;
  601. constructor TReference.Load(var S: TStream);
  602. begin
  603. S.Read(Position, SizeOf(Position));
  604. { --- items needing fixup --- }
  605. S.Read(FileName, SizeOf(FileName)); { ->ModulesNames^.Item }
  606. end;
  607. procedure TReference.Store(var S: TStream);
  608. begin
  609. S.Write(Position, SizeOf(Position));
  610. { --- items needing fixup --- }
  611. S.Write(FileName, SizeOf(FileName));
  612. end;
  613. {****************************************************************************
  614. TSymbol
  615. ****************************************************************************}
  616. constructor TSymbol.Init(const AName: string; ATyp: tsymtyp; AParams: string; AMemInfo: PSymbolMemInfo);
  617. begin
  618. inherited Init;
  619. inc(SymbolCount);
  620. VarSpez:=vs_value;
  621. VarOptions:=[];
  622. Name:=NewStr(AName); Typ:=ATyp;
  623. if AMemInfo<>nil then
  624. SetMemInfo(AMemInfo^);
  625. New(References, Init(20,50));
  626. if ATyp in RecordTypes then
  627. begin
  628. Items:=New(PSortedSymbolCollection, Init(50,100));
  629. end;
  630. end;
  631. procedure TSymbol.SetVarSpez(const AVarSpez : TVarSpez);
  632. begin
  633. VarSpez:=AVarSpez;
  634. end;
  635. procedure TSymbol.SetVarOptions(const AVarOptions : TVarOptions);
  636. begin
  637. VarOptions:=AVarOptions;
  638. end;
  639. procedure TSymbol.SetMemInfo(const AMemInfo: TSymbolMemInfo);
  640. begin
  641. if MemInfo=nil then New(MemInfo);
  642. Move(AMemInfo,MemInfo^,SizeOf(MemInfo^));
  643. Flags:=Flags or sfHasMemInfo;
  644. end;
  645. function TSymbol.GetReferenceCount: Sw_integer;
  646. var Count: Sw_integer;
  647. begin
  648. if References=nil then Count:=0 else
  649. Count:=References^.Count;
  650. GetReferenceCount:=Count;
  651. end;
  652. function TSymbol.GetReference(Index: Sw_integer): PReference;
  653. begin
  654. GetReference:=References^.At(Index);
  655. end;
  656. function TSymbol.GetItemCount: Sw_integer;
  657. var Count: Sw_integer;
  658. begin
  659. if Items=nil then Count:=0 else
  660. Count:=Items^.Count;
  661. GetItemCount:=Count;
  662. end;
  663. function TSymbol.GetItem(Index: Sw_integer): PSymbol;
  664. begin
  665. GetItem:=Items^.At(Index);
  666. end;
  667. function TSymbol.GetName: string;
  668. begin
  669. GetName:=GetStr(Name);
  670. end;
  671. function TSymbol.GetText: string;
  672. var S: string;
  673. begin
  674. S:=GetTypeName;
  675. if length(S)>SymbolTypLen then
  676. S:=Copy(S,1,SymbolTypLen)
  677. else
  678. begin
  679. while length(S)<SymbolTypLen do
  680. S:=S+' ';
  681. end;
  682. S:=S+' '+GetName;
  683. if (Flags and sfRecord)<>0 then
  684. S:=S+' = record'
  685. else
  686. if (Flags and sfObject)<>0 then
  687. begin
  688. S:=S+' = ';
  689. if (Flags and sfClass)<>0 then
  690. S:=S+'class'
  691. else
  692. S:=S+'object';
  693. if Ancestor<>nil then
  694. S:=S+'('+Ancestor^.GetName+')';
  695. end
  696. else
  697. begin
  698. if Assigned(DType) then
  699. S:=S+' = '+DType^;
  700. if Assigned(Params) then
  701. S:=S+'('+Params^+')';
  702. if Assigned(VType) then
  703. S:=S+': '+VType^;
  704. end;
  705. if Typ=ProcSym then
  706. S:=S+';';
  707. GetText:=S;
  708. end;
  709. function TSymbol.GetTypeName: string;
  710. var S: string;
  711. begin
  712. case Typ of
  713. abstractsym : S:='abst';
  714. fieldvarsym : S:='member';
  715. staticvarsym,
  716. localvarsym,
  717. paravarsym :
  718. begin
  719. if (vo_is_hidden_para in varoptions) then
  720. S:='hidden'
  721. else
  722. S:='var';
  723. end;
  724. typesym : S:='type';
  725. procsym : if VType=nil then
  726. S:='proc'
  727. else
  728. S:='func';
  729. unitsym : S:='unit';
  730. constsym : S:='const';
  731. enumsym : S:='enum';
  732. errorsym : S:='error';
  733. syssym : S:='sys';
  734. labelsym : S:='label';
  735. absolutevarsym :
  736. if (vo_is_funcret in varoptions) then
  737. S:='ret'
  738. else
  739. S:='abs';
  740. propertysym : S:='prop';
  741. macrosym : S:='macro';
  742. else S:='';
  743. end;
  744. GetTypeName:=S;
  745. end;
  746. destructor TSymbol.Done;
  747. begin
  748. if assigned(MemInfo) then
  749. Dispose(MemInfo);
  750. if assigned(References) then
  751. Dispose(References, Done);
  752. if assigned(Items) then
  753. Dispose(Items, Done);
  754. if assigned(Name) then
  755. DisposeStr(Name);
  756. { if assigned(Params) then
  757. DisposeStr(Params); in TypeNames
  758. if assigned(VType) then
  759. DisposeStr(VType);
  760. if assigned(DType) then
  761. DisposeStr(DType);
  762. if assigned(Ancestor) then
  763. DisposeStr(Ancestor);}
  764. dec(SymbolCount);
  765. inherited Done;
  766. end;
  767. constructor TSymbol.Load(var S: TStream);
  768. var MI: TSymbolMemInfo;
  769. W: word;
  770. begin
  771. TObject.Init;
  772. inc(SymbolCount);
  773. S.Read(Typ,SizeOf(Typ));
  774. case Typ of
  775. abstractsym,
  776. absolutevarsym,
  777. staticvarsym,
  778. localvarsym,
  779. paravarsym :
  780. begin
  781. S.Read(VarSpez,SizeOf(VarSpez));
  782. S.Read(VarOptions,SizeOf(VarOptions));
  783. end;
  784. else
  785. begin
  786. VarSpez:=vs_value;
  787. VarOptions:=[];
  788. end;
  789. end;
  790. S.Read(TypeID, SizeOf(TypeID));
  791. S.Read(RelatedTypeID, SizeOf(RelatedTypeID));
  792. S.Read(Flags, SizeOf(Flags));
  793. Name:=S.ReadStr;
  794. if (Flags and sfHasMemInfo)<>0 then
  795. begin
  796. S.Read(MI,SizeOf(MI));
  797. SetMemInfo(MI);
  798. end;
  799. W:=0;
  800. S.Read(W,SizeOf(W));
  801. if (W and 1)<>0 then
  802. New(References, Load(S));
  803. if (W and 2)<>0 then
  804. New(Items, Load(S));
  805. { --- items needing fixup --- }
  806. S.Read(DType, SizeOf(DType));
  807. S.Read(VType, SizeOf(VType));
  808. S.Read(Params, SizeOf(Params));
  809. end;
  810. procedure TSymbol.Store(var S: TStream);
  811. var W: word;
  812. begin
  813. S.Write(Typ,SizeOf(Typ));
  814. case Typ of
  815. abstractsym,
  816. absolutevarsym,
  817. staticvarsym,
  818. localvarsym,
  819. paravarsym :
  820. begin
  821. S.Write(VarSpez,SizeOf(VarSpez));
  822. S.Write(VarOptions,SizeOf(VarOptions));
  823. end;
  824. end;
  825. S.Write(TypeID, SizeOf(TypeID));
  826. S.Write(RelatedTypeID, SizeOf(RelatedTypeID));
  827. S.Write(Flags, SizeOf(Flags));
  828. S.WriteStr(Name);
  829. if (Flags and sfHasMemInfo)<>0 then
  830. S.Write(MemInfo^,SizeOf(MemInfo^));
  831. W:=0;
  832. if Assigned(References) then W:=W or 1;
  833. if Assigned(Items) then W:=W or 2;
  834. S.Write(W,SizeOf(W));
  835. if Assigned(References) then References^.Store(S);
  836. if Assigned(Items) then Items^.Store(S);
  837. { --- items needing fixup --- }
  838. S.Write(DType, SizeOf(DType));
  839. S.Write(VType, SizeOf(VType));
  840. S.Write(Params, SizeOf(Params));
  841. end;
  842. constructor TExport.Init(const AName: string; AIndex: longint; ASymbol: PSymbol);
  843. begin
  844. inherited Init;
  845. Name:=NewStr(AName); Index:=AIndex;
  846. Symbol:=ASymbol;
  847. end;
  848. function TExport.GetDisplayText: string;
  849. var S: string;
  850. begin
  851. S:=GetStr(Name)+' '+IntToStr(Index);
  852. if Assigned(Symbol) and (UpcaseStr(Symbol^.GetName)<>UpcaseStr(GetStr(Name))) then
  853. S:=S+' ('+Symbol^.GetName+')';
  854. GetDisplayText:=S;
  855. end;
  856. destructor TExport.Done;
  857. begin
  858. if Assigned(Name) then DisposeStr(Name);
  859. inherited Done;
  860. end;
  861. constructor TImport.Init(const ALibName, AFuncName,ARealName: string; AIndex: longint);
  862. begin
  863. inherited Init;
  864. LibName:=NewStr(ALibName);
  865. FuncName:=NewStr(AFuncName); RealName:=NewStr(ARealName);
  866. Index:=AIndex;
  867. end;
  868. function TImport.GetDisplayText: string;
  869. var S: string;
  870. begin
  871. S:=GetStr(RealName);
  872. if Assigned(FuncName) then S:=GetStr(FuncName)+' ('+S+')';
  873. if S='' then S:=IntToStr(Index);
  874. S:=GetStr(LibName)+' '+S;
  875. GetDisplayText:=S;
  876. end;
  877. destructor TImport.Done;
  878. begin
  879. if Assigned(LibName) then DisposeStr(LibName);
  880. if Assigned(FuncName) then DisposeStr(FuncName);
  881. if Assigned(RealName) then DisposeStr(RealName);
  882. inherited Done;
  883. end;
  884. function TImportCollection.At(Index: sw_Integer): PImport;
  885. begin
  886. At:=inherited At(Index);
  887. end;
  888. function TImportCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  889. var K1: PImport absolute Key1;
  890. K2: PImport absolute Key2;
  891. S1: string;
  892. S2: string;
  893. R: sw_integer;
  894. begin
  895. if (K1^.RealName=nil) and (K2^.RealName<>nil) then R:= 1 else
  896. if (K1^.RealName<>nil) and (K2^.RealName=nil) then R:=-1 else
  897. if (K1^.RealName=nil) and (K2^.RealName=nil) then
  898. begin
  899. if K1^.Index<K2^.Index then R:=-1 else
  900. if K1^.Index>K2^.Index then R:= 1 else
  901. R:=0;
  902. end
  903. else
  904. begin
  905. if K1^.FuncName=nil then S1:=GetStr(K1^.RealName) else S1:=GetStr(K1^.FuncName);
  906. if K2^.FuncName=nil then S2:=GetStr(K2^.RealName) else S2:=GetStr(K2^.FuncName);
  907. S1:=UpcaseStr(S1); S2:=UpcaseStr(S2);
  908. if S1<S2 then R:=-1 else
  909. if S1>S2 then R:= 1 else
  910. R:=0;
  911. end;
  912. Compare:=R;
  913. end;
  914. function TExportCollection.At(Index: sw_Integer): PExport;
  915. begin
  916. At:=inherited At(Index);
  917. end;
  918. function TExportCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  919. var K1: PExport absolute Key1;
  920. K2: PExport absolute Key2;
  921. S1: string;
  922. S2: string;
  923. R: sw_integer;
  924. begin
  925. S1:=UpcaseStr(GetStr(K1^.Name)); S2:=UpcaseStr(GetStr(K2^.Name));
  926. if S1<S2 then R:=-1 else
  927. if S1>S2 then R:= 1 else
  928. R:=0;
  929. Compare:=R;
  930. end;
  931. constructor TModuleSymbol.Init(const AName, AMainSource: string);
  932. begin
  933. inherited Init(AName,unitsym,'',nil);
  934. MainSource:=NewStr(AMainSource);
  935. end;
  936. procedure TModuleSymbol.SetLoadedFrom(const AModuleName: string);
  937. begin
  938. SetStr(LoadedFrom,AModuleName);
  939. end;
  940. procedure TModuleSymbol.AddUsedUnit(P: PSymbol);
  941. begin
  942. if Assigned(UsedUnits)=false then
  943. New(UsedUnits, Init(10,10));
  944. UsedUnits^.Insert(P);
  945. end;
  946. procedure TModuleSymbol.AddDependentUnit(P: PSymbol);
  947. begin
  948. if Assigned(DependentUnits)=false then
  949. New(DependentUnits, Init(10,10));
  950. DependentUnits^.Insert(P);
  951. end;
  952. procedure TModuleSymbol.AddSourceFile(const Path: string);
  953. begin
  954. if Assigned(SourceFiles)=false then
  955. New(SourceFiles, Init(10,10));
  956. sourcefiles^.Insert(NewStr(Path));
  957. end;
  958. destructor TModuleSymbol.Done;
  959. begin
  960. if Assigned(MainSource) then DisposeStr(MainSource);
  961. if assigned(Exports_) then
  962. Dispose(Exports_, Done);
  963. if Assigned(Imports) then
  964. Dispose(Imports, Done);
  965. if Assigned(LoadedFrom) then
  966. DisposeStr(LoadedFrom);
  967. if Assigned(UsedUnits) then
  968. begin
  969. UsedUnits^.DeleteAll;
  970. Dispose(UsedUnits, Done);
  971. end;
  972. if Assigned(DependentUnits) then
  973. begin
  974. DependentUnits^.DeleteAll;
  975. Dispose(DependentUnits, Done);
  976. end;
  977. if Assigned(SourceFiles) then Dispose(SourceFiles, Done);
  978. inherited Done;
  979. end;
  980. constructor TObjectSymbol.Init(AParent: PObjectSymbol; ASymbol: PSymbol);
  981. begin
  982. inherited Init;
  983. Parent:=AParent;
  984. Symbol:=ASymbol;
  985. end;
  986. constructor TObjectSymbol.InitName(const AName: string);
  987. begin
  988. inherited Init;
  989. Name:=NewStr(AName);
  990. end;
  991. function TObjectSymbol.GetName: string;
  992. begin
  993. if Name<>nil then
  994. GetName:=Name^
  995. else
  996. GetName:=Symbol^.GetName;
  997. end;
  998. function TObjectSymbol.GetDescendantCount: sw_integer;
  999. var Count: sw_integer;
  1000. begin
  1001. if Descendants=nil then Count:=0 else
  1002. Count:=Descendants^.Count;
  1003. GetDescendantCount:=Count;
  1004. end;
  1005. function TObjectSymbol.GetDescendant(Index: sw_integer): PObjectSymbol;
  1006. begin
  1007. GetDescendant:=Descendants^.At(Index);
  1008. end;
  1009. procedure TObjectSymbol.AddDescendant(P: PObjectSymbol);
  1010. begin
  1011. if Descendants=nil then
  1012. New(Descendants, Init(50,10));
  1013. Descendants^.Insert(P);
  1014. end;
  1015. destructor TObjectSymbol.Done;
  1016. begin
  1017. if Assigned(Name) then DisposeStr(Name); Name:=nil;
  1018. if Assigned(Descendants) then Dispose(Descendants, Done); Descendants:=nil;
  1019. inherited Done;
  1020. end;
  1021. constructor TObjectSymbol.Load(var S: TStream);
  1022. begin
  1023. end;
  1024. procedure TObjectSymbol.Store(S: TStream);
  1025. begin
  1026. end;
  1027. {****************************************************************************
  1028. TSourceFile
  1029. ****************************************************************************}
  1030. constructor TSourceFile.Init(ASourceFileName, AObjFileName, APPUFileName: string);
  1031. begin
  1032. inherited Init;
  1033. SourceFileName:=NewStr(ASourceFileName);
  1034. ObjFileName:=NewStr(AObjFileName);
  1035. PPUFileName:=NewStr(APPUFileName);
  1036. end;
  1037. destructor TSourceFile.Done;
  1038. begin
  1039. if assigned(SourceFileName) then DisposeStr(SourceFileName);
  1040. if assigned(ObjFileName) then DisposeStr(ObjFileName);
  1041. if assigned(PPUFileName) then DisposeStr(PPUFileName);
  1042. inherited Done;
  1043. end;
  1044. function TSourceFile.GetSourceFilename: string;
  1045. begin
  1046. GetSourceFilename:=GetStr(SourceFileName);
  1047. end;
  1048. function TSourceFile.GetObjFileName: string;
  1049. begin
  1050. GetObjFilename:=GetStr(ObjFileName);
  1051. end;
  1052. function TSourceFile.GetPPUFileName: string;
  1053. begin
  1054. GetPPUFilename:=GetStr(PPUFileName);
  1055. end;
  1056. function TSourceFileCollection.At(Index: sw_Integer): PSourceFile;
  1057. begin
  1058. At:=inherited At(Index);
  1059. end;
  1060. {*****************************************************************************
  1061. Main Routines
  1062. *****************************************************************************}
  1063. procedure DisposeBrowserCol;
  1064. begin
  1065. if assigned(Modules) then
  1066. begin
  1067. dispose(Modules,Done);
  1068. Modules:=nil;
  1069. end;
  1070. if assigned(ModuleNames) then
  1071. begin
  1072. dispose(ModuleNames,Done);
  1073. ModuleNames:=nil;
  1074. end;
  1075. if assigned(TypeNames) then
  1076. begin
  1077. dispose(TypeNames,Done);
  1078. TypeNames:=nil;
  1079. end;
  1080. if assigned(ObjectTree) then
  1081. begin
  1082. Dispose(ObjectTree, Done);
  1083. ObjectTree:=nil;
  1084. end;
  1085. end;
  1086. procedure NewBrowserCol;
  1087. begin
  1088. New(Modules, Init(50,50));
  1089. New(ModuleNames, Init(50,50));
  1090. New(TypeNames, Init(1000,5000));
  1091. end;
  1092. procedure ProcessSymTable(OwnerSym: PSymbol; var Owner: PSymbolCollection; Table: TSymTable);
  1093. var I,J: longint;
  1094. Sym: TSym;
  1095. pd : TProcDef;
  1096. Symbol: PSymbol;
  1097. Reference: PReference;
  1098. inputfile : Tinputfile;
  1099. Ref : TRefItem;
  1100. DefPos : TFilePosInfo;
  1101. procedure SetVType(Symbol: PSymbol; VType: string);
  1102. begin
  1103. Symbol^.VType:=TypeNames^.Add(VType);
  1104. end;
  1105. procedure SetDType(Symbol: PSymbol; DType: string);
  1106. begin
  1107. Symbol^.DType:=TypeNames^.Add(DType);
  1108. end;
  1109. function GetDefinitionStr(def: tdef): string; forward;
  1110. function GetEnumDefStr(def: tenumdef): string;
  1111. var Name: string;
  1112. esym: tenumsym;
  1113. Count: integer;
  1114. begin
  1115. Name:='(';
  1116. esym:=tenumsym(def.Firstenum); Count:=0;
  1117. while (esym<>nil) do
  1118. begin
  1119. if Count>0 then
  1120. Name:=Name+', ';
  1121. Name:=Name+esym.name;
  1122. esym:=esym.nextenum;
  1123. Inc(Count);
  1124. end;
  1125. Name:=Name+')';
  1126. GetEnumDefStr:=Name;
  1127. end;
  1128. function GetArrayDefStr(def: tarraydef): string;
  1129. var Name: string;
  1130. begin
  1131. Name:='array ['+IntToStr(def.lowrange)+'..'+IntToStr(def.highrange)+'] of ';
  1132. if assigned(def.elementdef) then
  1133. Name:=Name+GetDefinitionStr(def.elementdef);
  1134. GetArrayDefStr:=Name;
  1135. end;
  1136. function GetFileDefStr(def: tfiledef): string;
  1137. var Name: string;
  1138. begin
  1139. Name:='';
  1140. case def.filetyp of
  1141. ft_text : Name:='text';
  1142. ft_untyped : Name:='file';
  1143. ft_typed : Name:='file of '+GetDefinitionStr(def.typedfiledef);
  1144. end;
  1145. GetFileDefStr:=Name;
  1146. end;
  1147. function GetStringDefStr(def: tstringdef): string;
  1148. var Name: string;
  1149. begin
  1150. Name:='';
  1151. case def.stringtype of
  1152. st_shortstring :
  1153. if def.len=255 then
  1154. Name:='shortstring'
  1155. else
  1156. Name:='string['+IntToStr(def.len)+']';
  1157. st_longstring :
  1158. Name:='longstring';
  1159. st_ansistring :
  1160. Name:='ansistring';
  1161. st_widestring :
  1162. Name:='widestring';
  1163. st_unicodestring :
  1164. Name:='unicodestring';
  1165. else ;
  1166. end;
  1167. GetStringDefStr:=Name;
  1168. end;
  1169. function retdefassigned(def: tabstractprocdef): boolean;
  1170. var OK: boolean;
  1171. begin
  1172. OK:=false;
  1173. if assigned(def.returndef) then
  1174. if UpcaseStr(GetDefinitionStr(def.returndef))<>'VOID' then
  1175. OK:=true;
  1176. retdefassigned:=OK;
  1177. end;
  1178. function GetAbsProcParmDefStr(def: tabstractprocdef): string;
  1179. var Name: string;
  1180. dc: tabstractvarsym;
  1181. i,
  1182. Count: integer;
  1183. CurName: string;
  1184. begin
  1185. Name:='';
  1186. Count:=0;
  1187. for i:=0 to def.paras.count-1 do
  1188. begin
  1189. dc:=tabstractvarsym(def.paras[i]);
  1190. if not (vo_is_hidden_para in dc.VarOptions) then
  1191. begin
  1192. CurName:='';
  1193. if assigned(dc.vardef) then
  1194. CurName:=': '+GetDefinitionStr(dc.vardef);
  1195. CurName:=dc.RealName+CurName;
  1196. case dc.varspez of
  1197. vs_Value : ;
  1198. vs_Const : CurName:='const '+CurName;
  1199. vs_Var : CurName:='var '+CurName;
  1200. vs_Out : CurName:='out '+CurName;
  1201. end;
  1202. if Count>0 then
  1203. CurName:='; '+CurName;
  1204. Name:=Name+CurName;
  1205. Inc(Count);
  1206. end;
  1207. end;
  1208. GetAbsProcParmDefStr:=Name;
  1209. end;
  1210. function GetAbsProcDefStr(def: tabstractprocdef): string;
  1211. var Name: string;
  1212. begin
  1213. Name:=GetAbsProcParmDefStr(def);
  1214. if Name<>'' then Name:='('+Name+')';
  1215. if retdefassigned(def) then
  1216. Name:='function'+Name+': '+GetDefinitionStr(def.returndef)+';'
  1217. else
  1218. Name:='procedure'+Name+';';
  1219. GetAbsProcDefStr:=Name;
  1220. end;
  1221. function GetProcDefStr(def: tprocdef): string;
  1222. var DName: string;
  1223. {J: integer;}
  1224. begin
  1225. { DName:='';
  1226. if assigned(def) then
  1227. begin
  1228. if assigned(def.parast) then
  1229. begin
  1230. with def.parast^ do
  1231. for J:=1 to number_symbols do
  1232. begin
  1233. if J<>1 then DName:=DName+', ';
  1234. ParSym:=GetsymNr(J);
  1235. if ParSym=nil then Break;
  1236. DName:=DName+ParSym^.Name;
  1237. end;
  1238. end
  1239. end;}
  1240. DName:=GetAbsProcDefStr(def);
  1241. GetProcDefStr:=DName;
  1242. end;
  1243. function GetProcVarDefStr(def: tprocvardef): string;
  1244. begin
  1245. GetProcVarDefStr:=GetAbsProcDefStr(def);
  1246. end;
  1247. function GetSetDefStr(def: tsetdef): string;
  1248. var Name: string;
  1249. begin
  1250. Name:='';
  1251. case def.settype of
  1252. normset : Name:='set';
  1253. smallset : Name:='set';
  1254. varset : Name:='varset';
  1255. end;
  1256. Name:=Name+' of ';
  1257. Name:=Name+GetDefinitionStr(def.elementdef);
  1258. GetSetDefStr:=Name;
  1259. end;
  1260. function GetPointerDefStr(def: tpointerdef): string;
  1261. begin
  1262. GetPointerDefStr:='^'+GetDefinitionStr(def.pointeddef);
  1263. end;
  1264. function GetDefinitionStr(def: tdef): string;
  1265. var Name: string;
  1266. begin
  1267. Name:='';
  1268. if def<>nil then
  1269. begin
  1270. if assigned(def.typesym) then
  1271. Name:=def.typesym.name;
  1272. if Name='' then
  1273. case def.typ of
  1274. arraydef :
  1275. Name:=GetArrayDefStr(tarraydef(def));
  1276. stringdef :
  1277. Name:=GetStringDefStr(tstringdef(def));
  1278. enumdef :
  1279. Name:=GetEnumDefStr(tenumdef(def));
  1280. procdef :
  1281. Name:=GetProcDefStr(tprocdef(def));
  1282. procvardef :
  1283. Name:=GetProcVarDefStr(tprocvardef(def));
  1284. filedef :
  1285. Name:=GetFileDefStr(tfiledef(def));
  1286. setdef :
  1287. Name:=GetSetDefStr(tsetdef(def));
  1288. end;
  1289. end;
  1290. GetDefinitionStr:=Name;
  1291. end;
  1292. function GetEnumItemName(Sym: tenumsym): string;
  1293. var Name: string;
  1294. {ES: tenumsym;}
  1295. begin
  1296. Name:='';
  1297. if assigned(sym) and assigned(sym.definition) then
  1298. if assigned(sym.definition.typesym) then
  1299. begin
  1300. { ES:=sym.definition.First;
  1301. while (ES<>nil) and (ES^.Value<>sym.value) do
  1302. ES:=ES^.next;
  1303. if assigned(es) and (es^.value=sym.value) then
  1304. Name:=}
  1305. Name:=sym.definition.typesym.name;
  1306. if Name<>'' then
  1307. Name:=Name+'('+IntToStr(sym.value)+')';
  1308. end;
  1309. GetEnumItemName:=Name;
  1310. end;
  1311. function GetConstValueName(sym: tconstsym): string;
  1312. var Name: string;
  1313. begin
  1314. Name:='';
  1315. if Name='' then
  1316. case sym.consttyp of
  1317. constord :
  1318. begin
  1319. if sym.constdef.typ=enumdef then
  1320. Name:=sym.constdef.typesym.name+'('+tostr(sym.value.valueord)+')'
  1321. else
  1322. if is_boolean(sym.constdef) then
  1323. Name:='Longbool('+tostr(sym.value.valueord)+')'
  1324. else
  1325. if is_char(sym.constdef) or
  1326. is_widechar(sym.constdef) then
  1327. Name:=''''+chr(sym.value.valueord.svalue)+''''
  1328. else
  1329. Name:=tostr(sym.value.valueord);
  1330. end;
  1331. constresourcestring,
  1332. conststring :
  1333. Name:=''''+StrPas(pchar(sym.value.valueptr))+'''';
  1334. constreal:
  1335. Name:=FloatToStr(PBestReal(sym.value.valueptr)^);
  1336. constset:
  1337. { Name:=SetToStr(pnormalset(sym.value.valueptr)) };
  1338. constnil: ;
  1339. end;
  1340. GetConstValueName:=Name;
  1341. end;
  1342. procedure ProcessDefIfStruct(definition: tdef);
  1343. begin
  1344. { still led to infinite recursions
  1345. only usefull for unamed types PM }
  1346. if assigned(definition) and not assigned(definition.typesym) then
  1347. begin
  1348. case definition.typ of
  1349. recorddef :
  1350. if trecorddef(definition).symtable<>Table then
  1351. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(definition).symtable);
  1352. objectdef :
  1353. if tobjectdef(definition).symtable<>Table then
  1354. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(definition).symtable);
  1355. { leads to infinite loops !!
  1356. pointerdef :
  1357. with tpointerdef(definition)^ do
  1358. if assigned(definition) then
  1359. if assigned(definition.sym) then
  1360. ProcessDefIfStruct(definition.sym.definition);}
  1361. end;
  1362. end;
  1363. end;
  1364. var MemInfo: TSymbolMemInfo;
  1365. ObjDef: tobjectdef;
  1366. symidx : longint;
  1367. begin
  1368. if not Assigned(Table) then
  1369. Exit;
  1370. Symbol:=nil;
  1371. if Owner=nil then
  1372. Owner:=New(PSortedSymbolCollection, Init(10,50));
  1373. for symidx:=0 to Table.SymList.Count-1 do
  1374. begin
  1375. sym:=tsym(Table.SymList[symidx]);
  1376. New(Symbol, Init(Sym.Name,Sym.Typ,'',nil));
  1377. case Sym.Typ of
  1378. staticvarsym,
  1379. localvarsym,
  1380. absolutevarsym,
  1381. paravarsym :
  1382. begin
  1383. Symbol^.SetVarOptions(tabstractvarsym(sym).VarOptions);
  1384. Symbol^.SetVarSpez(tabstractvarsym(sym).VarSpez);
  1385. end;
  1386. end;
  1387. case Sym.Typ of
  1388. staticvarsym,
  1389. localvarsym,
  1390. paravarsym :
  1391. with tabstractvarsym(sym) do
  1392. begin
  1393. if (vo_is_funcret in varoptions) then
  1394. begin
  1395. if Assigned(OwnerSym) then
  1396. if assigned(vardef) then
  1397. if assigned(vardef.typesym) then
  1398. SetVType(OwnerSym,vardef.typesym.name)
  1399. else
  1400. SetVType(OwnerSym,GetDefinitionStr(vardef));
  1401. end;
  1402. if assigned(vardef) then
  1403. if assigned(vardef.typesym) then
  1404. SetVType(Symbol,vardef.typesym.name)
  1405. else
  1406. SetVType(Symbol,GetDefinitionStr(vardef));
  1407. ProcessDefIfStruct(vardef);
  1408. if assigned(vardef) then
  1409. if (vardef.typ=pointerdef) and
  1410. assigned(tpointerdef(vardef).pointeddef) then
  1411. begin
  1412. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1413. Symbol^.RelatedTypeID:=Ptrint(tpointerdef(vardef).pointeddef);
  1414. end;
  1415. if typ=fieldvarsym then
  1416. MemInfo.Addr:=tfieldvarsym(sym).fieldoffset
  1417. else
  1418. begin
  1419. if tabstractnormalvarsym(sym).localloc.loc=LOC_REFERENCE then
  1420. MemInfo.Addr:=tabstractnormalvarsym(sym).localloc.reference.offset
  1421. else
  1422. MemInfo.Addr:=0;
  1423. end;
  1424. if assigned(vardef) and (vardef.typ=arraydef) then
  1425. begin
  1426. if tarraydef(vardef).highrange<tarraydef(vardef).lowrange then
  1427. MemInfo.Size:=-1
  1428. else
  1429. MemInfo.Size:=getsize;
  1430. end
  1431. else
  1432. MemInfo.Size:=getsize;
  1433. { this is not completely correct... }
  1434. if assigned(vardef) then
  1435. MemInfo.PushSize:=paramanager.push_size(varspez,vardef,pocall_default)
  1436. else
  1437. begin
  1438. { This can happen, why? }
  1439. MemInfo.PushSize:=0;
  1440. end;
  1441. Symbol^.SetMemInfo(MemInfo);
  1442. end;
  1443. fieldvarsym :
  1444. with tfieldvarsym(sym) do
  1445. begin
  1446. if assigned(vardef) and (vardef.typ=arraydef) then
  1447. begin
  1448. if tarraydef(vardef).highrange<tarraydef(vardef).lowrange then
  1449. MemInfo.Size:=-1
  1450. else
  1451. MemInfo.Size:=getsize;
  1452. end
  1453. else
  1454. MemInfo.Size:=getsize;
  1455. Symbol^.SetMemInfo(MemInfo);
  1456. end;
  1457. constsym :
  1458. SetDType(Symbol,GetConstValueName(tconstsym(sym)));
  1459. enumsym :
  1460. if assigned(tenumsym(sym).definition) then
  1461. SetDType(Symbol,GetEnumItemName(tenumsym(sym)));
  1462. unitsym :
  1463. begin
  1464. { ProcessSymTable(Symbol^.Items,tunitsym(sym).unitsymtable);}
  1465. end;
  1466. syssym :
  1467. { if assigned(Table.Name) then
  1468. if Table.Name^='SYSTEM' then}
  1469. begin
  1470. Symbol^.Params:=TypeNames^.Add('...');
  1471. end;
  1472. procsym :
  1473. begin
  1474. for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
  1475. begin
  1476. if i>0 then
  1477. begin
  1478. if Assigned(Symbol) then
  1479. Owner^.Insert(Symbol);
  1480. New(Symbol, Init(Sym.Name,Sym.Typ,'',nil));
  1481. end;
  1482. with tprocsym(sym) do
  1483. begin
  1484. pd:=tprocdef(procdeflist[i]);
  1485. if assigned(pd) then
  1486. begin
  1487. ProcessSymTable(Symbol,Symbol^.Items,pd.parast);
  1488. if assigned(pd.parast) then
  1489. begin
  1490. Symbol^.Params:=TypeNames^.Add(
  1491. GetAbsProcParmDefStr(pd));
  1492. end
  1493. else { param-definition is NOT assigned }
  1494. if assigned(Table.Name) and
  1495. (Table.Name^='SYSTEM') then
  1496. begin
  1497. Symbol^.Params:=TypeNames^.Add('...');
  1498. end;
  1499. if cs_local_browser in current_settings.moduleswitches then
  1500. begin
  1501. if assigned(pd.localst) and
  1502. (pd.localst.symtabletype<>staticsymtable) then
  1503. ProcessSymTable(Symbol,Symbol^.Items,pd.localst);
  1504. end;
  1505. end;
  1506. end;
  1507. end;
  1508. end;
  1509. typesym :
  1510. begin
  1511. with ttypesym(sym) do
  1512. if assigned(typedef) then
  1513. begin
  1514. Symbol^.TypeID:=Ptrint(typedef);
  1515. case typedef.typ of
  1516. arraydef :
  1517. SetDType(Symbol,GetArrayDefStr(tarraydef(typedef)));
  1518. enumdef :
  1519. SetDType(Symbol,GetEnumDefStr(tenumdef(typedef)));
  1520. procdef :
  1521. SetDType(Symbol,GetProcDefStr(tprocdef(typedef)));
  1522. procvardef :
  1523. SetDType(Symbol,GetProcVarDefStr(tprocvardef(typedef)));
  1524. objectdef :
  1525. with tobjectdef(typedef) do
  1526. begin
  1527. ObjDef:=childof;
  1528. if ObjDef<>nil then
  1529. Symbol^.RelatedTypeID:=Ptrint(ObjDef);{TypeNames^.Add(S);}
  1530. Symbol^.Flags:=(Symbol^.Flags or sfObject);
  1531. if tobjectdef(typedef).objecttype=odt_class then
  1532. Symbol^.Flags:=(Symbol^.Flags or sfClass);
  1533. ProcessSymTable(Symbol,Symbol^.Items,tobjectdef(typedef).symtable);
  1534. end;
  1535. recorddef :
  1536. begin
  1537. Symbol^.Flags:=(Symbol^.Flags or sfRecord);
  1538. ProcessSymTable(Symbol,Symbol^.Items,trecorddef(typedef).symtable);
  1539. end;
  1540. pointerdef :
  1541. begin
  1542. Symbol^.Flags:=(Symbol^.Flags or sfPointer);
  1543. Symbol^.RelatedTypeID:=Ptrint(tpointerdef(typedef).pointeddef);{TypeNames^.Add(S);}
  1544. SetDType(Symbol,GetPointerDefStr(tpointerdef(typedef)));
  1545. end;
  1546. filedef :
  1547. SetDType(Symbol,GetFileDefStr(tfiledef(typedef)));
  1548. setdef :
  1549. SetDType(Symbol,GetSetDefStr(tsetdef(typedef)));
  1550. end;
  1551. end;
  1552. end;
  1553. end;
  1554. if assigned(sym) then
  1555. begin
  1556. DefPos:=tstoredsym(sym).FileInfo;
  1557. inputfile:=get_source_file(defpos.moduleindex,defpos.fileindex);
  1558. if Assigned(inputfile) and Assigned(inputfile.name) then
  1559. begin
  1560. New(Reference, Init(ModuleNames^.Add(inputfile.name^),
  1561. DefPos.line,DefPos.column));
  1562. Symbol^.References^.Insert(Reference);
  1563. end;
  1564. end;
  1565. if assigned(Symbol) and assigned(sym.RefList) then
  1566. begin
  1567. Ref:=TRefItem(tstoredsym(sym).RefList.First);
  1568. while assigned(Ref) do
  1569. begin
  1570. inputfile:=get_source_file(ref.refinfo.moduleindex,ref.refinfo.fileindex);
  1571. if Assigned(inputfile) and Assigned(inputfile.name) then
  1572. begin
  1573. New(Reference, Init(ModuleNames^.Add(inputfile.name^),
  1574. ref.refinfo.line,ref.refinfo.column));
  1575. Symbol^.References^.Insert(Reference);
  1576. end;
  1577. Ref:=TRefItem(Ref.next);
  1578. end;
  1579. end;
  1580. if Assigned(Symbol) then
  1581. begin
  1582. (* if not Owner^.Search(Symbol,J) then *)
  1583. Owner^.Insert(Symbol)
  1584. (*else
  1585. begin
  1586. Dispose(Symbol,done);
  1587. Symbol:=nil;
  1588. end;*)
  1589. end;
  1590. end;
  1591. end;
  1592. function SearchModule(const Name: string): PModuleSymbol;
  1593. function Match(P: PModuleSymbol): boolean;
  1594. begin
  1595. Match:=CompareText(P^.GetName,Name)=0;
  1596. end;
  1597. var P: PModuleSymbol;
  1598. begin
  1599. P:=nil;
  1600. if Assigned(Modules) then
  1601. P:=Modules^.FirstThat(@Match);
  1602. SearchModule:=P;
  1603. end;
  1604. procedure CreateBrowserCol;
  1605. var
  1606. path,module,
  1607. name,msource : string;
  1608. T: TSymTable;
  1609. UnitS,PM: PModuleSymbol;
  1610. hp : tmodule;
  1611. puu: tused_unit;
  1612. pdu: tdependent_unit;
  1613. pif: tinputfile;
  1614. begin
  1615. DisposeBrowserCol;
  1616. if (cs_browser in current_settings.moduleswitches) then
  1617. NewBrowserCol;
  1618. hp:=tmodule(loaded_units.first);
  1619. if (cs_browser in current_settings.moduleswitches) then
  1620. while assigned(hp) do
  1621. begin
  1622. current_moduleindex:=hp.unit_index;
  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 Ptrint(K1^.PtrValue)<Ptrint(K2^.PtrValue) then R:=-1 else
  1942. if Ptrint(K1^.PtrValue)>Ptrint(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.