authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-10 13:36:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-10 13:36:56-04:00
log57fb55032401860546dff0f825539139217f85db
treedfcab9e1d4f28a8737d8cc3a647281a9ebff8764
parent6330dfbea6d5434dc694aebd0203ea13e2511a0e
parent78d06ec4af5e51b2c5fafe4d2556bcc1037f2446
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'Vexu-docs-union-enum'


3 files changed, 153 insertions(+), 6 deletions(-)

lib/std/io.zig+6
...@@ -17,9 +17,15 @@ const File = std.fs.File;...@@ -17,9 +17,15 @@ const File = std.fs.File;
17const testing = std.testing;17const testing = std.testing;
1818
19pub const Mode = enum {19pub const Mode = enum {
20 /// I/O operates normally, waiting for the operating system syscalls to complete.
20 blocking,21 blocking,
22
23 /// I/O functions are generated async and rely on a global event loop. Event-based I/O.
21 evented,24 evented,
22};25};
26
27/// The application's chosen I/O mode. This defaults to `Mode.blocking` but can be overridden
28/// by `root.event_loop`.
23pub const mode: Mode = if (@hasDecl(root, "io_mode"))29pub const mode: Mode = if (@hasDecl(root, "io_mode"))
24 root.io_mode30 root.io_mode
25else if (@hasDecl(root, "event_loop"))31else if (@hasDecl(root, "event_loop"))
lib/std/special/docs/main.js+10-3
...@@ -790,12 +790,19 @@...@@ -790,12 +790,19 @@
790790
791 var containerNode = zigAnalysis.astNodes[container.src];791 var containerNode = zigAnalysis.astNodes[container.src];
792 for (var i = 0; i < container.fields.length; i += 1) {792 for (var i = 0; i < container.fields.length; i += 1) {
793 var fieldTypeIndex = container.fields[i];793 var field = container.fields[i];
794 var fieldNode = zigAnalysis.astNodes[containerNode.fields[i]];794 var fieldNode = zigAnalysis.astNodes[containerNode.fields[i]];
795 var divDom = domListFields.children[i];795 var divDom = domListFields.children[i];
796796
797 var html = '<pre>' + escapeHtml(fieldNode.name) + ": " +797 var html = '<pre>' + escapeHtml(fieldNode.name);
798 typeIndexName(fieldTypeIndex, true, true) + ',</pre>';798
799 if (container.kind === typeKinds.Enum) {
800 html += ' = <span class="tok-number">' + field + '</span>';
801 } else {
802 html += ": " + typeIndexName(field, true, true);
803 }
804
805 html += ',</pre>';
799806
800 var docs = fieldNode.docs;807 var docs = fieldNode.docs;
801 if (docs != null) {808 if (docs != null) {
src/dump_analysis.cpp+137-3
...@@ -216,6 +216,21 @@ static void jw_int(JsonWriter *jw, int64_t x) {...@@ -216,6 +216,21 @@ static void jw_int(JsonWriter *jw, int64_t x) {
216 jw_pop_state(jw);216 jw_pop_state(jw);
217}217}
218218
219static void jw_bigint(JsonWriter *jw, const BigInt *x) {
220 assert(jw->state[jw->state_index] == JsonWriterStateValue);
221 Buf *str = buf_alloc();
222 bigint_append_buf(str, x, 10);
223
224 if (bigint_fits_in_bits(x, 52, true)) {
225 fprintf(jw->f, "%s", buf_ptr(str));
226 } else {
227 fprintf(jw->f, "\"%s\"", buf_ptr(str));
228 }
229 jw_pop_state(jw);
230
231 buf_destroy(str);
232}
233
219static void jw_string(JsonWriter *jw, const char *s) {234static void jw_string(JsonWriter *jw, const char *s) {
220 assert(jw->state[jw->state_index] == JsonWriterStateValue);235 assert(jw->state[jw->state_index] == JsonWriterStateValue);
221 jw_write_escaped_string(jw, s);236 jw_write_escaped_string(jw, s);
...@@ -754,6 +769,10 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -754,6 +769,10 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
754769
755 jw_object_field(jw, "name");770 jw_object_field(jw, "name");
756 jw_string(jw, buf_ptr(&ty->name));771 jw_string(jw, buf_ptr(&ty->name));
772
773 jw_object_field(jw, "src");
774 anal_dump_node_ref(ctx, ty->data.structure.decl_node);
775
757 {776 {
758 jw_object_field(jw, "pubDecls");777 jw_object_field(jw, "pubDecls");
759 jw_begin_array(jw);778 jw_begin_array(jw);
...@@ -794,9 +813,6 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -794,9 +813,6 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
794 jw_end_array(jw);813 jw_end_array(jw);
795 }814 }
796815
797 jw_object_field(jw, "src");
798 anal_dump_node_ref(ctx, ty->data.structure.decl_node);
799
800 if (ty->data.structure.src_field_count != 0) {816 if (ty->data.structure.src_field_count != 0) {
801 jw_object_field(jw, "fields");817 jw_object_field(jw, "fields");
802 jw_begin_array(jw);818 jw_begin_array(jw);
...@@ -816,6 +832,124 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -816,6 +832,124 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
816 }832 }
817 break;833 break;
818 }834 }
835 case ZigTypeIdUnion: {
836 jw_object_field(jw, "name");
837 jw_string(jw, buf_ptr(&ty->name));
838
839 jw_object_field(jw, "src");
840 anal_dump_node_ref(ctx, ty->data.unionation.decl_node);
841
842 {
843 jw_object_field(jw, "pubDecls");
844 jw_begin_array(jw);
845
846 ScopeDecls *decls_scope = ty->data.unionation.decls_scope;
847 auto it = decls_scope->decl_table.entry_iterator();
848 for (;;) {
849 auto *entry = it.next();
850 if (!entry)
851 break;
852
853 Tld *tld = entry->value;
854 if (tld->visib_mod == VisibModPub) {
855 jw_array_elem(jw);
856 anal_dump_decl_ref(ctx, tld);
857 }
858 }
859 jw_end_array(jw);
860 }
861
862 {
863 jw_object_field(jw, "privDecls");
864 jw_begin_array(jw);
865
866 ScopeDecls *decls_scope = ty->data.unionation.decls_scope;
867 auto it = decls_scope->decl_table.entry_iterator();
868 for (;;) {
869 auto *entry = it.next();
870 if (!entry)
871 break;
872
873 Tld *tld = entry->value;
874 if (tld->visib_mod == VisibModPrivate) {
875 jw_array_elem(jw);
876 anal_dump_decl_ref(ctx, tld);
877 }
878 }
879 jw_end_array(jw);
880 }
881
882 if (ty->data.unionation.src_field_count != 0) {
883 jw_object_field(jw, "fields");
884 jw_begin_array(jw);
885
886 for(size_t i = 0; i < ty->data.unionation.src_field_count; i += 1) {
887 jw_array_elem(jw);
888 anal_dump_type_ref(ctx, ty->data.unionation.fields[i].type_entry);
889 }
890 jw_end_array(jw);
891 }
892 break;
893 }
894 case ZigTypeIdEnum: {
895 jw_object_field(jw, "name");
896 jw_string(jw, buf_ptr(&ty->name));
897
898 jw_object_field(jw, "src");
899 anal_dump_node_ref(ctx, ty->data.enumeration.decl_node);
900
901 {
902 jw_object_field(jw, "pubDecls");
903 jw_begin_array(jw);
904
905 ScopeDecls *decls_scope = ty->data.enumeration.decls_scope;
906 auto it = decls_scope->decl_table.entry_iterator();
907 for (;;) {
908 auto *entry = it.next();
909 if (!entry)
910 break;
911
912 Tld *tld = entry->value;
913 if (tld->visib_mod == VisibModPub) {
914 jw_array_elem(jw);
915 anal_dump_decl_ref(ctx, tld);
916 }
917 }
918 jw_end_array(jw);
919 }
920
921 {
922 jw_object_field(jw, "privDecls");
923 jw_begin_array(jw);
924
925 ScopeDecls *decls_scope = ty->data.enumeration.decls_scope;
926 auto it = decls_scope->decl_table.entry_iterator();
927 for (;;) {
928 auto *entry = it.next();
929 if (!entry)
930 break;
931
932 Tld *tld = entry->value;
933 if (tld->visib_mod == VisibModPrivate) {
934 jw_array_elem(jw);
935 anal_dump_decl_ref(ctx, tld);
936 }
937 }
938 jw_end_array(jw);
939 }
940
941 if (ty->data.enumeration.src_field_count != 0) {
942 jw_object_field(jw, "fields");
943 jw_begin_array(jw);
944
945 for(size_t i = 0; i < ty->data.enumeration.src_field_count; i += 1) {
946 jw_array_elem(jw);
947 jw_bigint(jw, &ty->data.enumeration.fields[i].value);
948 }
949 jw_end_array(jw);
950 }
951 break;
952 }
819 case ZigTypeIdFloat: {953 case ZigTypeIdFloat: {
820 jw_object_field(jw, "bits");954 jw_object_field(jw, "bits");
821 jw_int(jw, ty->data.floating.bit_count);955 jw_int(jw, ty->data.floating.bit_count);