| ... | @@ -9,13 +9,13 @@ const Graph = @import("Graph.zig"); | ... | @@ -9,13 +9,13 @@ const Graph = @import("Graph.zig"); |
| 9 | | 9 | |
| 10 | configuration: Configuration, | 10 | configuration: Configuration, |
| 11 | top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index), | 11 | top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index), |
| | 12 | modules: std.AutoArrayHashMapUnmanaged(Configuration.Module.Index, void), |
| 12 | | 13 | |
| 13 | pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { | 14 | pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| 14 | std.log.err("TODO also print paths", .{}); | 15 | std.log.err("TODO also print paths", .{}); |
| 15 | std.log.err("TODO also print unlazy deps", .{}); | 16 | std.log.err("TODO also print unlazy deps", .{}); |
| 16 | std.log.err("TODO also print system integrations", .{}); | 17 | std.log.err("TODO also print system integrations", .{}); |
| 17 | std.log.err("TODO also print available options", .{}); | 18 | std.log.err("TODO also print available options", .{}); |
| 18 | std.log.err("TODO also print modules", .{}); | | |
| 19 | const c = &sc.configuration; | 19 | const c = &sc.configuration; |
| 20 | var serializer: Serializer = .{ .writer = w }; | 20 | var serializer: Serializer = .{ .writer = w }; |
| 21 | var s = try serializer.beginStruct(.{}); | 21 | var s = try serializer.beginStruct(.{}); |
| ... | @@ -31,7 +31,7 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { | ... | @@ -31,7 +31,7 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| 31 | | 31 | |
| 32 | { | 32 | { |
| 33 | var tf = try s.beginTupleField("steps", .{}); | 33 | var tf = try s.beginTupleField("steps", .{}); |
| 34 | for (c.steps) |*step| { | 34 | for (c.steps) |step| { |
| 35 | var step_field = try tf.beginStructField(.{}); | 35 | var step_field = try tf.beginStructField(.{}); |
| 36 | try printStruct(sc, &step_field, Configuration.Step, step); | 36 | try printStruct(sc, &step_field, Configuration.Step, step); |
| 37 | try step_field.end(); | 37 | try step_field.end(); |
| ... | @@ -39,10 +39,23 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { | ... | @@ -39,10 +39,23 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| 39 | try tf.end(); | 39 | try tf.end(); |
| 40 | } | 40 | } |
| 41 | | 41 | |
| | 42 | { |
| | 43 | var sf = try s.beginStructField("modules", .{}); |
| | 44 | |
| | 45 | for (sc.modules.keys()) |module_index| { |
| | 46 | var int_buf: [50]u8 = undefined; |
| | 47 | const int_str = std.fmt.bufPrint(&int_buf, "{d}", .{module_index}) catch unreachable; |
| | 48 | var step_field = try sf.beginStructField(int_str, .{}); |
| | 49 | try printStruct(sc, &step_field, Configuration.Module, module_index.get(c)); |
| | 50 | try step_field.end(); |
| | 51 | } |
| | 52 | try sf.end(); |
| | 53 | } |
| | 54 | |
| 42 | try s.end(); | 55 | try s.end(); |
| 43 | } | 56 | } |
| 44 | | 57 | |
| 45 | fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: *const S) !void { | 58 | fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: S) !void { |
| 46 | inline for (@typeInfo(S).@"struct".fields) |field| { | 59 | inline for (@typeInfo(S).@"struct".fields) |field| { |
| 47 | try s.fieldPrefix(field.name); | 60 | try s.fieldPrefix(field.name); |
| 48 | try printValue(sc, s.container.serializer, field.type, @field(v, field.name)); | 61 | try printValue(sc, s.container.serializer, field.type, @field(v, field.name)); |
| ... | @@ -78,7 +91,11 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi | ... | @@ -78,7 +91,11 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi |
| 78 | if (@hasDecl(Field, "storage")) switch (Field.storage) { | 91 | if (@hasDecl(Field, "storage")) switch (Field.storage) { |
| 79 | .extended => { | 92 | .extended => { |
| 80 | var sub_struct = try s.beginStruct(.{}); | 93 | var sub_struct = try s.beginStruct(.{}); |
| 81 | try printTaggedUnion(sc, &sub_struct, field_value.get(c.extra)); | 94 | switch (field_value.get(c.extra)) { |
| | 95 | inline else => |u| { |
| | 96 | try printStruct(sc, &sub_struct, @TypeOf(u), u); |
| | 97 | }, |
| | 98 | } |
| 82 | try sub_struct.end(); | 99 | try sub_struct.end(); |
| 83 | }, | 100 | }, |
| 84 | .flag_optional => comptime unreachable, | 101 | .flag_optional => comptime unreachable, |
| ... | @@ -98,6 +115,11 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi | ... | @@ -98,6 +115,11 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi |
| 98 | .@"packed" => { | 115 | .@"packed" => { |
| 99 | try s.value(field_value, .{}); | 116 | try s.value(field_value, .{}); |
| 100 | }, | 117 | }, |
| | 118 | .@"extern" => { |
| | 119 | var sub_struct = try s.beginStruct(.{}); |
| | 120 | try printStruct(sc, &sub_struct, Field, field_value); |
| | 121 | try sub_struct.end(); |
| | 122 | }, |
| 101 | .auto => switch (Field.storage) { | 123 | .auto => switch (Field.storage) { |
| 102 | .flag_optional, .enum_optional => { | 124 | .flag_optional, .enum_optional => { |
| 103 | if (field_value.value) |some| { | 125 | if (field_value.value) |some| { |
| ... | @@ -110,35 +132,41 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi | ... | @@ -110,35 +132,41 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi |
| 110 | try printValue(sc, s, @TypeOf(field_value.slice), field_value.slice); | 132 | try printValue(sc, s, @TypeOf(field_value.slice), field_value.slice); |
| 111 | }, | 133 | }, |
| 112 | .extended => @compileError("TODO"), | 134 | .extended => @compileError("TODO"), |
| 113 | .union_list => @compileError("TODO"), | 135 | .union_list => { |
| | 136 | var slice_field = try s.beginTuple(.{}); |
| | 137 | for (field_value.get(c.extra), 0..) |elem, i| switch (field_value.tag(c.extra, i)) { |
| | 138 | inline else => |tag| { |
| | 139 | var sub_struct = try s.beginStruct(.{}); |
| | 140 | try sub_struct.fieldPrefix(@tagName(tag)); |
| | 141 | try printValue(sc, s, @FieldType(Field.Union, @tagName(tag)), @enumFromInt(elem)); |
| | 142 | try sub_struct.end(); |
| | 143 | }, |
| | 144 | }; |
| | 145 | try slice_field.end(); |
| | 146 | }, |
| 114 | .flag_union => try printValue(sc, s, Field.Union, field_value.u), | 147 | .flag_union => try printValue(sc, s, Field.Union, field_value.u), |
| 115 | .multi_list => @compileError("TODO"), | 148 | .multi_list => @compileError("TODO"), |
| 116 | }, | 149 | }, |
| 117 | else => @compileError("not implemented: " ++ @typeName(Field)), | | |
| 118 | }, | 150 | }, |
| 119 | .@"union" => { | 151 | .@"union" => { |
| 120 | switch (field_value) { | 152 | try printTaggedUnion(sc, s, field_value); |
| 121 | inline else => |u, tag| { | | |
| 122 | if (@TypeOf(u) == void) { | | |
| 123 | try s.ident(@tagName(tag)); | | |
| 124 | } else { | | |
| 125 | var sub_struct = try s.beginStruct(.{}); | | |
| 126 | try sub_struct.fieldPrefix(@tagName(tag)); | | |
| 127 | try printValue(sc, s, @TypeOf(u), u); | | |
| 128 | try sub_struct.end(); | | |
| 129 | } | | |
| 130 | }, | | |
| 131 | } | | |
| 132 | }, | 153 | }, |
| 133 | else => @compileError("not implemented: " ++ @typeName(Field)), | 154 | else => @compileError("not implemented: " ++ @typeName(Field)), |
| 134 | }, | 155 | }, |
| 135 | } | 156 | } |
| 136 | } | 157 | } |
| 137 | | 158 | |
| 138 | fn printTaggedUnion(sc: *const ScannedConfig, s: *Serializer.Struct, value: anytype) !void { | 159 | fn printTaggedUnion(sc: *const ScannedConfig, s: *Serializer, value: anytype) !void { |
| 139 | switch (value) { | 160 | switch (value) { |
| 140 | inline else => |*u| { | 161 | inline else => |u, tag| { |
| 141 | try printStruct(sc, s, @TypeOf(u.*), u); | 162 | if (@TypeOf(u) == void) { |
| | 163 | try s.ident(@tagName(tag)); |
| | 164 | } else { |
| | 165 | var sub_struct = try s.beginStruct(.{}); |
| | 166 | try sub_struct.fieldPrefix(@tagName(tag)); |
| | 167 | try printValue(sc, s, @TypeOf(u), u); |
| | 168 | try sub_struct.end(); |
| | 169 | } |
| 142 | }, | 170 | }, |
| 143 | } | 171 | } |
| 144 | } | 172 | } |