diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2021-05-20 14:08:57 +0200 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2021-05-20 14:54:44 +0200 |
| commit | 3fd8ac092e88ac4bc604afcdd3fcb33249dba967 (patch) | |
| tree | 7e0cb16071c65746f7fcf86bdaa0f3c67eded508 /src/AstGen.zig | |
| parent | 569525f03e17ba32204733108a950a5170662299 (diff) | |
| download | zig-3fd8ac092e88ac4bc604afcdd3fcb33249dba967.tar.gz zig-3fd8ac092e88ac4bc604afcdd3fcb33249dba967.zip | |
stage2: support inline keyword on function decls
This is an alternative to callconv(.Inline). Using an inline keyword
as well as an explicit callconv() is a compile error.
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 8798c98021..547d608625 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -995,7 +995,7 @@ fn fnProtoExpr( const token_tags = tree.tokens.items(.tag); const is_extern = blk: { - const maybe_extern_token = fn_proto.extern_export_token orelse break :blk false; + const maybe_extern_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_extern_token] == .keyword_extern; }; assert(!is_extern); @@ -2735,15 +2735,20 @@ fn fnDecl( }; defer decl_gz.instructions.deinit(gpa); + // TODO: support noinline const is_pub = fn_proto.visib_token != null; const is_export = blk: { - const maybe_export_token = fn_proto.extern_export_token orelse break :blk false; + const maybe_export_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_export_token] == .keyword_export; }; const is_extern = blk: { - const maybe_extern_token = fn_proto.extern_export_token orelse break :blk false; + const maybe_extern_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_extern_token] == .keyword_extern; }; + const has_inline_keyword = blk: { + const maybe_inline_token = fn_proto.extern_export_inline_token orelse break :blk false; + break :blk token_tags[maybe_inline_token] == .keyword_inline; + }; const align_inst: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: { break :inst try expr(&decl_gz, &decl_gz.base, align_rl, fn_proto.ast.align_expr); }; @@ -2812,17 +2817,30 @@ fn fnDecl( fn_proto.ast.return_type, ); - const cc: Zir.Inst.Ref = if (fn_proto.ast.callconv_expr != 0) - try AstGen.expr( - &decl_gz, - &decl_gz.base, - .{ .ty = .calling_convention_type }, - fn_proto.ast.callconv_expr, - ) - else if (is_extern) // note: https://github.com/ziglang/zig/issues/5269 - Zir.Inst.Ref.calling_convention_c - else - Zir.Inst.Ref.none; + const cc: Zir.Inst.Ref = blk: { + if (fn_proto.ast.callconv_expr != 0) { + if (has_inline_keyword) { + return astgen.failNode( + fn_proto.ast.callconv_expr, + "explicit callconv incompatible with inline keyword", + .{}, + ); + } + break :blk try AstGen.expr( + &decl_gz, + &decl_gz.base, + .{ .ty = .calling_convention_type }, + fn_proto.ast.callconv_expr, + ); + } else if (is_extern) { + // note: https://github.com/ziglang/zig/issues/5269 + break :blk .calling_convention_c; + } else if (has_inline_keyword) { + break :blk .calling_convention_inline; + } else { + break :blk .none; + } + }; const func_inst: Zir.Inst.Ref = if (body_node == 0) func: { if (!is_extern) { |
