| ... | @@ -216,6 +216,19 @@ static void jw_int(JsonWriter *jw, int64_t x) { | ... | @@ -216,6 +216,19 @@ 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 | |
| 219 | static void jw_string(JsonWriter *jw, const char *s) { | 232 | static void jw_string(JsonWriter *jw, const char *s) { |
| 220 | assert(jw->state[jw->state_index] == JsonWriterStateValue); | 233 | assert(jw->state[jw->state_index] == JsonWriterStateValue); |
| 221 | jw_write_escaped_string(jw, s); | 234 | jw_write_escaped_string(jw, s); |
| ... | @@ -749,6 +762,40 @@ static void anal_dump_struct_field(AnalDumpCtx *ctx, const TypeStructField *stru | ... | @@ -749,6 +762,40 @@ static void anal_dump_struct_field(AnalDumpCtx *ctx, const TypeStructField *stru |
| 749 | jw_end_object(jw); | 762 | jw_end_object(jw); |
| 750 | } | 763 | } |
| 751 | | 764 | |
| | 765 | static void anal_dump_union_field(AnalDumpCtx *ctx, const TypeUnionField *union_field) { |
| | 766 | JsonWriter *jw = &ctx->jw; |
| | 767 | |
| | 768 | jw_begin_object(jw); |
| | 769 | |
| | 770 | jw_object_field(jw, "name"); |
| | 771 | jw_string(jw, buf_ptr(union_field->name)); |
| | 772 | |
| | 773 | jw_object_field(jw, "type"); |
| | 774 | anal_dump_type_ref(ctx, union_field->type_entry); |
| | 775 | |
| | 776 | jw_object_field(jw, "src"); |
| | 777 | anal_dump_node_ref(ctx, union_field->decl_node); |
| | 778 | |
| | 779 | jw_end_object(jw); |
| | 780 | } |
| | 781 | |
| | 782 | static void anal_dump_enum_field(AnalDumpCtx *ctx, const TypeEnumField *enum_field) { |
| | 783 | JsonWriter *jw = &ctx->jw; |
| | 784 | |
| | 785 | jw_begin_object(jw); |
| | 786 | |
| | 787 | jw_object_field(jw, "name"); |
| | 788 | jw_string(jw, buf_ptr(enum_field->name)); |
| | 789 | |
| | 790 | jw_object_field(jw, "value"); |
| | 791 | jw_bigint(jw, &enum_field->value); |
| | 792 | |
| | 793 | jw_object_field(jw, "src"); |
| | 794 | anal_dump_node_ref(ctx, enum_field->decl_node); |
| | 795 | |
| | 796 | jw_end_object(jw); |
| | 797 | } |
| | 798 | |
| 752 | static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { | 799 | static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { |
| 753 | JsonWriter *jw = &ctx->jw; | 800 | JsonWriter *jw = &ctx->jw; |
| 754 | jw_array_elem(jw); | 801 | jw_array_elem(jw); |
| ... | @@ -831,6 +878,116 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { | ... | @@ -831,6 +878,116 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { |
| 831 | } | 878 | } |
| 832 | break; | 879 | break; |
| 833 | } | 880 | } |
| | 881 | case ZigTypeIdUnion: { |
| | 882 | jw_object_field(jw, "name"); |
| | 883 | jw_string(jw, buf_ptr(&ty->name)); |
| | 884 | { |
| | 885 | jw_object_field(jw, "pubDecls"); |
| | 886 | jw_begin_array(jw); |
| | 887 | |
| | 888 | ScopeDecls *decls_scope = ty->data.unionation.decls_scope; |
| | 889 | auto it = decls_scope->decl_table.entry_iterator(); |
| | 890 | for (;;) { |
| | 891 | auto *entry = it.next(); |
| | 892 | if (!entry) |
| | 893 | break; |
| | 894 | |
| | 895 | Tld *tld = entry->value; |
| | 896 | if (tld->visib_mod == VisibModPub) { |
| | 897 | jw_array_elem(jw); |
| | 898 | anal_dump_decl_ref(ctx, tld); |
| | 899 | } |
| | 900 | } |
| | 901 | jw_end_array(jw); |
| | 902 | } |
| | 903 | |
| | 904 | { |
| | 905 | jw_object_field(jw, "privDecls"); |
| | 906 | jw_begin_array(jw); |
| | 907 | |
| | 908 | ScopeDecls *decls_scope = ty->data.unionation.decls_scope; |
| | 909 | auto it = decls_scope->decl_table.entry_iterator(); |
| | 910 | for (;;) { |
| | 911 | auto *entry = it.next(); |
| | 912 | if (!entry) |
| | 913 | break; |
| | 914 | |
| | 915 | Tld *tld = entry->value; |
| | 916 | if (tld->visib_mod == VisibModPrivate) { |
| | 917 | jw_array_elem(jw); |
| | 918 | anal_dump_decl_ref(ctx, tld); |
| | 919 | } |
| | 920 | } |
| | 921 | jw_end_array(jw); |
| | 922 | } |
| | 923 | |
| | 924 | if (ty->data.unionation.src_field_count != 0) { |
| | 925 | jw_object_field(jw, "fields"); |
| | 926 | jw_begin_array(jw); |
| | 927 | |
| | 928 | for(size_t i = 0; i < ty->data.unionation.src_field_count; i += 1) { |
| | 929 | jw_array_elem(jw); |
| | 930 | anal_dump_union_field(ctx, &ty->data.unionation.fields[i]); |
| | 931 | } |
| | 932 | jw_end_array(jw); |
| | 933 | } |
| | 934 | break; |
| | 935 | } |
| | 936 | case ZigTypeIdEnum: { |
| | 937 | jw_object_field(jw, "name"); |
| | 938 | jw_string(jw, buf_ptr(&ty->name)); |
| | 939 | { |
| | 940 | jw_object_field(jw, "pubDecls"); |
| | 941 | jw_begin_array(jw); |
| | 942 | |
| | 943 | ScopeDecls *decls_scope = ty->data.enumeration.decls_scope; |
| | 944 | auto it = decls_scope->decl_table.entry_iterator(); |
| | 945 | for (;;) { |
| | 946 | auto *entry = it.next(); |
| | 947 | if (!entry) |
| | 948 | break; |
| | 949 | |
| | 950 | Tld *tld = entry->value; |
| | 951 | if (tld->visib_mod == VisibModPub) { |
| | 952 | jw_array_elem(jw); |
| | 953 | anal_dump_decl_ref(ctx, tld); |
| | 954 | } |
| | 955 | } |
| | 956 | jw_end_array(jw); |
| | 957 | } |
| | 958 | |
| | 959 | { |
| | 960 | jw_object_field(jw, "privDecls"); |
| | 961 | jw_begin_array(jw); |
| | 962 | |
| | 963 | ScopeDecls *decls_scope = ty->data.enumeration.decls_scope; |
| | 964 | auto it = decls_scope->decl_table.entry_iterator(); |
| | 965 | for (;;) { |
| | 966 | auto *entry = it.next(); |
| | 967 | if (!entry) |
| | 968 | break; |
| | 969 | |
| | 970 | Tld *tld = entry->value; |
| | 971 | if (tld->visib_mod == VisibModPrivate) { |
| | 972 | jw_array_elem(jw); |
| | 973 | anal_dump_decl_ref(ctx, tld); |
| | 974 | } |
| | 975 | } |
| | 976 | jw_end_array(jw); |
| | 977 | } |
| | 978 | |
| | 979 | if (ty->data.enumeration.src_field_count != 0) { |
| | 980 | jw_object_field(jw, "fields"); |
| | 981 | jw_begin_array(jw); |
| | 982 | |
| | 983 | for(size_t i = 0; i < ty->data.enumeration.src_field_count; i += 1) { |
| | 984 | jw_array_elem(jw); |
| | 985 | anal_dump_enum_field(ctx, &ty->data.enumeration.fields[i]); |
| | 986 | } |
| | 987 | jw_end_array(jw); |
| | 988 | } |
| | 989 | break; |
| | 990 | } |
| 834 | case ZigTypeIdFloat: { | 991 | case ZigTypeIdFloat: { |
| 835 | jw_object_field(jw, "bits"); | 992 | jw_object_field(jw, "bits"); |
| 836 | jw_int(jw, ty->data.floating.bit_count); | 993 | jw_int(jw, ty->data.floating.bit_count); |