zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 9c797fe3ac3a377caa01bdbd74b984d11b53398e (tree)
parent 61bcac108cecba0ab8e1b442bd71c51306c0e9fc
Author: Tadeo Kondrak <me@tadeo.ca>
Date:   Mon, 11 Jan 2021 07:56:48 -0700

std.zig: reformat inline fn to callconv(.Inline)

Diffstat:
Mlib/std/zig/ast.zig | 9+++++++++
Mlib/std/zig/parse.zig | 11+++++++++--
Mlib/std/zig/render.zig | 4+++-
3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig @@ -1357,6 +1357,7 @@ pub const Node = struct { extern_export_inline_token: TokenIndex, is_extern_prototype: void, // TODO: Remove once extern fn rewriting is is_async: void, // TODO: remove once async fn rewriting is + is_inline: void, // TODO: remove once inline fn rewriting is }); pub const RequiredFields = struct { @@ -1523,6 +1524,14 @@ pub const Node = struct { self.setTrailer(.is_async, value); } + pub fn getIsInline(self: *const FnProto) ?void { + return self.getTrailer(.is_inline); + } + + pub fn setIsInline(self: *FnProto, value: void) void { + self.setTrailer(.is_inline, value); + } + fn getTrailer(self: *const FnProto, comptime field: TrailerFlags.FieldEnum) ?TrailerFlags.Field(field) { const trailers_start = @alignCast( @alignOf(ParamDecl), diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig @@ -493,9 +493,15 @@ const Parser = struct { extern_export_inline_token: ?TokenIndex = null, lib_name: ?*Node = null, }) !?*Node { - // TODO: Remove once extern/async fn rewriting is - var is_async: ?void = null; + // TODO: Remove once extern/async/inline fn rewriting is var is_extern_prototype: ?void = null; + var is_async: ?void = null; + var is_inline: ?void = null; + if (fields.extern_export_inline_token != null and + p.token_ids[fields.extern_export_inline_token.?] == .Keyword_inline) + { + is_inline = {}; + } const cc_token: ?TokenIndex = blk: { if (p.eatToken(.Keyword_extern)) |token| { is_extern_prototype = {}; @@ -573,6 +579,7 @@ const Parser = struct { .callconv_expr = callconv_expr, .is_extern_prototype = is_extern_prototype, .is_async = is_async, + .is_inline = is_inline, }); std.mem.copy(Node.FnProto.ParamDecl, fn_proto_node.params(), params); diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig @@ -1558,7 +1558,7 @@ fn renderExpression( } if (fn_proto.getExternExportInlineToken()) |extern_export_inline_token| { - if (fn_proto.getIsExternPrototype() == null) + if (fn_proto.getIsExternPrototype() == null and fn_proto.getIsInline() == null) try renderToken(tree, ais, extern_export_inline_token, Space.Space); // extern/export/inline } @@ -1664,6 +1664,8 @@ fn renderExpression( try ais.writer().writeAll("callconv(.C) "); } else if (fn_proto.getIsAsync() != null) { try ais.writer().writeAll("callconv(.Async) "); + } else if (fn_proto.getIsInline() != null) { + try ais.writer().writeAll("callconv(.Inline) "); } switch (fn_proto.return_type) {