mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 00:08:56 +00:00
gen-h: use the bare type names for now
This commit is contained in:
parent
e8dad62441
commit
26128396f3
@ -6852,3 +6852,19 @@ void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Buf *type_bare_name(ZigType *type_entry) {
|
||||
if (is_container(type_entry)) {
|
||||
return get_container_scope(type_entry)->bare_name;
|
||||
} else if (type_entry->id == ZigTypeIdOpaque) {
|
||||
return type_entry->data.opaque.bare_name;
|
||||
} else {
|
||||
return &type_entry->name;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO this will have to be more clever, probably using the full name
|
||||
// and replacing '.' with '_' or something like that
|
||||
Buf *type_h_name(ZigType *t) {
|
||||
return type_bare_name(t);
|
||||
}
|
||||
|
||||
@ -240,4 +240,6 @@ Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_no
|
||||
ConstExprValue *const_val, ZigType *wanted_type);
|
||||
|
||||
void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
|
||||
Buf *type_bare_name(ZigType *t);
|
||||
Buf *type_h_name(ZigType *t);
|
||||
#endif
|
||||
|
||||
@ -8484,19 +8484,19 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
|
||||
case ZigTypeIdOpaque:
|
||||
{
|
||||
buf_init_from_str(out_buf, "struct ");
|
||||
buf_append_buf(out_buf, &type_entry->name);
|
||||
buf_append_buf(out_buf, type_h_name(type_entry));
|
||||
return;
|
||||
}
|
||||
case ZigTypeIdUnion:
|
||||
{
|
||||
buf_init_from_str(out_buf, "union ");
|
||||
buf_append_buf(out_buf, &type_entry->name);
|
||||
buf_append_buf(out_buf, type_h_name(type_entry));
|
||||
return;
|
||||
}
|
||||
case ZigTypeIdEnum:
|
||||
{
|
||||
buf_init_from_str(out_buf, "enum ");
|
||||
buf_append_buf(out_buf, &type_entry->name);
|
||||
buf_append_buf(out_buf, type_h_name(type_entry));
|
||||
return;
|
||||
}
|
||||
case ZigTypeIdArray:
|
||||
@ -8679,7 +8679,7 @@ static void gen_h_file(CodeGen *g) {
|
||||
zig_unreachable();
|
||||
case ZigTypeIdEnum:
|
||||
if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
|
||||
fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "enum %s {\n", buf_ptr(type_h_name(type_entry)));
|
||||
for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
|
||||
TypeEnumField *enum_field = &type_entry->data.enumeration.fields[field_i];
|
||||
Buf *value_buf = buf_alloc();
|
||||
@ -8692,12 +8692,12 @@ static void gen_h_file(CodeGen *g) {
|
||||
}
|
||||
fprintf(out_h, "};\n\n");
|
||||
} else {
|
||||
fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "enum %s;\n", buf_ptr(type_h_name(type_entry)));
|
||||
}
|
||||
break;
|
||||
case ZigTypeIdStruct:
|
||||
if (type_entry->data.structure.layout == ContainerLayoutExtern) {
|
||||
fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "struct %s {\n", buf_ptr(type_h_name(type_entry)));
|
||||
for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
|
||||
TypeStructField *struct_field = &type_entry->data.structure.fields[field_i];
|
||||
|
||||
@ -8715,12 +8715,12 @@ static void gen_h_file(CodeGen *g) {
|
||||
}
|
||||
fprintf(out_h, "};\n\n");
|
||||
} else {
|
||||
fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "struct %s;\n", buf_ptr(type_h_name(type_entry)));
|
||||
}
|
||||
break;
|
||||
case ZigTypeIdUnion:
|
||||
if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
|
||||
fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "union %s {\n", buf_ptr(type_h_name(type_entry)));
|
||||
for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
|
||||
TypeUnionField *union_field = &type_entry->data.unionation.fields[field_i];
|
||||
|
||||
@ -8730,11 +8730,11 @@ static void gen_h_file(CodeGen *g) {
|
||||
}
|
||||
fprintf(out_h, "};\n\n");
|
||||
} else {
|
||||
fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "union %s;\n", buf_ptr(type_h_name(type_entry)));
|
||||
}
|
||||
break;
|
||||
case ZigTypeIdOpaque:
|
||||
fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "struct %s;\n\n", buf_ptr(type_h_name(type_entry)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
10
src/ir.cpp
10
src/ir.cpp
@ -18685,15 +18685,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
if (!type_entry->cached_const_name_val) {
|
||||
Buf *name;
|
||||
if (is_container(type_entry)) {
|
||||
name = get_container_scope(type_entry)->bare_name;
|
||||
} else if (type_entry->id == ZigTypeIdOpaque) {
|
||||
name = type_entry->data.opaque.bare_name;
|
||||
} else {
|
||||
name = &type_entry->name;
|
||||
}
|
||||
type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, name);
|
||||
type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
|
||||
}
|
||||
IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
|
||||
copy_const_val(&result->value, type_entry->cached_const_name_val, true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user