Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/basewin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub fn BaseWindow(comptime DERIVED_TYPE: type) type {
if (uMsg == win32.WM_NCCREATE) {
const pCreate: *win32.CREATESTRUCTW = @ptrFromInt(@as(usize, @bitCast(lParam)));
pThis = @ptrCast(@alignCast(pCreate.lpCreateParams));
_ = windowlongptr.SetWindowLongPtr(hwnd, win32.GWL_USERDATA, @bitCast(@intFromPtr(pThis)));
_ = windowlongptr.SetWindowLongPtrW(hwnd, win32.GWL_USERDATA, @bitCast(@intFromPtr(pThis)));
pThis.?.base.m_hwnd = hwnd;
} else {
//pThis = @intToPtr(?*DERIVED_TYPE, @bitCast(usize, windowlongptr.GetWindowLongPtr(hwnd, win32.GWL_USERDATA)));
pThis = @ptrFromInt(@as(usize, @bitCast(windowlongptr.GetWindowLongPtr(hwnd, win32.GWL_USERDATA))));
pThis = @ptrFromInt(@as(usize, @bitCast(windowlongptr.GetWindowLongPtrW(hwnd, win32.GWL_USERDATA))));
}
if (pThis) |this| {
return this.HandleMessage(uMsg, wParam, lParam);
Expand Down
19 changes: 0 additions & 19 deletions src/genzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,6 @@ fn generateFile(module_dir: std.fs.Dir, module: *Module, api: metadata.Api) !voi
}
std.debug.assert(api.Functions.len >= sdk_file.func_exports.count());
try writer.line("");
try writer.line("//--------------------------------------------------------------------------------");
try writer.linef("// Section: Unicode Aliases ({})", .{api.UnicodeAliases.len});
try writer.line("//--------------------------------------------------------------------------------");
try generateUnicodeAliases(sdk_file, writer, api.UnicodeAliases);
const import_total = @intFromBool(sdk_file.uses_guid) + sdk_file.top_level_api_imports.count();
try writer.line("//--------------------------------------------------------------------------------");
try writer.linef("// Section: Imports ({})", .{import_total});
Expand Down Expand Up @@ -3137,21 +3133,6 @@ fn generateParams(
}
}

fn generateUnicodeAliases(sdk_file: *SdkFile, writer: *CodeWriter, unicode_aliases: []const []const u8) !void {
for (unicode_aliases) |alias| {
try writer.linef(
"pub const {s} = switch (@import(\"{s}zig.zig\").unicode_mode) {{",
.{ alias, sdk_file.getWin32DirImportPrefix() },
);
try writer.linef(" .ansi => @This().{s}A,", .{alias});
try writer.linef(" .wide => @This().{s}W,", .{alias});
try writer.line(" .unspecified => if (@import(\"builtin\").is_test) void else @compileError(");
try writer.linef(" \"'{0s}' requires that UNICODE be set to true or false in the root module\",", .{alias});
try writer.line(" ),");
try writer.line("};");
}
}

