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) {
225225 return node;
226226}
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
228236static TypeTableEntry *get_c_void_type(Context *c) {
229237 if (!c->c_void_type) {
230238 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)
625633 emit_warning(c, typedef_decl, "typedef %s - unresolved child type", buf_ptr(type_name));
626634 return;
627635 }
628 TypeTableEntry *decl_type = get_typedecl_type(c->codegen, buf_ptr(type_name), child_type);
629 add_typedef_node(c, decl_type);
636 add_const_var_node(c, type_name, child_type);
630637}
631638
632639static 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_
803810 c->struct_type_table.put(bare_name, struct_type);
804811
805812 RecordDecl *record_def = record_decl->getDefinition();
813 unsigned line = c->source_node ? c->source_node->line : 0;
806814 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
807822 return struct_type;
808823 }
809824
......@@ -835,7 +850,6 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
835850 uint64_t offset_in_bits = 0;
836851
837852 uint32_t i = 0;
838 unsigned line = c->source_node ? c->source_node->line : 0;
839853 for (auto it = record_def->field_begin(),
840854 it_end = record_def->field_end();
841855 it != it_end; ++it, i += 1)
src/zig_llvm.cpp+11
......@@ -262,6 +262,17 @@ LLVMZigDIType *LLVMZigCreateReplaceableCompositeType(LLVMZigDIBuilder *dibuilder
262262 return reinterpret_cast<LLVMZigDIType*>(di_type);
263263}
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
265276void LLVMZigReplaceTemporary(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,
266277 LLVMZigDIType *replacement)
267278{
src/zig_llvm.hpp+3
......@@ -75,6 +75,9 @@ LLVMZigDIType *LLVMZigCreateDebugMemberType(LLVMZigDIBuilder *dibuilder, LLVMZig
7575LLVMZigDIType *LLVMZigCreateReplaceableCompositeType(LLVMZigDIBuilder *dibuilder, unsigned tag,
7676 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
7881void LLVMZigReplaceTemporary(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *type,
7982 LLVMZigDIType *replacement);
8083
test/run_tests.cpp+2-2
......@@ -2046,8 +2046,8 @@ typedef void Foo;
20462046Foo fun(Foo *a);
20472047 )SOURCE", 3,
20482048 "pub type c_void = u8;",
2049 "pub type Foo = c_void;",
2050 "pub extern fn fun(a: ?&Foo);");
2049 "pub const Foo = c_void;",
2050 "pub extern fn fun(a: ?&c_void);");
20512051}
20522052
20532053static void print_compiler_invocation(TestCase *test_case) {