| author | |
| committer | |
| log | a284be3f69aabb13ad64753e03601169e8292a24 |
| tree | 32e41dc8d128711b059045018cde1e1716b2c0de |
| parent | b94525c45b695b116c2af69174283ad10dce6de9 |
Fixes #42505 files changed, 34 insertions(+), 1 deletions(-)
src-self-hosted/clang.zig+1| ... | @@ -809,6 +809,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType | ... | @@ -809,6 +809,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType |
| 809 | pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass; | 809 | pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass; |
| 810 | pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType; | 810 | pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType; |
| 811 | pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool; | 811 | pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool; |
| 812 | pub extern fn ZigClangType_isConstantArrayType(self: ?*const struct_ZigClangType) bool; | ||
| 812 | pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool; | 813 | pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool; |
| 813 | pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool; | 814 | pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool; |
| 814 | pub extern fn ZigClangType_isBooleanType(self: ?*const struct_ZigClangType) bool; | 815 | pub extern fn ZigClangType_isBooleanType(self: ?*const struct_ZigClangType) bool; |
src-self-hosted/translate_c.zig+2-1| ... | @@ -1982,7 +1982,8 @@ fn transInitListExprArray( | ... | @@ -1982,7 +1982,8 @@ fn transInitListExprArray( |
| 1982 | const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty); | 1982 | const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty); |
| 1983 | const child_qt = ZigClangArrayType_getElementType(arr_type); | 1983 | const child_qt = ZigClangArrayType_getElementType(arr_type); |
| 1984 | const init_count = ZigClangInitListExpr_getNumInits(expr); | 1984 | const init_count = ZigClangInitListExpr_getNumInits(expr); |
| 1985 | const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, ty); | 1985 | assert(ZigClangType_isConstantArrayType(@ptrCast(*const ZigClangType, arr_type))); |
| 1986 | const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, arr_type); | ||
| 1986 | const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty); | 1987 | const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty); |
| 1987 | const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize)); | 1988 | const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize)); |
| 1988 | const leftover_count = all_count - init_count; | 1989 | const leftover_count = all_count - init_count; |
src/zig_clang.cpp+5| ... | @@ -1877,6 +1877,11 @@ bool ZigClangType_isRecordType(const ZigClangType *self) { | ... | @@ -1877,6 +1877,11 @@ bool ZigClangType_isRecordType(const ZigClangType *self) { |
| 1877 | return casted->isRecordType(); | 1877 | return casted->isRecordType(); |
| 1878 | } | 1878 | } |
| 1879 | 1879 | ||
| 1880 | bool ZigClangType_isConstantArrayType(const ZigClangType *self) { | ||
| 1881 | auto casted = reinterpret_cast<const clang::Type *>(self); | ||
| 1882 | return casted->isConstantArrayType(); | ||
| 1883 | } | ||
| 1884 | |||
| 1880 | const char *ZigClangType_getTypeClassName(const ZigClangType *self) { | 1885 | const char *ZigClangType_getTypeClassName(const ZigClangType *self) { |
| 1881 | auto casted = reinterpret_cast<const clang::Type *>(self); | 1886 | auto casted = reinterpret_cast<const clang::Type *>(self); |
| 1882 | return casted->getTypeClassName(); | 1887 | return casted->getTypeClassName(); |
src/zig_clang.h+1| ... | @@ -945,6 +945,7 @@ ZIG_EXTERN_C bool ZigClangType_isBooleanType(const struct ZigClangType *self); | ... | @@ -945,6 +945,7 @@ ZIG_EXTERN_C bool ZigClangType_isBooleanType(const struct ZigClangType *self); |
| 945 | ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self); | 945 | ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self); |
| 946 | ZIG_EXTERN_C bool ZigClangType_isArrayType(const struct ZigClangType *self); | 946 | ZIG_EXTERN_C bool ZigClangType_isArrayType(const struct ZigClangType *self); |
| 947 | ZIG_EXTERN_C bool ZigClangType_isRecordType(const struct ZigClangType *self); | 947 | ZIG_EXTERN_C bool ZigClangType_isRecordType(const struct ZigClangType *self); |
| 948 | ZIG_EXTERN_C bool ZigClangType_isConstantArrayType(const ZigClangType *self); | ||
| 948 | ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self); | 949 | ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self); |
| 949 | ZIG_EXTERN_C const struct ZigClangArrayType *ZigClangType_getAsArrayTypeUnsafe(const struct ZigClangType *self); | 950 | ZIG_EXTERN_C const struct ZigClangArrayType *ZigClangType_getAsArrayTypeUnsafe(const struct ZigClangType *self); |
| 950 | ZIG_EXTERN_C const ZigClangRecordType *ZigClangType_getAsRecordType(const ZigClangType *self); | 951 | ZIG_EXTERN_C const ZigClangRecordType *ZigClangType_getAsRecordType(const ZigClangType *self); |
test/translate_c.zig+25| ... | @@ -2,6 +2,31 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,31 @@ const tests = @import("tests.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.TranslateCContext) void { | 4 | pub fn addCases(cases: *tests.TranslateCContext) void { |
| 5 | cases.add("array initializer w/ typedef", | ||
| 6 | \\typedef unsigned char uuid_t[16]; | ||
| 7 | \\static const uuid_t UUID_NULL __attribute__ ((unused)) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | ||
| 8 | , &[_][]const u8{ | ||
| 9 | \\pub const uuid_t = [16]u8; | ||
| 10 | \\pub const UUID_NULL: uuid_t = .{ | ||
| 11 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 12 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 13 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 14 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 15 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 16 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 17 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 18 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 19 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 20 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 21 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 22 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 23 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 24 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 25 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 26 | \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))), | ||
| 27 | \\}; | ||
| 28 | }); | ||
| 29 | |||
| 5 | cases.add("empty declaration", | 30 | cases.add("empty declaration", |
| 6 | \\; | 31 | \\; |
| 7 | , &[_][]const u8{""}); | 32 | , &[_][]const u8{""}); |