authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2019-10-08 22:57:28+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-08 17:29:03-04:00
logf74c29b49a550e5e7029fde46de93068a9eecb46
treec58a5909e5268bf79a3e04270557403cfa721e8e
parent1e59eb3c94ed459620a3504fb3c5110be92efced

Add initial support for struct fields in the docs


3 files changed, 49 insertions(+), 0 deletions(-)

lib/std/special/docs/index.html+5
...@@ -275,6 +275,11 @@...@@ -275,6 +275,11 @@
275 <h2>No Results Found</h2>275 <h2>No Results Found</h2>
276 <p>Press escape to exit search and then '?' to see more options.</p>276 <p>Press escape to exit search and then '?' to see more options.</p>
277 </div>277 </div>
278 <div id="sectFields" class="hidden">
279 <h2>Fields</h2>
280 <ul id="listFields">
281 </ul>
282 </div>
278 <div id="sectTypes" class="hidden">283 <div id="sectTypes" class="hidden">
279 <h2>Types</h2>284 <h2>Types</h2>
280 <ul id="listTypes">285 <ul id="listTypes">
lib/std/special/docs/main.js+16
...@@ -8,6 +8,8 @@...@@ -8,6 +8,8 @@
8 var domListTypes = document.getElementById("listTypes");8 var domListTypes = document.getElementById("listTypes");
9 var domSectFns = document.getElementById("sectFns");9 var domSectFns = document.getElementById("sectFns");
10 var domListFns = document.getElementById("listFns");10 var domListFns = document.getElementById("listFns");
11 var domSectFields = document.getElementById("sectFields");
12 var domListFields = document.getElementById("listFields");
11 var domFnProto = document.getElementById("fnProto");13 var domFnProto = document.getElementById("fnProto");
12 var domFnProtoCode = document.getElementById("fnProtoCode");14 var domFnProtoCode = document.getElementById("fnProtoCode");
13 var domFnDocs = document.getElementById("fnDocs");15 var domFnDocs = document.getElementById("fnDocs");
...@@ -94,6 +96,7 @@...@@ -94,6 +96,7 @@
94 domSectPkgs.classList.add("hidden");96 domSectPkgs.classList.add("hidden");
95 domSectTypes.classList.add("hidden");97 domSectTypes.classList.add("hidden");
96 domSectFns.classList.add("hidden");98 domSectFns.classList.add("hidden");
99 domSectFields.classList.add("hidden");
97 domSectSearchResults.classList.add("hidden");100 domSectSearchResults.classList.add("hidden");
98 domSectSearchNoResults.classList.add("hidden");101 domSectSearchNoResults.classList.add("hidden");
99 domSectInfo.classList.add("hidden");102 domSectInfo.classList.add("hidden");
...@@ -545,6 +548,19 @@...@@ -545,6 +548,19 @@
545 }548 }
546 domSectFns.classList.remove("hidden");549 domSectFns.classList.remove("hidden");
547 }550 }
551
552 if (container.fields.length !== 0) {
553 resizeDomList(domListFields, container.fields.length, '<li></li>');
554 for (var i = 0; i < container.fields.length; i += 1) {
555 var liDom = domListFields.children[i];
556 var field = container.fields[i];
557
558 var protoHtml = escapeHtml(field.name) + ": ";
559 protoHtml += typeIndexName(field.type, true, true);
560 liDom.innerHTML = protoHtml;
561 }
562 domSectFields.classList.remove("hidden");
563 }
548 }564 }
549565
550 function operatorCompare(a, b) {566 function operatorCompare(a, b) {
src/dump_analysis.cpp+28
...@@ -732,6 +732,23 @@ static void anal_dump_pointer_attrs(AnalDumpCtx *ctx, ZigType *ty) {...@@ -732,6 +732,23 @@ static void anal_dump_pointer_attrs(AnalDumpCtx *ctx, ZigType *ty) {
732 anal_dump_type_ref(ctx, ty->data.pointer.child_type);732 anal_dump_type_ref(ctx, ty->data.pointer.child_type);
733}733}
734734
735static void anal_dump_struct_field(AnalDumpCtx *ctx, const TypeStructField *struct_field) {
736 JsonWriter *jw = &ctx->jw;
737
738 jw_begin_object(jw);
739
740 jw_object_field(jw, "name");
741 jw_string(jw, buf_ptr(struct_field->name));
742
743 jw_object_field(jw, "type");
744 anal_dump_type_ref(ctx, struct_field->type_entry);
745
746 jw_object_field(jw, "src");
747 anal_dump_node_ref(ctx, struct_field->decl_node);
748
749 jw_end_object(jw);
750}
751
735static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {752static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
736 JsonWriter *jw = &ctx->jw;753 JsonWriter *jw = &ctx->jw;
737 jw_array_elem(jw);754 jw_array_elem(jw);
...@@ -794,6 +811,17 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {...@@ -794,6 +811,17 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
794 jw_end_array(jw);811 jw_end_array(jw);
795 }812 }
796813
814 {
815 jw_object_field(jw, "fields");
816 jw_begin_array(jw);
817
818 for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) {
819 jw_array_elem(jw);
820 anal_dump_struct_field(ctx, &ty->data.structure.fields[i]);
821 }
822 jw_end_array(jw);
823 }
824
797 if (ty->data.structure.root_struct != nullptr) {825 if (ty->data.structure.root_struct != nullptr) {
798 Buf *path_buf = ty->data.structure.root_struct->path;826 Buf *path_buf = ty->data.structure.root_struct->path;
799827