authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-04 01:31:29+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-05 21:11:42+00:00
log632acffcbd96a085ea92899e6f37465e40178f44
tree77b4af87060b43172eefb66943564faed365ec84
parentb3b6ccba50ef7a683ad05546cba2b71e7d10489f

update std lib to new hash map API


8 files changed, 111 insertions(+), 108 deletions(-)

lib/std/buf_map.zig+7-8
......@@ -33,10 +33,10 @@ pub const BufMap = struct {
3333 pub fn setMove(self: *BufMap, key: []u8, value: []u8) !void {
3434 const get_or_put = try self.hash_map.getOrPut(key);
3535 if (get_or_put.found_existing) {
36 self.free(get_or_put.kv.key);
37 get_or_put.kv.key = key;
36 self.free(get_or_put.entry.key);
37 get_or_put.entry.key = key;
3838 }
39 get_or_put.kv.value = value;
39 get_or_put.entry.value = value;
4040 }
4141
4242 /// `key` and `value` are copied into the BufMap.
......@@ -45,19 +45,18 @@ pub const BufMap = struct {
4545 errdefer self.free(value_copy);
4646 const get_or_put = try self.hash_map.getOrPut(key);
4747 if (get_or_put.found_existing) {
48 self.free(get_or_put.kv.value);
48 self.free(get_or_put.entry.value);
4949 } else {
50 get_or_put.kv.key = self.copy(key) catch |err| {
50 get_or_put.entry.key = self.copy(key) catch |err| {
5151 _ = self.hash_map.remove(key);
5252 return err;
5353 };
5454 }
55 get_or_put.kv.value = value_copy;
55 get_or_put.entry.value = value_copy;
5656 }
5757
5858 pub fn get(self: BufMap, key: []const u8) ?[]const u8 {
59 const entry = self.hash_map.get(key) orelse return null;
60 return entry.value;
59 return self.hash_map.get(key);
6160 }
6261
6362 pub fn delete(self: *BufMap, key: []const u8) void {
lib/std/buf_set.zig+3-5
......@@ -14,14 +14,12 @@ pub const BufSet = struct {
1414 return self;
1515 }
1616
17 pub fn deinit(self: *const BufSet) void {
18 var it = self.hash_map.iterator();
19 while (true) {
20 const entry = it.next() orelse break;
17 pub fn deinit(self: *BufSet) void {
18 for (self.hash_map.items()) |entry| {
2119 self.free(entry.key);
2220 }
23
2421 self.hash_map.deinit();
22 self.* = undefined;
2523 }
2624
2725 pub fn put(self: *BufSet, key: []const u8) !void {
lib/std/build.zig+6-6
......@@ -422,12 +422,12 @@ pub const Builder = struct {
422422 .type_id = type_id,
423423 .description = description,
424424 };
425 if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {
425 if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) {
426426 panic("Option '{}' declared twice", .{name});
427427 }
428428 self.available_options_list.append(available_option) catch unreachable;
429429
430 const entry = self.user_input_options.get(name) orelse return null;
430 const entry = self.user_input_options.getEntry(name) orelse return null;
431431 entry.value.used = true;
432432 switch (type_id) {
433433 TypeId.Bool => switch (entry.value.value) {
......@@ -634,7 +634,7 @@ pub const Builder = struct {
634634 pub fn addUserInputOption(self: *Builder, name: []const u8, value: []const u8) !bool {
635635 const gop = try self.user_input_options.getOrPut(name);
636636 if (!gop.found_existing) {
637 gop.kv.value = UserInputOption{
637 gop.entry.value = UserInputOption{
638638 .name = name,
639639 .value = UserValue{ .Scalar = value },
640640 .used = false,
......@@ -643,7 +643,7 @@ pub const Builder = struct {
643643 }
644644
645645 // option already exists
646 switch (gop.kv.value.value) {
646 switch (gop.entry.value.value) {
647647 UserValue.Scalar => |s| {
648648 // turn it into a list
649649 var list = ArrayList([]const u8).init(self.allocator);
......@@ -675,7 +675,7 @@ pub const Builder = struct {
675675 pub fn addUserInputFlag(self: *Builder, name: []const u8) !bool {
676676 const gop = try self.user_input_options.getOrPut(name);
677677 if (!gop.found_existing) {
678 gop.kv.value = UserInputOption{
678 gop.entry.value = UserInputOption{
679679 .name = name,
680680 .value = UserValue{ .Flag = {} },
681681 .used = false,
......@@ -684,7 +684,7 @@ pub const Builder = struct {
684684 }
685685
686686 // option already exists
687 switch (gop.kv.value.value) {
687 switch (gop.entry.value.value) {
688688 UserValue.Scalar => |s| {
689689 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s });
690690 return true;
lib/std/hash_map.zig+17-8
......@@ -293,18 +293,22 @@ pub fn HashMapUnmanaged(
293293
294294 pub fn clearRetainingCapacity(self: *Self) void {
295295 self.entries.items.len = 0;
296 if (self.header) |header| {
296 if (self.index_header) |header| {
297297 header.max_distance_from_start_index = 0;
298 const indexes = header.indexes(u8);
299 @memset(indexes.ptr, 0xff, indexes.len);
298 switch (header.capacityIndexType()) {
299 .u8 => mem.set(Index(u8), header.indexes(u8), Index(u8).empty),
300 .u16 => mem.set(Index(u16), header.indexes(u16), Index(u16).empty),
301 .u32 => mem.set(Index(u32), header.indexes(u32), Index(u32).empty),
302 .usize => mem.set(Index(usize), header.indexes(usize), Index(usize).empty),
303 }
300304 }
301305 }
302306
303307 pub fn clearAndFree(self: *Self, allocator: *Allocator) void {
304308 self.entries.shrink(allocator, 0);
305 if (self.header) |header| {
309 if (self.index_header) |header| {
306310 header.free(allocator);
307 self.header = null;
311 self.index_header = null;
308312 }
309313 }
310314
......@@ -378,13 +382,13 @@ pub fn HashMapUnmanaged(
378382 try self.entries.ensureCapacity(allocator, new_capacity);
379383 if (new_capacity <= linear_scan_max) return;
380384
381 // Resize if indexes would be more than 75% full.
382 const needed_len = new_capacity * 4 / 3;
385 // Resize if indexes would be more than 60% full.
386 const needed_len = new_capacity * 5 / 3;
383387 if (self.index_header) |header| {
384388 if (needed_len > header.indexes_len) {
385389 var new_indexes_len = header.indexes_len;
386390 while (true) {
387 new_indexes_len += new_indexes_len / 2 + 8;
391 new_indexes_len *= new_indexes_len / 2 + 8;
388392 if (new_indexes_len >= needed_len) break;
389393 }
390394 const new_header = try IndexHeader.alloc(allocator, new_indexes_len);
......@@ -789,6 +793,11 @@ fn Index(comptime I: type) type {
789793
790794 const Self = @This();
791795
796 const empty = Self{
797 .entry_index = math.maxInt(I),
798 .distance_from_start_index = undefined,
799 };
800
792801 fn isEmpty(idx: Self) bool {
793802 return idx.entry_index == math.maxInt(I);
794803 }
lib/std/http/headers.zig+35-37
......@@ -118,13 +118,12 @@ pub const Headers = struct {
118118 };
119119 }
120120
121 pub fn deinit(self: Self) void {
121 pub fn deinit(self: *Self) void {
122122 {
123 var it = self.index.iterator();
124 while (it.next()) |kv| {
125 var dex = &kv.value;
123 for (self.index.items()) |*entry| {
124 const dex = &entry.value;
126125 dex.deinit();
127 self.allocator.free(kv.key);
126 self.allocator.free(entry.key);
128127 }
129128 self.index.deinit();
130129 }
......@@ -134,6 +133,7 @@ pub const Headers = struct {
134133 }
135134 self.data.deinit();
136135 }
136 self.* = undefined;
137137 }
138138
139139 pub fn clone(self: Self, allocator: *Allocator) !Self {
......@@ -155,10 +155,10 @@ pub const Headers = struct {
155155 const n = self.data.items.len + 1;
156156 try self.data.ensureCapacity(n);
157157 var entry: HeaderEntry = undefined;
158 if (self.index.get(name)) |kv| {
158 if (self.index.getEntry(name)) |kv| {
159159 entry = try HeaderEntry.init(self.allocator, kv.key, value, never_index);
160160 errdefer entry.deinit();
161 var dex = &kv.value;
161 const dex = &kv.value;
162162 try dex.append(n - 1);
163163 } else {
164164 const name_dup = try mem.dupe(self.allocator, u8, name);
......@@ -195,7 +195,7 @@ pub const Headers = struct {
195195 /// Returns boolean indicating if something was deleted.
196196 pub fn delete(self: *Self, name: []const u8) bool {
197197 if (self.index.remove(name)) |kv| {
198 var dex = &kv.value;
198 const dex = &kv.value;
199199 // iterate backwards
200200 var i = dex.items.len;
201201 while (i > 0) {
......@@ -207,7 +207,7 @@ pub const Headers = struct {
207207 }
208208 dex.deinit();
209209 self.allocator.free(kv.key);
210 self.rebuild_index();
210 self.rebuildIndex();
211211 return true;
212212 } else {
213213 return false;
......@@ -216,45 +216,52 @@ pub const Headers = struct {
216216
217217 /// Removes the element at the specified index.
218218 /// Moves items down to fill the empty space.
219 /// TODO this implementation can be replaced by adding
220 /// orderedRemove to the new hash table implementation as an
221 /// alternative to swapRemove.
219222 pub fn orderedRemove(self: *Self, i: usize) void {
220223 const removed = self.data.orderedRemove(i);
221 const kv = self.index.get(removed.name).?;
222 var dex = &kv.value;
224 const kv = self.index.getEntry(removed.name).?;
225 const dex = &kv.value;
223226 if (dex.items.len == 1) {
224227 // was last item; delete the index
225 _ = self.index.remove(kv.key);
226228 dex.deinit();
227229 removed.deinit();
228 self.allocator.free(kv.key);
230 const key = kv.key;
231 _ = self.index.remove(key); // invalidates `kv` and `dex`
232 self.allocator.free(key);
229233 } else {
230234 dex.shrink(dex.items.len - 1);
231235 removed.deinit();
232236 }
233237 // if it was the last item; no need to rebuild index
234238 if (i != self.data.items.len) {
235 self.rebuild_index();
239 self.rebuildIndex();
236240 }
237241 }
238242
239243 /// Removes the element at the specified index.
240244 /// The empty slot is filled from the end of the list.
245 /// TODO this implementation can be replaced by simply using the
246 /// new hash table which does swap removal.
241247 pub fn swapRemove(self: *Self, i: usize) void {
242248 const removed = self.data.swapRemove(i);
243 const kv = self.index.get(removed.name).?;
244 var dex = &kv.value;
249 const kv = self.index.getEntry(removed.name).?;
250 const dex = &kv.value;
245251 if (dex.items.len == 1) {
246252 // was last item; delete the index
247 _ = self.index.remove(kv.key);
248253 dex.deinit();
249254 removed.deinit();
250 self.allocator.free(kv.key);
255 const key = kv.key;
256 _ = self.index.remove(key); // invalidates `kv` and `dex`
257 self.allocator.free(key);
251258 } else {
252259 dex.shrink(dex.items.len - 1);
253260 removed.deinit();
254261 }
255262 // if it was the last item; no need to rebuild index
256263 if (i != self.data.items.len) {
257 self.rebuild_index();
264 self.rebuildIndex();
258265 }
259266 }
260267
......@@ -266,11 +273,7 @@ pub const Headers = struct {
266273 /// Returns a list of indices containing headers with the given name.
267274 /// The returned list should not be modified by the caller.
268275 pub fn getIndices(self: Self, name: []const u8) ?HeaderIndexList {
269 if (self.index.get(name)) |kv| {
270 return kv.value;
271 } else {
272 return null;
273 }
276 return self.index.get(name);
274277 }
275278
276279 /// Returns a slice containing each header with the given name.
......@@ -325,25 +328,20 @@ pub const Headers = struct {
325328 return buf;
326329 }
327330
328 fn rebuild_index(self: *Self) void {
329 { // clear out the indexes
330 var it = self.index.iterator();
331 while (it.next()) |kv| {
332 var dex = &kv.value;
333 dex.items.len = 0; // keeps capacity available
334 }
331 fn rebuildIndex(self: *Self) void {
332 // clear out the indexes
333 for (self.index.items()) |*entry| {
334 entry.value.shrinkRetainingCapacity(0);
335335 }
336 { // fill up indexes again; we know capacity is fine from before
337 for (self.data.span()) |entry, i| {
338 var dex = &self.index.get(entry.name).?.value;
339 dex.appendAssumeCapacity(i);
340 }
336 // fill up indexes again; we know capacity is fine from before
337 for (self.data.items) |entry, i| {
338 self.index.getEntry(entry.name).?.value.appendAssumeCapacity(i);
341339 }
342340 }
343341
344342 pub fn sort(self: *Self) void {
345343 std.sort.sort(HeaderEntry, self.data.items, {}, HeaderEntry.compare);
346 self.rebuild_index();
344 self.rebuildIndex();
347345 }
348346
349347 pub fn format(
lib/std/json.zig+28-28
......@@ -2149,27 +2149,27 @@ test "json.parser.dynamic" {
21492149
21502150 var root = tree.root;
21512151
2152 var image = root.Object.get("Image").?.value;
2152 var image = root.Object.get("Image").?;
21532153
2154 const width = image.Object.get("Width").?.value;
2154 const width = image.Object.get("Width").?;
21552155 testing.expect(width.Integer == 800);
21562156
2157 const height = image.Object.get("Height").?.value;
2157 const height = image.Object.get("Height").?;
21582158 testing.expect(height.Integer == 600);
21592159
2160 const title = image.Object.get("Title").?.value;
2160 const title = image.Object.get("Title").?;
21612161 testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
21622162
2163 const animated = image.Object.get("Animated").?.value;
2163 const animated = image.Object.get("Animated").?;
21642164 testing.expect(animated.Bool == false);
21652165
2166 const array_of_object = image.Object.get("ArrayOfObject").?.value;
2166 const array_of_object = image.Object.get("ArrayOfObject").?;
21672167 testing.expect(array_of_object.Array.items.len == 1);
21682168
2169 const obj0 = array_of_object.Array.items[0].Object.get("n").?.value;
2169 const obj0 = array_of_object.Array.items[0].Object.get("n").?;
21702170 testing.expect(mem.eql(u8, obj0.String, "m"));
21712171
2172 const double = image.Object.get("double").?.value;
2172 const double = image.Object.get("double").?;
21732173 testing.expect(double.Float == 1.3412);
21742174}
21752175
......@@ -2217,12 +2217,12 @@ test "write json then parse it" {
22172217 var tree = try parser.parse(fixed_buffer_stream.getWritten());
22182218 defer tree.deinit();
22192219
2220 testing.expect(tree.root.Object.get("f").?.value.Bool == false);
2221 testing.expect(tree.root.Object.get("t").?.value.Bool == true);
2222 testing.expect(tree.root.Object.get("int").?.value.Integer == 1234);
2223 testing.expect(tree.root.Object.get("array").?.value.Array.items[0].Null == {});
2224 testing.expect(tree.root.Object.get("array").?.value.Array.items[1].Float == 12.34);
2225 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.value.String, "hello"));
2220 testing.expect(tree.root.Object.get("f").?.Bool == false);
2221 testing.expect(tree.root.Object.get("t").?.Bool == true);
2222 testing.expect(tree.root.Object.get("int").?.Integer == 1234);
2223 testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
2224 testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
2225 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
22262226}
22272227
22282228fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {
......@@ -2245,7 +2245,7 @@ test "integer after float has proper type" {
22452245 \\ "ints": [1, 2, 3]
22462246 \\}
22472247 );
2248 std.testing.expect(json.Object.getValue("ints").?.Array.items[0] == .Integer);
2248 std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
22492249}
22502250
22512251test "escaped characters" {
......@@ -2271,16 +2271,16 @@ test "escaped characters" {
22712271
22722272 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
22732273
2274 testing.expectEqualSlices(u8, obj.get("backslash").?.value.String, "\\");
2275 testing.expectEqualSlices(u8, obj.get("forwardslash").?.value.String, "/");
2276 testing.expectEqualSlices(u8, obj.get("newline").?.value.String, "\n");
2277 testing.expectEqualSlices(u8, obj.get("carriagereturn").?.value.String, "\r");
2278 testing.expectEqualSlices(u8, obj.get("tab").?.value.String, "\t");
2279 testing.expectEqualSlices(u8, obj.get("formfeed").?.value.String, "\x0C");
2280 testing.expectEqualSlices(u8, obj.get("backspace").?.value.String, "\x08");
2281 testing.expectEqualSlices(u8, obj.get("doublequote").?.value.String, "\"");
2282 testing.expectEqualSlices(u8, obj.get("unicode").?.value.String, "ą");
2283 testing.expectEqualSlices(u8, obj.get("surrogatepair").?.value.String, "😂");
2274 testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
2275 testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
2276 testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
2277 testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
2278 testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
2279 testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
2280 testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
2281 testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
2282 testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
2283 testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
22842284}
22852285
22862286test "string copy option" {
......@@ -2306,11 +2306,11 @@ test "string copy option" {
23062306 const obj_copy = tree_copy.root.Object;
23072307
23082308 for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {
2309 testing.expectEqualSlices(u8, obj_nocopy.getValue(field_name).?.String, obj_copy.getValue(field_name).?.String);
2309 testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
23102310 }
23112311
2312 const nocopy_addr = &obj_nocopy.getValue("noescape").?.String[0];
2313 const copy_addr = &obj_copy.getValue("noescape").?.String[0];
2312 const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
2313 const copy_addr = &obj_copy.get("noescape").?.String[0];
23142314
23152315 var found_nocopy = false;
23162316 for (input) |_, index| {
src-self-hosted/main.zig+2-2
......@@ -720,7 +720,7 @@ fn fmtPathDir(
720720 defer dir.close();
721721
722722 const stat = try dir.stat();
723 if (try fmt.seen.put(stat.inode, {})) |_| return;
723 if (try fmt.seen.fetchPut(stat.inode, {})) |_| return;
724724
725725 var dir_it = dir.iterate();
726726 while (try dir_it.next()) |entry| {
......@@ -768,7 +768,7 @@ fn fmtPathFile(
768768 defer fmt.gpa.free(source_code);
769769
770770 // Add to set after no longer possible to get error.IsDir.
771 if (try fmt.seen.put(stat.inode, {})) |_| return;
771 if (try fmt.seen.fetchPut(stat.inode, {})) |_| return;
772772
773773 const tree = try std.zig.parse(fmt.gpa, source_code);
774774 defer tree.deinit();
src-self-hosted/translate_c.zig+13-14
......@@ -20,7 +20,7 @@ pub const Error = error{OutOfMemory};
2020const TypeError = Error || error{UnsupportedType};
2121const TransError = TypeError || error{UnsupportedTranslation};
2222
23const DeclTable = std.HashMap(usize, []const u8, addrHash, addrEql);
23const DeclTable = std.HashMap(usize, []const u8, addrHash, addrEql, false);
2424
2525fn addrHash(x: usize) u32 {
2626 switch (@typeInfo(usize).Int.bits) {
......@@ -776,8 +776,8 @@ fn checkForBuiltinTypedef(checked_name: []const u8) ?[]const u8 {
776776}
777777
778778fn transTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, top_level_visit: bool) Error!?*ast.Node {
779 if (c.decl_table.get(@ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)))) |kv|
780 return transCreateNodeIdentifier(c, kv.value); // Avoid processing this decl twice
779 if (c.decl_table.get(@ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)))) |name|
780 return transCreateNodeIdentifier(c, name); // Avoid processing this decl twice
781781 const rp = makeRestorePoint(c);
782782
783783 const typedef_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, typedef_decl)));
......@@ -818,8 +818,8 @@ fn transCreateNodeTypedef(rp: RestorePoint, typedef_decl: *const ZigClangTypedef
818818}
819819
820820fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?*ast.Node {
821 if (c.decl_table.get(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)))) |kv|
822 return try transCreateNodeIdentifier(c, kv.value); // Avoid processing this decl twice
821 if (c.decl_table.get(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)))) |name|
822 return try transCreateNodeIdentifier(c, name); // Avoid processing this decl twice
823823 const record_loc = ZigClangRecordDecl_getLocation(record_decl);
824824
825825 var bare_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, record_decl)));
......@@ -969,7 +969,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?*
969969
970970fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.Node {
971971 if (c.decl_table.get(@ptrToInt(ZigClangEnumDecl_getCanonicalDecl(enum_decl)))) |name|
972 return try transCreateNodeIdentifier(c, name.value); // Avoid processing this decl twice
972 return try transCreateNodeIdentifier(c, name); // Avoid processing this decl twice
973973 const rp = makeRestorePoint(c);
974974 const enum_loc = ZigClangEnumDecl_getLocation(enum_decl);
975975
......@@ -2130,7 +2130,7 @@ fn transInitListExprRecord(
21302130 var raw_name = try rp.c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, field_decl)));
21312131 if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl)) {
21322132 const name = rp.c.decl_table.get(@ptrToInt(ZigClangFieldDecl_getCanonicalDecl(field_decl))).?;
2133 raw_name = try mem.dupe(rp.c.arena, u8, name.value);
2133 raw_name = try mem.dupe(rp.c.arena, u8, name);
21342134 }
21352135 const field_name_tok = try appendIdentifier(rp.c, raw_name);
21362136
......@@ -2855,7 +2855,7 @@ fn transMemberExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangMemberE
28552855 const field_decl = @ptrCast(*const struct_ZigClangFieldDecl, member_decl);
28562856 if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl)) {
28572857 const name = rp.c.decl_table.get(@ptrToInt(ZigClangFieldDecl_getCanonicalDecl(field_decl))).?;
2858 break :blk try mem.dupe(rp.c.arena, u8, name.value);
2858 break :blk try mem.dupe(rp.c.arena, u8, name);
28592859 }
28602860 }
28612861 const decl = @ptrCast(*const ZigClangNamedDecl, member_decl);
......@@ -6040,8 +6040,8 @@ fn getContainer(c: *Context, node: *ast.Node) ?*ast.Node {
60406040 } else if (node.id == .PrefixOp) {
60416041 return node;
60426042 } else if (node.cast(ast.Node.Identifier)) |ident| {
6043 if (c.global_scope.sym_table.get(tokenSlice(c, ident.token))) |kv| {
6044 if (kv.value.cast(ast.Node.VarDecl)) |var_decl|
6043 if (c.global_scope.sym_table.get(tokenSlice(c, ident.token))) |value| {
6044 if (value.cast(ast.Node.VarDecl)) |var_decl|
60456045 return getContainer(c, var_decl.init_node.?);
60466046 }
60476047 } else if (node.cast(ast.Node.InfixOp)) |infix| {
......@@ -6064,8 +6064,8 @@ fn getContainer(c: *Context, node: *ast.Node) ?*ast.Node {
60646064
60656065fn getContainerTypeOf(c: *Context, ref: *ast.Node) ?*ast.Node {
60666066 if (ref.cast(ast.Node.Identifier)) |ident| {
6067 if (c.global_scope.sym_table.get(tokenSlice(c, ident.token))) |kv| {
6068 if (kv.value.cast(ast.Node.VarDecl)) |var_decl| {
6067 if (c.global_scope.sym_table.get(tokenSlice(c, ident.token))) |value| {
6068 if (value.cast(ast.Node.VarDecl)) |var_decl| {
60696069 if (var_decl.type_node) |ty|
60706070 return getContainer(c, ty);
60716071 }
......@@ -6104,8 +6104,7 @@ fn getFnProto(c: *Context, ref: *ast.Node) ?*ast.Node.FnProto {
61046104}
61056105
61066106fn addMacros(c: *Context) !void {
6107 var macro_it = c.global_scope.macro_table.iterator();
6108 while (macro_it.next()) |kv| {
6107 for (c.global_scope.macro_table.items()) |kv| {
61096108 if (getFnProto(c, kv.value)) |proto_node| {
61106109 // If a macro aliases a global variable which is a function pointer, we conclude that
61116110 // the macro is intended to represent a function that assumes the function pointer