diff --git a/lib/docs/main.js b/lib/docs/main.js index 9877ffa8c5..221511f576 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -892,8 +892,8 @@ var zigAnalysis; let outer_decl_index = expr.switchOp.outer_decl; let outer_decl = zigAnalysis.types[outer_decl_index]; let line = 0; - console.log(expr.switchOp) - console.log(outer_decl) + // console.log(expr.switchOp) + // console.log(outer_decl) while (outer_decl_index !== 0 && outer_decl.line_number > 0) { line += outer_decl.line_number; outer_decl_index = outer_decl.outer_decl; @@ -912,14 +912,24 @@ var zigAnalysis; const switchIndex = zigAnalysis.exprs[expr.switchIndex]; return exprName(switchIndex, opts); } - case "fieldRef" : { + case "refPath" : { // const fieldRef = zigAnalysis.decls[expr.fieldRef.index]; - // const struct_name = zigAnalysis.decls[expr.struct[0].val.typeRef.refPath[0].declRef].name; - console.log(expr) - // console.log(fieldRef) - // return "@enumToInt(" + exprName(enumToInt, opts) + ")"; - // return exprName(fieldRef,opts); - return "WIP" + const declRef = expr.refPath[0].declRef; + let name = zigAnalysis.decls[declRef].name; + console.log("refPath") + console.log(expr.refPath) + console.log(declRef) + for (let i = 1; i < expr.refPath.length; i++) { + name += "." + exprName(expr.refPath[i]); + } + return name; + } + case "fieldRef" : { + const fieldRef = zigAnalysis.decls[expr.fieldRef.index]; + const enumObj = exprName({"type":expr.fieldRef.type} ,opts); + // const name = zigAnalysis.astNodes[enumObj.ast + expr.fieldRef.index].name; + const name = zigAnalysis.astNodes[enumObj.ast + expr.fieldRef.index + 1].name; + return name } case "enumToInt" : { const enumToInt = zigAnalysis.exprs[expr.enumToInt]; @@ -1457,6 +1467,12 @@ var zigAnalysis; if (typeof typeObj === 'number') typeObj = zigAnalysis.types[typeObj]; switch (typeObj.kind) { default: throw "TODO"; + case typeKinds.Enum: + { + let enumObj = (typeObj); + + return enumObj; + } case typeKinds.Opaque: { let opaqueObj = (typeObj); @@ -2011,9 +2027,15 @@ var zigAnalysis; function renderValue(decl) { let resolvedValue = resolveValue(decl.value) + if (resolvedValue.expr.fieldRef) { domFnProtoCode.innerHTML = 'const ' + - escapeHtml(decl.name) + ': ' + exprName(resolvedValue.typeRef, {wantHtml: true, wantLink:true}) + - " = " + exprName(decl.value.expr, {wantHtml: true, wantLink:true}) + ";"; + escapeHtml(decl.name) + ': ' + exprName(resolvedValue.expr.fieldRef, {wantHtml: true, wantLink:true}) + + " = " + exprName(decl.value.expr, {wantHtml: true, wantLink:true}) + ";"; + } else { + domFnProtoCode.innerHTML = 'const ' + + escapeHtml(decl.name) + ': ' + exprName(resolvedValue.typeRef, {wantHtml: true, wantLink:true}) + + " = " + exprName(decl.value.expr, {wantHtml: true, wantLink:true}) + ";"; + } let docs = zigAnalysis.astNodes[decl.src].docs; if (docs != null) { diff --git a/src/Autodoc.zig b/src/Autodoc.zig index ea79576678..220d623596 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -1760,15 +1760,15 @@ fn walkInstruction( const ast_index = self.ast_nodes.items.len; const type_index = self.types.items.len - 1; - const ast_line = self.ast_nodes.items[ast_index - 1]; + // const ast_line = self.ast_nodes.items[ast_index - 1]; - const sep = "=" ** 200; - std.debug.print("{s}\n", .{sep}); - std.debug.print("SWITCH BLOCK\n", .{}); - std.debug.print("extra = {any}\n", .{extra}); - std.debug.print("outer_decl = {any}\n", .{self.types.items[type_index]}); - std.debug.print("ast_lines = {}\n", .{ast_line}); - std.debug.print("{s}\n", .{sep}); + // const sep = "=" ** 200; + // std.debug.print("{s}\n", .{sep}); + // std.debug.print("SWITCH BLOCK\n", .{}); + // std.debug.print("extra = {any}\n", .{extra}); + // std.debug.print("outer_decl = {any}\n", .{self.types.items[type_index]}); + // std.debug.print("ast_lines = {}\n", .{ast_line}); + // std.debug.print("{s}\n", .{sep}); const switch_index = self.exprs.items.len; 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( const operand_index = self.exprs.items.len; try self.exprs.append(self.arena, operand.expr); - const ast_index = self.ast_nodes.items.len; - const sep = "=" ** 200; - std.debug.print("{s}\n", .{sep}); - std.debug.print("SWITCH COND\n", .{}); - std.debug.print("ast index = {}\n", .{ast_index}); - std.debug.print("ast previous = {}\n", .{self.ast_nodes.items[ast_index - 1]}); - std.debug.print("{s}\n", .{sep}); + // const ast_index = self.ast_nodes.items.len; + // const sep = "=" ** 200; + // std.debug.print("{s}\n", .{sep}); + // std.debug.print("SWITCH COND\n", .{}); + // std.debug.print("ast index = {}\n", .{ast_index}); + // std.debug.print("ast previous = {}\n", .{self.ast_nodes.items[ast_index - 1]}); + // std.debug.print("{s}\n", .{sep}); return DocData.WalkResult{ .typeRef = operand.typeRef, @@ -1917,7 +1917,9 @@ fn walkInstruction( // While it would make sense to grab the original decl's typeRef info, // that decl might not have been analyzed yet! The frontend will have // to navigate through all declRefs to find the underlying type. - return DocData.WalkResult{ .expr = .{ .declRef = decls_slot_index } }; + return DocData.WalkResult{ + .expr = .{ .declRef = decls_slot_index }, + }; }, .field_val, .field_call_bind, .field_ptr, .field_type => { // TODO: field type uses Zir.Inst.FieldType, it just happens to have the