/
DebugInfoExpression.cs
196 lines (165 loc) · 7.45 KB
/
DebugInfoExpression.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic.Utils;
namespace System.Linq.Expressions
{
/// <summary>
/// Emits or clears a sequence point for debug information.
///
/// This allows the debugger to highlight the correct source code when
/// debugging.
/// </summary>
[DebuggerTypeProxy(typeof(DebugInfoExpressionProxy))]
public class DebugInfoExpression : Expression
{
internal DebugInfoExpression(SymbolDocumentInfo document)
{
Document = document;
}
/// <summary>
/// Gets the static type of the expression that this <see cref="Expression"/> represents. (Inherited from <see cref="Expression"/>.)
/// </summary>
/// <returns>The <see cref="System.Type"/> that represents the static type of the expression.</returns>
public sealed override Type Type => typeof(void);
/// <summary>
/// Returns the node type of this <see cref="Expression"/>. (Inherited from <see cref="Expression"/>.)
/// </summary>
/// <returns>The <see cref="ExpressionType"/> that represents this expression.</returns>
public sealed override ExpressionType NodeType => ExpressionType.DebugInfo;
/// <summary>
/// Gets the start line of this <see cref="DebugInfoExpression"/>.
/// </summary>
[ExcludeFromCodeCoverage(Justification = "Unreachable")]
public virtual int StartLine
{
get { throw ContractUtils.Unreachable; }
}
/// <summary>
/// Gets the start column of this <see cref="DebugInfoExpression"/>.
/// </summary>
[ExcludeFromCodeCoverage(Justification = "Unreachable")]
public virtual int StartColumn
{
get { throw ContractUtils.Unreachable; }
}
/// <summary>
/// Gets the end line of this <see cref="DebugInfoExpression"/>.
/// </summary>
[ExcludeFromCodeCoverage(Justification = "Unreachable")]
public virtual int EndLine
{
get { throw ContractUtils.Unreachable; }
}
/// <summary>
/// Gets the end column of this <see cref="DebugInfoExpression"/>.
/// </summary>
[ExcludeFromCodeCoverage(Justification = "Unreachable")]
public virtual int EndColumn
{
get { throw ContractUtils.Unreachable; }
}
/// <summary>
/// Gets the <see cref="SymbolDocumentInfo"/> that represents the source file.
/// </summary>
public SymbolDocumentInfo Document { get; }
/// <summary>
/// Gets the value to indicate if the <see cref="DebugInfoExpression"/> is for clearing a sequence point.
/// </summary>
[ExcludeFromCodeCoverage(Justification = "Unreachable")]
public virtual bool IsClear
{
get { throw ContractUtils.Unreachable; }
}
/// <summary>
/// Dispatches to the specific visit method for this node type.
/// </summary>
protected internal override Expression Accept(ExpressionVisitor visitor)
{
return visitor.VisitDebugInfo(this);
}
}
#region Specialized subclasses
internal sealed class SpanDebugInfoExpression : DebugInfoExpression
{
private readonly int _startLine, _startColumn, _endLine, _endColumn;
internal SpanDebugInfoExpression(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn)
: base(document)
{
_startLine = startLine;
_startColumn = startColumn;
_endLine = endLine;
_endColumn = endColumn;
}
public override int StartLine => _startLine;
public override int StartColumn => _startColumn;
public override int EndLine => _endLine;
public override int EndColumn => _endColumn;
public override bool IsClear => false;
protected internal override Expression Accept(ExpressionVisitor visitor)
{
return visitor.VisitDebugInfo(this);
}
}
internal sealed class ClearDebugInfoExpression : DebugInfoExpression
{
internal ClearDebugInfoExpression(SymbolDocumentInfo document)
: base(document)
{
}
public override bool IsClear => true;
public override int StartLine => 0xfeefee;
public override int StartColumn => 0;
public override int EndLine => 0xfeefee;
public override int EndColumn => 0;
}
#endregion
public partial class Expression
{
/// <summary>
/// Creates a <see cref="DebugInfoExpression"/> with the specified span.
/// </summary>
/// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
/// <param name="startLine">The start line of this <see cref="DebugInfoExpression"/>. Must be greater than 0.</param>
/// <param name="startColumn">The start column of this <see cref="DebugInfoExpression"/>. Must be greater than 0.</param>
/// <param name="endLine">The end line of this <see cref="DebugInfoExpression"/>. Must be greater or equal than the start line.</param>
/// <param name="endColumn">The end column of this <see cref="DebugInfoExpression"/>. If the end line is the same as the start line, it must be greater or equal than the start column. In any case, must be greater than 0.</param>
/// <returns>An instance of <see cref="DebugInfoExpression"/>.</returns>
public static DebugInfoExpression DebugInfo(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn)
{
ArgumentNullException.ThrowIfNull(document);
if (startLine == 0xfeefee && startColumn == 0 && endLine == 0xfeefee && endColumn == 0)
{
return new ClearDebugInfoExpression(document);
}
ValidateSpan(startLine, startColumn, endLine, endColumn);
return new SpanDebugInfoExpression(document, startLine, startColumn, endLine, endColumn);
}
/// <summary>
/// Creates a <see cref="DebugInfoExpression"/> for clearing a sequence point.
/// </summary>
/// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
/// <returns>An instance of <see cref="DebugInfoExpression"/> for clearing a sequence point.</returns>
public static DebugInfoExpression ClearDebugInfo(SymbolDocumentInfo document)
{
ArgumentNullException.ThrowIfNull(document);
return new ClearDebugInfoExpression(document);
}
private static void ValidateSpan(int startLine, int startColumn, int endLine, int endColumn)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(startLine);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(startColumn);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(endLine);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(endColumn);
if (startLine > endLine)
{
throw Error.StartEndMustBeOrdered();
}
if (startLine == endLine && startColumn > endColumn)
{
throw Error.StartEndMustBeOrdered();
}
}
}
}