| ... | ... | @@ -82,9 +82,11 @@ pub fn generate(gpa: *Allocator, tree: ast.Tree) InnerError!Zir { |
| 82 | 82 | try astgen.extra.ensureTotalCapacity(gpa, tree.nodes.len + reserved_count); |
| 83 | 83 | astgen.extra.items.len += reserved_count; |
| 84 | 84 | |
| 85 | var top_scope: Scope.Top = .{}; |
| 86 | |
| 85 | 87 | var gen_scope: GenZir = .{ |
| 86 | 88 | .force_comptime = true, |
| 87 | | .parent = null, |
| 89 | .parent = &top_scope.base, |
| 88 | 90 | .anon_name_strategy = .parent, |
| 89 | 91 | .decl_node_index = 0, |
| 90 | 92 | .decl_line = 0, |
| ... | ... | @@ -1514,7 +1516,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) Inn |
| 1514 | 1516 | } else if (block_gz.break_block != 0) { |
| 1515 | 1517 | break :blk block_gz.break_block; |
| 1516 | 1518 | } |
| 1517 | | scope = block_gz.parent orelse break; |
| 1519 | scope = block_gz.parent; |
| 1518 | 1520 | continue; |
| 1519 | 1521 | }; |
| 1520 | 1522 | |
| ... | ... | @@ -1545,6 +1547,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) Inn |
| 1545 | 1547 | }, |
| 1546 | 1548 | .local_val => scope = scope.cast(Scope.LocalVal).?.parent, |
| 1547 | 1549 | .local_ptr => scope = scope.cast(Scope.LocalPtr).?.parent, |
| 1550 | .namespace => break, |
| 1548 | 1551 | .defer_normal => { |
| 1549 | 1552 | const defer_scope = scope.cast(Scope.Defer).?; |
| 1550 | 1553 | scope = defer_scope.parent; |
| ... | ... | @@ -1552,6 +1555,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) Inn |
| 1552 | 1555 | try unusedResultExpr(parent_gz, defer_scope.parent, expr_node); |
| 1553 | 1556 | }, |
| 1554 | 1557 | .defer_error => scope = scope.cast(Scope.Defer).?.parent, |
| 1558 | .top => unreachable, |
| 1555 | 1559 | } |
| 1556 | 1560 | } |
| 1557 | 1561 | if (break_label != 0) { |
| ... | ... | @@ -1576,7 +1580,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) |
| 1576 | 1580 | const gen_zir = scope.cast(GenZir).?; |
| 1577 | 1581 | const continue_block = gen_zir.continue_block; |
| 1578 | 1582 | if (continue_block == 0) { |
| 1579 | | scope = gen_zir.parent orelse break; |
| 1583 | scope = gen_zir.parent; |
| 1580 | 1584 | continue; |
| 1581 | 1585 | } |
| 1582 | 1586 | if (break_label != 0) blk: { |
| ... | ... | @@ -1587,7 +1591,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) |
| 1587 | 1591 | } |
| 1588 | 1592 | } |
| 1589 | 1593 | // found continue but either it has a different label, or no label |
| 1590 | | scope = gen_zir.parent orelse break; |
| 1594 | scope = gen_zir.parent; |
| 1591 | 1595 | continue; |
| 1592 | 1596 | } |
| 1593 | 1597 | |
| ... | ... | @@ -1604,6 +1608,8 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) |
| 1604 | 1608 | try unusedResultExpr(parent_gz, defer_scope.parent, expr_node); |
| 1605 | 1609 | }, |
| 1606 | 1610 | .defer_error => scope = scope.cast(Scope.Defer).?.parent, |
| 1611 | .namespace => break, |
| 1612 | .top => unreachable, |
| 1607 | 1613 | } |
| 1608 | 1614 | } |
| 1609 | 1615 | if (break_label != 0) { |
| ... | ... | @@ -1664,11 +1670,13 @@ fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.Toke |
| 1664 | 1670 | }); |
| 1665 | 1671 | } |
| 1666 | 1672 | } |
| 1667 | | scope = gen_zir.parent orelse return; |
| 1673 | scope = gen_zir.parent; |
| 1668 | 1674 | }, |
| 1669 | 1675 | .local_val => scope = scope.cast(Scope.LocalVal).?.parent, |
| 1670 | 1676 | .local_ptr => scope = scope.cast(Scope.LocalPtr).?.parent, |
| 1671 | 1677 | .defer_normal, .defer_error => scope = scope.cast(Scope.Defer).?.parent, |
| 1678 | .namespace => break, |
| 1679 | .top => unreachable, |
| 1672 | 1680 | } |
| 1673 | 1681 | } |
| 1674 | 1682 | } |
| ... | ... | @@ -2103,7 +2111,7 @@ fn genDefers( |
| 2103 | 2111 | var scope = inner_scope; |
| 2104 | 2112 | while (scope != outer_scope) { |
| 2105 | 2113 | switch (scope.tag) { |
| 2106 | | .gen_zir => scope = scope.cast(GenZir).?.parent.?, |
| 2114 | .gen_zir => scope = scope.cast(GenZir).?.parent, |
| 2107 | 2115 | .local_val => scope = scope.cast(Scope.LocalVal).?.parent, |
| 2108 | 2116 | .local_ptr => scope = scope.cast(Scope.LocalPtr).?.parent, |
| 2109 | 2117 | .defer_normal => { |
| ... | ... | @@ -2119,6 +2127,8 @@ fn genDefers( |
| 2119 | 2127 | const expr_node = node_datas[defer_scope.defer_node].rhs; |
| 2120 | 2128 | try unusedResultExpr(gz, defer_scope.parent, expr_node); |
| 2121 | 2129 | }, |
| 2130 | .namespace => unreachable, |
| 2131 | .top => unreachable, |
| 2122 | 2132 | } |
| 2123 | 2133 | } |
| 2124 | 2134 | } |
| ... | ... | @@ -2162,12 +2172,14 @@ fn varDecl( |
| 2162 | 2172 | .local_val => { |
| 2163 | 2173 | const local_val = s.cast(Scope.LocalVal).?; |
| 2164 | 2174 | if (local_val.name == ident_name) { |
| 2175 | const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(ident_name))); |
| 2176 | defer gpa.free(name); |
| 2165 | 2177 | return astgen.failTokNotes(name_token, "redeclaration of '{s}'", .{ |
| 2166 | | astgen.nullTerminatedString(ident_name), |
| 2178 | name, |
| 2167 | 2179 | }, &[_]u32{ |
| 2168 | 2180 | try astgen.errNoteTok( |
| 2169 | 2181 | local_val.token_src, |
| 2170 | | "previous declaration is here", |
| 2182 | "previously declared here", |
| 2171 | 2183 | .{}, |
| 2172 | 2184 | ), |
| 2173 | 2185 | }); |
| ... | ... | @@ -2177,20 +2189,37 @@ fn varDecl( |
| 2177 | 2189 | .local_ptr => { |
| 2178 | 2190 | const local_ptr = s.cast(Scope.LocalPtr).?; |
| 2179 | 2191 | if (local_ptr.name == ident_name) { |
| 2192 | const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(ident_name))); |
| 2193 | defer gpa.free(name); |
| 2180 | 2194 | return astgen.failTokNotes(name_token, "redeclaration of '{s}'", .{ |
| 2181 | | astgen.nullTerminatedString(ident_name), |
| 2195 | name, |
| 2182 | 2196 | }, &[_]u32{ |
| 2183 | 2197 | try astgen.errNoteTok( |
| 2184 | 2198 | local_ptr.token_src, |
| 2185 | | "previous declaration is here", |
| 2199 | "previously declared here", |
| 2186 | 2200 | .{}, |
| 2187 | 2201 | ), |
| 2188 | 2202 | }); |
| 2189 | 2203 | } |
| 2190 | 2204 | s = local_ptr.parent; |
| 2191 | 2205 | }, |
| 2192 | | .gen_zir => s = s.cast(GenZir).?.parent orelse break, |
| 2206 | .namespace => { |
| 2207 | const ns = s.cast(Scope.Namespace).?; |
| 2208 | const decl_node = ns.decls.get(ident_name) orelse { |
| 2209 | s = ns.parent; |
| 2210 | continue; |
| 2211 | }; |
| 2212 | const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(ident_name))); |
| 2213 | defer gpa.free(name); |
| 2214 | return astgen.failTokNotes(name_token, "local shadows declaration of '{s}'", .{ |
| 2215 | name, |
| 2216 | }, &[_]u32{ |
| 2217 | try astgen.errNoteNode(decl_node, "declared here", .{}), |
| 2218 | }); |
| 2219 | }, |
| 2220 | .gen_zir => s = s.cast(GenZir).?.parent, |
| 2193 | 2221 | .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent, |
| 2222 | .top => break, |
| 2194 | 2223 | }; |
| 2195 | 2224 | } |
| 2196 | 2225 | |
| ... | ... | @@ -2676,6 +2705,7 @@ const WipDecls = struct { |
| 2676 | 2705 | fn fnDecl( |
| 2677 | 2706 | astgen: *AstGen, |
| 2678 | 2707 | gz: *GenZir, |
| 2708 | scope: *Scope, |
| 2679 | 2709 | wip_decls: *WipDecls, |
| 2680 | 2710 | decl_node: ast.Node.Index, |
| 2681 | 2711 | body_node: ast.Node.Index, |
| ... | ... | @@ -2685,6 +2715,13 @@ fn fnDecl( |
| 2685 | 2715 | const tree = astgen.tree; |
| 2686 | 2716 | const token_tags = tree.tokens.items(.tag); |
| 2687 | 2717 | |
| 2718 | const fn_name_token = fn_proto.name_token orelse { |
| 2719 | return astgen.failTok(fn_proto.ast.fn_token, "missing function name", .{}); |
| 2720 | }; |
| 2721 | const fn_name_str_index = try astgen.identAsString(fn_name_token); |
| 2722 | |
| 2723 | try astgen.declareNewName(scope, fn_name_str_index, decl_node); |
| 2724 | |
| 2688 | 2725 | // We insert this at the beginning so that its instruction index marks the |
| 2689 | 2726 | // start of the top level declaration. |
| 2690 | 2727 | const block_inst = try gz.addBlock(.block_inline, fn_proto.ast.proto_node); |
| ... | ... | @@ -2693,7 +2730,7 @@ fn fnDecl( |
| 2693 | 2730 | .force_comptime = true, |
| 2694 | 2731 | .decl_node_index = fn_proto.ast.proto_node, |
| 2695 | 2732 | .decl_line = gz.calcLine(decl_node), |
| 2696 | | .parent = &gz.base, |
| 2733 | .parent = scope, |
| 2697 | 2734 | .astgen = astgen, |
| 2698 | 2735 | }; |
| 2699 | 2736 | defer decl_gz.instructions.deinit(gpa); |
| ... | ... | @@ -2891,11 +2928,6 @@ fn fnDecl( |
| 2891 | 2928 | }); |
| 2892 | 2929 | }; |
| 2893 | 2930 | |
| 2894 | | const fn_name_token = fn_proto.name_token orelse { |
| 2895 | | return astgen.failTok(fn_proto.ast.fn_token, "missing function name", .{}); |
| 2896 | | }; |
| 2897 | | const fn_name_str_index = try astgen.identAsString(fn_name_token); |
| 2898 | | |
| 2899 | 2931 | // We add this at the end so that its instruction index marks the end range |
| 2900 | 2932 | // of the top level declaration. |
| 2901 | 2933 | _ = try decl_gz.addBreak(.break_inline, block_inst, func_inst); |
| ... | ... | @@ -2941,6 +2973,8 @@ fn globalVarDecl( |
| 2941 | 2973 | const name_token = var_decl.ast.mut_token + 1; |
| 2942 | 2974 | const name_str_index = try astgen.identAsString(name_token); |
| 2943 | 2975 | |
| 2976 | try astgen.declareNewName(scope, name_str_index, node); |
| 2977 | |
| 2944 | 2978 | var block_scope: GenZir = .{ |
| 2945 | 2979 | .parent = scope, |
| 2946 | 2980 | .decl_node_index = node, |
| ... | ... | @@ -3289,6 +3323,9 @@ fn structDeclInner( |
| 3289 | 3323 | }; |
| 3290 | 3324 | defer block_scope.instructions.deinit(gpa); |
| 3291 | 3325 | |
| 3326 | var namespace: Scope.Namespace = .{ .parent = &gz.base }; |
| 3327 | defer namespace.decls.deinit(gpa); |
| 3328 | |
| 3292 | 3329 | var wip_decls: WipDecls = .{}; |
| 3293 | 3330 | defer wip_decls.deinit(gpa); |
| 3294 | 3331 | |
| ... | ... | @@ -3317,14 +3354,14 @@ fn structDeclInner( |
| 3317 | 3354 | switch (node_tags[fn_proto]) { |
| 3318 | 3355 | .fn_proto_simple => { |
| 3319 | 3356 | var params: [1]ast.Node.Index = undefined; |
| 3320 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 3357 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 3321 | 3358 | error.OutOfMemory => return error.OutOfMemory, |
| 3322 | 3359 | error.AnalysisFail => {}, |
| 3323 | 3360 | }; |
| 3324 | 3361 | continue; |
| 3325 | 3362 | }, |
| 3326 | 3363 | .fn_proto_multi => { |
| 3327 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 3364 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 3328 | 3365 | error.OutOfMemory => return error.OutOfMemory, |
| 3329 | 3366 | error.AnalysisFail => {}, |
| 3330 | 3367 | }; |
| ... | ... | @@ -3332,14 +3369,14 @@ fn structDeclInner( |
| 3332 | 3369 | }, |
| 3333 | 3370 | .fn_proto_one => { |
| 3334 | 3371 | var params: [1]ast.Node.Index = undefined; |
| 3335 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 3372 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 3336 | 3373 | error.OutOfMemory => return error.OutOfMemory, |
| 3337 | 3374 | error.AnalysisFail => {}, |
| 3338 | 3375 | }; |
| 3339 | 3376 | continue; |
| 3340 | 3377 | }, |
| 3341 | 3378 | .fn_proto => { |
| 3342 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 3379 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 3343 | 3380 | error.OutOfMemory => return error.OutOfMemory, |
| 3344 | 3381 | error.AnalysisFail => {}, |
| 3345 | 3382 | }; |
| ... | ... | @@ -3350,14 +3387,14 @@ fn structDeclInner( |
| 3350 | 3387 | }, |
| 3351 | 3388 | .fn_proto_simple => { |
| 3352 | 3389 | var params: [1]ast.Node.Index = undefined; |
| 3353 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 3390 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 3354 | 3391 | error.OutOfMemory => return error.OutOfMemory, |
| 3355 | 3392 | error.AnalysisFail => {}, |
| 3356 | 3393 | }; |
| 3357 | 3394 | continue; |
| 3358 | 3395 | }, |
| 3359 | 3396 | .fn_proto_multi => { |
| 3360 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 3397 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 3361 | 3398 | error.OutOfMemory => return error.OutOfMemory, |
| 3362 | 3399 | error.AnalysisFail => {}, |
| 3363 | 3400 | }; |
| ... | ... | @@ -3365,14 +3402,14 @@ fn structDeclInner( |
| 3365 | 3402 | }, |
| 3366 | 3403 | .fn_proto_one => { |
| 3367 | 3404 | var params: [1]ast.Node.Index = undefined; |
| 3368 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 3405 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 3369 | 3406 | error.OutOfMemory => return error.OutOfMemory, |
| 3370 | 3407 | error.AnalysisFail => {}, |
| 3371 | 3408 | }; |
| 3372 | 3409 | continue; |
| 3373 | 3410 | }, |
| 3374 | 3411 | .fn_proto => { |
| 3375 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 3412 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 3376 | 3413 | error.OutOfMemory => return error.OutOfMemory, |
| 3377 | 3414 | error.AnalysisFail => {}, |
| 3378 | 3415 | }; |
| ... | ... | @@ -3380,28 +3417,28 @@ fn structDeclInner( |
| 3380 | 3417 | }, |
| 3381 | 3418 | |
| 3382 | 3419 | .global_var_decl => { |
| 3383 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 3420 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 3384 | 3421 | error.OutOfMemory => return error.OutOfMemory, |
| 3385 | 3422 | error.AnalysisFail => {}, |
| 3386 | 3423 | }; |
| 3387 | 3424 | continue; |
| 3388 | 3425 | }, |
| 3389 | 3426 | .local_var_decl => { |
| 3390 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 3427 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 3391 | 3428 | error.OutOfMemory => return error.OutOfMemory, |
| 3392 | 3429 | error.AnalysisFail => {}, |
| 3393 | 3430 | }; |
| 3394 | 3431 | continue; |
| 3395 | 3432 | }, |
| 3396 | 3433 | .simple_var_decl => { |
| 3397 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 3434 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 3398 | 3435 | error.OutOfMemory => return error.OutOfMemory, |
| 3399 | 3436 | error.AnalysisFail => {}, |
| 3400 | 3437 | }; |
| 3401 | 3438 | continue; |
| 3402 | 3439 | }, |
| 3403 | 3440 | .aligned_var_decl => { |
| 3404 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 3441 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 3405 | 3442 | error.OutOfMemory => return error.OutOfMemory, |
| 3406 | 3443 | error.AnalysisFail => {}, |
| 3407 | 3444 | }; |
| ... | ... | @@ -3409,21 +3446,21 @@ fn structDeclInner( |
| 3409 | 3446 | }, |
| 3410 | 3447 | |
| 3411 | 3448 | .@"comptime" => { |
| 3412 | | astgen.comptimeDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 3449 | astgen.comptimeDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 3413 | 3450 | error.OutOfMemory => return error.OutOfMemory, |
| 3414 | 3451 | error.AnalysisFail => {}, |
| 3415 | 3452 | }; |
| 3416 | 3453 | continue; |
| 3417 | 3454 | }, |
| 3418 | 3455 | .@"usingnamespace" => { |
| 3419 | | astgen.usingnamespaceDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 3456 | astgen.usingnamespaceDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 3420 | 3457 | error.OutOfMemory => return error.OutOfMemory, |
| 3421 | 3458 | error.AnalysisFail => {}, |
| 3422 | 3459 | }; |
| 3423 | 3460 | continue; |
| 3424 | 3461 | }, |
| 3425 | 3462 | .test_decl => { |
| 3426 | | astgen.testDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 3463 | astgen.testDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 3427 | 3464 | error.OutOfMemory => return error.OutOfMemory, |
| 3428 | 3465 | error.AnalysisFail => {}, |
| 3429 | 3466 | }; |
| ... | ... | @@ -3547,6 +3584,9 @@ fn unionDeclInner( |
| 3547 | 3584 | }; |
| 3548 | 3585 | defer block_scope.instructions.deinit(gpa); |
| 3549 | 3586 | |
| 3587 | var namespace: Scope.Namespace = .{ .parent = &gz.base }; |
| 3588 | defer namespace.decls.deinit(gpa); |
| 3589 | |
| 3550 | 3590 | var wip_decls: WipDecls = .{}; |
| 3551 | 3591 | defer wip_decls.deinit(gpa); |
| 3552 | 3592 | |
| ... | ... | @@ -3575,14 +3615,14 @@ fn unionDeclInner( |
| 3575 | 3615 | switch (node_tags[fn_proto]) { |
| 3576 | 3616 | .fn_proto_simple => { |
| 3577 | 3617 | var params: [1]ast.Node.Index = undefined; |
| 3578 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 3618 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 3579 | 3619 | error.OutOfMemory => return error.OutOfMemory, |
| 3580 | 3620 | error.AnalysisFail => {}, |
| 3581 | 3621 | }; |
| 3582 | 3622 | continue; |
| 3583 | 3623 | }, |
| 3584 | 3624 | .fn_proto_multi => { |
| 3585 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 3625 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 3586 | 3626 | error.OutOfMemory => return error.OutOfMemory, |
| 3587 | 3627 | error.AnalysisFail => {}, |
| 3588 | 3628 | }; |
| ... | ... | @@ -3590,14 +3630,14 @@ fn unionDeclInner( |
| 3590 | 3630 | }, |
| 3591 | 3631 | .fn_proto_one => { |
| 3592 | 3632 | var params: [1]ast.Node.Index = undefined; |
| 3593 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 3633 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 3594 | 3634 | error.OutOfMemory => return error.OutOfMemory, |
| 3595 | 3635 | error.AnalysisFail => {}, |
| 3596 | 3636 | }; |
| 3597 | 3637 | continue; |
| 3598 | 3638 | }, |
| 3599 | 3639 | .fn_proto => { |
| 3600 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 3640 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 3601 | 3641 | error.OutOfMemory => return error.OutOfMemory, |
| 3602 | 3642 | error.AnalysisFail => {}, |
| 3603 | 3643 | }; |
| ... | ... | @@ -3608,14 +3648,14 @@ fn unionDeclInner( |
| 3608 | 3648 | }, |
| 3609 | 3649 | .fn_proto_simple => { |
| 3610 | 3650 | var params: [1]ast.Node.Index = undefined; |
| 3611 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 3651 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 3612 | 3652 | error.OutOfMemory => return error.OutOfMemory, |
| 3613 | 3653 | error.AnalysisFail => {}, |
| 3614 | 3654 | }; |
| 3615 | 3655 | continue; |
| 3616 | 3656 | }, |
| 3617 | 3657 | .fn_proto_multi => { |
| 3618 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 3658 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 3619 | 3659 | error.OutOfMemory => return error.OutOfMemory, |
| 3620 | 3660 | error.AnalysisFail => {}, |
| 3621 | 3661 | }; |
| ... | ... | @@ -3623,14 +3663,14 @@ fn unionDeclInner( |
| 3623 | 3663 | }, |
| 3624 | 3664 | .fn_proto_one => { |
| 3625 | 3665 | var params: [1]ast.Node.Index = undefined; |
| 3626 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 3666 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 3627 | 3667 | error.OutOfMemory => return error.OutOfMemory, |
| 3628 | 3668 | error.AnalysisFail => {}, |
| 3629 | 3669 | }; |
| 3630 | 3670 | continue; |
| 3631 | 3671 | }, |
| 3632 | 3672 | .fn_proto => { |
| 3633 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 3673 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 3634 | 3674 | error.OutOfMemory => return error.OutOfMemory, |
| 3635 | 3675 | error.AnalysisFail => {}, |
| 3636 | 3676 | }; |
| ... | ... | @@ -3638,28 +3678,28 @@ fn unionDeclInner( |
| 3638 | 3678 | }, |
| 3639 | 3679 | |
| 3640 | 3680 | .global_var_decl => { |
| 3641 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 3681 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 3642 | 3682 | error.OutOfMemory => return error.OutOfMemory, |
| 3643 | 3683 | error.AnalysisFail => {}, |
| 3644 | 3684 | }; |
| 3645 | 3685 | continue; |
| 3646 | 3686 | }, |
| 3647 | 3687 | .local_var_decl => { |
| 3648 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 3688 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 3649 | 3689 | error.OutOfMemory => return error.OutOfMemory, |
| 3650 | 3690 | error.AnalysisFail => {}, |
| 3651 | 3691 | }; |
| 3652 | 3692 | continue; |
| 3653 | 3693 | }, |
| 3654 | 3694 | .simple_var_decl => { |
| 3655 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 3695 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 3656 | 3696 | error.OutOfMemory => return error.OutOfMemory, |
| 3657 | 3697 | error.AnalysisFail => {}, |
| 3658 | 3698 | }; |
| 3659 | 3699 | continue; |
| 3660 | 3700 | }, |
| 3661 | 3701 | .aligned_var_decl => { |
| 3662 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 3702 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 3663 | 3703 | error.OutOfMemory => return error.OutOfMemory, |
| 3664 | 3704 | error.AnalysisFail => {}, |
| 3665 | 3705 | }; |
| ... | ... | @@ -3667,21 +3707,21 @@ fn unionDeclInner( |
| 3667 | 3707 | }, |
| 3668 | 3708 | |
| 3669 | 3709 | .@"comptime" => { |
| 3670 | | astgen.comptimeDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 3710 | astgen.comptimeDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 3671 | 3711 | error.OutOfMemory => return error.OutOfMemory, |
| 3672 | 3712 | error.AnalysisFail => {}, |
| 3673 | 3713 | }; |
| 3674 | 3714 | continue; |
| 3675 | 3715 | }, |
| 3676 | 3716 | .@"usingnamespace" => { |
| 3677 | | astgen.usingnamespaceDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 3717 | astgen.usingnamespaceDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 3678 | 3718 | error.OutOfMemory => return error.OutOfMemory, |
| 3679 | 3719 | error.AnalysisFail => {}, |
| 3680 | 3720 | }; |
| 3681 | 3721 | continue; |
| 3682 | 3722 | }, |
| 3683 | 3723 | .test_decl => { |
| 3684 | | astgen.testDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 3724 | astgen.testDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 3685 | 3725 | error.OutOfMemory => return error.OutOfMemory, |
| 3686 | 3726 | error.AnalysisFail => {}, |
| 3687 | 3727 | }; |
| ... | ... | @@ -3940,6 +3980,9 @@ fn containerDecl( |
| 3940 | 3980 | }; |
| 3941 | 3981 | defer block_scope.instructions.deinit(gpa); |
| 3942 | 3982 | |
| 3983 | var namespace: Scope.Namespace = .{ .parent = &gz.base }; |
| 3984 | defer namespace.decls.deinit(gpa); |
| 3985 | |
| 3943 | 3986 | var wip_decls: WipDecls = .{}; |
| 3944 | 3987 | defer wip_decls.deinit(gpa); |
| 3945 | 3988 | |
| ... | ... | @@ -3968,14 +4011,14 @@ fn containerDecl( |
| 3968 | 4011 | switch (node_tags[fn_proto]) { |
| 3969 | 4012 | .fn_proto_simple => { |
| 3970 | 4013 | var params: [1]ast.Node.Index = undefined; |
| 3971 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 4014 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 3972 | 4015 | error.OutOfMemory => return error.OutOfMemory, |
| 3973 | 4016 | error.AnalysisFail => {}, |
| 3974 | 4017 | }; |
| 3975 | 4018 | continue; |
| 3976 | 4019 | }, |
| 3977 | 4020 | .fn_proto_multi => { |
| 3978 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 4021 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 3979 | 4022 | error.OutOfMemory => return error.OutOfMemory, |
| 3980 | 4023 | error.AnalysisFail => {}, |
| 3981 | 4024 | }; |
| ... | ... | @@ -3983,14 +4026,14 @@ fn containerDecl( |
| 3983 | 4026 | }, |
| 3984 | 4027 | .fn_proto_one => { |
| 3985 | 4028 | var params: [1]ast.Node.Index = undefined; |
| 3986 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 4029 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 3987 | 4030 | error.OutOfMemory => return error.OutOfMemory, |
| 3988 | 4031 | error.AnalysisFail => {}, |
| 3989 | 4032 | }; |
| 3990 | 4033 | continue; |
| 3991 | 4034 | }, |
| 3992 | 4035 | .fn_proto => { |
| 3993 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 4036 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 3994 | 4037 | error.OutOfMemory => return error.OutOfMemory, |
| 3995 | 4038 | error.AnalysisFail => {}, |
| 3996 | 4039 | }; |
| ... | ... | @@ -4001,14 +4044,14 @@ fn containerDecl( |
| 4001 | 4044 | }, |
| 4002 | 4045 | .fn_proto_simple => { |
| 4003 | 4046 | var params: [1]ast.Node.Index = undefined; |
| 4004 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 4047 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 4005 | 4048 | error.OutOfMemory => return error.OutOfMemory, |
| 4006 | 4049 | error.AnalysisFail => {}, |
| 4007 | 4050 | }; |
| 4008 | 4051 | continue; |
| 4009 | 4052 | }, |
| 4010 | 4053 | .fn_proto_multi => { |
| 4011 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 4054 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 4012 | 4055 | error.OutOfMemory => return error.OutOfMemory, |
| 4013 | 4056 | error.AnalysisFail => {}, |
| 4014 | 4057 | }; |
| ... | ... | @@ -4016,14 +4059,14 @@ fn containerDecl( |
| 4016 | 4059 | }, |
| 4017 | 4060 | .fn_proto_one => { |
| 4018 | 4061 | var params: [1]ast.Node.Index = undefined; |
| 4019 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 4062 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 4020 | 4063 | error.OutOfMemory => return error.OutOfMemory, |
| 4021 | 4064 | error.AnalysisFail => {}, |
| 4022 | 4065 | }; |
| 4023 | 4066 | continue; |
| 4024 | 4067 | }, |
| 4025 | 4068 | .fn_proto => { |
| 4026 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 4069 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 4027 | 4070 | error.OutOfMemory => return error.OutOfMemory, |
| 4028 | 4071 | error.AnalysisFail => {}, |
| 4029 | 4072 | }; |
| ... | ... | @@ -4031,28 +4074,28 @@ fn containerDecl( |
| 4031 | 4074 | }, |
| 4032 | 4075 | |
| 4033 | 4076 | .global_var_decl => { |
| 4034 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 4077 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 4035 | 4078 | error.OutOfMemory => return error.OutOfMemory, |
| 4036 | 4079 | error.AnalysisFail => {}, |
| 4037 | 4080 | }; |
| 4038 | 4081 | continue; |
| 4039 | 4082 | }, |
| 4040 | 4083 | .local_var_decl => { |
| 4041 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 4084 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 4042 | 4085 | error.OutOfMemory => return error.OutOfMemory, |
| 4043 | 4086 | error.AnalysisFail => {}, |
| 4044 | 4087 | }; |
| 4045 | 4088 | continue; |
| 4046 | 4089 | }, |
| 4047 | 4090 | .simple_var_decl => { |
| 4048 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 4091 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 4049 | 4092 | error.OutOfMemory => return error.OutOfMemory, |
| 4050 | 4093 | error.AnalysisFail => {}, |
| 4051 | 4094 | }; |
| 4052 | 4095 | continue; |
| 4053 | 4096 | }, |
| 4054 | 4097 | .aligned_var_decl => { |
| 4055 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 4098 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 4056 | 4099 | error.OutOfMemory => return error.OutOfMemory, |
| 4057 | 4100 | error.AnalysisFail => {}, |
| 4058 | 4101 | }; |
| ... | ... | @@ -4060,21 +4103,21 @@ fn containerDecl( |
| 4060 | 4103 | }, |
| 4061 | 4104 | |
| 4062 | 4105 | .@"comptime" => { |
| 4063 | | astgen.comptimeDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 4106 | astgen.comptimeDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 4064 | 4107 | error.OutOfMemory => return error.OutOfMemory, |
| 4065 | 4108 | error.AnalysisFail => {}, |
| 4066 | 4109 | }; |
| 4067 | 4110 | continue; |
| 4068 | 4111 | }, |
| 4069 | 4112 | .@"usingnamespace" => { |
| 4070 | | astgen.usingnamespaceDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 4113 | astgen.usingnamespaceDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 4071 | 4114 | error.OutOfMemory => return error.OutOfMemory, |
| 4072 | 4115 | error.AnalysisFail => {}, |
| 4073 | 4116 | }; |
| 4074 | 4117 | continue; |
| 4075 | 4118 | }, |
| 4076 | 4119 | .test_decl => { |
| 4077 | | astgen.testDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 4120 | astgen.testDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 4078 | 4121 | error.OutOfMemory => return error.OutOfMemory, |
| 4079 | 4122 | error.AnalysisFail => {}, |
| 4080 | 4123 | }; |
| ... | ... | @@ -4164,6 +4207,9 @@ fn containerDecl( |
| 4164 | 4207 | return rvalue(gz, scope, rl, gz.indexToRef(decl_inst), node); |
| 4165 | 4208 | }, |
| 4166 | 4209 | .keyword_opaque => { |
| 4210 | var namespace: Scope.Namespace = .{ .parent = &gz.base }; |
| 4211 | defer namespace.decls.deinit(gpa); |
| 4212 | |
| 4167 | 4213 | var wip_decls: WipDecls = .{}; |
| 4168 | 4214 | defer wip_decls.deinit(gpa); |
| 4169 | 4215 | |
| ... | ... | @@ -4179,14 +4225,14 @@ fn containerDecl( |
| 4179 | 4225 | switch (node_tags[fn_proto]) { |
| 4180 | 4226 | .fn_proto_simple => { |
| 4181 | 4227 | var params: [1]ast.Node.Index = undefined; |
| 4182 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 4228 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) { |
| 4183 | 4229 | error.OutOfMemory => return error.OutOfMemory, |
| 4184 | 4230 | error.AnalysisFail => {}, |
| 4185 | 4231 | }; |
| 4186 | 4232 | continue; |
| 4187 | 4233 | }, |
| 4188 | 4234 | .fn_proto_multi => { |
| 4189 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 4235 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoMulti(fn_proto)) catch |err| switch (err) { |
| 4190 | 4236 | error.OutOfMemory => return error.OutOfMemory, |
| 4191 | 4237 | error.AnalysisFail => {}, |
| 4192 | 4238 | }; |
| ... | ... | @@ -4194,14 +4240,14 @@ fn containerDecl( |
| 4194 | 4240 | }, |
| 4195 | 4241 | .fn_proto_one => { |
| 4196 | 4242 | var params: [1]ast.Node.Index = undefined; |
| 4197 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 4243 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoOne(&params, fn_proto)) catch |err| switch (err) { |
| 4198 | 4244 | error.OutOfMemory => return error.OutOfMemory, |
| 4199 | 4245 | error.AnalysisFail => {}, |
| 4200 | 4246 | }; |
| 4201 | 4247 | continue; |
| 4202 | 4248 | }, |
| 4203 | 4249 | .fn_proto => { |
| 4204 | | astgen.fnDecl(gz, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 4250 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProto(fn_proto)) catch |err| switch (err) { |
| 4205 | 4251 | error.OutOfMemory => return error.OutOfMemory, |
| 4206 | 4252 | error.AnalysisFail => {}, |
| 4207 | 4253 | }; |
| ... | ... | @@ -4212,14 +4258,14 @@ fn containerDecl( |
| 4212 | 4258 | }, |
| 4213 | 4259 | .fn_proto_simple => { |
| 4214 | 4260 | var params: [1]ast.Node.Index = undefined; |
| 4215 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 4261 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoSimple(&params, member_node)) catch |err| switch (err) { |
| 4216 | 4262 | error.OutOfMemory => return error.OutOfMemory, |
| 4217 | 4263 | error.AnalysisFail => {}, |
| 4218 | 4264 | }; |
| 4219 | 4265 | continue; |
| 4220 | 4266 | }, |
| 4221 | 4267 | .fn_proto_multi => { |
| 4222 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 4268 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoMulti(member_node)) catch |err| switch (err) { |
| 4223 | 4269 | error.OutOfMemory => return error.OutOfMemory, |
| 4224 | 4270 | error.AnalysisFail => {}, |
| 4225 | 4271 | }; |
| ... | ... | @@ -4227,14 +4273,14 @@ fn containerDecl( |
| 4227 | 4273 | }, |
| 4228 | 4274 | .fn_proto_one => { |
| 4229 | 4275 | var params: [1]ast.Node.Index = undefined; |
| 4230 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 4276 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProtoOne(&params, member_node)) catch |err| switch (err) { |
| 4231 | 4277 | error.OutOfMemory => return error.OutOfMemory, |
| 4232 | 4278 | error.AnalysisFail => {}, |
| 4233 | 4279 | }; |
| 4234 | 4280 | continue; |
| 4235 | 4281 | }, |
| 4236 | 4282 | .fn_proto => { |
| 4237 | | astgen.fnDecl(gz, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 4283 | astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, 0, tree.fnProto(member_node)) catch |err| switch (err) { |
| 4238 | 4284 | error.OutOfMemory => return error.OutOfMemory, |
| 4239 | 4285 | error.AnalysisFail => {}, |
| 4240 | 4286 | }; |
| ... | ... | @@ -4242,28 +4288,28 @@ fn containerDecl( |
| 4242 | 4288 | }, |
| 4243 | 4289 | |
| 4244 | 4290 | .global_var_decl => { |
| 4245 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 4291 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.globalVarDecl(member_node)) catch |err| switch (err) { |
| 4246 | 4292 | error.OutOfMemory => return error.OutOfMemory, |
| 4247 | 4293 | error.AnalysisFail => {}, |
| 4248 | 4294 | }; |
| 4249 | 4295 | continue; |
| 4250 | 4296 | }, |
| 4251 | 4297 | .local_var_decl => { |
| 4252 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 4298 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.localVarDecl(member_node)) catch |err| switch (err) { |
| 4253 | 4299 | error.OutOfMemory => return error.OutOfMemory, |
| 4254 | 4300 | error.AnalysisFail => {}, |
| 4255 | 4301 | }; |
| 4256 | 4302 | continue; |
| 4257 | 4303 | }, |
| 4258 | 4304 | .simple_var_decl => { |
| 4259 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 4305 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.simpleVarDecl(member_node)) catch |err| switch (err) { |
| 4260 | 4306 | error.OutOfMemory => return error.OutOfMemory, |
| 4261 | 4307 | error.AnalysisFail => {}, |
| 4262 | 4308 | }; |
| 4263 | 4309 | continue; |
| 4264 | 4310 | }, |
| 4265 | 4311 | .aligned_var_decl => { |
| 4266 | | astgen.globalVarDecl(gz, scope, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 4312 | astgen.globalVarDecl(gz, &namespace.base, &wip_decls, member_node, tree.alignedVarDecl(member_node)) catch |err| switch (err) { |
| 4267 | 4313 | error.OutOfMemory => return error.OutOfMemory, |
| 4268 | 4314 | error.AnalysisFail => {}, |
| 4269 | 4315 | }; |
| ... | ... | @@ -4271,21 +4317,21 @@ fn containerDecl( |
| 4271 | 4317 | }, |
| 4272 | 4318 | |
| 4273 | 4319 | .@"comptime" => { |
| 4274 | | astgen.comptimeDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 4320 | astgen.comptimeDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 4275 | 4321 | error.OutOfMemory => return error.OutOfMemory, |
| 4276 | 4322 | error.AnalysisFail => {}, |
| 4277 | 4323 | }; |
| 4278 | 4324 | continue; |
| 4279 | 4325 | }, |
| 4280 | 4326 | .@"usingnamespace" => { |
| 4281 | | astgen.usingnamespaceDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 4327 | astgen.usingnamespaceDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 4282 | 4328 | error.OutOfMemory => return error.OutOfMemory, |
| 4283 | 4329 | error.AnalysisFail => {}, |
| 4284 | 4330 | }; |
| 4285 | 4331 | continue; |
| 4286 | 4332 | }, |
| 4287 | 4333 | .test_decl => { |
| 4288 | | astgen.testDecl(gz, scope, &wip_decls, member_node) catch |err| switch (err) { |
| 4334 | astgen.testDecl(gz, &namespace.base, &wip_decls, member_node) catch |err| switch (err) { |
| 4289 | 4335 | error.OutOfMemory => return error.OutOfMemory, |
| 4290 | 4336 | error.AnalysisFail => {}, |
| 4291 | 4337 | }; |
| ... | ... | @@ -4971,6 +5017,8 @@ fn whileExpr( |
| 4971 | 5017 | var loop_scope = parent_gz.makeSubBlock(scope); |
| 4972 | 5018 | loop_scope.setBreakResultLoc(rl); |
| 4973 | 5019 | defer loop_scope.instructions.deinit(astgen.gpa); |
| 5020 | defer loop_scope.labeled_breaks.deinit(astgen.gpa); |
| 5021 | defer loop_scope.labeled_store_to_block_ptr_list.deinit(astgen.gpa); |
| 4974 | 5022 | |
| 4975 | 5023 | var continue_scope = parent_gz.makeSubBlock(&loop_scope.base); |
| 4976 | 5024 | defer continue_scope.instructions.deinit(astgen.gpa); |
| ... | ... | @@ -5178,6 +5226,8 @@ fn forExpr( |
| 5178 | 5226 | var loop_scope = parent_gz.makeSubBlock(scope); |
| 5179 | 5227 | loop_scope.setBreakResultLoc(rl); |
| 5180 | 5228 | defer loop_scope.instructions.deinit(astgen.gpa); |
| 5229 | defer loop_scope.labeled_breaks.deinit(astgen.gpa); |
| 5230 | defer loop_scope.labeled_store_to_block_ptr_list.deinit(astgen.gpa); |
| 5181 | 5231 | |
| 5182 | 5232 | var cond_scope = parent_gz.makeSubBlock(&loop_scope.base); |
| 5183 | 5233 | defer cond_scope.instructions.deinit(astgen.gpa); |
| ... | ... | @@ -6006,8 +6056,9 @@ fn identifier( |
| 6006 | 6056 | } |
| 6007 | 6057 | s = local_ptr.parent; |
| 6008 | 6058 | }, |
| 6009 | | .gen_zir => s = s.cast(GenZir).?.parent orelse break, |
| 6059 | .gen_zir => s = s.cast(GenZir).?.parent, |
| 6010 | 6060 | .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent, |
| 6061 | .namespace, .top => break, // TODO look for ambiguous references to decls |
| 6011 | 6062 | }; |
| 6012 | 6063 | } |
| 6013 | 6064 | |
| ... | ... | @@ -7922,6 +7973,8 @@ const Scope = struct { |
| 7922 | 7973 | local_ptr, |
| 7923 | 7974 | defer_normal, |
| 7924 | 7975 | defer_error, |
| 7976 | namespace, |
| 7977 | top, |
| 7925 | 7978 | }; |
| 7926 | 7979 | |
| 7927 | 7980 | /// This is always a `const` local and importantly the `inst` is a value type, not a pointer. |
| ... | ... | @@ -7962,6 +8015,23 @@ const Scope = struct { |
| 7962 | 8015 | parent: *Scope, |
| 7963 | 8016 | defer_node: ast.Node.Index, |
| 7964 | 8017 | }; |
| 8018 | |
| 8019 | /// Represents a global scope that has any number of declarations in it. |
| 8020 | /// Each declaration has this as the parent scope. |
| 8021 | const Namespace = struct { |
| 8022 | const base_tag: Tag = .namespace; |
| 8023 | base: Scope = Scope{ .tag = base_tag }, |
| 8024 | |
| 8025 | parent: *Scope, |
| 8026 | /// Maps string table index to the source location of declaration, |
| 8027 | /// for the purposes of reporting name shadowing compile errors. |
| 8028 | decls: std.AutoHashMapUnmanaged(u32, ast.Node.Index) = .{}, |
| 8029 | }; |
| 8030 | |
| 8031 | const Top = struct { |
| 8032 | const base_tag: Scope.Tag = .top; |
| 8033 | base: Scope = Scope{ .tag = base_tag }, |
| 8034 | }; |
| 7965 | 8035 | }; |
| 7966 | 8036 | |
| 7967 | 8037 | /// This is a temporary structure; references to it are valid only |
| ... | ... | @@ -7979,7 +8049,7 @@ const GenZir = struct { |
| 7979 | 8049 | decl_node_index: ast.Node.Index, |
| 7980 | 8050 | /// The containing decl line index, absolute. |
| 7981 | 8051 | decl_line: u32, |
| 7982 | | parent: ?*Scope, |
| 8052 | parent: *Scope, |
| 7983 | 8053 | /// All `GenZir` scopes for the same ZIR share this. |
| 7984 | 8054 | astgen: *AstGen, |
| 7985 | 8055 | /// Keeps track of the list of instructions in this scope only. Indexes |
| ... | ... | @@ -8989,3 +9059,37 @@ const GenZir = struct { |
| 8989 | 9059 | fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 { |
| 8990 | 9060 | return @ptrCast([*:0]const u8, astgen.string_bytes.items.ptr) + index; |
| 8991 | 9061 | } |
| 9062 | |
| 9063 | fn declareNewName( |
| 9064 | astgen: *AstGen, |
| 9065 | start_scope: *Scope, |
| 9066 | name_index: u32, |
| 9067 | node: ast.Node.Index, |
| 9068 | ) !void { |
| 9069 | const gpa = astgen.gpa; |
| 9070 | var scope = start_scope; |
| 9071 | while (true) { |
| 9072 | switch (scope.tag) { |
| 9073 | .gen_zir => scope = scope.cast(GenZir).?.parent, |
| 9074 | .local_val => scope = scope.cast(Scope.LocalVal).?.parent, |
| 9075 | .local_ptr => scope = scope.cast(Scope.LocalPtr).?.parent, |
| 9076 | .defer_normal, .defer_error => scope = scope.cast(Scope.Defer).?.parent, |
| 9077 | .namespace => { |
| 9078 | const ns = scope.cast(Scope.Namespace).?; |
| 9079 | const gop = try ns.decls.getOrPut(gpa, name_index); |
| 9080 | if (gop.found_existing) { |
| 9081 | const name = try gpa.dupe(u8, mem.spanZ(astgen.nullTerminatedString(name_index))); |
| 9082 | defer gpa.free(name); |
| 9083 | return astgen.failNodeNotes(node, "redeclaration of '{s}'", .{ |
| 9084 | name, |
| 9085 | }, &[_]u32{ |
| 9086 | try astgen.errNoteNode(gop.entry.value, "other declaration here", .{}), |
| 9087 | }); |
| 9088 | } |
| 9089 | gop.entry.value = node; |
| 9090 | break; |
| 9091 | }, |
| 9092 | .top => break, |
| 9093 | } |
| 9094 | } |
| 9095 | } |