| ... | ... | @@ -476,8 +476,9 @@ const DocData = struct { |
| 476 | 476 | }, |
| 477 | 477 | Fn: struct { |
| 478 | 478 | name: []const u8, |
| 479 | | src: ?usize = null, // index into astNodes |
| 479 | src: ?usize = null, // index into `astNodes` |
| 480 | 480 | ret: Expr, |
| 481 | generic_ret: ?Expr = null, |
| 481 | 482 | params: ?[]Expr = null, // (use src->fields to find names) |
| 482 | 483 | lib_name: []const u8 = "", |
| 483 | 484 | is_var_args: bool = false, |
| ... | ... | @@ -522,7 +523,6 @@ const DocData = struct { |
| 522 | 523 | .ComptimeFloat => |v| try printTypeBody(v, options, w), |
| 523 | 524 | .Null => |v| try printTypeBody(v, options, w), |
| 524 | 525 | .Optional => |v| try printTypeBody(v, options, w), |
| 525 | | |
| 526 | 526 | .Struct => |v| try printTypeBody(v, options, w), |
| 527 | 527 | .Fn => |v| try printTypeBody(v, options, w), |
| 528 | 528 | .Union => |v| try printTypeBody(v, options, w), |
| ... | ... | @@ -886,6 +886,10 @@ fn walkInstruction( |
| 886 | 886 | ); |
| 887 | 887 | return self.cteTodo(@tagName(tags[inst_index])); |
| 888 | 888 | }, |
| 889 | .ret_node => { |
| 890 | const un_node = data[inst_index].un_node; |
| 891 | return self.walkRef(file, parent_scope, un_node.operand, false); |
| 892 | }, |
| 889 | 893 | .closure_get => { |
| 890 | 894 | const inst_node = data[inst_index].inst_node; |
| 891 | 895 | return try self.walkInstruction(file, parent_scope, inst_node.inst, need_type); |
| ... | ... | @@ -3882,7 +3886,20 @@ fn analyzeFunctionExtended( |
| 3882 | 3886 | } |
| 3883 | 3887 | |
| 3884 | 3888 | self.types.items[type_slot_index] = .{ |
| 3885 | | .Fn = .{ .name = "todo_name func", .src = self_ast_node_index, .params = param_type_refs.items, .ret = ret_type_ref.expr, .is_extern = extra.data.bits.is_extern, .has_cc = extra.data.bits.has_cc, .has_align = extra.data.bits.has_align, .has_lib_name = extra.data.bits.has_lib_name, .lib_name = lib_name, .is_inferred_error = extra.data.bits.is_inferred_error, .cc = cc_index, .@"align" = align_index }, |
| 3889 | .Fn = .{ |
| 3890 | .name = "todo_name func", |
| 3891 | .src = self_ast_node_index, |
| 3892 | .params = param_type_refs.items, |
| 3893 | .ret = ret_type_ref.expr, |
| 3894 | .is_extern = extra.data.bits.is_extern, |
| 3895 | .has_cc = extra.data.bits.has_cc, |
| 3896 | .has_align = extra.data.bits.has_align, |
| 3897 | .has_lib_name = extra.data.bits.has_lib_name, |
| 3898 | .lib_name = lib_name, |
| 3899 | .is_inferred_error = extra.data.bits.is_inferred_error, |
| 3900 | .cc = cc_index, |
| 3901 | .@"align" = align_index, |
| 3902 | }, |
| 3886 | 3903 | }; |
| 3887 | 3904 | |
| 3888 | 3905 | return DocData.WalkResult{ |
| ... | ... | @@ -3974,6 +3991,21 @@ fn analyzeFunction( |
| 3974 | 3991 | break :blk wr; |
| 3975 | 3992 | }; |
| 3976 | 3993 | |
| 3994 | // TODO: a complete version of this will probably need a scope |
| 3995 | // in order to evaluate correctly closures around funcion |
| 3996 | // parameters etc. |
| 3997 | const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) { |
| 3998 | .type => |t| if (t == @enumToInt(Ref.type_type)) |
| 3999 | try self.getGenericReturnType( |
| 4000 | file, |
| 4001 | scope, |
| 4002 | fn_info.body[fn_info.body.len - 1], |
| 4003 | ) |
| 4004 | else |
| 4005 | null, |
| 4006 | else => null, |
| 4007 | }; |
| 4008 | |
| 3977 | 4009 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; |
| 3978 | 4010 | self.types.items[type_slot_index] = .{ |
| 3979 | 4011 | .Fn = .{ |
| ... | ... | @@ -3981,6 +4013,7 @@ fn analyzeFunction( |
| 3981 | 4013 | .src = self_ast_node_index, |
| 3982 | 4014 | .params = param_type_refs.items, |
| 3983 | 4015 | .ret = ret_type_ref.expr, |
| 4016 | .generic_ret = generic_ret, |
| 3984 | 4017 | }, |
| 3985 | 4018 | }; |
| 3986 | 4019 | |
| ... | ... | @@ -3990,6 +4023,16 @@ fn analyzeFunction( |
| 3990 | 4023 | }; |
| 3991 | 4024 | } |
| 3992 | 4025 | |
| 4026 | fn getGenericReturnType( |
| 4027 | self: *Autodoc, |
| 4028 | file: *File, |
| 4029 | scope: *Scope, |
| 4030 | body_end: usize, |
| 4031 | ) !DocData.Expr { |
| 4032 | const wr = try self.walkInstruction(file, scope, body_end, false); |
| 4033 | return wr.expr; |
| 4034 | } |
| 4035 | |
| 3993 | 4036 | fn collectUnionFieldInfo( |
| 3994 | 4037 | self: *Autodoc, |
| 3995 | 4038 | file: *File, |