authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-21 18:20:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-21 18:20:46-07:00
logc6efb23796053a4409b0cf7b6abb4044719779aa
tree2c83d31549f52fa7287817f80d1b6085e49c4125
parent878e99d580faf27aba2fbd782cb664da5d460614

zig fmt: rewrite inline functions as callconv(.Inline)


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

lib/std/zig/parser_test.zig+10-14
......@@ -4,18 +4,16 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66
7// TODO Remove this after zig 0.8.0 is released.
8// TODO need to add the logic to make this test pass. it was added in master
9// but was not added in the ast-memory-layout branch yet.
10//test "zig fmt: rewrite inline functions as callconv(.Inline)" {
11// try testTransform(
12// \\inline fn foo() void {}
13// \\
14// ,
15// \\fn foo() callconv(.Inline) void {}
16// \\
17// );
18//}
7// TODO Remove this after zig 0.9.0 is released.
8test "zig fmt: rewrite inline functions as callconv(.Inline)" {
9 try testTransform(
10 \\inline fn foo() void {}
11 \\
12 ,
13 \\fn foo() callconv(.Inline) void {}
14 \\
15 );
16}
1917
2018test "zig fmt: simple top level comptime block" {
2119 try testCanonical(
......@@ -2490,8 +2488,6 @@ test "zig fmt: function attributes" {
24902488 \\pub extern fn foo() void;
24912489 \\extern "c" fn foo() void;
24922490 \\pub extern "c" fn foo() void;
2493 \\inline fn foo() void {}
2494 \\pub inline fn foo() void {}
24952491 \\noinline fn foo() void {}
24962492 \\pub noinline fn foo() void {}
24972493 \\
lib/std/zig/render.zig+10
......@@ -79,6 +79,11 @@ fn renderMember(ais: *Ais, tree: ast.Tree, decl: ast.Node.Index, space: Space) E
7979 }
8080 }
8181 while (i < fn_token) : (i += 1) {
82 if (token_tags[i] == .keyword_inline) {
83 // TODO remove this special case when 0.9.0 is released.
84 // See the commit that introduced this comment for more details.
85 continue;
86 }
8287 try renderToken(ais, tree, i, .space);
8388 }
8489 assert(datas[decl].rhs != 0);
......@@ -1260,6 +1265,9 @@ fn renderFnProto(ais: *Ais, tree: ast.Tree, fn_proto: ast.full.FnProto, space: S
12601265 const token_tags = tree.tokens.items(.tag);
12611266 const token_starts = tree.tokens.items(.start);
12621267
1268 const is_inline = fn_proto.ast.fn_token > 0 and
1269 token_tags[fn_proto.ast.fn_token - 1] == .keyword_inline;
1270
12631271 const after_fn_token = fn_proto.ast.fn_token + 1;
12641272 const lparen = if (token_tags[after_fn_token] == .identifier) blk: {
12651273 try renderToken(ais, tree, fn_proto.ast.fn_token, .space); // fn
......@@ -1435,6 +1443,8 @@ fn renderFnProto(ais: *Ais, tree: ast.Tree, fn_proto: ast.full.FnProto, space: S
14351443 try renderToken(ais, tree, callconv_lparen, .none); // (
14361444 try renderExpression(ais, tree, fn_proto.ast.callconv_expr, .none);
14371445 try renderToken(ais, tree, callconv_rparen, .space); // )
1446 } else if (is_inline) {
1447 try ais.writer().writeAll("callconv(.Inline) ");
14381448 }
14391449
14401450 if (token_tags[maybe_bang] == .bang) {