feature. See also
. The project being documented here (as the example) is the Zig library itself.
Translator.transStaticAssert
fn transStaticAssert(t: *Translator, scope: *Scope, static_assert: Node.StaticAssert) Error!void
File
Code
fn transStaticAssert(t: *Translator, scope: *Scope, static_assert: Node.StaticAssert) Error!void {
const condition = t.transExpr(scope, static_assert.cond, .used) catch |err| switch (err) {
error.SelfReferential => unreachable,
error.UnsupportedTranslation, error.UnsupportedType => {
return try t.warn(&t.global_scope.base, static_assert.cond.tok(t.tree), "unable to translate _Static_assert condition", .{});
},
error.OutOfMemory => |e| return e,
};
const diagnostic = if (static_assert.message) |message| str: {
const str_val = t.tree.value_map.get(message).?;
const str_qt = message.qt(t.tree);
const bytes = t.comp.interner.get(str_val.ref()).bytes;
var allocating: std.Io.Writer.Allocating = .init(t.gpa);
defer allocating.deinit();
allocating.writer.writeAll("\"static assertion failed \\") catch return error.OutOfMemory;
aro.Value.printString(bytes, str_qt, t.comp, &allocating.writer) catch return error.OutOfMemory;
allocating.writer.end -= 1;
allocating.writer.writeAll("\\\"\"") catch return error.OutOfMemory;
break :str try ZigTag.string_literal.create(t.arena, try t.arena.dupe(u8, allocating.written()));
} else try ZigTag.string_literal.create(t.arena, "\"static assertion failed\"");
const assert_node = try ZigTag.static_assert.create(t.arena, .{ .lhs = condition, .rhs = diagnostic });
try scope.appendNode(assert_node);
}