-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathamScript.Debugger.Frame.LocalVariables.pas
More file actions
514 lines (424 loc) · 15.2 KB
/
Copy pathamScript.Debugger.Frame.LocalVariables.pas
File metadata and controls
514 lines (424 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
unit amScript.Debugger.Frame.LocalVariables;
(*
* Copyright © 2011 Brian Frost
* Copyright © 2019 Anders Melander
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*)
interface
uses
Generics.Collections,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, ImgList, Menus, ActnList, System.Actions,
cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore,
cxContainer, cxEdit, cxCustomData, cxStyles, cxTL, cxTextEdit, cxTLdxBarBuiltInMenu, cxInplaceContainer,
cxClasses, cxTLData, dxSkinsdxBarPainter, dxBar, cxFilter, dxScrollbarAnnotations,
dwsUtils,
dwsExprs,
dwsSymbols,
dwsErrors,
dwsInfo,
dwsScriptSource,
amScript.Debugger.API,
amScript.Debugger.InfoEvaluationBuilder;
// -----------------------------------------------------------------------------
//
// TScriptDebuggerLocalVariablesFrame
//
// -----------------------------------------------------------------------------
// Displays variables in current context (i.e. local) and, optionally, variables
// from parent contexts.
// Both simple and complex types are supported.
// -----------------------------------------------------------------------------
type
TFrame = TScriptDebuggerFrame;
TScriptDebuggerLocalVariablesFrame = class(TFrame)
TreeListVariables: TcxTreeList;
TreeListVariablesColumnVariable: TcxTreeListColumn;
TreeListVariablesColumnValue: TcxTreeListColumn;
TreeListVariablesColumnType: TcxTreeListColumn;
StyleRepository: TcxStyleRepository;
StyleBackground: TcxStyle;
PopupMenu: TdxBarPopupMenu;
BarManager: TdxBarManager;
dxBarSeparator1: TdxBarSeparator;
MenuItemScopePublished: TdxBarButton;
MenuItemScopePublic: TdxBarButton;
MenuItemScopeProtected: TdxBarButton;
MenuItemScopePrivate: TdxBarButton;
dxBarSeparator2: TdxBarSeparator;
MenuItemMembersInherited: TdxBarButton;
MenuItemMembersProperties: TdxBarButton;
MenuItemMembersFields: TdxBarButton;
MenuItemItemWatch: TdxBarButton;
MenuItemItemModify: TdxBarButton;
ActionList: TActionList;
ActionItemWatch: TAction;
ActionItemModify: TAction;
MenuItemMembersPropertyGetters: TdxBarButton;
ActionViewMemberFields: TAction;
ActionViewMemberProperties: TAction;
ActionViewMemberPropertySideEffects: TAction;
ActionViewMemberInherited: TAction;
ActionViewScopePublished: TAction;
ActionViewScopePublic: TAction;
ActionViewScopeProtected: TAction;
ActionViewScopePrivate: TAction;
TreeListVariablesColumnScope: TcxTreeListColumn;
ActionViewScopeGlobal: TAction;
dxBarButton1: TdxBarButton;
procedure TreeListVariablesDeletion(Sender: TcxCustomTreeList; ANode: TcxTreeListNode);
procedure TreeListVariablesExpanding(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; var Allow: Boolean);
procedure TreeListVariablesDblClick(Sender: TObject);
procedure ActionItemWatchExecute(Sender: TObject);
procedure ActionItemWatchUpdate(Sender: TObject);
procedure ActionItemModifyUpdate(Sender: TObject);
procedure ActionItemModifyExecute(Sender: TObject);
procedure ActionViewMemberFieldsExecute(Sender: TObject);
procedure ActionViewMemberPropertiesExecute(Sender: TObject);
procedure ActionViewMemberPropertySideEffectsExecute(Sender: TObject);
procedure ActionViewMemberFieldsUpdate(Sender: TObject);
procedure ActionViewMemberPropertiesUpdate(Sender: TObject);
procedure ActionViewMemberPropertySideEffectsUpdate(Sender: TObject);
procedure ActionViewMemberInheritedExecute(Sender: TObject);
procedure ActionViewMemberInheritedUpdate(Sender: TObject);
procedure ActionViewScopeExecute(Sender: TObject);
procedure ActionViewScopeUpdate(Sender: TObject);
procedure ActionViewScopeGlobalExecute(Sender: TObject);
procedure ActionViewScopeGlobalUpdate(Sender: TObject);
strict private
FEvaluationBuilder: TInfoEvaluationBuilder;
FVisibilities: TdwsVisibilities;
FInspectOptions: TInspectOptions;
strict private
procedure UpdateInfo;
strict protected
// IScriptDebuggerWindow
procedure Initialize(const ADebugger: IScriptDebugger; AImageList, AImageListSymbols: TCustomImageList); override;
strict protected
// IScriptDebuggerWindow
procedure ScriptDebuggerNotification(Notification: TScriptDebuggerNotification); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
{$R *.dfm}
uses
dwsDebugger,
{$ifdef OLD_DWSCRIPT}
dwsInfo,
{$else OLD_DWSCRIPT}
dwsInfoClasses,
dwsEvaluate,
dwsContextMap,
{$endif OLD_DWSCRIPT}
dwsCompiler,
dwsDataContext,
dwsSuggestions,
amScript.IDE.Settings;
// -----------------------------------------------------------------------------
//
// TScriptDebuggerLocalVariablesFrame
//
// -----------------------------------------------------------------------------
constructor TScriptDebuggerLocalVariablesFrame.Create(AOwner: TComponent);
begin
inherited;
FEvaluationBuilder := TInfoEvaluationBuilder.Create(TreeListVariables);
FVisibilities := FEvaluationBuilder.Visibilities;
FInspectOptions := FEvaluationBuilder.InspectOptions;
end;
destructor TScriptDebuggerLocalVariablesFrame.Destroy;
begin
FEvaluationBuilder.Free;
inherited;
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.Initialize(const ADebugger: IScriptDebugger; AImageList, AImageListSymbols: TCustomImageList);
begin
inherited Initialize(ADebugger, AImageList, AImageListSymbols);
FEvaluationBuilder.Initialize(ADebugger);
TreeListVariables.Images := AImageListSymbols;
ActionItemWatch.Visible := ScriptSettings.Features.ViewWatches;
UpdateInfo;
end;
procedure TScriptDebuggerLocalVariablesFrame.ScriptDebuggerNotification(Notification: TScriptDebuggerNotification);
begin
inherited;
case Notification of
dnDebugSuspended:
// Debugger has paused on single-step; Update view
UpdateInfo;
dnIdle,
dnDebugDone:
// Debugger is stopped; Clear view
FEvaluationBuilder.Clear;
end;
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.TreeListVariablesDblClick(Sender: TObject);
begin
ActionItemModify.Execute;
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.TreeListVariablesDeletion(Sender: TcxCustomTreeList; ANode: TcxTreeListNode);
var
Info: IInfo;
begin
if (ANode.Data = nil) then
exit;
// Get the interface pointer from the node
pointer(Info) := ANode.Data;
ANode.Data := nil;
// Release then interface
Info := nil;
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.TreeListVariablesExpanding(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; var Allow: Boolean);
begin
FEvaluationBuilder.PopulateNode(ANode);
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.ActionItemModifyExecute(Sender: TObject);
begin
var Node := TreeListVariables.FocusedNode;
if (Node = nil) then
exit;
// Build expression from focused node
var Expression := '';
while (Node <> nil) and (Node.Parent <> nil) do
begin
if (Expression = '') then
Expression := Node.Texts[0]
else
Expression := Node.Texts[0] + '.' + Expression;
Node := Node.Parent;
end;
Debugger.Evaluate(Expression);
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionItemModifyUpdate(Sender: TObject);
begin
TAction(Sender).Enabled := (TreeListVariables.FocusedNode <> nil);
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.ActionItemWatchExecute(Sender: TObject);
begin
var Node := TreeListVariables.FocusedNode;
if (Node = nil) then
exit;
// Build expression from focused node
var Expression := '';
while (Node <> nil) and (Node.Parent <> nil) do
begin
if (Expression = '') then
Expression := Node.Texts[0]
else
Expression := Node.Texts[0] + '.' + Expression;
Node := Node.Parent;
end;
Debugger.AddWatch(Expression);
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionItemWatchUpdate(Sender: TObject);
begin
TAction(Sender).Enabled := (TreeListVariables.FocusedNode <> nil);
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberFieldsExecute(Sender: TObject);
begin
if (TAction(Sender).Checked) then
Include(FInspectOptions, ioShowFields)
else
Exclude(FInspectOptions, ioShowFields);
FEvaluationBuilder.InspectOptions := FInspectOptions;
UpdateInfo;
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberFieldsUpdate(Sender: TObject);
begin
TAction(Sender).Checked := (ioShowFields in FInspectOptions);
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberInheritedExecute(Sender: TObject);
begin
if (TAction(Sender).Checked) then
Include(FInspectOptions, ioShowInherited)
else
Exclude(FInspectOptions, ioShowInherited);
FEvaluationBuilder.BeginUpdate;
try
FEvaluationBuilder.InspectOptions := FInspectOptions;
UpdateInfo;
finally
FEvaluationBuilder.EndUpdate;
end;
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberInheritedUpdate(Sender: TObject);
begin
TAction(Sender).Checked := (ioShowInherited in FInspectOptions);
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberPropertiesExecute(Sender: TObject);
begin
if (TAction(Sender).Checked) then
Include(FInspectOptions, ioShowProperties)
else
Exclude(FInspectOptions, ioShowProperties);
FEvaluationBuilder.BeginUpdate;
try
FEvaluationBuilder.InspectOptions := FInspectOptions;
UpdateInfo;
finally
FEvaluationBuilder.EndUpdate;
end;
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberPropertiesUpdate(Sender: TObject);
begin
TAction(Sender).Checked := (ioShowProperties in FInspectOptions);
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberPropertySideEffectsExecute(Sender: TObject);
begin
if (TAction(Sender).Checked) then
Include(FInspectOptions, ioAllowPropertySideEffects)
else
Exclude(FInspectOptions, ioAllowPropertySideEffects);
FEvaluationBuilder.BeginUpdate;
try
FEvaluationBuilder.InspectOptions := FInspectOptions;
UpdateInfo;
finally
FEvaluationBuilder.EndUpdate;
end;
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewMemberPropertySideEffectsUpdate(Sender: TObject);
begin
TAction(Sender).Checked := (ioAllowPropertySideEffects in FInspectOptions);
TAction(Sender).Enabled := (ioShowProperties in FInspectOptions);
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewScopeGlobalExecute(Sender: TObject);
begin
if (TAction(Sender).Checked) then
Include(FInspectOptions, ioShowGlobal)
else
Exclude(FInspectOptions, ioShowGlobal);
FEvaluationBuilder.BeginUpdate;
try
FEvaluationBuilder.InspectOptions := FInspectOptions;
UpdateInfo;
finally
FEvaluationBuilder.EndUpdate;
end;
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewScopeGlobalUpdate(Sender: TObject);
begin
TAction(Sender).Checked := (ioShowGlobal in FInspectOptions);
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewScopeExecute(Sender: TObject);
var
Visibility: TdwsVisibility;
begin
Visibility := TdwsVisibility(TAction(Sender).Tag);
if (TAction(Sender).Checked) then
Include(FVisibilities, Visibility)
else
Exclude(FVisibilities, Visibility);
FEvaluationBuilder.BeginUpdate;
try
FEvaluationBuilder.Visibilities := FVisibilities;
UpdateInfo;
finally
FEvaluationBuilder.EndUpdate;
end;
end;
procedure TScriptDebuggerLocalVariablesFrame.ActionViewScopeUpdate(Sender: TObject);
begin
TAction(Sender).Checked := (TdwsVisibility(TAction(Sender).Tag) in FVisibilities);
end;
// -----------------------------------------------------------------------------
procedure TScriptDebuggerLocalVariablesFrame.UpdateInfo;
procedure LoadSymbol(Symbol: TSymbol; ScriptPos : PScriptPos = nil;
ImageIndex: integer = -1; ContextSymbol: TSymbol = nil);
begin
if (Symbol.Name = '') then
exit;
FEvaluationBuilder.EvaluateExpression(nil, nil, Symbol.Name, ScriptPos, ImageIndex, ContextSymbol);
end;
procedure LoadSymbols(ATable: TSymbolTable; ScriptPos: PScriptPos = nil; AContext: TdwsSourceContext = nil);
begin
var ContextSymbol: TSymbol := nil;
var HasContext := (AContext = nil);
for var Symbol in ATable do
if (Symbol is TDataSymbol) then
begin
if (not HasContext) then
begin
HasContext := True;
while (AContext <> nil) and (ContextSymbol = nil) do
begin
ContextSymbol := AContext.ParentSym;
AContext := AContext.Parent;
end;
end;
LoadSymbol(Symbol, ScriptPos, Ord(scVariable), ContextSymbol);
end;
end;
procedure LoadParams(AProc: TdwsProcedure);
begin
for var Symbol in AProc.Func.Params do
if (Symbol is TDataSymbol) then
LoadSymbol(Symbol, nil, Ord(scParameter));
// If it is a function, get the function result
var Symbol := AProc.Func.Result;
if (Symbol <> nil) then
LoadSymbol(Symbol, nil, Ord(scParameter));
end;
procedure FetchVariables(AScope: TdwsProgram);
begin
if (AScope is TdwsProcedure) then
begin
var MethodSymbol := TdwsProcedure(AScope).ContextMethodSymbol;
// If scope is a function then display the return value
if (MethodSymbol <> nil) and (MethodSymbol.SelfSym <> nil) then
LoadSymbol(MethodSymbol.SelfSym);
// Display any parameter values
LoadParams(TdwsProcedure(AScope));
end else
if (AScope is TdwsMainProgram) then
begin
var ScriptPos := Debugger.GetDebugger.CurrentScriptPos;
var Context := TdwsMainProgram(AScope).SourceContextMap.FindContext(ScriptPos);
while (Context <> nil) do
begin
if (Context.LocalTable <> nil) then
LoadSymbols(Context.LocalTable, @ScriptPos, Context);
Context := Context.Parent;
end;
end;
LoadSymbols(AScope.Table);
end;
begin
FEvaluationBuilder.BeginUpdate;
try
var ProgramExecution := TdwsProgramExecution(Debugger.GetDebugger.Execution);
if (ProgramExecution = nil) or (ProgramExecution.Debugger = nil) then
begin
FEvaluationBuilder.Clear;
exit;
end;
var Scope := ProgramExecution.CurrentProg;
while (Scope <> nil) do
begin
FetchVariables(Scope);
if (not (ioShowGlobal in FInspectOptions)) then
break;
Scope := Scope.Parent;
end;
FEvaluationBuilder.PurgeUnusedNodes;
finally
FEvaluationBuilder.EndUpdate;
end;
end;
// -----------------------------------------------------------------------------
initialization
RegisterClass(TScriptDebuggerLocalVariablesFrame);
finalization
end.