fpsymbol.pas 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Symbol browse support routines for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$i globdir.inc}
  12. unit FPSymbol;
  13. interface
  14. uses Objects,Drivers,Views,Menus,Dialogs,
  15. {$ifdef HASOUTLINE}
  16. Outline,
  17. {$endif HASOUTLINE}
  18. BrowCol,
  19. WViews,
  20. FPViews;
  21. const
  22. { Browser tab constants }
  23. btScope = 0;
  24. btReferences = 1;
  25. btInheritance = 2;
  26. btMemInfo = 3;
  27. btUnitInfo = 4;
  28. btBreakWatch = 7;
  29. type
  30. PBrowserWindow = ^TBrowserWindow;
  31. PGDBValueCollection = ^TGDBValueCollection;
  32. PGDBValue = ^TGDBValue;
  33. TGDBValue = Object(TObject)
  34. constructor Init(Const AExpr : String;ASym : PSymbol);
  35. procedure GetValue;
  36. function GetText : String;
  37. destructor Done;virtual;
  38. private
  39. expr : Pstring;
  40. St : Pstring;
  41. S : PSymbol;
  42. GDBI : longint;
  43. end;
  44. TGDBValueCollection = Object(TCollection)
  45. function At(Index: sw_Integer): PGDBValue;
  46. end;
  47. PSymbolView = ^TSymbolView;
  48. TSymbolView = object(TLocalMenuListBox)
  49. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  50. destructor Done;virtual;
  51. procedure HandleEvent(var Event: TEvent); virtual;
  52. procedure SetState(AState: Word; Enable: Boolean); virtual;
  53. function GotoItem(Item: sw_integer): boolean; virtual;
  54. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  55. function GetPalette: PPalette; virtual;
  56. function GetLocalMenu: PMenu; virtual;
  57. procedure ClearHighlights;
  58. procedure AutoTrackSource; virtual;
  59. procedure Browse; virtual;
  60. procedure GotoSource; virtual;
  61. procedure TrackSource; virtual;
  62. procedure OptionsDlg; virtual;
  63. private
  64. MyBW : PBrowserWindow;
  65. function TrackReference(R: PReference; AutoTrack: boolean): boolean; virtual;
  66. function GotoReference(R: PReference): boolean; virtual;
  67. end;
  68. PSymbolScopeView = ^TSymbolScopeView;
  69. TSymbolScopeView = object(TSymbolView)
  70. constructor Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  71. destructor Done; virtual;
  72. procedure SetGDBCol;
  73. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  74. procedure HandleEvent(var Event: TEvent); virtual;
  75. procedure Draw; virtual;
  76. procedure LookUp(S: string); virtual;
  77. function GotoItem(Item: sw_integer): boolean; virtual;
  78. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  79. private
  80. Symbols: PSymbolCollection;
  81. SymbolsValue : PGDBValueCollection;
  82. LookupStr: string;
  83. end;
  84. PSymbolReferenceView = ^TSymbolReferenceView;
  85. TSymbolReferenceView = object(TSymbolView)
  86. constructor Init(var Bounds: TRect; AReferences: PReferenceCollection; AHScrollBar, AVScrollBar: PScrollBar);
  87. destructor Done; virtual;
  88. procedure HandleEvent(var Event: TEvent); virtual;
  89. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  90. procedure SelectItem(Item: Sw_Integer); virtual;
  91. function GotoItem(Item: sw_integer): boolean; virtual;
  92. function TrackItem(Item: sw_integer; AutoTrack: boolean): boolean; virtual;
  93. procedure Browse; virtual;
  94. private
  95. References: PReferenceCollection;
  96. end;
  97. PSymbolMemInfoView = ^TSymbolMemInfoView;
  98. TSymbolMemInfoView = object(TStaticText)
  99. constructor Init(var Bounds: TRect; AMemInfo: PSymbolMemInfo);
  100. destructor Done; virtual;
  101. procedure GetText(var S: String); virtual;
  102. function GetPalette: PPalette; virtual;
  103. private
  104. MemInfo: PSymbolMemInfo;
  105. MyBW : PBrowserWindow;
  106. end;
  107. PSymbolMemoView = ^TSymbolMemoView;
  108. TSymbolMemoView = object(TFPMemo)
  109. function GetPalette: PPalette; virtual;
  110. end;
  111. PSymbolInheritanceView = ^TSymbolInheritanceView;
  112. {$ifdef HASOUTLINE}
  113. TSymbolInheritanceView = object(TOutlineViewer)
  114. {$else notHASOUTLINE}
  115. TSymbolInheritanceView = object(TLocalMenuListBox)
  116. {$endif HASOUTLINE}
  117. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar; ARoot: PObjectSymbol);
  118. destructor Done; virtual;
  119. function GetRoot: Pointer; virtual;
  120. function HasChildren(Node: Pointer): Boolean; virtual;
  121. function GetChild(Node: Pointer; I: sw_Integer): Pointer; virtual;
  122. function GetNumChildren(Node: Pointer): sw_Integer; virtual;
  123. function GetNumChildrenExposed(Node: Pointer) : sw_Integer; virtual;
  124. procedure Adjust(Node: Pointer; Expand: Boolean); virtual;
  125. function IsExpanded(Node: Pointer): Boolean; virtual;
  126. {$ifdef HASOUTLINE}
  127. function GetText(Node: Pointer): String; virtual;
  128. {$else not HASOUTLINE}
  129. procedure ExpandAll(Node: Pointer);
  130. function GetNode(I : sw_Integer) : Pointer; virtual;
  131. function GetLineNode(Item : sw_Integer) : Pointer; virtual;
  132. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  133. {$endif HASOUTLINE}
  134. procedure NodeSelected(P: pointer); virtual;
  135. procedure Selected(I: sw_Integer); virtual;
  136. procedure HandleEvent(var Event: TEvent); virtual;
  137. function GetPalette: PPalette; virtual;
  138. private
  139. Root : PObjectSymbol;
  140. MyBW : PBrowserWindow;
  141. end;
  142. PBrowserTabItem = ^TBrowserTabItem;
  143. TBrowserTabItem = record
  144. Sign : char;
  145. Link : PView;
  146. Next : PBrowserTabItem;
  147. end;
  148. PBrowserTab = ^TBrowserTab;
  149. TBrowserTab = object(TView)
  150. Items: PBrowserTabItem;
  151. constructor Init(var Bounds: TRect; AItems: PBrowserTabItem);
  152. function GetItemCount: sw_integer; virtual;
  153. function GetItem(Index: sw_integer): PBrowserTabItem; virtual;
  154. procedure SetParams(AFlags: word; ACurrent: Sw_integer); virtual;
  155. procedure SelectItem(Index: Sw_integer); virtual;
  156. procedure Draw; virtual;
  157. function GetPalette: PPalette; virtual;
  158. procedure HandleEvent(var Event: TEvent); virtual;
  159. destructor Done; virtual;
  160. private
  161. Flags : word;
  162. Current : Sw_integer;
  163. end;
  164. PUnitInfoPanel = ^TUnitInfoPanel;
  165. TUnitInfoPanel = object(TPanel)
  166. InOwnerCall: boolean;
  167. procedure HandleEvent(var Event: TEvent); virtual;
  168. end;
  169. TBrowserWindow = object(TFPWindow)
  170. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  171. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  172. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemInfo);
  173. procedure HandleEvent(var Event: TEvent); virtual;
  174. procedure SetState(AState: Word; Enable: Boolean); virtual;
  175. procedure Close; virtual;
  176. procedure SelectTab(BrowserTab: Sw_integer); virtual;
  177. function GetPalette: PPalette; virtual;
  178. function Disassemble : boolean;
  179. destructor Done;virtual;
  180. private
  181. PageTab : PBrowserTab;
  182. ST : PStaticText;
  183. Sym : PSymbol;
  184. ScopeView : PSymbolScopeView;
  185. ReferenceView : PSymbolReferenceView;
  186. InheritanceView: PSymbolInheritanceView;
  187. MemInfoView : PSymbolMemInfoView;
  188. UnitInfoText : PSymbolMemoView;
  189. UnitInfoUsed : PSymbolScopeView;
  190. UnitInfoDependent : PSymbolScopeView;
  191. UnitInfo : PUnitInfoPanel;
  192. Prefix : PString;
  193. IsValid : boolean;
  194. DebuggerValue : PGDBValue;
  195. end;
  196. procedure OpenSymbolBrowser(X,Y: Sw_integer;const Name,Line: string;S : PSymbol;
  197. ParentBrowser : PBrowserWindow;
  198. Symbols: PSymbolCollection; References: PReferenceCollection;
  199. Inheritance: PObjectSymbol; MemInfo: PSymbolMemInfo);
  200. function IsSymbolInfoAvailable: boolean;
  201. procedure OpenOneSymbolBrowser(Name : String);
  202. procedure CloseAllBrowsers;
  203. procedure RemoveBrowsersCollection;
  204. const
  205. GlobalsCollection : PSortedCollection = nil;
  206. ProcedureCollection : PSortedCollection = nil;
  207. ModulesCollection : PSortedCollection = nil;
  208. implementation
  209. uses App,Strings,
  210. FVConsts,
  211. {$ifdef BROWSERCOL}
  212. symconst,
  213. {$endif BROWSERCOL}
  214. WUtils,WEditor,
  215. FPConst,FPUtils,FPVars,{$ifndef FPDEBUG}FPDebug{$endif},FPIDE;
  216. {$ifdef USERESSTRINGS}
  217. resourcestring
  218. {$else}
  219. const
  220. {$endif}
  221. msg_symbolnotfound = #3'Symbol %s not found';
  222. msg_nobrowserinfoavailable = 'No Browser info available';
  223. msg_cantfindfile = 'Can''t find %s';
  224. menu_local_gotosource = '~G~oto source';
  225. menu_local_tracksource = '~T~rack source';
  226. menu_local_options = '~O~ptions...';
  227. menu_local_clear = '~C~lear';
  228. menu_local_saveas = 'Save ~a~s';
  229. { Symbol view local menu items }
  230. menu_symlocal_browse = '~B~rowse';
  231. menu_symlocal_gotosource = '~G~oto source';
  232. menu_symlocal_tracksource = '~T~rack source';
  233. menu_symlocal_options = '~O~ptions...';
  234. { Symbol browser meminfo page }
  235. msg_sizeinmemory = 'Size in memory';
  236. msg_sizeonstack = 'Size on stack';
  237. msg_usedfirstin = 'Used first in';
  238. msg_mainsource = 'Main source';
  239. msg_sourcefiles = 'Source files';
  240. dialog_browse = 'Browse: %s';
  241. const { Symbol browser tabs }
  242. { must be char constants (so cannot be resourcestring)}
  243. label_browsertab_scope = 'S';
  244. label_browsertab_reference = 'R';
  245. label_browsertab_inheritance = 'I';
  246. label_browsertab_memory = 'M';
  247. label_browsertab_unit = 'U';
  248. procedure CloseAllBrowsers;
  249. procedure SendCloseIfBrowser(P: PView); {$ifndef FPC}far;{$endif}
  250. begin
  251. if assigned(P) and
  252. ((TypeOf(P^)=TypeOf(TBrowserWindow)) or
  253. (TypeOf(P^)=TypeOf(TSymbolView)) or
  254. (TypeOf(P^)=TypeOf(TSymbolScopeView)) or
  255. (TypeOf(P^)=TypeOf(TSymbolReferenceView)) or
  256. (TypeOf(P^)=TypeOf(TSymbolMemInfoView)) or
  257. (TypeOf(P^)=TypeOf(TSymbolInheritanceView)) or
  258. (TypeOf(P^)=TypeOf(TSymbolMemoView))) then
  259. Message(P,evCommand,cmClose,nil);
  260. end;
  261. begin
  262. Desktop^.ForEach(@SendCloseIfBrowser);
  263. end;
  264. procedure RemoveBrowsersCollection;
  265. begin
  266. if assigned(GlobalsCollection) then
  267. begin
  268. GlobalsCollection^.deleteAll;
  269. Dispose(GlobalsCollection,done);
  270. GlobalsCollection:=nil;
  271. end;
  272. if assigned(ProcedureCollection) then
  273. begin
  274. ProcedureCollection^.deleteAll;
  275. Dispose(ProcedureCollection,done);
  276. ProcedureCollection:=nil;
  277. end;
  278. if assigned(ModulesCollection) then
  279. begin
  280. ModulesCollection^.deleteAll;
  281. Dispose(ModulesCollection,done);
  282. ModulesCollection:=nil;
  283. end;
  284. end;
  285. function NewBrowserTabItem(ASign: char; ALink: PView; ANext: PBrowserTabItem): PBrowserTabItem;
  286. var P: PBrowserTabItem;
  287. begin
  288. New(P); FillChar(P^,SizeOf(P^),0);
  289. with P^ do begin Sign:=ASign; Link:=ALink; Next:=ANext; end;
  290. NewBrowserTabItem:=P;
  291. end;
  292. procedure DisposeBrowserTabItem(P: PBrowserTabItem);
  293. begin
  294. if P<>nil then Dispose(P);
  295. end;
  296. procedure DisposeBrowserTabList(P: PBrowserTabItem);
  297. begin
  298. if P<>nil then
  299. begin
  300. if P^.Next<>nil then DisposeBrowserTabList(P^.Next);
  301. DisposeBrowserTabItem(P);
  302. end;
  303. end;
  304. function IsSymbolInfoAvailable: boolean;
  305. begin
  306. IsSymbolInfoAvailable:=BrowCol.Modules<>nil;
  307. end;
  308. procedure OpenOneSymbolBrowser(Name : String);
  309. var Index : sw_integer;
  310. PS,S : PSymbol;
  311. Anc : PObjectSymbol;
  312. P : Pstring;
  313. Symbols: PSymbolCollection;
  314. function Search(P : PSymbol) : boolean;
  315. begin
  316. Search:=UpcaseStr(P^.Items^.LookUp(Name,Index))=Name;
  317. end;
  318. begin
  319. Name:=UpcaseStr(Name);
  320. If BrowCol.Modules<>nil then
  321. begin
  322. PS:=BrowCol.Modules^.FirstThat(@Search);
  323. If assigned(PS) then
  324. begin
  325. S:=PS^.Items^.At(Index);
  326. Symbols:=S^.Items;
  327. if (not assigned(symbols) or (symbols^.count=0)) and
  328. assigned(S^.Ancestor) then
  329. Symbols:=S^.Ancestor^.Items;
  330. if (S^.Flags and (sfObject or sfClass))=0 then
  331. Anc:=nil
  332. else if S^.Ancestor=nil then
  333. Anc:=ObjectTree
  334. else
  335. Anc:=SearchObjectForSymbol(S^.Ancestor);
  336. OpenSymbolBrowser(0,20,
  337. PS^.Items^.At(Index)^.GetName,
  338. PS^.Items^.At(Index)^.GetText,
  339. PS^.Items^.At(Index),nil,
  340. Symbols,PS^.Items^.At(Index)^.References,Anc,PS^.MemInfo);
  341. end
  342. else
  343. begin
  344. P:=@Name;
  345. ErrorBox(msg_symbolnotfound,@P);
  346. end;
  347. end
  348. else
  349. ErrorBox(msg_nobrowserinfoavailable,nil);
  350. end;
  351. (*procedure ReadBrowseLog(FileName: string);
  352. var f: text;
  353. IOOK,EndOfFile: boolean;
  354. Line: string;
  355. procedure NextLine;
  356. begin
  357. readln(f,Line);
  358. EndOfFile:=Eof(f);
  359. end;
  360. var Level: integer;
  361. procedure ProcessSymTable(Indent: integer; Owner: PSymbolCollection);
  362. var IndentS,S,Source: string;
  363. Sym: PSymbol;
  364. Ref: PSymbolReference;
  365. P: byte;
  366. PX: TPoint;
  367. PS: PString;
  368. PCount: integer;
  369. Params: array[0..30] of PString;
  370. Typ: tsymtyp;
  371. ExitBack: boolean;
  372. begin
  373. Inc(Level);
  374. IndentS:=CharStr(' ',Indent); ExitBack:=false;
  375. Sym:=nil;
  376. repeat
  377. if copy(Line,1,length(IndentS))<>IndentS then ExitBack:=true else
  378. if copy(Line,Indent+1,3)='***' then
  379. { new symbol }
  380. begin
  381. S:=copy(Line,Indent+1+3,255);
  382. P:=Pos('***',S); if P=0 then P:=length(S)+1;
  383. S:=Trim(copy(S,1,P-1));
  384. if (copy(S,1,1)='_') and (Pos('$$',S)>0) then
  385. begin
  386. repeat
  387. P:=Pos('$$',S);
  388. if P>0 then Delete(S,1,P+1);
  389. until P=0;
  390. P:=Pos('$',S);
  391. Delete(S,1,P);
  392. PCount:=0;
  393. repeat
  394. P:=Pos('$',S); if P=0 then P:=length(S)+1;
  395. Params[PCount]:=TypeNames^.Add(copy(S,1,P-1));
  396. Inc(PCount);
  397. Delete(S,1,P);
  398. until S='';
  399. Sym^.Typ:=procsym;
  400. Sym^.SetParams(PCount,@Params);
  401. end
  402. else
  403. New(Sym, Init(S, varsym, 0, nil));
  404. Owner^.Insert(Sym);
  405. NextLine;
  406. end else
  407. if copy(Line,Indent+1,3)='---' then
  408. { child symtable }
  409. begin
  410. S:=Trim(copy(Line,Indent+1+12,255));
  411. if Level=1 then Typ:=unitsym else
  412. Typ:=typesym;
  413. if (Sym<>nil) and (Sym^.GetName=S) then
  414. else
  415. begin
  416. New(Sym, Init(S, Typ, 0, nil));
  417. Owner^.Insert(Sym);
  418. end;
  419. Sym^.Typ:=Typ;
  420. NextLine;
  421. New(Sym^.Items, Init(0,50));
  422. ProcessSymTable(Indent+2,Sym^.Items);
  423. end else
  424. { if Sym<>nil then}
  425. if copy(Line,Indent+1,1)=' ' then
  426. { reference }
  427. begin
  428. S:=copy(Line,Indent+1+2,255);
  429. P:=Pos('(',S); if P=0 then P:=length(S)+1;
  430. Source:=Trim(copy(S,1,P-1)); Delete(S,1,P);
  431. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  432. PX.Y:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  433. P:=Pos(')',S); if P=0 then P:=length(S)+1;
  434. PX.X:=StrToInt(copy(S,1,P-1)); Delete(S,1,P);
  435. PS:=ModuleNames^.Add(Source);
  436. New(Ref, Init(PS, PX));
  437. if Sym^.References=nil then
  438. New(Sym^.References, Init(10,50));
  439. Sym^.References^.Insert(Ref);
  440. end;
  441. if ExitBack=false then
  442. NextLine;
  443. until EndOfFile or ExitBack;
  444. Dec(Level);
  445. end;
  446. begin
  447. DoneSymbolBrowser;
  448. InitSymbolBrowser;
  449. {$I-}
  450. Assign(f,FileName);
  451. Reset(f);
  452. Level:=0;
  453. NextLine;
  454. while (IOResult=0) and (EndOfFile=false) do
  455. ProcessSymTable(0,Modules);
  456. Close(f);
  457. EatIO;
  458. {$I+}
  459. end;*)
  460. {****************************************************************************
  461. TGDBValue
  462. ****************************************************************************}
  463. constructor TGDBValue.Init(Const AExpr : String;ASym : PSymbol);
  464. begin
  465. St := nil;
  466. S := ASym;
  467. Expr:=NewStr(AExpr);
  468. GDBI:=-1;
  469. end;
  470. destructor TGDBValue.Done;
  471. begin
  472. If Assigned(St) then
  473. begin
  474. DisposeStr(St);
  475. st:=nil;
  476. end;
  477. If Assigned(Expr) then
  478. begin
  479. DisposeStr(Expr);
  480. Expr:=nil;
  481. end;
  482. end;
  483. procedure TGDBValue.GetValue;
  484. var
  485. p : pchar;
  486. begin
  487. {$ifdef BROWSERCOL}
  488. {$ifndef NODEBUG}
  489. if not assigned(Debugger) then
  490. exit;
  491. if not Debugger^.IsRunning then
  492. exit;
  493. if (S^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) or (GDBI=Debugger^.RunCount) then
  494. exit;
  495. If Assigned(St) then
  496. DisposeStr(St);
  497. if assigned(Expr) then
  498. begin
  499. p:=Debugger^.GetValue(Expr^);
  500. St:=NewStr(GetPChar(p));
  501. if assigned(p) then
  502. StrDispose(p);
  503. GDBI:=Debugger^.RunCount;
  504. end;
  505. {$endif ndef NODEBUG}
  506. {$endif BROWSERCOL}
  507. end;
  508. function TGDBValue.GetText : String;
  509. begin
  510. GetValue;
  511. if assigned(St) then
  512. GetText:=S^.GetText+' = '+GetStr(St)
  513. else
  514. GetText:=S^.GetText;
  515. end;
  516. {****************************************************************************
  517. TGDBValueCollection
  518. ****************************************************************************}
  519. function TGDBValueCollection.At(Index: sw_Integer): PGDBValue;
  520. begin
  521. At:= Inherited At(Index);
  522. end;
  523. {****************************************************************************
  524. TSymbolView
  525. ****************************************************************************}
  526. constructor TSymbolView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  527. begin
  528. inherited Init(Bounds,1,AVScrollBar);
  529. HScrollBar:=AHScrollBar;
  530. MyBW:=nil;
  531. if assigned(HScrollBar) then
  532. begin
  533. HScrollBar^.SetRange(1,80);
  534. end;
  535. Options:=Options or (ofSelectable+ofTopSelect);
  536. EventMask:=EventMask or evBroadcast;
  537. end;
  538. procedure TSymbolView.ClearHighlights;
  539. begin
  540. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  541. end;
  542. procedure TSymbolView.AutoTrackSource;
  543. begin
  544. if Range>0 then
  545. TrackSource;
  546. end;
  547. procedure TSymbolView.OptionsDlg;
  548. begin
  549. { Abstract }
  550. end;
  551. destructor TSymbolView.Done;
  552. begin
  553. EventMask:=EventMask and not evBroadcast;
  554. Inherited Done;
  555. end;
  556. procedure TSymbolView.SetState(AState: Word; Enable: Boolean);
  557. var OState: longint;
  558. begin
  559. OState:=State;
  560. inherited SetState(AState,Enable);
  561. if ((OState xor State) and sfFocused)<>0 then
  562. if GetState(sfFocused) then
  563. begin
  564. if (MiscOptions and moAutoTrackSource)<>0 then
  565. AutoTrackSource;
  566. end
  567. else
  568. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  569. end;
  570. procedure TSymbolView.Browse;
  571. begin
  572. SelectItem(Focused);
  573. end;
  574. procedure TSymbolView.GotoSource;
  575. begin
  576. if GotoItem(Focused) then
  577. PutCommand(Owner,evCommand,cmClose,nil);
  578. end;
  579. procedure TSymbolView.TrackSource;
  580. begin
  581. TrackItem(Focused,false);
  582. end;
  583. procedure TSymbolView.HandleEvent(var Event: TEvent);
  584. var DontClear: boolean;
  585. begin
  586. case Event.What of
  587. evKeyDown :
  588. begin
  589. DontClear:=false;
  590. case Event.KeyCode of
  591. kbEnter :
  592. Browse;
  593. kbCtrlEnter :
  594. GotoSource;
  595. kbSpaceBar :
  596. TrackSource;
  597. kbRight,kbLeft :
  598. if HScrollBar<>nil then
  599. HScrollBar^.HandleEvent(Event);
  600. else DontClear:=true;
  601. end;
  602. if DontClear=false then ClearEvent(Event);
  603. end;
  604. evMouseDown :
  605. begin
  606. if Event.double then
  607. begin
  608. Browse;
  609. ClearEvent(Event);
  610. end;
  611. end;
  612. evCommand :
  613. begin
  614. DontClear:=false;
  615. case Event.Command of
  616. cmSymBrowse :
  617. Browse;
  618. cmSymGotoSource :
  619. GotoSource;
  620. cmSymTrackSource :
  621. TrackSource;
  622. cmSymOptions :
  623. OptionsDlg;
  624. else DontClear:=true;
  625. end;
  626. if DontClear=false then ClearEvent(Event);
  627. end;
  628. evBroadcast :
  629. case Event.Command of
  630. cmListFocusChanged :
  631. if Event.InfoPtr=@Self then
  632. if (MiscOptions and moAutoTrackSource)<>0 then
  633. if GetState(sfFocused) then
  634. AutoTrackSource;
  635. end;
  636. end;
  637. inherited HandleEvent(Event);
  638. end;
  639. function TSymbolView.GetPalette: PPalette;
  640. const
  641. P: string[length(CBrowserListBox)] = CBrowserListBox;
  642. begin
  643. GetPalette:=@P;
  644. end;
  645. function TSymbolView.GetLocalMenu: PMenu;
  646. begin
  647. GetLocalMenu:=NewMenu(
  648. NewItem(menu_symlocal_browse,'',kbNoKey,cmSymBrowse,hcSymBrowse,
  649. NewItem(menu_symlocal_gotosource,'',kbNoKey,cmSymGotoSource,hcSymGotoSource,
  650. NewItem(menu_symlocal_tracksource,'',kbNoKey,cmSymTrackSource,hcSymTrackSource,
  651. NewLine(
  652. NewItem(menu_symlocal_options,'',kbNoKey,cmSymOptions,hcSymOptions,
  653. nil))))));
  654. end;
  655. function TSymbolView.GotoItem(Item: sw_integer): boolean;
  656. begin
  657. SelectItem(Item);
  658. GotoItem:=true;
  659. end;
  660. function TSymbolView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  661. begin
  662. SelectItem(Item);
  663. TrackItem:=true;
  664. end;
  665. function LastBrowserWindow: PBrowserWindow;
  666. var BW: PBrowserWindow;
  667. procedure IsBW(P: PView); {$ifndef FPC}far;{$endif}
  668. begin
  669. if (P^.HelpCtx=hcBrowserWindow) then
  670. BW:=pointer(P);
  671. end;
  672. begin
  673. BW:=nil;
  674. Desktop^.ForEach(@IsBW);
  675. LastBrowserWindow:=BW;
  676. end;
  677. function TSymbolView.TrackReference(R: PReference; AutoTrack: boolean): boolean;
  678. var W: PSourceWindow;
  679. BW: PBrowserWindow;
  680. P: TPoint;
  681. begin
  682. ClearHighlights;
  683. Desktop^.Lock;
  684. P.X:=R^.Position.X-1; P.Y:=R^.Position.Y-1;
  685. if AutoTrack then
  686. W:=SearchOnDesktop(R^.GetFileName,false)
  687. else
  688. W:=TryToOpenFile(nil,R^.GetFileName,P.X,P.Y,true);
  689. if not assigned(W) then
  690. begin
  691. Desktop^.Unlock;
  692. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  693. begin
  694. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  695. if Assigned(W) then
  696. W^.Select;
  697. end;
  698. Desktop^.Lock;
  699. end;
  700. if W<>nil then
  701. begin
  702. BW:=LastBrowserWindow;
  703. if BW=nil then
  704. W^.Select
  705. else
  706. begin
  707. Desktop^.Delete(W);
  708. Desktop^.InsertBefore(W,BW^.NextView);
  709. end;
  710. W^.Editor^.SetLineFlagExclusive(lfHighlightRow,P.Y);
  711. end;
  712. Desktop^.UnLock;
  713. if Assigned(W)=false then
  714. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  715. TrackReference:=W<>nil;
  716. end;
  717. function TSymbolView.GotoReference(R: PReference): boolean;
  718. var W: PSourceWindow;
  719. begin
  720. Desktop^.Lock;
  721. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  722. if Assigned(W) then
  723. W^.Select
  724. else
  725. begin
  726. Desktop^.Unlock;
  727. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  728. begin
  729. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  730. if Assigned(W) then
  731. W^.Select;
  732. end;
  733. Desktop^.Lock;
  734. end;
  735. Desktop^.UnLock;
  736. if Assigned(W)=false then
  737. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  738. GotoReference:=W<>nil;
  739. end;
  740. {****************************************************************************
  741. TSymbolScopeView
  742. ****************************************************************************}
  743. constructor TSymbolScopeView.Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  744. begin
  745. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  746. Symbols:=ASymbols;
  747. NewList(ASymbols);
  748. New(SymbolsValue,Init(50,50));
  749. SetRange(Symbols^.Count);
  750. end;
  751. destructor TSymbolScopeView.Done;
  752. begin
  753. {if assigned(Symbols) then
  754. begin
  755. the elements belong to other lists
  756. Symbols^.DeleteAll;
  757. dispose(Symbols,done);
  758. end;}
  759. if Assigned(SymbolsValue) then
  760. begin
  761. Dispose(SymbolsValue,Done);
  762. SymbolsValue:=nil;
  763. end;
  764. Inherited Done;
  765. end;
  766. procedure TSymbolScopeView.HandleEvent(var Event: TEvent);
  767. var OldFocus: sw_integer;
  768. begin
  769. case Event.What of
  770. evKeyDown :
  771. case Event.KeyCode of
  772. kbBack :
  773. begin
  774. LookUp(copy(LookUpStr,1,length(LookUpStr)-1));
  775. ClearEvent(Event);
  776. end;
  777. else
  778. if Event.CharCode in[#33..#255] then
  779. begin
  780. LookUp(LookUpStr+Event.CharCode);
  781. ClearEvent(Event);
  782. end;
  783. end;
  784. end;
  785. OldFocus:=Focused;
  786. inherited HandleEvent(Event);
  787. if OldFocus<>Focused then
  788. Lookup('');
  789. end;
  790. procedure TSymbolScopeView.Draw;
  791. var DeltaX: sw_integer;
  792. begin
  793. inherited Draw;
  794. if Assigned(HScrollBar)=false then DeltaX:=0 else
  795. DeltaX:=HScrollBar^.Value-HScrollBar^.Min;
  796. SetCursor(2+SymbolTypLen+length(LookUpStr)-DeltaX,Focused-TopItem);
  797. end;
  798. procedure TSymbolScopeView.LookUp(S: string);
  799. var Idx,Slength: Sw_integer;
  800. NS: string;
  801. begin
  802. NS:=LookUpStr;
  803. Slength:=Length(S);
  804. if (Symbols=nil) or (S='') then NS:='' else
  805. begin
  806. S:=Symbols^.LookUp(S,Idx);
  807. if Idx<>-1 then
  808. begin
  809. NS:=S;
  810. FocusItem(Idx);
  811. end;
  812. end;
  813. LookUpStr:=Copy(NS,1,Slength);
  814. SetState(sfCursorVis,LookUpStr<>'');
  815. DrawView;
  816. end;
  817. function TSymbolScopeView.GotoItem(Item: sw_integer): boolean;
  818. var S: PSymbol;
  819. OK: boolean;
  820. begin
  821. OK:=Range>0;
  822. if OK then
  823. begin
  824. S:=List^.At(Item);
  825. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  826. if OK then
  827. OK:=GotoReference(S^.References^.At(0));
  828. end;
  829. GotoItem:=OK;
  830. end;
  831. function TSymbolScopeView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  832. var S: PSymbol;
  833. OK: boolean;
  834. begin
  835. OK:=Range>0;
  836. if OK then
  837. begin
  838. S:=List^.At(Item);
  839. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  840. if OK then
  841. OK:=TrackReference(S^.References^.At(0),AutoTrack);
  842. end;
  843. TrackItem:=OK;
  844. end;
  845. procedure TSymbolScopeView.SetGDBCol;
  846. var S : PSymbol;
  847. I : sw_integer;
  848. begin
  849. if assigned(MyBW) and (SymbolsValue^.Count=0) then
  850. begin
  851. For i:=0 to Symbols^.Count-1 do
  852. begin
  853. S:=Symbols^.At(I);
  854. SymbolsValue^.Insert(New(PGDBValue,Init(GetStr(MyBW^.Prefix)+S^.GetName,S)));
  855. end;
  856. end;
  857. end;
  858. function TSymbolScopeView.GetText(Item,MaxLen: Sw_Integer): String;
  859. var S1: string;
  860. S : PSymbol;
  861. SG : PGDBValue;
  862. begin
  863. S:=Symbols^.At(Item);
  864. if Assigned(SymbolsValue) and (SymbolsValue^.Count>Item) then
  865. SG:=SymbolsValue^.At(Item)
  866. else
  867. SG:=nil;
  868. if assigned(SG) then
  869. S1:=SG^.getText
  870. else
  871. S1:=S^.GetText;
  872. GetText:=copy(S1,1,MaxLen);
  873. end;
  874. {****************************************************************************
  875. TSymbolReferenceView
  876. ****************************************************************************}
  877. constructor TSymbolReferenceView.Init(var Bounds: TRect; AReferences: PReferenceCollection;
  878. AHScrollBar, AVScrollBar: PScrollBar);
  879. begin
  880. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  881. References:=AReferences;
  882. NewList(AReferences);
  883. SetRange(References^.Count);
  884. end;
  885. destructor TSymbolReferenceView.Done;
  886. begin
  887. Inherited Done;
  888. end;
  889. procedure TSymbolReferenceView.HandleEvent(var Event: TEvent);
  890. var OldFocus: sw_integer;
  891. DontClear: boolean;
  892. begin
  893. OldFocus:=Focused;
  894. case Event.What of
  895. evKeyDown :
  896. begin
  897. DontClear:=false;
  898. case Event.KeyCode of
  899. kbEnter :
  900. TrackItem(Focused,false);
  901. kbCtrlEnter :
  902. GotoItem(Focused);
  903. else DontClear:=true;
  904. end;
  905. if DontClear=false then ClearEvent(Event);
  906. end;
  907. end;
  908. inherited HandleEvent(Event);
  909. if OldFocus<>Focused then
  910. if (MiscOptions and moAutoTrackSource)=0 then
  911. ClearHighlights;
  912. end;
  913. procedure TSymbolReferenceView.Browse;
  914. begin
  915. { do nothing here }
  916. end;
  917. function TSymbolReferenceView.GetText(Item,MaxLen: Sw_Integer): String;
  918. var S: string;
  919. P: PReference;
  920. begin
  921. P:=References^.At(Item);
  922. S:=P^.GetFileName+'('+IntToStr(P^.Position.Y)+','+IntToStr(P^.Position.X)+')';
  923. GetText:=copy(S,1,MaxLen);
  924. end;
  925. function TSymbolReferenceView.GotoItem(Item: sw_integer): boolean;
  926. var OK: boolean;
  927. begin
  928. OK:=Range>0;
  929. if OK then
  930. OK:=GotoReference(List^.At(Item));
  931. GotoItem:=OK;
  932. end;
  933. function TSymbolReferenceView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  934. var OK: boolean;
  935. begin
  936. OK:=Range>0;
  937. if OK then
  938. OK:=TrackReference(List^.At(Item),AutoTrack);
  939. TrackItem:=OK;
  940. end;
  941. procedure TSymbolReferenceView.SelectItem(Item: Sw_Integer);
  942. begin
  943. GotoItem(Item);
  944. end;
  945. constructor TSymbolMemInfoView.Init(var Bounds: TRect; AMemInfo: PSymbolMemInfo);
  946. begin
  947. inherited Init(Bounds,'');
  948. Options:=Options or (ofSelectable+ofTopSelect);
  949. MemInfo:=AMemInfo;
  950. MyBW:=nil;
  951. end;
  952. destructor TSymbolMemInfoView.Done;
  953. begin
  954. { if assigned(MemInfo) then
  955. dispose(MemInfo);}
  956. Inherited Done;
  957. end;
  958. procedure TSymbolMemInfoView.GetText(var S: String);
  959. function SizeStr(Size: longint): string;
  960. var S: string[40];
  961. begin
  962. S:=IntToStrL(Size,7);
  963. S:=S+' byte';
  964. if Size>1 then S:=S+'s';
  965. if Size=-1 then
  966. SizeStr:='variable'
  967. else
  968. SizeStr:=S;
  969. end;
  970. function AddrStr(Addr: longint): string;
  971. { Warning this is endian specific code !! (PM) }
  972. type TLongint = record LoW,HiW: word; end;
  973. begin
  974. with TLongint(Addr) do
  975. AddrStr:='$'+hexstr(HiW,4)+hexstr(LoW,4);
  976. end;
  977. begin
  978. ClearFormatParams;
  979. AddFormatParamStr(msg_sizeinmemory);
  980. AddFormatParamStr(msg_sizeonstack);
  981. S:=
  982. FormatStrF(
  983. #13+
  984. { ' Memory location: '+AddrStr(MemInfo^.Addr)+#13+
  985. ' Local address: '+AddrStr(MemInfo^.LocalAddr)+#13+}
  986. { ??? internal linker ??? }
  987. '%18s: '+SizeStr(MemInfo^.Size)+#13+
  988. '%18s: '+SizeStr(MemInfo^.PushSize)+#13+
  989. '',
  990. FormatParams);
  991. end;
  992. function TSymbolMemInfoView.GetPalette: PPalette;
  993. begin
  994. GetPalette:=inherited GetPalette;
  995. end;
  996. function TSymbolMemoView.GetPalette: PPalette;
  997. const P: string[length(CFPSymbolMemo)] = CFPSymbolMemo;
  998. begin
  999. GetPalette:=@P;
  1000. end;
  1001. {****************************************************************************
  1002. TSymbolInheritanceView
  1003. ****************************************************************************}
  1004. constructor TSymbolInheritanceView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar; ARoot: PObjectSymbol);
  1005. begin
  1006. {$ifdef HASOUTLINE}
  1007. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  1008. {$else not HASOUTLINE}
  1009. inherited Init(Bounds,1,AVScrollBar);
  1010. HScrollBar:=AHScrollBar;
  1011. {$endif not HASOUTLINE}
  1012. Options:=Options or (ofSelectable+ofTopSelect);
  1013. Root:=ARoot;
  1014. MyBW:=nil;
  1015. ExpandAll(Root);
  1016. {$ifdef HASOUTLINE}
  1017. Update;
  1018. {$else not HASOUTLINE}
  1019. SetRange(GetNumChildrenExposed(Root));
  1020. {$endif not HASOUTLINE}
  1021. end;
  1022. destructor TSymbolInheritanceView.Done;
  1023. begin
  1024. { do not dispose,
  1025. belongs to a symbolcollection (PM)
  1026. if assigned(Root) then
  1027. dispose(Root,done); }
  1028. Inherited Done;
  1029. end;
  1030. function TSymbolInheritanceView.GetRoot: Pointer;
  1031. begin
  1032. GetRoot:=Root;
  1033. end;
  1034. function TSymbolInheritanceView.HasChildren(Node: Pointer): Boolean;
  1035. begin
  1036. HasChildren:=GetNumChildren(Node)>0;
  1037. end;
  1038. function TSymbolInheritanceView.GetChild(Node: Pointer; I: sw_Integer): Pointer;
  1039. begin
  1040. GetChild:=PObjectSymbol(Node)^.GetDescendant(I);
  1041. end;
  1042. function TSymbolInheritanceView.GetNumChildren(Node: Pointer): sw_Integer;
  1043. begin
  1044. GetNumChildren:=PObjectSymbol(Node)^.GetDescendantCount;
  1045. end;
  1046. function TSymbolInheritanceView.GetNumChildrenExposed(Node: Pointer) : sw_Integer;
  1047. var
  1048. Nb : integer;
  1049. P : PObjectSymbol;
  1050. Procedure AddCount(P : PObjectSymbol);
  1051. var
  1052. i,count : integer;
  1053. D : PObjectSymbol;
  1054. begin
  1055. if not assigned(P) then
  1056. exit;
  1057. Count:=P^.GetDescendantCount;
  1058. Inc(Nb,Count);
  1059. for I:=0 to Count-1 do
  1060. begin
  1061. D:=P^.GetDescendant(I);
  1062. AddCount(D);
  1063. end;
  1064. end;
  1065. begin
  1066. Nb:=0;
  1067. AddCount(Node);
  1068. GetNumChildrenExposed:=Nb;
  1069. end;
  1070. procedure TSymbolInheritanceView.Adjust(Node: Pointer; Expand: Boolean);
  1071. begin
  1072. PObjectSymbol(Node)^.Expanded:=Expand;
  1073. end;
  1074. function TSymbolInheritanceView.IsExpanded(Node: Pointer): Boolean;
  1075. begin
  1076. IsExpanded:=PObjectSymbol(Node)^.Expanded;
  1077. end;
  1078. procedure TSymbolInheritanceView.HandleEvent(var Event: TEvent);
  1079. var DontClear: boolean;
  1080. {$ifndef HASOUTLINE}
  1081. P: TPoint;
  1082. {$endif HASOUTLINE}
  1083. begin
  1084. case Event.What of
  1085. evKeyDown :
  1086. begin
  1087. DontClear:=false;
  1088. case Event.KeyCode of
  1089. {$ifndef HASOUTLINE}
  1090. kbEnter:
  1091. NodeSelected(GetLineNode(Cursor.Y-Origin.Y));
  1092. {$endif HASOUTLINE}
  1093. kbLeft,kbRight,
  1094. kbCtrlLeft,kbCtrlRight :
  1095. if Assigned(HScrollBar) then
  1096. HScrollBar^.HandleEvent(Event)
  1097. else
  1098. DontClear:=true;
  1099. else DontClear:=true;
  1100. end;
  1101. if DontClear=false then ClearEvent(Event);
  1102. end;
  1103. evMouseDown :
  1104. begin
  1105. {$ifndef HASOUTLINE}
  1106. MakeLocal(Event.Where,P);
  1107. SetCursor(P.X,P.Y);
  1108. {$endif HASOUTLINE}
  1109. if Event.double then
  1110. begin
  1111. Message(@Self,evKeyDown,kbEnter,nil);
  1112. ClearEvent(Event);
  1113. end;
  1114. end;
  1115. end;
  1116. inherited HandleEvent(Event);
  1117. end;
  1118. function TSymbolInheritanceView.GetPalette: PPalette;
  1119. const P: string[length(CBrowserOutline)] = CBrowserOutline;
  1120. begin
  1121. GetPalette:=@P;
  1122. end;
  1123. {$ifdef HASOUTLINE}
  1124. function TSymbolInheritanceView.GetText(Node: Pointer): String;
  1125. begin
  1126. GetText:=PObjectSymbol(Node)^.GetName;
  1127. end;
  1128. {$else not HASOUTLINE}
  1129. function TSymbolInheritanceView.GetNode(I : sw_Integer) : Pointer;
  1130. var
  1131. P : PObjectSymbol;
  1132. begin
  1133. P:=Root;
  1134. If Assigned(P) then
  1135. P:=P^.GetDescendant(I);
  1136. GetNode:=Pointer(P);
  1137. end;
  1138. procedure TSymbolInheritanceView.ExpandAll(Node: Pointer);
  1139. var
  1140. i : integer;
  1141. P : Pointer;
  1142. begin
  1143. Adjust(Node,true);
  1144. For i:=0 to GetNumChildren(Node)-1 do
  1145. begin
  1146. P:=GetChild(Node,I);
  1147. if Assigned(P) then
  1148. ExpandAll(P);
  1149. end;
  1150. end;
  1151. function TSymbolInheritanceView.GetLineNode(Item : sw_Integer) : Pointer;
  1152. var
  1153. P : PObjectSymbol;
  1154. NT: Integer;
  1155. procedure FindSymbol(var P:PObjectSymbol);
  1156. var
  1157. Q : PObjectSymbol;
  1158. Nc,Des : integer;
  1159. begin
  1160. if not assigned(P) then
  1161. exit;
  1162. Des:=0;
  1163. While (NT<Item) and (Des<GetNumChildren(P)) do
  1164. begin
  1165. Q:=P^.GetDescendant(Des);
  1166. Inc(NT);
  1167. if NT=Item then
  1168. begin
  1169. P:=Q;
  1170. exit;
  1171. end;
  1172. Nc:=GetNumChildrenExposed(Q);
  1173. If NT+Nc<Item then
  1174. Inc(NT,Nc)
  1175. else
  1176. begin
  1177. FindSymbol(Q);
  1178. P:=Q;
  1179. exit;
  1180. end;
  1181. Inc(Des);
  1182. end;
  1183. end;
  1184. begin
  1185. P:=Root;
  1186. NT:=0;
  1187. FindSymbol(P);
  1188. GetLineNode:=P;
  1189. end;
  1190. function TSymbolInheritanceView.GetText(Item,MaxLen: Sw_Integer): String;
  1191. var
  1192. P,Ans : PObjectSymbol;
  1193. NC,NT,NumParents : Integer;
  1194. S : String;
  1195. procedure FindSymbol(var P:PObjectSymbol);
  1196. var
  1197. Q : PObjectSymbol;
  1198. Des : integer;
  1199. begin
  1200. if not assigned(P) then
  1201. exit;
  1202. Des:=0;
  1203. While (NT<Item) and (Des<GetNumChildren(P)) do
  1204. begin
  1205. Q:=P^.GetDescendant(Des);
  1206. Inc(NT);
  1207. if NT=Item then
  1208. begin
  1209. P:=Q;
  1210. exit;
  1211. end;
  1212. Nc:=GetNumChildrenExposed(Q);
  1213. If NT+Nc<Item then
  1214. Inc(NT,Nc)
  1215. else
  1216. begin
  1217. FindSymbol(Q);
  1218. P:=Q;
  1219. exit;
  1220. end;
  1221. Inc(Des);
  1222. end;
  1223. end;
  1224. begin
  1225. P:=Root;
  1226. NT:=0;
  1227. FindSymbol(P);
  1228. if assigned(P) then
  1229. begin
  1230. S:=P^.GetName;
  1231. Ans:=P^.Parent;
  1232. NumParents:=0;
  1233. While Assigned(Ans) do
  1234. begin
  1235. Inc(NumParents);
  1236. Ans:=Ans^.Parent;
  1237. end;
  1238. S:=CharStr('-',NumParents)+S;
  1239. GetText:=Copy(S,1,MaxLen);
  1240. end
  1241. else
  1242. GetText:='';
  1243. end;
  1244. {$endif HASOUTLINE}
  1245. procedure TSymbolInheritanceView.Selected(I: sw_Integer);
  1246. var P: pointer;
  1247. begin
  1248. P:=GetNode(I);
  1249. NodeSelected(P);
  1250. end;
  1251. procedure TSymbolInheritanceView.NodeSelected(P: pointer);
  1252. var
  1253. S: PSymbol;
  1254. St : String;
  1255. Anc: PObjectSymbol;
  1256. begin
  1257. if P=nil then Exit;
  1258. S:=PObjectSymbol(P)^.Symbol;
  1259. { this happens for the top objects view (PM) }
  1260. if S=nil then exit;
  1261. st:=S^.GetName;
  1262. if S^.Ancestor=nil then
  1263. Anc:=ObjectTree
  1264. else
  1265. Anc:=SearchObjectForSymbol(S^.Ancestor);
  1266. OpenSymbolBrowser(Origin.X-1,
  1267. {$ifdef HASOUTLINE}
  1268. FOC-Delta.Y+1,
  1269. {$else not HASOUTLINE}
  1270. Origin.Y+1,
  1271. {$endif not HASOUTLINE}
  1272. st,
  1273. S^.GetText,S,nil,
  1274. S^.Items,S^.References,Anc,S^.MemInfo);
  1275. end;
  1276. {****************************************************************************
  1277. TBrowserTab
  1278. ****************************************************************************}
  1279. constructor TBrowserTab.Init(var Bounds: TRect; AItems: PBrowserTabItem);
  1280. begin
  1281. inherited Init(Bounds);
  1282. Options:=Options or ofPreProcess;
  1283. Items:=AItems;
  1284. SetParams(0,0);
  1285. end;
  1286. procedure TBrowserTab.SetParams(AFlags: word; ACurrent: Sw_integer);
  1287. begin
  1288. Flags:=AFlags;
  1289. SelectItem(ACurrent);
  1290. end;
  1291. procedure TBrowserTab.SelectItem(Index: Sw_integer);
  1292. var P: PBrowserTabItem;
  1293. begin
  1294. Current:=Index;
  1295. P:=GetItem(Current);
  1296. if (P<>nil) and (P^.Link<>nil) then
  1297. P^.Link^.Focus;
  1298. DrawView;
  1299. end;
  1300. function TBrowserTab.GetItemCount: sw_integer;
  1301. var Count: integer;
  1302. P: PBrowserTabItem;
  1303. begin
  1304. Count:=0; P:=Items;
  1305. while (P<>nil) do
  1306. begin
  1307. Inc(Count);
  1308. P:=P^.Next;
  1309. end;
  1310. GetItemCount:=Count;
  1311. end;
  1312. function TBrowserTab.GetItem(Index: sw_integer): PBrowserTabItem;
  1313. var Counter: integer;
  1314. P: PBrowserTabItem;
  1315. begin
  1316. P:=Items;
  1317. Counter:=0;
  1318. while (P<>nil) and (Counter<Index) do
  1319. begin
  1320. P:=P^.Next;
  1321. Inc(Counter);
  1322. end;
  1323. GetItem:=P;
  1324. end;
  1325. procedure TBrowserTab.Draw;
  1326. var B: TDrawBuffer;
  1327. SelColor, NormColor, C: word;
  1328. I,CurX,Count: Sw_integer;
  1329. function Names(Idx: integer): char;
  1330. begin
  1331. Names:=GetItem(Idx)^.Sign;
  1332. end;
  1333. begin
  1334. NormColor:=GetColor(1); SelColor:=GetColor(2);
  1335. MoveChar(B,'Ä',SelColor,Size.X);
  1336. CurX:=0; Count:=0;
  1337. for I:=0 to GetItemCount-1 do
  1338. if (Flags and (1 shl I))<>0 then
  1339. begin
  1340. Inc(Count);
  1341. if Current=I then C:=SelColor
  1342. else C:=NormColor;
  1343. if Count=1 then MoveChar(B[CurX],'´',SelColor,1)
  1344. else MoveChar(B[CurX],'³',SelColor,1);
  1345. MoveCStr(B[CurX+1],' '+Names(I)+' ',C);
  1346. Inc(CurX,4);
  1347. end;
  1348. if Count>0 then
  1349. MoveChar(B[CurX],'Ã',SelColor,1);
  1350. WriteLine(0,0,Size.X,Size.Y,B);
  1351. end;
  1352. procedure TBrowserTab.HandleEvent(var Event: TEvent);
  1353. var I,Idx: integer;
  1354. DontClear: boolean;
  1355. P: TPoint;
  1356. function GetItemForCoord(X: integer): integer;
  1357. var I,CurX,Idx: integer;
  1358. begin
  1359. CurX:=0; Idx:=-1;
  1360. for I:=0 to GetItemCount-1 do
  1361. if (Flags and (1 shl I))<>0 then
  1362. begin
  1363. if (CurX+1<=X) and (X<=CurX+3) then
  1364. begin Idx:=I; Break; end;
  1365. Inc(CurX,4);
  1366. end;
  1367. GetItemForCoord:=Idx;
  1368. end;
  1369. begin
  1370. case Event.What of
  1371. evMouseDown :
  1372. if MouseInView(Event.Where) then
  1373. begin
  1374. repeat
  1375. MakeLocal(Event.Where,P);
  1376. Idx:=GetItemForCoord(P.X);
  1377. if Idx<>-1 then
  1378. SelectItem(Idx);
  1379. until not MouseEvent(Event, evMouseMove);
  1380. ClearEvent(Event);
  1381. end;
  1382. evKeyDown :
  1383. begin
  1384. DontClear:=false; Idx:=-1;
  1385. for I:=0 to GetItemCount-1 do
  1386. if (GetCtrlCode(GetItem(I)^.Sign)=Event.KeyCode){ or
  1387. (GetItem(I)^.Sign=UpCase(Event.CharCode))} then
  1388. if (Flags and (1 shl I))<>0 then
  1389. begin
  1390. Idx:=I;
  1391. Break;
  1392. end;
  1393. if Idx=-1 then
  1394. DontClear:=true
  1395. else
  1396. SelectItem(Idx);
  1397. if DontClear=false then ClearEvent(Event);
  1398. end;
  1399. end;
  1400. inherited HandleEvent(Event);
  1401. end;
  1402. function TBrowserTab.GetPalette: PPalette;
  1403. const P: string[length(CBrowserTab)] = CBrowserTab;
  1404. begin
  1405. GetPalette:=@P;
  1406. end;
  1407. destructor TBrowserTab.Done;
  1408. begin
  1409. if Items<>nil then DisposeBrowserTabList(Items);
  1410. inherited Done;
  1411. end;
  1412. procedure TUnitInfoPanel.HandleEvent(var Event: TEvent);
  1413. begin
  1414. if (Event.What=evBroadcast) and (Event.Command=cmListItemSelected) and
  1415. (InOwnerCall=false) then
  1416. begin
  1417. InOwnerCall:=true;
  1418. if Assigned(Owner) then
  1419. Owner^.HandleEvent(Event);
  1420. InOwnerCall:=false;
  1421. end;
  1422. inherited HandleEvent(Event);
  1423. end;
  1424. constructor TBrowserWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  1425. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  1426. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemINfo);
  1427. var R,R2,R3: TRect;
  1428. HSB,VSB: PScrollBar;
  1429. CST: PColorStaticText;
  1430. I: sw_integer;
  1431. function CreateVSB(R: TRect): PScrollBar;
  1432. var R2: TRect;
  1433. SB: PScrollBar;
  1434. begin
  1435. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  1436. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  1437. CreateVSB:=SB;
  1438. end;
  1439. function CreateHSB(R: TRect): PScrollBar;
  1440. var R2: TRect;
  1441. SB: PScrollBar;
  1442. begin
  1443. R2.Copy(R); R2.Move(0,1); R2.A.Y:=R2.B.Y-1;
  1444. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1445. CreateHSB:=SB;
  1446. end;
  1447. begin
  1448. inherited Init(Bounds, FormatStrStr(dialog_browse,ATitle), ANumber);
  1449. HelpCtx:=hcBrowserWindow;
  1450. Sym:=ASym;
  1451. Prefix:=NewStr(APrefix);
  1452. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+1;
  1453. {$ifndef NODEBUG}
  1454. if {assigned(Debugger) and Debugger^.IsRunning and}
  1455. assigned(Sym) and (Sym^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) then
  1456. begin
  1457. New(DebuggerValue,Init(ATitle,Sym));
  1458. New(ST, Init(R, ' '+DebuggerValue^.GetText));
  1459. end
  1460. else
  1461. {$endif NODEBUG}
  1462. begin
  1463. New(ST, Init(R, ' '+AName));
  1464. DebuggerValue:=nil;
  1465. end;
  1466. ST^.GrowMode:=gfGrowHiX;
  1467. Insert(ST);
  1468. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,2);
  1469. if assigned(ASymbols) and (ASymbols^.Count>0) then
  1470. begin
  1471. HSB:=CreateHSB(R);
  1472. Insert(HSB);
  1473. VSB:=CreateVSB(R);
  1474. Insert(VSB);
  1475. New(ScopeView, Init(R, ASymbols, HSB, VSB));
  1476. ScopeView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1477. Insert(ScopeView);
  1478. ScopeView^.MyBW:=@Self;
  1479. ScopeView^.SetGDBCol;
  1480. end;
  1481. if assigned(AReferences) and (AReferences^.Count>0) then
  1482. begin
  1483. HSB:=CreateHSB(R);
  1484. Insert(HSB);
  1485. VSB:=CreateVSB(R);
  1486. Insert(VSB);
  1487. New(ReferenceView, Init(R, AReferences, HSB, VSB));
  1488. ReferenceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1489. Insert(ReferenceView);
  1490. ReferenceView^.MyBW:=@Self;
  1491. end;
  1492. if assigned(AInheritance) then
  1493. begin
  1494. HSB:=CreateHSB(R);
  1495. Insert(HSB);
  1496. VSB:=CreateVSB(R);
  1497. Insert(VSB);
  1498. New(InheritanceView, Init(R, HSB,VSB, AInheritance));
  1499. InheritanceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1500. Insert(InheritanceView);
  1501. InheritanceView^.MyBW:=@Self;
  1502. end;
  1503. if assigned(AMemInfo) then
  1504. begin
  1505. New(MemInfoView, Init(R, AMemInfo));
  1506. MemInfoView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1507. Insert(MemInfoView);
  1508. MemInfoView^.MyBW:=@Self;
  1509. end;
  1510. if Assigned(Asym) and (TypeOf(ASym^)=TypeOf(TModuleSymbol)) then
  1511. with PModuleSymbol(Sym)^ do
  1512. begin
  1513. New(UnitInfo, Init(R));
  1514. UnitInfo^.GetExtent(R3);
  1515. R2.Copy(R3);
  1516. R2.B.Y:=R2.A.Y+3;
  1517. if (Assigned(UsedUnits) or Assigned(DependentUnits))=false then
  1518. R2.B.Y:=R3.B.Y;
  1519. HSB:=CreateHSB(R2); {UnitInfo^.Insert(HSB); HSB:=nil;}
  1520. VSB:=CreateVSB(R2);
  1521. {UnitInfo^.Insert(VSB);
  1522. VSB will be owned by UnitInfoText PM }
  1523. New(UnitInfoText, Init(R2,HSB,VSB, nil));
  1524. with UnitInfoText^ do
  1525. begin
  1526. GrowMode:=gfGrowHiX;
  1527. if Assigned(LoadedFrom) then
  1528. begin
  1529. AddLine(FormatStrStr2('%s : %s',msg_usedfirstin,GetStr(LoadedFrom)));
  1530. AddLine(FormatStrStr('%s : ',msg_mainsource));
  1531. AddLine(FormatStrStr(' %s',GetStr(MainSource)));
  1532. if Assigned(SourceFiles) and (SourceFiles^.Count>1) then
  1533. begin
  1534. AddLine(FormatStrStr('%s : ',msg_sourcefiles));
  1535. for I:=0 to SourceFiles^.Count-1 do
  1536. AddLine(FormatStrStr(' %s',GetStr(SourceFiles^.At(I))));
  1537. end;
  1538. end;
  1539. end;
  1540. UnitInfo^.Insert(UnitInfoText);
  1541. if Assigned(UsedUnits) then
  1542. begin
  1543. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  1544. New(CST, Init(R2,'´ Used units Ã'+CharStr('Ä',255),ColorIndex(12),false));
  1545. CST^.GrowMode:=gfGrowHiX;
  1546. UnitInfo^.Insert(CST);
  1547. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+4;
  1548. if Assigned(DependentUnits)=false then R2.B.Y:=R3.B.Y;
  1549. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  1550. HSB:=nil;
  1551. VSB:=CreateVSB(R2);
  1552. {UnitInfo^.Insert(VSB); this created crashes,
  1553. that were difficult to findout PM }
  1554. New(UnitInfoUsed, Init(R2,UsedUnits,HSB,VSB));
  1555. UnitInfoUsed^.GrowMode:=gfGrowHiY+gfGrowHiX;
  1556. UnitInfoUsed^.MyBW:=@Self;
  1557. UnitInfo^.Insert(UnitInfoUsed);
  1558. end;
  1559. if Assigned(DependentUnits) then
  1560. begin
  1561. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  1562. New(CST, Init(R2,'´ Dependent units Ã'+CharStr('Ä',255),ColorIndex(12),false));
  1563. CST^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1564. UnitInfo^.Insert(CST);
  1565. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R3.B.Y;
  1566. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  1567. HSB:=nil;
  1568. VSB:=CreateVSB(R2);
  1569. { UnitInfo^.Insert(VSB); this created crashes,
  1570. that were difficult to findout PM }
  1571. New(UnitInfoDependent, Init(R2,DependentUnits,HSB,VSB));
  1572. UnitInfoDependent^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1573. UnitInfoDependent^.MyBW:=@Self;
  1574. UnitInfo^.Insert(UnitInfoDependent);
  1575. end;
  1576. if Assigned(UnitInfoText) then
  1577. UnitInfoText^.Select;
  1578. Insert(UnitInfo);
  1579. end;
  1580. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.B.Y:=R.A.Y+1;
  1581. New(PageTab, Init(R,
  1582. NewBrowserTabItem(label_browsertab_scope,ScopeView,
  1583. NewBrowserTabItem(label_browsertab_reference,ReferenceView,
  1584. NewBrowserTabItem(label_browsertab_inheritance,InheritanceView,
  1585. NewBrowserTabItem(label_browsertab_memory,MemInfoView,
  1586. NewBrowserTabItem(label_browsertab_unit,UnitInfo,
  1587. nil)))))));
  1588. PageTab^.GrowMode:=gfGrowHiX;
  1589. Insert(PageTab);
  1590. if assigned(ScopeView) then
  1591. SelectTab(btScope)
  1592. else if assigned(ReferenceView) then
  1593. SelectTab(btReferences)
  1594. else if assigned(MemInfoView) then
  1595. SelectTab(btMemInfo)
  1596. else
  1597. if assigned(InheritanceView) then
  1598. SelectTab(btInheritance);
  1599. end;
  1600. destructor TBrowserWindow.Done;
  1601. begin
  1602. { UnitInfoText needs to be removed first
  1603. to avoid crashes within the UnitInfo destructor PM }
  1604. if Assigned(UnitInfoText) then
  1605. begin
  1606. UnitInfo^.Delete(UnitInfoText);
  1607. Dispose(UnitInfoText,Done);
  1608. UnitInfoText:=nil;
  1609. end;
  1610. if assigned(DebuggerValue) then
  1611. begin
  1612. Dispose(DebuggerValue,Done);
  1613. DebuggerValue:=nil;
  1614. end;
  1615. if assigned(Prefix) then
  1616. begin
  1617. DisposeStr(Prefix);
  1618. Prefix:=nil;
  1619. end;
  1620. inherited Done;
  1621. end;
  1622. procedure TBrowserWindow.HandleEvent(var Event: TEvent);
  1623. var DontClear: boolean;
  1624. S: PSymbol;
  1625. Symbols: PSymbolCollection;
  1626. Anc: PObjectSymbol;
  1627. P: TPoint;
  1628. begin
  1629. case Event.What of
  1630. evBroadcast :
  1631. case Event.Command of
  1632. cmDebuggerStopped :
  1633. begin
  1634. if Assigned(DebuggerValue) and
  1635. (DebuggerValue^.GDBI<>Event.InfoLong) then
  1636. begin
  1637. If Assigned(ST^.Text) then
  1638. DisposeStr(ST^.Text);
  1639. ST^.Text:=NewStr(DebuggerValue^.GetText);
  1640. ST^.DrawView;
  1641. end;
  1642. end;
  1643. cmSearchWindow :
  1644. ClearEvent(Event);
  1645. cmListItemSelected :
  1646. begin
  1647. S:=nil;
  1648. if (Event.InfoPtr=ScopeView) then
  1649. begin
  1650. S:=ScopeView^.Symbols^.At(ScopeView^.Focused);
  1651. MakeGlobal(ScopeView^.Origin,P);
  1652. Desktop^.MakeLocal(P,P); Inc(P.Y,ScopeView^.Focused-ScopeView^.TopItem);
  1653. Inc(P.Y);
  1654. end;
  1655. if (Event.InfoPtr=UnitInfoUsed) then
  1656. begin
  1657. S:=UnitInfoUsed^.Symbols^.At(UnitInfoUsed^.Focused);
  1658. MakeGlobal(UnitInfoUsed^.Origin,P);
  1659. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoUsed^.Focused-UnitInfoUsed^.TopItem);
  1660. Inc(P.Y);
  1661. end;
  1662. if (Event.InfoPtr=UnitInfoDependent) then
  1663. begin
  1664. S:=UnitInfoDependent^.Symbols^.At(UnitInfoDependent^.Focused);
  1665. MakeGlobal(UnitInfoDependent^.Origin,P);
  1666. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoDependent^.Focused-UnitInfoDependent^.TopItem);
  1667. Inc(P.Y);
  1668. end;
  1669. if Assigned(S) then
  1670. begin
  1671. if S^.Ancestor=nil then Anc:=nil else
  1672. Anc:=SearchObjectForSymbol(S^.Ancestor);
  1673. Symbols:=S^.Items;
  1674. if (not assigned(Symbols) or (symbols^.count=0)) then
  1675. if assigned(S^.Ancestor) then
  1676. Symbols:=S^.Ancestor^.Items;
  1677. if (S^.GetReferenceCount>0) or (assigned(Symbols) and (Symbols^.Count>0)) or (Anc<>nil) then
  1678. OpenSymbolBrowser(Origin.X-1,P.Y,
  1679. S^.GetName,
  1680. ScopeView^.GetText(ScopeView^.Focused,255),
  1681. S,@self,
  1682. Symbols,S^.References,Anc,S^.MemInfo);
  1683. end;
  1684. end;
  1685. end;
  1686. { evCommand :
  1687. begin
  1688. DontClear:=false;
  1689. case Event.Command of
  1690. cmGotoSymbol :
  1691. if Event.InfoPtr=ScopeView then
  1692. if ReferenceView<>nil then
  1693. if ReferenceView^.Range>0 then
  1694. ReferenceView^.GotoItem(0);
  1695. cmTrackSymbol :
  1696. if Event.InfoPtr=ScopeView then
  1697. if (ScopeView<>nil) and (ScopeView^.Range>0) then
  1698. begin
  1699. S:=ScopeView^.At(ScopeView^.Focused);
  1700. if (S^.References<>nil) and (S^.References^.Count>0) then
  1701. TrackItem(S^.References^.At(0));
  1702. else DontClear:=true;
  1703. end;
  1704. if DontClear=false then ClearEvent(Event);
  1705. end;}
  1706. evKeyDown :
  1707. begin
  1708. DontClear:=false;
  1709. case Event.KeyCode of
  1710. kbEsc :
  1711. Close;
  1712. kbAltI :
  1713. If not Disassemble then
  1714. DontClear:=true;
  1715. else DontClear:=true;
  1716. end;
  1717. if DontClear=false then ClearEvent(Event);
  1718. end;
  1719. end;
  1720. inherited HandleEvent(Event);
  1721. end;
  1722. function TBrowserWindow.Disassemble : boolean;
  1723. begin
  1724. Disassemble:=false;
  1725. if not assigned(sym) or (sym^.typ<>procsym) then
  1726. exit;
  1727. { We need to load exefile }
  1728. {$ifndef NODEBUG}
  1729. InitGDBWindow;
  1730. if not assigned(Debugger) then
  1731. begin
  1732. new(Debugger,Init);
  1733. if assigned(Debugger) then
  1734. Debugger^.SetExe(ExeFile);
  1735. end;
  1736. if not assigned(Debugger) or not Debugger^.HasExe then
  1737. exit;
  1738. { goto source/assembly mixture }
  1739. InitDisassemblyWindow;
  1740. DisassemblyWindow^.LoadFunction(Sym^.GetName);
  1741. DisassemblyWindow^.SelectInDebugSession;
  1742. Disassemble:=true;
  1743. {$else NODEBUG}
  1744. NoDebugger;
  1745. {$endif NODEBUG}
  1746. end;
  1747. procedure TBrowserWindow.SetState(AState: Word; Enable: Boolean);
  1748. {var OldState: word;}
  1749. begin
  1750. { OldState:=State;}
  1751. inherited SetState(AState,Enable);
  1752. { if ((State xor OldState) and sfActive)<>0 then
  1753. if GetState(sfActive)=false then
  1754. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);}
  1755. end;
  1756. procedure TBrowserWindow.Close;
  1757. begin
  1758. inherited Close;
  1759. end;
  1760. procedure TBrowserWindow.SelectTab(BrowserTab: Sw_integer);
  1761. var Tabs: Sw_integer;
  1762. {$ifndef NODEBUG}
  1763. PB : PBreakpoint;
  1764. {$endif}
  1765. PS :PString;
  1766. l : longint;
  1767. begin
  1768. case BrowserTab of
  1769. btScope :
  1770. if assigned(ScopeView) then
  1771. ScopeView^.Select;
  1772. btReferences :
  1773. if assigned(ReferenceView) then
  1774. ReferenceView^.Select;
  1775. btMemInfo:
  1776. if assigned(MemInfoView) then
  1777. MemInfoView^.Select;
  1778. {$ifndef NODEBUG}
  1779. btBreakWatch :
  1780. begin
  1781. if Assigned(Sym) then
  1782. begin
  1783. if Pos('proc',Sym^.GetText)>0 then
  1784. { insert function breakpoint }
  1785. begin
  1786. { make it visible }
  1787. PS:=Sym^.Name;
  1788. l:=Length(PS^);
  1789. If PS^[l]='*' then
  1790. begin
  1791. PB:=BreakpointsCollection^.GetType(bt_function,copy(GetStr(PS),1,l-1));
  1792. If Assigned(PB) then
  1793. BreakpointsCollection^.Delete(PB);
  1794. Sym^.Name:=NewStr(copy(GetStr(PS),1,l-1));
  1795. DrawView;
  1796. DisposeStr(PS);
  1797. end
  1798. else
  1799. begin
  1800. Sym^.Name:=NewStr(GetStr(PS)+'*');
  1801. DrawView;
  1802. New(PB,init_function(GetStr(PS)));
  1803. DisposeStr(PS);
  1804. BreakpointsCollection^.Insert(PB);
  1805. BreakpointsCollection^.Update;
  1806. end;
  1807. end
  1808. else if pos('var',Sym^.GetText)>0 then
  1809. { insert watch point }
  1810. begin
  1811. { make it visible }
  1812. PS:=Sym^.Name;
  1813. l:=Length(PS^);
  1814. If PS^[l]='*' then
  1815. begin
  1816. PB:=BreakpointsCollection^.GetType(bt_awatch,copy(PS^,1,l-1));
  1817. If Assigned(PB) then
  1818. BreakpointsCollection^.Delete(PB);
  1819. Sym^.Name:=NewStr(copy(PS^,1,l-1));
  1820. DrawView;
  1821. DisposeStr(PS);
  1822. end
  1823. else
  1824. begin
  1825. Sym^.Name:=NewStr(GetStr(PS)+'*');
  1826. DrawView;
  1827. New(PB,init_type(bt_awatch,GetStr(PS)));
  1828. DisposeStr(PS);
  1829. BreakpointsCollection^.Insert(PB);
  1830. BreakpointsCollection^.Update;
  1831. end;
  1832. end;
  1833. end;
  1834. end;
  1835. {$endif NODEBUG}
  1836. end;
  1837. Tabs:=0;
  1838. if assigned(ScopeView) then
  1839. Tabs:=Tabs or (1 shl btScope);
  1840. if assigned(ReferenceView) then
  1841. Tabs:=Tabs or (1 shl btReferences);
  1842. if assigned(InheritanceView) then
  1843. Tabs:=Tabs or (1 shl btInheritance);
  1844. if assigned(MemInfoView) then
  1845. Tabs:=Tabs or (1 shl btMemInfo);
  1846. {$ifndef NODEBUG}
  1847. if Assigned(Sym) then
  1848. if (Pos('proc',Sym^.GetText)>0) or (Pos('var',Sym^.GetText)>0) then
  1849. Tabs:=Tabs or (1 shl btBreakWatch);
  1850. {$endif NODEBUG}
  1851. if assigned(UnitInfo) then
  1852. Tabs:=Tabs or (1 shl btUnitInfo);
  1853. if PageTab<>nil then PageTab^.SetParams(Tabs,BrowserTab);
  1854. end;
  1855. function TBrowserWindow.GetPalette: PPalette;
  1856. const S: string[length(CBrowserWindow)] = CBrowserWindow;
  1857. begin
  1858. GetPalette:=@S;
  1859. end;
  1860. procedure OpenSymbolBrowser(X,Y: Sw_integer;const Name,Line: string;S : PSymbol;
  1861. ParentBrowser : PBrowserWindow;
  1862. Symbols: PSymbolCollection; References: PReferenceCollection;
  1863. Inheritance: PObjectSymbol; MemInfo: PSymbolMemInfo);
  1864. var R: TRect;
  1865. PB : PBrowserWindow;
  1866. St,st2 : string;
  1867. begin
  1868. if X=0 then X:=Desktop^.Size.X-35;
  1869. R.A.X:=X; R.A.Y:=Y;
  1870. R.B.X:=R.A.X+35; R.B.Y:=R.A.Y+15;
  1871. while (R.B.Y>Desktop^.Size.Y) do R.Move(0,-1);
  1872. if assigned(ParentBrowser) and assigned(ParentBrowser^.Prefix) and
  1873. assigned(ParentBrowser^.sym) and
  1874. (ParentBrowser^.sym^.typ<>unitsym)
  1875. then
  1876. begin
  1877. st:=GetStr(ParentBrowser^.Prefix)+' '+Name;
  1878. end
  1879. else
  1880. st:=Name;
  1881. st2:=st;
  1882. if assigned(S) and ((S^.Flags and sfPointer)<>0) then
  1883. begin
  1884. st:=st+'^';
  1885. if assigned(S^.Ancestor) and
  1886. ((S^.Ancestor^.Flags and sfRecord)<>0) then
  1887. st:=st+'.';
  1888. end
  1889. else if assigned(S) and ((S^.Flags and sfRecord)<>0) then
  1890. st:=st+'.';
  1891. PB:=New(PBrowserWindow, Init(R,
  1892. st2,SearchFreeWindowNo,S,Line,st,
  1893. Symbols,References,Inheritance,MemInfo));
  1894. if (assigned(S) and (S^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym])) or
  1895. (assigned(ParentBrowser) and ParentBrowser^.IsValid) then
  1896. PB^.IsValid:=true;
  1897. Desktop^.Insert(PB);
  1898. end;
  1899. END.