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

Anonymous structs and unions #29

Merged
merged 3 commits into from
Apr 10, 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
27 changes: 27 additions & 0 deletions src/c/tests/structs/struct_anonymous_char_int/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"inputFilePath": "./main.c",
"userIncludeDirectories": [
"../../../production/ffi_helper/include"
],
"ignoredIncludeFiles": [
"../../../production/ffi_helper/include/ffi_helper.h"
],
"targetPlatforms": {
"windows": {
"i686-pc-windows-msvc": {},
"x86_64-pc-windows-msvc": {},
"aarch64-pc-windows-msvc": {}
},
"macos": {
"i686-apple-darwin": {},
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"aarch64-apple-ios": {}
},
"linux": {
"i686-unknown-linux-gnu": {},
"x86_64-unknown-linux-gnu": {},
"aarch64-unknown-linux-gnu": {}
}
}
}
12 changes: 12 additions & 0 deletions src/c/tests/structs/struct_anonymous_char_int/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
#include "ffi_helper.h"

struct struct_anonymous_char_int
{
struct {
char a;
int b;
};
};

FFI_API_DECL struct struct_anonymous_char_int struct_anonymous_char_int;
27 changes: 27 additions & 0 deletions src/c/tests/structs/struct_anonymous_nested/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"inputFilePath": "./main.c",
"userIncludeDirectories": [
"../../../production/ffi_helper/include"
],
"ignoredIncludeFiles": [
"../../../production/ffi_helper/include/ffi_helper.h"
],
"targetPlatforms": {
"windows": {
"i686-pc-windows-msvc": {},
"x86_64-pc-windows-msvc": {},
"aarch64-pc-windows-msvc": {}
},
"macos": {
"i686-apple-darwin": {},
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"aarch64-apple-ios": {}
},
"linux": {
"i686-unknown-linux-gnu": {},
"x86_64-unknown-linux-gnu": {},
"aarch64-unknown-linux-gnu": {}
}
}
}
18 changes: 18 additions & 0 deletions src/c/tests/structs/struct_anonymous_nested/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
#include "ffi_helper.h"

struct struct_anonymous_nested
{
struct {
struct {
char a;
int b;
};
struct {
char c;
int d;
};
};
};

FFI_API_DECL struct struct_anonymous_nested struct_anonymous_nested;
2 changes: 1 addition & 1 deletion src/c/tests/structs/struct_int/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
struct struct_int
{
int a;
}
};

FFI_API_DECL struct struct_int struct_int;
27 changes: 27 additions & 0 deletions src/c/tests/unions/union_anonymous_char_int/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"inputFilePath": "./main.c",
"userIncludeDirectories": [
"../../../production/ffi_helper/include"
],
"ignoredIncludeFiles": [
"../../../production/ffi_helper/include/ffi_helper.h"
],
"targetPlatforms": {
"windows": {
"i686-pc-windows-msvc": {},
"x86_64-pc-windows-msvc": {},
"aarch64-pc-windows-msvc": {}
},
"macos": {
"i686-apple-darwin": {},
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"aarch64-apple-ios": {}
},
"linux": {
"i686-unknown-linux-gnu": {},
"x86_64-unknown-linux-gnu": {},
"aarch64-unknown-linux-gnu": {}
}
}
}
12 changes: 12 additions & 0 deletions src/c/tests/unions/union_anonymous_char_int/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
#include "ffi_helper.h"

union union_anonymous_char_int
{
union {
char a;
int b;
};
};

FFI_API_DECL union union_anonymous_char_int union_anonymous_char_int;
27 changes: 27 additions & 0 deletions src/c/tests/unions/union_anonymous_nested/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"inputFilePath": "./main.c",
"userIncludeDirectories": [
"../../../production/ffi_helper/include"
],
"ignoredIncludeFiles": [
"../../../production/ffi_helper/include/ffi_helper.h"
],
"targetPlatforms": {
"windows": {
"i686-pc-windows-msvc": {},
"x86_64-pc-windows-msvc": {},
"aarch64-pc-windows-msvc": {}
},
"macos": {
"i686-apple-darwin": {},
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"aarch64-apple-ios": {}
},
"linux": {
"i686-unknown-linux-gnu": {},
"x86_64-unknown-linux-gnu": {},
"aarch64-unknown-linux-gnu": {}
}
}
}
18 changes: 18 additions & 0 deletions src/c/tests/unions/union_anonymous_nested/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
#include "ffi_helper.h"

union union_anonymous_nested
{
union {
union {
char a;
int b;
};
union {
char c;
int d;
};
};
};

FFI_API_DECL union union_anonymous_nested union_anonymous_nested;
11 changes: 3 additions & 8 deletions src/cs/production/c2ffi.Data/CLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public record struct CLocation : IComparable<CLocation>
/// <summary>
/// Gets or sets the file name of the C header file with it's file extension but without it's directory path.
/// </summary>
[JsonPropertyName("fileName")]
[JsonPropertyName("file_name")]
public string FileName { get; set; }

/// <summary>
/// Gets or sets the relative file path of the C header file.
/// </summary>
[JsonPropertyName("filePath")]
[JsonPropertyName("file_path")]
public string FilePath { get; set; }

