authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-31 17:48:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-31 17:48:19-07:00
log41b95cc2374010f39b903cb4b90d233d2f7d57c4
treedb26d562e8b0f2621df474b9bd16aec0289caa14
parent773cd851fe83d1ee89d7e0ca9e7ad7327d2962c9

parseh: correct debug for forward decls

also C typedefs emit simply `const Foo = Bar;` since in C you can implicitly cast from a typedef child to parent but in zig you can't.

4 files changed, 33 insertions(+), 5 deletions(-)

src/parseh.cpp+17-3
...@@ -225,6 +225,14 @@ static AstNode *add_typedef_node(Context *c, TypeTableEntry *type_decl) {...@@ -225,6 +225,14 @@ static AstNode *add_typedef_node(Context *c, TypeTableEntry *type_decl) {
225 return node;225 return node;
226}226}
227227
228static AstNode *add_const_var_node(Context *c, Buf *name, TypeTableEntry *type_entry) {
229 AstNode *node = create_var_decl_node(c, buf_ptr(name), make_type_node(c, type_entry));
230
231 c->global_type_table.put(name, type_entry);
232 c->root->data.root.top_level_decls.append(node);
233 return node;
234}
235
228static TypeTableEntry *get_c_void_type(Context *c) {236static TypeTableEntry *get_c_void_type(Context *c) {
229 if (!c->c_void_type) {237 if (!c->c_void_type) {
230 c->c_void_type = get_typedecl_type(c->codegen, "c_void", c->codegen->builtin_types.entry_u8);238 c->c_void_type = get_typedecl_type(c->codegen, "c_void", c->codegen->builtin_types.entry_u8);
...@@ -625,8 +633,7 @@ static void visit_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl)...@@ -625,8 +633,7 @@ static void visit_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl)
625 emit_warning(c, typedef_decl, "typedef %s - unresolved child type", buf_ptr(type_name));633 emit_warning(c, typedef_decl, "typedef %s - unresolved child type", buf_ptr(type_name));
626 return;634 return;
627 }635 }
628 TypeTableEntry *decl_type = get_typedecl_type(c->codegen, buf_ptr(type_name), child_type);636 add_const_var_node(c, type_name, child_type);
629 add_typedef_node(c, decl_type);
630}637}
631638
632static void add_alias(Context *c, const char *new_name, const char *target_name) {639static void add_alias(Context *c, const char *new_name, const char *target_name) {
...@@ -803,7 +810,15 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_...@@ -803,7 +810,15 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
803 c->struct_type_table.put(bare_name, struct_type);810 c->struct_type_table.put(bare_name, struct_type);
804811
805 RecordDecl *record_def = record_decl->getDefinition();812 RecordDecl *record_def = record_decl->getDefinition();
813 unsigned line = c->source_node ? c->source_node->line : 0;
806 if (!record_def) {814 if (!record_def) {
815 LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugForwardDeclType(c->codegen->dbuilder,
816 LLVMZigTag_DW_structure_type(), buf_ptr(full_type_name),
817 LLVMZigFileToScope(c->import->di_file), c->import->di_file, line);
818
819 LLVMZigReplaceTemporary(c->codegen->dbuilder, struct_type->di_type, replacement_di_type);
820 struct_type->di_type = replacement_di_type;
821
807 return struct_type;822 return struct_type;
808 }823 }
809824
...@@ -835,7 +850,6 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_...@@ -835,7 +850,6 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
835 uint64_t offset_in_bits = 0;850 uint64_t offset_in_bits = 0;
836851
837 uint32_t i = 0;852 uint32_t i = 0;
838 unsigned line = c->source_node ? c->source_node->line : 0;
839 for (auto it = record_def->field_begin(),853 for (auto it = record_def->field_begin(),
840 it_end = record_def->field_end();854 it_end = record_def->field_end();
841 it != it_end; ++it, i += 1)855 it != it_end; ++it, i += 1)
src/zig_llvm.cpp+11
...@@ -262,6 +262,17 @@ LLVMZigDIType *LLVMZigCreateReplaceableCompositeType(LLVMZigDIBuilder *dibuilder...@@ -262,6 +262,17 @@ LLVMZigDIType *LLVMZigCreateReplaceableCompositeType(LLVMZigDIBuilder *dibuilder
262 return reinterpret_cast<LLVMZigDIType*>(di_type);262 return reinterpret_cast<LLVMZigDIType*>(di_type);
263}263}
264264
265LLVMZigDIType *LLVMZigCreateDebugForwardDeclType(LLVMZigDIBuilder *dibuilder, unsigned tag,
266 const char *name, LLVMZigDIScope *scope, LLVMZigDIFile *file, unsigned line)
267{
268 DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createForwardDecl(
269 tag, name,
270 reinterpret_cast<DIScope*>(scope),
271 reinterpret_cast<DIFile*>(file),
272 line);
273 return reinterpret_cast<LLVMZigDIType*>(di_type);
274}
275
265void LLVMZigReplaceTemporary(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,276void LLVMZigReplaceTemporary(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,
266 LLVMZigDIType *replacement)277 LLVMZigDIType *replacement)
267{278{
src/zig_llvm.hpp+3
...@@ -75,6 +75,9 @@ LLVMZigDIType *LLVMZigCreateDebugMemberType(LLVMZigDIBuilder *dibuilder, LLVMZig...@@ -75,6 +75,9 @@ LLVMZigDIType *LLVMZigCreateDebugMemberType(LLVMZigDIBuilder *dibuilder, LLVMZig
75LLVMZigDIType *LLVMZigCreateReplaceableCompositeType(LLVMZigDIBuilder *dibuilder, unsigned tag,75LLVMZigDIType *LLVMZigCreateReplaceableCompositeType(LLVMZigDIBuilder *dibuilder, unsigned tag,
76 const char *name, LLVMZigDIScope *scope, LLVMZigDIFile *file, unsigned line);76 const char *name, LLVMZigDIScope *scope, LLVMZigDIFile *file, unsigned line);
7777
78LLVMZigDIType *LLVMZigCreateDebugForwardDeclType(LLVMZigDIBuilder *dibuilder, unsigned tag,
79 const char *name, LLVMZigDIScope *scope, LLVMZigDIFile *file, unsigned line);
80
78void LLVMZigReplaceTemporary(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,81void LLVMZigReplaceTemporary(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,
79 LLVMZigDIType *replacement);82 LLVMZigDIType *replacement);
8083
test/run_tests.cpp+2-2
...@@ -2046,8 +2046,8 @@ typedef void Foo;...@@ -2046,8 +2046,8 @@ typedef void Foo;
2046Foo fun(Foo *a);2046Foo fun(Foo *a);
2047 )SOURCE", 3,2047 )SOURCE", 3,
2048 "pub type c_void = u8;",2048 "pub type c_void = u8;",
2049 "pub type Foo = c_void;",2049 "pub const Foo = c_void;",
2050 "pub extern fn fun(a: ?&Foo);");2050 "pub extern fn fun(a: ?&c_void);");
2051}2051}
20522052
2053static void print_compiler_invocation(TestCase *test_case) {2053static void print_compiler_invocation(TestCase *test_case) {