BadScript 2
Loading...
Searching...
No Matches
BadDebuggerStep.cs
Go to the documentation of this file.
1using System.Text;
2
6
8
12public readonly struct BadDebuggerStep : IEquatable<BadDebuggerStep>
13{
17 public readonly object? StepSource;
18
23
27 public readonly BadSourcePosition Position;
28
35 public BadDebuggerStep(BadExecutionContext context, BadSourcePosition position, object? stepSource)
36 {
37 Context = context;
38 Position = position;
39 StepSource = stepSource;
40 }
41
46 public string GetInfo()
47 {
48 return
49 $"######################################\nDebug Step at {Position.GetPositionInfo()}\n\nStepSource: {StepSource}\n\nContext: {Context.Scope.Name}: {Context.Scope}\n\n######################################\n";
50 }
51
52
61 public string GetSourceView(int[] breakpoints, out int topInSource, out int lineInSource, int lineDelta = 4)
62 {
63 return GetSourceView(lineDelta, lineDelta, breakpoints, out topInSource, out lineInSource);
64 }
65
66
76 public string GetSourceView(int top, int bottom, int[] breakpoints, out int topInSource, out int lineInSource)
77 {
78 StringBuilder sb = new StringBuilder($"File: {Position.FileName}\n");
79 string[] lines = GetLines(top, bottom, out topInSource, out lineInSource);
80
81 for (int i = 0; i < lines.Length; i++)
82 {
83 int ln = topInSource + i;
84 string line = lines[i];
85 string prefix = ln.ToString();
86
87 if (ln == lineInSource)
88 {
89 prefix = ">>";
90 }
91 else
92 {
93 if (breakpoints.Any(breakpoint => ln == breakpoint))
94 {
95 prefix = "@";
96 }
97 }
98
99 sb.AppendLine($"{prefix}\t| {line}");
100 }
101
102 return sb.ToString();
103 }
104
109 public override string ToString()
110 {
111 return GetInfo();
112 }
113
122 public string[] GetLines(int top, int bottom, out int topInSource, out int lineInSource)
123 {
124 lineInSource = 1;
125
126 for (int i = 0; i < Position.Index; i++)
127 {
128 if (Position.Source[i] == '\n')
129 {
130 lineInSource++;
131 }
132 }
133
134 topInSource = Math.Max(1, lineInSource - top);
135
136 string[] lines = Position.Source.Split('\n');
137
138 List<string> lns = new List<string>();
139
140 for (int i = topInSource - 1;
141 i < topInSource - 1 + Math.Min(top + bottom, lines.Length - (topInSource - 1));
142 i++)
143 {
144 lns.Add(lines[i]);
145 }
146
147 return lns.ToArray();
148 }
149
155 public bool Equals(BadDebuggerStep other)
156 {
157 return Equals(StepSource, other.StepSource) && Context.Equals(other.Context) && Position.Equals(other.Position);
158 }
159
165 public override bool Equals(object? obj)
166 {
167 return obj is BadDebuggerStep other && Equals(other);
168 }
169
174 public override int GetHashCode()
175 {
176 return BadHashCode.Combine(StepSource, Context, Position);
177 }
178
185 public static bool operator ==(BadDebuggerStep left, BadDebuggerStep right)
186 {
187 return left.Equals(right);
188 }
189
196 public static bool operator !=(BadDebuggerStep left, BadDebuggerStep right)
197 {
198 return !left.Equals(right);
199 }
200}
Describes a specific position inside a source file.
int Index
The Start Index of the Position.
The Execution Context. Every execution of a script needs a context the script is running in....
Implements Combination of HashCode Functions Taken from decompiled source of System....
Contains Shared Data Structures and Functionality.
Contains the debugging abstractions for the BadScript2 Runtime.
Definition BadDebugger.cs:7
Contains the Runtime Implementation.
Contains Utility Functions and Classes.
Definition BadEnum.cs:5
Represents a Debugging Step.
string GetInfo()
Returns a string representation of the Step.
string GetSourceView(int[] breakpoints, out int topInSource, out int lineInSource, int lineDelta=4)
Returns a line listing of the Step.
readonly BadExecutionContext Context
The Execution Context of where the Step was executed.
static bool operator!=(BadDebuggerStep left, BadDebuggerStep right)
Implements the != operator.
bool Equals(BadDebuggerStep other)
Returns true if the Step is equal to another object.
override int GetHashCode()
Returns the Hash Code of the Step.
override string ToString()
Returns string representation of the Step.
BadDebuggerStep(BadExecutionContext context, BadSourcePosition position, object? stepSource)
Creates a new Debugger Step.
readonly? object StepSource
The Source of the Step.
string GetSourceView(int top, int bottom, int[] breakpoints, out int topInSource, out int lineInSource)
Returns a line listing of the Step.
readonly BadSourcePosition Position
The Source Position of the Step.
override bool Equals(object? obj)
Returns true if the Step is equal to another object.
static bool operator==(BadDebuggerStep left, BadDebuggerStep right)
Implements the == operator.
string[] GetLines(int top, int bottom, out int topInSource, out int lineInSource)
Returns a line excerpt of the Step.