Skip to content

Commit

Permalink
Update for latest Zig
Browse files Browse the repository at this point in the history
  • Loading branch information
squeek502 committed Jun 24, 2023
1 parent d7b808e commit 7f34f4d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/bmp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo {

bitmap_info.colors_in_palette = try dib_header.numColorsInTable();
bitmap_info.bytes_per_color_palette_element = 4;
bitmap_info.compression = @intToEnum(Compression, dib_header.biCompression);
bitmap_info.compression = @enumFromInt(Compression, dib_header.biCompression);

if (bitmap_info.getByteLenBetweenHeadersAndPixels() < bitmap_info.getBitmasksByteLen()) {
return error.MissingBitfieldMasks;
Expand Down
8 changes: 4 additions & 4 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub const Options = struct {
try writer.print("Default language: {s} (id=0x{x})\n", .{ language_name, language_id });

const code_page = self.default_code_page orelse .windows1252;
try writer.print("Default codepage: {s} (id={})\n", .{ @tagName(code_page), @enumToInt(code_page) });
try writer.print("Default codepage: {s} (id={})\n", .{ @tagName(code_page), @intFromEnum(code_page) });
}
};

Expand Down Expand Up @@ -333,7 +333,7 @@ pub const Arg = struct {
const prefix_len = arg.prefixSlice().len;
switch (self.index_increment) {
1 => return .{
.value_offset = @ptrToInt(self.slice.ptr) - @ptrToInt(arg.full.ptr),
.value_offset = @intFromPtr(self.slice.ptr) - @intFromPtr(arg.full.ptr),
.prefix_len = prefix_len,
.name_offset = arg.name_offset,
},
Expand Down Expand Up @@ -548,8 +548,8 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn
arg_i += value.index_increment;
continue :next_arg;
}
const percent_float = @intToFloat(f32, percent) / 100;
options.max_string_literal_codepoints = @floatToInt(u15, percent_float * max_string_literal_length_100_percent);
const percent_float = @floatFromInt(f32, percent) / 100;
options.max_string_literal_codepoints = @intFromFloat(u15, percent_float * max_string_literal_length_100_percent);
arg_i += value.index_increment;
continue :next_arg;
} else if (std.ascii.startsWithIgnoreCase(arg_name, "ln")) {
Expand Down
18 changes: 9 additions & 9 deletions src/compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ pub const Compiler = struct {
.GROUP_CURSOR => .ANICURSOR,
else => unreachable,
};
header.type_value.ordinal = @enumToInt(new_predefined_type);
header.type_value.ordinal = @intFromEnum(new_predefined_type);
header.memory_flags = MemoryFlags.defaults(new_predefined_type);
header.applyMemoryFlags(node.common_resource_attributes, self.source);
header.data_size = @intCast(u32, try file.getEndPos());
Expand Down Expand Up @@ -501,7 +501,7 @@ pub const Compiler = struct {
applyToGroupMemoryFlags(&header.memory_flags, node.common_resource_attributes, self.source);

const first_icon_id = self.state.icon_id;
const entry_type = if (predefined_type == .GROUP_ICON) @enumToInt(res.RT.ICON) else @enumToInt(res.RT.CURSOR);
const entry_type = if (predefined_type == .GROUP_ICON) @intFromEnum(res.RT.ICON) else @intFromEnum(res.RT.CURSOR);
for (icon_dir.entries, 0..) |*entry, entry_i_usize| {
// We know that the entry index must fit within a u16, so
// cast it here to simplify usage sites.
Expand Down Expand Up @@ -1672,7 +1672,7 @@ pub const Compiler = struct {
}

if (res.ControlClass.fromControl(control_type)) |control_class| {
const ordinal = NameOrOrdinal{ .ordinal = @enumToInt(control_class) };
const ordinal = NameOrOrdinal{ .ordinal = @intFromEnum(control_class) };
try ordinal.write(data_writer);
} else {
const class_node = control.class.?;
Expand Down Expand Up @@ -1707,7 +1707,7 @@ pub const Compiler = struct {
const parsed = try self.parseQuotedStringAsWideString(literal_node.token);
defer self.allocator.free(parsed);
if (rc.ControlClass.fromWideString(parsed)) |control_class| {
const ordinal = NameOrOrdinal{ .ordinal = @enumToInt(control_class) };
const ordinal = NameOrOrdinal{ .ordinal = @intFromEnum(control_class) };
try ordinal.write(data_writer);
} else {
// NUL acts as a terminator
Expand All @@ -1722,7 +1722,7 @@ pub const Compiler = struct {
const literal_slice = literal_node.token.slice(self.source);
// This succeeding is guaranteed by the parser
const control_class = rc.ControlClass.map.get(literal_slice) orelse unreachable;
const ordinal = NameOrOrdinal{ .ordinal = @enumToInt(control_class) };
const ordinal = NameOrOrdinal{ .ordinal = @intFromEnum(control_class) };
try ordinal.write(data_writer);
}
}
Expand Down Expand Up @@ -1853,7 +1853,7 @@ pub const Compiler = struct {
}

if (resource == .dialogex) {
try writer.writeIntLittle(u8, @boolToInt(values.italic));
try writer.writeIntLittle(u8, @intFromBool(values.italic));
}

if (node.char_set) |char_set| {
Expand Down Expand Up @@ -2370,7 +2370,7 @@ pub const Compiler = struct {
const type_value = type: {
const resource_type = Resource.fromString(type_bytes);
if (res.RT.fromResource(resource_type)) |rt_constant| {
break :type NameOrOrdinal{ .ordinal = @enumToInt(rt_constant) };
break :type NameOrOrdinal{ .ordinal = @intFromEnum(rt_constant) };
} else {
break :type try NameOrOrdinal.fromString(allocator, type_bytes);
}
Expand Down Expand Up @@ -2654,7 +2654,7 @@ pub const FontDir = struct {

var header = Compiler.ResourceHeader{
.name_value = try NameOrOrdinal.nameFromString(compiler.allocator, .{ .slice = "FONTDIR", .code_page = .windows1252 }),
.type_value = NameOrOrdinal{ .ordinal = @enumToInt(res.RT.FONTDIR) },
.type_value = NameOrOrdinal{ .ordinal = @intFromEnum(res.RT.FONTDIR) },
.memory_flags = res.MemoryFlags.defaults(res.RT.FONTDIR),
.language = compiler.state.language,
.version = compiler.state.version,
Expand Down Expand Up @@ -2911,7 +2911,7 @@ pub const StringTable = struct {

const header = Compiler.ResourceHeader{
.name_value = .{ .ordinal = block_id },
.type_value = .{ .ordinal = @enumToInt(res.RT.STRING) },
.type_value = .{ .ordinal = @intFromEnum(res.RT.STRING) },
.memory_flags = self.memory_flags,
.language = language,
.version = self.version,
Expand Down
2 changes: 1 addition & 1 deletion src/ico.zig
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub const IconDir = struct {

pub fn writeResData(self: IconDir, writer: anytype, first_image_id: u16) !void {
try writer.writeIntLittle(u16, 0);
try writer.writeIntLittle(u16, @enumToInt(self.image_type));
try writer.writeIntLittle(u16, @intFromEnum(self.image_type));
// We know that entries.len must fit into a u16
try writer.writeIntLittle(u16, @intCast(u16, self.entries.len));

Expand Down
2 changes: 1 addition & 1 deletion src/lang.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test parseInt {
pub fn tagToInt(tag: []const u8) error{InvalidLanguageTag}!u16 {
const maybe_id = try tagToId(tag);
if (maybe_id) |id| {
return @enumToInt(id);
return @intFromEnum(id);
} else {
return LOCALE_CUSTOM_UNSPECIFIED;
}
Expand Down
16 changes: 8 additions & 8 deletions src/rc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub const Resource = enum {
const maybe_ordinal = res.NameOrOrdinal.maybeOrdinalFromString(bytes);
if (maybe_ordinal) |ordinal| {
if (ordinal.ordinal >= 256) return .user_defined;
const rt = @intToEnum(res.RT, ordinal.ordinal);
const rt = @enumFromInt(res.RT, ordinal.ordinal);
return fromRT(rt);
}
return map.get(bytes.slice) orelse .user_defined;
Expand Down Expand Up @@ -131,13 +131,13 @@ pub const Resource = enum {
.toolbar, .versioninfo, .vxd => @tagName(resource),
// zig fmt: on
.user_defined => "user-defined",
.cursor_num => std.fmt.comptimePrint("{d} (cursor)", .{@enumToInt(res.RT.CURSOR)}),
.icon_num => std.fmt.comptimePrint("{d} (icon)", .{@enumToInt(res.RT.ICON)}),
.string_num => std.fmt.comptimePrint("{d} (string)", .{@enumToInt(res.RT.STRING)}),
.anicursor_num => std.fmt.comptimePrint("{d} (anicursor)", .{@enumToInt(res.RT.ANICURSOR)}),
.aniicon_num => std.fmt.comptimePrint("{d} (aniicon)", .{@enumToInt(res.RT.ANIICON)}),
.fontdir_num => std.fmt.comptimePrint("{d} (fontdir)", .{@enumToInt(res.RT.FONTDIR)}),
.manifest_num => std.fmt.comptimePrint("{d} (manifest)", .{@enumToInt(res.RT.MANIFEST)}),
.cursor_num => std.fmt.comptimePrint("{d} (cursor)", .{@intFromEnum(res.RT.CURSOR)}),
.icon_num => std.fmt.comptimePrint("{d} (icon)", .{@intFromEnum(res.RT.ICON)}),
.string_num => std.fmt.comptimePrint("{d} (string)", .{@intFromEnum(res.RT.STRING)}),
.anicursor_num => std.fmt.comptimePrint("{d} (anicursor)", .{@intFromEnum(res.RT.ANICURSOR)}),
.aniicon_num => std.fmt.comptimePrint("{d} (aniicon)", .{@intFromEnum(res.RT.ANIICON)}),
.fontdir_num => std.fmt.comptimePrint("{d} (fontdir)", .{@intFromEnum(res.RT.FONTDIR)}),
.manifest_num => std.fmt.comptimePrint("{d} (manifest)", .{@intFromEnum(res.RT.MANIFEST)}),
};
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/res.zig
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub const NameOrOrdinal = union(enum) {
switch (self) {
.ordinal => |ordinal| {
if (ordinal >= 256) return null;
switch (@intToEnum(RT, ordinal)) {
switch (@enumFromInt(RT, ordinal)) {
.ACCELERATOR,
.ANICURSOR,
.ANIICON,
Expand Down

0 comments on commit 7f34f4d

Please sign in to comment.