autodoc: Added int_big support

This commit is contained in:
Der Teufel 2022-08-31 21:18:50 +02:00
parent 36f4f32fad
commit 0d3c6b7aa8
2 changed files with 38 additions and 13 deletions

View File

@ -1555,6 +1555,10 @@ var zigAnalysis;
return '"' + escapeHtml(expr.string) + '"';
}
case "int_big": {
return (expr.int_big.negated ? "-" : "") + expr.int_big.value;
}
case "anytype": {
return "anytype";
}

View File

@ -625,7 +625,7 @@ const DocData = struct {
negated: bool = false,
},
int_big: struct {
value: []const u8, // direct value
value: []const u8, // string representation
negated: bool = false,
},
float: f64, // direct value
@ -714,9 +714,12 @@ const DocData = struct {
},
.int_big => {
//@panic("TODO: json serialization of big ints!");
//if (v.negated) try w.writeAll("-");
//try jsw.emitNumber(v.value);
try jsw.beginObject();
try jsw.objectField("value");
try jsw.emitString(self.int_big.value);
try jsw.objectField("negated");
try jsw.emitBool(self.int_big.negated);
try jsw.endObject();
},
.builtinField => {
try jsw.emitString(@tagName(self.builtinField));
@ -1084,15 +1087,32 @@ fn walkInstruction(
},
.int_big => {
// @check
const str = data[inst_index].str.get(file.zir);
_ = str;
printWithContext(
file,
inst_index,
"TODO: implement `{s}` for walkInstruction\n\n",
.{@tagName(tags[inst_index])},
);
return self.cteTodo(@tagName(tags[inst_index]));
const str = data[inst_index].str; //.get(file.zir);
const byte_count = str.len * @sizeOf(std.math.big.Limb);
const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
std.mem.copy(u8, std.mem.sliceAsBytes(limbs), limb_bytes);
const big_int = std.math.big.int.Const{
.limbs = limbs,
.positive = true,
};
const as_string = try big_int.toStringAlloc(self.arena, 10, .lower);
return DocData.WalkResult{
.typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
.expr = .{ .int_big = .{ .value = as_string } },
};
// printWithContext(
// file,
// inst_index,
// "TODO: implement `{s}` for walkInstruction\n\n",
// .{@tagName(tags[inst_index])},
// );
// return self.cteTodo(@tagName(tags[inst_index]));
},
.slice_start => {
@ -1714,6 +1734,7 @@ fn walkInstruction(
);
switch (operand.expr) {
.int => |*int| int.negated = true,
.int_big => |*int_big| int_big.negated = true,
else => {
printWithContext(
file,