authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-05-31 18:15:16+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
logd858f261396fa6b9b3097b5b4d377f6465ec5909
tree940d1bfc8ab0ad77aed6f8fbdbb52d7f7abac19c
parent413cfd4066c547ec1cf3c7b81b0ca34e9eddb82a

autodoc: fixes to generic fn support plus linking support


2 files changed, 57 insertions(+), 16 deletions(-)

lib/docs/main.js+25-8
...@@ -482,13 +482,13 @@ var zigAnalysis;...@@ -482,13 +482,13 @@ var zigAnalysis;
482 continue;482 continue;
483 }483 }
484484
485// if ("as" in value.expr) {485 if ("as" in value.expr) {
486// value = {486 value = {
487// typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg],487 typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg],
488// expr: zigAnalysis.exprs[value.expr.as.exprArg],488 expr: zigAnalysis.exprs[value.expr.as.exprArg],
489// };489 };
490// continue;490 continue;
491// }491 }
492492
493 return value;493 return value;
494494
...@@ -1355,7 +1355,7 @@ var zigAnalysis;...@@ -1355,7 +1355,7 @@ var zigAnalysis;
1355 }1355 }
13561356
1357 case "this":{1357 case "this":{
1358 return "this";1358 return "@This()";
1359 }1359 }
13601360
1361 case "type": {1361 case "type": {
...@@ -2333,6 +2333,23 @@ var zigAnalysis;...@@ -2333,6 +2333,23 @@ var zigAnalysis;
2333 * @param {string} childName2333 * @param {string} childName
2334 */2334 */
2335 function findSubDecl(parentType, childName) {2335 function findSubDecl(parentType, childName) {
2336 {
2337 // Generic functions
2338 if ("value" in parentType) {
2339 const rv = resolveValue(parentType.value);
2340 if ("type" in rv.expr) {
2341 const t = zigAnalysis.types[rv.expr.type];
2342 if (t.kind == typeKinds.Fn && t.generic_ret != null) {
2343 const rgr = resolveValue({expr: t.generic_ret});
2344 if ("type" in rgr.expr) {
2345 parentType = zigAnalysis.types[rgr.expr.type];
2346 }
2347 }
2348 }
2349 }
2350 }
2351
2352
2336 if (!parentType.pubDecls) return null;2353 if (!parentType.pubDecls) return null;
2337 for (let i = 0; i < parentType.pubDecls.length; i += 1) {2354 for (let i = 0; i < parentType.pubDecls.length; i += 1) {
2338 let declIndex = parentType.pubDecls[i];2355 let declIndex = parentType.pubDecls[i];
src/Autodoc.zig+32-8
...@@ -3885,12 +3885,32 @@ fn analyzeFunctionExtended(...@@ -3885,12 +3885,32 @@ fn analyzeFunctionExtended(
3885 _ = try self.walkRef(file, scope, align_ref, false);3885 _ = try self.walkRef(file, scope, align_ref, false);
3886 }3886 }
38873887
3888 // TODO: a complete version of this will probably need a scope
3889 // in order to evaluate correctly closures around funcion
3890 // parameters etc.
3891 const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) {
3892 .type => |t| blk: {
3893 if (fn_info.body.len == 0) break :blk null;
3894 if (t == @enumToInt(Ref.type_type)) {
3895 break :blk try self.getGenericReturnType(
3896 file,
3897 scope,
3898 fn_info.body[fn_info.body.len - 1],
3899 );
3900 } else {
3901 break :blk null;
3902 }
3903 },
3904 else => null,
3905 };
3906
3888 self.types.items[type_slot_index] = .{3907 self.types.items[type_slot_index] = .{
3889 .Fn = .{3908 .Fn = .{
3890 .name = "todo_name func",3909 .name = "todo_name func",
3891 .src = self_ast_node_index,3910 .src = self_ast_node_index,
3892 .params = param_type_refs.items,3911 .params = param_type_refs.items,
3893 .ret = ret_type_ref.expr,3912 .ret = ret_type_ref.expr,
3913 .generic_ret = generic_ret,
3894 .is_extern = extra.data.bits.is_extern,3914 .is_extern = extra.data.bits.is_extern,
3895 .has_cc = extra.data.bits.has_cc,3915 .has_cc = extra.data.bits.has_cc,
3896 .has_align = extra.data.bits.has_align,3916 .has_align = extra.data.bits.has_align,
...@@ -3995,14 +4015,18 @@ fn analyzeFunction(...@@ -3995,14 +4015,18 @@ fn analyzeFunction(
3995 // in order to evaluate correctly closures around funcion4015 // in order to evaluate correctly closures around funcion
3996 // parameters etc.4016 // parameters etc.
3997 const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) {4017 const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) {
3998 .type => |t| if (t == @enumToInt(Ref.type_type))4018 .type => |t| blk: {
3999 try self.getGenericReturnType(4019 if (fn_info.body.len == 0) break :blk null;
4000 file,4020 if (t == @enumToInt(Ref.type_type)) {
4001 scope,4021 break :blk try self.getGenericReturnType(
4002 fn_info.body[fn_info.body.len - 1],4022 file,
4003 )4023 scope,
4004 else4024 fn_info.body[fn_info.body.len - 1],
4005 null,4025 );
4026 } else {
4027 break :blk null;
4028 }
4029 },
4006 else => null,4030 else => null,
4007 };4031 };
40084032