forked from mirror/vulkan-zig
Basic basetype parsing
This commit is contained in:
@@ -32,10 +32,11 @@ pub const TypeInfo = union(enum) {
|
||||
Handle: Handle,
|
||||
FnPtr: Command,
|
||||
Command: Command,
|
||||
Alias: []const u8,
|
||||
Alias: []const u8, // Alias of another declaration
|
||||
Pointer: Pointer,
|
||||
Array: Array,
|
||||
Opaque: void,
|
||||
Foreign: Foreign
|
||||
};
|
||||
|
||||
pub const Container = struct {
|
||||
@@ -108,3 +109,7 @@ pub const Array = struct {
|
||||
size: ArraySize,
|
||||
child: *TypeInfo,
|
||||
};
|
||||
|
||||
pub const Foreign = struct {
|
||||
dependency: []const u8, // Either a header or vk_platform
|
||||
};
|
||||
|
||||
@@ -53,17 +53,23 @@ fn parseTypes(allocator: *Allocator, out: []registry.Declaration, types_elem: *x
|
||||
var i: usize = 0;
|
||||
var it = types_elem.findChildrenByTag("type");
|
||||
while (it.next()) |ty| {
|
||||
// TODO: Handle foreign types
|
||||
const category = ty.getAttribute("category") orelse continue;
|
||||
out[i] = blk: {
|
||||
const category = ty.getAttribute("category") orelse {
|
||||
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.
|
||||
out[i] = if (mem.eql(u8, category, "bitmask"))
|
||||
try parseBitmaskType(ty)
|
||||
else if (mem.eql(u8, category, "handle"))
|
||||
try parseHandleType(ty)
|
||||
else
|
||||
continue;
|
||||
// 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")) {
|
||||
break :blk try parseHandleType(ty);
|
||||
} else if (mem.eql(u8, category, "basetype")) {
|
||||
break :blk try parseBaseType(ty);
|
||||
}
|
||||
|
||||
continue;
|
||||
};
|
||||
|
||||
i += 1;
|
||||
}
|
||||
@@ -71,6 +77,19 @@ fn parseTypes(allocator: *Allocator, out: []registry.Declaration, types_elem: *x
|
||||
return i;
|
||||
}
|
||||
|
||||
fn parseForeigntype(ty: *xml.Element) !registry.Declaration {
|
||||
const name = ty.getAttribute("name") orelse return error.InvalidRegistry;
|
||||
const dependency = ty.getAttribute("requires") orelse if (mem.eql(u8, name, "int"))
|
||||
"vk_platform" // for some reason, int doesn't depend on vk_platform (but the other c types do)
|
||||
else
|
||||
return error.InvalidRegistry;
|
||||
|
||||
return registry.Declaration{
|
||||
.name = name,
|
||||
.decl_type = .{.Foreign = .{.dependency = dependency}},
|
||||
};
|
||||
}
|
||||
|
||||
fn parseBitmaskType(ty: *xml.Element) !registry.Declaration {
|
||||
if (ty.getAttribute("name")) |name| {
|
||||
const alias = ty.getAttribute("alias") orelse return error.InvalidRegistry;
|
||||
@@ -114,6 +133,21 @@ fn parseHandleType(ty: *xml.Element) !registry.Declaration {
|
||||
}
|
||||
}
|
||||
|
||||
fn parseBaseType(ty: *xml.Element) !registry.Declaration {
|
||||
const name = ty.getCharData("name") orelse return error.InvalidRegistry;
|
||||
if (ty.getCharData("type")) |alias| { // TODO: Parse as full type?
|
||||
return registry.Declaration{
|
||||
.name = name,
|
||||
.decl_type = .{.Alias = alias},
|
||||
};
|
||||
} else {
|
||||
return registry.Declaration{
|
||||
.name = name,
|
||||
.decl_type = .{.Opaque = {}},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn parseEnums(allocator: *Allocator, out: []registry.Declaration, root: *xml.Element) !usize {
|
||||
var i: usize = 0;
|
||||
var it = root.findChildrenByTag("enums");
|
||||
|
||||
Reference in New Issue
Block a user