From fc9430f56798a53f9393a697f4ccd6bf9981b970 Mon Sep 17 00:00:00 2001 From: Martin Wickham Date: Thu, 3 Jun 2021 15:39:26 -0500 Subject: Breaking hash map changes for 0.8.0 - hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig --- src/codegen/c.zig | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/codegen/c.zig') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 55c9c5b641..68b74d7659 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -39,7 +39,7 @@ const BlockData = struct { }; pub const CValueMap = std.AutoHashMap(*Inst, CValue); -pub const TypedefMap = std.HashMap(Type, struct { name: []const u8, rendered: []u8 }, Type.hash, Type.eql, std.hash_map.default_max_load_percentage); +pub const TypedefMap = std.HashMap(Type, struct { name: []const u8, rendered: []u8 }, Type.HashContext, std.hash_map.default_max_load_percentage); fn formatTypeAsCIdentifier( data: Type, @@ -309,7 +309,7 @@ pub const DeclGen = struct { .enum_full, .enum_nonexhaustive => { const enum_full = t.cast(Type.Payload.EnumFull).?.data; if (enum_full.values.count() != 0) { - const tag_val = enum_full.values.entries.items[field_index].key; + const tag_val = enum_full.values.keys()[field_index]; return dg.renderValue(writer, enum_full.tag_ty, tag_val); } else { return writer.print("{d}", .{field_index}); @@ -493,10 +493,13 @@ pub const DeclGen = struct { defer buffer.deinit(); try buffer.appendSlice("typedef struct {\n"); - for (struct_obj.fields.entries.items) |entry| { - try buffer.append(' '); - try dg.renderType(buffer.writer(), entry.value.ty); - try buffer.writer().print(" {s};\n", .{fmtIdent(entry.key)}); + { + var it = struct_obj.fields.iterator(); + while (it.next()) |entry| { + try buffer.append(' '); + try dg.renderType(buffer.writer(), entry.value_ptr.ty); + try buffer.writer().print(" {s};\n", .{fmtIdent(entry.key_ptr.*)}); + } } try buffer.appendSlice("} "); @@ -1186,7 +1189,7 @@ fn genStructFieldPtr(o: *Object, inst: *Inst.StructFieldPtr) !CValue { const writer = o.writer(); const struct_ptr = try o.resolveInst(inst.struct_ptr); const struct_obj = inst.struct_ptr.ty.elemType().castTag(.@"struct").?.data; - const field_name = struct_obj.fields.entries.items[inst.field_index].key; + const field_name = struct_obj.fields.keys()[inst.field_index]; const local = try o.allocLocal(inst.base.ty, .Const); switch (struct_ptr) { -- cgit v1.2.3