From 1f56ff8343ef07d2d04d4a596b3f03f61230a753 Mon Sep 17 00:00:00 2001 From: Loris Cro Date: Fri, 21 Jan 2022 17:42:48 +0100 Subject: [PATCH] add support for more decl attributes in doc comment zir The previous commit that implemented doc comment zir support for decls did not properly account for all the possible attribute keyword combinations (threadlocal, extern, and such). --- src/AstGen.zig | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 142806e74c..c6b4e6e866 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -3193,7 +3193,6 @@ fn fnDecl( // missing function name already happened in scanDecls() const fn_name_token = fn_proto.name_token orelse return error.AnalysisFail; const fn_name_str_index = try astgen.identAsString(fn_name_token); - const doc_comment_index = try astgen.docCommentAsString(fn_name_token - 1); // We insert this at the beginning so that its instruction index marks the // start of the top level declaration. @@ -3237,6 +3236,13 @@ fn fnDecl( const maybe_inline_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_inline_token] == .keyword_inline; }; + + const doc_comment_index = try astgen.docCommentAsString(fn_name_token - 1 - + @boolToInt(is_pub) - + @boolToInt(is_export) - + @boolToInt(is_extern) - + @boolToInt(has_inline_keyword)); // TODO subtract noinline too + const has_section_or_addrspace = fn_proto.ast.section_expr != 0 or fn_proto.ast.addrspace_expr != 0; wip_members.nextDecl(is_pub, is_export, fn_proto.ast.align_expr != 0, has_section_or_addrspace); @@ -3474,7 +3480,6 @@ fn globalVarDecl( const name_token = var_decl.ast.mut_token + 1; const name_str_index = try astgen.identAsString(name_token); - const doc_comment_index = try astgen.docCommentAsString(var_decl.ast.mut_token); var block_scope: GenZir = .{ .parent = scope, @@ -3522,6 +3527,12 @@ fn globalVarDecl( break :blk lib_name_str.index; } else 0; + const doc_comment_index = try astgen.docCommentAsString(var_decl.ast.mut_token - + @boolToInt(is_pub) - + @boolToInt(is_export) - + @boolToInt(lib_name != 0) - + @boolToInt(is_threadlocal)); + assert(var_decl.comptime_token == null); // handled by parser const var_inst: Zir.Inst.Ref = if (var_decl.ast.init_node != 0) vi: {