| author | |
| committer | |
| log | edfbf85ecdf29ee976534403369323def7905c62 |
| tree | 04e9be8dfd761336da9544c2fbf52db27ede20d5 |
| parent | 230ce72f168d5bcd0feb2f8f0aed42ea6ad27b09 |
3 files changed, 24 insertions(+), 23 deletions(-)
BRANCH_TODO-22| ... | @@ -118,31 +118,9 @@ fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool { | ... | @@ -118,31 +118,9 @@ fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool { |
| 118 | return mod.failWithOwnedErrorMsg(scope, msg); | 118 | return mod.failWithOwnedErrorMsg(scope, msg); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | |||
| 122 | const error_set = try arena.create(Module.ErrorSet); | ||
| 123 | error_set.* = .{ | ||
| 124 | .owner_decl = astgen.decl, | ||
| 125 | .node_offset = astgen.decl.nodeIndexToRelative(node), | ||
| 126 | .names_ptr = fields.ptr, | ||
| 127 | .names_len = @intCast(u32, fields.len), | ||
| 128 | }; | ||
| 129 | const error_set_ty = try Type.Tag.error_set.create(arena, error_set); | ||
| 130 | const error_set_val = try Value.Tag.ty.create(arena, error_set_ty); | ||
| 131 | const new_decl = try mod.createAnonymousDecl(scope, &new_decl_arena, .{ | ||
| 132 | .ty = Type.initTag(.type), | ||
| 133 | .val = error_set_val, | ||
| 134 | }); | ||
| 135 | const decl_index = try mod.declareDeclDependency(astgen.decl, new_decl); | ||
| 136 | const result = try gz.addDecl(.decl_val, decl_index, node); | ||
| 137 | return rvalue(gz, scope, rl, result, node); | ||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | // when implementing this be sure to add test coverage for the asm return type | 121 | // when implementing this be sure to add test coverage for the asm return type |
| 142 | // not resolving into a type (the node_offset_asm_ret_ty field of LazySrcLoc) | 122 | // not resolving into a type (the node_offset_asm_ret_ty field of LazySrcLoc) |
| 143 | 123 | ||
| 144 | |||
| 145 | |||
| 146 | pub fn analyzeNamespace( | 124 | pub fn analyzeNamespace( |
| 147 | mod: *Module, | 125 | mod: *Module, |
| 148 | namespace: *Scope.Namespace, | 126 | namespace: *Scope.Namespace, |
src/Module.zig+1| ... | @@ -478,6 +478,7 @@ pub const ErrorSet = struct { | ... | @@ -478,6 +478,7 @@ pub const ErrorSet = struct { |
| 478 | names_len: u32, | 478 | names_len: u32, |
| 479 | /// The string bytes are stored in the owner Decl arena. | 479 | /// The string bytes are stored in the owner Decl arena. |
| 480 | /// They are in the same order they appear in the AST. | 480 | /// They are in the same order they appear in the AST. |
| 481 | /// The length is given by `names_len`. | ||
| 481 | names_ptr: [*]const []const u8, | 482 | names_ptr: [*]const []const u8, |
| 482 | 483 | ||
| 483 | pub fn srcLoc(self: ErrorSet) SrcLoc { | 484 | pub fn srcLoc(self: ErrorSet) SrcLoc { |
src/Sema.zig+23-1| ... | @@ -908,11 +908,33 @@ fn zirErrorSetDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner | ... | @@ -908,11 +908,33 @@ fn zirErrorSetDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner |
| 908 | const tracy = trace(@src()); | 908 | const tracy = trace(@src()); |
| 909 | defer tracy.end(); | 909 | defer tracy.end(); |
| 910 | 910 | ||
| 911 | const gpa = sema.gpa; | ||
| 911 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 912 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 912 | const src = inst_data.src(); | 913 | const src = inst_data.src(); |
| 913 | const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); | 914 | const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); |
| 915 | const fields = sema.code.extra[extra.end..][0..extra.data.fields_len]; | ||
| 916 | |||
| 917 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); | ||
| 914 | 918 | ||
| 915 | return sema.mod.fail(&block.base, sema.src, "TODO implement zirErrorSetDecl", .{}); | 919 | const error_set = try new_decl_arena.allocator.create(Module.ErrorSet); |
| 920 | const error_set_ty = try Type.Tag.error_set.create(&new_decl_arena.allocator, error_set); | ||
| 921 | const error_set_val = try Value.Tag.ty.create(&new_decl_arena.allocator, error_set_ty); | ||
| 922 | const new_decl = try sema.mod.createAnonymousDecl(&block.base, .{ | ||
| 923 | .ty = Type.initTag(.type), | ||
| 924 | .val = error_set_val, | ||
| 925 | }); | ||
| 926 | const names = try new_decl_arena.allocator.alloc([]const u8, fields.len); | ||
| 927 | for (fields) |str_index, i| { | ||
| 928 | names[i] = try new_decl_arena.allocator.dupe(u8, sema.code.nullTerminatedString(str_index)); | ||
| 929 | } | ||
| 930 | error_set.* = .{ | ||
| 931 | .owner_decl = new_decl, | ||
| 932 | .node_offset = inst_data.src_node, | ||
| 933 | .names_ptr = names.ptr, | ||
| 934 | .names_len = @intCast(u32, names.len), | ||
| 935 | }; | ||
| 936 | try new_decl.finalizeNewArena(&new_decl_arena); | ||
| 937 | return sema.analyzeDeclVal(block, src, new_decl); | ||
| 916 | } | 938 | } |
| 917 | 939 | ||
| 918 | fn zirRetPtr( | 940 | fn zirRetPtr( |