forked from mirror/vulkan-zig
Basic basetype parsing
This commit is contained in:
@@ -32,10 +32,11 @@ pub const TypeInfo = union(enum) {
|
|||||||
Handle: Handle,
|
Handle: Handle,
|
||||||
FnPtr: Command,
|
FnPtr: Command,
|
||||||
Command: Command,
|
Command: Command,
|
||||||
Alias: []const u8,
|
Alias: []const u8, // Alias of another declaration
|
||||||
Pointer: Pointer,
|
Pointer: Pointer,
|
||||||
Array: Array,
|
Array: Array,
|
||||||
Opaque: void,
|
Opaque: void,
|
||||||
|
Foreign: Foreign
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Container = struct {
|
pub const Container = struct {
|
||||||
@@ -108,3 +109,7 @@ pub const Array = struct {
|
|||||||
size: ArraySize,
|
size: ArraySize,
|
||||||
child: *TypeInfo,
|
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 i: usize = 0;
|
||||||
var it = types_elem.findChildrenByTag("type");
|
var it = types_elem.findChildrenByTag("type");
|
||||||
while (it.next()) |ty| {
|
while (it.next()) |ty| {
|
||||||
// TODO: Handle foreign types
|
out[i] = blk: {
|
||||||
const category = ty.getAttribute("category") orelse continue;
|
const category = ty.getAttribute("category") orelse {
|
||||||
|
break :blk try parseForeigntype(ty);
|
||||||
|
};
|
||||||
|
|
||||||
// Enums are handled later, in parseEnums. This also has the effect of filtering
|
// 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 any enums which have no elements, and should be unused by other parts of the API.
|
||||||
out[i] = if (mem.eql(u8, category, "bitmask"))
|
if (mem.eql(u8, category, "bitmask")) {
|
||||||
try parseBitmaskType(ty)
|
break :blk try parseBitmaskType(ty);
|
||||||
else if (mem.eql(u8, category, "handle"))
|
} else if (mem.eql(u8, category, "handle")) {
|
||||||
try parseHandleType(ty)
|
break :blk try parseHandleType(ty);
|
||||||
else
|
} else if (mem.eql(u8, category, "basetype")) {
|
||||||
|
break :blk try parseBaseType(ty);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
@@ -71,6 +77,19 @@ fn parseTypes(allocator: *Allocator, out: []registry.Declaration, types_elem: *x
|
|||||||
return i;
|
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 {
|
fn parseBitmaskType(ty: *xml.Element) !registry.Declaration {
|
||||||
if (ty.getAttribute("name")) |name| {
|
if (ty.getAttribute("name")) |name| {
|
||||||
const alias = ty.getAttribute("alias") orelse return error.InvalidRegistry;
|
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 {
|
fn parseEnums(allocator: *Allocator, out: []registry.Declaration, root: *xml.Element) !usize {
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
var it = root.findChildrenByTag("enums");
|
var it = root.findChildrenByTag("enums");
|
||||||
|
|||||||
Reference in New Issue
Block a user