authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-09 15:52:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-09 15:52:55-04:00
log8d5e3a2f332e1fb09da8b221888c87a6fbf18f8e
treef31180a35066bc675cf3ca6de593454e9474bdbf
parentc4e4fa22877d2929d585f1fea1b2fc82ec8e2d1d
signaturelock-open Commit is signed but in an unrecognized format.

generated docs: separate section for namespaces

if a type is a struct with no fields, then it goes in the namespaces section.

2 files changed, 38 insertions(+), 0 deletions(-)

lib/std/special/docs/index.html+5
......@@ -321,6 +321,11 @@
321321 <ul id="listTypes">
322322 </ul>
323323 </div>
324 <div id="sectNamespaces" class="hidden">
325 <h2>Namespaces</h2>
326 <ul id="listNamespaces">
327 </ul>
328 </div>
324329 <div id="sectGlobalVars" class="hidden">
325330 <h2>Global Variables</h2>
326331 <table>
lib/std/special/docs/main.js+33
......@@ -6,6 +6,8 @@
66 var domListPkgs = document.getElementById("listPkgs");
77 var domSectTypes = document.getElementById("sectTypes");
88 var domListTypes = document.getElementById("listTypes");
9 var domSectNamespaces = document.getElementById("sectNamespaces");
10 var domListNamespaces = document.getElementById("listNamespaces");
911 var domSectErrSets = document.getElementById("sectErrSets");
1012 var domListErrSets = document.getElementById("listErrSets");
1113 var domSectFns = document.getElementById("sectFns");
......@@ -47,6 +49,7 @@
4749 var typeKindNoReturnId;
4850 var typeKindErrSetId;
4951 var typeKindErrUnionId;
52 var typeKindStructId;
5053 findTypeKinds();
5154
5255 // for each package, is an array with packages to get to this one
......@@ -104,6 +107,7 @@
104107 domFnDocs.classList.add("hidden");
105108 domSectPkgs.classList.add("hidden");
106109 domSectTypes.classList.add("hidden");
110 domSectNamespaces.classList.add("hidden");
107111 domSectErrSets.classList.add("hidden");
108112 domSectFns.classList.add("hidden");
109113 domSectFields.classList.add("hidden");
......@@ -185,6 +189,13 @@
185189 return typeObj.kind === typeKindErrSetId;
186190 }
187191
192 function typeIsStructWithNoFields(typeIndex) {
193 var typeObj = zigAnalysis.types[typeIndex];
194 if (typeObj.kind !== typeKindStructId)
195 return false;
196 return typeObj.fields == null || typeObj.fields.length === 0;
197 }
198
188199 function typeIsGenericFn(typeIndex) {
189200 var typeObj = zigAnalysis.types[typeIndex];
190201 if (typeObj.kind !== typeKindFnId) {
......@@ -628,6 +639,7 @@
628639
629640 function renderContainer(container) {
630641 var typesList = [];
642 var namespacesList = [];
631643 var errSetsList = [];
632644 var fnsList = [];
633645 var varsList = [];
......@@ -641,6 +653,8 @@
641653 if (decl.type == typeTypeId) {
642654 if (typeIsErrSet(decl.value)) {
643655 errSetsList.push(decl);
656 } else if (typeIsStructWithNoFields(decl.value)) {
657 namespacesList.push(decl);
644658 } else {
645659 typesList.push(decl);
646660 }
......@@ -659,6 +673,9 @@
659673 typesList.sort(function(a, b) {
660674 return operatorCompare(a.name, b.name);
661675 });
676 namespacesList.sort(function(a, b) {
677 return operatorCompare(a.name, b.name);
678 });
662679 errSetsList.sort(function(a, b) {
663680 return operatorCompare(a.name, b.name);
664681 });
......@@ -680,6 +697,17 @@
680697 }
681698 domSectTypes.classList.remove("hidden");
682699 }
700 if (namespacesList.length !== 0) {
701 resizeDomList(domListNamespaces, namespacesList.length, '<li><a href="#"></a></li>');
702 for (var i = 0; i < namespacesList.length; i += 1) {
703 var liDom = domListNamespaces.children[i];
704 var aDom = liDom.children[0];
705 var decl = namespacesList[i];
706 aDom.textContent = decl.name;
707 aDom.setAttribute('href', navLinkDecl(decl.name));
708 }
709 domSectNamespaces.classList.remove("hidden");
710 }
683711
684712 if (errSetsList.length !== 0) {
685713 resizeDomList(domListErrSets, errSetsList.length, '<li><a href="#"></a></li>');
......@@ -816,6 +844,8 @@
816844 typeKindErrSetId = i;
817845 } else if (zigAnalysis.typeKinds[i] === "ErrorUnion") {
818846 typeKindErrUnionId = i;
847 } else if (zigAnalysis.typeKinds[i] === "Struct") {
848 typeKindStructId = i;
819849 }
820850 }
821851 if (typeKindTypeId == null) {
......@@ -848,6 +878,9 @@
848878 if (typeKindErrUnionId == null) {
849879 throw new Error("No type kind 'ErrorUnion' found");
850880 }
881 if (typeKindStructId == null) {
882 throw new Error("No type kind 'Struct' found");
883 }
851884 }
852885
853886 function findTypeTypeId() {