pub fn formatArchesCase(filter: metadata.Architectures.Filter, buf: []u8) !usize {
var fbs = std.io.fixedBufferStream(buf);
const arch_writer = fbs.writer();
Expand Down
3 changes: 0 additions & 3 deletions src/genzigexports.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const std = @import("std");
const win32_stub = @import("win32_stub");
const zig = win32_stub.zig;

// make win32/zig.zig happy
pub const UNICODE = true;

pub fn main() !void {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const arena = arena_instance.allocator();
Expand Down
1 change: 0 additions & 1 deletion src/metadata.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub const Api = struct {
Constants: []const Constant,
Types: []const Type,
Functions: []const Function,
UnicodeAliases: []const []const u8,
};

pub const ValueType = enum {
Expand Down
12 changes: 0 additions & 12 deletions src/static/win32/windowlongptr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,3 @@ pub const GetWindowLongPtrW = if (@sizeOf(usize) == 8)
win32.ui.windows_and_messaging.GetWindowLongPtrW
else
win32.ui.windows_and_messaging.GetWindowLongW;

pub const SetWindowLongPtr = switch (@import("zig.zig").unicode_mode) {
.ansi => SetWindowLongPtrA,
.wide => SetWindowLongPtrW,
.unspecified => if (@import("builtin").is_test) *opaque {} else @compileError("'SetWindowLongPtr' requires that UNICODE be set to true or false in the root module"),
};

pub const GetWindowLongPtr = switch (@import("zig.zig").unicode_mode) {
.ansi => GetWindowLongPtrA,
.wide => GetWindowLongPtrW,
.unspecified => if (@import("builtin").is_test) *opaque {} else @compileError("'GetWindowLongPtr' requires that UNICODE be set to true or false in the root module"),
};
35 changes: 0 additions & 35 deletions src/static/win32/zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,8 @@ const win32 = struct {
const GetDpiForWindow = mod_root.ui.hi_dpi.GetDpiForWindow;
};

const root = @import("root");
pub const UnicodeMode = enum { ansi, wide, unspecified };
pub const unicode_mode: UnicodeMode = if (@hasDecl(root, "UNICODE")) (if (root.UNICODE) .wide else .ansi) else .unspecified;

pub const L = std.unicode.utf8ToUtf16LeStringLiteral;

pub const TCHAR = switch (unicode_mode) {
.ansi => u8,
.wide => u16,
.unspecified => if (builtin.is_test) void else @compileError("'TCHAR' requires that UNICODE be set to true or false in the root module"),
};
pub const _T = switch (unicode_mode) {
.ansi => (struct {
pub fn _T(comptime str: []const u8) *const [str.len:0]u8 {
return str;
}
})._T,
.wide => L,
.unspecified => if (builtin.is_test) void else @compileError("'_T' requires that UNICODE be set to true or false in the root module"),
};

pub const Arch = enum { X86, X64, Arm64 };
pub const arch: Arch = switch (builtin.target.cpu.arch) {
.x86 => .X86,
Expand Down Expand Up @@ -402,22 +383,6 @@ pub const has_window_longptr = switch (arch) {
.X64, .Arm64 => true,
};

pub const getWindowLongPtr = switch (unicode_mode) {
.ansi => getWindowLongPtrA,
.wide => getWindowLongPtrW,
.unspecified => if (builtin.is_test) struct {} else @compileError(
"getWindowLongPtr requires that UNICODE be set to true or false in the root module",
),
};

pub const setWindowLongPtr = switch (unicode_mode) {
.ansi => setWindowLongPtrA,
.wide => setWindowLongPtrW,
.unspecified => if (builtin.is_test) struct {} else @compileError(
"setWindowLongPtr requires that UNICODE be set to true or false in the root module",
),
};

pub fn getWindowLongPtrA(hwnd: win32.HWND, index: i32) usize {
if (!has_window_longptr) @compileError("this arch does not have GetWindowLongPtr");
return @bitCast(win32.GetWindowLongPtrA(hwnd, @enumFromInt(index)));
Expand Down
55 changes: 1 addition & 54 deletions src/textparse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! see dumpwinmd-grammar.md) and rebuilds `metadata.Api`, applying the win32
//! corrections that dumpwinmd deliberately leaves out — patches, the
//! MediaFoundation constant filter, ComClassID/not_com derivation, MissingClrType
//! classification, UnicodeAliases, and the platform string->enum mapping.
//! classification, and the platform string->enum mapping.
//! This is the generator's input path: winmd -> text (dumpwinmd) -> model (here)
//! -> bindings. It reads text only; it does not depend on `winmd`.

Expand Down Expand Up @@ -387,12 +387,10 @@ fn finalize(
) void {
switch (frame.data) {
.api => |*a| {
const aliases = deriveAliases(arena, a.types.items, a.funcs.items);
result.append(arena, .{ .name = a.name, .api = .{
.Constants = a.consts.items,
.Types = a.types.items,
.Functions = a.funcs.items,
.UnicodeAliases = aliases,
} }) catch |e| oom(e);
},
.enum_ => |*e| attachType(arena, stack, .{
Expand Down Expand Up @@ -562,57 +560,6 @@ fn deriveComment(arena: std.mem.Allocator, constfields: []const ConstField) ?[]c
return aw.written();
}

// Derives UnicodeAliases from the type and function names (base names that have
// both an "A" and a "W" variant). Types are visited
// before functions, in declaration order.
fn deriveAliases(arena: std.mem.Allocator, types: []const metadata.Type, funcs: []const metadata.Function) []const []const u8 {
var ua: UnicodeAliases = .{};
for (types) |t| ua.add(arena, t.Name);
for (funcs) |f| ua.add(arena, f.Name);
var aliases: std.ArrayListUnmanaged([]const u8) = .empty;
var it = ua.map.iterator();
while (it.next()) |entry| switch (entry.value_ptr.*) {
.base_exists, .a_only, .w_only => {},
.both => aliases.append(arena, entry.key_ptr.*) catch |e| oom(e),
};
return aliases.items;
}

const UnicodeAliases = struct {
map: std.StringArrayHashMapUnmanaged(State) = .{},
const State = enum { base_exists, a_only, w_only, both };
pub fn add(aliases: *UnicodeAliases, allocator: std.mem.Allocator, name: []const u8) void {
if (name.len <= 1) return;
const kind: enum { a, w, base }, const key = blk: {
if (std.mem.endsWith(u8, name, "A")) break :blk .{ .a, name[0 .. name.len - 1] };
if (std.mem.endsWith(u8, name, "W")) break :blk .{ .w, name[0 .. name.len - 1] };
break :blk .{ .base, name };
};
const entry = aliases.map.getOrPut(allocator, key) catch |e| oom(e);
const sub_kind: enum { a, w } = switch (kind) {
.a => .a,
.w => .w,
.base => {
entry.value_ptr.* = .base_exists;
return;
},
};
if (entry.found_existing) switch (entry.value_ptr.*) {
.base_exists => return,
.a_only => if (sub_kind == .w) {
entry.value_ptr.* = .both;
},
.w_only => if (sub_kind == .a) {
entry.value_ptr.* = .both;
},
.both => {},
} else entry.value_ptr.* = switch (sub_kind) {
.a => .a_only,
.w => .w_only,
};
}
};

// Windows.* CLR types that are referenced but not defined in this winmd (dumpwinmd
// emits them as `extref`); the reference generator classified these as MissingClrType.
fn isKnownMissingClrType(namespace: []const u8, name: []const u8) bool {
Expand Down
Loading