feature. See also
. The project being documented here (as the example) is the Zig library itself.
Translator.transFloatLiteral
fn transFloatLiteral(
t: *Translator,
scope: *Scope,
literal_index: Node.Index,
used: ResultUsed,
suppress_as: SuppressCast,
) TransError!ZigNode
File
Code
fn transFloatLiteral(
t: *Translator,
scope: *Scope,
literal_index: Node.Index,
used: ResultUsed,
suppress_as: SuppressCast,
) TransError!ZigNode {
if (try t.checkLiteralMacro(literal_index.tok(t.tree), used)) |node| return node;
const val = t.tree.value_map.get(literal_index).?;
const float_literal = literal_index.get(t.tree).float_literal;
var allocating: std.Io.Writer.Allocating = .init(t.gpa);
defer allocating.deinit();
_ = val.print(float_literal.qt, t.comp, &allocating.writer) catch return error.OutOfMemory;
if (mem.findScalar(u8, allocating.written(), '.') == null) {
allocating.writer.writeAll(".0") catch return error.OutOfMemory;
}
const float_lit_node = try ZigTag.float_literal.create(t.arena, try t.arena.dupe(u8, allocating.written()));
if (suppress_as == .no_as) {
return t.maybeSuppressResult(used, float_lit_node);
}
const as_node = try ZigTag.as.create(t.arena, .{
.lhs = try t.transType(scope, float_literal.qt, float_literal.literal_tok),
.rhs = float_lit_node,
});
return t.maybeSuppressResult(used, as_node);
}