authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-01 17:36:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-01 17:36:08-05:00
log26128396f3abaaba725642220b1fd34e281c8939
tree17ab3f606a0c781d92e9113a3c5a79fc0574121c
parente8dad624419cee8e106185e478969d4a3ca44f0a
signaturelock-open Commit is signed but in an unrecognized format.

gen-h: use the bare type names for now


4 files changed, 29 insertions(+), 19 deletions(-)

src/analyze.cpp+16
......@@ -6852,3 +6852,19 @@ void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg) {
68526852 }
68536853 }
68546854}
6855
6856Buf *type_bare_name(ZigType *type_entry) {
6857 if (is_container(type_entry)) {
6858 return get_container_scope(type_entry)->bare_name;
6859 } else if (type_entry->id == ZigTypeIdOpaque) {
6860 return type_entry->data.opaque.bare_name;
6861 } else {
6862 return &type_entry->name;
6863 }
6864}
6865
6866// TODO this will have to be more clever, probably using the full name
6867// and replacing '.' with '_' or something like that
6868Buf *type_h_name(ZigType *t) {
6869 return type_bare_name(t);
6870}
src/analyze.hpp+2
......@@ -240,4 +240,6 @@ Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_no
240240 ConstExprValue *const_val, ZigType *wanted_type);
241241
242242void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
243Buf *type_bare_name(ZigType *t);
244Buf *type_h_name(ZigType *t);
243245#endif
src/codegen.cpp+10-10
......@@ -8484,19 +8484,19 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
84848484 case ZigTypeIdOpaque:
84858485 {
84868486 buf_init_from_str(out_buf, "struct ");
8487 buf_append_buf(out_buf, &type_entry->name);
8487 buf_append_buf(out_buf, type_h_name(type_entry));
84888488 return;
84898489 }
84908490 case ZigTypeIdUnion:
84918491 {
84928492 buf_init_from_str(out_buf, "union ");
8493 buf_append_buf(out_buf, &type_entry->name);
8493 buf_append_buf(out_buf, type_h_name(type_entry));
84948494 return;
84958495 }
84968496 case ZigTypeIdEnum:
84978497 {
84988498 buf_init_from_str(out_buf, "enum ");
8499 buf_append_buf(out_buf, &type_entry->name);
8499 buf_append_buf(out_buf, type_h_name(type_entry));
85008500 return;
85018501 }
85028502 case ZigTypeIdArray:
......@@ -8679,7 +8679,7 @@ static void gen_h_file(CodeGen *g) {
86798679 zig_unreachable();
86808680 case ZigTypeIdEnum:
86818681 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
8682 fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
8682 fprintf(out_h, "enum %s {\n", buf_ptr(type_h_name(type_entry)));
86838683 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
86848684 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[field_i];
86858685 Buf *value_buf = buf_alloc();
......@@ -8692,12 +8692,12 @@ static void gen_h_file(CodeGen *g) {
86928692 }
86938693 fprintf(out_h, "};\n\n");
86948694 } else {
8695 fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));
8695 fprintf(out_h, "enum %s;\n", buf_ptr(type_h_name(type_entry)));
86968696 }
86978697 break;
86988698 case ZigTypeIdStruct:
86998699 if (type_entry->data.structure.layout == ContainerLayoutExtern) {
8700 fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
8700 fprintf(out_h, "struct %s {\n", buf_ptr(type_h_name(type_entry)));
87018701 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
87028702 TypeStructField *struct_field = &type_entry->data.structure.fields[field_i];
87038703
......@@ -8715,12 +8715,12 @@ static void gen_h_file(CodeGen *g) {
87158715 }
87168716 fprintf(out_h, "};\n\n");
87178717 } else {
8718 fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));
8718 fprintf(out_h, "struct %s;\n", buf_ptr(type_h_name(type_entry)));
87198719 }
87208720 break;
87218721 case ZigTypeIdUnion:
87228722 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
8723 fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
8723 fprintf(out_h, "union %s {\n", buf_ptr(type_h_name(type_entry)));
87248724 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
87258725 TypeUnionField *union_field = &type_entry->data.unionation.fields[field_i];
87268726
......@@ -8730,11 +8730,11 @@ static void gen_h_file(CodeGen *g) {
87308730 }
87318731 fprintf(out_h, "};\n\n");
87328732 } else {
8733 fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));
8733 fprintf(out_h, "union %s;\n", buf_ptr(type_h_name(type_entry)));
87348734 }
87358735 break;
87368736 case ZigTypeIdOpaque:
8737 fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
8737 fprintf(out_h, "struct %s;\n\n", buf_ptr(type_h_name(type_entry)));
87388738 break;
87398739 }
87408740 }
src/ir.cpp+1-9
......@@ -18685,15 +18685,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
1868518685 return ira->codegen->invalid_instruction;
1868618686
1868718687 if (!type_entry->cached_const_name_val) {
18688 Buf *name;
18689 if (is_container(type_entry)) {
18690 name = get_container_scope(type_entry)->bare_name;
18691 } else if (type_entry->id == ZigTypeIdOpaque) {
18692 name = type_entry->data.opaque.bare_name;
18693 } else {
18694 name = &type_entry->name;
18695 }
18696 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, name);
18688 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
1869718689 }
1869818690 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
1869918691 copy_const_val(&result->value, type_entry->cached_const_name_val, true);