diff options
| author | Timon Kruiper <timonkruiper@gmail.com> | 2019-10-10 14:21:35 +0200 |
|---|---|---|
| committer | Timon Kruiper <timonkruiper@gmail.com> | 2019-10-10 14:21:35 +0200 |
| commit | 4250d27fe500cf16701066277fd6643491e7ab09 (patch) | |
| tree | cfc2d2f3f9a24d0f608b07ef13b801dceda02cbc /src/dump_analysis.cpp | |
| parent | 12ed85d0d13136a5e8c1a54da5c3d2174cebee37 (diff) | |
| download | zig-4250d27fe500cf16701066277fd6643491e7ab09.tar.gz zig-4250d27fe500cf16701066277fd6643491e7ab09.zip | |
Generated docs: store static container info in a containerDecl astNode
And then get the struct field astNodes through the containerDecl astNode.
The type of a struct field is still stored in the types array, but the
static information is in the astNodes.
Diffstat (limited to 'src/dump_analysis.cpp')
| -rw-r--r-- | src/dump_analysis.cpp | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/src/dump_analysis.cpp b/src/dump_analysis.cpp index 35a249c92a..29a04b2d48 100644 --- a/src/dump_analysis.cpp +++ b/src/dump_analysis.cpp @@ -732,23 +732,6 @@ static void anal_dump_pointer_attrs(AnalDumpCtx *ctx, ZigType *ty) { anal_dump_type_ref(ctx, ty->data.pointer.child_type); } -static void anal_dump_struct_field(AnalDumpCtx *ctx, const TypeStructField *struct_field) { - JsonWriter *jw = &ctx->jw; - - jw_begin_object(jw); - - jw_object_field(jw, "name"); - jw_string(jw, buf_ptr(struct_field->name)); - - jw_object_field(jw, "type"); - anal_dump_type_ref(ctx, struct_field->type_entry); - - jw_object_field(jw, "src"); - anal_dump_node_ref(ctx, struct_field->decl_node); - - jw_end_object(jw); -} - static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { JsonWriter *jw = &ctx->jw; jw_array_elem(jw); @@ -811,13 +794,16 @@ 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); for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { jw_array_elem(jw); - anal_dump_struct_field(ctx, &ty->data.structure.fields[i]); + anal_dump_type_ref(ctx, ty->data.structure.fields[i].type_entry); } jw_end_array(jw); } @@ -827,7 +813,6 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { jw_object_field(jw, "file"); anal_dump_file_ref(ctx, path_buf); - } break; } @@ -974,6 +959,39 @@ static void anal_dump_node(AnalDumpCtx *ctx, const AstNode *node) { jw_string(jw, buf_ptr(doc_comments_buf)); } + const Buf *name_buf; + switch (node->type) { + case NodeTypeStructField: + name_buf = node->data.struct_field.name; + break; + default: + name_buf = nullptr; + break; + } + if (name_buf != nullptr) { + jw_object_field(jw, "name"); + jw_string(jw, buf_ptr(name_buf)); + } + + const ZigList<AstNode *> *fieldNodes; + switch (node->type) { + case NodeTypeContainerDecl: + fieldNodes = &node->data.container_decl.fields; + break; + default: + fieldNodes = nullptr; + break; + } + if (fieldNodes != nullptr) { + jw_object_field(jw, "fields"); + jw_begin_array(jw); + for (size_t i = 0; i < fieldNodes->length; i += 1) { + jw_array_elem(jw); + anal_dump_node_ref(ctx, fieldNodes->at(i)); + } + jw_end_array(jw); + } + jw_end_object(jw); } |
