authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-05-24 18:03:04+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
logd707cd6e6df0aca14a9faaf2b411b3c4a3f08d10
treec8fbba7edb6f23eaaf89ea2c2780f2773ab69976
parentbde1caa4ceecb976e728c04c5aebb34f260d9b70

autodoc: improve decl categorization and fix enumliteral arrays/ptrs


2 files changed, 48 insertions(+), 14 deletions(-)

lib/docs/main.js+29-13
......@@ -1045,7 +1045,11 @@ var zigAnalysis;
10451045 */
10461046 function walkResultTypeRef(wr) {
10471047 if (wr.typeRef) return wr.typeRef;
1048 return walkResultTypeRef(resolveValue(wr));
1048 let resolved = resolveValue(wr);
1049 if (wr === resolved) {
1050 return {type: 0};
1051 }
1052 return walkResultTypeRef(resolved);
10491053 }
10501054 /**
10511055 * @typedef {{
......@@ -1128,6 +1132,10 @@ var zigAnalysis;
11281132
11291133 switch (typeObj.kind) {
11301134 default: throw "TODO";
1135 case typeKinds.ComptimeExpr:
1136 {
1137 return "[ComptimeExpr]";
1138 }
11311139 case typeKinds.Array:
11321140 {
11331141 let arrayObj = /** @type {ArrayType} */ (typeObj);
......@@ -1660,7 +1668,7 @@ var zigAnalysis;
16601668 const funcRetExpr = resolveValue({
16611669 expr: /** @type {Fn} */(typeExpr).ret
16621670 });
1663 if ("type" in funcRetExpr && funcRetExpr.type != typeTypeId) {
1671 if ("type" in funcRetExpr.expr && funcRetExpr.expr.type == typeTypeId) {
16641672 if (typeIsErrSet(declValue.expr.type)) {
16651673 errSetsList.push(decl);
16661674 } else if (typeIsStructWithNoFields(declValue.expr.type)) {
......@@ -1671,9 +1679,15 @@ var zigAnalysis;
16711679 } else {
16721680 fnsList.push(decl);
16731681 }
1674 } else {
1675 typesList.push(decl);
1676 }
1682 } else {
1683 if (typeIsErrSet(declValue.expr.type)) {
1684 errSetsList.push(decl);
1685 } else if (typeIsStructWithNoFields(declValue.expr.type)) {
1686 namespacesList.push(decl);
1687 } else {
1688 typesList.push(decl);
1689 }
1690 }
16771691 } else if ("typeRef" in declValue) {
16781692 if ("type" in declValue.typeRef && declValue.typeRef == typeTypeId) {
16791693 // We don't know what the type expression is, but we know it's a type.
......@@ -2098,14 +2112,14 @@ var zigAnalysis;
20982112 if (list[mainDeclIndex] != null) continue;
20992113
21002114 let decl = zigAnalysis.decls[mainDeclIndex];
2101 let declVal = resolveValue(decl.value);
2115 let declVal = decl.value; //resolveValue(decl.value);
21022116 let declNames = item.declNames.concat([decl.name]);
21032117 list[mainDeclIndex] = {
21042118 pkgNames: pkgNames,
21052119 declNames: declNames,
21062120 };
2107 if ("type" in declVal) {
2108 let value = zigAnalysis.types[declVal.type];
2121 if ("type" in declVal.expr) {
2122 let value = zigAnalysis.types[declVal.expr.type];
21092123 if (declCanRepresentTypeKind(value.kind))
21102124 {
21112125 canonTypeDecls[declVal.type] = mainDeclIndex;
......@@ -2130,15 +2144,15 @@ var zigAnalysis;
21302144 if (canonDeclPaths == null) {
21312145 canonDeclPaths = computeCanonDeclPaths();
21322146 }
2133 let cd = /** @type {CanonDecl[]}*/(canonDeclPaths);
2134 return cd[index];
2147 //let cd = /** @type {CanonDecl[]}*/(canonDeclPaths);
2148 return canonDeclPaths[index];
21352149 }
21362150
21372151 /** @param {number} index */
21382152 function getCanonTypeDecl(index) {
21392153 getCanonDeclPath(0);
2140 let ct = /** @type {number[]}*/(canonTypeDecls);
2141 return ct[index];
2154 //let ct = /** @type {number[]}*/(canonTypeDecls);
2155 return canonTypeDecls[index];
21422156 }
21432157
21442158 /** @param {string} text */
......@@ -2646,7 +2660,9 @@ function renderSearch() {
26462660 let lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];
26472661 let fullPathSearchText = lastPkgName + "." + canonPath.declNames.join('.');
26482662 let astNode = zigAnalysis.astNodes[decl.src];
2649 let fileAndDocs = zigAnalysis.files[astNode.file];
2663 let fileAndDocs = "" //zigAnalysis.files[astNode.file];
2664 // TODO: understand what this piece of code is trying to achieve
2665 // also right now `files` are expressed as a hashmap.
26502666 if (astNode.docs != null) {
26512667 fileAndDocs += "\n" + astNode.docs;
26522668 }
src/Autodoc.zig+19-1
......@@ -474,6 +474,7 @@ const DocData = struct {
474474 .Int => |v| try printTypeBody(v, options, w),
475475 .Float => |v| try printTypeBody(v, options, w),
476476 .Type => |v| try printTypeBody(v, options, w),
477 .EnumLiteral => |v| try printTypeBody(v, options, w),
477478 .Pointer => |v| {
478479 if (options.whitespace) |ws| try ws.outputIndent(w);
479480 try w.print(
......@@ -807,7 +808,15 @@ fn walkInstruction(
807808 .enum_literal => {
808809 const str_tok = data[inst_index].str_tok;
809810 const literal = file.zir.nullTerminatedString(str_tok.start);
810 return DocData.WalkResult{ .expr = .{ .enumLiteral = literal } };
811 const type_index = self.types.items.len;
812 try self.types.append(self.arena, .{
813 .EnumLiteral = .{ .name = "todo enum literal" },
814 });
815
816 return DocData.WalkResult{
817 .typeRef = .{ .type = type_index },
818 .expr = .{ .enumLiteral = literal },
819 };
811820 },
812821 .int => {
813822 const int = data[inst_index].int;
......@@ -1019,6 +1028,15 @@ fn walkInstruction(
10191028 array_data[idx] = expr_index;
10201029 }
10211030
1031 if (array_type == null) {
1032 panicWithContext(
1033 file,
1034 inst_index,
1035 "array_type was null!!",
1036 .{},
1037 );
1038 }
1039
10221040 const type_slot_index = self.types.items.len;
10231041 try self.types.append(self.arena, .{
10241042 .Array = .{