Skip to content

Commit cae0233

Browse files
authored
Update Symbols to be records (#890)
1 parent 75c3600 commit cae0233

File tree

8 files changed

+30
-70
lines changed

8 files changed

+30
-70
lines changed

src/generators/Silk.NET.SilkTouch.Symbols/FieldSymbol.cs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,7 @@ namespace Silk.NET.SilkTouch.Symbols;
66
/// <summary>
77
/// A <see cref="FieldSymbol"/>. A field is simply a named location that can hold some type.
88
/// </summary>
9+
/// <param name="Type">The <see cref="TypeSymbol"/> of the data stored in this field</param>
10+
/// <param name="Identifier">The Identifier of this field</param>
911
/// <seealso cref="MemberSymbol"/>
10-
public sealed class FieldSymbol : MemberSymbol
11-
{
12-
/// <summary>
13-
/// Create a field symbol from the parent <see cref="TypeSymbol"/>, the type of the field and it's identifier
14-
/// </summary>
15-
/// <param name="type">The type of the data stored in this field</param>
16-
/// <param name="identifier">The identifier of this field</param>
17-
public FieldSymbol(TypeSymbol type, IdentifierSymbol identifier)
18-
{
19-
Type = type;
20-
Identifier = identifier;
21-
}
22-
23-
/// <summary>
24-
/// The <see cref="TypeSymbol"/> of the data stored in this field
25-
/// </summary>
26-
public TypeSymbol Type { get; }
27-
28-
/// <summary>
29-
/// The Identifier of this field
30-
/// </summary>
31-
public IdentifierSymbol Identifier { get; }
32-
}
12+
public sealed record FieldSymbol(TypeSymbol Type, IdentifierSymbol Identifier) : MemberSymbol;

src/generators/Silk.NET.SilkTouch.Symbols/IdentifierSymbol.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ namespace Silk.NET.SilkTouch.Symbols;
66
/// <summary>
77
/// An Identifier. Generally used to identify another symbol
88
/// </summary>
9+
/// <param name="Value">The String Value of this identifier</param>
910
/// <seealso cref="TypeSymbol"/>
10-
public sealed class IdentifierSymbol : Symbol
11-
{
12-
/// <summary>
13-
/// Create an <see cref="IdentifierSymbol"/> from a string
14-
/// </summary>
15-
/// <param name="value">The identifier as a string</param>
16-
public IdentifierSymbol(string value)
17-
{
18-
Value = value;
19-
}
20-
21-
/// <summary>
22-
/// The Value of this Identifier as a String
23-
/// </summary>
24-
public string Value { get; }
25-
}
11+
public sealed record IdentifierSymbol(string Value) : Symbol;

src/generators/Silk.NET.SilkTouch.Symbols/MemberSymbol.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ namespace Silk.NET.SilkTouch.Symbols;
77
/// A <see cref="MemberSymbol"/>, representing a generic member of some <see cref="TypeSymbol"/>
88
/// </summary>
99
/// <seealso cref="FieldSymbol"/>
10-
public abstract class MemberSymbol : Symbol
11-
{
12-
}
10+
public abstract record MemberSymbol : Symbol;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#if NETSTANDARD2_0
5+
using System.ComponentModel;
6+
7+
// ReSharper disable once CheckNamespace
8+
namespace System.Runtime.CompilerServices
9+
{
10+
/// <summary>
11+
/// Reserved to be used by the compiler for tracking metadata.
12+
/// This class should not be used by developers in source code.
13+
/// </summary>
14+
[EditorBrowsable(EditorBrowsableState.Never)]
15+
internal static class IsExternalInit
16+
{
17+
}
18+
}
19+
#endif

src/generators/Silk.NET.SilkTouch.Symbols/Silk.NET.SilkTouch.Symbols.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
8-
98
</Project>

src/generators/Silk.NET.SilkTouch.Symbols/StructSymbol.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,11 @@ namespace Silk.NET.SilkTouch.Symbols;
66
/// <summary>
77
/// A <see cref="TypeSymbol"/> representing a <c>struct</c>.
88
/// </summary>
9+
/// <param name="Identifier">The Identifier of this struct</param>
910
/// <remarks>
1011
/// In this context, a Struct means a type that represents the layout of a continuous block of memory.
1112
/// </remarks>
1213
// /// Each meaningful place in this memory called a field (see <see cref="FieldSymbol"/>) is accessible via this type.
1314
// /// Fields are allowed to overlap.
1415
// /// Additionally it may contain one or multiple <see cref="MethodSymbol"/> that are called with an instance of this type as their first argument.
15-
public sealed class StructSymbol : TypeSymbol
16-
{
17-
/// <summary>
18-
/// Creates a struct symbol given it's identifier
19-
/// </summary>
20-
/// <param name="identifier">The identifier of the struct</param>
21-
public StructSymbol(IdentifierSymbol identifier)
22-
{
23-
Identifier = identifier;
24-
}
25-
26-
/// <summary>
27-
/// The identifier of this struct
28-
/// </summary>
29-
public override IdentifierSymbol Identifier { get; }
30-
}
16+
public sealed record StructSymbol(IdentifierSymbol Identifier) : TypeSymbol(Identifier);

src/generators/Silk.NET.SilkTouch.Symbols/Symbol.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@ namespace Silk.NET.SilkTouch.Symbols;
66
/// <summary>
77
/// The base Symbol. Represents shared properties of all Symbols. Primarily used with <see cref="SymbolVisitor"/>
88
/// </summary>
9-
public abstract class Symbol
10-
{
11-
12-
}
9+
public abstract record Symbol;

src/generators/Silk.NET.SilkTouch.Symbols/TypeSymbol.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ namespace Silk.NET.SilkTouch.Symbols;
66
/// <summary>
77
/// A generic <see cref="Symbol"/> representing a named type.
88
/// </summary>
9+
/// <param name="Identifier">The identifier of this type</param>
910
/// <seealso cref="StructSymbol"/>
10-
public abstract class TypeSymbol : Symbol
11-
{
12-
/// <summary>
13-
/// The identifier of this type
14-
/// </summary>
15-
public abstract IdentifierSymbol Identifier { get; }
16-
}
11+
public abstract record TypeSymbol(IdentifierSymbol Identifier) : Symbol;

0 commit comments

Comments
 (0)