diff options
| author | Tadeo Kondrak <me@tadeo.ca> | 2020-05-05 05:08:46 -0600 |
|---|---|---|
| committer | Tadeo Kondrak <me@tadeo.ca> | 2020-05-05 05:17:33 -0600 |
| commit | 8d5636ebe4b1d70db14e28c67f7986fb2a1ce3cf (patch) | |
| tree | ec2bb66b5e5b180bf55e891b09220e7eeac85ea3 /lib | |
| parent | 9b788b765c1557a414710872fa9c11fce1f8c504 (diff) | |
| download | zig-8d5636ebe4b1d70db14e28c67f7986fb2a1ce3cf.tar.gz zig-8d5636ebe4b1d70db14e28c67f7986fb2a1ce3cf.zip | |
Rename noasync to nosuspend in self-hosted, add rewriter
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/zig/ast.zig | 22 | ||||
| -rw-r--r-- | lib/std/zig/parse.zig | 24 | ||||
| -rw-r--r-- | lib/std/zig/parser_test.zig | 26 | ||||
| -rw-r--r-- | lib/std/zig/render.zig | 14 | ||||
| -rw-r--r-- | lib/std/zig/tokenizer.zig | 7 |
5 files changed, 56 insertions, 37 deletions
diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 91b9a704c9..50051040d9 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -438,7 +438,7 @@ pub const Node = struct { ContainerDecl, Asm, Comptime, - Noasync, + Nosuspend, Block, // Misc @@ -569,9 +569,9 @@ pub const Node = struct { return true; }, - .Noasync => { - const noasync_node = @fieldParentPtr(Noasync, "base", n); - return noasync_node.expr.id != .Block; + .Nosuspend => { + const nosuspend_node = @fieldParentPtr(Nosuspend, "base", n); + return nosuspend_node.expr.id != .Block; }, else => return true, } @@ -1084,12 +1084,12 @@ pub const Node = struct { } }; - pub const Noasync = struct { - base: Node = Node{ .id = .Noasync }, - noasync_token: TokenIndex, + pub const Nosuspend = struct { + base: Node = Node{ .id = .Nosuspend }, + nosuspend_token: TokenIndex, expr: *Node, - pub fn iterate(self: *Noasync, index: usize) ?*Node { + pub fn iterate(self: *Nosuspend, index: usize) ?*Node { var i = index; if (i < 1) return self.expr; @@ -1098,11 +1098,11 @@ pub const Node = struct { return null; } - pub fn firstToken(self: *const Noasync) TokenIndex { - return self.noasync_token; + pub fn firstToken(self: *const Nosuspend) TokenIndex { + return self.nosuspend_token; } - pub fn lastToken(self: *const Noasync) TokenIndex { + pub fn lastToken(self: *const Nosuspend) TokenIndex { return self.expr.lastToken(); } }; diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index fdaf0ec8f1..d7f4d76cf6 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -495,7 +495,7 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No /// Statement /// <- KEYWORD_comptime? VarDecl /// / KEYWORD_comptime BlockExprStatement -/// / KEYWORD_noasync BlockExprStatement +/// / KEYWORD_nosuspend BlockExprStatement /// / KEYWORD_suspend (SEMICOLON / BlockExprStatement) /// / KEYWORD_defer BlockExprStatement /// / KEYWORD_errdefer Payload? BlockExprStatement @@ -527,14 +527,14 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No return &node.base; } - if (eatToken(it, .Keyword_noasync)) |noasync_token| { + if (eatToken(it, .Keyword_nosuspend)) |nosuspend_token| { const block_expr = try expectNode(arena, it, tree, parseBlockExprStatement, .{ .ExpectedBlockOrAssignment = .{ .token = it.index }, }); - const node = try arena.create(Node.Noasync); + const node = try arena.create(Node.Nosuspend); node.* = .{ - .noasync_token = noasync_token, + .nosuspend_token = nosuspend_token, .expr = block_expr, }; return &node.base; @@ -908,7 +908,7 @@ fn parsePrefixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { /// / IfExpr /// / KEYWORD_break BreakLabel? Expr? /// / KEYWORD_comptime Expr -/// / KEYWORD_noasync Expr +/// / KEYWORD_nosuspend Expr /// / KEYWORD_continue BreakLabel? /// / KEYWORD_resume Expr /// / KEYWORD_return Expr? @@ -944,13 +944,13 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node return &node.base; } - if (eatToken(it, .Keyword_noasync)) |token| { + if (eatToken(it, .Keyword_nosuspend)) |token| { const expr_node = try expectNode(arena, it, tree, parseExpr, .{ .ExpectedExpr = .{ .token = it.index }, }); - const node = try arena.create(Node.Noasync); + const node = try arena.create(Node.Nosuspend); node.* = .{ - .noasync_token = token, + .nosuspend_token = token, .expr = expr_node, }; return &node.base; @@ -1288,7 +1288,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node { /// / IfTypeExpr /// / INTEGER /// / KEYWORD_comptime TypeExpr -/// / KEYWORD_noasync TypeExpr +/// / KEYWORD_nosuspend TypeExpr /// / KEYWORD_error DOT IDENTIFIER /// / KEYWORD_false /// / KEYWORD_null @@ -1327,11 +1327,11 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N }; return &node.base; } - if (eatToken(it, .Keyword_noasync)) |token| { + if (eatToken(it, .Keyword_nosuspend)) |token| { const expr = (try parseTypeExpr(arena, it, tree)) orelse return null; - const node = try arena.create(Node.Noasync); + const node = try arena.create(Node.Nosuspend); node.* = .{ - .noasync_token = token, + .nosuspend_token = token, .expr = expr, }; return &node.base; diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 7fca72ac70..ebc6b92b78 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -35,10 +35,10 @@ test "zig fmt: errdefer with payload" { ); } -test "zig fmt: noasync block" { +test "zig fmt: nosuspend block" { try testCanonical( \\pub fn main() anyerror!void { - \\ noasync { + \\ nosuspend { \\ var foo: Foo = .{ .bar = 42 }; \\ } \\} @@ -46,10 +46,10 @@ test "zig fmt: noasync block" { ); } -test "zig fmt: noasync await" { +test "zig fmt: nosuspend await" { try testCanonical( \\fn foo() void { - \\ x = noasync await y; + \\ x = nosuspend await y; \\} \\ ); @@ -2519,9 +2519,9 @@ test "zig fmt: async functions" { ); } -test "zig fmt: noasync" { +test "zig fmt: nosuspend" { try testCanonical( - \\const a = noasync foo(); + \\const a = nosuspend foo(); \\ ); } @@ -2926,6 +2926,20 @@ test "zig fmt: hexadeciaml float literals with underscore separators" { ); } +test "zig fmt: noasync to nosuspend" { + // TODO: remove this + try testTransform( + \\pub fn main() void { + \\ noasync call(); + \\} + , + \\pub fn main() void { + \\ nosuspend call(); + \\} + \\ + ); +} + const std = @import("std"); const mem = std.mem; const warn = std.debug.warn; diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 1e1552dae4..441a91a28a 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -391,11 +391,15 @@ fn renderExpression( try renderToken(tree, stream, comptime_node.comptime_token, indent, start_col, Space.Space); return renderExpression(allocator, stream, tree, indent, start_col, comptime_node.expr, space); }, - .Noasync => { - const noasync_node = @fieldParentPtr(ast.Node.Noasync, "base", base); - - try renderToken(tree, stream, noasync_node.noasync_token, indent, start_col, Space.Space); - return renderExpression(allocator, stream, tree, indent, start_col, noasync_node.expr, space); + .Nosuspend => { + const nosuspend_node = @fieldParentPtr(ast.Node.Nosuspend, "base", base); + if (mem.eql(u8, tree.tokenSlice(nosuspend_node.nosuspend_token), "noasync")) { + // TODO: remove this + try stream.writeAll("nosuspend "); + } else { + try renderToken(tree, stream, nosuspend_node.nosuspend_token, indent, start_col, Space.Space); + } + return renderExpression(allocator, stream, tree, indent, start_col, nosuspend_node.expr, space); }, .Suspend => { diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig index 99574f2a98..b6c1a06276 100644 --- a/lib/std/zig/tokenizer.zig +++ b/lib/std/zig/tokenizer.zig @@ -49,8 +49,9 @@ pub const Token = struct { Keyword.init("inline", .Keyword_inline), Keyword.init("nakedcc", .Keyword_nakedcc), Keyword.init("noalias", .Keyword_noalias), - Keyword.init("noasync", .Keyword_noasync), + Keyword.init("noasync", .Keyword_nosuspend), // TODO: remove this Keyword.init("noinline", .Keyword_noinline), + Keyword.init("nosuspend", .Keyword_nosuspend), Keyword.init("null", .Keyword_null), Keyword.init("or", .Keyword_or), Keyword.init("orelse", .Keyword_orelse), @@ -182,8 +183,8 @@ pub const Token = struct { Keyword_inline, Keyword_nakedcc, Keyword_noalias, - Keyword_noasync, Keyword_noinline, + Keyword_nosuspend, Keyword_null, Keyword_or, Keyword_orelse, @@ -307,8 +308,8 @@ pub const Token = struct { .Keyword_inline => "inline", .Keyword_nakedcc => "nakedcc", .Keyword_noalias => "noalias", - .Keyword_noasync => "noasync", .Keyword_noinline => "noinline", + .Keyword_nosuspend => "nosuspend", .Keyword_null => "null", .Keyword_or => "or", .Keyword_orelse => "orelse", |
