authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-10-21 22:22:08+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-21 23:04:19-04:00
log2550cb4638e12e94073cbca5c0ee3aa263c25dbe
tree7b53d3b4e92e570155292623a98af3c840b17de6
parent859cbef8a41dfbfde9c8caab00272b77912d3f0b

remove pub syntax for container fields


12 files changed, 54 insertions(+), 66 deletions(-)

doc/langref.html.in+2-2
......@@ -10086,8 +10086,8 @@ ContainerMembers
1008610086 &lt;- TestDecl ContainerMembers
1008710087 / TopLevelComptime ContainerMembers
1008810088 / KEYWORD_pub? TopLevelDecl ContainerMembers
10089 / KEYWORD_pub? ContainerField COMMA ContainerMembers
10090 / KEYWORD_pub? ContainerField
10089 / ContainerField COMMA ContainerMembers
10090 / ContainerField
1009110091 /
1009210092
1009310093TestDecl &lt;- KEYWORD_test STRINGLITERAL Block
lib/std/child_process.zig+16-16
......@@ -17,35 +17,35 @@ const TailQueue = std.TailQueue;
1717const maxInt = std.math.maxInt;
1818
1919pub const ChildProcess = struct {
20 pub pid: if (os.windows.is_the_target) void else i32,
21 pub handle: if (os.windows.is_the_target) windows.HANDLE else void,
22 pub thread_handle: if (os.windows.is_the_target) windows.HANDLE else void,
20 pid: if (os.windows.is_the_target) void else i32,
21 handle: if (os.windows.is_the_target) windows.HANDLE else void,
22 thread_handle: if (os.windows.is_the_target) windows.HANDLE else void,
2323
24 pub allocator: *mem.Allocator,
24 allocator: *mem.Allocator,
2525
26 pub stdin: ?File,
27 pub stdout: ?File,
28 pub stderr: ?File,
26 stdin: ?File,
27 stdout: ?File,
28 stderr: ?File,
2929
30 pub term: ?(SpawnError!Term),
30 term: ?(SpawnError!Term),
3131
32 pub argv: []const []const u8,
32 argv: []const []const u8,
3333
3434 /// Leave as null to use the current env map using the supplied allocator.
35 pub env_map: ?*const BufMap,
35 env_map: ?*const BufMap,
3636
37 pub stdin_behavior: StdIo,
38 pub stdout_behavior: StdIo,
39 pub stderr_behavior: StdIo,
37 stdin_behavior: StdIo,
38 stdout_behavior: StdIo,
39 stderr_behavior: StdIo,
4040
4141 /// Set to change the user id when spawning the child process.
42 pub uid: if (os.windows.is_the_target) void else ?u32,
42 uid: if (os.windows.is_the_target) void else ?u32,
4343
4444 /// Set to change the group id when spawning the child process.
45 pub gid: if (os.windows.is_the_target) void else ?u32,
45 gid: if (os.windows.is_the_target) void else ?u32,
4646
4747 /// Set to change the current working directory when spawning the child process.
48 pub cwd: ?[]const u8,
48 cwd: ?[]const u8,
4949
5050 err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t,
5151 llnode: if (os.windows.is_the_target) void else TailQueue(*ChildProcess).Node,
lib/std/heap.zig+1-1
......@@ -338,7 +338,7 @@ pub const HeapAllocator = switch (builtin.os) {
338338/// This allocator takes an existing allocator, wraps it, and provides an interface
339339/// where you can allocate without freeing, and then free it all together.
340340pub const ArenaAllocator = struct {
341 pub allocator: Allocator,
341 allocator: Allocator,
342342
343343 child_allocator: *Allocator,
344344 buffer_list: std.SinglyLinkedList([]u8),
lib/std/http/headers.zig+3-3
......@@ -28,9 +28,9 @@ fn never_index_default(name: []const u8) bool {
2828
2929const HeaderEntry = struct {
3030 allocator: *Allocator,
31 pub name: []const u8,
32 pub value: []u8,
33 pub never_index: bool,
31 name: []const u8,
32 value: []u8,
33 never_index: bool,
3434
3535 const Self = @This();
3636
lib/std/io.zig+10-10
......@@ -161,7 +161,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
161161 const Self = @This();
162162 const Stream = InStream(Error);
163163
164 pub stream: Stream,
164 stream: Stream,
165165
166166 unbuffered_in_stream: *Stream,
167167
......@@ -273,7 +273,7 @@ pub fn PeekStream(comptime buffer_size: usize, comptime InStreamError: type) typ
273273 pub const Error = InStreamError;
274274 pub const Stream = InStream(Error);
275275
276 pub stream: Stream,
276 stream: Stream,
277277 base: *Stream,
278278
279279 // Right now the look-ahead space is statically allocated, but a version with dynamic allocation
......@@ -336,7 +336,7 @@ pub const SliceInStream = struct {
336336 pub const Error = error{};
337337 pub const Stream = InStream(Error);
338338
339 pub stream: Stream,
339 stream: Stream,
340340
341341 pos: usize,
342342 slice: []const u8,
......@@ -514,9 +514,9 @@ pub const SliceOutStream = struct {
514514 pub const Error = error{OutOfSpace};
515515 pub const Stream = OutStream(Error);
516516
517 pub stream: Stream,
517 stream: Stream,
518518
519 pub pos: usize,
519 pos: usize,
520520 slice: []u8,
521521
522522 pub fn init(slice: []u8) SliceOutStream {
......@@ -571,7 +571,7 @@ pub const NullOutStream = struct {
571571 pub const Error = error{};
572572 pub const Stream = OutStream(Error);
573573
574 pub stream: Stream,
574 stream: Stream,
575575
576576 pub fn init() NullOutStream {
577577 return NullOutStream{
......@@ -595,8 +595,8 @@ pub fn CountingOutStream(comptime OutStreamError: type) type {
595595 pub const Stream = OutStream(Error);
596596 pub const Error = OutStreamError;
597597
598 pub stream: Stream,
599 pub bytes_written: u64,
598 stream: Stream,
599 bytes_written: u64,
600600 child_stream: *Stream,
601601
602602 pub fn init(child_stream: *Stream) Self {
......@@ -635,7 +635,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
635635 pub const Stream = OutStream(Error);
636636 pub const Error = OutStreamError;
637637
638 pub stream: Stream,
638 stream: Stream,
639639
640640 unbuffered_out_stream: *Stream,
641641
......@@ -1084,7 +1084,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
10841084 // safety. If it is bad, it will be caught anyway.
10851085 const TagInt = @TagType(TagType);
10861086 const tag = try self.deserializeInt(TagInt);
1087
1087
10881088 inline for (info.fields) |field_info| {
10891089 if (field_info.enum_field.?.value == tag) {
10901090 const name = field_info.name;
lib/std/io/seekable_stream.zig+2-2
......@@ -39,8 +39,8 @@ pub const SliceSeekableInStream = struct {
3939 pub const Stream = InStream(Error);
4040 pub const SeekableInStream = SeekableStream(SeekError, GetSeekPosError);
4141
42 pub stream: Stream,
43 pub seekable_stream: SeekableInStream,
42 stream: Stream,
43 seekable_stream: SeekableInStream,
4444
4545 pos: usize,
4646 slice: []const u8,
lib/std/zig/ast.zig+1-3
......@@ -290,7 +290,7 @@ pub const Error = union(enum) {
290290 pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'");
291291
292292 pub const ExpectedParamType = SimpleError("Expected parameter type");
293 pub const ExpectedPubItem = SimpleError("Pub must be followed by fn decl, var decl, or container member");
293 pub const ExpectedPubItem = SimpleError("Expected function or variable declaration after pub");
294294 pub const UnattachedDocComment = SimpleError("Unattached documentation comment");
295295 pub const ExtraAlignQualifier = SimpleError("Extra align qualifier");
296296 pub const ExtraConstQualifier = SimpleError("Extra const qualifier");
......@@ -757,7 +757,6 @@ pub const Node = struct {
757757 pub const ContainerField = struct {
758758 base: Node,
759759 doc_comments: ?*DocComment,
760 visib_token: ?TokenIndex,
761760 name_token: TokenIndex,
762761 type_expr: ?*Node,
763762 value_expr: ?*Node,
......@@ -780,7 +779,6 @@ pub const Node = struct {
780779 }
781780
782781 pub fn firstToken(self: *const ContainerField) TokenIndex {
783 if (self.visib_token) |visib_token| return visib_token;
784782 return self.name_token;
785783 }
786784
lib/std/zig/parse.zig+7-9
......@@ -138,9 +138,15 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
138138 continue;
139139 }
140140
141 if (visib_token != null) {
142 try tree.errors.push(AstError{
143 .ExpectedPubItem = AstError.ExpectedPubItem{ .token = it.index },
144 });
145 return error.ParseError;
146 }
147
141148 if (try parseContainerField(arena, it, tree)) |node| {
142149 const field = node.cast(Node.ContainerField).?;
143 field.visib_token = visib_token;
144150 field.doc_comments = doc_comments;
145151 try list.push(node);
146152 const comma = eatToken(it, .Comma) orelse break;
......@@ -149,13 +155,6 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
149155 continue;
150156 }
151157
152 // Dangling pub
153 if (visib_token != null) {
154 try tree.errors.push(AstError{
155 .ExpectedPubItem = AstError.ExpectedPubItem{ .token = it.index },
156 });
157 }
158
159158 break;
160159 }
161160
......@@ -407,7 +406,6 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
407406 node.* = Node.ContainerField{
408407 .base = Node{ .id = .ContainerField },
409408 .doc_comments = null,
410 .visib_token = null,
411409 .name_token = name_token,
412410 .type_expr = type_expr,
413411 .value_expr = value_expr,
lib/std/zig/parser_test.zig+3-3
......@@ -1766,7 +1766,7 @@ test "zig fmt: struct declaration" {
17661766 \\const S = struct {
17671767 \\ const Self = @This();
17681768 \\ f1: u8,
1769 \\ pub f3: u8,
1769 \\ f3: u8,
17701770 \\
17711771 \\ fn method(self: *Self) Self {
17721772 \\ return self.*;
......@@ -1777,14 +1777,14 @@ test "zig fmt: struct declaration" {
17771777 \\
17781778 \\const Ps = packed struct {
17791779 \\ a: u8,
1780 \\ pub b: u8,
1780 \\ b: u8,
17811781 \\
17821782 \\ c: u8,
17831783 \\};
17841784 \\
17851785 \\const Es = extern struct {
17861786 \\ a: u8,
1787 \\ pub b: u8,
1787 \\ b: u8,
17881788 \\
17891789 \\ c: u8,
17901790 \\};
lib/std/zig/render.zig+2-6
......@@ -254,10 +254,6 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
254254
255255 try renderDocComments(tree, stream, field, indent, start_col);
256256
257 if (field.visib_token) |visib_token| {
258 try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
259 }
260
261257 if (field.type_expr == null and field.value_expr == null) {
262258 return renderToken(tree, stream, field.name_token, indent, start_col, Space.Comma); // name,
263259 } else if (field.type_expr != null and field.value_expr == null) {
......@@ -2206,8 +2202,8 @@ const FindByteOutStream = struct {
22062202 pub const Error = error{};
22072203 pub const Stream = std.io.OutStream(Error);
22082204
2209 pub stream: Stream,
2210 pub byte_found: bool,
2205 stream: Stream,
2206 byte_found: bool,
22112207 byte: u8,
22122208
22132209 pub fn init(byte: u8) Self {
src/all_types.hpp-2
......@@ -990,8 +990,6 @@ struct AstNodeStructField {
990990 // populated if the "align(A)" is present
991991 AstNode *align_expr;
992992 Buf doc_comments;
993
994 VisibMod visib_mod;
995993};
996994
997995struct AstNodeStringLiteral {
src/parser.cpp+7-9
......@@ -518,8 +518,8 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
518518// <- TestDecl ContainerMembers
519519// / TopLevelComptime ContainerMembers
520520// / KEYWORD_pub? TopLevelDecl ContainerMembers
521// / KEYWORD_pub? ContainerField COMMA ContainerMembers
522// / KEYWORD_pub? ContainerField
521// / ContainerField COMMA ContainerMembers
522// / ContainerField
523523// /
524524static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
525525 AstNodeContainerDecl res = {};
......@@ -548,10 +548,13 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
548548 continue;
549549 }
550550
551 if (visib_token != nullptr) {
552 ast_error(pc, peek_token(pc), "expected function or variable declaration after pub");
553 }
554
551555 AstNode *container_field = ast_parse_container_field(pc);
552556 if (container_field != nullptr) {
553557 assert(container_field->type == NodeTypeStructField);
554 container_field->data.struct_field.visib_mod = visib_mod;
555558 container_field->data.struct_field.doc_comments = doc_comment_buf;
556559 res.fields.append(container_field);
557560 if (eat_token_if(pc, TokenIdComma) != nullptr) {
......@@ -561,12 +564,7 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
561564 }
562565 }
563566
564 // We visib_token wasn't eaten, then we haven't consumed the first token in this rule yet.
565 // It is therefore safe to return and let the caller continue parsing.
566 if (visib_token == nullptr)
567 break;
568
569 ast_invalid_token_error(pc, peek_token(pc));
567 break;
570568 }
571569
572570 return res;