| ... | @@ -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 | } |
| 218 | | 218 | |
| | 219 | static 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 | |
| 219 | static void jw_string(JsonWriter *jw, const char *s) { | 234 | static 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) { |
| 754 | | 769 | |
| 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 | } |
| 796 | | 815 | |
| 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); |