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;
482482 continue;
483483 }
484484
485// if ("as" in value.expr) {
486// value = {
487// typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg],
488// expr: zigAnalysis.exprs[value.expr.as.exprArg],
489// };
490// continue;
491// }
485 if ("as" in value.expr) {
486 value = {
487 typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg],
488 expr: zigAnalysis.exprs[value.expr.as.exprArg],
489 };
490 continue;
491 }
492492
493493 return value;
494494
......@@ -1355,7 +1355,7 @@ var zigAnalysis;
13551355 }
13561356
13571357 case "this":{
1358 return "this";
1358 return "@This()";
13591359 }
13601360
13611361 case "type": {
......@@ -2333,6 +2333,23 @@ var zigAnalysis;
23332333 * @param {string} childName
23342334 */
23352335 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
23362353 if (!parentType.pubDecls) return null;
23372354 for (let i = 0; i < parentType.pubDecls.length; i += 1) {
23382355 let declIndex = parentType.pubDecls[i];
src/Autodoc.zig+32-8
......@@ -3885,12 +3885,32 @@ fn analyzeFunctionExtended(
38853885 _ = try self.walkRef(file, scope, align_ref, false);
38863886 }
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
38883907 self.types.items[type_slot_index] = .{
38893908 .Fn = .{
38903909 .name = "todo_name func",
38913910 .src = self_ast_node_index,
38923911 .params = param_type_refs.items,
38933912 .ret = ret_type_ref.expr,
3913 .generic_ret = generic_ret,
38943914 .is_extern = extra.data.bits.is_extern,
38953915 .has_cc = extra.data.bits.has_cc,
38963916 .has_align = extra.data.bits.has_align,
......@@ -3995,14 +4015,18 @@ fn analyzeFunction(
39954015 // in order to evaluate correctly closures around funcion
39964016 // parameters etc.
39974017 const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) {
3998 .type => |t| if (t == @enumToInt(Ref.type_type))
3999 try self.getGenericReturnType(
4000 file,
4001 scope,
4002 fn_info.body[fn_info.body.len - 1],
4003 )
4004 else
4005 null,
4018 .type => |t| blk: {
4019 if (fn_info.body.len == 0) break :blk null;
4020 if (t == @enumToInt(Ref.type_type)) {
4021 break :blk try self.getGenericReturnType(
4022 file,
4023 scope,
4024 fn_info.body[fn_info.body.len - 1],
4025 );
4026 } else {
4027 break :blk null;
4028 }
4029 },
40064030 else => null,
40074031 };
40084032