| author | |
| committer | |
| log | 5df091fea98e91536f95e3b4bd5bcb0881f06989 |
| tree | 72e34976d9bf0119a1f72cc9f991192c558de9c1 |
| parent | 660a50661b22b279fed548387d19ffcddb031b23 |
6 files changed, 15 insertions(+), 23 deletions(-)
doc/langref.md+1| ... | ... | @@ -204,6 +204,7 @@ c_ulong unsigned long for ABI compatibility with C |
| 204 | 204 | c_longlong long long for ABI compatibility with C |
| 205 | 205 | c_ulonglong unsigned long long for ABI compatibility with C |
| 206 | 206 | c_long_double long double for ABI compatibility with C |
| 207 | c_void void for ABI compatibility with C | |
| 207 | 208 | ``` |
| 208 | 209 | |
| 209 | 210 | ### Boolean Type |
src/all_types.hpp+1| ... | ... | @@ -1062,6 +1062,7 @@ struct CodeGen { |
| 1062 | 1062 | TypeTableEntry *entry_int[2][4]; // [signed,unsigned][8,16,32,64] |
| 1063 | 1063 | TypeTableEntry *entry_c_int[CIntTypeCount]; |
| 1064 | 1064 | TypeTableEntry *entry_c_long_double; |
| 1065 | TypeTableEntry *entry_c_void; | |
| 1065 | 1066 | TypeTableEntry *entry_u8; |
| 1066 | 1067 | TypeTableEntry *entry_u16; |
| 1067 | 1068 | TypeTableEntry *entry_u32; |
src/analyze.cpp+2-2| ... | ... | @@ -2320,9 +2320,9 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i |
| 2320 | 2320 | bool pointer_only = false; |
| 2321 | 2321 | return analyze_decl_ref(g, node, decl_node, pointer_only); |
| 2322 | 2322 | } else { |
| 2323 | const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)"; | |
| 2323 | 2324 | add_node_error(g, node, |
| 2324 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), | |
| 2325 | buf_ptr(namespace_import->path))); | |
| 2325 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name)); | |
| 2326 | 2326 | return g->builtin_types.entry_invalid; |
| 2327 | 2327 | } |
| 2328 | 2328 | } else { |
src/codegen.cpp+5| ... | ... | @@ -3551,6 +3551,11 @@ static void define_builtin_types(CodeGen *g) { |
| 3551 | 3551 | g->builtin_types.entry_i32 = get_int_type(g, true, 32); |
| 3552 | 3552 | g->builtin_types.entry_i64 = get_int_type(g, true, 64); |
| 3553 | 3553 | |
| 3554 | { | |
| 3555 | g->builtin_types.entry_c_void = get_typedecl_type(g, "c_void", g->builtin_types.entry_u8); | |
| 3556 | g->primitive_type_table.put(&g->builtin_types.entry_c_void->name, g->builtin_types.entry_c_void); | |
| 3557 | } | |
| 3558 | ||
| 3554 | 3559 | { |
| 3555 | 3560 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPureError); |
| 3556 | 3561 | buf_init_from_str(&entry->name, "error"); |
src/parseh.cpp+2-15| ... | ... | @@ -36,7 +36,6 @@ struct Context { |
| 36 | 36 | ZigList<ErrorMsg *> *errors; |
| 37 | 37 | bool warnings_on; |
| 38 | 38 | VisibMod visib_mod; |
| 39 | TypeTableEntry *c_void_type; | |
| 40 | 39 | AstNode *root; |
| 41 | 40 | HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> global_type_table; |
| 42 | 41 | HashMap<Buf *, GlobalValue, buf_hash, buf_eql_buf> global_value_table; |
| ... | ... | @@ -292,21 +291,9 @@ static AstNode *add_const_var_node(Context *c, Buf *name, TypeTableEntry *type_e |
| 292 | 291 | return node; |
| 293 | 292 | } |
| 294 | 293 | |
| 295 | static TypeTableEntry *get_c_void_type(Context *c) { | |
| 296 | if (!c->c_void_type) { | |
| 297 | c->c_void_type = get_typedecl_type(c->codegen, "c_void", c->codegen->builtin_types.entry_u8); | |
| 298 | add_typedef_node(c, c->c_void_type); | |
| 299 | } | |
| 300 | ||
| 301 | return c->c_void_type; | |
| 302 | } | |
| 303 | ||
| 304 | 294 | static bool is_c_void_type(Context *c, TypeTableEntry *type_entry) { |
| 305 | if (!c->c_void_type) { | |
| 306 | return false; | |
| 307 | } | |
| 308 | 295 | while (type_entry->id == TypeTableEntryIdTypeDecl) { |
| 309 | if (type_entry == c->c_void_type) { | |
| 296 | if (type_entry == c->codegen->builtin_types.entry_c_void) { | |
| 310 | 297 | return true; |
| 311 | 298 | } |
| 312 | 299 | type_entry = type_entry->data.type_decl.child_type; |
| ... | ... | @@ -336,7 +323,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 336 | 323 | const BuiltinType *builtin_ty = static_cast<const BuiltinType*>(ty); |
| 337 | 324 | switch (builtin_ty->getKind()) { |
| 338 | 325 | case BuiltinType::Void: |
| 339 | return get_c_void_type(c); | |
| 326 | return c->codegen->builtin_types.entry_c_void; | |
| 340 | 327 | case BuiltinType::Bool: |
| 341 | 328 | return c->codegen->builtin_types.entry_bool; |
| 342 | 329 | case BuiltinType::Char_U: |
test/run_tests.cpp+4-6| ... | ... | @@ -1095,7 +1095,7 @@ pub fn main(args: [][]u8) -> %void { |
| 1095 | 1095 | add_simple_case_libc("expose function pointer to C land", R"SOURCE( |
| 1096 | 1096 | const c = @c_import(@c_include("stdlib.h")); |
| 1097 | 1097 | |
| 1098 | export fn compare_fn(a: ?&const c.c_void, b: ?&const c.c_void) -> c_int { | |
| 1098 | export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int { | |
| 1099 | 1099 | const a_int = (&i32)(a ?? unreachable{}); |
| 1100 | 1100 | const b_int = (&i32)(b ?? unreachable{}); |
| 1101 | 1101 | if (*a_int < *b_int) { |
| ... | ... | @@ -1110,7 +1110,7 @@ export fn compare_fn(a: ?&const c.c_void, b: ?&const c.c_void) -> c_int { |
| 1110 | 1110 | export fn main(args: c_int, argv: &&u8) -> c_int { |
| 1111 | 1111 | var array = []i32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; |
| 1112 | 1112 | |
| 1113 | c.qsort((&c.c_void)(&array[0]), c_ulong(array.len), @sizeof(i32), compare_fn); | |
| 1113 | c.qsort((&c_void)(&array[0]), c_ulong(array.len), @sizeof(i32), compare_fn); | |
| 1114 | 1114 | |
| 1115 | 1115 | for (array) |item, i| { |
| 1116 | 1116 | if (item != i) { |
| ... | ... | @@ -1802,8 +1802,7 @@ pub const Foo1 = enum_Foo._1;)OUTPUT", |
| 1802 | 1802 | |
| 1803 | 1803 | add_parseh_case("restrict -> noalias", R"SOURCE( |
| 1804 | 1804 | void foo(void *restrict bar, void *restrict); |
| 1805 | )SOURCE", 1, R"OUTPUT(pub type c_void = u8; | |
| 1806 | pub extern fn foo(noalias bar: ?&c_void, noalias arg1: ?&c_void);)OUTPUT"); | |
| 1805 | )SOURCE", 1, R"OUTPUT(pub extern fn foo(noalias bar: ?&c_void, noalias arg1: ?&c_void);)OUTPUT"); | |
| 1807 | 1806 | |
| 1808 | 1807 | add_parseh_case("simple struct", R"SOURCE( |
| 1809 | 1808 | struct Foo { |
| ... | ... | @@ -1916,8 +1915,7 @@ struct Bar { |
| 1916 | 1915 | add_parseh_case("typedef void", R"SOURCE( |
| 1917 | 1916 | typedef void Foo; |
| 1918 | 1917 | Foo fun(Foo *a); |
| 1919 | )SOURCE", 3, | |
| 1920 | "pub type c_void = u8;", | |
| 1918 | )SOURCE", 2, | |
| 1921 | 1919 | "pub const Foo = c_void;", |
| 1922 | 1920 | "pub extern fn fun(a: ?&c_void);"); |
| 1923 | 1921 |