authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-09-10 21:08:26+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-09-11 21:35:01+02:00
log2a96f80d03c70546e5166e7752ee2b4b64c7cc5f
tree7f70dd408413dba97d039afdee3a62a261c322e4
parent81939a4939638fb296bc874afcef2f0f141f5c0c

autodoc: reduce json payload size

this commit removes whitespace and changes Decl, AstNode and Type to be json arrays instead of json objects. This change reduces json payload size for the stdlib from 25mb to < 10mb.

2 files changed, 309 insertions(+), 80 deletions(-)

lib/docs/main.js+226-61
...@@ -203,7 +203,7 @@ var zigAnalysis;...@@ -203,7 +203,7 @@ var zigAnalysis;
203 if (!("type" in resolvedExpr)) {203 if (!("type" in resolvedExpr)) {
204 return null;204 return null;
205 }205 }
206 let type = zigAnalysis.types[resolvedExpr.type];206 let type = getType(resolvedExpr.type);
207207
208 outer: for (let i = 0; i < 10000; i += 1) {208 outer: for (let i = 0; i < 10000; i += 1) {
209 switch (type.kind) {209 switch (type.kind) {
...@@ -212,7 +212,7 @@ var zigAnalysis;...@@ -212,7 +212,7 @@ var zigAnalysis;
212 let child = type.child;212 let child = type.child;
213 let resolvedChild = resolveValue(child);213 let resolvedChild = resolveValue(child);
214 if ("type" in resolvedChild) {214 if ("type" in resolvedChild) {
215 type = zigAnalysis.types[resolvedChild.type];215 type = getType(resolvedChild.type);
216 continue;216 continue;
217 } else {217 } else {
218 return null;218 return null;
...@@ -276,7 +276,7 @@ var zigAnalysis;...@@ -276,7 +276,7 @@ var zigAnalysis;
276 }276 }
277277
278 if ("declRef" in value.expr) {278 if ("declRef" in value.expr) {
279 value = zigAnalysis.decls[value.expr.declRef].value;279 value = getDecl(value.expr.declRef).value;
280 continue;280 continue;
281 }281 }
282282
...@@ -430,7 +430,7 @@ var zigAnalysis;...@@ -430,7 +430,7 @@ var zigAnalysis;
430 curNav.pkgObjs.push(pkg);430 curNav.pkgObjs.push(pkg);
431 }431 }
432432
433 let currentType = zigAnalysis.types[pkg.main];433 let currentType = getType(pkg.main);
434 curNav.declObjs = [currentType];434 curNav.declObjs = [currentType];
435 for (let i = 0; i < curNav.declNames.length; i += 1) {435 for (let i = 0; i < curNav.declNames.length; i += 1) {
436 let childDecl = findSubDecl(currentType, curNav.declNames[i]);436 let childDecl = findSubDecl(currentType, curNav.declNames[i]);
...@@ -440,7 +440,7 @@ var zigAnalysis;...@@ -440,7 +440,7 @@ var zigAnalysis;
440440
441 let childDeclValue = resolveValue(childDecl.value).expr;441 let childDeclValue = resolveValue(childDecl.value).expr;
442 if ("type" in childDeclValue) {442 if ("type" in childDeclValue) {
443 const t = zigAnalysis.types[childDeclValue.type];443 const t = getType(childDeclValue.type);
444 if (t.kind != typeKinds.Fn) {444 if (t.kind != typeKinds.Fn) {
445 childDecl = t;445 childDecl = t;
446 }446 }
...@@ -478,7 +478,7 @@ var zigAnalysis;...@@ -478,7 +478,7 @@ var zigAnalysis;
478 }478 }
479479
480 if (lastIsDecl && last.kind === "const") {480 if (lastIsDecl && last.kind === "const") {
481 let typeObj = zigAnalysis.types[resolveValue(last.value).expr.type];481 let typeObj = getType(resolveValue(last.value).expr.type);
482 if (typeObj && typeObj.kind === typeKinds.Fn) {482 if (typeObj && typeObj.kind === typeKinds.Fn) {
483 return renderFn(last);483 return renderFn(last);
484 }484 }
...@@ -489,8 +489,8 @@ var zigAnalysis;...@@ -489,8 +489,8 @@ var zigAnalysis;
489 }489 }
490 490
491 function renderDocTest(decl) {491 function renderDocTest(decl) {
492 if (!("decltest" in decl)) return;492 if (!decl.decltest) return;
493 const astNode = zigAnalysis.astNodes[decl.decltest];493 const astNode = getAstNode(decl.decltest);
494 domSectDocTests.classList.remove("hidden");494 domSectDocTests.classList.remove("hidden");
495 domDocTestsCode.innerHTML = astNode.code;495 domDocTestsCode.innerHTML = astNode.code;
496 }496 }
...@@ -498,7 +498,7 @@ var zigAnalysis;...@@ -498,7 +498,7 @@ var zigAnalysis;
498 function renderUnknownDecl(decl) {498 function renderUnknownDecl(decl) {
499 domDeclNoRef.classList.remove("hidden");499 domDeclNoRef.classList.remove("hidden");
500500
501 let docs = zigAnalysis.astNodes[decl.src].docs;501 let docs = getAstNode(decl.src).docs;
502 if (docs != null) {502 if (docs != null) {
503 domTldDocs.innerHTML = markdown(docs);503 domTldDocs.innerHTML = markdown(docs);
504 } else {504 } else {
...@@ -509,18 +509,18 @@ var zigAnalysis;...@@ -509,18 +509,18 @@ var zigAnalysis;
509 }509 }
510510
511 function typeIsErrSet(typeIndex) {511 function typeIsErrSet(typeIndex) {
512 let typeObj = zigAnalysis.types[typeIndex];512 let typeObj = getType(typeIndex);
513 return typeObj.kind === typeKinds.ErrorSet;513 return typeObj.kind === typeKinds.ErrorSet;
514 }514 }
515515
516 function typeIsStructWithNoFields(typeIndex) {516 function typeIsStructWithNoFields(typeIndex) {
517 let typeObj = zigAnalysis.types[typeIndex];517 let typeObj = getType(typeIndex);
518 if (typeObj.kind !== typeKinds.Struct) return false;518 if (typeObj.kind !== typeKinds.Struct) return false;
519 return typeObj.fields.length == 0;519 return typeObj.fields.length == 0;
520 }520 }
521521
522 function typeIsGenericFn(typeIndex) {522 function typeIsGenericFn(typeIndex) {
523 let typeObj = zigAnalysis.types[typeIndex];523 let typeObj = getType(typeIndex);
524 if (typeObj.kind !== typeKinds.Fn) {524 if (typeObj.kind !== typeKinds.Fn) {
525 return false;525 return false;
526 }526 }
...@@ -532,12 +532,12 @@ var zigAnalysis;...@@ -532,12 +532,12 @@ var zigAnalysis;
532 let last = fnDecl.value.expr.refPath.length - 1;532 let last = fnDecl.value.expr.refPath.length - 1;
533 let lastExpr = fnDecl.value.expr.refPath[last];533 let lastExpr = fnDecl.value.expr.refPath[last];
534 console.assert("declRef" in lastExpr);534 console.assert("declRef" in lastExpr);
535 fnDecl = zigAnalysis.decls[lastExpr.declRef];535 fnDecl = getDecl(lastExpr.declRef);
536 }536 }
537537
538 let value = resolveValue(fnDecl.value);538 let value = resolveValue(fnDecl.value);
539 console.assert("type" in value.expr);539 console.assert("type" in value.expr);
540 let typeObj = zigAnalysis.types[value.expr.type];540 let typeObj = getType(value.expr.type);
541541
542 domFnProtoCode.innerHTML = exprName(value.expr, {542 domFnProtoCode.innerHTML = exprName(value.expr, {
543 wantHtml: true,543 wantHtml: true,
...@@ -546,7 +546,7 @@ var zigAnalysis;...@@ -546,7 +546,7 @@ var zigAnalysis;
546 });546 });
547547
548 let docsSource = null;548 let docsSource = null;
549 let srcNode = zigAnalysis.astNodes[fnDecl.src];549 let srcNode = getAstNode(fnDecl.src);
550 if (srcNode.docs != null) {550 if (srcNode.docs != null) {
551 docsSource = srcNode.docs;551 docsSource = srcNode.docs;
552 }552 }
...@@ -557,14 +557,14 @@ var zigAnalysis;...@@ -557,14 +557,14 @@ var zigAnalysis;
557 if ("type" in retExpr) {557 if ("type" in retExpr) {
558 let retIndex = retExpr.type;558 let retIndex = retExpr.type;
559 let errSetTypeIndex = null;559 let errSetTypeIndex = null;
560 let retType = zigAnalysis.types[retIndex];560 let retType = getType(retIndex);
561 if (retType.kind === typeKinds.ErrorSet) {561 if (retType.kind === typeKinds.ErrorSet) {
562 errSetTypeIndex = retIndex;562 errSetTypeIndex = retIndex;
563 } else if (retType.kind === typeKinds.ErrorUnion) {563 } else if (retType.kind === typeKinds.ErrorUnion) {
564 errSetTypeIndex = retType.err.type;564 errSetTypeIndex = retType.err.type;
565 }565 }
566 if (errSetTypeIndex != null) {566 if (errSetTypeIndex != null) {
567 let errSetType = zigAnalysis.types[errSetTypeIndex];567 let errSetType = getType(errSetTypeIndex);
568 renderErrorSet(errSetType);568 renderErrorSet(errSetType);
569 }569 }
570 }570 }
...@@ -578,7 +578,7 @@ var zigAnalysis;...@@ -578,7 +578,7 @@ var zigAnalysis;
578 let call = zigAnalysis.calls[resolvedGenericRet.expr.call];578 let call = zigAnalysis.calls[resolvedGenericRet.expr.call];
579 let resolvedFunc = resolveValue({ expr: call.func });579 let resolvedFunc = resolveValue({ expr: call.func });
580 if (!("type" in resolvedFunc.expr)) return;580 if (!("type" in resolvedFunc.expr)) return;
581 let callee = zigAnalysis.types[resolvedFunc.expr.type];581 let callee = getType(resolvedFunc.expr.type);
582 if (!callee.generic_ret) return;582 if (!callee.generic_ret) return;
583 resolvedGenericRet = resolveValue({ expr: callee.generic_ret });583 resolvedGenericRet = resolveValue({ expr: callee.generic_ret });
584 }584 }
...@@ -591,7 +591,7 @@ var zigAnalysis;...@@ -591,7 +591,7 @@ var zigAnalysis;
591 }591 }
592592
593 if (!("type" in resolvedGenericRet.expr)) return;593 if (!("type" in resolvedGenericRet.expr)) return;
594 const genericType = zigAnalysis.types[resolvedGenericRet.expr.type];594 const genericType = getType(resolvedGenericRet.expr.type);
595 if (isContainerType(genericType)) {595 if (isContainerType(genericType)) {
596 renderContainer(genericType);596 renderContainer(genericType);
597 }597 }
...@@ -621,7 +621,7 @@ var zigAnalysis;...@@ -621,7 +621,7 @@ var zigAnalysis;
621 domFnNoExamples.classList.add("hidden");621 domFnNoExamples.classList.add("hidden");
622 }622 }
623623
624 let protoSrcNode = zigAnalysis.astNodes[protoSrcIndex];624 let protoSrcNode = getAstNode(protoSrcIndex);
625 if (625 if (
626 docsSource == null &&626 docsSource == null &&
627 protoSrcNode != null &&627 protoSrcNode != null &&
...@@ -639,13 +639,13 @@ var zigAnalysis;...@@ -639,13 +639,13 @@ var zigAnalysis;
639 function renderFnParamDocs(fnDecl, typeObj) {639 function renderFnParamDocs(fnDecl, typeObj) {
640 let docCount = 0;640 let docCount = 0;
641641
642 let fnNode = zigAnalysis.astNodes[fnDecl.src];642 let fnNode = getAstNode(fnDecl.src);
643 let fields = fnNode.fields;643 let fields = fnNode.fields;
644 let isVarArgs = fnNode.varArgs;644 let isVarArgs = fnNode.varArgs;
645645
646 for (let i = 0; i < fields.length; i += 1) {646 for (let i = 0; i < fields.length; i += 1) {
647 let field = fields[i];647 let field = fields[i];
648 let fieldNode = zigAnalysis.astNodes[field];648 let fieldNode = getAstNode(field);
649 if (fieldNode.docs != null) {649 if (fieldNode.docs != null) {
650 docCount += 1;650 docCount += 1;
651 }651 }
...@@ -659,7 +659,7 @@ var zigAnalysis;...@@ -659,7 +659,7 @@ var zigAnalysis;
659659
660 for (let i = 0; i < fields.length; i += 1) {660 for (let i = 0; i < fields.length; i += 1) {
661 let field = fields[i];661 let field = fields[i];
662 let fieldNode = zigAnalysis.astNodes[field];662 let fieldNode = getAstNode(field);
663 let docs = fieldNode.docs;663 let docs = fieldNode.docs;
664 if (fieldNode.docs == null) {664 if (fieldNode.docs == null) {
665 continue;665 continue;
...@@ -967,17 +967,17 @@ var zigAnalysis;...@@ -967,17 +967,17 @@ var zigAnalysis;
967 }967 }
968 case "switchOp": {968 case "switchOp": {
969 let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index];969 let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index];
970 let ast = zigAnalysis.astNodes[expr.switchOp.ast];970 let ast = getAstNode(expr.switchOp.src);
971 let file_name = expr.switchOp.file_name;971 let file_name = expr.switchOp.file_name;
972 let outer_decl_index = expr.switchOp.outer_decl;972 let outer_decl_index = expr.switchOp.outer_decl;
973 let outer_decl = zigAnalysis.types[outer_decl_index];973 let outer_decl = getType(outer_decl_index);
974 let line = 0;974 let line = 0;
975 // console.log(expr.switchOp)975 // console.log(expr.switchOp)
976 // console.log(outer_decl)976 // console.log(outer_decl)
977 while (outer_decl_index !== 0 && outer_decl.line_number > 0) {977 while (outer_decl_index !== 0 && outer_decl.line_number > 0) {
978 line += outer_decl.line_number;978 line += outer_decl.line_number;
979 outer_decl_index = outer_decl.outer_decl;979 outer_decl_index = outer_decl.outer_decl;
980 outer_decl = zigAnalysis.types[outer_decl_index];980 outer_decl = getType(outer_decl_index);
981 // console.log(outer_decl)981 // console.log(outer_decl)
982 }982 }
983 line += ast.line + 1;983 line += ast.line + 1;
...@@ -1028,8 +1028,8 @@ var zigAnalysis;...@@ -1028,8 +1028,8 @@ var zigAnalysis;
1028 case "fieldRef": {1028 case "fieldRef": {
1029 const enumObj = exprName({ type: expr.fieldRef.type }, opts);1029 const enumObj = exprName({ type: expr.fieldRef.type }, opts);
1030 const field =1030 const field =
1031 zigAnalysis.astNodes[enumObj.ast].fields[expr.fieldRef.index];1031 getAstNode(enumObj.src).fields[expr.fieldRef.index];
1032 const name = zigAnalysis.astNodes[field].name;1032 const name = getAstNode(field).name;
1033 return name;1033 return name;
1034 }1034 }
1035 case "enumToInt": {1035 case "enumToInt": {
...@@ -1452,13 +1452,13 @@ var zigAnalysis;...@@ -1452,13 +1452,13 @@ var zigAnalysis;
1452 return print_lhs + " " + operator + " " + print_rhs;1452 return print_lhs + " " + operator + " " + print_rhs;
1453 }1453 }
1454 case "errorSets": {1454 case "errorSets": {
1455 const errUnionObj = zigAnalysis.types[expr.errorSets];1455 const errUnionObj = getType(expr.errorSets);
1456 let lhs = exprName(errUnionObj.lhs, opts);1456 let lhs = exprName(errUnionObj.lhs, opts);
1457 let rhs = exprName(errUnionObj.rhs, opts);1457 let rhs = exprName(errUnionObj.rhs, opts);
1458 return lhs + " || " + rhs;1458 return lhs + " || " + rhs;
1459 }1459 }
1460 case "errorUnion": {1460 case "errorUnion": {
1461 const errUnionObj = zigAnalysis.types[expr.errorUnion];1461 const errUnionObj = getType(expr.errorUnion);
1462 let lhs = exprName(errUnionObj.lhs, opts);1462 let lhs = exprName(errUnionObj.lhs, opts);
1463 let rhs = exprName(errUnionObj.rhs, opts);1463 let rhs = exprName(errUnionObj.rhs, opts);
1464 return lhs + "!" + rhs;1464 return lhs + "!" + rhs;
...@@ -1574,7 +1574,7 @@ var zigAnalysis;...@@ -1574,7 +1574,7 @@ var zigAnalysis;
1574 return exprName(exprArg, opts);1574 return exprName(exprArg, opts);
1575 }1575 }
1576 case "declRef": {1576 case "declRef": {
1577 return zigAnalysis.decls[expr.declRef].name;1577 return getDecl(expr.declRef).name;
1578 }1578 }
1579 case "refPath": {1579 case "refPath": {
1580 return expr.refPath.map((x) => exprName(x, opts)).join(".");1580 return expr.refPath.map((x) => exprName(x, opts)).join(".");
...@@ -1611,7 +1611,7 @@ var zigAnalysis;...@@ -1611,7 +1611,7 @@ var zigAnalysis;
1611 let name = "";1611 let name = "";
16121612
1613 let typeObj = expr.type;1613 let typeObj = expr.type;
1614 if (typeof typeObj === "number") typeObj = zigAnalysis.types[typeObj];1614 if (typeof typeObj === "number") typeObj = getType(typeObj);
1615 switch (typeObj.kind) {1615 switch (typeObj.kind) {
1616 default:1616 default:
1617 throw "TODO";1617 throw "TODO";
...@@ -1865,7 +1865,7 @@ var zigAnalysis;...@@ -1865,7 +1865,7 @@ var zigAnalysis;
1865 if (fnObj.params) {1865 if (fnObj.params) {
1866 let fields = null;1866 let fields = null;
1867 let isVarArgs = false;1867 let isVarArgs = false;
1868 let fnNode = zigAnalysis.astNodes[fnObj.src];1868 let fnNode = getAstNode(fnObj.src);
1869 fields = fnNode.fields;1869 fields = fnNode.fields;
1870 isVarArgs = fnNode.varArgs;1870 isVarArgs = fnNode.varArgs;
18711871
...@@ -1880,7 +1880,7 @@ var zigAnalysis;...@@ -1880,7 +1880,7 @@ var zigAnalysis;
1880 let paramValue = resolveValue({ expr: value });1880 let paramValue = resolveValue({ expr: value });
18811881
1882 if (fields != null) {1882 if (fields != null) {
1883 let paramNode = zigAnalysis.astNodes[fields[i]];1883 let paramNode = getAstNode(fields[i]);
18841884
1885 if (paramNode.varArgs) {1885 if (paramNode.varArgs) {
1886 payloadHtml += "...";1886 payloadHtml += "...";
...@@ -2046,7 +2046,7 @@ var zigAnalysis;...@@ -2046,7 +2046,7 @@ var zigAnalysis;
2046 function shouldSkipParamName(typeRef, paramName) {2046 function shouldSkipParamName(typeRef, paramName) {
2047 let resolvedTypeRef = resolveValue({ expr: typeRef });2047 let resolvedTypeRef = resolveValue({ expr: typeRef });
2048 if ("type" in resolvedTypeRef) {2048 if ("type" in resolvedTypeRef) {
2049 let typeObj = zigAnalysis.types[resolvedTypeRef.type];2049 let typeObj = getType(resolvedTypeRef.type);
2050 if (typeObj.kind === typeKinds.Pointer) {2050 if (typeObj.kind === typeKinds.Pointer) {
2051 let ptrObj = typeObj;2051 let ptrObj = typeObj;
2052 if (getPtrSize(ptrObj) === pointerSizeEnum.One) {2052 if (getPtrSize(ptrObj) === pointerSizeEnum.One) {
...@@ -2067,7 +2067,7 @@ var zigAnalysis;...@@ -2067,7 +2067,7 @@ var zigAnalysis;
2067 if (2067 if (
2068 rootIsStd &&2068 rootIsStd &&
2069 typeObj ===2069 typeObj ===
2070 zigAnalysis.types[zigAnalysis.packages[zigAnalysis.rootPkg].main]2070 getType(zigAnalysis.packages[zigAnalysis.rootPkg].main)
2071 ) {2071 ) {
2072 name = "std";2072 name = "std";
2073 } else {2073 } else {
...@@ -2189,7 +2189,7 @@ var zigAnalysis;...@@ -2189,7 +2189,7 @@ var zigAnalysis;
21892189
2190 if (resolvedValue.expr.fieldRef) {2190 if (resolvedValue.expr.fieldRef) {
2191 const declRef = decl.value.expr.refPath[0].declRef;2191 const declRef = decl.value.expr.refPath[0].declRef;
2192 const type = zigAnalysis.decls[declRef];2192 const type = getDecl(declRef);
2193 domFnProtoCode.innerHTML =2193 domFnProtoCode.innerHTML =
2194 '<span class="tok-kw">const</span> ' +2194 '<span class="tok-kw">const</span> ' +
2195 escapeHtml(decl.name) +2195 escapeHtml(decl.name) +
...@@ -2229,7 +2229,7 @@ var zigAnalysis;...@@ -2229,7 +2229,7 @@ var zigAnalysis;
2229 ";";2229 ";";
2230 }2230 }
22312231
2232 let docs = zigAnalysis.astNodes[decl.src].docs;2232 let docs = getAstNode(decl.src).docs;
2233 if (docs != null) {2233 if (docs != null) {
2234 domTldDocs.innerHTML = markdown(docs);2234 domTldDocs.innerHTML = markdown(docs);
2235 domTldDocs.classList.remove("hidden");2235 domTldDocs.classList.remove("hidden");
...@@ -2246,7 +2246,7 @@ var zigAnalysis;...@@ -2246,7 +2246,7 @@ var zigAnalysis;
2246 ": " +2246 ": " +
2247 typeValueName(declTypeRef, true, true);2247 typeValueName(declTypeRef, true, true);
22482248
2249 let docs = zigAnalysis.astNodes[decl.src].docs;2249 let docs = getAstNode(decl.src).docs;
2250 if (docs != null) {2250 if (docs != null) {
2251 domTldDocs.innerHTML = markdown(docs);2251 domTldDocs.innerHTML = markdown(docs);
2252 domTldDocs.classList.remove("hidden");2252 domTldDocs.classList.remove("hidden");
...@@ -2266,7 +2266,7 @@ var zigAnalysis;...@@ -2266,7 +2266,7 @@ var zigAnalysis;
2266 testsList2266 testsList
2267 ) {2267 ) {
2268 for (let i = 0; i < decls.length; i += 1) {2268 for (let i = 0; i < decls.length; i += 1) {
2269 let decl = zigAnalysis.decls[decls[i]];2269 let decl = getDecl(decls[i]);
2270 let declValue = resolveValue(decl.value);2270 let declValue = resolveValue(decl.value);
22712271
2272 if (decl.isTest) {2272 if (decl.isTest) {
...@@ -2282,7 +2282,7 @@ var zigAnalysis;...@@ -2282,7 +2282,7 @@ var zigAnalysis;
2282 if (decl.kind === "const") {2282 if (decl.kind === "const") {
2283 if ("type" in declValue.expr) {2283 if ("type" in declValue.expr) {
2284 // We have the actual type expression at hand.2284 // We have the actual type expression at hand.
2285 const typeExpr = zigAnalysis.types[declValue.expr.type];2285 const typeExpr = getType(declValue.expr.type);
2286 if (typeExpr.kind == typeKinds.Fn) {2286 if (typeExpr.kind == typeKinds.Fn) {
2287 const funcRetExpr = resolveValue({2287 const funcRetExpr = resolveValue({
2288 expr: typeExpr.ret,2288 expr: typeExpr.ret,
...@@ -2310,7 +2310,7 @@ var zigAnalysis;...@@ -2310,7 +2310,7 @@ var zigAnalysis;
2310 typesList.push(decl);2310 typesList.push(decl);
2311 }2311 }
2312 }2312 }
2313 } else if ("typeRef" in declValue) {2313 } else if (declValue.typeRef) {
2314 if ("type" in declValue.typeRef && declValue.typeRef == typeTypeId) {2314 if ("type" in declValue.typeRef && declValue.typeRef == typeTypeId) {
2315 // We don't know what the type expression is, but we know it's a type.2315 // We don't know what the type expression is, but we know it's a type.
2316 typesList.push(decl);2316 typesList.push(decl);
...@@ -2324,7 +2324,7 @@ var zigAnalysis;...@@ -2324,7 +2324,7 @@ var zigAnalysis;
2324 }2324 }
2325 }2325 }
2326 function renderSourceFileLink(decl) {2326 function renderSourceFileLink(decl) {
2327 let srcNode = zigAnalysis.astNodes[decl.src];2327 let srcNode = getAstNode(decl.src);
23282328
2329 return "<a style=\"float: right;\" href=\"" +2329 return "<a style=\"float: right;\" href=\"" +
2330 sourceFileUrlTemplate.replace("{{file}}",2330 sourceFileUrlTemplate.replace("{{file}}",
...@@ -2377,7 +2377,7 @@ var zigAnalysis;...@@ -2377,7 +2377,7 @@ var zigAnalysis;
2377 testsList.sort(byNameProperty);2377 testsList.sort(byNameProperty);
23782378
2379 if (container.src != null) {2379 if (container.src != null) {
2380 let docs = zigAnalysis.astNodes[container.src].docs;2380 let docs = getAstNode(container.src).docs;
2381 if (docs != null) {2381 if (docs != null) {
2382 domTldDocs.innerHTML = markdown(docs);2382 domTldDocs.innerHTML = markdown(docs);
2383 domTldDocs.classList.remove("hidden");2383 domTldDocs.classList.remove("hidden");
...@@ -2457,7 +2457,7 @@ var zigAnalysis;...@@ -2457,7 +2457,7 @@ var zigAnalysis;
2457 });2457 });
2458 tdFnSrc.innerHTML = renderSourceFileLink(decl);2458 tdFnSrc.innerHTML = renderSourceFileLink(decl);
24592459
2460 let docs = zigAnalysis.astNodes[decl.src].docs;2460 let docs = getAstNode(decl.src).docs;
2461 if (docs != null) {2461 if (docs != null) {
2462 tdDesc.innerHTML = shortDescMarkdown(docs);2462 tdDesc.innerHTML = shortDescMarkdown(docs);
2463 } else {2463 } else {
...@@ -2467,12 +2467,12 @@ var zigAnalysis;...@@ -2467,12 +2467,12 @@ var zigAnalysis;
2467 domSectFns.classList.remove("hidden");2467 domSectFns.classList.remove("hidden");
2468 }2468 }
24692469
2470 let containerNode = zigAnalysis.astNodes[container.src];2470 let containerNode = getAstNode(container.src);
2471 if (containerNode.fields && containerNode.fields.length > 0) {2471 if (containerNode.fields && containerNode.fields.length > 0) {
2472 resizeDomList(domListFields, containerNode.fields.length, "<div></div>");2472 resizeDomList(domListFields, containerNode.fields.length, "<div></div>");
24732473
2474 for (let i = 0; i < containerNode.fields.length; i += 1) {2474 for (let i = 0; i < containerNode.fields.length; i += 1) {
2475 let fieldNode = zigAnalysis.astNodes[containerNode.fields[i]];2475 let fieldNode = getAstNode(containerNode.fields[i]);
2476 let divDom = domListFields.children[i];2476 let divDom = domListFields.children[i];
2477 let fieldName = fieldNode.name;2477 let fieldName = fieldNode.name;
2478 let docs = fieldNode.docs;2478 let docs = fieldNode.docs;
...@@ -2528,7 +2528,7 @@ var zigAnalysis;...@@ -2528,7 +2528,7 @@ var zigAnalysis;
25282528
2529 tdType.innerHTML = typeValueName(typeOfDecl(decl), true, true);2529 tdType.innerHTML = typeValueName(typeOfDecl(decl), true, true);
25302530
2531 let docs = zigAnalysis.astNodes[decl.src].docs;2531 let docs = getAstNode(decl.src).docs;
2532 if (docs != null) {2532 if (docs != null) {
2533 tdDesc.innerHTML = shortDescMarkdown(docs);2533 tdDesc.innerHTML = shortDescMarkdown(docs);
2534 } else {2534 } else {
...@@ -2561,7 +2561,7 @@ var zigAnalysis;...@@ -2561,7 +2561,7 @@ var zigAnalysis;
2561 wantLink: true,2561 wantLink: true,
2562 });2562 });
25632563
2564 let docs = zigAnalysis.astNodes[decl.src].docs;2564 let docs = getAstNode(decl.src).docs;
2565 if (docs != null) {2565 if (docs != null) {
2566 tdDesc.innerHTML = shortDescMarkdown(docs);2566 tdDesc.innerHTML = shortDescMarkdown(docs);
2567 } else {2567 } else {
...@@ -2594,7 +2594,7 @@ var zigAnalysis;...@@ -2594,7 +2594,7 @@ var zigAnalysis;
2594 wantLink: true,2594 wantLink: true,
2595 });2595 });
25962596
2597 let docs = zigAnalysis.astNodes[decl.src].docs;2597 let docs = getAstNode(decl.src).docs;
2598 if (docs != null) {2598 if (docs != null) {
2599 tdDesc.innerHTML = shortDescMarkdown(docs);2599 tdDesc.innerHTML = shortDescMarkdown(docs);
2600 } else {2600 } else {
...@@ -2668,7 +2668,7 @@ var zigAnalysis;...@@ -2668,7 +2668,7 @@ var zigAnalysis;
26682668
2669 function findTypeTypeId() {2669 function findTypeTypeId() {
2670 for (let i = 0; i < zigAnalysis.types.length; i += 1) {2670 for (let i = 0; i < zigAnalysis.types.length; i += 1) {
2671 if (zigAnalysis.types[i].kind == typeKinds.Type) {2671 if (getType(i).kind == typeKinds.Type) {
2672 return i;2672 return i;
2673 }2673 }
2674 }2674 }
...@@ -2732,11 +2732,11 @@ var zigAnalysis;...@@ -2732,11 +2732,11 @@ var zigAnalysis;
2732 if ("value" in parentType) {2732 if ("value" in parentType) {
2733 const rv = resolveValue(parentType.value);2733 const rv = resolveValue(parentType.value);
2734 if ("type" in rv.expr) {2734 if ("type" in rv.expr) {
2735 const t = zigAnalysis.types[rv.expr.type];2735 const t = getType(rv.expr.type);
2736 if (t.kind == typeKinds.Fn && t.generic_ret != null) {2736 if (t.kind == typeKinds.Fn && t.generic_ret != null) {
2737 const rgr = resolveValue({ expr: t.generic_ret });2737 const rgr = resolveValue({ expr: t.generic_ret });
2738 if ("type" in rgr.expr) {2738 if ("type" in rgr.expr) {
2739 parentType = zigAnalysis.types[rgr.expr.type];2739 parentType = getType(rgr.expr.type);
2740 }2740 }
2741 }2741 }
2742 }2742 }
...@@ -2746,7 +2746,7 @@ var zigAnalysis;...@@ -2746,7 +2746,7 @@ var zigAnalysis;
2746 if (!parentType.pubDecls) return null;2746 if (!parentType.pubDecls) return null;
2747 for (let i = 0; i < parentType.pubDecls.length; i += 1) {2747 for (let i = 0; i < parentType.pubDecls.length; i += 1) {
2748 let declIndex = parentType.pubDecls[i];2748 let declIndex = parentType.pubDecls[i];
2749 let childDecl = zigAnalysis.decls[declIndex];2749 let childDecl = getDecl(declIndex);
2750 if (childDecl.name === childName) {2750 if (childDecl.name === childName) {
2751 return childDecl;2751 return childDecl;
2752 }2752 }
...@@ -2754,7 +2754,7 @@ var zigAnalysis;...@@ -2754,7 +2754,7 @@ var zigAnalysis;
2754 if (!parentType.privDecls) return null;2754 if (!parentType.privDecls) return null;
2755 for (let i = 0; i < parentType.privDecls.length; i += 1) {2755 for (let i = 0; i < parentType.privDecls.length; i += 1) {
2756 let declIndex = parentType.privDecls[i];2756 let declIndex = parentType.privDecls[i];
2757 let childDecl = zigAnalysis.decls[declIndex];2757 let childDecl = getDecl(declIndex);
2758 if (childDecl.name === childName) {2758 if (childDecl.name === childName) {
2759 return childDecl;2759 return childDecl;
2760 }2760 }
...@@ -2805,7 +2805,7 @@ var zigAnalysis;...@@ -2805,7 +2805,7 @@ var zigAnalysis;
2805 let stack = [2805 let stack = [
2806 {2806 {
2807 declNames: [],2807 declNames: [],
2808 type: zigAnalysis.types[pkg.main],2808 type: getType(pkg.main),
2809 },2809 },
2810 ];2810 ];
2811 while (stack.length !== 0) {2811 while (stack.length !== 0) {
...@@ -2819,7 +2819,7 @@ var zigAnalysis;...@@ -2819,7 +2819,7 @@ var zigAnalysis;
2819 let mainDeclIndex = t.pubDecls[declI];2819 let mainDeclIndex = t.pubDecls[declI];
2820 if (list[mainDeclIndex] != null) continue;2820 if (list[mainDeclIndex] != null) continue;
28212821
2822 let decl = zigAnalysis.decls[mainDeclIndex];2822 let decl = getDecl(mainDeclIndex);
2823 let declVal = resolveValue(decl.value);2823 let declVal = resolveValue(decl.value);
2824 let declNames = item.declNames.concat([decl.name]);2824 let declNames = item.declNames.concat([decl.name]);
2825 list[mainDeclIndex] = {2825 list[mainDeclIndex] = {
...@@ -2827,7 +2827,7 @@ var zigAnalysis;...@@ -2827,7 +2827,7 @@ var zigAnalysis;
2827 declNames: declNames,2827 declNames: declNames,
2828 };2828 };
2829 if ("type" in declVal.expr) {2829 if ("type" in declVal.expr) {
2830 let value = zigAnalysis.types[declVal.expr.type];2830 let value = getType(declVal.expr.type);
2831 if (declCanRepresentTypeKind(value.kind)) {2831 if (declCanRepresentTypeKind(value.kind)) {
2832 canonTypeDecls[declVal.type] = mainDeclIndex;2832 canonTypeDecls[declVal.type] = mainDeclIndex;
2833 }2833 }
...@@ -2843,7 +2843,7 @@ var zigAnalysis;...@@ -2843,7 +2843,7 @@ var zigAnalysis;
2843 if (value.kind == typeKinds.Fn && value.generic_ret != null) {2843 if (value.kind == typeKinds.Fn && value.generic_ret != null) {
2844 let resolvedVal = resolveValue({ expr: value.generic_ret });2844 let resolvedVal = resolveValue({ expr: value.generic_ret });
2845 if ("type" in resolvedVal.expr) {2845 if ("type" in resolvedVal.expr) {
2846 let generic_type = zigAnalysis.types[resolvedVal.expr.type];2846 let generic_type = getType(resolvedVal.expr.type);
2847 if (isContainerType(generic_type)) {2847 if (isContainerType(generic_type)) {
2848 stack.push({2848 stack.push({
2849 declNames: declNames,2849 declNames: declNames,
...@@ -3394,11 +3394,11 @@ var zigAnalysis;...@@ -3394,11 +3394,11 @@ var zigAnalysis;
3394 let canonPath = getCanonDeclPath(declIndex);3394 let canonPath = getCanonDeclPath(declIndex);
3395 if (canonPath == null) continue;3395 if (canonPath == null) continue;
33963396
3397 let decl = zigAnalysis.decls[declIndex];3397 let decl = getDecl(declIndex);
3398 let lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];3398 let lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];
3399 let fullPathSearchText =3399 let fullPathSearchText =
3400 lastPkgName + "." + canonPath.declNames.join(".");3400 lastPkgName + "." + canonPath.declNames.join(".");
3401 let astNode = zigAnalysis.astNodes[decl.src];3401 let astNode = getAstNode(decl.src);
3402 let fileAndDocs = ""; //zigAnalysis.files[astNode.file];3402 let fileAndDocs = ""; //zigAnalysis.files[astNode.file];
3403 // TODO: understand what this piece of code is trying to achieve3403 // TODO: understand what this piece of code is trying to achieve
3404 // also right now `files` are expressed as a hashmap.3404 // also right now `files` are expressed as a hashmap.
...@@ -3513,4 +3513,169 @@ var zigAnalysis;...@@ -3513,4 +3513,169 @@ var zigAnalysis;
3513 function byNameProperty(a, b) {3513 function byNameProperty(a, b) {
3514 return operatorCompare(a.name, b.name);3514 return operatorCompare(a.name, b.name);
3515 }3515 }
3516
3517
3518 function getDecl(idx) {
3519 const decl = zigAnalysis.decls[idx];
3520 return {
3521 name: decl[0],
3522 kind: decl[1],
3523 isTest: decl[2],
3524 src: decl[3],
3525 value: decl[4],
3526 decltest: decl[5],
3527 };
3528 }
3529
3530 function getAstNode(idx) {
3531 const ast = zigAnalysis.astNodes[idx];
3532 return {
3533 file: ast[0],
3534 line: ast[1],
3535 col: ast[2],
3536 name: ast[3],
3537 code: ast[4],
3538 docs: ast[5],
3539 fields: ast[6],
3540 comptime: ast[7],
3541 };
3542 }
3543
3544 function getType(idx){
3545 const ty = zigAnalysis.types[idx];
3546 switch(ty[0]) {
3547 default:
3548 throw "unhandled type kind!";
3549 case 0: // Unanalyzed
3550 throw "unanalyzed type!";
3551 case 1: // Type
3552 case 2: // Void
3553 case 3: // Bool
3554 case 4: // NoReturn
3555 case 5: // Int
3556 case 6: // Float
3557 return { kind: ty[0], name: ty[1]};
3558 case 7: // Pointer
3559 return {
3560 kind: ty[0],
3561 size: ty[1],
3562 child: ty[2],
3563 sentinel: ty[3],
3564 align: ty[4],
3565 address_space: ty[5],
3566 bit_start: ty[6],
3567 host_size: ty[7],
3568 is_ref: ty[8],
3569 is_allowzero: ty[9],
3570 is_mutable: ty[10],
3571 is_volatile: ty[11],
3572 has_sentinel: ty[12],
3573 has_align: ty[13],
3574 has_addrspace: ty[14],
3575 has_bit_range: ty[15],
3576 };
3577 case 8: // Array
3578 return {
3579 kind: ty[0],
3580 len: ty[1],
3581 child: ty[2],
3582 sentinel: ty[3],
3583 };
3584 case 9: // Struct
3585 return {
3586 kind: ty[0],
3587 name: ty[1],
3588 src: ty[2],
3589 privDecls: ty[3],
3590 pubDecls: ty[4],
3591 fields: ty[5],
3592 line_number: ty[6],
3593 outer_decl: ty[7],
3594 };
3595 case 10: // ComptimeExpr
3596 case 11: // ComptimeFloat
3597 case 12: // ComptimeInt
3598 case 13: // Undefined
3599 case 14: // Null
3600 return { kind: ty[0], name: ty[1] };
3601 case 15: // Optional
3602 return {
3603 kind: ty[0],
3604 name: ty[1],
3605 child: ty[2],
3606 };
3607 case 16: // ErrorUnion
3608 return {
3609 kind: ty[0],
3610 lhs: ty[1],
3611 rhs: ty[2],
3612 };
3613 case 17: // InferredErrorUnion
3614 return {
3615 kind: ty[0],
3616 payload: ty[1],
3617 };
3618 case 18: // ErrorSet
3619 return {
3620 kind: ty[0],
3621 name: ty[1],
3622 fields: ty[2],
3623 };
3624 case 19: // Enum
3625 return {
3626 kind: ty[0],
3627 name: ty[1],
3628 src: ty[2],
3629 privDecls: ty[3],
3630 pubDecls: ty[4],
3631 };
3632 case 20: // Union
3633 return {
3634 kind: ty[0],
3635 name: ty[1],
3636 src: ty[2],
3637 privDecls: ty[3],
3638 pubDecls: ty[4],
3639 fields: ty[5],
3640 };
3641 case 21: // Fn
3642 return {
3643 kind: ty[0],
3644 name: ty[1],
3645 src: ty[2],
3646 ret: ty[3],
3647 generic_ret: ty[4],
3648 params: ty[5],
3649 lib_name: ty[6],
3650 is_var_args: ty[7],
3651 is_inferred_error: ty[8],
3652 has_lib_name: ty[9],
3653 has_cc: ty[10],
3654 cc: ty[11],
3655 align: ty[12],
3656 has_align: ty[13],
3657 is_test: ty[14],
3658 is_extern: ty[15],
3659 };
3660 case 22: // BoundFn
3661 return { kind: ty[0], name: ty[1] };
3662 case 23: // Opaque
3663 return {
3664 kind: ty[0],
3665 name: ty[1],
3666 src: ty[2],
3667 privDecls: ty[3],
3668 pubDecls: ty[4],
3669 };
3670 case 24: // Frame
3671 case 25: // AnyFrame
3672 case 26: // Vector
3673 case 27: // EnumLiteral
3674 return { kind: ty[0], name: ty[1] };
3675 }
3676 }
3677
3516})();3678})();
3679
3680
3681
src/Autodoc.zig+83-19
...@@ -280,8 +280,8 @@ pub fn generateZirData(self: *Autodoc) !void {...@@ -280,8 +280,8 @@ pub fn generateZirData(self: *Autodoc) !void {
280 try std.json.stringify(280 try std.json.stringify(
281 data,281 data,
282 .{282 .{
283 .whitespace = .{ .indent = if (builtin.mode == .Debug) .{ .Space = 4 } else .None },283 .whitespace = .{ .indent = .None, .separator = false },
284 .emit_null_optional_fields = false,284 .emit_null_optional_fields = true,
285 },285 },
286 out,286 out,
287 );287 );
...@@ -404,6 +404,7 @@ const DocData = struct {...@@ -404,6 +404,7 @@ const DocData = struct {
404 w: anytype,404 w: anytype,
405 ) !void {405 ) !void {
406 var jsw = std.json.writeStream(w, 15);406 var jsw = std.json.writeStream(w, 15);
407 if (opts.whitespace) |ws| jsw.whitespace = ws;
407 try jsw.beginObject();408 try jsw.beginObject();
408 inline for (comptime std.meta.tags(std.meta.FieldEnum(DocData))) |f| {409 inline for (comptime std.meta.tags(std.meta.FieldEnum(DocData))) |f| {
409 const f_name = @tagName(f);410 const f_name = @tagName(f);
...@@ -449,6 +450,8 @@ const DocData = struct {...@@ -449,6 +450,8 @@ const DocData = struct {
449 w: anytype,450 w: anytype,
450 ) !void {451 ) !void {
451 var jsw = std.json.writeStream(w, 15);452 var jsw = std.json.writeStream(w, 15);
453 if (opts.whitespace) |ws| jsw.whitespace = ws;
454
452 try jsw.beginObject();455 try jsw.beginObject();
453 inline for (comptime std.meta.tags(std.meta.FieldEnum(DocPackage))) |f| {456 inline for (comptime std.meta.tags(std.meta.FieldEnum(DocPackage))) |f| {
454 const f_name = @tagName(f);457 const f_name = @tagName(f);
...@@ -474,6 +477,22 @@ const DocData = struct {...@@ -474,6 +477,22 @@ const DocData = struct {
474 // The index in astNodes of the `test declname { }` node477 // The index in astNodes of the `test declname { }` node
475 decltest: ?usize = null,478 decltest: ?usize = null,
476 _analyzed: bool, // omitted in json data479 _analyzed: bool, // omitted in json data
480
481 pub fn jsonStringify(
482 self: Decl,
483 opts: std.json.StringifyOptions,
484 w: anytype,
485 ) !void {
486 var jsw = std.json.writeStream(w, 15);
487 if (opts.whitespace) |ws| jsw.whitespace = ws;
488 try jsw.beginArray();
489 inline for (comptime std.meta.fields(Decl)) |f| {
490 try jsw.arrayElem();
491 try std.json.stringify(@field(self, f.name), opts, w);
492 jsw.state_index -= 1;
493 }
494 try jsw.endArray();
495 }
477 };496 };
478497
479 const AstNode = struct {498 const AstNode = struct {
...@@ -485,6 +504,22 @@ const DocData = struct {...@@ -485,6 +504,22 @@ const DocData = struct {
485 docs: ?[]const u8 = null,504 docs: ?[]const u8 = null,
486 fields: ?[]usize = null, // index into astNodes505 fields: ?[]usize = null, // index into astNodes
487 @"comptime": bool = false,506 @"comptime": bool = false,
507
508 pub fn jsonStringify(
509 self: AstNode,
510 opts: std.json.StringifyOptions,
511 w: anytype,
512 ) !void {
513 var jsw = std.json.writeStream(w, 15);
514 if (opts.whitespace) |ws| jsw.whitespace = ws;
515 try jsw.beginArray();
516 inline for (comptime std.meta.fields(AstNode)) |f| {
517 try jsw.arrayElem();
518 try std.json.stringify(@field(self, f.name), opts, w);
519 jsw.state_index -= 1;
520 }
521 try jsw.endArray();
522 }
488 };523 };
489524
490 const Type = union(enum) {525 const Type = union(enum) {
...@@ -525,7 +560,6 @@ const DocData = struct {...@@ -525,7 +560,6 @@ const DocData = struct {
525 fields: ?[]Expr = null, // (use src->fields to find names)560 fields: ?[]Expr = null, // (use src->fields to find names)
526 line_number: usize,561 line_number: usize,
527 outer_decl: usize,562 outer_decl: usize,
528 ast: usize,
529 },563 },
530 ComptimeExpr: struct { name: []const u8 },564 ComptimeExpr: struct { name: []const u8 },
531 ComptimeFloat: struct { name: []const u8 },565 ComptimeFloat: struct { name: []const u8 },
...@@ -548,7 +582,6 @@ const DocData = struct {...@@ -548,7 +582,6 @@ const DocData = struct {
548 src: usize, // index into astNodes582 src: usize, // index into astNodes
549 privDecls: []usize = &.{}, // index into decls583 privDecls: []usize = &.{}, // index into decls
550 pubDecls: []usize = &.{}, // index into decls584 pubDecls: []usize = &.{}, // index into decls
551 ast: usize,
552 // (use src->fields to find field names)585 // (use src->fields to find field names)
553 },586 },
554 Union: struct {587 Union: struct {
...@@ -557,7 +590,6 @@ const DocData = struct {...@@ -557,7 +590,6 @@ const DocData = struct {
557 privDecls: []usize = &.{}, // index into decls590 privDecls: []usize = &.{}, // index into decls
558 pubDecls: []usize = &.{}, // index into decls591 pubDecls: []usize = &.{}, // index into decls
559 fields: []Expr = &.{}, // (use src->fields to find names)592 fields: []Expr = &.{}, // (use src->fields to find names)
560 ast: usize,
561 },593 },
562 Fn: struct {594 Fn: struct {
563 name: []const u8,595 name: []const u8,
...@@ -582,7 +614,6 @@ const DocData = struct {...@@ -582,7 +614,6 @@ const DocData = struct {
582 src: usize, // index into astNodes614 src: usize, // index into astNodes
583 privDecls: []usize = &.{}, // index into decls615 privDecls: []usize = &.{}, // index into decls
584 pubDecls: []usize = &.{}, // index into decls616 pubDecls: []usize = &.{}, // index into decls
585 ast: usize,
586 },617 },
587 Frame: struct { name: []const u8 },618 Frame: struct { name: []const u8 },
588 AnyFrame: struct { name: []const u8 },619 AnyFrame: struct { name: []const u8 },
...@@ -601,14 +632,15 @@ const DocData = struct {...@@ -601,14 +632,15 @@ const DocData = struct {
601 ) !void {632 ) !void {
602 const active_tag = std.meta.activeTag(self);633 const active_tag = std.meta.activeTag(self);
603 var jsw = std.json.writeStream(w, 15);634 var jsw = std.json.writeStream(w, 15);
604 try jsw.beginObject();635 if (opts.whitespace) |ws| jsw.whitespace = ws;
605 try jsw.objectField("kind");636 try jsw.beginArray();
637 try jsw.arrayElem();
606 try jsw.emitNumber(@enumToInt(active_tag));638 try jsw.emitNumber(@enumToInt(active_tag));
607 inline for (comptime std.meta.fields(Type)) |case| {639 inline for (comptime std.meta.fields(Type)) |case| {
608 if (@field(Type, case.name) == active_tag) {640 if (@field(Type, case.name) == active_tag) {
609 const current_value = @field(self, case.name);641 const current_value = @field(self, case.name);
610 inline for (comptime std.meta.fields(case.field_type)) |f| {642 inline for (comptime std.meta.fields(case.field_type)) |f| {
611 try jsw.objectField(f.name);643 try jsw.arrayElem();
612 if (f.field_type == std.builtin.TypeInfo.Pointer.Size) {644 if (f.field_type == std.builtin.TypeInfo.Pointer.Size) {
613 try jsw.emitNumber(@enumToInt(@field(current_value, f.name)));645 try jsw.emitNumber(@enumToInt(@field(current_value, f.name)));
614 } else {646 } else {
...@@ -618,7 +650,7 @@ const DocData = struct {...@@ -618,7 +650,7 @@ const DocData = struct {
618 }650 }
619 }651 }
620 }652 }
621 try jsw.endObject();653 try jsw.endArray();
622 }654 }
623 };655 };
624656
...@@ -686,7 +718,7 @@ const DocData = struct {...@@ -686,7 +718,7 @@ const DocData = struct {
686 const SwitchOp = struct {718 const SwitchOp = struct {
687 cond_index: usize,719 cond_index: usize,
688 file_name: []const u8,720 file_name: []const u8,
689 ast: usize,721 src: usize,
690 outer_decl: usize, // index in `types`722 outer_decl: usize, // index in `types`
691 };723 };
692 const BuiltinBin = struct {724 const BuiltinBin = struct {
...@@ -704,7 +736,15 @@ const DocData = struct {...@@ -704,7 +736,15 @@ const DocData = struct {
704 end: ?usize = null,736 end: ?usize = null,
705 sentinel: ?usize = null, // index in `exprs`737 sentinel: ?usize = null, // index in `exprs`
706 };738 };
707 const Cmpxchg = struct { name: []const u8, type: usize, ptr: usize, expected_value: usize, new_value: usize, success_order: usize, failure_order: usize };739 const Cmpxchg = struct {
740 name: []const u8,
741 type: usize,
742 ptr: usize,
743 expected_value: usize,
744 new_value: usize,
745 success_order: usize,
746 failure_order: usize,
747 };
708 const As = struct {748 const As = struct {
709 typeRefArg: ?usize, // index in `exprs`749 typeRefArg: ?usize, // index in `exprs`
710 exprArg: usize, // index in `exprs`750 exprArg: usize, // index in `exprs`
...@@ -721,11 +761,12 @@ const DocData = struct {...@@ -721,11 +761,12 @@ const DocData = struct {
721761
722 pub fn jsonStringify(762 pub fn jsonStringify(
723 self: Expr,763 self: Expr,
724 opt: std.json.StringifyOptions,764 opts: std.json.StringifyOptions,
725 w: anytype,765 w: anytype,
726 ) !void {766 ) !void {
727 const active_tag = std.meta.activeTag(self);767 const active_tag = std.meta.activeTag(self);
728 var jsw = std.json.writeStream(w, 15);768 var jsw = std.json.writeStream(w, 15);
769 if (opts.whitespace) |ws| jsw.whitespace = ws;
729 try jsw.beginObject();770 try jsw.beginObject();
730 try jsw.objectField(@tagName(active_tag));771 try jsw.objectField(@tagName(active_tag));
731 switch (self) {772 switch (self) {
...@@ -742,7 +783,7 @@ const DocData = struct {...@@ -742,7 +783,7 @@ const DocData = struct {
742 if (comptime std.mem.eql(u8, case.name, "builtinField"))783 if (comptime std.mem.eql(u8, case.name, "builtinField"))
743 continue;784 continue;
744 if (@field(Expr, case.name) == active_tag) {785 if (@field(Expr, case.name) == active_tag) {
745 try std.json.stringify(@field(self, case.name), opt, w);786 try std.json.stringify(@field(self, case.name), opts, w);
746 jsw.state_index -= 1;787 jsw.state_index -= 1;
747 // TODO: we should not reach into the state of the788 // TODO: we should not reach into the state of the
748 // json writer, but alas, this is what's789 // json writer, but alas, this is what's
...@@ -1874,7 +1915,12 @@ fn walkInstruction(...@@ -1874,7 +1915,12 @@ fn walkInstruction(
1874 // log.debug("{s}", .{sep});1915 // log.debug("{s}", .{sep});
18751916
1876 const switch_index = self.exprs.items.len;1917 const switch_index = self.exprs.items.len;
1877 try self.exprs.append(self.arena, .{ .switchOp = .{ .cond_index = cond_index, .file_name = file.sub_file_path, .ast = ast_index, .outer_decl = type_index } });1918 try self.exprs.append(self.arena, .{ .switchOp = .{
1919 .cond_index = cond_index,
1920 .file_name = file.sub_file_path,
1921 .src = ast_index,
1922 .outer_decl = type_index,
1923 } });
18781924
1879 return DocData.WalkResult{1925 return DocData.WalkResult{
1880 .typeRef = .{ .type = @enumToInt(Ref.type_type) },1926 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
...@@ -2505,7 +2551,6 @@ fn walkInstruction(...@@ -2505,7 +2551,6 @@ fn walkInstruction(
2505 .src = self_ast_node_index,2551 .src = self_ast_node_index,
2506 .privDecls = priv_decl_indexes.items,2552 .privDecls = priv_decl_indexes.items,
2507 .pubDecls = decl_indexes.items,2553 .pubDecls = decl_indexes.items,
2508 .ast = self_ast_node_index,
2509 },2554 },
2510 };2555 };
2511 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {2556 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
...@@ -2644,7 +2689,13 @@ fn walkInstruction(...@@ -2644,7 +2689,13 @@ fn walkInstruction(
2644 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;2689 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
26452690
2646 self.types.items[type_slot_index] = .{2691 self.types.items[type_slot_index] = .{
2647 .Union = .{ .name = "todo_name", .src = self_ast_node_index, .privDecls = priv_decl_indexes.items, .pubDecls = decl_indexes.items, .fields = field_type_refs.items, .ast = self_ast_node_index },2692 .Union = .{
2693 .name = "todo_name",
2694 .src = self_ast_node_index,
2695 .privDecls = priv_decl_indexes.items,
2696 .pubDecls = decl_indexes.items,
2697 .fields = field_type_refs.items,
2698 },
2648 };2699 };
26492700
2650 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {2701 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
...@@ -2796,7 +2847,12 @@ fn walkInstruction(...@@ -2796,7 +2847,12 @@ fn walkInstruction(
2796 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;2847 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
27972848
2798 self.types.items[type_slot_index] = .{2849 self.types.items[type_slot_index] = .{
2799 .Enum = .{ .name = "todo_name", .src = self_ast_node_index, .privDecls = priv_decl_indexes.items, .pubDecls = decl_indexes.items, .ast = self_ast_node_index },2850 .Enum = .{
2851 .name = "todo_name",
2852 .src = self_ast_node_index,
2853 .privDecls = priv_decl_indexes.items,
2854 .pubDecls = decl_indexes.items,
2855 },
2800 };2856 };
2801 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {2857 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
2802 for (paths.items) |resume_info| {2858 for (paths.items) |resume_info| {
...@@ -2910,7 +2966,15 @@ fn walkInstruction(...@@ -2910,7 +2966,15 @@ fn walkInstruction(
2910 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;2966 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
29112967
2912 self.types.items[type_slot_index] = .{2968 self.types.items[type_slot_index] = .{
2913 .Struct = .{ .name = "todo_name", .src = self_ast_node_index, .privDecls = priv_decl_indexes.items, .pubDecls = decl_indexes.items, .fields = field_type_refs.items, .line_number = self.ast_nodes.items[self_ast_node_index].line, .outer_decl = type_slot_index - 1, .ast = self_ast_node_index },2969 .Struct = .{
2970 .name = "todo_name",
2971 .src = self_ast_node_index,
2972 .privDecls = priv_decl_indexes.items,
2973 .pubDecls = decl_indexes.items,
2974 .fields = field_type_refs.items,
2975 .line_number = self.ast_nodes.items[self_ast_node_index].line,
2976 .outer_decl = type_slot_index - 1,
2977 },
2914 };2978 };
2915 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {2979 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
2916 for (paths.items) |resume_info| {2980 for (paths.items) |resume_info| {