Add initial support for struct fields in the docs

This commit is contained in:
Timon Kruiper
2019-10-08 22:57:28 +02:00
committed by Andrew Kelley
parent 1e59eb3c94
commit f74c29b49a
3 changed files with 49 additions and 0 deletions

View File

@@ -732,6 +732,23 @@ static void anal_dump_pointer_attrs(AnalDumpCtx *ctx, ZigType *ty) {
anal_dump_type_ref(ctx, ty->data.pointer.child_type);
}
static void anal_dump_struct_field(AnalDumpCtx *ctx, const TypeStructField *struct_field) {
JsonWriter *jw = &ctx->jw;
jw_begin_object(jw);
jw_object_field(jw, "name");
jw_string(jw, buf_ptr(struct_field->name));
jw_object_field(jw, "type");
anal_dump_type_ref(ctx, struct_field->type_entry);
jw_object_field(jw, "src");
anal_dump_node_ref(ctx, struct_field->decl_node);
jw_end_object(jw);
}
static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
JsonWriter *jw = &ctx->jw;
jw_array_elem(jw);
@@ -794,6 +811,17 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
jw_end_array(jw);
}
{
jw_object_field(jw, "fields");
jw_begin_array(jw);
for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) {
jw_array_elem(jw);
anal_dump_struct_field(ctx, &ty->data.structure.fields[i]);
}
jw_end_array(jw);
}
if (ty->data.structure.root_struct != nullptr) {
Buf *path_buf = ty->data.structure.root_struct->path;