| ... | @@ -228,7 +228,7 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -228,7 +228,7 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 228 | | 228 | |
| 229 | var root_scope = Scope{ | 229 | var root_scope = Scope{ |
| 230 | .parent = null, | 230 | .parent = null, |
| 231 | .enclosing_type = main_type_index, | 231 | .enclosing_type = null, |
| 232 | }; | 232 | }; |
| 233 | | 233 | |
| 234 | const tldoc_comment = try self.getTLDocComment(file); | 234 | const tldoc_comment = try self.getTLDocComment(file); |
| ... | @@ -363,7 +363,7 @@ const Scope = struct { | ... | @@ -363,7 +363,7 @@ const Scope = struct { |
| 363 | *DeclStatus, | 363 | *DeclStatus, |
| 364 | ) = .{}, | 364 | ) = .{}, |
| 365 | | 365 | |
| 366 | enclosing_type: usize, // index into `types` | 366 | enclosing_type: ?usize, // index into `types`, null = file top-level struct |
| 367 | | 367 | |
| 368 | pub const DeclStatus = union(enum) { | 368 | pub const DeclStatus = union(enum) { |
| 369 | Analyzed: usize, // index into `decls` | 369 | Analyzed: usize, // index into `decls` |
| ... | @@ -516,6 +516,7 @@ const DocData = struct { | ... | @@ -516,6 +516,7 @@ const DocData = struct { |
| 516 | // The index in astNodes of the `test declname { }` node | 516 | // The index in astNodes of the `test declname { }` node |
| 517 | decltest: ?usize = null, | 517 | decltest: ?usize = null, |
| 518 | is_uns: bool = false, // usingnamespace | 518 | is_uns: bool = false, // usingnamespace |
| | 519 | parent_container: ?usize, // index into `types` |
| 519 | | 520 | |
| 520 | pub fn jsonStringify( | 521 | pub fn jsonStringify( |
| 521 | self: Decl, | 522 | self: Decl, |
| ... | @@ -600,7 +601,7 @@ const DocData = struct { | ... | @@ -600,7 +601,7 @@ const DocData = struct { |
| 600 | field_defaults: []?Expr = &.{}, // default values is specified | 601 | field_defaults: []?Expr = &.{}, // default values is specified |
| 601 | is_tuple: bool, | 602 | is_tuple: bool, |
| 602 | line_number: usize, | 603 | line_number: usize, |
| 603 | outer_decl: usize, | 604 | parent_container: ?usize, // index into `types` |
| 604 | }, | 605 | }, |
| 605 | ComptimeExpr: struct { name: []const u8 }, | 606 | ComptimeExpr: struct { name: []const u8 }, |
| 606 | ComptimeFloat: struct { name: []const u8 }, | 607 | ComptimeFloat: struct { name: []const u8 }, |
| ... | @@ -627,6 +628,7 @@ const DocData = struct { | ... | @@ -627,6 +628,7 @@ const DocData = struct { |
| 627 | tag: ?Expr = null, // tag type if specified | 628 | tag: ?Expr = null, // tag type if specified |
| 628 | values: []?Expr = &.{}, // tag values if specified | 629 | values: []?Expr = &.{}, // tag values if specified |
| 629 | nonexhaustive: bool, | 630 | nonexhaustive: bool, |
| | 631 | parent_container: ?usize, // index into `types` |
| 630 | }, | 632 | }, |
| 631 | Union: struct { | 633 | Union: struct { |
| 632 | name: []const u8, | 634 | name: []const u8, |
| ... | @@ -636,6 +638,7 @@ const DocData = struct { | ... | @@ -636,6 +638,7 @@ const DocData = struct { |
| 636 | fields: []Expr = &.{}, // (use src->fields to find names) | 638 | fields: []Expr = &.{}, // (use src->fields to find names) |
| 637 | tag: ?Expr, // tag type if specified | 639 | tag: ?Expr, // tag type if specified |
| 638 | auto_enum: bool, // tag is an auto enum | 640 | auto_enum: bool, // tag is an auto enum |
| | 641 | parent_container: ?usize, // index into `types` |
| 639 | }, | 642 | }, |
| 640 | Fn: struct { | 643 | Fn: struct { |
| 641 | name: []const u8, | 644 | name: []const u8, |
| ... | @@ -659,6 +662,7 @@ const DocData = struct { | ... | @@ -659,6 +662,7 @@ const DocData = struct { |
| 659 | src: usize, // index into astNodes | 662 | src: usize, // index into astNodes |
| 660 | privDecls: []usize = &.{}, // index into decls | 663 | privDecls: []usize = &.{}, // index into decls |
| 661 | pubDecls: []usize = &.{}, // index into decls | 664 | pubDecls: []usize = &.{}, // index into decls |
| | 665 | parent_container: ?usize, // index into `types` |
| 662 | }, | 666 | }, |
| 663 | Frame: struct { name: []const u8 }, | 667 | Frame: struct { name: []const u8 }, |
| 664 | AnyFrame: struct { name: []const u8 }, | 668 | AnyFrame: struct { name: []const u8 }, |
| ... | @@ -961,7 +965,7 @@ fn walkInstruction( | ... | @@ -961,7 +965,7 @@ fn walkInstruction( |
| 961 | | 965 | |
| 962 | var root_scope = Scope{ | 966 | var root_scope = Scope{ |
| 963 | .parent = null, | 967 | .parent = null, |
| 964 | .enclosing_type = main_type_index, | 968 | .enclosing_type = null, |
| 965 | }; | 969 | }; |
| 966 | const maybe_tldoc_comment = try self.getTLDocComment(file); | 970 | const maybe_tldoc_comment = try self.getTLDocComment(file); |
| 967 | try self.ast_nodes.append(self.arena, .{ | 971 | try self.ast_nodes.append(self.arena, .{ |
| ... | @@ -991,7 +995,7 @@ fn walkInstruction( | ... | @@ -991,7 +995,7 @@ fn walkInstruction( |
| 991 | | 995 | |
| 992 | var new_scope = Scope{ | 996 | var new_scope = Scope{ |
| 993 | .parent = null, | 997 | .parent = null, |
| 994 | .enclosing_type = self.types.items.len, | 998 | .enclosing_type = null, |
| 995 | }; | 999 | }; |
| 996 | | 1000 | |
| 997 | return self.walkInstruction( | 1001 | return self.walkInstruction( |
| ... | @@ -2493,6 +2497,7 @@ fn walkInstruction( | ... | @@ -2493,6 +2497,7 @@ fn walkInstruction( |
| 2493 | .src = self_ast_node_index, | 2497 | .src = self_ast_node_index, |
| 2494 | .privDecls = priv_decl_indexes.items, | 2498 | .privDecls = priv_decl_indexes.items, |
| 2495 | .pubDecls = decl_indexes.items, | 2499 | .pubDecls = decl_indexes.items, |
| | 2500 | .parent_container = parent_scope.enclosing_type, |
| 2496 | }, | 2501 | }, |
| 2497 | }; | 2502 | }; |
| 2498 | if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| { | 2503 | if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| { |
| ... | @@ -2635,6 +2640,7 @@ fn walkInstruction( | ... | @@ -2635,6 +2640,7 @@ fn walkInstruction( |
| 2635 | .fields = field_type_refs.items, | 2640 | .fields = field_type_refs.items, |
| 2636 | .tag = tag_type.expr, | 2641 | .tag = tag_type.expr, |
| 2637 | .auto_enum = small.auto_enum_tag, | 2642 | .auto_enum = small.auto_enum_tag, |
| | 2643 | .parent_container = parent_scope.enclosing_type, |
| 2638 | }, | 2644 | }, |
| 2639 | }; | 2645 | }; |
| 2640 | | 2646 | |
| ... | @@ -2772,6 +2778,7 @@ fn walkInstruction( | ... | @@ -2772,6 +2778,7 @@ fn walkInstruction( |
| 2772 | .tag = tag_type, | 2778 | .tag = tag_type, |
| 2773 | .values = field_values.items, | 2779 | .values = field_values.items, |
| 2774 | .nonexhaustive = small.nonexhaustive, | 2780 | .nonexhaustive = small.nonexhaustive, |
| | 2781 | .parent_container = parent_scope.enclosing_type, |
| 2775 | }, | 2782 | }, |
| 2776 | }; | 2783 | }; |
| 2777 | if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| { | 2784 | if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| { |
| ... | @@ -2872,7 +2879,7 @@ fn walkInstruction( | ... | @@ -2872,7 +2879,7 @@ fn walkInstruction( |
| 2872 | .field_defaults = field_default_refs.items, | 2879 | .field_defaults = field_default_refs.items, |
| 2873 | .is_tuple = small.is_tuple, | 2880 | .is_tuple = small.is_tuple, |
| 2874 | .line_number = self.ast_nodes.items[self_ast_node_index].line, | 2881 | .line_number = self.ast_nodes.items[self_ast_node_index].line, |
| 2875 | .outer_decl = type_slot_index - 1, | 2882 | .parent_container = parent_scope.enclosing_type, |
| 2876 | }, | 2883 | }, |
| 2877 | }; | 2884 | }; |
| 2878 | if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| { | 2885 | if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| { |
| ... | @@ -2897,7 +2904,12 @@ fn walkInstruction( | ... | @@ -2897,7 +2904,12 @@ fn walkInstruction( |
| 2897 | .this => { | 2904 | .this => { |
| 2898 | return DocData.WalkResult{ | 2905 | return DocData.WalkResult{ |
| 2899 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, | 2906 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| 2900 | .expr = .{ .this = parent_scope.enclosing_type }, | 2907 | .expr = .{ |
| | 2908 | .this = parent_scope.enclosing_type.?, |
| | 2909 | // We know enclosing_type is always present |
| | 2910 | // because it's only null for the top-level |
| | 2911 | // struct instruction of a file. |
| | 2912 | }, |
| 2901 | }; | 2913 | }; |
| 2902 | }, | 2914 | }, |
| 2903 | .error_to_int, | 2915 | .error_to_int, |
| ... | @@ -3224,6 +3236,7 @@ fn analyzeDecl( | ... | @@ -3224,6 +3236,7 @@ fn analyzeDecl( |
| 3224 | .src = ast_node_index, | 3236 | .src = ast_node_index, |
| 3225 | .value = walk_result, | 3237 | .value = walk_result, |
| 3226 | .kind = kind, | 3238 | .kind = kind, |
| | 3239 | .parent_container = scope.enclosing_type, |
| 3227 | }); | 3240 | }); |
| 3228 | | 3241 | |
| 3229 | if (is_pub) { | 3242 | if (is_pub) { |
| ... | @@ -3299,6 +3312,7 @@ fn analyzeUsingnamespaceDecl( | ... | @@ -3299,6 +3312,7 @@ fn analyzeUsingnamespaceDecl( |
| 3299 | .src = ast_node_index, | 3312 | .src = ast_node_index, |
| 3300 | .value = walk_result, | 3313 | .value = walk_result, |
| 3301 | .is_uns = true, | 3314 | .is_uns = true, |
| | 3315 | .parent_container = scope.enclosing_type, |
| 3302 | }); | 3316 | }); |
| 3303 | | 3317 | |
| 3304 | if (is_pub) { | 3318 | if (is_pub) { |