authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-08-27 16:01:08-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-08-27 16:02:00-06:00
loge4b61aa527f7ea06943bab720f672dd435b9dfba
tree43e8b8e051ba5c0007d005334fb1cc408359f4aa
parent3c87872dc5d7574e0e845568dc753ec48cb0cba0
signature Commit is signed but in an unrecognized format.

std.meta.TrailerFlags fixes


2 files changed, 12 insertions(+), 14 deletions(-)

lib/std/meta/trailer_flags.zig+11-13
...@@ -22,16 +22,14 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -22,16 +22,14 @@ pub fn TrailerFlags(comptime Fields: type) type {
22 pub const bit_count = @typeInfo(Fields).Struct.fields.len;22 pub const bit_count = @typeInfo(Fields).Struct.fields.len;
2323
24 pub const FieldEnum = blk: {24 pub const FieldEnum = blk: {
25 comptime var fields: []const TypeInfo.EnumField = &[_]TypeInfo.EnumField{};25 comptime var fields: [bit_count]TypeInfo.EnumField = undefined;
26 inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| {26 inline for (@typeInfo(Fields).Struct.fields) |struct_field, i|
27 const field = TypeInfo.EnumField{ .name = struct_field.name, .value = i };27 fields[i] = .{ .name = struct_field.name, .value = i };
28 fields = fields ++ [_]TypeInfo.EnumField{field};
29 }
30 break :blk @Type(.{28 break :blk @Type(.{
31 .Enum = .{29 .Enum = .{
32 .layout = .Auto,30 .layout = .Auto,
33 .tag_type = std.math.IntFittingRange(0, bit_count - 1),31 .tag_type = std.math.IntFittingRange(0, bit_count - 1),
34 .fields = fields,32 .fields = &fields,
35 .decls = &[_]TypeInfo.Declaration{},33 .decls = &[_]TypeInfo.Declaration{},
36 .is_exhaustive = true,34 .is_exhaustive = true,
37 },35 },
...@@ -39,19 +37,21 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -39,19 +37,21 @@ pub fn TrailerFlags(comptime Fields: type) type {
39 };37 };
4038
41 pub const InitStruct = blk: {39 pub const InitStruct = blk: {
42 comptime var fields: []const TypeInfo.StructField = &[_]TypeInfo.StructField{};40 comptime var fields: [bit_count]TypeInfo.StructField = undefined;
43 inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| {41 inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| {
44 const field = TypeInfo.StructField{42 fields[i] = TypeInfo.StructField{
45 .name = struct_field.name,43 .name = struct_field.name,
46 .field_type = ?struct_field.field_type,44 .field_type = ?struct_field.field_type,
47 .default_value = @as(??struct_field.field_type, @as(?struct_field.field_type, null)),45 .default_value = @as(
46 ??struct_field.field_type,
47 @as(?struct_field.field_type, null),
48 ),
48 };49 };
49 fields = fields ++ [_]TypeInfo.StructField{field};
50 }50 }
51 break :blk @Type(.{51 break :blk @Type(.{
52 .Struct = .{52 .Struct = .{
53 .layout = .Auto,53 .layout = .Auto,
54 .fields = fields,54 .fields = &fields,
55 .decls = &[_]TypeInfo.Declaration{},55 .decls = &[_]TypeInfo.Declaration{},
56 .is_tuple = false,56 .is_tuple = false,
57 },57 },
...@@ -77,7 +77,6 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -77,7 +77,6 @@ pub fn TrailerFlags(comptime Fields: type) type {
77 }77 }
7878
79 /// `fields` is a struct with each field set to an optional value.79 /// `fields` is a struct with each field set to an optional value.
80 /// Missing fields are assumed to be `null`.
81 /// Only the non-null bits are observed and are used to set the flag bits.80 /// Only the non-null bits are observed and are used to set the flag bits.
82 pub fn init(fields: InitStruct) Self {81 pub fn init(fields: InitStruct) Self {
83 var self: Self = .{ .bits = 0 };82 var self: Self = .{ .bits = 0 };
...@@ -89,7 +88,6 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -89,7 +88,6 @@ pub fn TrailerFlags(comptime Fields: type) type {
89 }88 }
9089
91 /// `fields` is a struct with each field set to an optional value (same as `init`).90 /// `fields` is a struct with each field set to an optional value (same as `init`).
92 /// Missing fields are assumed to be `null`.
93 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: InitStruct) void {91 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: InitStruct) void {
94 inline for (@typeInfo(Fields).Struct.fields) |field, i| {92 inline for (@typeInfo(Fields).Struct.fields) |field, i| {
95 if (@field(fields, field.name)) |value|93 if (@field(fields, field.name)) |value|
lib/std/zig/ast.zig+1-1
...@@ -1321,7 +1321,7 @@ pub const Node = struct {...@@ -1321,7 +1321,7 @@ pub const Node = struct {
1321 self,1321 self,
1322 self.trailer_flags.bits,1322 self.trailer_flags.bits,
1323 self.getTrailer(.name_token),1323 self.getTrailer(.name_token),
1324 self.trailer_flags.ptrConst(trailers_start, "name_token"),1324 self.trailer_flags.ptrConst(trailers_start, .name_token),
1325 self.params_len,1325 self.params_len,
1326 });1326 });
1327 }1327 }