/// <summary>
Expand All @@ -47,7 +47,7 @@ public record struct CLocation : IComparable<CLocation>
/// <summary>
/// Gets or sets a value indicating whether the location originates from a system header.
/// </summary>
[JsonPropertyName("isSystem")]
[JsonPropertyName("is_system")]
public bool IsSystem { get; set; }

/// <summary>
Expand All @@ -71,11 +71,6 @@ public int CompareTo(CLocation other)
}

result = LineColumn.CompareTo(other.LineColumn);
if (result != 0)
{
return result;
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace c2ffi.Data;
// NOTE: Properties are required for System.Text.Json serialization

/// <summary>
/// Represents information about a C type.
/// Represents a C type.
/// </summary>
[PublicAPI]
public class CTypeInfo : IEquatable<CTypeInfo>
public class CType : IEquatable<CType>
{
/// <summary>
/// Gets or sets the name of the C type.
Expand Down Expand Up @@ -54,7 +54,7 @@ public class CTypeInfo : IEquatable<CTypeInfo>
/// <summary>
/// Gets or sets a value indicating whether the C type is anonymous.
/// </summary>
[JsonPropertyName("is_snonymous")]
[JsonPropertyName("is_anonymous")]
public bool? IsAnonymous { get; set; }

/// <summary>
Expand All @@ -73,7 +73,7 @@ public class CTypeInfo : IEquatable<CTypeInfo>
/// Gets or sets the inner type information for pointer, array, and typedef alias types.
/// </summary>
[JsonPropertyName("inner_type")]
public CTypeInfo? InnerTypeInfo { get; set; }
public CType? InnerType { get; set; }

/// <inheritdoc />
[ExcludeFromCodeCoverage]
Expand All @@ -83,14 +83,14 @@ public override string ToString()
}

/// <summary>
/// Determines whether the specified <see cref="CTypeInfo" /> is equal to the current <see cref="CTypeInfo" />.
/// Determines whether the specified <see cref="CType" /> is equal to the current <see cref="CType" />.
/// </summary>
/// <param name="other">The <see cref="CTypeInfo" /> to compare with the current <see cref="CTypeInfo" />.</param>
/// <param name="other">The <see cref="CType" /> to compare with the current <see cref="CType" />.</param>
/// <returns>
/// <see langword="true" /> if the specified <see cref="CTypeInfo" /> is equal to the current
/// <see cref="CTypeInfo" />; otherwise, <see langword="false" />.
/// <see langword="true" /> if the specified <see cref="CType" /> is equal to the current
/// <see cref="CType" />; otherwise, <see langword="false" />.
/// </returns>
public bool Equals(CTypeInfo? other)
public bool Equals(CType? other)
{
if (other is null)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public override bool Equals(object? obj)
return false;
}

return Equals((CTypeInfo)obj);
return Equals((CType)obj);
}

/// <inheritdoc />
Expand All @@ -147,7 +147,7 @@ public override int GetHashCode()
hashCode.Add(IsAnonymous);
hashCode.Add(IsConst);
hashCode.Add(Location);
hashCode.Add(InnerTypeInfo);
hashCode.Add(InnerType);
return hashCode.ToHashCode();
// ReSharper restore NonReadonlyMemberInGetHashCode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ public partial class JsonSerializerContextCFfiCrossPlatform

properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::c2ffi.Data.CFunctionCallingConvention>(options, info0);

var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::c2ffi.Data.CTypeInfo>
var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::c2ffi.Data.CType>
{
IsProperty = true,
IsPublic = true,
IsVirtual = false,
DeclaringType = typeof(global::c2ffi.Data.Nodes.CFunction),
Converter = null,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunction)obj).ReturnTypeInfo,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunction)obj).ReturnTypeInfo = value!,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunction)obj).ReturnType,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunction)obj).ReturnType = value!,
IgnoreCondition = null,
HasJsonInclude = false,
IsExtensionData = false,
NumberHandling = null,
PropertyName = "ReturnTypeInfo",
PropertyName = "ReturnType",
JsonPropertyName = "return_type"
};

properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::c2ffi.Data.CTypeInfo>(options, info1);
properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::c2ffi.Data.CType>(options, info1);

var info2 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Collections.Immutable.ImmutableArray<global::c2ffi.Data.Nodes.CFunctionParameter>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ public partial class JsonSerializerContextCFfiCrossPlatform

properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<string>(options, info0);

var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::c2ffi.Data.CTypeInfo>
var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::c2ffi.Data.CType>
{
IsProperty = true,
IsPublic = true,
IsVirtual = false,
DeclaringType = typeof(global::c2ffi.Data.Nodes.CFunctionParameter),
Converter = null,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunctionParameter)obj).TypeInfo,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunctionParameter)obj).TypeInfo = value!,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunctionParameter)obj).Type,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunctionParameter)obj).Type = value!,
IgnoreCondition = null,
HasJsonInclude = false,
IsExtensionData = false,
NumberHandling = null,
PropertyName = "TypeInfo",
PropertyName = "Type",
JsonPropertyName = "type"
};

properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::c2ffi.Data.CTypeInfo>(options, info1);
properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::c2ffi.Data.CType>(options, info1);

var info2 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::c2ffi.Data.CLocation?>
{
Expand Down
Loading