authorgravatar for cody+topolarity@tapscott.meCody Tapscott <cody+topolarity@tapscott.me> 2022-01-24 12:47:03-07:00
committergravatar for cody+topolarity@tapscott.meCody Tapscott <cody+topolarity@tapscott.me> 2022-01-24 12:49:14-07:00
log60e6bf112cf00e96818209cafd36b98546cc4d8b
tree68f7d007711c77e29cd6bfd748afcfd1e48630de
parentcb24799368c3b944f18aae3c030a070038f3de9b

Cleanup unnecessary switches in union logic


1 files changed, 4 insertions(+), 10 deletions(-)

src/codegen/c.zig+4-10
...@@ -591,6 +591,7 @@ pub const DeclGen = struct {...@@ -591,6 +591,7 @@ pub const DeclGen = struct {
591 },591 },
592 .Union => {592 .Union => {
593 const union_obj = val.castTag(.@"union").?.data;593 const union_obj = val.castTag(.@"union").?.data;
594 const union_ty = ty.cast(Type.Payload.Union).?.data;
594 const target = dg.module.getTarget();595 const target = dg.module.getTarget();
595 const layout = ty.unionGetLayout(target);596 const layout = ty.unionGetLayout(target);
596597
...@@ -607,11 +608,7 @@ pub const DeclGen = struct {...@@ -607,11 +608,7 @@ pub const DeclGen = struct {
607 try writer.writeAll(".payload = {");608 try writer.writeAll(".payload = {");
608 }609 }
609610
610 const index = switch (ty.tag()) {611 const index = union_ty.tag_ty.enumTagFieldIndex(union_obj.tag).?;
611 .union_tagged => ty.castTag(.union_tagged).?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?,
612 .@"union" => ty.castTag(.@"union").?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?,
613 else => unreachable,
614 };
615 const field_ty = ty.unionFields().values()[index].ty;612 const field_ty = ty.unionFields().values()[index].ty;
616 const field_name = ty.unionFields().keys()[index];613 const field_name = ty.unionFields().keys()[index];
617 if (field_ty.hasCodeGenBits()) {614 if (field_ty.hasCodeGenBits()) {
...@@ -815,11 +812,8 @@ pub const DeclGen = struct {...@@ -815,11 +812,8 @@ pub const DeclGen = struct {
815 }812 }
816813
817 fn renderUnionTypedef(dg: *DeclGen, t: Type) error{ OutOfMemory, AnalysisFail }![]const u8 {814 fn renderUnionTypedef(dg: *DeclGen, t: Type) error{ OutOfMemory, AnalysisFail }![]const u8 {
818 const fqn = switch (t.tag()) {815 const union_ty = t.cast(Type.Payload.Union).?.data;
819 .@"union" => try t.castTag(.@"union").?.data.getFullyQualifiedName(dg.typedefs.allocator),816 const fqn = try union_ty.getFullyQualifiedName(dg.typedefs.allocator);
820 .union_tagged => try t.castTag(.union_tagged).?.data.getFullyQualifiedName(dg.typedefs.allocator),
821 else => unreachable,
822 };
823 defer dg.typedefs.allocator.free(fqn);817 defer dg.typedefs.allocator.free(fqn);
824818
825 const target = dg.module.getTarget();819 const target = dg.module.getTarget();