Stop fixing up tags.

This seems to not be needed anymore.
This commit is contained in:
Robin Voetter
2021-04-08 12:48:35 +02:00
parent 272c1160eb
commit fb5ca7cf90

View File

@@ -105,128 +105,6 @@ const EnumFieldMerger = struct {
} }
}; };
const TagFixerUpper = struct {
allocator: *Allocator,
registry: *reg.Registry,
names: std.StringHashMap(void),
id_renderer: *const IdRenderer,
fn init(allocator: *Allocator, registry: *reg.Registry, id_renderer: *const IdRenderer) TagFixerUpper {
return .{
.allocator = allocator,
.registry = registry,
.names = std.StringHashMap(void).init(allocator),
.id_renderer = id_renderer,
};
}
fn deinit(self: *TagFixerUpper) void {
self.names.deinit();
}
fn insertName(self: *TagFixerUpper, name: []const u8) !void {
const tagless = self.id_renderer.stripAuthorTag(name);
const result = try self.names.getOrPut(name);
if (result.found_existing) {
return error.DuplicateDefinition;
}
}
fn extractNames(self: *TagFixerUpper) !void {
for (self.registry.decls) |decl| {
try self.insertName(decl.name);
switch (decl.decl_type) {
.enumeration => |enumeration| {
for (enumeration.fields) |field| {
try self.insertName(field.name);
}
},
else => {},
}
}
}
fn fixAlias(self: *TagFixerUpper, name: *[]const u8) !void {
if (self.names.contains(name.*)) {
// The alias exists, everything is fine
return;
}
// The alias does not exist, check if the tagless version exists
const tagless = self.id_renderer.stripAuthorTag(name.*);
if (self.names.contains(tagless)) {
// Fix up the name to the tagless version
name.* = tagless;
return;
}
// Neither original nor tagless version exists
return error.InvalidRegistry;
}
fn fixCommand(self: *TagFixerUpper, command: *reg.Command) !void {
for (command.params) |*param| {
try self.fixTypeInfo(&param.param_type);
}
try self.fixTypeInfo(command.return_type);
for (command.success_codes) |*code| {
try self.fixAlias(code);
}
for (command.error_codes) |*code| {
try self.fixAlias(code);
}
}
fn fixTypeInfo(self: *TagFixerUpper, type_info: *reg.TypeInfo) error{InvalidRegistry}!void {
switch (type_info.*) {
.name => |*name| try self.fixAlias(name),
.command_ptr => |*command| try self.fixCommand(command),
.pointer => |ptr| try self.fixTypeInfo(ptr.child),
.array => |arr| try self.fixTypeInfo(arr.child),
}
}
fn fixNames(self: *TagFixerUpper) !void {
for (self.registry.decls) |*decl| {
switch (decl.decl_type) {
.container => |*container| {
for (container.fields) |*field| {
try self.fixTypeInfo(&field.field_type);
}
},
.enumeration => |*enumeration| {
for (enumeration.fields) |*field| {
if (field.value == .alias) {
try self.fixAlias(&field.value.alias.name);
}
}
},
.bitmask => |*bitmask| {
if (bitmask.bits_enum) |*bits| {
try self.fixAlias(bits);
}
},
.command => |*command| try self.fixCommand(command),
.alias => |*alias| try self.fixAlias(&alias.name),
.typedef => |*type_info| try self.fixTypeInfo(type_info),
else => {},
}
}
}
fn fixup(self: *TagFixerUpper) !void {
// Extract all non-aliases
try self.extractNames();
// Fix aliases
try self.fixNames();
}
};
pub const Generator = struct { pub const Generator = struct {
gpa: *Allocator, gpa: *Allocator,
reg_arena: std.heap.ArenaAllocator, reg_arena: std.heap.ArenaAllocator,
@@ -321,6 +199,5 @@ pub fn generate(allocator: *Allocator, spec_xml: []const u8, writer: anytype) !v
try gen.mergeEnumFields(); try gen.mergeEnumFields();
try gen.fixupBitmasks(); try gen.fixupBitmasks();
try gen.fixupTags();
try gen.render(writer); try gen.render(writer);
} }