Skip to content
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

Generating compiling code for .NET Framework 4.x #164

Merged
merged 6 commits into from
May 8, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// <auto-generated>
// This code was generated by the following tool on 2024-05-07 16:36:40 GMT-04:00:
// This code was generated by the following tool on 2024-05-07 22:28:44 GMT-04:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// To disable generating this file set `isEnabledGeneratingRuntimeCode` to `false` in the config file for generating C# code.

// <auto-generated>
// This code was generated by the following tool on 2024-05-07 16:36:40 GMT-04:00:
// This code was generated by the following tool on 2024-05-07 22:28:44 GMT-04:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
// ReSharper disable All

#region Template
#nullable enable
#pragma warning disable CS1591
#pragma warning disable CS8981
using Bindgen.Runtime;
Expand Down Expand Up @@ -85,7 +84,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CBool b && Equals(b);
}
Expand Down Expand Up @@ -197,7 +196,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CChar value && Equals(value);
}
Expand Down Expand Up @@ -260,27 +259,27 @@ public static bool Equals(CChar left, CChar right)
[StructLayout(LayoutKind.Sequential)]
public readonly unsafe struct CString : IEquatable<CString>, IDisposable
{
public readonly nint Pointer;
public readonly IntPtr Pointer;

/// <summary>
/// Gets a value indicating whether this <see cref="CString" /> is a null pointer.
/// </summary>
public bool IsNull => Pointer == 0;
public bool IsNull => Pointer == IntPtr.Zero;

/// <summary>
/// Initializes a new instance of the <see cref="CString" /> struct.
/// </summary>
/// <param name="value">The pointer value.</param>
public CString(byte* value)
{
Pointer = (nint)value;
Pointer = (IntPtr)value;
}

/// <summary>
/// Initializes a new instance of the <see cref="CString" /> struct.
/// </summary>
/// <param name="value">The pointer value.</param>
public CString(nint value)
public CString(IntPtr value)
{
Pointer = value;
}
Expand Down Expand Up @@ -309,7 +308,7 @@ public void Dispose()
/// <returns>
/// The resulting <see cref="CString" />.
/// </returns>
public static explicit operator CString(nint value)
public static explicit operator CString(IntPtr value)
{
return FromIntPtr(value);
}
Expand All @@ -321,7 +320,7 @@ public static explicit operator CString(nint value)
/// <returns>
/// The resulting <see cref="CString" />.
/// </returns>
public static CString FromIntPtr(nint value)
public static CString FromIntPtr(IntPtr value)
{
return new CString(value);
}
Expand All @@ -347,7 +346,7 @@ public static implicit operator CString(byte* value)
/// </returns>
public static CString From(byte* value)
{
return new CString((nint)value);
return new CString((IntPtr)value);
}

/// <summary>
Expand All @@ -357,7 +356,7 @@ public static CString From(byte* value)
/// <returns>
/// The resulting <see cref="IntPtr" />.
/// </returns>
public static implicit operator nint(CString value)
public static implicit operator IntPtr(CString value)
{
return value.Pointer;
}
Expand All @@ -369,7 +368,7 @@ public static implicit operator nint(CString value)
/// <returns>
/// The resulting <see cref="IntPtr" />.
/// </returns>
public static nint ToIntPtr(CString value)
public static IntPtr ToIntPtr(CString value)
{
return value.Pointer;
}
Expand Down Expand Up @@ -442,7 +441,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CString value && Equals(value);
}
Expand Down Expand Up @@ -496,7 +495,7 @@ public static unsafe class CStrings
/// </remarks>
/// <param name="values">The strings.</param>
/// <returns>An array pointer of C string pointers. You are responsible for freeing the returned pointer.</returns>
public static CString* CStringArray(ReadOnlySpan<string> values)
public static CString* CStringArray(string[] values)
{
var pointerSize = IntPtr.Size;
var result = (CString*)Marshal.AllocHGlobal(pointerSize * values.Length);
Expand All @@ -519,7 +518,7 @@ public static unsafe class CStrings
/// </remarks>
/// <param name="values">The strings.</param>
/// <returns>An array pointer of C string pointers. You are responsible for freeing the returned pointer.</returns>
public static CStringWide* CStringWideArray(ReadOnlySpan<string> values)
public static CStringWide* CStringWideArray(string[] values)
{
var pointerSize = IntPtr.Size;
var result = (CStringWide*)Marshal.AllocHGlobal(pointerSize * values.Length);
Expand All @@ -540,27 +539,27 @@ public static unsafe class CStrings
[StructLayout(LayoutKind.Sequential)]
public readonly unsafe struct CStringWide : IEquatable<CStringWide>
{
public readonly nint Pointer;
public readonly IntPtr Pointer;

/// <summary>
/// Gets a value indicating whether this <see cref="CStringWide" /> is a null pointer.
/// </summary>
public bool IsNull => Pointer == 0;
public bool IsNull => Pointer == IntPtr.Zero;

/// <summary>
/// Initializes a new instance of the <see cref="CStringWide" /> struct.
/// </summary>
/// <param name="value">The pointer value.</param>
public CStringWide(byte* value)
{
Pointer = (nint)value;
Pointer = (IntPtr)value;
}

/// <summary>
/// Initializes a new instance of the <see cref="CStringWide" /> struct.
/// </summary>
/// <param name="value">The pointer value.</param>
public CStringWide(nint value)
public CStringWide(IntPtr value)
{
Pointer = value;
}
Expand All @@ -581,7 +580,7 @@ public CStringWide(string s)
/// <returns>
/// The resulting <see cref="CStringWide" />.
/// </returns>
public static explicit operator CStringWide(nint value)
public static explicit operator CStringWide(IntPtr value)
{
return FromIntPtr(value);
}
Expand All @@ -593,7 +592,7 @@ public static explicit operator CStringWide(nint value)
/// <returns>
/// The resulting <see cref="CStringWide" />.
/// </returns>
public static CStringWide FromIntPtr(nint value)
public static CStringWide FromIntPtr(IntPtr value)
{
return new CStringWide(value);
}
Expand All @@ -619,7 +618,7 @@ public static implicit operator CStringWide(byte* value)
/// </returns>
public static CStringWide From(byte* value)
{
return new CStringWide((nint)value);
return new CStringWide((IntPtr)value);
}

/// <summary>
Expand All @@ -629,7 +628,7 @@ public static CStringWide From(byte* value)
/// <returns>
/// The resulting <see cref="IntPtr" />.
/// </returns>
public static implicit operator nint(CStringWide value)
public static implicit operator IntPtr(CStringWide value)
{
return value.Pointer;
}
Expand All @@ -641,7 +640,7 @@ public static implicit operator nint(CStringWide value)
/// <returns>
/// The resulting <see cref="IntPtr" />.
/// </returns>
public static nint ToIntPtr(CStringWide value)
public static IntPtr ToIntPtr(CStringWide value)
{
return value.Pointer;
}
Expand Down Expand Up @@ -714,7 +713,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CStringWide value && Equals(value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// <auto-generated>
// This code was generated by the following tool on 2024-05-07 16:36:40 GMT-04:00:
// This code was generated by the following tool on 2024-05-07 22:28:44 GMT-04:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion src/cs/production/Bindgen.Runtime/Bindgen.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>Bindgen.Runtime</RootNamespace>
<AssemblyName>Bindgen.Runtime</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion src/cs/production/Bindgen.Runtime/CBool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CBool b && Equals(b);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cs/production/Bindgen.Runtime/CChar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CChar value && Equals(value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cs/production/Bindgen.Runtime/CString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CString value && Equals(value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cs/production/Bindgen.Runtime/CStringWide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public override string ToString()
}

/// <inheritdoc />
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
return obj is CStringWide value && Equals(value);
}
Expand Down
5 changes: 3 additions & 2 deletions src/cs/production/Bindgen.Runtime/CStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Bindgen.Runtime;
Expand All @@ -20,7 +21,7 @@ public static unsafe class CStrings
/// </remarks>
/// <param name="values">The strings.</param>
/// <returns>An array pointer of C string pointers. You are responsible for freeing the returned pointer.</returns>
public static CString* CStringArray(ReadOnlySpan<string> values)
public static CString* CStringArray(string[] values)
{
var pointerSize = IntPtr.Size;
var result = (CString*)Marshal.AllocHGlobal(pointerSize * values.Length);
Expand All @@ -43,7 +44,7 @@ public static unsafe class CStrings
/// </remarks>
/// <param name="values">The strings.</param>
/// <returns>An array pointer of C string pointers. You are responsible for freeing the returned pointer.</returns>
public static CStringWide* CStringWideArray(ReadOnlySpan<string> values)
public static CStringWide* CStringWideArray(string[] values)
{
var pointerSize = IntPtr.Size;
var result = (CStringWide*)Marshal.AllocHGlobal(pointerSize * values.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace C2CS.Commands.WriteCodeCSharp.Data;
public sealed class CSharpStructField : CSharpNode
{
public readonly string BackingFieldName;
public readonly bool IsWrapped;
public readonly int OffsetOf;
public readonly CSharpType Type;

Expand All @@ -19,13 +18,11 @@ public CSharpStructField(
string cName,
int? sizeOf,
CSharpType type,
int offsetOf,
bool isWrapped)
int offsetOf)
: base(name, className, cName, sizeOf)
{
Type = type;
OffsetOf = offsetOf;
IsWrapped = isWrapped;
BackingFieldName = name.StartsWith('@') ? $"_{name[1..]}" : $"_{name}";
}

Expand All @@ -37,15 +34,14 @@ public override bool Equals(CSharpNode? other)
}

return BackingFieldName == other2.BackingFieldName &&
IsWrapped == other2.IsWrapped &&
OffsetOf == other2.OffsetOf &&
Type == other2.Type;
}

public override int GetHashCode()
{
var baseHashCOde = base.GetHashCode();
var hashCode = HashCode.Combine(baseHashCOde, BackingFieldName, IsWrapped, OffsetOf, Type);
var hashCode = HashCode.Combine(baseHashCOde, BackingFieldName, OffsetOf, Type);
return hashCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information.

using System;
using c2ffi.Data;

namespace C2CS.Commands.WriteCodeCSharp.Data;

public sealed class CSharpType : IEquatable<CSharpType>
{
public CNodeKind OriginalNodeKind { get; init; }

public string Name { get; init; } = string.Empty;

public string ClassName { get; init; } = string.Empty;
Expand All @@ -23,6 +26,8 @@ public sealed class CSharpType : IEquatable<CSharpType>

public bool IsArray => ArraySizeOf > 0;

public CSharpType? InnerType { get; init; }

public bool Equals(CSharpType? other)
{
if (ReferenceEquals(null, other))
Expand Down
Loading
Loading