49 lines
1.8 KiB
Zig
49 lines
1.8 KiB
Zig
const std = @import("std");
|
|
const patterns = @import("src/patterns.zig");
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
const allocator = gpa.allocator();
|
|
|
|
const source = @embedFile("test_rect_simple.c");
|
|
|
|
var scanner = patterns.Scanner.init(allocator, source);
|
|
const decls = try scanner.scan();
|
|
defer {
|
|
for (decls) |decl| {
|
|
switch (decl) {
|
|
.struct_decl => |s| {
|
|
allocator.free(s.name);
|
|
if (s.doc_comment) |doc| allocator.free(doc);
|
|
for (s.fields) |field| {
|
|
std.debug.print("Field: {s}: {s}\n", .{field.name, field.type_name});
|
|
allocator.free(field.name);
|
|
allocator.free(field.type_name);
|
|
if (field.comment) |c| allocator.free(c);
|
|
}
|
|
allocator.free(s.fields);
|
|
},
|
|
.function_decl => |f| {
|
|
std.debug.print("Function: {s}\n", .{f.name});
|
|
for (f.params) |p| {
|
|
std.debug.print(" Param: {s}: {s}\n", .{p.name, p.type_name});
|
|
}
|
|
allocator.free(f.name);
|
|
allocator.free(f.return_type);
|
|
if (f.doc_comment) |doc| allocator.free(doc);
|
|
for (f.params) |p| {
|
|
allocator.free(p.name);
|
|
allocator.free(p.type_name);
|
|
}
|
|
allocator.free(f.params);
|
|
},
|
|
else => {},
|
|
}
|
|
}
|
|
allocator.free(decls);
|
|
}
|
|
|
|
std.debug.print("\nTotal declarations: {d}\n", .{decls.len});
|
|
}
|