| ... | ... | @@ -55,72 +55,6 @@ |
| 55 | 55 | natural alignment for fields and do not have any comptime fields. this |
| 56 | 56 | will save 16 bytes per struct field in the compilation. |
| 57 | 57 | |
| 58 | | fn getAnonTypeName(mod: *Module, scope: *Scope, base_token: std.zig.ast.TokenIndex) ![]u8 { |
| 59 | | // TODO add namespaces, generic function signatrues |
| 60 | | const tree = scope.tree(); |
| 61 | | const token_tags = tree.tokens.items(.tag); |
| 62 | | const base_name = switch (token_tags[base_token]) { |
| 63 | | .keyword_struct => "struct", |
| 64 | | .keyword_enum => "enum", |
| 65 | | .keyword_union => "union", |
| 66 | | .keyword_opaque => "opaque", |
| 67 | | else => unreachable, |
| 68 | | }; |
| 69 | | const loc = tree.tokenLocation(0, base_token); |
| 70 | | return std.fmt.allocPrint(mod.gpa, "{s}:{d}:{d}", .{ base_name, loc.line, loc.column }); |
| 71 | | } |
| 72 | | |
| 73 | | |
| 74 | | /// Returns `true` if the Decl type changed. |
| 75 | | /// Returns `true` if this is the first time analyzing the Decl. |
| 76 | | /// Returns `false` otherwise. |
| 77 | | fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool { |
| 78 | | switch (node_tags[decl_node]) { |
| 79 | | .@"usingnamespace" => { |
| 80 | | decl.analysis = .in_progress; |
| 81 | | |
| 82 | | var code: Zir = blk: { |
| 83 | | var astgen = try AstGen.init(mod, decl, &analysis_arena.allocator); |
| 84 | | defer astgen.deinit(); |
| 85 | | |
| 86 | | var gen_scope: Scope.GenZir = .{ |
| 87 | | .force_comptime = true, |
| 88 | | .parent = &decl.namespace.base, |
| 89 | | .astgen = &astgen, |
| 90 | | }; |
| 91 | | defer gen_scope.instructions.deinit(mod.gpa); |
| 92 | | |
| 93 | | const ns_type = try AstGen.typeExpr(&gen_scope, &gen_scope.base, type_expr); |
| 94 | | |
| 95 | | }; |
| 96 | | try decl.namespace.usingnamespace_set.put(mod.gpa, ty.getNamespace().?, is_pub); |
| 97 | | |
| 98 | | decl.analysis = .complete; |
| 99 | | decl.generation = mod.generation; |
| 100 | | return true; |
| 101 | | }, |
| 102 | | else => unreachable, |
| 103 | | } |
| 104 | | } |
| 105 | | |
| 106 | | if (mod.lookupIdentifier(scope, ident_name)) |decl| { |
| 107 | | const msg = msg: { |
| 108 | | const msg = try mod.errMsg( |
| 109 | | scope, |
| 110 | | name_src, |
| 111 | | "redeclaration of '{s}'", |
| 112 | | .{ident_name}, |
| 113 | | ); |
| 114 | | errdefer msg.destroy(gpa); |
| 115 | | try mod.errNoteNonLazy(decl.srcLoc(), msg, "previously declared here", .{}); |
| 116 | | break :msg msg; |
| 117 | | }; |
| 118 | | return mod.failWithOwnedErrorMsg(scope, msg); |
| 119 | | } |
| 120 | | |
| 121 | | // when implementing this be sure to add test coverage for the asm return type |
| 122 | | // not resolving into a type (the node_offset_asm_ret_ty field of LazySrcLoc) |
| 123 | | |
| 124 | 58 | pub fn analyzeNamespace( |
| 125 | 59 | mod: *Module, |
| 126 | 60 | namespace: *Scope.Namespace, |