@@ -77,7 +77,7 @@ fn printTypeDefinition(options: *Options, out: Writer, comptime T: type) !void {
77
77
if (@"struct" .is_tuple ) return ;
78
78
79
79
try out .print ("pub const {} = " , .{std .zig .fmtId (@typeName (T ))});
80
- try printStructDefinition (options , out , T );
80
+ try printStructDefinition (options , out , T , 0 );
81
81
try out .writeAll (";\n\n " );
82
82
},
83
83
.@"union" = > | @"union" | {
@@ -114,36 +114,38 @@ fn printEnumDefinition(options: *Options, out: Writer, comptime T: type) !void {
114
114
try out.writeAll(" }");
115
115
}
116
116
117
- fn printStructDefinition(options: *Options, out: Writer, comptime T: type) !void {
117
+ fn printStructDefinition(options: *Options, out: Writer, comptime T: type, indent: u8 ) !void {
118
118
const @" struct " = @typeInfo(T).@" struct ";
119
119
120
120
switch (@" struct ".layout) {
121
121
.auto => try out.writeAll(" struct "),
122
122
.@" extern " => try out.writeAll(" extern struct "),
123
123
.@" packed " => {
124
124
try out.writeAll(" packed struct (");
125
- try printTypeName(options, out, @" struct ".backing_integer.?, indent_width );
125
+ try printTypeName(options, out, @" struct ".backing_integer.?, indent );
126
126
try out.writeAll(" )");
127
127
},
128
128
}
129
129
if (@" struct ".fields.len == 0) return out.writeAll(" {}");
130
130
try out.writeAll(" {\n ");
131
131
132
132
inline for (@" struct ".fields) |field| {
133
- try out.writeAll(" " ** indent_width);
133
+ const field_indent = indent +| indent_width;
134
+ try out.writeByteNTimes(' ', field_indent);
134
135
if (field.is_comptime) try out.writeAll(" comptime ");
135
136
if (!@" struct ".is_tuple) try out.print(" {p_ }: ", .{std.zig.fmtId(field.name)});
136
- try printTypeName(options, out, field.type, indent_width );
137
+ try printTypeName(options, out, field.type, field_indent );
137
138
if (!@" struct ".is_tuple and @" struct ".layout != .@" packed " and field.alignment != @alignOf(field.type)) {
138
139
try out.print(" align ({})", .{field.alignment});
139
140
}
140
141
if (field.defaultValue()) |default_value| {
141
142
try out.writeAll(" = ");
142
- try printValue(options, out, field.type, default_value, indent_width );
143
+ try printValue(options, out, field.type, default_value, field_indent );
143
144
}
144
145
try out.writeAll(" ,\n ");
145
146
}
146
147
148
+ try out.writeByteNTimes(' ', indent);
147
149
try out.writeAll(" }");
148
150
}
149
151
@@ -216,7 +218,7 @@ fn printTypeName(options: *Options, out: Writer, comptime T: type, indent: u8) !
216
218
.@"enum" = > try out .print ("{}" , .{std .zig .fmtId (@typeName (T ))}),
217
219
.@"struct" = > | @"struct" | {
218
220
if (@"struct" .is_tuple ) {
219
- try printStructDefinition (options , out , T );
221
+ try printStructDefinition (options , out , T , indent );
220
222
} else {
221
223
try out .print ("{}" , .{std .zig .fmtId (@typeName (T ))});
222
224
}
@@ -276,10 +278,10 @@ fn printValue(options: *Options, out: Writer, comptime T: type, value: T, indent
276
278
277
279
try out .writeAll (".{\n " );
278
280
inline for (@"struct" .fields ) | field | {
279
- const elem_indent = indent + | indent_width ;
280
- try out .writeByteNTimes (' ' , elem_indent );
281
+ const field_indent = indent + | indent_width ;
282
+ try out .writeByteNTimes (' ' , field_indent );
281
283
if (! @"struct" .is_tuple ) try out .print (".{p_} = " , .{std .zig .fmtId (field .name )});
282
- try printValue (options , out , field .type , @field (value , field .name ), elem_indent );
284
+ try printValue (options , out , field .type , @field (value , field .name ), field_indent );
283
285
try out .writeAll (",\n " );
284
286
}
285
287
try out .writeByteNTimes (' ' , indent );
0 commit comments