| author | |
| committer | |
| log | 3e095d8ef32fc93f5050cead708849846d626d1d |
| tree | 64b9b837d024c459bb87e96e050d9e6657c458f6 |
| parent | 1a989ba39dbf2b718df7cc9792b6abaac7f5986d |
| signature | Commit is signed but in an unrecognized format. |
5 files changed, 22 insertions(+), 23 deletions(-)
lib/std/zig/ast.zig+4-4| ... | ... | @@ -993,7 +993,7 @@ pub const Node = struct { |
| 993 | 993 | param_type: ParamType, |
| 994 | 994 | |
| 995 | 995 | pub const ParamType = union(enum) { |
| 996 | var_type: *Node, | |
| 996 | any_type: *Node, | |
| 997 | 997 | var_args: TokenIndex, |
| 998 | 998 | type_expr: *Node, |
| 999 | 999 | }; |
| ... | ... | @@ -1004,7 +1004,7 @@ pub const Node = struct { |
| 1004 | 1004 | if (i < 1) { |
| 1005 | 1005 | switch (self.param_type) { |
| 1006 | 1006 | .var_args => return null, |
| 1007 | .var_type, .type_expr => |node| return node, | |
| 1007 | .any_type, .type_expr => |node| return node, | |
| 1008 | 1008 | } |
| 1009 | 1009 | } |
| 1010 | 1010 | i -= 1; |
| ... | ... | @@ -1018,14 +1018,14 @@ pub const Node = struct { |
| 1018 | 1018 | if (self.name_token) |name_token| return name_token; |
| 1019 | 1019 | switch (self.param_type) { |
| 1020 | 1020 | .var_args => |tok| return tok, |
| 1021 | .var_type, .type_expr => |node| return node.firstToken(), | |
| 1021 | .any_type, .type_expr => |node| return node.firstToken(), | |
| 1022 | 1022 | } |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | 1025 | pub fn lastToken(self: *const ParamDecl) TokenIndex { |
| 1026 | 1026 | switch (self.param_type) { |
| 1027 | 1027 | .var_args => |tok| return tok, |
| 1028 | .var_type, .type_expr => |node| return node.lastToken(), | |
| 1028 | .any_type, .type_expr => |node| return node.lastToken(), | |
| 1029 | 1029 | } |
| 1030 | 1030 | } |
| 1031 | 1031 | }; |
lib/std/zig/parse.zig+3-3| ... | ... | @@ -519,7 +519,7 @@ const Parser = struct { |
| 519 | 519 | const callconv_expr = try p.parseCallconv(); |
| 520 | 520 | const exclamation_token = p.eatToken(.Bang); |
| 521 | 521 | |
| 522 | const return_type_expr = (try p.parseVarType()) orelse | |
| 522 | const return_type_expr = (try p.parseAnyType()) orelse | |
| 523 | 523 | try p.expectNodeRecoverable(parseTypeExpr, .{ |
| 524 | 524 | // most likely the user forgot to specify the return type. |
| 525 | 525 | // Mark return type as invalid and try to continue. |
| ... | ... | @@ -2028,7 +2028,7 @@ const Parser = struct { |
| 2028 | 2028 | fn parseParamType(p: *Parser) !?Node.FnProto.ParamDecl.ParamType { |
| 2029 | 2029 | // TODO cast from tuple to error union is broken |
| 2030 | 2030 | const P = Node.FnProto.ParamDecl.ParamType; |
| 2031 | if (try p.parseVarType()) |node| return P{ .var_type = node }; | |
| 2031 | if (try p.parseAnyType()) |node| return P{ .any_type = node }; | |
| 2032 | 2032 | if (p.eatToken(.Ellipsis3)) |token| return P{ .var_args = token }; |
| 2033 | 2033 | if (try p.parseTypeExpr()) |node| return P{ .type_expr = node }; |
| 2034 | 2034 | return null; |
| ... | ... | @@ -3057,7 +3057,7 @@ const Parser = struct { |
| 3057 | 3057 | return &node.base; |
| 3058 | 3058 | } |
| 3059 | 3059 | |
| 3060 | fn parseVarType(p: *Parser) !?*Node { | |
| 3060 | fn parseAnyType(p: *Parser) !?*Node { | |
| 3061 | 3061 | const token = p.eatToken(.Keyword_anytype) orelse |
| 3062 | 3062 | p.eatToken(.Keyword_var) orelse return null; // TODO remove in next release cycle |
| 3063 | 3063 | const node = try p.arena.allocator.create(Node.AnyType); |
lib/std/zig/render.zig+1-1| ... | ... | @@ -2198,7 +2198,7 @@ fn renderParamDecl( |
| 2198 | 2198 | } |
| 2199 | 2199 | switch (param_decl.param_type) { |
| 2200 | 2200 | .var_args => |token| try renderToken(tree, stream, token, indent, start_col, space), |
| 2201 | .var_type, .type_expr => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, space), | |
| 2201 | .any_type, .type_expr => |node| try renderExpression(allocator, stream, tree, indent, start_col, node, space), | |
| 2202 | 2202 | } |
| 2203 | 2203 | } |
| 2204 | 2204 |
src-self-hosted/translate_c.zig+4-5| ... | ... | @@ -5215,10 +5215,9 @@ fn transMacroFnDefine(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5215 | 5215 | const param_name_tok = try appendIdentifier(c, mangled_name); |
| 5216 | 5216 | _ = try appendToken(c, .Colon, ":"); |
| 5217 | 5217 | |
| 5218 | const token_index = try appendToken(c, .Keyword_var, "var"); | |
| 5219 | const identifier = try c.arena.create(ast.Node.Identifier); | |
| 5220 | identifier.* = .{ | |
| 5221 | .token = token_index, | |
| 5218 | const any_type = try c.arena.create(ast.Node.AnyType); | |
| 5219 | any_type.* = .{ | |
| 5220 | .token = try appendToken(c, .Keyword_anytype, "anytype"), | |
| 5222 | 5221 | }; |
| 5223 | 5222 | |
| 5224 | 5223 | (try fn_params.addOne()).* = .{ |
| ... | ... | @@ -5226,7 +5225,7 @@ fn transMacroFnDefine(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5226 | 5225 | .comptime_token = null, |
| 5227 | 5226 | .noalias_token = null, |
| 5228 | 5227 | .name_token = param_name_tok, |
| 5229 | .param_type = .{ .type_expr = &identifier.base }, | |
| 5228 | .param_type = .{ .any_type = &any_type.base }, | |
| 5230 | 5229 | }; |
| 5231 | 5230 | |
| 5232 | 5231 | if (it.peek().?.id != .Comma) |
test/translate_c.zig+10-10| ... | ... | @@ -21,7 +21,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 21 | 21 | cases.add("correct semicolon after infixop", |
| 22 | 22 | \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) |
| 23 | 23 | , &[_][]const u8{ |
| 24 | \\pub inline fn __ferror_unlocked_body(_fp: var) @TypeOf(((_fp.*._flags) & _IO_ERR_SEEN) != 0) { | |
| 24 | \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf(((_fp.*._flags) & _IO_ERR_SEEN) != 0) { | |
| 25 | 25 | \\ return ((_fp.*._flags) & _IO_ERR_SEEN) != 0; |
| 26 | 26 | \\} |
| 27 | 27 | }); |
| ... | ... | @@ -30,7 +30,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 30 | 30 | \\#define FOO(x) ((x >= 0) + (x >= 0)) |
| 31 | 31 | \\#define BAR 1 && 2 > 4 |
| 32 | 32 | , &[_][]const u8{ |
| 33 | \\pub inline fn FOO(x: var) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) { | |
| 33 | \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) { | |
| 34 | 34 | \\ return @boolToInt(x >= 0) + @boolToInt(x >= 0); |
| 35 | 35 | \\} |
| 36 | 36 | , |
| ... | ... | @@ -81,7 +81,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 81 | 81 | \\ break :blk bar; |
| 82 | 82 | \\}; |
| 83 | 83 | , |
| 84 | \\pub inline fn bar(x: var) @TypeOf(baz(1, 2)) { | |
| 84 | \\pub inline fn bar(x: anytype) @TypeOf(baz(1, 2)) { | |
| 85 | 85 | \\ return blk: { |
| 86 | 86 | \\ _ = &x; |
| 87 | 87 | \\ _ = 3; |
| ... | ... | @@ -1483,11 +1483,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1483 | 1483 | , &[_][]const u8{ |
| 1484 | 1484 | \\pub extern var c: c_int; |
| 1485 | 1485 | , |
| 1486 | \\pub inline fn BASIC(c_1: var) @TypeOf(c_1 * 2) { | |
| 1486 | \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * 2) { | |
| 1487 | 1487 | \\ return c_1 * 2; |
| 1488 | 1488 | \\} |
| 1489 | 1489 | , |
| 1490 | \\pub inline fn FOO(L: var, b: var) @TypeOf(L + b) { | |
| 1490 | \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { | |
| 1491 | 1491 | \\ return L + b; |
| 1492 | 1492 | \\} |
| 1493 | 1493 | }); |
| ... | ... | @@ -2123,7 +2123,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2123 | 2123 | cases.add("macro call", |
| 2124 | 2124 | \\#define CALL(arg) bar(arg) |
| 2125 | 2125 | , &[_][]const u8{ |
| 2126 | \\pub inline fn CALL(arg: var) @TypeOf(bar(arg)) { | |
| 2126 | \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) { | |
| 2127 | 2127 | \\ return bar(arg); |
| 2128 | 2128 | \\} |
| 2129 | 2129 | }); |
| ... | ... | @@ -2683,7 +2683,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2683 | 2683 | \\#define FOO(bar) baz((void *)(baz)) |
| 2684 | 2684 | \\#define BAR (void*) a |
| 2685 | 2685 | , &[_][]const u8{ |
| 2686 | \\pub inline fn FOO(bar: var) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) { | |
| 2686 | \\pub inline fn FOO(bar: anytype) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) { | |
| 2687 | 2687 | \\ return baz((@import("std").meta.cast(?*c_void, baz))); |
| 2688 | 2688 | \\} |
| 2689 | 2689 | , |
| ... | ... | @@ -2713,11 +2713,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2713 | 2713 | \\#define MIN(a, b) ((b) < (a) ? (b) : (a)) |
| 2714 | 2714 | \\#define MAX(a, b) ((b) > (a) ? (b) : (a)) |
| 2715 | 2715 | , &[_][]const u8{ |
| 2716 | \\pub inline fn MIN(a: var, b: var) @TypeOf(if (b < a) b else a) { | |
| 2716 | \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) { | |
| 2717 | 2717 | \\ return if (b < a) b else a; |
| 2718 | 2718 | \\} |
| 2719 | 2719 | , |
| 2720 | \\pub inline fn MAX(a: var, b: var) @TypeOf(if (b > a) b else a) { | |
| 2720 | \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) { | |
| 2721 | 2721 | \\ return if (b > a) b else a; |
| 2722 | 2722 | \\} |
| 2723 | 2723 | }); |
| ... | ... | @@ -2905,7 +2905,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2905 | 2905 | \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen) |
| 2906 | 2906 | \\ |
| 2907 | 2907 | , &[_][]const u8{ |
| 2908 | \\pub inline fn DefaultScreen(dpy: var) @TypeOf((@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen) { | |
| 2908 | \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf((@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen) { | |
| 2909 | 2909 | \\ return (@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen; |
| 2910 | 2910 | \\} |
| 2911 | 2911 | }); |