| ... | @@ -380,16 +380,48 @@ export fn decl_params(decl_index: Decl.Index) Slice(Ast.Node.Index) { | ... | @@ -380,16 +380,48 @@ export fn decl_params(decl_index: Decl.Index) Slice(Ast.Node.Index) { |
| 380 | } | 380 | } |
| 381 | | 381 | |
| 382 | fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index { | 382 | fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index { |
| | 383 | const decl = decl_index.get(); |
| | 384 | const ast = decl.file.get_ast(); |
| | 385 | |
| | 386 | switch (decl.categorize()) { |
| | 387 | .type_function => { |
| | 388 | const node_tags = ast.nodes.items(.tag); |
| | 389 | |
| | 390 | // Find the return statement |
| | 391 | if (decl.get_type_fn_return_expr()) |return_expr| { |
| | 392 | switch (node_tags[return_expr]) { |
| | 393 | .call, .call_comma, .call_one, .call_one_comma => { |
| | 394 | const node_data = ast.nodes.items(.data); |
| | 395 | const function = node_data[return_expr].lhs; |
| | 396 | const token = ast.nodes.items(.main_token)[function]; |
| | 397 | const name = ast.tokenSlice(token); |
| | 398 | if (decl.lookup(name)) |function_decl| { |
| | 399 | return decl_fields_fallible(function_decl); |
| | 400 | } |
| | 401 | }, |
| | 402 | .container_decl, .container_decl_trailing, .container_decl_two, .container_decl_two_trailing, .container_decl_arg, .container_decl_arg_trailing => { |
| | 403 | return ast_decl_fields_fallible(ast, return_expr); |
| | 404 | }, |
| | 405 | else => {}, |
| | 406 | } |
| | 407 | } |
| | 408 | return &.{}; |
| | 409 | }, |
| | 410 | else => { |
| | 411 | const value_node = decl.value_node() orelse return &.{}; |
| | 412 | return ast_decl_fields_fallible(ast, value_node); |
| | 413 | }, |
| | 414 | } |
| | 415 | } |
| | 416 | |
| | 417 | fn ast_decl_fields_fallible(ast: *Ast, ast_index: Ast.Node.Index) ![]Ast.Node.Index { |
| 383 | const g = struct { | 418 | const g = struct { |
| 384 | var result: std.ArrayListUnmanaged(Ast.Node.Index) = .empty; | 419 | var result: std.ArrayListUnmanaged(Ast.Node.Index) = .empty; |
| 385 | }; | 420 | }; |
| 386 | g.result.clearRetainingCapacity(); | 421 | g.result.clearRetainingCapacity(); |
| 387 | const decl = decl_index.get(); | | |
| 388 | const ast = decl.file.get_ast(); | | |
| 389 | const node_tags = ast.nodes.items(.tag); | 422 | const node_tags = ast.nodes.items(.tag); |
| 390 | const value_node = decl.value_node() orelse return &.{}; | | |
| 391 | var buf: [2]Ast.Node.Index = undefined; | 423 | var buf: [2]Ast.Node.Index = undefined; |
| 392 | const container_decl = ast.fullContainerDecl(&buf, value_node) orelse return &.{}; | 424 | const container_decl = ast.fullContainerDecl(&buf, ast_index) orelse return &.{}; |
| 393 | for (container_decl.ast.members) |member_node| switch (node_tags[member_node]) { | 425 | for (container_decl.ast.members) |member_node| switch (node_tags[member_node]) { |
| 394 | .container_field_init, | 426 | .container_field_init, |
| 395 | .container_field_align, | 427 | .container_field_align, |
| ... | @@ -883,6 +915,13 @@ export fn categorize_decl(decl_index: Decl.Index, resolve_alias_count: usize) Wa | ... | @@ -883,6 +915,13 @@ export fn categorize_decl(decl_index: Decl.Index, resolve_alias_count: usize) Wa |
| 883 | } | 915 | } |
| 884 | | 916 | |
| 885 | export fn type_fn_members(parent: Decl.Index, include_private: bool) Slice(Decl.Index) { | 917 | export fn type_fn_members(parent: Decl.Index, include_private: bool) Slice(Decl.Index) { |
| | 918 | const decl = parent.get(); |
| | 919 | |
| | 920 | // If the type function returns another type function, get the members of that function |
| | 921 | if (decl.get_type_fn_return_type_fn()) |function_decl| { |
| | 922 | return namespace_members(function_decl, include_private); |
| | 923 | } |
| | 924 | |
| 886 | return namespace_members(parent, include_private); | 925 | return namespace_members(parent, include_private); |
| 887 | } | 926 | } |
| 888 | | 927 | |