This commit is contained in:
agra
2026-03-06 10:46:28 +02:00
parent f9dda972d2
commit 69934592d8
8 changed files with 113 additions and 14 deletions

View File

@@ -382,21 +382,28 @@ pub fn writeCObjectFiles(
}
/// Walk the resolved AST and collect CImportInfo from all c_import_decl nodes.
/// Deduplicates by source pointer identity (shared nodes from import propagation).
pub fn collectCImportSources(allocator: std.mem.Allocator, root: *const Node) ![]CImportInfo {
if (root.data != .root) return &.{};
var infos = std.ArrayList(CImportInfo).empty;
var seen = std.AutoHashMap([*]const []const u8, void).init(allocator);
defer seen.deinit();
for (root.data.root.decls) |decl| {
switch (decl.data) {
.c_import_decl => |ci| {
if (ci.sources.len > 0) {
try infos.append(allocator, .{
.sources = ci.sources,
.includes = ci.includes,
.defines = ci.defines,
.flags = ci.flags,
});
const key = ci.sources.ptr;
if (!seen.contains(key)) {
try seen.put(key, {});
try infos.append(allocator, .{
.sources = ci.sources,
.includes = ci.includes,
.defines = ci.defines,
.flags = ci.flags,
});
}
}
},
.namespace_decl => |ns| {
@@ -404,12 +411,16 @@ pub fn collectCImportSources(allocator: std.mem.Allocator, root: *const Node) ![
if (nd.data == .c_import_decl) {
const nci = nd.data.c_import_decl;
if (nci.sources.len > 0) {
try infos.append(allocator, .{
.sources = nci.sources,
.includes = nci.includes,
.defines = nci.defines,
.flags = nci.flags,
});
const key = nci.sources.ptr;
if (!seen.contains(key)) {
try seen.put(key, {});
try infos.append(allocator, .{
.sources = nci.sources,
.includes = nci.includes,
.defines = nci.defines,
.flags = nci.flags,
});
}
}
}
}