| author | |
| committer | |
| log | b6fe839248751f6e2cfbdbe2cc31e47aee154555 |
| tree | 1278697f1d9095eba22bc9cf1d4c4033b7fe6f24 |
| parent | fff00c3bbb9ed211f46eb1f1be07ebab84bc8d9d |
| signature |
10 files changed, 103 insertions(+), 42 deletions(-)
lib/std/json.zig+14-18| ... | ... | @@ -77,7 +77,7 @@ test "encodesTo" { |
| 77 | 77 | testing.expectEqual(true, encodesTo("false", "false")); |
| 78 | 78 | // totally different |
| 79 | 79 | testing.expectEqual(false, encodesTo("false", "true")); |
| 80 | // differnt lengths | |
| 80 | // different lengths | |
| 81 | 81 | testing.expectEqual(false, encodesTo("false", "other")); |
| 82 | 82 | // with escape |
| 83 | 83 | testing.expectEqual(true, encodesTo("\\", "\\\\")); |
| ... | ... | @@ -1771,22 +1771,20 @@ test "parse into struct with misc fields" { |
| 1771 | 1771 | static_array: [3]f64, |
| 1772 | 1772 | dynamic_array: []f64, |
| 1773 | 1773 | |
| 1774 | const Bar = struct { | |
| 1774 | complex: struct { | |
| 1775 | 1775 | nested: []const u8, |
| 1776 | }; | |
| 1777 | complex: Bar, | |
| 1776 | }, | |
| 1778 | 1777 | |
| 1779 | const Baz = struct { | |
| 1778 | veryComplex: []struct { | |
| 1780 | 1779 | foo: []const u8, |
| 1781 | }; | |
| 1782 | veryComplex: []Baz, | |
| 1780 | }, | |
| 1783 | 1781 | |
| 1782 | a_union: Union, | |
| 1784 | 1783 | const Union = union(enum) { |
| 1785 | 1784 | x: u8, |
| 1786 | 1785 | float: f64, |
| 1787 | 1786 | string: []const u8, |
| 1788 | 1787 | }; |
| 1789 | a_union: Union, | |
| 1790 | 1788 | }; |
| 1791 | 1789 | const r = try parse(T, &TokenStream.init( |
| 1792 | 1790 | \\{ |
| ... | ... | @@ -2323,13 +2321,14 @@ pub const StringifyOptions = struct { |
| 2323 | 2321 | /// How many indentation levels deep are we? |
| 2324 | 2322 | indent_level: usize = 0, |
| 2325 | 2323 | |
| 2326 | pub const Indentation = union(enum) { | |
| 2324 | /// What character(s) should be used for indentation? | |
| 2325 | indent: union(enum) { | |
| 2327 | 2326 | Space: u8, |
| 2328 | 2327 | Tab: void, |
| 2329 | }; | |
| 2328 | } = .{ .Space = 4 }, | |
| 2330 | 2329 | |
| 2331 | /// What character(s) should be used for indentation? | |
| 2332 | indent: Indentation = Indentation{ .Space = 4 }, | |
| 2330 | /// After a colon, should whitespace be inserted? | |
| 2331 | separator: bool = true, | |
| 2333 | 2332 | |
| 2334 | 2333 | fn outputIndent( |
| 2335 | 2334 | whitespace: @This(), |
| ... | ... | @@ -2350,17 +2349,17 @@ pub const StringifyOptions = struct { |
| 2350 | 2349 | n_chars *= whitespace.indent_level; |
| 2351 | 2350 | try out_stream.writeByteNTimes(char, n_chars); |
| 2352 | 2351 | } |
| 2353 | ||
| 2354 | /// After a colon, should whitespace be inserted? | |
| 2355 | separator: bool = true, | |
| 2356 | 2352 | }; |
| 2357 | 2353 | |
| 2358 | 2354 | /// Controls the whitespace emitted |
| 2359 | 2355 | whitespace: ?Whitespace = null, |
| 2360 | 2356 | |
| 2357 | string: StringOptions = StringOptions{ .String = .{} }, | |
| 2358 | ||
| 2361 | 2359 | /// Should []u8 be serialised as a string? or an array? |
| 2362 | 2360 | pub const StringOptions = union(enum) { |
| 2363 | 2361 | Array, |
| 2362 | String: StringOutputOptions, | |
| 2364 | 2363 | |
| 2365 | 2364 | /// String output options |
| 2366 | 2365 | const StringOutputOptions = struct { |
| ... | ... | @@ -2370,10 +2369,7 @@ pub const StringifyOptions = struct { |
| 2370 | 2369 | /// Should unicode characters be escaped in strings? |
| 2371 | 2370 | escape_unicode: bool = false, |
| 2372 | 2371 | }; |
| 2373 | String: StringOutputOptions, | |
| 2374 | 2372 | }; |
| 2375 | ||
| 2376 | string: StringOptions = StringOptions{ .String = .{} }, | |
| 2377 | 2373 | }; |
| 2378 | 2374 | |
| 2379 | 2375 | fn outputUnicodeEscape( |
lib/std/mem.zig+4-7| ... | ... | @@ -374,7 +374,7 @@ test "mem.zeroes" { |
| 374 | 374 | testing.expect(a.y == 10); |
| 375 | 375 | |
| 376 | 376 | const ZigStruct = struct { |
| 377 | const IntegralTypes = struct { | |
| 377 | integral_types: struct { | |
| 378 | 378 | integer_0: i0, |
| 379 | 379 | integer_8: i8, |
| 380 | 380 | integer_16: i16, |
| ... | ... | @@ -390,16 +390,13 @@ test "mem.zeroes" { |
| 390 | 390 | |
| 391 | 391 | float_32: f32, |
| 392 | 392 | float_64: f64, |
| 393 | }; | |
| 394 | ||
| 395 | integral_types: IntegralTypes, | |
| 393 | }, | |
| 396 | 394 | |
| 397 | const Pointers = struct { | |
| 395 | pointers: struct { | |
| 398 | 396 | optional: ?*u8, |
| 399 | 397 | c_pointer: [*c]u8, |
| 400 | 398 | slice: []u8, |
| 401 | }; | |
| 402 | pointers: Pointers, | |
| 399 | }, | |
| 403 | 400 | |
| 404 | 401 | array: [2]u32, |
| 405 | 402 | optional_int: ?u8, |
lib/std/os/bits/linux.zig+19-9| ... | ... | @@ -1226,17 +1226,11 @@ pub const io_cqring_offsets = extern struct { |
| 1226 | 1226 | }; |
| 1227 | 1227 | |
| 1228 | 1228 | pub const io_uring_sqe = extern struct { |
| 1229 | opcode: IORING_OP, | |
| 1230 | flags: u8, | |
| 1231 | ioprio: u16, | |
| 1232 | fd: i32, | |
| 1233 | 1229 | pub const union1 = extern union { |
| 1234 | 1230 | off: u64, |
| 1235 | 1231 | addr2: u64, |
| 1236 | 1232 | }; |
| 1237 | union1: union1, | |
| 1238 | addr: u64, | |
| 1239 | len: u32, | |
| 1233 | ||
| 1240 | 1234 | pub const union2 = extern union { |
| 1241 | 1235 | rw_flags: kernel_rwf, |
| 1242 | 1236 | fsync_flags: u32, |
| ... | ... | @@ -1250,8 +1244,7 @@ pub const io_uring_sqe = extern struct { |
| 1250 | 1244 | statx_flags: u32, |
| 1251 | 1245 | fadvise_flags: u32, |
| 1252 | 1246 | }; |
| 1253 | union2: union2, | |
| 1254 | user_data: u64, | |
| 1247 | ||
| 1255 | 1248 | pub const union3 = extern union { |
| 1256 | 1249 | struct1: extern struct { |
| 1257 | 1250 | /// index into fixed buffers, if used |
| ... | ... | @@ -1262,6 +1255,23 @@ pub const io_uring_sqe = extern struct { |
| 1262 | 1255 | }, |
| 1263 | 1256 | __pad2: [3]u64, |
| 1264 | 1257 | }; |
| 1258 | opcode: IORING_OP, | |
| 1259 | flags: u8, | |
| 1260 | ioprio: u16, | |
| 1261 | fd: i32, | |
| 1262 | ||
| 1263 | opcode: u8, | |
| 1264 | flags: u8, | |
| 1265 | ioprio: u16, | |
| 1266 | fd: i32, | |
| 1267 | ||
| 1268 | union1: union1, | |
| 1269 | addr: u64, | |
| 1270 | len: u32, | |
| 1271 | ||
| 1272 | union2: union2, | |
| 1273 | user_data: u64, | |
| 1274 | ||
| 1265 | 1275 | union3: union3, |
| 1266 | 1276 | }; |
| 1267 | 1277 |
lib/std/os/bits/linux/errno-generic.zig+2| ... | ... | @@ -384,8 +384,10 @@ pub const EKEYREVOKED = 128; |
| 384 | 384 | pub const EKEYREJECTED = 129; |
| 385 | 385 | |
| 386 | 386 | // for robust mutexes |
| 387 | ||
| 387 | 388 | /// Owner died |
| 388 | 389 | pub const EOWNERDEAD = 130; |
| 390 | ||
| 389 | 391 | /// State not recoverable |
| 390 | 392 | pub const ENOTRECOVERABLE = 131; |
| 391 | 393 |
lib/std/os/bits/linux/netlink.zig+3-3| ... | ... | @@ -122,6 +122,9 @@ pub const NLM_F_CAPPED = 0x100; |
| 122 | 122 | pub const NLM_F_ACK_TLVS = 0x200; |
| 123 | 123 | |
| 124 | 124 | pub const NetlinkMessageType = extern enum(u16) { |
| 125 | /// < 0x10: reserved control messages | |
| 126 | pub const MIN_TYPE = 0x10; | |
| 127 | ||
| 125 | 128 | /// Nothing. |
| 126 | 129 | NOOP = 0x1, |
| 127 | 130 | |
| ... | ... | @@ -134,9 +137,6 @@ pub const NetlinkMessageType = extern enum(u16) { |
| 134 | 137 | /// Data lost |
| 135 | 138 | OVERRUN = 0x4, |
| 136 | 139 | |
| 137 | /// < 0x10: reserved control messages | |
| 138 | pub const MIN_TYPE = 0x10; | |
| 139 | ||
| 140 | 140 | // rtlink types |
| 141 | 141 | |
| 142 | 142 | RTM_NEWLINK = 16, |
lib/std/os/bits/linux/riscv64.zig+2-1| ... | ... | @@ -5,6 +5,8 @@ const gid_t = std.os.linux.gid_t; |
| 5 | 5 | const pid_t = std.os.linux.pid_t; |
| 6 | 6 | |
| 7 | 7 | pub const SYS = extern enum(usize) { |
| 8 | pub const arch_specific_syscall = 244; | |
| 9 | ||
| 8 | 10 | io_setup = 0, |
| 9 | 11 | io_destroy = 1, |
| 10 | 12 | io_submit = 2, |
| ... | ... | @@ -249,7 +251,6 @@ pub const SYS = extern enum(usize) { |
| 249 | 251 | accept4 = 242, |
| 250 | 252 | recvmmsg = 243, |
| 251 | 253 | |
| 252 | pub const arch_specific_syscall = 244; | |
| 253 | 254 | riscv_flush_icache = arch_specific_syscall + 15, |
| 254 | 255 | |
| 255 | 256 | wait4 = 260, |
lib/std/zig/ast.zig+4| ... | ... | @@ -164,6 +164,7 @@ pub const Error = union(enum) { |
| 164 | 164 | ExpectedLoopExpr: ExpectedLoopExpr, |
| 165 | 165 | ExpectedDerefOrUnwrap: ExpectedDerefOrUnwrap, |
| 166 | 166 | ExpectedSuffixOp: ExpectedSuffixOp, |
| 167 | DeclBetweenFields: DeclBetweenFields, | |
| 167 | 168 | |
| 168 | 169 | pub fn render(self: *const Error, tokens: *Tree.TokenList, stream: var) !void { |
| 169 | 170 | switch (self.*) { |
| ... | ... | @@ -211,6 +212,7 @@ pub const Error = union(enum) { |
| 211 | 212 | .ExpectedLoopExpr => |*x| return x.render(tokens, stream), |
| 212 | 213 | .ExpectedDerefOrUnwrap => |*x| return x.render(tokens, stream), |
| 213 | 214 | .ExpectedSuffixOp => |*x| return x.render(tokens, stream), |
| 215 | .DeclBetweenFields => |*x| return x.render(tokens, stream), | |
| 214 | 216 | } |
| 215 | 217 | } |
| 216 | 218 | |
| ... | ... | @@ -260,6 +262,7 @@ pub const Error = union(enum) { |
| 260 | 262 | .ExpectedLoopExpr => |x| return x.token, |
| 261 | 263 | .ExpectedDerefOrUnwrap => |x| return x.token, |
| 262 | 264 | .ExpectedSuffixOp => |x| return x.token, |
| 265 | .DeclBetweenFields => |x| return x.token, | |
| 263 | 266 | } |
| 264 | 267 | } |
| 265 | 268 | |
| ... | ... | @@ -304,6 +307,7 @@ pub const Error = union(enum) { |
| 304 | 307 | pub const ExtraConstQualifier = SimpleError("Extra const qualifier"); |
| 305 | 308 | pub const ExtraVolatileQualifier = SimpleError("Extra volatile qualifier"); |
| 306 | 309 | pub const ExtraAllowZeroQualifier = SimpleError("Extra allowzero qualifier"); |
| 310 | pub const DeclBetweenFields = SimpleError("Declarations are not allowed between container fields"); | |
| 307 | 311 | |
| 308 | 312 | pub const ExpectedCall = struct { |
| 309 | 313 | node: *Node, |
lib/std/zig/parse.zig+33| ... | ... | @@ -88,6 +88,18 @@ fn parseRoot(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!*Node.Roo |
| 88 | 88 | fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !Node.Root.DeclList { |
| 89 | 89 | var list = Node.Root.DeclList.init(arena); |
| 90 | 90 | |
| 91 | var field_state: union(enum) { | |
| 92 | /// no fields have been seen | |
| 93 | none, | |
| 94 | /// currently parsing fields | |
| 95 | seen, | |
| 96 | /// saw fields and then a declaration after them. | |
| 97 | /// payload is first token of previous declaration. | |
| 98 | end: TokenIndex, | |
| 99 | /// ther was a declaration between fields, don't report more errors | |
| 100 | err, | |
| 101 | } = .none; | |
| 102 | ||
| 91 | 103 | while (true) { |
| 92 | 104 | if (try parseContainerDocComments(arena, it, tree)) |node| { |
| 93 | 105 | try list.push(node); |
| ... | ... | @@ -97,12 +109,18 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No |
| 97 | 109 | const doc_comments = try parseDocComment(arena, it, tree); |
| 98 | 110 | |
| 99 | 111 | if (try parseTestDecl(arena, it, tree)) |node| { |
| 112 | if (field_state == .seen) { | |
| 113 | field_state = .{ .end = node.firstToken() }; | |
| 114 | } | |
| 100 | 115 | node.cast(Node.TestDecl).?.doc_comments = doc_comments; |
| 101 | 116 | try list.push(node); |
| 102 | 117 | continue; |
| 103 | 118 | } |
| 104 | 119 | |
| 105 | 120 | if (try parseTopLevelComptime(arena, it, tree)) |node| { |
| 121 | if (field_state == .seen) { | |
| 122 | field_state = .{ .end = node.firstToken() }; | |
| 123 | } | |
| 106 | 124 | node.cast(Node.Comptime).?.doc_comments = doc_comments; |
| 107 | 125 | try list.push(node); |
| 108 | 126 | continue; |
| ... | ... | @@ -111,6 +129,9 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No |
| 111 | 129 | const visib_token = eatToken(it, .Keyword_pub); |
| 112 | 130 | |
| 113 | 131 | if (try parseTopLevelDecl(arena, it, tree)) |node| { |
| 132 | if (field_state == .seen) { | |
| 133 | field_state = .{ .end = visib_token orelse node.firstToken() }; | |
| 134 | } | |
| 114 | 135 | switch (node.id) { |
| 115 | 136 | .FnProto => { |
| 116 | 137 | node.cast(Node.FnProto).?.doc_comments = doc_comments; |
| ... | ... | @@ -146,6 +167,18 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No |
| 146 | 167 | } |
| 147 | 168 | |
| 148 | 169 | if (try parseContainerField(arena, it, tree)) |node| { |
| 170 | switch (field_state) { | |
| 171 | .none => field_state = .seen, | |
| 172 | .err, .seen => {}, | |
| 173 | .end => |tok| { | |
| 174 | try tree.errors.push(.{ | |
| 175 | .DeclBetweenFields = .{ .token = tok }, | |
| 176 | }); | |
| 177 | // continue parsing, error will be reported later | |
| 178 | field_state = .err; | |
| 179 | }, | |
| 180 | } | |
| 181 | ||
| 149 | 182 | const field = node.cast(Node.ContainerField).?; |
| 150 | 183 | field.doc_comments = doc_comments; |
| 151 | 184 | try list.push(node); |
lib/std/zig/parser_test.zig+17-2| ... | ... | @@ -1,3 +1,18 @@ |
| 1 | test "zig fmt: decl between fields" { | |
| 2 | try testError( | |
| 3 | \\const S = struct { | |
| 4 | \\ const foo = 2; | |
| 5 | \\ const bar = 2; | |
| 6 | \\ const baz = 2; | |
| 7 | \\ a: usize, | |
| 8 | \\ const foo1 = 2; | |
| 9 | \\ const bar1 = 2; | |
| 10 | \\ const baz1 = 2; | |
| 11 | \\ b: usize, | |
| 12 | \\}; | |
| 13 | ); | |
| 14 | } | |
| 15 | ||
| 1 | 16 | test "zig fmt: errdefer with payload" { |
| 2 | 17 | try testCanonical( |
| 3 | 18 | \\pub fn main() anyerror!void { |
| ... | ... | @@ -2001,11 +2016,11 @@ test "zig fmt: struct declaration" { |
| 2001 | 2016 | \\ f1: u8, |
| 2002 | 2017 | \\ f3: u8, |
| 2003 | 2018 | \\ |
| 2019 | \\ f2: u8, | |
| 2020 | \\ | |
| 2004 | 2021 | \\ fn method(self: *Self) Self { |
| 2005 | 2022 | \\ return self.*; |
| 2006 | 2023 | \\ } |
| 2007 | \\ | |
| 2008 | \\ f2: u8, | |
| 2009 | 2024 | \\}; |
| 2010 | 2025 | \\ |
| 2011 | 2026 | \\const Ps = packed struct { |
test/compile_errors.zig+5-2| ... | ... | @@ -4,17 +4,20 @@ const std = @import("std"); |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | 5 | cases.add("declaration between fields", |
| 6 | 6 | \\const S = struct { |
| 7 | \\ a: usize, | |
| 8 | 7 | \\ const foo = 2; |
| 9 | 8 | \\ const bar = 2; |
| 10 | 9 | \\ const baz = 2; |
| 10 | \\ a: usize, | |
| 11 | \\ const foo1 = 2; | |
| 12 | \\ const bar1 = 2; | |
| 13 | \\ const baz1 = 2; | |
| 11 | 14 | \\ b: usize, |
| 12 | 15 | \\}; |
| 13 | 16 | \\comptime { |
| 14 | 17 | \\ _ = S; |
| 15 | 18 | \\} |
| 16 | 19 | , &[_][]const u8{ |
| 17 | "tmp.zig:3:5: error: declarations are not allowed between container fields", | |
| 20 | "tmp.zig:6:5: error: declarations are not allowed between container fields", | |
| 18 | 21 | }); |
| 19 | 22 | |
| 20 | 23 | cases.add("non-extern function with var args", |