aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorCody Tapscott <cody+topolarity@tapscott.me>2022-01-24 12:47:03 -0700
committerCody Tapscott <cody+topolarity@tapscott.me>2022-01-24 12:49:14 -0700
commit60e6bf112cf00e96818209cafd36b98546cc4d8b (patch)
tree68f7d007711c77e29cd6bfd748afcfd1e48630de /src/codegen/c.zig
parentcb24799368c3b944f18aae3c030a070038f3de9b (diff)
downloadzig-60e6bf112cf00e96818209cafd36b98546cc4d8b.tar.gz
zig-60e6bf112cf00e96818209cafd36b98546cc4d8b.zip
Cleanup unnecessary switches in union logic
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index d0132734a8..5a13ea7914 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -591,6 +591,7 @@ pub const DeclGen = struct {
},
.Union => {
const union_obj = val.castTag(.@"union").?.data;
+ const union_ty = ty.cast(Type.Payload.Union).?.data;
const target = dg.module.getTarget();
const layout = ty.unionGetLayout(target);
@@ -607,11 +608,7 @@ pub const DeclGen = struct {
try writer.writeAll(".payload = {");
}
- const index = switch (ty.tag()) {
- .union_tagged => ty.castTag(.union_tagged).?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?,
- .@"union" => ty.castTag(.@"union").?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?,
- else => unreachable,
- };
+ const index = union_ty.tag_ty.enumTagFieldIndex(union_obj.tag).?;
const field_ty = ty.unionFields().values()[index].ty;
const field_name = ty.unionFields().keys()[index];
if (field_ty.hasCodeGenBits()) {
@@ -815,11 +812,8 @@ pub const DeclGen = struct {
}
fn renderUnionTypedef(dg: *DeclGen, t: Type) error{ OutOfMemory, AnalysisFail }![]const u8 {
- const fqn = switch (t.tag()) {
- .@"union" => try t.castTag(.@"union").?.data.getFullyQualifiedName(dg.typedefs.allocator),
- .union_tagged => try t.castTag(.union_tagged).?.data.getFullyQualifiedName(dg.typedefs.allocator),
- else => unreachable,
- };
+ const union_ty = t.cast(Type.Payload.Union).?.data;
+ const fqn = try union_ty.getFullyQualifiedName(dg.typedefs.allocator);
defer dg.typedefs.allocator.free(fqn);
const target = dg.module.getTarget();