autodoc: fixes to generic fn support plus linking support

This commit is contained in:
Loris Cro 2022-05-31 18:15:16 +02:00 committed by Andrew Kelley
parent 413cfd4066
commit d858f26139
2 changed files with 57 additions and 16 deletions

View File

@ -482,13 +482,13 @@ var zigAnalysis;
continue;
}
// if ("as" in value.expr) {
// value = {
// typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg],
// expr: zigAnalysis.exprs[value.expr.as.exprArg],
// };
// continue;
// }
if ("as" in value.expr) {
value = {
typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg],
expr: zigAnalysis.exprs[value.expr.as.exprArg],
};
continue;
}
return value;
@ -1355,7 +1355,7 @@ var zigAnalysis;
}
case "this":{
return "this";
return "@This()";
}
case "type": {
@ -2333,6 +2333,23 @@ var zigAnalysis;
* @param {string} childName
*/
function findSubDecl(parentType, childName) {
{
// Generic functions
if ("value" in parentType) {
const rv = resolveValue(parentType.value);
if ("type" in rv.expr) {
const t = zigAnalysis.types[rv.expr.type];
if (t.kind == typeKinds.Fn && t.generic_ret != null) {
const rgr = resolveValue({expr: t.generic_ret});
if ("type" in rgr.expr) {
parentType = zigAnalysis.types[rgr.expr.type];
}
}
}
}
}
if (!parentType.pubDecls) return null;
for (let i = 0; i < parentType.pubDecls.length; i += 1) {
let declIndex = parentType.pubDecls[i];

View File

@ -3885,12 +3885,32 @@ fn analyzeFunctionExtended(
_ = try self.walkRef(file, scope, align_ref, false);
}
// TODO: a complete version of this will probably need a scope
// in order to evaluate correctly closures around funcion
// parameters etc.
const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) {
.type => |t| blk: {
if (fn_info.body.len == 0) break :blk null;
if (t == @enumToInt(Ref.type_type)) {
break :blk try self.getGenericReturnType(
file,
scope,
fn_info.body[fn_info.body.len - 1],
);
} else {
break :blk null;
}
},
else => null,
};
self.types.items[type_slot_index] = .{
.Fn = .{
.name = "todo_name func",
.src = self_ast_node_index,
.params = param_type_refs.items,
.ret = ret_type_ref.expr,
.generic_ret = generic_ret,
.is_extern = extra.data.bits.is_extern,
.has_cc = extra.data.bits.has_cc,
.has_align = extra.data.bits.has_align,
@ -3995,14 +4015,18 @@ fn analyzeFunction(
// in order to evaluate correctly closures around funcion
// parameters etc.
const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) {
.type => |t| if (t == @enumToInt(Ref.type_type))
try self.getGenericReturnType(
file,
scope,
fn_info.body[fn_info.body.len - 1],
)
else
null,
.type => |t| blk: {
if (fn_info.body.len == 0) break :blk null;
if (t == @enumToInt(Ref.type_type)) {
break :blk try self.getGenericReturnType(
file,
scope,
fn_info.body[fn_info.body.len - 1],
);
} else {
break :blk null;
}
},
else => null,
};