| ... | ... | @@ -253,17 +253,12 @@ fn transDecl(c: *Context, scope: *Scope, decl: NodeIndex) !void { |
| 253 | 253 | .struct_decl_two, |
| 254 | 254 | .union_decl_two, |
| 255 | 255 | => { |
| 256 | | var fields = [2]NodeIndex{ data.bin.lhs, data.bin.rhs }; |
| 257 | | var field_count: u2 = 0; |
| 258 | | if (fields[0] != .none) field_count += 1; |
| 259 | | if (fields[1] != .none) field_count += 1; |
| 260 | | try transRecordDecl(c, scope, decl, fields[0..field_count]); |
| 256 | try transRecordDecl(c, scope, node_ty[@intFromEnum(decl)]); |
| 261 | 257 | }, |
| 262 | 258 | .struct_decl, |
| 263 | 259 | .union_decl, |
| 264 | 260 | => { |
| 265 | | const fields = c.tree.data[data.range.start..data.range.end]; |
| 266 | | try transRecordDecl(c, scope, decl, fields); |
| 261 | try transRecordDecl(c, scope, node_ty[@intFromEnum(decl)]); |
| 267 | 262 | }, |
| 268 | 263 | |
| 269 | 264 | .enum_decl_two => { |
| ... | ... | @@ -333,16 +328,14 @@ fn mangleWeakGlobalName(c: *Context, want_name: []const u8) ![]const u8 { |
| 333 | 328 | return cur_name; |
| 334 | 329 | } |
| 335 | 330 | |
| 336 | | fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nodes: []const NodeIndex) Error!void { |
| 337 | | const node_types = c.tree.nodes.items(.ty); |
| 338 | | const raw_record_ty = node_types[@intFromEnum(record_node)]; |
| 339 | | const record_decl = raw_record_ty.getRecord().?; |
| 331 | fn transRecordDecl(c: *Context, scope: *Scope, record_ty: Type) Error!void { |
| 332 | const record_decl = record_ty.getRecord().?; |
| 340 | 333 | if (c.decl_table.get(@intFromPtr(record_decl))) |_| |
| 341 | 334 | return; // Avoid processing this decl twice |
| 342 | 335 | const toplevel = scope.id == .root; |
| 343 | 336 | const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined; |
| 344 | 337 | |
| 345 | | const container_kind: ZigTag = if (raw_record_ty.is(.@"union")) .@"union" else .@"struct"; |
| 338 | const container_kind: ZigTag = if (record_ty.is(.@"union")) .@"union" else .@"struct"; |
| 346 | 339 | const container_kind_name: []const u8 = @tagName(container_kind); |
| 347 | 340 | |
| 348 | 341 | var is_unnamed = false; |
| ... | ... | @@ -353,7 +346,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nod |
| 353 | 346 | bare_name = typedef_name; |
| 354 | 347 | name = typedef_name; |
| 355 | 348 | } else { |
| 356 | | if (raw_record_ty.isAnonymousRecord(c.comp)) { |
| 349 | if (record_ty.isAnonymousRecord(c.comp)) { |
| 357 | 350 | bare_name = try std.fmt.allocPrint(c.arena, "unnamed_{d}", .{c.getMangle()}); |
| 358 | 351 | is_unnamed = true; |
| 359 | 352 | } |
| ... | ... | @@ -380,17 +373,10 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nod |
| 380 | 373 | // layout, then we can just use a simple `extern` type. If it does have attributes, |
| 381 | 374 | // then we need to inspect the layout and assign an `align` value for each field. |
| 382 | 375 | const has_alignment_attributes = record_decl.field_attributes != null or |
| 383 | | raw_record_ty.hasAttribute(.@"packed") or |
| 384 | | raw_record_ty.hasAttribute(.aligned); |
| 376 | record_ty.hasAttribute(.@"packed") or |
| 377 | record_ty.hasAttribute(.aligned); |
| 385 | 378 | const head_field_alignment: ?c_uint = if (has_alignment_attributes) headFieldAlignment(record_decl) else null; |
| 386 | 379 | |
| 387 | | // Iterate over field nodes so that we translate any type decls included in this record decl. |
| 388 | | // TODO: Move this logic into `fn transType()` instead of handling decl translation here. |
| 389 | | for (field_nodes) |field_node| { |
| 390 | | const field_raw_ty = node_types[@intFromEnum(field_node)]; |
| 391 | | if (field_raw_ty.isEnumOrRecord()) try transDecl(c, scope, field_node); |
| 392 | | } |
| 393 | | |
| 394 | 380 | for (record_decl.fields, 0..) |field, field_index| { |
| 395 | 381 | const field_loc = field.name_tok; |
| 396 | 382 | |
| ... | ... | @@ -742,6 +728,7 @@ fn transType(c: *Context, scope: *Scope, raw_ty: Type, qual_handling: Type.QualH |
| 742 | 728 | const name_id = c.mapper.lookup(record_decl.name); |
| 743 | 729 | if (c.weak_global_names.contains(name_id)) trans_scope = &c.global_scope.base; |
| 744 | 730 | } |
| 731 | try transRecordDecl(c, trans_scope, ty); |
| 745 | 732 | const name = c.decl_table.get(@intFromPtr(ty.data.record)).?; |
| 746 | 733 | return ZigTag.identifier.create(c.arena, name); |
| 747 | 734 | }, |