Skip to content

Update Symbols to be records #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions src/generators/Silk.NET.SilkTouch.Symbols/FieldSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,7 @@ namespace Silk.NET.SilkTouch.Symbols;
/// <summary>
/// A <see cref="FieldSymbol"/>. A field is simply a named location that can hold some type.
/// </summary>
/// <param name="Type">The <see cref="TypeSymbol"/> of the data stored in this field</param>
/// <param name="Identifier">The Identifier of this field</param>
/// <seealso cref="MemberSymbol"/>
public sealed class FieldSymbol : MemberSymbol
{
/// <summary>
/// Create a field symbol from the parent <see cref="TypeSymbol"/>, the type of the field and it's identifier
/// </summary>
/// <param name="type">The type of the data stored in this field</param>
/// <param name="identifier">The identifier of this field</param>
public FieldSymbol(TypeSymbol type, IdentifierSymbol identifier)
{
Type = type;
Identifier = identifier;
}

/// <summary>
/// The <see cref="TypeSymbol"/> of the data stored in this field
/// </summary>
public TypeSymbol Type { get; }

/// <summary>
/// The Identifier of this field
/// </summary>
public IdentifierSymbol Identifier { get; }
}
public sealed record FieldSymbol(TypeSymbol Type, IdentifierSymbol Identifier) : MemberSymbol;
18 changes: 2 additions & 16 deletions src/generators/Silk.NET.SilkTouch.Symbols/IdentifierSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ namespace Silk.NET.SilkTouch.Symbols;
/// <summary>
/// An Identifier. Generally used to identify another symbol
/// </summary>
/// <param name="Value">The String Value of this identifier</param>
/// <seealso cref="TypeSymbol"/>
public sealed class IdentifierSymbol : Symbol
{
/// <summary>
/// Create an <see cref="IdentifierSymbol"/> from a string
/// </summary>
/// <param name="value">The identifier as a string</param>
public IdentifierSymbol(string value)
{
Value = value;
}

/// <summary>
/// The Value of this Identifier as a String
/// </summary>
public string Value { get; }
}
public sealed record IdentifierSymbol(string Value) : Symbol;
4 changes: 1 addition & 3 deletions src/generators/Silk.NET.SilkTouch.Symbols/MemberSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ namespace Silk.NET.SilkTouch.Symbols;
/// A <see cref="MemberSymbol"/>, representing a generic member of some <see cref="TypeSymbol"/>
/// </summary>
/// <seealso cref="FieldSymbol"/>
public abstract class MemberSymbol : Symbol
{
}
public abstract record MemberSymbol : Symbol;
19 changes: 19 additions & 0 deletions src/generators/Silk.NET.SilkTouch.Symbols/Shims.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETSTANDARD2_0
using System.ComponentModel;

// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
18 changes: 2 additions & 16 deletions src/generators/Silk.NET.SilkTouch.Symbols/StructSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,11 @@ namespace Silk.NET.SilkTouch.Symbols;
/// <summary>
/// A <see cref="TypeSymbol"/> representing a <c>struct</c>.
/// </summary>
/// <param name="Identifier">The Identifier of this struct</param>
/// <remarks>
/// In this context, a Struct means a type that represents the layout of a continuous block of memory.
/// </remarks>
// /// Each meaningful place in this memory called a field (see <see cref="FieldSymbol"/>) is accessible via this type.
// /// Fields are allowed to overlap.
// /// Additionally it may contain one or multiple <see cref="MethodSymbol"/> that are called with an instance of this type as their first argument.
public sealed class StructSymbol : TypeSymbol
{
/// <summary>
/// Creates a struct symbol given it's identifier
/// </summary>
/// <param name="identifier">The identifier of the struct</param>
public StructSymbol(IdentifierSymbol identifier)
{
Identifier = identifier;
}

/// <summary>
/// The identifier of this struct
/// </summary>
public override IdentifierSymbol Identifier { get; }
}
public sealed record StructSymbol(IdentifierSymbol Identifier) : TypeSymbol(Identifier);
5 changes: 1 addition & 4 deletions src/generators/Silk.NET.SilkTouch.Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ namespace Silk.NET.SilkTouch.Symbols;
/// <summary>
/// The base Symbol. Represents shared properties of all Symbols. Primarily used with <see cref="SymbolVisitor"/>
/// </summary>
public abstract class Symbol
{

}
public abstract record Symbol;
9 changes: 2 additions & 7 deletions src/generators/Silk.NET.SilkTouch.Symbols/TypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ namespace Silk.NET.SilkTouch.Symbols;
/// <summary>
/// A generic <see cref="Symbol"/> representing a named type.
/// </summary>
/// <param name="Identifier">The identifier of this type</param>
/// <seealso cref="StructSymbol"/>
public abstract class TypeSymbol : Symbol
{
/// <summary>
/// The identifier of this type
/// </summary>
public abstract IdentifierSymbol Identifier { get; }
}
public abstract record TypeSymbol(IdentifierSymbol Identifier) : Symbol;