zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 78d06ec4af5e51b2c5fafe4d2556bcc1037f2446 (tree)
parent 6330dfbea6d5434dc694aebd0203ea13e2511a0e
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 10 Oct 2019 13:36:37 -0400

Merge branch 'docs-union-enum' of https://github.com/Vexu/zig into Vexu-docs-union-enum

Diffstat:
Mlib/std/io.zig | 6++++++
Mlib/std/special/docs/main.js | 13++++++++++---
Msrc/dump_analysis.cpp | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 153 insertions(+), 6 deletions(-)

diff --git a/lib/std/io.zig b/lib/std/io.zig @@ -17,9 +17,15 @@ const File = std.fs.File; const testing = std.testing; pub const Mode = enum { + /// I/O operates normally, waiting for the operating system syscalls to complete. blocking, + + /// I/O functions are generated async and rely on a global event loop. Event-based I/O. evented, }; + +/// The application's chosen I/O mode. This defaults to `Mode.blocking` but can be overridden +/// by `root.event_loop`. pub const mode: Mode = if (@hasDecl(root, "io_mode")) root.io_mode else if (@hasDecl(root, "event_loop")) diff --git a/lib/std/special/docs/main.js b/lib/std/special/docs/main.js @@ -790,12 +790,19 @@ var containerNode = zigAnalysis.astNodes[container.src]; for (var i = 0; i < container.fields.length; i += 1) { - var fieldTypeIndex = container.fields[i]; + var field = container.fields[i]; var fieldNode = zigAnalysis.astNodes[containerNode.fields[i]]; var divDom = domListFields.children[i]; - var html = '<pre>' + escapeHtml(fieldNode.name) + ": " + - typeIndexName(fieldTypeIndex, true, true) + ',</pre>'; + var html = '<pre>' + escapeHtml(fieldNode.name); + + if (container.kind === typeKinds.Enum) { + html += ' = <span class="tok-number">' + field + '</span>'; + } else { + html += ": " + typeIndexName(field, true, true); + } + + html += ',</pre>'; var docs = fieldNode.docs; if (docs != null) { diff --git a/src/dump_analysis.cpp b/src/dump_analysis.cpp @@ -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);