fix: handling more types of sentinels. now can be structs too

This commit is contained in:
Vallahor
2022-05-24 22:14:05 -03:00
committed by Andrew Kelley
parent d707cd6e6d
commit 2a3fb341aa
2 changed files with 86 additions and 40 deletions

View File

@@ -1062,6 +1062,30 @@ var zigAnalysis;
function exprName(expr, opts) {
switch (Object.keys(expr)[0]) {
default: throw "oh no";
case "struct": {
const struct_name = zigAnalysis.decls[expr.struct[0].val.typeRef.refPath[0].declRef].name;
let struct_body = "";
struct_body += struct_name + "{ ";
for (let i = 0; i < expr.struct.length; i++) {
const val = expr.struct[i].name
const exprArg = zigAnalysis.exprs[expr.struct[i].val.expr.as.exprArg];
let value_field = exprArg[Object.keys(exprArg)[0]];
if (value_field instanceof Object) {
value_field = zigAnalysis.decls[value_field[0].val.typeRef.refPath[0].declRef].name;
};
struct_body += "." + val + " = " + value_field;
if (i !== expr.struct.length - 1) {
struct_body += ", ";
} else {
struct_body += " ";
}
}
struct_body += "}";
return struct_body;
}
case "null": {
return "null";
}
case "array": {
let payloadHtml = ".{";
for (let i = 0; i < expr.array.length; i++) {
@@ -1141,7 +1165,7 @@ var zigAnalysis;
let arrayObj = /** @type {ArrayType} */ (typeObj);
let name = "[";
let lenName = exprName(arrayObj.len, opts);
let sentinel = arrayObj.sentinel ? ":0" : "";
let sentinel = arrayObj.sentinel ? ":"+exprName(arrayObj.sentinel, opts) : "";
let is_mutable = arrayObj.is_multable ? "const " : "";
if (opts.wantHtml) {
@@ -1160,7 +1184,7 @@ var zigAnalysis;
case typeKinds.Pointer:
{
let ptrObj = /** @type {PointerType} */(typeObj);
let sentinel = ptrObj.sentinel ? ":0" : "";
let sentinel = ptrObj.sentinel ? ":"+exprName(ptrObj.sentinel, opts) : "";
let is_mutable = !ptrObj.is_mutable ? "const " : "";
let name = "";
switch (ptrObj.size) {