mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-07 14:24:43 +00:00
autodoc: add frontend support for optionals & generic cleanup
This commit is contained in:
parent
fbf0d0bee9
commit
253e7e112e
1 changed files with 142 additions and 122 deletions
|
|
@ -149,8 +149,9 @@
|
|||
while(i < 1000) {
|
||||
i += 1;
|
||||
|
||||
if ("declRef" in value) {
|
||||
value = zigAnalysis.decls[value.declRef].value;
|
||||
if ("declPath" in value) {
|
||||
console.assert(value.declPath.length == 1); // only support declRefs for now
|
||||
value = zigAnalysis.decls[value.declPath[0]].value;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -169,8 +170,9 @@
|
|||
return typeTypeId;
|
||||
}
|
||||
|
||||
if ("declRef" in decl.value) {
|
||||
decl = zigAnalysis.decls[decl.value.declRef];
|
||||
if ("declPath" in decl.value) {
|
||||
console.assert(decl.value.declPath.length == 1); // only support declRefs for now
|
||||
decl = zigAnalysis.decls[decl.value.declPath[0]];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -193,6 +195,7 @@
|
|||
|
||||
console.log("TODO: handle in `typeOfDecl` more cases: ", decl);
|
||||
console.assert(false);
|
||||
throw {};
|
||||
}
|
||||
console.assert(false);
|
||||
}
|
||||
|
|
@ -637,6 +640,25 @@
|
|||
}
|
||||
|
||||
function typeIndexName(typeIndex, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
|
||||
return typeValueName({ type: typeIndex }, wantHtml, wantLink, fnDecl, linkFnNameDecl);
|
||||
}
|
||||
|
||||
function typeValueName(typeValue, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
|
||||
if ("declPath" in typeValue) {
|
||||
console.assert(typeValue.declPath.length == 1);
|
||||
var declIndex = typeValue.declPath[0];
|
||||
var name = zigAnalysis.decls[declIndex].name;
|
||||
var declPath = getCanonDeclPath(declIndex);
|
||||
if (wantLink) {
|
||||
var nl = navLink(declPath.pkgNames, declPath.declNames);
|
||||
return '<a href="' + nl + '">' + name + '</a>';
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
console.assert("type" in typeValue)
|
||||
var typeIndex = typeValue.type;
|
||||
var typeObj = zigAnalysis.types[typeIndex];
|
||||
var declNameOk = declCanRepresentTypeKind(typeObj.kind);
|
||||
if (wantLink) {
|
||||
|
|
@ -714,10 +736,11 @@
|
|||
name += typeObj.len;
|
||||
}
|
||||
name += "]";
|
||||
name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null);
|
||||
name += typeValueName(typeObj.elem, wantHtml, wantSubLink, null);
|
||||
return name;
|
||||
case typeKinds.Optional:
|
||||
return "?" + typeIndexName(typeObj.child, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
|
||||
|
||||
return "?" + typeValueName(typeObj.child, wantHtml, wantSubLink, fnDecl, linkFnNameDecl);
|
||||
case typeKinds.Pointer:
|
||||
var name = "";
|
||||
switch (typeObj.len) {
|
||||
|
|
@ -776,7 +799,7 @@
|
|||
}
|
||||
name += ") ";
|
||||
}
|
||||
name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null);
|
||||
name += typeValueName(typeObj.elem, wantHtml, wantSubLink, null);
|
||||
return name;
|
||||
case typeKinds.Float:
|
||||
if (wantHtml) {
|
||||
|
|
@ -949,13 +972,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
var retValue = resolveValue(typeObj.ret);
|
||||
console.assert("type" in retValue);
|
||||
var retTypeIndex = retValue.type;
|
||||
|
||||
payloadHtml += ') ';
|
||||
if (retTypeIndex != null) {
|
||||
payloadHtml += typeIndexName(retTypeIndex, wantHtml, wantSubLink, fnDecl);
|
||||
if (typeObj.ret != null) {
|
||||
payloadHtml += typeValueName(typeObj.ret, wantHtml, wantSubLink, fnDecl);
|
||||
} else if (wantHtml) {
|
||||
payloadHtml += '<span class="tok-kw">anytype</span>';
|
||||
} else {
|
||||
|
|
@ -1295,8 +1314,9 @@
|
|||
if (typeof(field) === 'object') {
|
||||
if (field.failure === true) {
|
||||
html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>';
|
||||
} else if ("declRef" in field) {
|
||||
var decl = zigAnalysis.decls[field.declRef];
|
||||
} else if ("declPath" in field) {
|
||||
console.assert(field.declPath.lenght == 1);
|
||||
var decl = zigAnalysis.decls[field.declPath[0]];
|
||||
var val = resolveValue(decl.value);
|
||||
console.assert("type" in val);
|
||||
var valType = zigAnalysis.types[val.type];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue