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 @@...@@ -4,18 +4,16 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
66
7// TODO Remove this after zig 0.8.0 is released.7// TODO Remove this after zig 0.9.0 is released.
8// TODO need to add the logic to make this test pass. it was added in master8test "zig fmt: rewrite inline functions as callconv(.Inline)" {
9// but was not added in the ast-memory-layout branch yet.9 try testTransform(
10//test "zig fmt: rewrite inline functions as callconv(.Inline)" {10 \\inline fn foo() void {}
11// try testTransform(11 \\
12// \\inline fn foo() void {}12 ,
13// \\13 \\fn foo() callconv(.Inline) void {}
14// ,14 \\
15// \\fn foo() callconv(.Inline) void {}15 );
16// \\16}
17// );
18//}
1917
20test "zig fmt: simple top level comptime block" {18test "zig fmt: simple top level comptime block" {
21 try testCanonical(19 try testCanonical(
...@@ -2490,8 +2488,6 @@ test "zig fmt: function attributes" {...@@ -2490,8 +2488,6 @@ test "zig fmt: function attributes" {
2490 \\pub extern fn foo() void;2488 \\pub extern fn foo() void;
2491 \\extern "c" fn foo() void;2489 \\extern "c" fn foo() void;
2492 \\pub extern "c" fn foo() void;2490 \\pub extern "c" fn foo() void;
2493 \\inline fn foo() void {}
2494 \\pub inline fn foo() void {}
2495 \\noinline fn foo() void {}2491 \\noinline fn foo() void {}
2496 \\pub noinline fn foo() void {}2492 \\pub noinline fn foo() void {}
2497 \\2493 \\
lib/std/zig/render.zig+10
...@@ -79,6 +79,11 @@ fn renderMember(ais: *Ais, tree: ast.Tree, decl: ast.Node.Index, space: Space) E...@@ -79,6 +79,11 @@ fn renderMember(ais: *Ais, tree: ast.Tree, decl: ast.Node.Index, space: Space) E
79 }79 }
80 }80 }
81 while (i < fn_token) : (i += 1) {81 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 }
82 try renderToken(ais, tree, i, .space);87 try renderToken(ais, tree, i, .space);
83 }88 }
84 assert(datas[decl].rhs != 0);89 assert(datas[decl].rhs != 0);
...@@ -1260,6 +1265,9 @@ fn renderFnProto(ais: *Ais, tree: ast.Tree, fn_proto: ast.full.FnProto, space: S...@@ -1260,6 +1265,9 @@ fn renderFnProto(ais: *Ais, tree: ast.Tree, fn_proto: ast.full.FnProto, space: S
1260 const token_tags = tree.tokens.items(.tag);1265 const token_tags = tree.tokens.items(.tag);
1261 const token_starts = tree.tokens.items(.start);1266 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
1263 const after_fn_token = fn_proto.ast.fn_token + 1;1271 const after_fn_token = fn_proto.ast.fn_token + 1;
1264 const lparen = if (token_tags[after_fn_token] == .identifier) blk: {1272 const lparen = if (token_tags[after_fn_token] == .identifier) blk: {
1265 try renderToken(ais, tree, fn_proto.ast.fn_token, .space); // fn1273 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...@@ -1435,6 +1443,8 @@ fn renderFnProto(ais: *Ais, tree: ast.Tree, fn_proto: ast.full.FnProto, space: S
1435 try renderToken(ais, tree, callconv_lparen, .none); // (1443 try renderToken(ais, tree, callconv_lparen, .none); // (
1436 try renderExpression(ais, tree, fn_proto.ast.callconv_expr, .none);1444 try renderExpression(ais, tree, fn_proto.ast.callconv_expr, .none);
1437 try renderToken(ais, tree, callconv_rparen, .space); // )1445 try renderToken(ais, tree, callconv_rparen, .space); // )
1446 } else if (is_inline) {
1447 try ais.writer().writeAll("callconv(.Inline) ");
1438 }1448 }
14391449
1440 if (token_tags[maybe_bang] == .bang) {1450 if (token_tags[maybe_bang] == .bang) {