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
signature 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) {...@@ -6852,3 +6852,19 @@ void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg) {
6852 }6852 }
6853 }6853 }
6854}6854}
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...@@ -240,4 +240,6 @@ Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_no
240 ConstExprValue *const_val, ZigType *wanted_type);240 ConstExprValue *const_val, ZigType *wanted_type);
241241
242void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);242void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
243Buf *type_bare_name(ZigType *t);
244Buf *type_h_name(ZigType *t);
243#endif245#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...@@ -8484,19 +8484,19 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
8484 case ZigTypeIdOpaque:8484 case ZigTypeIdOpaque:
8485 {8485 {
8486 buf_init_from_str(out_buf, "struct ");8486 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));
8488 return;8488 return;
8489 }8489 }
8490 case ZigTypeIdUnion:8490 case ZigTypeIdUnion:
8491 {8491 {
8492 buf_init_from_str(out_buf, "union ");8492 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));
8494 return;8494 return;
8495 }8495 }
8496 case ZigTypeIdEnum:8496 case ZigTypeIdEnum:
8497 {8497 {
8498 buf_init_from_str(out_buf, "enum ");8498 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));
8500 return;8500 return;
8501 }8501 }
8502 case ZigTypeIdArray:8502 case ZigTypeIdArray:
...@@ -8679,7 +8679,7 @@ static void gen_h_file(CodeGen *g) {...@@ -8679,7 +8679,7 @@ static void gen_h_file(CodeGen *g) {
8679 zig_unreachable();8679 zig_unreachable();
8680 case ZigTypeIdEnum:8680 case ZigTypeIdEnum:
8681 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {8681 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)));
8683 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {8683 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
8684 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[field_i];8684 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[field_i];
8685 Buf *value_buf = buf_alloc();8685 Buf *value_buf = buf_alloc();
...@@ -8692,12 +8692,12 @@ static void gen_h_file(CodeGen *g) {...@@ -8692,12 +8692,12 @@ static void gen_h_file(CodeGen *g) {
8692 }8692 }
8693 fprintf(out_h, "};\n\n");8693 fprintf(out_h, "};\n\n");
8694 } else {8694 } 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)));
8696 }8696 }
8697 break;8697 break;
8698 case ZigTypeIdStruct:8698 case ZigTypeIdStruct:
8699 if (type_entry->data.structure.layout == ContainerLayoutExtern) {8699 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)));
8701 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {8701 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
8702 TypeStructField *struct_field = &type_entry->data.structure.fields[field_i];8702 TypeStructField *struct_field = &type_entry->data.structure.fields[field_i];
87038703
...@@ -8715,12 +8715,12 @@ static void gen_h_file(CodeGen *g) {...@@ -8715,12 +8715,12 @@ static void gen_h_file(CodeGen *g) {
8715 }8715 }
8716 fprintf(out_h, "};\n\n");8716 fprintf(out_h, "};\n\n");
8717 } else {8717 } 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)));
8719 }8719 }
8720 break;8720 break;
8721 case ZigTypeIdUnion:8721 case ZigTypeIdUnion:
8722 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {8722 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)));
8724 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {8724 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
8725 TypeUnionField *union_field = &type_entry->data.unionation.fields[field_i];8725 TypeUnionField *union_field = &type_entry->data.unionation.fields[field_i];
87268726
...@@ -8730,11 +8730,11 @@ static void gen_h_file(CodeGen *g) {...@@ -8730,11 +8730,11 @@ static void gen_h_file(CodeGen *g) {
8730 }8730 }
8731 fprintf(out_h, "};\n\n");8731 fprintf(out_h, "};\n\n");
8732 } else {8732 } 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)));
8734 }8734 }
8735 break;8735 break;
8736 case ZigTypeIdOpaque:8736 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)));
8738 break;8738 break;
8739 }8739 }
8740 }8740 }
src/ir.cpp+1-9
...@@ -18685,15 +18685,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc...@@ -18685,15 +18685,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
18685 return ira->codegen->invalid_instruction;18685 return ira->codegen->invalid_instruction;
1868618686
18687 if (!type_entry->cached_const_name_val) {18687 if (!type_entry->cached_const_name_val) {
18688 Buf *name;18688 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
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);
18697 }18689 }
18698 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);18690 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
18699 copy_const_val(&result->value, type_entry->cached_const_name_val, true);18691 copy_const_val(&result->value, type_entry->cached_const_name_val, true);