Skip to content

Commit

Permalink
Anonymous structs and unions
Browse files Browse the repository at this point in the history
  • Loading branch information
lithiumtoast committed Apr 10, 2024
1 parent 469be70 commit 23a4cb4
Show file tree
Hide file tree
Showing 85 changed files with 1,280 additions and 399 deletions.
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;
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;
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,43 +45,43 @@ public partial class JsonSerializerContextCFfiCrossPlatform
{
var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[7];

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

properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::c2ffi.Data.CTypeInfo>(options, info0);
properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::c2ffi.Data.CType>(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.CFunctionPointer),
Converter = null,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunctionPointer)obj).ReturnTypeInfo,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunctionPointer)obj).ReturnTypeInfo = value!,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunctionPointer)obj).ReturnType,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunctionPointer)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.CFunctionPointerParameter>>
{
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.CFunctionPointerParameter),
Converter = null,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunctionPointerParameter)obj).TypeInfo,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunctionPointerParameter)obj).TypeInfo = value!,
Getter = static obj => ((global::c2ffi.Data.Nodes.CFunctionPointerParameter)obj).Type,
Setter = static (obj, value) => ((global::c2ffi.Data.Nodes.CFunctionPointerParameter)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<string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public partial class JsonSerializerContextCFfiCrossPlatform
IsExtensionData = false,
NumberHandling = null,
PropertyName = "FileName",
JsonPropertyName = "fileName"
JsonPropertyName = "file_name"
};

properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<string>(options, info0);
Expand All @@ -78,7 +78,7 @@ public partial class JsonSerializerContextCFfiCrossPlatform
IsExtensionData = false,
NumberHandling = null,
PropertyName = "FilePath",
JsonPropertyName = "filePath"
JsonPropertyName = "file_path"
};

properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<string>(options, info1);
Expand Down Expand Up @@ -154,7 +154,7 @@ public partial class JsonSerializerContextCFfiCrossPlatform
IsExtensionData = false,
NumberHandling = null,
PropertyName = "IsSystem",
JsonPropertyName = "isSystem"
JsonPropertyName = "is_system"
};

properties[5] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<bool>(options, info5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ public partial class JsonSerializerContextCFfiCrossPlatform
{
var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[5];

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

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

var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<string>
{
Expand Down
Loading

0 comments on commit 23a4cb4

Please sign in to comment.