mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
autodoc: add support for anytype and improve semantics for array length
This commit is contained in:
+111
-68
@@ -187,7 +187,7 @@
|
||||
i += 1;
|
||||
console.assert(isDecl(decl));
|
||||
if ("type" in decl.value) {
|
||||
return typeTypeId;
|
||||
return { type: typeTypeId };
|
||||
}
|
||||
|
||||
if ("declPath" in decl.value) {
|
||||
@@ -232,6 +232,10 @@
|
||||
return fn_type.ret;
|
||||
}
|
||||
|
||||
if ("void" in decl.value) {
|
||||
return { type: typeTypeId };
|
||||
}
|
||||
|
||||
console.log("TODO: handle in `typeOfDecl` more cases: ", decl);
|
||||
console.assert(false);
|
||||
throw {};
|
||||
@@ -472,22 +476,9 @@
|
||||
var html = '<pre>' + escapeHtml(fieldNode.name) + ": ";
|
||||
if (isVarArgs && i === typeObj.params.length - 1) {
|
||||
html += '...';
|
||||
} else if ("declRef" in value) {
|
||||
var decl = zigAnalysis.decls[value.declRef];
|
||||
var val = resolveValue(decl.value);
|
||||
var valType = zigAnalysis.types[argTypeIndex];
|
||||
|
||||
var valTypeName = typeShorthandName(valType);
|
||||
|
||||
html += '<a href="'+navLinkDecl(decl.name)+'">';
|
||||
html += '<span class="tok-kw" style="color:lightblue;">' + escapeHtml(decl.name) + '</span>';
|
||||
html += '</a>';
|
||||
html += ' ('+ valTypeName +')';
|
||||
} else if ("type" in value) {
|
||||
var name = zigAnalysis.types[value.type].name;
|
||||
html += '<span class="tok-kw">' + escapeHtml(name) + '</span>';
|
||||
} else {
|
||||
html += '<span class="tok-kw">var</span>';
|
||||
var name = typeValueName(value);
|
||||
html += '<span class="tok-kw">' + name + '</span>';
|
||||
}
|
||||
|
||||
html += ',</pre>';
|
||||
@@ -657,24 +648,52 @@
|
||||
}
|
||||
|
||||
function typeValueName(typeValue, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
|
||||
|
||||
if ("int" in typeValue) {
|
||||
return typeValue.int.value;
|
||||
}
|
||||
if ("call" in typeValue) {
|
||||
var result = "";
|
||||
var call = zigAnalysis.calls[typeValue.call];
|
||||
var functionName = typeValueName(call.func);
|
||||
result += functionName + "(";
|
||||
for (var j = 0; j < call.args.length; j += 1) {
|
||||
result += typeValueName(call.args[j]);
|
||||
if (j != call.args.length -1) result += ",";
|
||||
}
|
||||
|
||||
return result + ")";
|
||||
}
|
||||
if ("comptimeExpr" in typeValue) {
|
||||
return "[ComptimeExpr]";
|
||||
}
|
||||
if ("declPath" in typeValue) {
|
||||
if (typeValue.hasCte) {
|
||||
// TODO: find the cte, print it nicely
|
||||
if (wantLink) {
|
||||
return '<a href="">[ComptimeExpr]</a>';
|
||||
} else {
|
||||
return "[ComptimeExpr]";
|
||||
}
|
||||
}
|
||||
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;
|
||||
var result = "";
|
||||
for (var j = typeValue.declPath.length - 1; j >= 0; j--) {
|
||||
var decl = zigAnalysis.decls[typeValue.declPath[j]];
|
||||
|
||||
// TODO: handle nested decl paths properly!
|
||||
if (typeValue.hasCte) {
|
||||
if (wantHtml)
|
||||
result += "<a href=\"\">[ComptimeExpr]</a>";
|
||||
else
|
||||
result += "[ComptimeExpr]";
|
||||
break;
|
||||
}
|
||||
var name = escapeHtml(decl.name);
|
||||
if (wantHtml) {
|
||||
result += '<a href="'+navLinkDecl(decl.name)+'">';
|
||||
result += '<span class="tok-kw" style="color:lightblue;">' +
|
||||
name + '</span>';
|
||||
result += '</a>';
|
||||
} else {
|
||||
result += name;
|
||||
}
|
||||
|
||||
if (j != 0) result += ".";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
console.assert("type" in typeValue)
|
||||
@@ -760,10 +779,11 @@
|
||||
switch (typeObj.kind) {
|
||||
case typeKinds.Array:
|
||||
var name = "[";
|
||||
var lenName = typeValueName(typeObj.len, wantHtml);
|
||||
if (wantHtml) {
|
||||
name += '<span class="tok-number">' + typeObj.len + '</span>';
|
||||
name += '<span class="tok-number">' + lenName + '</span>';
|
||||
} else {
|
||||
name += typeObj.len;
|
||||
name += lenName;
|
||||
}
|
||||
name += "]";
|
||||
name += typeValueName(typeObj.child, wantHtml, wantSubLink, null);
|
||||
@@ -986,12 +1006,16 @@
|
||||
} else {
|
||||
var decl = zigAnalysis.decls[value.declPath[0]];
|
||||
var val = resolveValue(decl.value);
|
||||
var valType = zigAnalysis.types[argTypeIndex];
|
||||
|
||||
var valTypeName = typeShorthandName(valType);
|
||||
payloadHtml += '<a href="'+navLinkDecl(decl.name)+'">';
|
||||
payloadHtml += '<span class="tok-kw" style="color:lightblue;">' + escapeHtml(decl.name) + '</span>';
|
||||
payloadHtml += '</a>';
|
||||
if ("comptimeExpr" in val) {
|
||||
payloadHtml += "[ComptimeExpr]";
|
||||
} else {
|
||||
console.assert("type" in val);
|
||||
var valType = zigAnalysis.types[val.type];
|
||||
var valTypeName = typeShorthandName(valType);
|
||||
payloadHtml += '<a href="'+navLinkDecl(decl.name)+'">';
|
||||
payloadHtml += '<span class="tok-kw" style="color:lightblue;">' + escapeHtml(decl.name) + '</span>';
|
||||
payloadHtml += '</a>';
|
||||
}
|
||||
}
|
||||
} else if ("type" in value) {
|
||||
var name = typeValueName(value, false);
|
||||
@@ -1258,6 +1282,43 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declLen = container.privDecls ? container.privDecls.length : 0;
|
||||
for (var i = 0; i < declLen; i += 1) {
|
||||
var decl = zigAnalysis.decls[container.privDecls[i]];
|
||||
var declValue = resolveValue(decl.value);
|
||||
|
||||
if (decl.kind === 'var') {
|
||||
varsList.push(decl);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (decl.kind === 'const') {
|
||||
if (!("type" in declValue)){
|
||||
valsList.push(decl);
|
||||
} else {
|
||||
var value = zigAnalysis.types[declValue.type];
|
||||
var kind = value.kind;
|
||||
if (kind === typeKinds.Fn) {
|
||||
// TODO: handle CTE return types when we know their type.
|
||||
const resVal = resolveValue(value.ret);
|
||||
if ("type" in resVal && resVal.type == typeTypeId) {
|
||||
typesList.push(decl);
|
||||
} else {
|
||||
fnsList.push(decl);
|
||||
}
|
||||
|
||||
} else if (typeIsErrSet(declValue.type)) {
|
||||
errSetsList.push(decl);
|
||||
} else if (typeIsStructWithNoFields(declValue.type)) {
|
||||
namespacesList.push(decl);
|
||||
} else {
|
||||
typesList.push(decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typesList.sort(byNameProperty);
|
||||
namespacesList.sort(byNameProperty);
|
||||
errSetsList.sort(byNameProperty);
|
||||
@@ -1349,35 +1410,9 @@
|
||||
html += ": ";
|
||||
if (field.failure === true) {
|
||||
html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>';
|
||||
} else if ("declPath" in field) {
|
||||
for (var j = field.declPath.length - 1; j >= 0; j--) {
|
||||
var decl = zigAnalysis.decls[field.declPath[j]];
|
||||
|
||||
// TODO: handle nested decl paths properly!
|
||||
if (field.hasCte) {
|
||||
html += "<a href=\"\">[ComptimeExpr]</a>";
|
||||
break;
|
||||
}
|
||||
|
||||
html += '<a href="'+navLinkDecl(decl.name)+'">';
|
||||
html += '<span class="tok-kw" style="color:lightblue;">' +
|
||||
escapeHtml(decl.name) + '</span>';
|
||||
html += '</a>';
|
||||
if (j != 0) html += ".";
|
||||
}
|
||||
// at the end of the for loop this is the value of `decl`
|
||||
//decl = zigAnalysis.decls[field.declPath[0]];
|
||||
|
||||
var val = resolveValue(decl.value);
|
||||
console.assert("type" in val);
|
||||
var valType = zigAnalysis.types[val.type];
|
||||
var valTypeName = typeShorthandName(valType);
|
||||
html += ' ('+ valTypeName +')';
|
||||
} else if ("type" in field) {
|
||||
var name = zigAnalysis.types[field.type].name;
|
||||
html += '<span class="tok-kw">' + escapeHtml(name) + '</span>';
|
||||
} else {
|
||||
html += '<span class="tok-kw">var</span>';
|
||||
var name = typeValueName(field);
|
||||
html += '<span class="tok-kw">'+ name +'</span>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1544,6 +1579,14 @@
|
||||
return childDecl;
|
||||
}
|
||||
}
|
||||
if (!parentType.privDecls) return null;
|
||||
for (var i = 0; i < parentType.privDecls.length; i += 1) {
|
||||
var declIndex = parentType.privDecls[i];
|
||||
var childDecl = zigAnalysis.decls[declIndex];
|
||||
if (childDecl.name === childName) {
|
||||
return childDecl;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user