moved decls to patterns
This commit is contained in:
parent
aaa8ffba47
commit
41b11099be
|
|
@ -462,80 +462,7 @@ fn writeDebugFile(allocator: std.mem.Allocator, header_path: []const u8, output:
|
|||
|
||||
fn freeDeclDeep(allocator: std.mem.Allocator, decl: patterns.Declaration) void {
|
||||
switch (decl) {
|
||||
.opaque_type => |o| {
|
||||
allocator.free(o.name);
|
||||
if (o.doc_comment) |doc| allocator.free(doc);
|
||||
},
|
||||
.typedef_decl => |t| {
|
||||
allocator.free(t.name);
|
||||
allocator.free(t.underlying_type);
|
||||
if (t.doc_comment) |doc| allocator.free(doc);
|
||||
},
|
||||
.function_pointer_decl => |fp| {
|
||||
allocator.free(fp.name);
|
||||
allocator.free(fp.return_type);
|
||||
if (fp.doc_comment) |doc| allocator.free(doc);
|
||||
for (fp.params) |param| {
|
||||
allocator.free(param.name);
|
||||
allocator.free(param.type_name);
|
||||
}
|
||||
allocator.free(fp.params);
|
||||
},
|
||||
.c_type_alias => |a| {
|
||||
allocator.free(a.name);
|
||||
if (a.doc_comment) |doc| allocator.free(doc);
|
||||
},
|
||||
.enum_decl => |e| {
|
||||
allocator.free(e.name);
|
||||
if (e.doc_comment) |doc| allocator.free(doc);
|
||||
for (e.values) |val| {
|
||||
allocator.free(val.name);
|
||||
if (val.value) |v| allocator.free(v);
|
||||
if (val.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(e.values);
|
||||
},
|
||||
.struct_decl => |s| {
|
||||
allocator.free(s.name);
|
||||
if (s.doc_comment) |doc| allocator.free(doc);
|
||||
for (s.fields) |field| {
|
||||
allocator.free(field.name);
|
||||
allocator.free(field.type_name);
|
||||
if (field.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(s.fields);
|
||||
},
|
||||
.union_decl => |u| {
|
||||
allocator.free(u.name);
|
||||
if (u.doc_comment) |doc| allocator.free(doc);
|
||||
for (u.fields) |field| {
|
||||
allocator.free(field.name);
|
||||
allocator.free(field.type_name);
|
||||
if (field.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(u.fields);
|
||||
},
|
||||
.flag_decl => |f| {
|
||||
allocator.free(f.name);
|
||||
allocator.free(f.underlying_type);
|
||||
if (f.doc_comment) |doc| allocator.free(doc);
|
||||
for (f.flags) |flag| {
|
||||
allocator.free(flag.name);
|
||||
allocator.free(flag.value);
|
||||
if (flag.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(f.flags);
|
||||
},
|
||||
.function_decl => |func| {
|
||||
allocator.free(func.name);
|
||||
allocator.free(func.return_type);
|
||||
if (func.doc_comment) |doc| allocator.free(doc);
|
||||
for (func.params) |param| {
|
||||
allocator.free(param.name);
|
||||
allocator.free(param.type_name);
|
||||
}
|
||||
allocator.free(func.params);
|
||||
},
|
||||
inline else => |*d| d.deinit(allocator),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,12 +27,28 @@ pub const Declaration = union(enum) {
|
|||
pub const OpaqueType = struct {
|
||||
name: []const u8, // SDL_GPUDevice
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: OpaqueType, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
}
|
||||
};
|
||||
|
||||
pub const EnumDecl = struct {
|
||||
name: []const u8, // SDL_GPUPrimitiveType
|
||||
values: []EnumValue,
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: EnumDecl, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
for (self.values) |val| {
|
||||
allocator.free(val.name);
|
||||
if (val.value) |v| allocator.free(v);
|
||||
if (val.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(self.values);
|
||||
}
|
||||
};
|
||||
|
||||
pub const EnumValue = struct {
|
||||
|
|
@ -46,12 +62,34 @@ pub const StructDecl = struct {
|
|||
fields: []FieldDecl,
|
||||
doc_comment: ?[]const u8,
|
||||
has_unions: bool = false, // If true, codegen should emit as opaque (C unions can't be represented in other languages)
|
||||
|
||||
pub fn deinit(self: StructDecl, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
for (self.fields) |field| {
|
||||
allocator.free(field.name);
|
||||
allocator.free(field.type_name);
|
||||
if (field.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(self.fields);
|
||||
}
|
||||
};
|
||||
|
||||
pub const UnionDecl = struct {
|
||||
name: []const u8, // SDL_Event
|
||||
fields: []FieldDecl,
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: UnionDecl, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
for (self.fields) |field| {
|
||||
allocator.free(field.name);
|
||||
allocator.free(field.type_name);
|
||||
if (field.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(self.fields);
|
||||
}
|
||||
};
|
||||
|
||||
pub const FieldDecl = struct {
|
||||
|
|
@ -65,6 +103,18 @@ pub const FlagDecl = struct {
|
|||
underlying_type: []const u8, // Uint32
|
||||
flags: []FlagValue,
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: FlagDecl, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
allocator.free(self.underlying_type);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
for (self.flags) |flag| {
|
||||
allocator.free(flag.name);
|
||||
allocator.free(flag.value);
|
||||
if (flag.comment) |c| allocator.free(c);
|
||||
}
|
||||
allocator.free(self.flags);
|
||||
}
|
||||
};
|
||||
|
||||
pub const FlagValue = struct {
|
||||
|
|
@ -77,6 +127,12 @@ pub const TypedefDecl = struct {
|
|||
name: []const u8, // SDL_PropertiesID
|
||||
underlying_type: []const u8, // Uint32
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: TypedefDecl, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
allocator.free(self.underlying_type);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
}
|
||||
};
|
||||
|
||||
pub const FunctionPointerDecl = struct {
|
||||
|
|
@ -84,6 +140,17 @@ pub const FunctionPointerDecl = struct {
|
|||
return_type: []const u8, // Uint32
|
||||
params: []ParamDecl,
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: FunctionPointerDecl, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
allocator.free(self.return_type);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
for (self.params) |param| {
|
||||
allocator.free(param.name);
|
||||
allocator.free(param.type_name);
|
||||
}
|
||||
allocator.free(self.params);
|
||||
}
|
||||
};
|
||||
|
||||
/// C type alias - for function pointer typedefs that should alias to C type directly
|
||||
|
|
@ -91,6 +158,11 @@ pub const FunctionPointerDecl = struct {
|
|||
pub const CTypeAlias = struct {
|
||||
name: []const u8, // SDL_HitTest
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: CTypeAlias, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
}
|
||||
};
|
||||
|
||||
pub const FunctionDecl = struct {
|
||||
|
|
@ -98,6 +170,17 @@ pub const FunctionDecl = struct {
|
|||
return_type: []const u8, // SDL_GPUDevice *
|
||||
params: []ParamDecl,
|
||||
doc_comment: ?[]const u8,
|
||||
|
||||
pub fn deinit(self: FunctionDecl, allocator: Allocator) void {
|
||||
allocator.free(self.name);
|
||||
allocator.free(self.return_type);
|
||||
if (self.doc_comment) |doc| allocator.free(doc);
|
||||
for (self.params) |param| {
|
||||
allocator.free(param.name);
|
||||
allocator.free(param.type_name);
|
||||
}
|
||||
allocator.free(self.params);
|
||||
}
|
||||
};
|
||||
|
||||
pub const ParamDecl = struct {
|
||||
|
|
|
|||
Loading…
Reference in New Issue