Skip to content

Commit

Permalink
fix appkit generation
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
slimsag committed Jul 29, 2024
1 parent e886c58 commit 1a8bcff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
27 changes: 22 additions & 5 deletions generator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ fn Generator(comptime WriterType: type) type {
defer inherited_method_sets.deinit();
if (container.super) |super| {
const will_generate = blk: {
if (std.mem.eql(u8, "NSObject", super.name)) break :blk true;
if (self.isExternalContainerName(super)) break :blk true;
if (getNamespace(super.name).len > 0) break :blk true;
for (self.containers.items) |container2| {
if (std.mem.eql(u8, container2.name, super.name)) break :blk true;
Expand All @@ -1202,7 +1202,7 @@ fn Generator(comptime WriterType: type) type {
}
for (container.protocols.items) |protocol| {
const will_generate = blk: {
if (std.mem.eql(u8, "NSObject", protocol.name)) break :blk true;
if (self.isExternalContainerName(protocol)) break :blk true;
if (getNamespace(protocol.name).len > 0) break :blk true;

for (self.containers.items) |container2| {
Expand All @@ -1221,9 +1221,18 @@ fn Generator(comptime WriterType: type) type {
try self.writer.print(" return struct {{\n", .{});

for (inherited_method_sets.items) |inherited| {
try self.writer.print(" pub usingnamespace ", .{});
try self.generateContainerName(inherited);
try self.writer.print(".Methods(T);\n", .{});
const will_generate = blk: {
if (self.isExternalContainerName(inherited)) break :blk true;
for (self.containers.items) |container2| {
if (std.mem.eql(u8, container2.name, inherited.name)) break :blk true;
}
break :blk false;
};
if (will_generate) {
try self.writer.print(" pub usingnamespace ", .{});
try self.generateContainerName(inherited);
try self.writer.print(".Methods(T);\n", .{});
}
}
if (inherited_method_sets.items.len > 0) {
try self.writer.print("\n", .{});
Expand Down Expand Up @@ -1546,6 +1555,14 @@ fn Generator(comptime WriterType: type) type {
try self.generateContainerSuffix(container);
}

fn isExternalContainerName(self: *Self, container: *Container) bool {
const namespace = getNamespace(container.name);
if (namespace.len > 0 and !std.mem.eql(u8, namespace, self.namespace)) {
return true;
}
return false;
}

fn generateLower(self: *Self, str: []const u8) !void {
for (str) |ch| {
try self.writer.writeByte(std.ascii.toLower(ch));
Expand Down
4 changes: 0 additions & 4 deletions src/appkit/appkit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ pub const Application = opaque {

pub fn Methods(comptime T: type) type {
return struct {
pub usingnamespace Responder.Methods(T);

pub fn sharedApplication() *Application {
return @as(*const fn (*c.objc_class, *c.objc_selector) callconv(.C) *Application, @ptrCast(&c.objc_msgSend))(T.class(), sel_sharedApplication);
}
Expand All @@ -97,8 +95,6 @@ pub const Window = opaque {

pub fn Methods(comptime T: type) type {
return struct {
pub usingnamespace Responder.Methods(T);

pub fn initWithContentRect_styleMask_backing_defer_screen(self_: *T, contentRect_: Rect, style_: WindowStyleMask, backingStoreType_: BackingStoreType, flag_: bool, screen_: ?*Screen) *T {
return @as(*const fn (*T, *c.objc_selector, Rect, WindowStyleMask, BackingStoreType, bool, ?*Screen) callconv(.C) *T, @ptrCast(&c.objc_msgSend))(self_, sel_initWithContentRect_styleMask_backing_defer_screen_, contentRect_, style_, backingStoreType_, flag_, screen_);
}
Expand Down

0 comments on commit 1a8bcff

Please sign in to comment.