diff --git a/generator/main.zig b/generator/main.zig index de33d43..4c7ce9e 100644 --- a/generator/main.zig +++ b/generator/main.zig @@ -139,5 +139,4 @@ test "main" { _ = @import("registry/c-parse.zig"); } -// TODO: Fix not all enums being parsed. // TODO: Fix not all struct fields being marked as optional properly. diff --git a/generator/registry/parse.zig b/generator/registry/parse.zig index 1654d52..6421a50 100644 --- a/generator/registry/parse.zig +++ b/generator/registry/parse.zig @@ -60,8 +60,6 @@ fn parseTypes(allocator: *Allocator, out: []registry.Declaration, types_elem: *x break :blk try parseForeigntype(ty); }; - // Enums are handled later, in parseEnums. This also has the effect of filtering - // out any enums which have no elements, and should be unused by other parts of the API. if (mem.eql(u8, category, "bitmask")) { break :blk try parseBitmaskType(ty); } else if (mem.eql(u8, category, "handle")) { @@ -74,6 +72,8 @@ fn parseTypes(allocator: *Allocator, out: []registry.Declaration, types_elem: *x break :blk try parseContainer(allocator, ty, true); } else if (mem.eql(u8, category, "funcpointer")) { break :blk try parseFuncPointer(allocator, ty); + } else if (mem.eql(u8, category, "enum")) { + break :blk (try parseEnumAlias(allocator, ty)) orelse continue; } continue; @@ -234,6 +234,18 @@ fn parsePointerMeta(type_info: *registry.TypeInfo, elem: *xml.Element) !void { } } +fn parseEnumAlias(allocator: *Allocator, elem: *xml.Element) !?registry.Declaration { + if (elem.getAttribute("alias")) |alias| { + const name = elem.getAttribute("name") orelse return error.InvalidRegistry; + return registry.Declaration{ + .name = name, + .decl_type = .{.alias = .{.name = alias, .target = .other_type}}, + }; + } + + return null; +} + fn parseEnums(allocator: *Allocator, out: []registry.Declaration, root: *xml.Element) !usize { var i: usize = 0; var it = root.findChildrenByTag("enums");