Split out TypeInfo to TypeInfo and DeclarationType

This commit is contained in:
Robin Voetter
2020-06-15 01:56:39 +02:00
parent e6884a4622
commit b113aad195
4 changed files with 54 additions and 44 deletions

View File

@@ -229,7 +229,7 @@ pub fn parseTypedef(allocator: *Allocator, xctok: *XmlCTokenizer) !registry.Decl
return registry.Declaration{
.name = decl.name orelse return error.MissingTypeIdentifier,
.decl_type = decl.decl_type,
.decl_type = .{.typedef = decl.decl_type},
};
}
@@ -268,7 +268,7 @@ pub fn parseParamOrProto(allocator: *Allocator, xctok: *XmlCTokenizer) !registry
}
return registry.Declaration{
.name = decl.name orelse return error.MissingTypeIdentifier,
.decl_type = decl.decl_type,
.decl_type = .{.typedef = decl.decl_type},
};
}
@@ -307,7 +307,7 @@ fn parseDeclaration(allocator: *Allocator, xctok: *XmlCTokenizer) ParseError!Dec
if (tok.id != .type_name and tok.id != .id) return error.InvalidSyntax;
const type_name = tok.text;
var type_info = TypeInfo{.alias = type_name};
var type_info = TypeInfo{.name = type_name};
// Parse pointers
type_info = try parsePointers(allocator, xctok, inner_is_const, type_info);
@@ -366,32 +366,24 @@ fn parseFnPtrSuffix(allocator: *Allocator, xctok: *XmlCTokenizer, return_type: T
_ = try xctok.expect(.rparen);
_ = try xctok.expect(.lparen);
const command = try allocator.create(registry.TypeInfo);
command.* = .{
.command = .{
.params = &[_]registry.Command.Param{},
.return_type = try allocator.create(TypeInfo),
.success_codes = &[_][]const u8{},
.error_codes = &[_][]const u8{},
}
};
const return_type_heap = try allocator.create(TypeInfo);
return_type_heap.* = return_type;
command.command.return_type.* = return_type;
const command_ptr = Declaration{
var command_ptr = Declaration{
.name = name.text,
.decl_type = .{
.pointer = .{
.is_const = true,
.is_optional = false,
.size = .one,
.child = command,
.command_ptr = .{
.params = &[_]registry.Command.Param{},
.return_type = return_type_heap,
.success_codes = &[_][]const u8{},
.error_codes = &[_][]const u8{},
}
},
}
};
const first_param = try parseDeclaration(allocator, xctok);
if (first_param.name == null) {
if (first_param.decl_type != .alias or !mem.eql(u8, first_param.decl_type.alias, "void")) {
if (first_param.decl_type != .name or !mem.eql(u8, first_param.decl_type.name, "void")) {
return error.InvalidSyntax;
}
@@ -423,7 +415,7 @@ fn parseFnPtrSuffix(allocator: *Allocator, xctok: *XmlCTokenizer, return_type: T
}
_ = try xctok.nextNoEof();
command.command.params = params.toOwnedSlice();
command_ptr.decl_type.command_ptr.params = params.toOwnedSlice();
return command_ptr;
}

View File

@@ -103,7 +103,7 @@ fn parseBitmaskType(ty: *xml.Element) !registry.Declaration {
const alias = ty.getAttribute("alias") orelse return error.InvalidRegistry;
return registry.Declaration{
.name = name,
.decl_type = .{.alias = alias},
.decl_type = .{.alias = .{.name = alias, .target = .other_type}},
};
} else {
return registry.Declaration{
@@ -119,7 +119,7 @@ fn parseHandleType(ty: *xml.Element) !registry.Declaration {
const alias = ty.getAttribute("alias") orelse return error.InvalidRegistry;
return registry.Declaration{
.name = name,
.decl_type = .{.alias = alias},
.decl_type = .{.alias = .{.name = alias, .target = .other_type}},
};
} else {
const name = ty.getCharData("name") orelse return error.InvalidRegistry;
@@ -151,7 +151,7 @@ fn parseBaseType(allocator: *Allocator, ty: *xml.Element) !registry.Declaration
// macros, which is why this part is not built into the xml/c parser.
return registry.Declaration{
.name = name,
.decl_type = .{.opaque = {}},
.decl_type = .{.typedef = .{.opaque = {}}},
};
}
}
@@ -162,7 +162,7 @@ fn parseContainer(allocator: *Allocator, ty: *xml.Element, is_union: bool) !regi
if (ty.getAttribute("alias")) |alias| {
return registry.Declaration{
.name = name,
.decl_type = .{.alias = alias},
.decl_type = .{.alias = .{.name = alias, .target = .other_type}},
};
}
@@ -345,7 +345,7 @@ fn parseCommand(allocator: *Allocator, elem: *xml.Element) !registry.Declaration
const name = elem.getAttribute("name") orelse return error.InvalidRegistry;
return registry.Declaration{
.name = name,
.decl_type = .{.alias = alias}
.decl_type = .{.alias = .{.name = alias, .target = .other_command}}
};
}
@@ -360,13 +360,13 @@ fn parseCommand(allocator: *Allocator, elem: *xml.Element) !registry.Declaration
while (it.next()) |param| {
var xctok = xmlc.XmlCTokenizer.init(param);
const decl = try xmlc.parseParamOrProto(allocator, &xctok);
params[i] = .{.name = decl.name, .param_type = decl.decl_type};
params[i] = .{.name = decl.name, .param_type = decl.decl_type.typedef};
try parsePointerMeta(&params[i].param_type, param);
i += 1;
}
const return_type = try allocator.create(registry.TypeInfo);
return_type.* = command_decl.decl_type;
return_type.* = command_decl.decl_type.typedef;
const success_codes = if (elem.getAttribute("successcodes")) |codes|
try splitCommaAlloc(allocator, codes)