| author | |
| committer | |
| log | 665eba93c1733f83614c443c19cd9a5f1be910df |
| tree | 79d9456c5841e54705591f1d37b66727fe4ee2d5 |
| parent | e6e459e9e36fcd84edca548d8c722fc1f81c07a4 |
C void is perfectly fine.3 files changed, 48 insertions(+), 35 deletions(-)
lib/zig.h-2| ... | ... | @@ -189,8 +189,6 @@ |
| 189 | 189 | |
| 190 | 190 | #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) |
| 191 | 191 | |
| 192 | typedef void zig_void; | |
| 193 | ||
| 194 | 192 | #if defined(__cplusplus) |
| 195 | 193 | typedef bool zig_bool; |
| 196 | 194 | #define zig_false false |
src/codegen/c.zig+37-22| ... | ... | @@ -1802,33 +1802,24 @@ pub const DeclGen = struct { |
| 1802 | 1802 | const target = dg.module.getTarget(); |
| 1803 | 1803 | |
| 1804 | 1804 | switch (t.zigTypeTag()) { |
| 1805 | .NoReturn, .Void, .Bool, .Int, .Float, .ErrorSet => |tag| { | |
| 1806 | const is_named = switch (tag) { | |
| 1807 | .Int => t.isNamedInt(), | |
| 1808 | .ErrorSet => false, | |
| 1809 | else => true, | |
| 1810 | }; | |
| 1811 | if (is_named) { | |
| 1805 | .Void => { | |
| 1806 | try w.writeAll("void"); | |
| 1807 | }, | |
| 1808 | .NoReturn, .Bool, .Float => { | |
| 1809 | try w.writeAll("zig_"); | |
| 1810 | try t.print(w, dg.module); | |
| 1811 | }, | |
| 1812 | .Int => { | |
| 1813 | if (t.isNamedInt()) { | |
| 1812 | 1814 | try w.writeAll("zig_"); |
| 1813 | 1815 | try t.print(w, dg.module); |
| 1814 | 1816 | } else { |
| 1815 | const int_info = t.intInfo(target); | |
| 1816 | if (toCIntBits(int_info.bits)) |c_bits| | |
| 1817 | return w.print("zig_{c}{d}", .{ signAbbrev(int_info.signedness), c_bits }) | |
| 1818 | else if (loweredArrayInfo(t, target)) |array_info| { | |
| 1819 | assert(array_info.sentinel == null); | |
| 1820 | var array_pl = Type.Payload.Array{ | |
| 1821 | .base = .{ .tag = .array }, | |
| 1822 | .data = .{ .len = array_info.len, .elem_type = array_info.elem_type }, | |
| 1823 | }; | |
| 1824 | const array_ty = Type.initPayload(&array_pl.base); | |
| 1825 | ||
| 1826 | return dg.renderType(w, array_ty, kind); | |
| 1827 | } else return dg.fail("C backend: Unable to lower unnamed integer type {}", .{ | |
| 1828 | t.fmt(dg.module), | |
| 1829 | }); | |
| 1817 | return renderTypeUnnamed(dg, w, t, kind); | |
| 1830 | 1818 | } |
| 1831 | 1819 | }, |
| 1820 | .ErrorSet => { | |
| 1821 | return renderTypeUnnamed(dg, w, t, kind); | |
| 1822 | }, | |
| 1832 | 1823 | .Pointer => { |
| 1833 | 1824 | const ptr_info = t.ptrInfo().data; |
| 1834 | 1825 | if (ptr_info.size == .Slice) { |
| ... | ... | @@ -2015,6 +2006,30 @@ pub const DeclGen = struct { |
| 2015 | 2006 | } |
| 2016 | 2007 | } |
| 2017 | 2008 | |
| 2009 | fn renderTypeUnnamed( | |
| 2010 | dg: *DeclGen, | |
| 2011 | w: anytype, | |
| 2012 | t: Type, | |
| 2013 | kind: TypedefKind, | |
| 2014 | ) error{ OutOfMemory, AnalysisFail }!void { | |
| 2015 | const target = dg.module.getTarget(); | |
| 2016 | const int_info = t.intInfo(target); | |
| 2017 | if (toCIntBits(int_info.bits)) |c_bits| | |
| 2018 | return w.print("zig_{c}{d}", .{ signAbbrev(int_info.signedness), c_bits }) | |
| 2019 | else if (loweredArrayInfo(t, target)) |array_info| { | |
| 2020 | assert(array_info.sentinel == null); | |
| 2021 | var array_pl = Type.Payload.Array{ | |
| 2022 | .base = .{ .tag = .array }, | |
| 2023 | .data = .{ .len = array_info.len, .elem_type = array_info.elem_type }, | |
| 2024 | }; | |
| 2025 | const array_ty = Type.initPayload(&array_pl.base); | |
| 2026 | ||
| 2027 | return dg.renderType(w, array_ty, kind); | |
| 2028 | } else return dg.fail("C backend: Unable to lower unnamed integer type {}", .{ | |
| 2029 | t.fmt(dg.module), | |
| 2030 | }); | |
| 2031 | } | |
| 2032 | ||
| 2018 | 2033 | /// Renders a type in C typecast format. |
| 2019 | 2034 | /// |
| 2020 | 2035 | /// This is guaranteed to be valid in a typecast expression, but not |
test/stage2/cbe.zig+11-11| ... | ... | @@ -951,7 +951,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 951 | 951 | ctx.h("simple header", linux_x64, |
| 952 | 952 | \\export fn start() void{} |
| 953 | 953 | , |
| 954 | \\zig_extern zig_void start(zig_void); | |
| 954 | \\zig_extern void start(void); | |
| 955 | 955 | \\ |
| 956 | 956 | ); |
| 957 | 957 | ctx.h("header with single param function", linux_x64, |
| ... | ... | @@ -959,7 +959,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 959 | 959 | \\ _ = a; |
| 960 | 960 | \\} |
| 961 | 961 | , |
| 962 | \\zig_extern zig_void start(zig_u8 const a0); | |
| 962 | \\zig_extern void start(zig_u8 const a0); | |
| 963 | 963 | \\ |
| 964 | 964 | ); |
| 965 | 965 | ctx.h("header with multiple param function", linux_x64, |
| ... | ... | @@ -967,25 +967,25 @@ pub fn addCases(ctx: *TestContext) !void { |
| 967 | 967 | \\ _ = a; _ = b; _ = c; |
| 968 | 968 | \\} |
| 969 | 969 | , |
| 970 | \\zig_extern zig_void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2); | |
| 970 | \\zig_extern void start(zig_u8 const a0, zig_u8 const a1, zig_u8 const a2); | |
| 971 | 971 | \\ |
| 972 | 972 | ); |
| 973 | 973 | ctx.h("header with u32 param function", linux_x64, |
| 974 | 974 | \\export fn start(a: u32) void{ _ = a; } |
| 975 | 975 | , |
| 976 | \\zig_extern zig_void start(zig_u32 const a0); | |
| 976 | \\zig_extern void start(zig_u32 const a0); | |
| 977 | 977 | \\ |
| 978 | 978 | ); |
| 979 | 979 | ctx.h("header with usize param function", linux_x64, |
| 980 | 980 | \\export fn start(a: usize) void{ _ = a; } |
| 981 | 981 | , |
| 982 | \\zig_extern zig_void start(zig_usize const a0); | |
| 982 | \\zig_extern void start(zig_usize const a0); | |
| 983 | 983 | \\ |
| 984 | 984 | ); |
| 985 | 985 | ctx.h("header with bool param function", linux_x64, |
| 986 | 986 | \\export fn start(a: bool) void{_ = a;} |
| 987 | 987 | , |
| 988 | \\zig_extern zig_void start(zig_bool const a0); | |
| 988 | \\zig_extern void start(zig_bool const a0); | |
| 989 | 989 | \\ |
| 990 | 990 | ); |
| 991 | 991 | ctx.h("header with noreturn function", linux_x64, |
| ... | ... | @@ -993,7 +993,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 993 | 993 | \\ unreachable; |
| 994 | 994 | \\} |
| 995 | 995 | , |
| 996 | \\zig_extern zig_noreturn start(zig_void); | |
| 996 | \\zig_extern zig_noreturn start(void); | |
| 997 | 997 | \\ |
| 998 | 998 | ); |
| 999 | 999 | ctx.h("header with multiple functions", linux_x64, |
| ... | ... | @@ -1001,15 +1001,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1001 | 1001 | \\export fn b() void{} |
| 1002 | 1002 | \\export fn c() void{} |
| 1003 | 1003 | , |
| 1004 | \\zig_extern zig_void a(zig_void); | |
| 1005 | \\zig_extern zig_void b(zig_void); | |
| 1006 | \\zig_extern zig_void c(zig_void); | |
| 1004 | \\zig_extern void a(void); | |
| 1005 | \\zig_extern void b(void); | |
| 1006 | \\zig_extern void c(void); | |
| 1007 | 1007 | \\ |
| 1008 | 1008 | ); |
| 1009 | 1009 | ctx.h("header with multiple includes", linux_x64, |
| 1010 | 1010 | \\export fn start(a: u32, b: usize) void{ _ = a; _ = b; } |
| 1011 | 1011 | , |
| 1012 | \\zig_extern zig_void start(zig_u32 const a0, zig_usize const a1); | |
| 1012 | \\zig_extern void start(zig_u32 const a0, zig_usize const a1); | |
| 1013 | 1013 | \\ |
| 1014 | 1014 | ); |
| 1015 | 1015 | } |