translate-c: use struct_init_one for empty struct initializer
This commit is contained in:
@@ -2048,29 +2048,38 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
|
||||
}
|
||||
_ = try c.addToken(.r_brace, "}");
|
||||
|
||||
if (payload.inits.len < 2) {
|
||||
return c.addNode(.{
|
||||
return switch (payload.inits.len) {
|
||||
0 => c.addNode(.{
|
||||
.tag = .struct_init_one,
|
||||
.main_token = l_brace,
|
||||
.data = .{
|
||||
.lhs = lhs,
|
||||
.rhs = 0,
|
||||
},
|
||||
}),
|
||||
1 => c.addNode(.{
|
||||
.tag = .struct_init_one_comma,
|
||||
.main_token = l_brace,
|
||||
.data = .{
|
||||
.lhs = lhs,
|
||||
.rhs = inits[0],
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const span = try c.listToSpan(inits);
|
||||
return c.addNode(.{
|
||||
.tag = .struct_init_comma,
|
||||
.main_token = l_brace,
|
||||
.data = .{
|
||||
.lhs = lhs,
|
||||
.rhs = try c.addExtra(NodeSubRange{
|
||||
.start = span.start,
|
||||
.end = span.end,
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
}),
|
||||
else => blk: {
|
||||
const span = try c.listToSpan(inits);
|
||||
break :blk c.addNode(.{
|
||||
.tag = .struct_init_comma,
|
||||
.main_token = l_brace,
|
||||
.data = .{
|
||||
.lhs = lhs,
|
||||
.rhs = try c.addExtra(NodeSubRange{
|
||||
.start = span.start,
|
||||
.end = span.end,
|
||||
}),
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
.@"anytype" => unreachable, // Handled in renderParams
|
||||
}
|
||||
|
||||
17
test/cases/translate_c/static empty struct.c
Normal file
17
test/cases/translate_c/static empty struct.c
Normal file
@@ -0,0 +1,17 @@
|
||||
struct empty_struct {};
|
||||
|
||||
static inline void foo() {
|
||||
static struct empty_struct bar = {};
|
||||
}
|
||||
|
||||
// translate-c
|
||||
// target=x86_64-linux
|
||||
// c_frontend=clang
|
||||
//
|
||||
// pub const struct_empty_struct = extern struct {};
|
||||
// pub fn foo() callconv(.C) void {
|
||||
// const bar = struct {
|
||||
// var static: struct_empty_struct = struct_empty_struct{};
|
||||
// };
|
||||
// _ = &bar;
|
||||
// }
|
||||
@@ -976,7 +976,7 @@ const TestManifest = struct {
|
||||
|
||||
fn next(self: *TrailingIterator) ?[]const u8 {
|
||||
const next_inner = self.inner.next() orelse return null;
|
||||
return std.mem.trim(u8, next_inner[2..], " \t");
|
||||
return if (next_inner.len == 2) "" else std.mem.trimRight(u8, next_inner[3..], " \t");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user