-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathSyntaxElement.cs
44 lines (37 loc) · 1.54 KB
/
SyntaxElement.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
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Esprima.Utils;
namespace Esprima.Ast;
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(), nq}}")]
public abstract class SyntaxElement
{
private protected AdditionalDataSlot _additionalDataSlot;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private protected object? GetDynamicPropertyValue(int propertyIndex)
{
Debug.Assert(propertyIndex > 0, "Index must be greater than 0.");
return _additionalDataSlot[propertyIndex];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private protected void SetDynamicPropertyValue(int propertyIndex, object? value)
{
Debug.Assert(propertyIndex > 0, "Index must be greater than 0.");
_additionalDataSlot[propertyIndex] = value;
}
/// <summary>
/// Gets or sets the arbitrary, user-defined data object associated with the current <see cref="SyntaxElement"/>.
/// </summary>
/// <remarks>
/// The operation is not guaranteed to be thread-safe. In case concurrent access or update is possible, the necessary synchronization is caller's responsibility.
/// </remarks>
public object? AssociatedData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _additionalDataSlot.PrimaryData;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => _additionalDataSlot.PrimaryData = value;
}
public Range Range;
public Location Location;
private protected virtual string GetDebuggerDisplay() => ToString();
}