-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdwsDebugFunctions.pas
More file actions
152 lines (131 loc) · 5.8 KB
/
Copy pathdwsDebugFunctions.pas
File metadata and controls
152 lines (131 loc) · 5.8 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
{**********************************************************************}
{ }
{ "The contents of this file are subject to the Mozilla Public }
{ License Version 1.1 (the "License"); you may not use this }
{ file except in compliance with the License. You may obtain }
{ a copy of the License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express }
{ or implied. See the License for the specific language }
{ governing rights and limitations under the License. }
{ }
{ Copyright Creative IT. }
{ Current maintainer: Eric Grange }
{ }
{**********************************************************************}
unit dwsDebugFunctions;
{$I dws.inc}
interface
uses
Classes, SysUtils,
dwsFunctions, dwsExprs, dwsSymbols, dwsUtils, dwsExprList, dwsStrings, dwsScriptSource,
dwsMagicExprs, dwsUnitSymbols, dwsXPlatform, dwsErrors, dwsDataContext, dwsInfo;
type
TOutputDebugStringFunc = class(TInternalMagicProcedure)
procedure DoEvalProc(const args : TExprBaseListExec); override;
end;
TCurrentSourceCodeLocation = class(TInternalMagicDataFunction)
procedure DoEval(const args : TExprBaseListExec; var result : IDataContext); override;
end;
TCallerSourceCodeLocation = class(TInternalMagicDataFunction)
procedure DoEval(const args : TExprBaseListExec; var result : IDataContext); override;
end;
const
SYS_TSOURCECODELOCATION = 'TSourceCodeLocation';
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// ------------------------------------------------------------------
implementation
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// RegisterComplexType
//
procedure RegisterDebugTypes(systemTable : TSystemSymbolTable; unitSyms : TUnitMainSymbols;
unitTable : TSymbolTable);
var
typLocation : TRecordSymbol;
begin
if systemTable.FindLocal(SYS_TSOURCECODELOCATION)<>nil then exit;
typLocation:=TRecordSymbol.Create(SYS_TSOURCECODELOCATION, nil);
typLocation.AddField(TFieldSymbol.Create('Name', systemTable.TypString, cvPublic));
typLocation.AddField(TFieldSymbol.Create('File', systemTable.TypString, cvPublic));
typLocation.AddField(TFieldSymbol.Create('Line', systemTable.TypInteger, cvPublic));
systemTable.AddSymbol(typLocation);
end;
// DoEvalProc
//
procedure TOutputDebugStringFunc.DoEvalProc(const args : TExprBaseListExec);
var
exec : TdwsExecution;
begin
exec:=args.Exec;
if exec.Debugger<>nil then
exec.Debugger.DebugMessage(args.AsString[0])
else OutputDebugString(args.AsString[0]);
end;
// ------------------
// ------------------ TCurrentSourceCodeLocation ------------------
// ------------------
// DoEval
//
procedure TCurrentSourceCodeLocation.DoEval(const args : TExprBaseListExec; var result : IDataContext);
var
expr : TExprBase;
sp : TScriptPos;
prog : TObject;
begin
expr := args.Expr as TExprBase;
if expr<>nil then begin
sp := expr.ScriptPos;
prog := (args.Exec as TdwsProgramExecution).CurrentProg;
if prog.ClassType = TdwsProcedure then
result.AsString[0] := TdwsProcedure(prog).Func.QualifiedName
else result.AsString[0] := '';
result.AsString[1] := sp.SourceName;
result.AsInteger[2] := sp.Line;
end else begin
result.AsString[0] := '';
result.AsString[1] := '';
result.AsInteger[2] := 0;
end;
end;
// ------------------
// ------------------ TCallerSourceCodeLocation ------------------
// ------------------
// DoEval
//
procedure TCallerSourceCodeLocation.DoEval(const args : TExprBaseListExec; var result : IDataContext);
var
expr : TExprBase;
sp : TScriptPos;
prog : TObject;
begin
expr := args.Exec.CallStackLastExpr;
if expr<>nil then begin
sp := expr.ScriptPos;
prog := args.Exec.CallStackLastProg;
if prog.ClassType = TdwsProcedure then
result.AsString[0] := TdwsProcedure(prog).Func.QualifiedName
else result.AsString[0] := '';
result.AsString[1] := sp.SourceName;
result.AsInteger[2] := sp.Line;
end else begin
result.AsString[0] := '';
result.AsString[1] := '';
result.AsInteger[2] := 0;
end;
end;
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// ------------------------------------------------------------------
initialization
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// ------------------------------------------------------------------
dwsInternalUnit.AddSymbolsRegistrationProc(RegisterDebugTypes);
RegisterInternalProcedure(TOutputDebugStringFunc, 'OutputDebugString', ['m', SYS_STRING]);
RegisterInternalFunction(TCurrentSourceCodeLocation, 'CurrentSourceCodeLocation', [], SYS_TSOURCECODELOCATION, []);
RegisterInternalFunction(TCallerSourceCodeLocation, 'CallerSourceCodeLocation', [], SYS_TSOURCECODELOCATION, []);
end.