diff --git a/build.zig b/build.zig index 9c2316e..b06fd7a 100644 --- a/build.zig +++ b/build.zig @@ -26,7 +26,7 @@ pub fn build(b: *std.Build) !void { }); tests.linkSystemLibrary("objc"); tests.linkFramework("Foundation"); - try addAppleSDK(b, &tests.root_module); + try addAppleSDK(b, tests.root_module); b.installArtifact(tests); const test_step = b.step("test", "Run tests"); diff --git a/src/block.zig b/src/block.zig index ccdb4fe..549475f 100644 --- a/src/block.zig +++ b/src/block.zig @@ -1,13 +1,13 @@ const std = @import("std"); const assert = std.debug.assert; +const alloc = std.heap.raw_c_allocator; + const objc = @import("main.zig"); // We have to use the raw C allocator for all heap allocation in here // because the objc runtime expects `malloc` to be used. If you don't use // malloc you'll get segfaults because the objc runtime will try to free // the memory with `free`. -const alloc = std.heap.raw_c_allocator; - /// Creates a new block type with captured (closed over) values. /// /// The CapturesArg is the a struct of captured values that will become @@ -34,7 +34,7 @@ pub fn Block( ) type { return struct { const Self = @This(); - const captures_info = @typeInfo(Captures).Struct; + const captures_info = @typeInfo(Captures).@"struct"; const InvokeFn = FnType(anyopaque); const descriptor: Descriptor = .{ .reserved = 0, @@ -63,7 +63,7 @@ pub fn Block( var ctx = try alloc.create(Context); errdefer alloc.destroy(ctx); - const flags: BlockFlags = .{ .stret = @typeInfo(Return) == .Struct }; + const flags: BlockFlags = .{ .stret = @typeInfo(Return) == .@"struct" }; ctx.isa = NSConcreteStackBlock; ctx.flags = @bitCast(flags); ctx.invoke = @ptrCast(func); @@ -120,7 +120,7 @@ pub fn Block( } return @Type(.{ - .Fn = .{ + .@"fn" = .{ .calling_convention = .C, .is_generic = false, .is_var_args = false, @@ -135,40 +135,40 @@ pub fn Block( /// This is the type of a block structure that is passed as the first /// argument to any block invocation. See Block. fn BlockContext(comptime Captures: type, comptime InvokeFn: type) type { - const captures_info = @typeInfo(Captures).Struct; + const captures_info = @typeInfo(Captures).@"struct"; var fields: [captures_info.fields.len + 5]std.builtin.Type.StructField = undefined; fields[0] = .{ .name = "isa", .type = ?*anyopaque, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(*anyopaque), }; fields[1] = .{ .name = "flags", .type = c_int, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(c_int), }; fields[2] = .{ .name = "reserved", .type = c_int, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(c_int), }; fields[3] = .{ .name = "invoke", .type = *const InvokeFn, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, - .alignment = @typeInfo(*const InvokeFn).Pointer.alignment, + .alignment = @typeInfo(*const InvokeFn).pointer.alignment, }; fields[4] = .{ .name = "descriptor", .type = *const Descriptor, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(*Descriptor), }; @@ -183,14 +183,14 @@ fn BlockContext(comptime Captures: type, comptime InvokeFn: type) type { fields[i] = .{ .name = capture.name, .type = capture.type, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = capture.alignment, }; } return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .@"extern", .fields = &fields, .decls = &.{}, diff --git a/src/c.zig b/src/c.zig index 00469a1..04d6023 100644 --- a/src/c.zig +++ b/src/c.zig @@ -6,7 +6,7 @@ pub const c = @cImport({ /// This is a funky helper to help with the fact that some macOS /// SDKs have an i8 return value for bools and some have stdbool. pub fn boolResult(comptime Fn: type, result: anytype) bool { - const fn_info = @typeInfo(Fn).Fn; + const fn_info = @typeInfo(Fn).@"fn"; return switch (fn_info.return_type.?) { bool => result, i8 => result == 1, diff --git a/src/class.zig b/src/class.zig index 18dd871..24b6f1d 100644 --- a/src/class.zig +++ b/src/class.zig @@ -57,8 +57,8 @@ pub const Class = struct { // imp should be a function with C calling convention // whose first two arguments are a `c.id` and a `c.SEL`. pub fn replaceMethod(self: Class, name: [:0]const u8, imp: anytype) void { - const fn_info = @typeInfo(@TypeOf(imp)).Fn; - assert(fn_info.calling_convention == .C); + const fn_info = @typeInfo(@TypeOf(imp)).@"fn"; + assert(fn_info.calling_convention.eql(.c)); assert(fn_info.is_var_args == false); assert(fn_info.params.len >= 2); assert(fn_info.params[0].type == c.id); @@ -71,8 +71,8 @@ pub const Class = struct { // whose first two arguments are a `c.id` and a `c.SEL`. pub fn addMethod(self: Class, name: [:0]const u8, imp: anytype) !bool { const Fn = @TypeOf(imp); - const fn_info = @typeInfo(Fn).Fn; - assert(fn_info.calling_convention == .C); + const fn_info = @typeInfo(Fn).@"fn"; + assert(fn_info.calling_convention.eql(.c)); assert(fn_info.is_var_args == false); assert(fn_info.params.len >= 2); assert(fn_info.params[0].type == c.id); diff --git a/src/encoding.zig b/src/encoding.zig index 9dcb64c..38a375d 100644 --- a/src/encoding.zig +++ b/src/encoding.zig @@ -83,14 +83,14 @@ pub const Encoding = union(enum) { c.Class, objc.Class => .class, c.id, objc.Object => .object, else => switch (@typeInfo(T)) { - .Array => |arr| .{ .array = .{ .len = arr.len, .arr_type = arr.child } }, - .Struct => .{ .structure = .{ .struct_type = T, .show_type_spec = true } }, - .Union => .{ .@"union" = .{ + .array => |arr| .{ .array = .{ .len = arr.len, .arr_type = arr.child } }, + .@"struct" => .{ .structure = .{ .struct_type = T, .show_type_spec = true } }, + .@"union" => .{ .@"union" = .{ .union_type = T, .show_type_spec = true, } }, - .Pointer => |ptr| .{ .pointer = .{ .ptr_type = T, .size = ptr.size } }, - .Fn => |fn_info| .{ .function = fn_info }, + .pointer => |ptr| .{ .pointer = .{ .ptr_type = T, .size = ptr.size } }, + .@"fn" => |fn_info| .{ .function = fn_info }, else => @compileError("unsupported type: " ++ @typeName(T)), }, }; @@ -129,7 +129,7 @@ pub const Encoding = union(enum) { }, .structure => |s| { const struct_info = @typeInfo(s.struct_type); - assert(struct_info.Struct.layout == .@"extern"); + assert(struct_info.@"struct".layout == .@"extern"); // Strips the fully qualified type name to leave just the // type name. Used in naming the Struct in an encoding. @@ -141,7 +141,7 @@ pub const Encoding = union(enum) { // of the struct (determined by levels of pointer indirection) if (s.show_type_spec) { try writer.writeAll("="); - inline for (struct_info.Struct.fields) |field| { + inline for (struct_info.@"struct".fields) |field| { const field_encode = init(field.type); try field_encode.format(fmt, options, writer); } @@ -151,7 +151,7 @@ pub const Encoding = union(enum) { }, .@"union" => |u| { const union_info = @typeInfo(u.union_type); - assert(union_info.Union.layout == .@"extern"); + assert(union_info.@"union".layout == .@"extern"); // Strips the fully qualified type name to leave just the // type name. Used in naming the Union in an encoding @@ -163,7 +163,7 @@ pub const Encoding = union(enum) { // of the Union (determined by levels of pointer indirection) if (u.show_type_spec) { try writer.writeAll("="); - inline for (union_info.Union.fields) |field| { + inline for (union_info.@"union".fields) |field| { const field_encode = init(field.type); try field_encode.format(fmt, options, writer); } @@ -174,7 +174,7 @@ pub const Encoding = union(enum) { .bitfield => |b| try writer.print("b{}", .{b}), // not sure if needed from Zig -> Obj-C .pointer => |p| { switch (p.size) { - .One => { + .one => { // get the pointer info (count of levels of direction // and the underlying type) const pointer_info = indirectionCountAndType(p.ptr_type); @@ -206,7 +206,7 @@ pub const Encoding = union(enum) { } }, .function => |fn_info| { - assert(fn_info.calling_convention == .C); + assert(fn_info.calling_convention.eql(.c)); // Return type is first in a method encoding const ret_type_enc = init(fn_info.return_type.?); @@ -230,8 +230,8 @@ fn indirectionCountAndType(comptime T: type) struct { } { var WalkType = T; var count: usize = 0; - while (@typeInfo(WalkType) == .Pointer) : (count += 1) { - WalkType = @typeInfo(WalkType).Pointer.child; + while (@typeInfo(WalkType) == .pointer) : (count += 1) { + WalkType = @typeInfo(WalkType).pointer.child; } return .{ .child = WalkType, .indirection_levels = count }; diff --git a/src/msg_send.zig b/src/msg_send.zig index b4dd69b..8ad9ee8 100644 --- a/src/msg_send.zig +++ b/src/msg_send.zig @@ -174,7 +174,7 @@ fn MsgSendFn( comptime Target: type, comptime Args: type, ) type { - const argsInfo = @typeInfo(Args).Struct; + const argsInfo = @typeInfo(Args).@"struct"; assert(argsInfo.is_tuple); // Target must always be an "id". Lots of types (Class, Object, etc.) @@ -203,7 +203,7 @@ fn MsgSendFn( }; return @Type(.{ - .Fn = .{ + .@"fn" = .{ .calling_convention = .C, .is_generic = false, .is_var_args = false,