fpsymbol.pas 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066
  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);
  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(TCallbackProcParam(@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(TCallbackFunBoolParam(@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. { avoid infinite recursion here }
  500. GDBI:=Debugger^.RunCount;
  501. p:=Debugger^.GetValue(Expr^);
  502. St:=NewStr(GetPChar(p));
  503. if assigned(p) then
  504. StrDispose(p);
  505. end;
  506. {$endif ndef NODEBUG}
  507. {$endif BROWSERCOL}
  508. end;
  509. function TGDBValue.GetText : String;
  510. begin
  511. GetValue;
  512. if assigned(St) then
  513. GetText:=S^.GetText+' = '+GetStr(St)
  514. else
  515. GetText:=S^.GetText;
  516. end;
  517. {****************************************************************************
  518. TGDBValueCollection
  519. ****************************************************************************}
  520. function TGDBValueCollection.At(Index: sw_Integer): PGDBValue;
  521. begin
  522. At:= Inherited At(Index);
  523. end;
  524. {****************************************************************************
  525. TSymbolView
  526. ****************************************************************************}
  527. constructor TSymbolView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  528. begin
  529. inherited Init(Bounds,1,AVScrollBar);
  530. HScrollBar:=AHScrollBar;
  531. MyBW:=nil;
  532. if assigned(HScrollBar) then
  533. begin
  534. HScrollBar^.SetRange(1,80);
  535. end;
  536. Options:=Options or (ofSelectable+ofTopSelect);
  537. EventMask:=EventMask or evBroadcast;
  538. end;
  539. procedure TSymbolView.ClearHighlights;
  540. begin
  541. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  542. end;
  543. procedure TSymbolView.AutoTrackSource;
  544. begin
  545. if Range>0 then
  546. TrackSource;
  547. end;
  548. procedure TSymbolView.OptionsDlg;
  549. begin
  550. { Abstract }
  551. end;
  552. destructor TSymbolView.Done;
  553. begin
  554. EventMask:=EventMask and not evBroadcast;
  555. Inherited Done;
  556. end;
  557. procedure TSymbolView.SetState(AState: Word; Enable: Boolean);
  558. var OState: longint;
  559. begin
  560. OState:=State;
  561. inherited SetState(AState,Enable);
  562. if ((OState xor State) and sfFocused)<>0 then
  563. if GetState(sfFocused) then
  564. begin
  565. if (MiscOptions and moAutoTrackSource)<>0 then
  566. AutoTrackSource;
  567. end
  568. else
  569. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);
  570. end;
  571. procedure TSymbolView.Browse;
  572. begin
  573. SelectItem(Focused);
  574. end;
  575. procedure TSymbolView.GotoSource;
  576. begin
  577. if GotoItem(Focused) then
  578. PutCommand(Owner,evCommand,cmClose,nil);
  579. end;
  580. procedure TSymbolView.TrackSource;
  581. begin
  582. TrackItem(Focused,false);
  583. end;
  584. procedure TSymbolView.HandleEvent(var Event: TEvent);
  585. var DontClear: boolean;
  586. begin
  587. case Event.What of
  588. evKeyDown :
  589. begin
  590. DontClear:=false;
  591. case Event.KeyCode of
  592. kbEnter :
  593. Browse;
  594. kbCtrlEnter :
  595. GotoSource;
  596. kbSpaceBar :
  597. TrackSource;
  598. kbRight,kbLeft :
  599. if HScrollBar<>nil then
  600. HScrollBar^.HandleEvent(Event);
  601. else DontClear:=true;
  602. end;
  603. if DontClear=false then ClearEvent(Event);
  604. end;
  605. evMouseDown :
  606. begin
  607. if Event.double then
  608. begin
  609. Browse;
  610. ClearEvent(Event);
  611. end;
  612. end;
  613. evCommand :
  614. begin
  615. DontClear:=false;
  616. case Event.Command of
  617. cmSymBrowse :
  618. Browse;
  619. cmSymGotoSource :
  620. GotoSource;
  621. cmSymTrackSource :
  622. TrackSource;
  623. cmSymOptions :
  624. OptionsDlg;
  625. else DontClear:=true;
  626. end;
  627. if DontClear=false then ClearEvent(Event);
  628. end;
  629. evBroadcast :
  630. case Event.Command of
  631. cmListFocusChanged :
  632. if Event.InfoPtr=@Self then
  633. if (MiscOptions and moAutoTrackSource)<>0 then
  634. if GetState(sfFocused) then
  635. AutoTrackSource;
  636. end;
  637. end;
  638. inherited HandleEvent(Event);
  639. end;
  640. function TSymbolView.GetPalette: PPalette;
  641. const
  642. P: string[length(CBrowserListBox)] = CBrowserListBox;
  643. begin
  644. GetPalette:=@P;
  645. end;
  646. function TSymbolView.GetLocalMenu: PMenu;
  647. begin
  648. GetLocalMenu:=NewMenu(
  649. NewItem(menu_symlocal_browse,'',kbNoKey,cmSymBrowse,hcSymBrowse,
  650. NewItem(menu_symlocal_gotosource,'',kbNoKey,cmSymGotoSource,hcSymGotoSource,
  651. NewItem(menu_symlocal_tracksource,'',kbNoKey,cmSymTrackSource,hcSymTrackSource,
  652. NewLine(
  653. NewItem(menu_symlocal_options,'',kbNoKey,cmSymOptions,hcSymOptions,
  654. nil))))));
  655. end;
  656. function TSymbolView.GotoItem(Item: sw_integer): boolean;
  657. begin
  658. SelectItem(Item);
  659. GotoItem:=true;
  660. end;
  661. function TSymbolView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  662. begin
  663. SelectItem(Item);
  664. TrackItem:=true;
  665. end;
  666. function LastBrowserWindow: PBrowserWindow;
  667. var BW: PBrowserWindow;
  668. procedure IsBW(P: PView);
  669. begin
  670. if (P^.HelpCtx=hcBrowserWindow) then
  671. BW:=pointer(P);
  672. end;
  673. begin
  674. BW:=nil;
  675. Desktop^.ForEach(TCallbackProcParam(@IsBW));
  676. LastBrowserWindow:=BW;
  677. end;
  678. function TSymbolView.TrackReference(R: PReference; AutoTrack: boolean): boolean;
  679. var W: PSourceWindow;
  680. BW: PBrowserWindow;
  681. P: TPoint;
  682. begin
  683. ClearHighlights;
  684. Desktop^.Lock;
  685. P.X:=R^.Position.X-1; P.Y:=R^.Position.Y-1;
  686. if AutoTrack then
  687. W:=SearchOnDesktop(R^.GetFileName,false)
  688. else
  689. W:=TryToOpenFile(nil,R^.GetFileName,P.X,P.Y,true);
  690. if not assigned(W) then
  691. begin
  692. Desktop^.Unlock;
  693. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  694. begin
  695. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  696. if Assigned(W) then
  697. W^.Select;
  698. end;
  699. Desktop^.Lock;
  700. end;
  701. if W<>nil then
  702. begin
  703. BW:=LastBrowserWindow;
  704. if BW=nil then
  705. W^.Select
  706. else
  707. begin
  708. Desktop^.Delete(W);
  709. Desktop^.InsertBefore(W,BW^.NextView);
  710. end;
  711. W^.Editor^.SetLineFlagExclusive(lfHighlightRow,P.Y);
  712. end;
  713. Desktop^.UnLock;
  714. if Assigned(W)=false then
  715. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  716. TrackReference:=W<>nil;
  717. end;
  718. function TSymbolView.GotoReference(R: PReference): boolean;
  719. var W: PSourceWindow;
  720. begin
  721. Desktop^.Lock;
  722. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  723. if Assigned(W) then
  724. W^.Select
  725. else
  726. begin
  727. Desktop^.Unlock;
  728. if IDEApp.OpenSearch(R^.GetFileName+'*') then
  729. begin
  730. W:=TryToOpenFile(nil,R^.GetFileName,R^.Position.X-1,R^.Position.Y-1,true);
  731. if Assigned(W) then
  732. W^.Select;
  733. end;
  734. Desktop^.Lock;
  735. end;
  736. Desktop^.UnLock;
  737. if Assigned(W)=false then
  738. ErrorBox(FormatStrStr(msg_cantfindfile,R^.GetFileName),nil);
  739. GotoReference:=W<>nil;
  740. end;
  741. {****************************************************************************
  742. TSymbolScopeView
  743. ****************************************************************************}
  744. constructor TSymbolScopeView.Init(var Bounds: TRect; ASymbols: PSymbolCollection; AHScrollBar, AVScrollBar: PScrollBar);
  745. begin
  746. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  747. Symbols:=ASymbols;
  748. NewList(ASymbols);
  749. New(SymbolsValue,Init(50,50));
  750. SetRange(Symbols^.Count);
  751. end;
  752. destructor TSymbolScopeView.Done;
  753. begin
  754. {if assigned(Symbols) then
  755. begin
  756. the elements belong to other lists
  757. Symbols^.DeleteAll;
  758. dispose(Symbols,done);
  759. end;}
  760. if Assigned(SymbolsValue) then
  761. begin
  762. Dispose(SymbolsValue,Done);
  763. SymbolsValue:=nil;
  764. end;
  765. Inherited Done;
  766. end;
  767. procedure TSymbolScopeView.HandleEvent(var Event: TEvent);
  768. var OldFocus: sw_integer;
  769. begin
  770. case Event.What of
  771. evKeyDown :
  772. case Event.KeyCode of
  773. kbBack :
  774. begin
  775. LookUp(copy(LookUpStr,1,length(LookUpStr)-1));
  776. ClearEvent(Event);
  777. end;
  778. else
  779. if Event.CharCode in[#33..#255] then
  780. begin
  781. LookUp(LookUpStr+Event.CharCode);
  782. ClearEvent(Event);
  783. end;
  784. end;
  785. end;
  786. OldFocus:=Focused;
  787. inherited HandleEvent(Event);
  788. if OldFocus<>Focused then
  789. Lookup('');
  790. end;
  791. procedure TSymbolScopeView.Draw;
  792. var DeltaX: sw_integer;
  793. begin
  794. inherited Draw;
  795. if Assigned(HScrollBar)=false then DeltaX:=0 else
  796. DeltaX:=HScrollBar^.Value-HScrollBar^.Min;
  797. SetCursor(2+SymbolTypLen+length(LookUpStr)-DeltaX,Focused-TopItem);
  798. end;
  799. procedure TSymbolScopeView.LookUp(S: string);
  800. var Idx,Slength: Sw_integer;
  801. NS: string;
  802. begin
  803. NS:=LookUpStr;
  804. Slength:=Length(S);
  805. if (Symbols=nil) or (S='') then NS:='' else
  806. begin
  807. S:=Symbols^.LookUp(S,Idx);
  808. if Idx<>-1 then
  809. begin
  810. NS:=S;
  811. FocusItem(Idx);
  812. end;
  813. end;
  814. LookUpStr:=Copy(NS,1,Slength);
  815. SetState(sfCursorVis,LookUpStr<>'');
  816. DrawView;
  817. end;
  818. function TSymbolScopeView.GotoItem(Item: sw_integer): boolean;
  819. var S: PSymbol;
  820. OK: boolean;
  821. begin
  822. OK:=Range>0;
  823. if OK then
  824. begin
  825. S:=List^.At(Item);
  826. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  827. if OK then
  828. OK:=GotoReference(S^.References^.At(0));
  829. end;
  830. GotoItem:=OK;
  831. end;
  832. function TSymbolScopeView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  833. var S: PSymbol;
  834. OK: boolean;
  835. begin
  836. OK:=Range>0;
  837. if OK then
  838. begin
  839. S:=List^.At(Item);
  840. OK:=(S^.References<>nil) and (S^.References^.Count>0);
  841. if OK then
  842. OK:=TrackReference(S^.References^.At(0),AutoTrack);
  843. end;
  844. TrackItem:=OK;
  845. end;
  846. procedure TSymbolScopeView.SetGDBCol;
  847. var S : PSymbol;
  848. I : sw_integer;
  849. begin
  850. if assigned(MyBW) and (SymbolsValue^.Count=0) then
  851. begin
  852. For i:=0 to Symbols^.Count-1 do
  853. begin
  854. S:=Symbols^.At(I);
  855. SymbolsValue^.Insert(New(PGDBValue,Init(GetStr(MyBW^.Prefix)+S^.GetName,S)));
  856. end;
  857. end;
  858. end;
  859. function TSymbolScopeView.GetText(Item,MaxLen: Sw_Integer): String;
  860. var S1: string;
  861. S : PSymbol;
  862. SG : PGDBValue;
  863. begin
  864. S:=Symbols^.At(Item);
  865. if Assigned(SymbolsValue) and (SymbolsValue^.Count>Item) then
  866. SG:=SymbolsValue^.At(Item)
  867. else
  868. SG:=nil;
  869. if assigned(SG) then
  870. S1:=SG^.getText
  871. else
  872. S1:=S^.GetText;
  873. GetText:=copy(S1,1,MaxLen);
  874. end;
  875. {****************************************************************************
  876. TSymbolReferenceView
  877. ****************************************************************************}
  878. constructor TSymbolReferenceView.Init(var Bounds: TRect; AReferences: PReferenceCollection;
  879. AHScrollBar, AVScrollBar: PScrollBar);
  880. begin
  881. inherited Init(Bounds,AHScrollBar, AVScrollBar);
  882. References:=AReferences;
  883. NewList(AReferences);
  884. SetRange(References^.Count);
  885. end;
  886. destructor TSymbolReferenceView.Done;
  887. begin
  888. Inherited Done;
  889. end;
  890. procedure TSymbolReferenceView.HandleEvent(var Event: TEvent);
  891. var OldFocus: sw_integer;
  892. DontClear: boolean;
  893. begin
  894. OldFocus:=Focused;
  895. case Event.What of
  896. evKeyDown :
  897. begin
  898. DontClear:=false;
  899. case Event.KeyCode of
  900. kbEnter :
  901. TrackItem(Focused,false);
  902. kbCtrlEnter :
  903. GotoItem(Focused);
  904. else DontClear:=true;
  905. end;
  906. if DontClear=false then ClearEvent(Event);
  907. end;
  908. end;
  909. inherited HandleEvent(Event);
  910. if OldFocus<>Focused then
  911. if (MiscOptions and moAutoTrackSource)=0 then
  912. ClearHighlights;
  913. end;
  914. procedure TSymbolReferenceView.Browse;
  915. begin
  916. { do nothing here }
  917. end;
  918. function TSymbolReferenceView.GetText(Item,MaxLen: Sw_Integer): String;
  919. var S: string;
  920. P: PReference;
  921. begin
  922. P:=References^.At(Item);
  923. S:=P^.GetFileName+'('+IntToStr(P^.Position.Y)+','+IntToStr(P^.Position.X)+')';
  924. GetText:=copy(S,1,MaxLen);
  925. end;
  926. function TSymbolReferenceView.GotoItem(Item: sw_integer): boolean;
  927. var OK: boolean;
  928. begin
  929. OK:=Range>0;
  930. if OK then
  931. OK:=GotoReference(List^.At(Item));
  932. GotoItem:=OK;
  933. end;
  934. function TSymbolReferenceView.TrackItem(Item: sw_integer; AutoTrack: boolean): boolean;
  935. var OK: boolean;
  936. begin
  937. OK:=Range>0;
  938. if OK then
  939. OK:=TrackReference(List^.At(Item),AutoTrack);
  940. TrackItem:=OK;
  941. end;
  942. procedure TSymbolReferenceView.SelectItem(Item: Sw_Integer);
  943. begin
  944. GotoItem(Item);
  945. end;
  946. constructor TSymbolMemInfoView.Init(var Bounds: TRect; AMemInfo: PSymbolMemInfo);
  947. begin
  948. inherited Init(Bounds,'');
  949. Options:=Options or (ofSelectable+ofTopSelect);
  950. MemInfo:=AMemInfo;
  951. MyBW:=nil;
  952. end;
  953. destructor TSymbolMemInfoView.Done;
  954. begin
  955. { if assigned(MemInfo) then
  956. dispose(MemInfo);}
  957. Inherited Done;
  958. end;
  959. procedure TSymbolMemInfoView.GetText(var S: String);
  960. function SizeStr(Size: longint): string;
  961. var S: string[40];
  962. begin
  963. S:=IntToStrL(Size,7);
  964. S:=S+' byte';
  965. if Size>1 then S:=S+'s';
  966. if Size=-1 then
  967. SizeStr:='variable'
  968. else
  969. SizeStr:=S;
  970. end;
  971. function AddrStr(Addr: longint): string;
  972. { Warning this is endian specific code !! (PM) }
  973. type TLongint = record LoW,HiW: word; end;
  974. begin
  975. with TLongint(Addr) do
  976. AddrStr:='$'+hexstr(HiW,4)+hexstr(LoW,4);
  977. end;
  978. begin
  979. ClearFormatParams;
  980. AddFormatParamStr(msg_sizeinmemory);
  981. AddFormatParamStr(msg_sizeonstack);
  982. S:=
  983. FormatStrF(
  984. #13+
  985. { ' Memory location: '+AddrStr(MemInfo^.Addr)+#13+
  986. ' Local address: '+AddrStr(MemInfo^.LocalAddr)+#13+}
  987. { ??? internal linker ??? }
  988. '%18s: '+SizeStr(MemInfo^.Size)+#13+
  989. '%18s: '+SizeStr(MemInfo^.PushSize)+#13+
  990. '',
  991. FormatParams);
  992. end;
  993. function TSymbolMemInfoView.GetPalette: PPalette;
  994. begin
  995. GetPalette:=inherited GetPalette;
  996. end;
  997. function TSymbolMemoView.GetPalette: PPalette;
  998. const P: string[length(CFPSymbolMemo)] = CFPSymbolMemo;
  999. begin
  1000. GetPalette:=@P;
  1001. end;
  1002. {****************************************************************************
  1003. TSymbolInheritanceView
  1004. ****************************************************************************}
  1005. constructor TSymbolInheritanceView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar; ARoot: PObjectSymbol);
  1006. begin
  1007. {$ifdef HASOUTLINE}
  1008. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  1009. {$else not HASOUTLINE}
  1010. inherited Init(Bounds,1,AVScrollBar);
  1011. HScrollBar:=AHScrollBar;
  1012. {$endif not HASOUTLINE}
  1013. Options:=Options or (ofSelectable+ofTopSelect);
  1014. Root:=ARoot;
  1015. MyBW:=nil;
  1016. ExpandAll(Root);
  1017. {$ifdef HASOUTLINE}
  1018. Update;
  1019. {$else not HASOUTLINE}
  1020. SetRange(GetNumChildrenExposed(Root));
  1021. {$endif not HASOUTLINE}
  1022. end;
  1023. destructor TSymbolInheritanceView.Done;
  1024. begin
  1025. { do not dispose,
  1026. belongs to a symbolcollection (PM)
  1027. if assigned(Root) then
  1028. dispose(Root,done); }
  1029. Inherited Done;
  1030. end;
  1031. function TSymbolInheritanceView.GetRoot: Pointer;
  1032. begin
  1033. GetRoot:=Root;
  1034. end;
  1035. function TSymbolInheritanceView.HasChildren(Node: Pointer): Boolean;
  1036. begin
  1037. HasChildren:=GetNumChildren(Node)>0;
  1038. end;
  1039. function TSymbolInheritanceView.GetChild(Node: Pointer; I: sw_Integer): Pointer;
  1040. begin
  1041. GetChild:=PObjectSymbol(Node)^.GetDescendant(I);
  1042. end;
  1043. function TSymbolInheritanceView.GetNumChildren(Node: Pointer): sw_Integer;
  1044. begin
  1045. GetNumChildren:=PObjectSymbol(Node)^.GetDescendantCount;
  1046. end;
  1047. function TSymbolInheritanceView.GetNumChildrenExposed(Node: Pointer) : sw_Integer;
  1048. var
  1049. Nb : integer;
  1050. P : PObjectSymbol;
  1051. Procedure AddCount(P : PObjectSymbol);
  1052. var
  1053. i,count : integer;
  1054. D : PObjectSymbol;
  1055. begin
  1056. if not assigned(P) then
  1057. exit;
  1058. Count:=P^.GetDescendantCount;
  1059. Inc(Nb,Count);
  1060. for I:=0 to Count-1 do
  1061. begin
  1062. D:=P^.GetDescendant(I);
  1063. AddCount(D);
  1064. end;
  1065. end;
  1066. begin
  1067. Nb:=0;
  1068. AddCount(Node);
  1069. GetNumChildrenExposed:=Nb;
  1070. end;
  1071. procedure TSymbolInheritanceView.Adjust(Node: Pointer; Expand: Boolean);
  1072. begin
  1073. PObjectSymbol(Node)^.Expanded:=Expand;
  1074. end;
  1075. function TSymbolInheritanceView.IsExpanded(Node: Pointer): Boolean;
  1076. begin
  1077. IsExpanded:=PObjectSymbol(Node)^.Expanded;
  1078. end;
  1079. procedure TSymbolInheritanceView.HandleEvent(var Event: TEvent);
  1080. var DontClear: boolean;
  1081. {$ifndef HASOUTLINE}
  1082. P: TPoint;
  1083. {$endif HASOUTLINE}
  1084. begin
  1085. case Event.What of
  1086. evKeyDown :
  1087. begin
  1088. DontClear:=false;
  1089. case Event.KeyCode of
  1090. {$ifndef HASOUTLINE}
  1091. kbEnter:
  1092. NodeSelected(GetLineNode(Cursor.Y-Origin.Y));
  1093. {$endif HASOUTLINE}
  1094. kbLeft,kbRight,
  1095. kbCtrlLeft,kbCtrlRight :
  1096. if Assigned(HScrollBar) then
  1097. HScrollBar^.HandleEvent(Event)
  1098. else
  1099. DontClear:=true;
  1100. else DontClear:=true;
  1101. end;
  1102. if DontClear=false then ClearEvent(Event);
  1103. end;
  1104. evMouseDown :
  1105. begin
  1106. {$ifndef HASOUTLINE}
  1107. MakeLocal(Event.Where,P);
  1108. SetCursor(P.X,P.Y);
  1109. {$endif HASOUTLINE}
  1110. if Event.double then
  1111. begin
  1112. Message(@Self,evKeyDown,kbEnter,nil);
  1113. ClearEvent(Event);
  1114. end;
  1115. end;
  1116. end;
  1117. inherited HandleEvent(Event);
  1118. end;
  1119. function TSymbolInheritanceView.GetPalette: PPalette;
  1120. const P: string[length(CBrowserOutline)] = CBrowserOutline;
  1121. begin
  1122. GetPalette:=@P;
  1123. end;
  1124. {$ifdef HASOUTLINE}
  1125. function TSymbolInheritanceView.GetText(Node: Pointer): String;
  1126. begin
  1127. GetText:=PObjectSymbol(Node)^.GetName;
  1128. end;
  1129. {$else not HASOUTLINE}
  1130. function TSymbolInheritanceView.GetNode(I : sw_Integer) : Pointer;
  1131. var
  1132. P : PObjectSymbol;
  1133. begin
  1134. P:=Root;
  1135. If Assigned(P) then
  1136. P:=P^.GetDescendant(I);
  1137. GetNode:=Pointer(P);
  1138. end;
  1139. procedure TSymbolInheritanceView.ExpandAll(Node: Pointer);
  1140. var
  1141. i : integer;
  1142. P : Pointer;
  1143. begin
  1144. Adjust(Node,true);
  1145. For i:=0 to GetNumChildren(Node)-1 do
  1146. begin
  1147. P:=GetChild(Node,I);
  1148. if Assigned(P) then
  1149. ExpandAll(P);
  1150. end;
  1151. end;
  1152. function TSymbolInheritanceView.GetLineNode(Item : sw_Integer) : Pointer;
  1153. var
  1154. P : PObjectSymbol;
  1155. NT: Integer;
  1156. procedure FindSymbol(var P:PObjectSymbol);
  1157. var
  1158. Q : PObjectSymbol;
  1159. Nc,Des : integer;
  1160. begin
  1161. if not assigned(P) then
  1162. exit;
  1163. Des:=0;
  1164. While (NT<Item) and (Des<GetNumChildren(P)) do
  1165. begin
  1166. Q:=P^.GetDescendant(Des);
  1167. Inc(NT);
  1168. if NT=Item then
  1169. begin
  1170. P:=Q;
  1171. exit;
  1172. end;
  1173. Nc:=GetNumChildrenExposed(Q);
  1174. If NT+Nc<Item then
  1175. Inc(NT,Nc)
  1176. else
  1177. begin
  1178. FindSymbol(Q);
  1179. P:=Q;
  1180. exit;
  1181. end;
  1182. Inc(Des);
  1183. end;
  1184. end;
  1185. begin
  1186. P:=Root;
  1187. NT:=0;
  1188. FindSymbol(P);
  1189. GetLineNode:=P;
  1190. end;
  1191. function TSymbolInheritanceView.GetText(Item,MaxLen: Sw_Integer): String;
  1192. var
  1193. P,Ans : PObjectSymbol;
  1194. NC,NT,NumParents : Integer;
  1195. S : String;
  1196. procedure FindSymbol(var P:PObjectSymbol);
  1197. var
  1198. Q : PObjectSymbol;
  1199. Des : integer;
  1200. begin
  1201. if not assigned(P) then
  1202. exit;
  1203. Des:=0;
  1204. While (NT<Item) and (Des<GetNumChildren(P)) do
  1205. begin
  1206. Q:=P^.GetDescendant(Des);
  1207. Inc(NT);
  1208. if NT=Item then
  1209. begin
  1210. P:=Q;
  1211. exit;
  1212. end;
  1213. Nc:=GetNumChildrenExposed(Q);
  1214. If NT+Nc<Item then
  1215. Inc(NT,Nc)
  1216. else
  1217. begin
  1218. FindSymbol(Q);
  1219. P:=Q;
  1220. exit;
  1221. end;
  1222. Inc(Des);
  1223. end;
  1224. end;
  1225. begin
  1226. P:=Root;
  1227. NT:=0;
  1228. FindSymbol(P);
  1229. if assigned(P) then
  1230. begin
  1231. S:=P^.GetName;
  1232. Ans:=P^.Parent;
  1233. NumParents:=0;
  1234. While Assigned(Ans) do
  1235. begin
  1236. Inc(NumParents);
  1237. Ans:=Ans^.Parent;
  1238. end;
  1239. S:=CharStr('-',NumParents)+S;
  1240. GetText:=Copy(S,1,MaxLen);
  1241. end
  1242. else
  1243. GetText:='';
  1244. end;
  1245. {$endif HASOUTLINE}
  1246. procedure TSymbolInheritanceView.Selected(I: sw_Integer);
  1247. var P: pointer;
  1248. begin
  1249. P:=GetNode(I);
  1250. NodeSelected(P);
  1251. end;
  1252. procedure TSymbolInheritanceView.NodeSelected(P: pointer);
  1253. var
  1254. S: PSymbol;
  1255. St : String;
  1256. Anc: PObjectSymbol;
  1257. begin
  1258. if P=nil then Exit;
  1259. S:=PObjectSymbol(P)^.Symbol;
  1260. { this happens for the top objects view (PM) }
  1261. if S=nil then exit;
  1262. st:=S^.GetName;
  1263. if S^.Ancestor=nil then
  1264. Anc:=ObjectTree
  1265. else
  1266. Anc:=SearchObjectForSymbol(S^.Ancestor);
  1267. OpenSymbolBrowser(Origin.X-1,
  1268. {$ifdef HASOUTLINE}
  1269. FOC-Delta.Y+1,
  1270. {$else not HASOUTLINE}
  1271. Origin.Y+1,
  1272. {$endif not HASOUTLINE}
  1273. st,
  1274. S^.GetText,S,nil,
  1275. S^.Items,S^.References,Anc,S^.MemInfo);
  1276. end;
  1277. {****************************************************************************
  1278. TBrowserTab
  1279. ****************************************************************************}
  1280. constructor TBrowserTab.Init(var Bounds: TRect; AItems: PBrowserTabItem);
  1281. begin
  1282. inherited Init(Bounds);
  1283. Options:=Options or ofPreProcess;
  1284. Items:=AItems;
  1285. SetParams(0,0);
  1286. end;
  1287. procedure TBrowserTab.SetParams(AFlags: word; ACurrent: Sw_integer);
  1288. begin
  1289. Flags:=AFlags;
  1290. SelectItem(ACurrent);
  1291. end;
  1292. procedure TBrowserTab.SelectItem(Index: Sw_integer);
  1293. var P: PBrowserTabItem;
  1294. begin
  1295. Current:=Index;
  1296. P:=GetItem(Current);
  1297. if (P<>nil) and (P^.Link<>nil) then
  1298. P^.Link^.Focus;
  1299. DrawView;
  1300. end;
  1301. function TBrowserTab.GetItemCount: sw_integer;
  1302. var Count: integer;
  1303. P: PBrowserTabItem;
  1304. begin
  1305. Count:=0; P:=Items;
  1306. while (P<>nil) do
  1307. begin
  1308. Inc(Count);
  1309. P:=P^.Next;
  1310. end;
  1311. GetItemCount:=Count;
  1312. end;
  1313. function TBrowserTab.GetItem(Index: sw_integer): PBrowserTabItem;
  1314. var Counter: integer;
  1315. P: PBrowserTabItem;
  1316. begin
  1317. P:=Items;
  1318. Counter:=0;
  1319. while (P<>nil) and (Counter<Index) do
  1320. begin
  1321. P:=P^.Next;
  1322. Inc(Counter);
  1323. end;
  1324. GetItem:=P;
  1325. end;
  1326. procedure TBrowserTab.Draw;
  1327. var B: TDrawBuffer;
  1328. SelColor, NormColor, C: word;
  1329. I,CurX,Count: Sw_integer;
  1330. function Names(Idx: integer): char;
  1331. begin
  1332. Names:=GetItem(Idx)^.Sign;
  1333. end;
  1334. begin
  1335. NormColor:=GetColor(1); SelColor:=GetColor(2);
  1336. MoveChar(B,'Ä',SelColor,Size.X);
  1337. CurX:=0; Count:=0;
  1338. for I:=0 to GetItemCount-1 do
  1339. if (Flags and (1 shl I))<>0 then
  1340. begin
  1341. Inc(Count);
  1342. if Current=I then C:=SelColor
  1343. else C:=NormColor;
  1344. if Count=1 then MoveChar(B[CurX],'´',SelColor,1)
  1345. else MoveChar(B[CurX],'³',SelColor,1);
  1346. MoveCStr(B[CurX+1],' '+Names(I)+' ',C);
  1347. Inc(CurX,4);
  1348. end;
  1349. if Count>0 then
  1350. MoveChar(B[CurX],'Ã',SelColor,1);
  1351. WriteLine(0,0,Size.X,Size.Y,B);
  1352. end;
  1353. procedure TBrowserTab.HandleEvent(var Event: TEvent);
  1354. var I,Idx: integer;
  1355. DontClear: boolean;
  1356. P: TPoint;
  1357. function GetItemForCoord(X: integer): integer;
  1358. var I,CurX,Idx: integer;
  1359. begin
  1360. CurX:=0; Idx:=-1;
  1361. for I:=0 to GetItemCount-1 do
  1362. if (Flags and (1 shl I))<>0 then
  1363. begin
  1364. if (CurX+1<=X) and (X<=CurX+3) then
  1365. begin Idx:=I; Break; end;
  1366. Inc(CurX,4);
  1367. end;
  1368. GetItemForCoord:=Idx;
  1369. end;
  1370. begin
  1371. case Event.What of
  1372. evMouseDown :
  1373. if MouseInView(Event.Where) then
  1374. begin
  1375. repeat
  1376. MakeLocal(Event.Where,P);
  1377. Idx:=GetItemForCoord(P.X);
  1378. if Idx<>-1 then
  1379. SelectItem(Idx);
  1380. until not MouseEvent(Event, evMouseMove);
  1381. ClearEvent(Event);
  1382. end;
  1383. evKeyDown :
  1384. begin
  1385. DontClear:=false; Idx:=-1;
  1386. for I:=0 to GetItemCount-1 do
  1387. if (GetCtrlCode(GetItem(I)^.Sign)=Event.KeyCode){ or
  1388. (GetItem(I)^.Sign=UpCase(Event.CharCode))} then
  1389. if (Flags and (1 shl I))<>0 then
  1390. begin
  1391. Idx:=I;
  1392. Break;
  1393. end;
  1394. if Idx=-1 then
  1395. DontClear:=true
  1396. else
  1397. SelectItem(Idx);
  1398. if DontClear=false then ClearEvent(Event);
  1399. end;
  1400. end;
  1401. inherited HandleEvent(Event);
  1402. end;
  1403. function TBrowserTab.GetPalette: PPalette;
  1404. const P: string[length(CBrowserTab)] = CBrowserTab;
  1405. begin
  1406. GetPalette:=@P;
  1407. end;
  1408. destructor TBrowserTab.Done;
  1409. begin
  1410. if Items<>nil then DisposeBrowserTabList(Items);
  1411. inherited Done;
  1412. end;
  1413. procedure TUnitInfoPanel.HandleEvent(var Event: TEvent);
  1414. begin
  1415. if (Event.What=evBroadcast) and (Event.Command=cmListItemSelected) and
  1416. (InOwnerCall=false) then
  1417. begin
  1418. InOwnerCall:=true;
  1419. if Assigned(Owner) then
  1420. Owner^.HandleEvent(Event);
  1421. InOwnerCall:=false;
  1422. end;
  1423. inherited HandleEvent(Event);
  1424. end;
  1425. constructor TBrowserWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer;ASym : PSymbol;
  1426. const AName,APrefix: string; ASymbols: PSymbolCollection; AReferences: PReferenceCollection;
  1427. AInheritance: PObjectSymbol; AMemInfo: PSymbolMemINfo);
  1428. var R,R2,R3: TRect;
  1429. HSB,VSB: PScrollBar;
  1430. CST: PColorStaticText;
  1431. I: sw_integer;
  1432. function CreateVSB(R: TRect): PScrollBar;
  1433. var R2: TRect;
  1434. SB: PScrollBar;
  1435. begin
  1436. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  1437. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  1438. CreateVSB:=SB;
  1439. end;
  1440. function CreateHSB(R: TRect): PScrollBar;
  1441. var R2: TRect;
  1442. SB: PScrollBar;
  1443. begin
  1444. R2.Copy(R); R2.Move(0,1); R2.A.Y:=R2.B.Y-1;
  1445. New(SB, Init(R2)); SB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1446. CreateHSB:=SB;
  1447. end;
  1448. begin
  1449. inherited Init(Bounds, FormatStrStr(dialog_browse,ATitle), ANumber);
  1450. HelpCtx:=hcBrowserWindow;
  1451. Sym:=ASym;
  1452. Prefix:=NewStr(APrefix);
  1453. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+1;
  1454. {$ifndef NODEBUG}
  1455. if {assigned(Debugger) and Debugger^.IsRunning and}
  1456. assigned(Sym) and (Sym^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) then
  1457. begin
  1458. New(DebuggerValue,Init(ATitle,Sym));
  1459. New(ST, Init(R, ' '+DebuggerValue^.GetText));
  1460. end
  1461. else
  1462. {$endif NODEBUG}
  1463. begin
  1464. New(ST, Init(R, ' '+AName));
  1465. DebuggerValue:=nil;
  1466. end;
  1467. ST^.GrowMode:=gfGrowHiX;
  1468. Insert(ST);
  1469. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,2);
  1470. if assigned(ASymbols) and (ASymbols^.Count>0) then
  1471. begin
  1472. HSB:=CreateHSB(R);
  1473. Insert(HSB);
  1474. VSB:=CreateVSB(R);
  1475. Insert(VSB);
  1476. New(ScopeView, Init(R, ASymbols, HSB, VSB));
  1477. ScopeView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1478. Insert(ScopeView);
  1479. ScopeView^.MyBW:=@Self;
  1480. ScopeView^.SetGDBCol;
  1481. end;
  1482. if assigned(AReferences) and (AReferences^.Count>0) then
  1483. begin
  1484. HSB:=CreateHSB(R);
  1485. Insert(HSB);
  1486. VSB:=CreateVSB(R);
  1487. Insert(VSB);
  1488. New(ReferenceView, Init(R, AReferences, HSB, VSB));
  1489. ReferenceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1490. Insert(ReferenceView);
  1491. ReferenceView^.MyBW:=@Self;
  1492. end;
  1493. if assigned(AInheritance) then
  1494. begin
  1495. HSB:=CreateHSB(R);
  1496. Insert(HSB);
  1497. VSB:=CreateVSB(R);
  1498. Insert(VSB);
  1499. New(InheritanceView, Init(R, HSB,VSB, AInheritance));
  1500. InheritanceView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1501. Insert(InheritanceView);
  1502. InheritanceView^.MyBW:=@Self;
  1503. end;
  1504. if assigned(AMemInfo) then
  1505. begin
  1506. New(MemInfoView, Init(R, AMemInfo));
  1507. MemInfoView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1508. Insert(MemInfoView);
  1509. MemInfoView^.MyBW:=@Self;
  1510. end;
  1511. if Assigned(Asym) and (TypeOf(ASym^)=TypeOf(TModuleSymbol)) then
  1512. with PModuleSymbol(Sym)^ do
  1513. begin
  1514. New(UnitInfo, Init(R));
  1515. UnitInfo^.GetExtent(R3);
  1516. R2.Copy(R3);
  1517. R2.B.Y:=R2.A.Y+3;
  1518. if (Assigned(UsedUnits) or Assigned(DependentUnits))=false then
  1519. R2.B.Y:=R3.B.Y;
  1520. HSB:=CreateHSB(R2); {UnitInfo^.Insert(HSB); HSB:=nil;}
  1521. VSB:=CreateVSB(R2);
  1522. {UnitInfo^.Insert(VSB);
  1523. VSB will be owned by UnitInfoText PM }
  1524. New(UnitInfoText, Init(R2,HSB,VSB, nil));
  1525. with UnitInfoText^ do
  1526. begin
  1527. GrowMode:=gfGrowHiX;
  1528. if Assigned(LoadedFrom) then
  1529. begin
  1530. AddLine(FormatStrStr2('%s : %s',msg_usedfirstin,GetStr(LoadedFrom)));
  1531. AddLine(FormatStrStr('%s : ',msg_mainsource));
  1532. AddLine(FormatStrStr(' %s',GetStr(MainSource)));
  1533. if Assigned(SourceFiles) and (SourceFiles^.Count>1) then
  1534. begin
  1535. AddLine(FormatStrStr('%s : ',msg_sourcefiles));
  1536. for I:=0 to SourceFiles^.Count-1 do
  1537. AddLine(FormatStrStr(' %s',GetStr(SourceFiles^.At(I))));
  1538. end;
  1539. end;
  1540. end;
  1541. UnitInfo^.Insert(UnitInfoText);
  1542. if Assigned(UsedUnits) then
  1543. begin
  1544. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  1545. New(CST, Init(R2,'´ Used units Ã'+CharStr('Ä',255),ColorIndex(12),false));
  1546. CST^.GrowMode:=gfGrowHiX;
  1547. UnitInfo^.Insert(CST);
  1548. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+4;
  1549. if Assigned(DependentUnits)=false then R2.B.Y:=R3.B.Y;
  1550. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  1551. HSB:=nil;
  1552. VSB:=CreateVSB(R2);
  1553. {UnitInfo^.Insert(VSB); this created crashes,
  1554. that were difficult to findout PM }
  1555. New(UnitInfoUsed, Init(R2,UsedUnits,HSB,VSB));
  1556. UnitInfoUsed^.GrowMode:=gfGrowHiY+gfGrowHiX;
  1557. UnitInfoUsed^.MyBW:=@Self;
  1558. UnitInfo^.Insert(UnitInfoUsed);
  1559. end;
  1560. if Assigned(DependentUnits) then
  1561. begin
  1562. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R2.A.Y+1;
  1563. New(CST, Init(R2,'´ Dependent units Ã'+CharStr('Ä',255),ColorIndex(12),false));
  1564. CST^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1565. UnitInfo^.Insert(CST);
  1566. Inc(R2.A.Y,R2.B.Y-R2.A.Y); R2.B.Y:=R3.B.Y;
  1567. {HSB:=CreateHSB(R2); UnitInfo^.Insert(HSB); }
  1568. HSB:=nil;
  1569. VSB:=CreateVSB(R2);
  1570. { UnitInfo^.Insert(VSB); this created crashes,
  1571. that were difficult to findout PM }
  1572. New(UnitInfoDependent, Init(R2,DependentUnits,HSB,VSB));
  1573. UnitInfoDependent^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  1574. UnitInfoDependent^.MyBW:=@Self;
  1575. UnitInfo^.Insert(UnitInfoDependent);
  1576. end;
  1577. if Assigned(UnitInfoText) then
  1578. UnitInfoText^.Select;
  1579. Insert(UnitInfo);
  1580. end;
  1581. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.B.Y:=R.A.Y+1;
  1582. New(PageTab, Init(R,
  1583. NewBrowserTabItem(label_browsertab_scope,ScopeView,
  1584. NewBrowserTabItem(label_browsertab_reference,ReferenceView,
  1585. NewBrowserTabItem(label_browsertab_inheritance,InheritanceView,
  1586. NewBrowserTabItem(label_browsertab_memory,MemInfoView,
  1587. NewBrowserTabItem(label_browsertab_unit,UnitInfo,
  1588. nil)))))));
  1589. PageTab^.GrowMode:=gfGrowHiX;
  1590. Insert(PageTab);
  1591. if assigned(ScopeView) then
  1592. SelectTab(btScope)
  1593. else if assigned(ReferenceView) then
  1594. SelectTab(btReferences)
  1595. else if assigned(MemInfoView) then
  1596. SelectTab(btMemInfo)
  1597. else
  1598. if assigned(InheritanceView) then
  1599. SelectTab(btInheritance);
  1600. end;
  1601. destructor TBrowserWindow.Done;
  1602. begin
  1603. { UnitInfoText needs to be removed first
  1604. to avoid crashes within the UnitInfo destructor PM }
  1605. if Assigned(UnitInfoText) then
  1606. begin
  1607. UnitInfo^.Delete(UnitInfoText);
  1608. Dispose(UnitInfoText,Done);
  1609. UnitInfoText:=nil;
  1610. end;
  1611. if assigned(DebuggerValue) then
  1612. begin
  1613. Dispose(DebuggerValue,Done);
  1614. DebuggerValue:=nil;
  1615. end;
  1616. if assigned(Prefix) then
  1617. begin
  1618. DisposeStr(Prefix);
  1619. Prefix:=nil;
  1620. end;
  1621. inherited Done;
  1622. end;
  1623. procedure TBrowserWindow.HandleEvent(var Event: TEvent);
  1624. var DontClear: boolean;
  1625. S: PSymbol;
  1626. Symbols: PSymbolCollection;
  1627. Anc: PObjectSymbol;
  1628. P: TPoint;
  1629. begin
  1630. case Event.What of
  1631. evBroadcast :
  1632. case Event.Command of
  1633. cmDebuggerStopped :
  1634. begin
  1635. if Assigned(DebuggerValue) and
  1636. (DebuggerValue^.GDBI<>PtrInt(Event.InfoPtr)) then
  1637. begin
  1638. If Assigned(ST^.Text) then
  1639. DisposeStr(ST^.Text);
  1640. ST^.Text:=NewStr(DebuggerValue^.GetText);
  1641. ST^.DrawView;
  1642. end;
  1643. end;
  1644. cmSearchWindow :
  1645. ClearEvent(Event);
  1646. cmListItemSelected :
  1647. begin
  1648. S:=nil;
  1649. if (Event.InfoPtr=ScopeView) then
  1650. begin
  1651. S:=ScopeView^.Symbols^.At(ScopeView^.Focused);
  1652. MakeGlobal(ScopeView^.Origin,P);
  1653. Desktop^.MakeLocal(P,P); Inc(P.Y,ScopeView^.Focused-ScopeView^.TopItem);
  1654. Inc(P.Y);
  1655. end;
  1656. if (Event.InfoPtr=UnitInfoUsed) then
  1657. begin
  1658. S:=UnitInfoUsed^.Symbols^.At(UnitInfoUsed^.Focused);
  1659. MakeGlobal(UnitInfoUsed^.Origin,P);
  1660. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoUsed^.Focused-UnitInfoUsed^.TopItem);
  1661. Inc(P.Y);
  1662. end;
  1663. if (Event.InfoPtr=UnitInfoDependent) then
  1664. begin
  1665. S:=UnitInfoDependent^.Symbols^.At(UnitInfoDependent^.Focused);
  1666. MakeGlobal(UnitInfoDependent^.Origin,P);
  1667. Desktop^.MakeLocal(P,P); Inc(P.Y,UnitInfoDependent^.Focused-UnitInfoDependent^.TopItem);
  1668. Inc(P.Y);
  1669. end;
  1670. if Assigned(S) then
  1671. begin
  1672. if S^.Ancestor=nil then Anc:=nil else
  1673. Anc:=SearchObjectForSymbol(S^.Ancestor);
  1674. Symbols:=S^.Items;
  1675. if (not assigned(Symbols) or (symbols^.count=0)) then
  1676. if assigned(S^.Ancestor) then
  1677. Symbols:=S^.Ancestor^.Items;
  1678. if (S^.GetReferenceCount>0) or (assigned(Symbols) and (Symbols^.Count>0)) or (Anc<>nil) then
  1679. OpenSymbolBrowser(Origin.X-1,P.Y,
  1680. S^.GetName,
  1681. ScopeView^.GetText(ScopeView^.Focused,255),
  1682. S,@self,
  1683. Symbols,S^.References,Anc,S^.MemInfo);
  1684. end;
  1685. end;
  1686. end;
  1687. { evCommand :
  1688. begin
  1689. DontClear:=false;
  1690. case Event.Command of
  1691. cmGotoSymbol :
  1692. if Event.InfoPtr=ScopeView then
  1693. if ReferenceView<>nil then
  1694. if ReferenceView^.Range>0 then
  1695. ReferenceView^.GotoItem(0);
  1696. cmTrackSymbol :
  1697. if Event.InfoPtr=ScopeView then
  1698. if (ScopeView<>nil) and (ScopeView^.Range>0) then
  1699. begin
  1700. S:=ScopeView^.At(ScopeView^.Focused);
  1701. if (S^.References<>nil) and (S^.References^.Count>0) then
  1702. TrackItem(S^.References^.At(0));
  1703. else DontClear:=true;
  1704. end;
  1705. if DontClear=false then ClearEvent(Event);
  1706. end;}
  1707. evKeyDown :
  1708. begin
  1709. DontClear:=false;
  1710. case Event.KeyCode of
  1711. kbEsc :
  1712. Close;
  1713. kbAltI :
  1714. If not Disassemble then
  1715. DontClear:=true;
  1716. else DontClear:=true;
  1717. end;
  1718. if DontClear=false then ClearEvent(Event);
  1719. end;
  1720. end;
  1721. inherited HandleEvent(Event);
  1722. end;
  1723. function TBrowserWindow.Disassemble : boolean;
  1724. begin
  1725. Disassemble:=false;
  1726. if not assigned(sym) or (sym^.typ<>procsym) then
  1727. exit;
  1728. { We need to load exefile }
  1729. {$ifndef NODEBUG}
  1730. InitGDBWindow;
  1731. if not assigned(Debugger) then
  1732. begin
  1733. new(Debugger,Init);
  1734. if assigned(Debugger) then
  1735. Debugger^.SetExe(ExeFile);
  1736. end;
  1737. if not assigned(Debugger) or not Debugger^.HasExe then
  1738. exit;
  1739. { goto source/assembly mixture }
  1740. InitDisassemblyWindow;
  1741. DisassemblyWindow^.LoadFunction(Sym^.GetName);
  1742. DisassemblyWindow^.SelectInDebugSession;
  1743. Disassemble:=true;
  1744. {$else NODEBUG}
  1745. NoDebugger;
  1746. {$endif NODEBUG}
  1747. end;
  1748. procedure TBrowserWindow.SetState(AState: Word; Enable: Boolean);
  1749. {var OldState: word;}
  1750. begin
  1751. { OldState:=State;}
  1752. inherited SetState(AState,Enable);
  1753. { if ((State xor OldState) and sfActive)<>0 then
  1754. if GetState(sfActive)=false then
  1755. Message(Desktop,evBroadcast,cmClearLineHighlights,nil);}
  1756. end;
  1757. procedure TBrowserWindow.Close;
  1758. begin
  1759. inherited Close;
  1760. end;
  1761. procedure TBrowserWindow.SelectTab(BrowserTab: Sw_integer);
  1762. var Tabs: Sw_integer;
  1763. {$ifndef NODEBUG}
  1764. PB : PBreakpoint;
  1765. {$endif}
  1766. PS :PString;
  1767. l : longint;
  1768. begin
  1769. case BrowserTab of
  1770. btScope :
  1771. if assigned(ScopeView) then
  1772. ScopeView^.Select;
  1773. btReferences :
  1774. if assigned(ReferenceView) then
  1775. ReferenceView^.Select;
  1776. btMemInfo:
  1777. if assigned(MemInfoView) then
  1778. MemInfoView^.Select;
  1779. {$ifndef NODEBUG}
  1780. btBreakWatch :
  1781. begin
  1782. if Assigned(Sym) then
  1783. begin
  1784. if Pos('proc',Sym^.GetText)>0 then
  1785. { insert function breakpoint }
  1786. begin
  1787. { make it visible }
  1788. PS:=Sym^.Name;
  1789. l:=Length(PS^);
  1790. If PS^[l]='*' then
  1791. begin
  1792. PB:=BreakpointsCollection^.GetType(bt_function,copy(GetStr(PS),1,l-1));
  1793. If Assigned(PB) then
  1794. BreakpointsCollection^.Delete(PB);
  1795. Sym^.Name:=NewStr(copy(GetStr(PS),1,l-1));
  1796. DrawView;
  1797. DisposeStr(PS);
  1798. end
  1799. else
  1800. begin
  1801. Sym^.Name:=NewStr(GetStr(PS)+'*');
  1802. DrawView;
  1803. New(PB,init_function(GetStr(PS)));
  1804. DisposeStr(PS);
  1805. BreakpointsCollection^.Insert(PB);
  1806. BreakpointsCollection^.Update;
  1807. end;
  1808. end
  1809. else if pos('var',Sym^.GetText)>0 then
  1810. { insert watch point }
  1811. begin
  1812. { make it visible }
  1813. PS:=Sym^.Name;
  1814. l:=Length(PS^);
  1815. If PS^[l]='*' then
  1816. begin
  1817. PB:=BreakpointsCollection^.GetType(bt_awatch,copy(PS^,1,l-1));
  1818. If Assigned(PB) then
  1819. BreakpointsCollection^.Delete(PB);
  1820. Sym^.Name:=NewStr(copy(PS^,1,l-1));
  1821. DrawView;
  1822. DisposeStr(PS);
  1823. end
  1824. else
  1825. begin
  1826. Sym^.Name:=NewStr(GetStr(PS)+'*');
  1827. DrawView;
  1828. New(PB,init_type(bt_awatch,GetStr(PS)));
  1829. DisposeStr(PS);
  1830. BreakpointsCollection^.Insert(PB);
  1831. BreakpointsCollection^.Update;
  1832. end;
  1833. end;
  1834. end;
  1835. end;
  1836. {$endif NODEBUG}
  1837. end;
  1838. Tabs:=0;
  1839. if assigned(ScopeView) then
  1840. Tabs:=Tabs or (1 shl btScope);
  1841. if assigned(ReferenceView) then
  1842. Tabs:=Tabs or (1 shl btReferences);
  1843. if assigned(InheritanceView) then
  1844. Tabs:=Tabs or (1 shl btInheritance);
  1845. if assigned(MemInfoView) then
  1846. Tabs:=Tabs or (1 shl btMemInfo);
  1847. {$ifndef NODEBUG}
  1848. if Assigned(Sym) then
  1849. if (Pos('proc',Sym^.GetText)>0) or (Pos('var',Sym^.GetText)>0) then
  1850. Tabs:=Tabs or (1 shl btBreakWatch);
  1851. {$endif NODEBUG}
  1852. if assigned(UnitInfo) then
  1853. Tabs:=Tabs or (1 shl btUnitInfo);
  1854. if PageTab<>nil then PageTab^.SetParams(Tabs,BrowserTab);
  1855. end;
  1856. function TBrowserWindow.GetPalette: PPalette;
  1857. const S: string[length(CBrowserWindow)] = CBrowserWindow;
  1858. begin
  1859. GetPalette:=@S;
  1860. end;
  1861. procedure OpenSymbolBrowser(X,Y: Sw_integer;const Name,Line: string;S : PSymbol;
  1862. ParentBrowser : PBrowserWindow;
  1863. Symbols: PSymbolCollection; References: PReferenceCollection;
  1864. Inheritance: PObjectSymbol; MemInfo: PSymbolMemInfo);
  1865. var R: TRect;
  1866. PB : PBrowserWindow;
  1867. St,st2 : string;
  1868. begin
  1869. if X=0 then X:=Desktop^.Size.X-35;
  1870. R.A.X:=X; R.A.Y:=Y;
  1871. R.B.X:=R.A.X+35; R.B.Y:=R.A.Y+15;
  1872. while (R.B.Y>Desktop^.Size.Y) do R.Move(0,-1);
  1873. if assigned(ParentBrowser) and assigned(ParentBrowser^.Prefix) and
  1874. assigned(ParentBrowser^.sym) and
  1875. (ParentBrowser^.sym^.typ<>unitsym)
  1876. then
  1877. begin
  1878. st:=GetStr(ParentBrowser^.Prefix)+' '+Name;
  1879. end
  1880. else
  1881. st:=Name;
  1882. st2:=st;
  1883. if assigned(S) and ((S^.Flags and sfPointer)<>0) then
  1884. begin
  1885. st:=st+'^';
  1886. if assigned(S^.Ancestor) and
  1887. ((S^.Ancestor^.Flags and sfRecord)<>0) then
  1888. st:=st+'.';
  1889. end
  1890. else if assigned(S) and ((S^.Flags and sfRecord)<>0) then
  1891. st:=st+'.';
  1892. PB:=New(PBrowserWindow, Init(R,
  1893. st2,SearchFreeWindowNo,S,Line,st,
  1894. Symbols,References,Inheritance,MemInfo));
  1895. if (assigned(S) and (S^.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym])) or
  1896. (assigned(ParentBrowser) and ParentBrowser^.IsValid) then
  1897. PB^.IsValid:=true;
  1898. Desktop^.Insert(PB);
  1899. end;
  1900. END.