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

This commit is contained in:
Tadeo Kondrak 2021-01-11 07:56:48 -07:00
parent 61bcac108c
commit 9c797fe3ac
No known key found for this signature in database
GPG Key ID: D41E092CA43F1D8B
3 changed files with 21 additions and 3 deletions

View File

@ -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),

View File

@ -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);

View File

@ -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) {