authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-06-10 13:06:08-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
loge7476fd81c9a4c95aa3f136c25b69e78ac53d803
treecb8f03a9146b7aaa2f6994d940c48b74e8c7ea9d
parent81147dd1010644da0e61991561988d0e39de729c

autodoc: handling refPath and fieldRef


2 files changed, 51 insertions(+), 27 deletions(-)

lib/docs/main.js+33-11
......@@ -892,8 +892,8 @@ var zigAnalysis;
892892 let outer_decl_index = expr.switchOp.outer_decl;
893893 let outer_decl = zigAnalysis.types[outer_decl_index];
894894 let line = 0;
895 console.log(expr.switchOp)
896 console.log(outer_decl)
895 // console.log(expr.switchOp)
896 // console.log(outer_decl)
897897 while (outer_decl_index !== 0 && outer_decl.line_number > 0) {
898898 line += outer_decl.line_number;
899899 outer_decl_index = outer_decl.outer_decl;
......@@ -912,14 +912,24 @@ var zigAnalysis;
912912 const switchIndex = zigAnalysis.exprs[expr.switchIndex];
913913 return exprName(switchIndex, opts);
914914 }
915 case "fieldRef" : {
915 case "refPath" : {
916916 // const fieldRef = zigAnalysis.decls[expr.fieldRef.index];
917 // const struct_name = zigAnalysis.decls[expr.struct[0].val.typeRef.refPath[0].declRef].name;
918 console.log(expr)
919 // console.log(fieldRef)
920 // return "@enumToInt(" + exprName(enumToInt, opts) + ")";
921 // return exprName(fieldRef,opts);
922 return "WIP"
917 const declRef = expr.refPath[0].declRef;
918 let name = zigAnalysis.decls[declRef].name;
919 console.log("refPath")
920 console.log(expr.refPath)
921 console.log(declRef)
922 for (let i = 1; i < expr.refPath.length; i++) {
923 name += "." + exprName(expr.refPath[i]);
924 }
925 return name;
926 }
927 case "fieldRef" : {
928 const fieldRef = zigAnalysis.decls[expr.fieldRef.index];
929 const enumObj = exprName({"type":expr.fieldRef.type} ,opts);
930 // const name = zigAnalysis.astNodes[enumObj.ast + expr.fieldRef.index].name;
931 const name = zigAnalysis.astNodes[enumObj.ast + expr.fieldRef.index + 1].name;
932 return name
923933 }
924934 case "enumToInt" : {
925935 const enumToInt = zigAnalysis.exprs[expr.enumToInt];
......@@ -1457,6 +1467,12 @@ var zigAnalysis;
14571467 if (typeof typeObj === 'number') typeObj = zigAnalysis.types[typeObj];
14581468 switch (typeObj.kind) {
14591469 default: throw "TODO";
1470 case typeKinds.Enum:
1471 {
1472 let enumObj = (typeObj);
1473
1474 return enumObj;
1475 }
14601476 case typeKinds.Opaque:
14611477 {
14621478 let opaqueObj = (typeObj);
......@@ -2011,9 +2027,15 @@ var zigAnalysis;
20112027 function renderValue(decl) {
20122028 let resolvedValue = resolveValue(decl.value)
20132029
2030 if (resolvedValue.expr.fieldRef) {
20142031 domFnProtoCode.innerHTML = '<span class="tok-kw">const</span> ' +
2015 escapeHtml(decl.name) + ': ' + exprName(resolvedValue.typeRef, {wantHtml: true, wantLink:true}) +
2016 " = " + exprName(decl.value.expr, {wantHtml: true, wantLink:true}) + ";";
2032 escapeHtml(decl.name) + ': ' + exprName(resolvedValue.expr.fieldRef, {wantHtml: true, wantLink:true}) +
2033 " = " + exprName(decl.value.expr, {wantHtml: true, wantLink:true}) + ";";
2034 } else {
2035 domFnProtoCode.innerHTML = '<span class="tok-kw">const</span> ' +
2036 escapeHtml(decl.name) + ': ' + exprName(resolvedValue.typeRef, {wantHtml: true, wantLink:true}) +
2037 " = " + exprName(decl.value.expr, {wantHtml: true, wantLink:true}) + ";";
2038 }
20172039
20182040 let docs = zigAnalysis.astNodes[decl.src].docs;
20192041 if (docs != null) {
src/Autodoc.zig+18-16
......@@ -1760,15 +1760,15 @@ fn walkInstruction(
17601760 const ast_index = self.ast_nodes.items.len;
17611761 const type_index = self.types.items.len - 1;
17621762
1763 const ast_line = self.ast_nodes.items[ast_index - 1];
1763 // const ast_line = self.ast_nodes.items[ast_index - 1];
17641764
1765 const sep = "=" ** 200;
1766 std.debug.print("{s}\n", .{sep});
1767 std.debug.print("SWITCH BLOCK\n", .{});
1768 std.debug.print("extra = {any}\n", .{extra});
1769 std.debug.print("outer_decl = {any}\n", .{self.types.items[type_index]});
1770 std.debug.print("ast_lines = {}\n", .{ast_line});
1771 std.debug.print("{s}\n", .{sep});
1765 // const sep = "=" ** 200;
1766 // std.debug.print("{s}\n", .{sep});
1767 // std.debug.print("SWITCH BLOCK\n", .{});
1768 // std.debug.print("extra = {any}\n", .{extra});
1769 // std.debug.print("outer_decl = {any}\n", .{self.types.items[type_index]});
1770 // std.debug.print("ast_lines = {}\n", .{ast_line});
1771 // std.debug.print("{s}\n", .{sep});
17721772
17731773 const switch_index = self.exprs.items.len;
17741774 try self.exprs.append(self.arena, .{ .switchOp = .{ .cond_index = cond_index, .file_name = file.sub_file_path, .ast = ast_index, .outer_decl = type_index } });
......@@ -1789,13 +1789,13 @@ fn walkInstruction(
17891789 const operand_index = self.exprs.items.len;
17901790 try self.exprs.append(self.arena, operand.expr);
17911791
1792 const ast_index = self.ast_nodes.items.len;
1793 const sep = "=" ** 200;
1794 std.debug.print("{s}\n", .{sep});
1795 std.debug.print("SWITCH COND\n", .{});
1796 std.debug.print("ast index = {}\n", .{ast_index});
1797 std.debug.print("ast previous = {}\n", .{self.ast_nodes.items[ast_index - 1]});
1798 std.debug.print("{s}\n", .{sep});
1792 // const ast_index = self.ast_nodes.items.len;
1793 // const sep = "=" ** 200;
1794 // std.debug.print("{s}\n", .{sep});
1795 // std.debug.print("SWITCH COND\n", .{});
1796 // std.debug.print("ast index = {}\n", .{ast_index});
1797 // std.debug.print("ast previous = {}\n", .{self.ast_nodes.items[ast_index - 1]});
1798 // std.debug.print("{s}\n", .{sep});
17991799
18001800 return DocData.WalkResult{
18011801 .typeRef = operand.typeRef,
......@@ -1917,7 +1917,9 @@ fn walkInstruction(
19171917 // While it would make sense to grab the original decl's typeRef info,
19181918 // that decl might not have been analyzed yet! The frontend will have
19191919 // to navigate through all declRefs to find the underlying type.
1920 return DocData.WalkResult{ .expr = .{ .declRef = decls_slot_index } };
1920 return DocData.WalkResult{
1921 .expr = .{ .declRef = decls_slot_index },
1922 };
19211923 },
19221924 .field_val, .field_call_bind, .field_ptr, .field_type => {
19231925 // TODO: field type uses Zir.Inst.FieldType, it just happens to have the