mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
autodoc: fixes to generic fn support plus linking support
This commit is contained in:
parent
413cfd4066
commit
d858f26139
@ -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];
|
||||
|
||||
@ -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,
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user