0.11: generate: upgrade according with structs changes

This commit is contained in:
Pierre Tachoire
2023-09-19 16:58:36 +02:00
parent e64ffa0c27
commit b4e7da3e16

View File

@@ -77,7 +77,7 @@ pub const Union = struct {
const member_union = member_info.Union; const member_union = member_info.Union;
for (member_union.fields) |field| { for (member_union.fields) |field| {
enum_fields[done] = .{ enum_fields[done] = .{
.name = fmtName(field.field_type), .name = fmtName(field.type),
.value = done, .value = done,
}; };
done += 1; done += 1;
@@ -92,7 +92,6 @@ pub const Union = struct {
} }
const decls: [0]std.builtin.Type.Declaration = undefined; const decls: [0]std.builtin.Type.Declaration = undefined;
const enum_info = std.builtin.Type.Enum{ const enum_info = std.builtin.Type.Enum{
.layout = .Auto,
.tag_type = tag_type, .tag_type = tag_type,
.fields = &enum_fields, .fields = &enum_fields,
.decls = &decls, .decls = &decls,
@@ -110,15 +109,15 @@ pub const Union = struct {
const member_union = member_info.Union; const member_union = member_info.Union;
for (member_union.fields) |field| { for (member_union.fields) |field| {
var T: type = undefined; var T: type = undefined;
if (@hasDecl(field.field_type, "Self")) { if (@hasDecl(field.type, "Self")) {
T = @field(field.field_type, "Self"); T = @field(field.type, "Self");
T = *T; T = *T;
} else { } else {
T = field.field_type; T = field.type;
} }
union_fields[done] = .{ union_fields[done] = .{
.name = fmtName(field.field_type), .name = fmtName(field.type),
.field_type = T, .type = T,
.alignment = @alignOf(T), .alignment = @alignOf(T),
}; };
done += 1; done += 1;
@@ -132,7 +131,7 @@ pub const Union = struct {
} }
union_fields[done] = .{ union_fields[done] = .{
.name = fmtName(member_T), .name = fmtName(member_T),
.field_type = T, .type = T,
.alignment = @alignOf(T), .alignment = @alignOf(T),
}; };
done += 1; done += 1;
@@ -205,7 +204,7 @@ pub fn TupleT(comptime tuple: anytype) type {
while (done < members_nb) { while (done < members_nb) {
fields[done] = .{ fields[done] = .{
.name = try itoa(done), .name = try itoa(done),
.field_type = type, .type = type,
.default_value = null, .default_value = null,
.is_comptime = false, .is_comptime = false,
.alignment = @alignOf(type), .alignment = @alignOf(type),
@@ -299,7 +298,7 @@ pub fn tests() !void {
try std.testing.expect(from_structs_union == .Union); try std.testing.expect(from_structs_union == .Union);
try std.testing.expect(from_structs_union.Union.tag_type == FromStructs._enum); try std.testing.expect(from_structs_union.Union.tag_type == FromStructs._enum);
try std.testing.expect(from_structs_union.Union.fields.len == 3); try std.testing.expect(from_structs_union.Union.fields.len == 3);
try std.testing.expect(from_structs_union.Union.fields[0].field_type == Astruct); try std.testing.expect(from_structs_union.Union.fields[0].type == Astruct);
try std.testing.expectEqualStrings(from_structs_union.Union.fields[0].name, "Astruct"); try std.testing.expectEqualStrings(from_structs_union.Union.fields[0].name, "Astruct");
// Union from union and structs // Union from union and structs
@@ -316,7 +315,7 @@ pub fn tests() !void {
try std.testing.expect(from_mix_union == .Union); try std.testing.expect(from_mix_union == .Union);
try std.testing.expect(from_mix_union.Union.tag_type == FromMix._enum); try std.testing.expect(from_mix_union.Union.tag_type == FromMix._enum);
try std.testing.expect(from_mix_union.Union.fields.len == 4); try std.testing.expect(from_mix_union.Union.fields.len == 4);
try std.testing.expect(from_mix_union.Union.fields[3].field_type == Dstruct); try std.testing.expect(from_mix_union.Union.fields[3].type == Dstruct);
try std.testing.expectEqualStrings(from_mix_union.Union.fields[3].name, "Dstruct"); try std.testing.expectEqualStrings(from_mix_union.Union.fields[3].name, "Dstruct");
std.debug.print("Generate Union: OK\n", .{}); std.debug.print("Generate Union: OK\n", .{});