diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-10-08 13:41:13 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-10-08 13:41:13 -0400 |
| commit | 784a493dc7114b6e6807c2a37d03dbadecee81e6 (patch) | |
| tree | b2a9709664aed3f9a2d53aa4c233a3887aa93984 /lib/std | |
| parent | 03a6b33a73612500038635633d4c8326c2b5cf5f (diff) | |
| download | zig-784a493dc7114b6e6807c2a37d03dbadecee81e6.tar.gz zig-784a493dc7114b6e6807c2a37d03dbadecee81e6.zip | |
generated docs: functions with inferred error sets display nicely
infrastructure in place for displaying error sets
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/special/docs/index.html | 1 | ||||
| -rw-r--r-- | lib/std/special/docs/main.js | 64 |
2 files changed, 57 insertions, 8 deletions
diff --git a/lib/std/special/docs/index.html b/lib/std/special/docs/index.html index 23cdcc265c..05cbc3fb97 100644 --- a/lib/std/special/docs/index.html +++ b/lib/std/special/docs/index.html @@ -262,6 +262,7 @@ </div> <h1 id="hdrName" class="hidden"></h1> <div id="fnDocs" class="hidden"></div> + <div id="fnErrors" class="hidden"></div> <div id="fnExamples" class="hidden"></div> <div id="fnNoExamples" class="hidden"> <p>This function is not tested or referenced.</p> diff --git a/lib/std/special/docs/main.js b/lib/std/special/docs/main.js index 244fabad77..ccd43c3983 100644 --- a/lib/std/special/docs/main.js +++ b/lib/std/special/docs/main.js @@ -11,6 +11,7 @@ var domFnProto = document.getElementById("fnProto"); var domFnProtoCode = document.getElementById("fnProtoCode"); var domFnDocs = document.getElementById("fnDocs"); + var domFnErrors = document.getElementById("fnErrors"); var domFnExamples = document.getElementById("fnExamples"); var domFnNoExamples = document.getElementById("fnNoExamples"); var domSearch = document.getElementById("search"); @@ -33,6 +34,8 @@ var typeKindFloatId; var typeKindIntId; var typeKindBoolId; + var typeKindErrSetId; + var typeKindErrUnionId; findTypeKinds(); // for each package, is an array with packages to get to this one @@ -96,6 +99,7 @@ domSectInfo.classList.add("hidden"); domHdrName.classList.add("hidden"); domSectNav.classList.add("hidden"); + domFnErrors.classList.add("hidden"); domFnExamples.classList.add("hidden"); domFnNoExamples.classList.add("hidden"); @@ -183,7 +187,7 @@ protoHtml += ') '; if (typeObj.ret != null) { - protoHtml += typeIndexName(typeObj.ret, true, true); + protoHtml += typeIndexName(typeObj.ret, true, true, fnDecl.value); } else { protoHtml += '<span class="tok-kw">var</span>'; } @@ -335,24 +339,24 @@ } } - function typeIndexName(typeIndex, wantHtml, wantLink) { + function typeIndexName(typeIndex, wantHtml, wantLink, fnIndex) { var typeObj = zigAnalysis.types[typeIndex]; if (wantLink) { var declIndex = getCanonTypeDecl(typeIndex); var declPath = getCanonDeclPath(declIndex); var haveLink = declPath != null; - var typeNameHtml = typeName(typeObj, true, !haveLink); + var typeNameHtml = typeName(typeObj, true, !haveLink, fnIndex); if (haveLink) { return '<a href="' + navLink(declPath.pkgNames, declPath.declNames) + '">' + typeNameHtml + '</a>'; } else { return typeNameHtml; } } else { - return typeName(typeObj, wantHtml); + return typeName(typeObj, wantHtml, false, fnIndex); } } - function typeName(typeObj, wantHtml, wantSubLink) { + function typeName(typeObj, wantHtml, wantSubLink, fnIndex) { switch (typeObj.kind) { case typeKindPtrId: var name = ""; @@ -397,11 +401,22 @@ name += typeObj.align; } if (typeObj.hostIntBytes != null) { - name += ":" + typeObj.bitOffsetInHost + ":" + typeObj.hostIntBytes; + name += ":"; + if (wantHtml) { + name += '<span class="tok-number">' + typeObj.bitOffsetInHost + '</span>'; + } else { + name += typeObj.bitOffsetInHost; + } + name += ":"; + if (wantHtml) { + name += '<span class="tok-number">' + typeObj.hostIntBytes + '</span>'; + } else { + name += typeObj.hostIntBytes; + } } name += ") "; } - name += typeIndexName(typeObj.elem, wantHtml, wantSubLink); + name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null); return name; case typeKindFloatId: if (wantHtml) { @@ -429,6 +444,29 @@ } else { return "bool"; } + case typeKindErrSetId: + if (typeObj.errors == null) { + if (wantHtml) { + return '<span class="tok-type">anyerror</span>'; + } else { + return "anyerror"; + } + } else { + if (wantHtml) { + return escapeHtml(typeObj.name); + } else { + return typeObj.name; + } + } + case typeKindErrUnionId: + var errSetTypeObj = zigAnalysis.types[typeObj.err]; + var payloadHtml = typeIndexName(typeObj.payload, wantHtml, wantSubLink, null); + if (errSetTypeObj.fn != null && errSetTypeObj.fn == fnIndex) { + // function index parameter supplied and this is the inferred error set of it + return "!" + payloadHtml; + } else { + return typeIndexName(typeObj.err, wantHtml, wantSubLink, null) + "!" + payloadHtml; + } default: if (wantHtml) { return escapeHtml(typeObj.name); @@ -439,7 +477,7 @@ } function renderType(typeObj) { - var name = typeName(typeObj); + var name = typeName(typeObj, false, false); if (name != null && name != "") { domHdrName.innerText = zigAnalysis.typeKinds[typeObj.kind] + " " + name; domHdrName.classList.remove("hidden"); @@ -543,6 +581,10 @@ typeKindIntId = i; } else if (zigAnalysis.typeKinds[i] === "Bool") { typeKindBoolId = i; + } else if (zigAnalysis.typeKinds[i] === "ErrorSet") { + typeKindErrSetId = i; + } else if (zigAnalysis.typeKinds[i] === "ErrorUnion") { + typeKindErrUnionId = i; } } if (typeKindTypeId == null) { @@ -563,6 +605,12 @@ if (typeKindBoolId == null) { throw new Error("No type kind 'Bool' found"); } + if (typeKindErrSetId == null) { + throw new Error("No type kind 'ErrorSet' found"); + } + if (typeKindErrUnionId == null) { + throw new Error("No type kind 'ErrorUnion' found"); + } } function findTypeTypeId() { |
