Merge branch 'docs-union-enum' of https://github.com/Vexu/zig into Vexu-docs-union-enum
This commit is contained in:
@@ -216,6 +216,21 @@ static void jw_int(JsonWriter *jw, int64_t x) {
|
||||
jw_pop_state(jw);
|
||||
}
|
||||
|
||||
static void jw_bigint(JsonWriter *jw, const BigInt *x) {
|
||||
assert(jw->state[jw->state_index] == JsonWriterStateValue);
|
||||
Buf *str = buf_alloc();
|
||||
bigint_append_buf(str, x, 10);
|
||||
|
||||
if (bigint_fits_in_bits(x, 52, true)) {
|
||||
fprintf(jw->f, "%s", buf_ptr(str));
|
||||
} else {
|
||||
fprintf(jw->f, "\"%s\"", buf_ptr(str));
|
||||
}
|
||||
jw_pop_state(jw);
|
||||
|
||||
buf_destroy(str);
|
||||
}
|
||||
|
||||
static void jw_string(JsonWriter *jw, const char *s) {
|
||||
assert(jw->state[jw->state_index] == JsonWriterStateValue);
|
||||
jw_write_escaped_string(jw, s);
|
||||
@@ -754,6 +769,10 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
|
||||
|
||||
jw_object_field(jw, "name");
|
||||
jw_string(jw, buf_ptr(&ty->name));
|
||||
|
||||
jw_object_field(jw, "src");
|
||||
anal_dump_node_ref(ctx, ty->data.structure.decl_node);
|
||||
|
||||
{
|
||||
jw_object_field(jw, "pubDecls");
|
||||
jw_begin_array(jw);
|
||||
@@ -794,9 +813,6 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
|
||||
jw_end_array(jw);
|
||||
}
|
||||
|
||||
jw_object_field(jw, "src");
|
||||
anal_dump_node_ref(ctx, ty->data.structure.decl_node);
|
||||
|
||||
if (ty->data.structure.src_field_count != 0) {
|
||||
jw_object_field(jw, "fields");
|
||||
jw_begin_array(jw);
|
||||
@@ -816,6 +832,124 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ZigTypeIdUnion: {
|
||||
jw_object_field(jw, "name");
|
||||
jw_string(jw, buf_ptr(&ty->name));
|
||||
|
||||
jw_object_field(jw, "src");
|
||||
anal_dump_node_ref(ctx, ty->data.unionation.decl_node);
|
||||
|
||||
{
|
||||
jw_object_field(jw, "pubDecls");
|
||||
jw_begin_array(jw);
|
||||
|
||||
ScopeDecls *decls_scope = ty->data.unionation.decls_scope;
|
||||
auto it = decls_scope->decl_table.entry_iterator();
|
||||
for (;;) {
|
||||
auto *entry = it.next();
|
||||
if (!entry)
|
||||
break;
|
||||
|
||||
Tld *tld = entry->value;
|
||||
if (tld->visib_mod == VisibModPub) {
|
||||
jw_array_elem(jw);
|
||||
anal_dump_decl_ref(ctx, tld);
|
||||
}
|
||||
}
|
||||
jw_end_array(jw);
|
||||
}
|
||||
|
||||
{
|
||||
jw_object_field(jw, "privDecls");
|
||||
jw_begin_array(jw);
|
||||
|
||||
ScopeDecls *decls_scope = ty->data.unionation.decls_scope;
|
||||
auto it = decls_scope->decl_table.entry_iterator();
|
||||
for (;;) {
|
||||
auto *entry = it.next();
|
||||
if (!entry)
|
||||
break;
|
||||
|
||||
Tld *tld = entry->value;
|
||||
if (tld->visib_mod == VisibModPrivate) {
|
||||
jw_array_elem(jw);
|
||||
anal_dump_decl_ref(ctx, tld);
|
||||
}
|
||||
}
|
||||
jw_end_array(jw);
|
||||
}
|
||||
|
||||
if (ty->data.unionation.src_field_count != 0) {
|
||||
jw_object_field(jw, "fields");
|
||||
jw_begin_array(jw);
|
||||
|
||||
for(size_t i = 0; i < ty->data.unionation.src_field_count; i += 1) {
|
||||
jw_array_elem(jw);
|
||||
anal_dump_type_ref(ctx, ty->data.unionation.fields[i].type_entry);
|
||||
}
|
||||
jw_end_array(jw);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ZigTypeIdEnum: {
|
||||
jw_object_field(jw, "name");
|
||||
jw_string(jw, buf_ptr(&ty->name));
|
||||
|
||||
jw_object_field(jw, "src");
|
||||
anal_dump_node_ref(ctx, ty->data.enumeration.decl_node);
|
||||
|
||||
{
|
||||
jw_object_field(jw, "pubDecls");
|
||||
jw_begin_array(jw);
|
||||
|
||||
ScopeDecls *decls_scope = ty->data.enumeration.decls_scope;
|
||||
auto it = decls_scope->decl_table.entry_iterator();
|
||||
for (;;) {
|
||||
auto *entry = it.next();
|
||||
if (!entry)
|
||||
break;
|
||||
|
||||
Tld *tld = entry->value;
|
||||
if (tld->visib_mod == VisibModPub) {
|
||||
jw_array_elem(jw);
|
||||
anal_dump_decl_ref(ctx, tld);
|
||||
}
|
||||
}
|
||||
jw_end_array(jw);
|
||||
}
|
||||
|
||||
{
|
||||
jw_object_field(jw, "privDecls");
|
||||
jw_begin_array(jw);
|
||||
|
||||
ScopeDecls *decls_scope = ty->data.enumeration.decls_scope;
|
||||
auto it = decls_scope->decl_table.entry_iterator();
|
||||
for (;;) {
|
||||
auto *entry = it.next();
|
||||
if (!entry)
|
||||
break;
|
||||
|
||||
Tld *tld = entry->value;
|
||||
if (tld->visib_mod == VisibModPrivate) {
|
||||
jw_array_elem(jw);
|
||||
anal_dump_decl_ref(ctx, tld);
|
||||
}
|
||||
}
|
||||
jw_end_array(jw);
|
||||
}
|
||||
|
||||
if (ty->data.enumeration.src_field_count != 0) {
|
||||
jw_object_field(jw, "fields");
|
||||
jw_begin_array(jw);
|
||||
|
||||
for(size_t i = 0; i < ty->data.enumeration.src_field_count; i += 1) {
|
||||
jw_array_elem(jw);
|
||||
jw_bigint(jw, &ty->data.enumeration.fields[i].value);
|
||||
}
|
||||
jw_end_array(jw);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ZigTypeIdFloat: {
|
||||
jw_object_field(jw, "bits");
|
||||
jw_int(jw, ty->data.floating.bit_count);
|
||||
|
||||
Reference in New Issue
Block a user