refactor(ffi-linkage): Phase 9.2c — rename extern-ref validators → Extern (linkage)
checkForeignRefs→checkExternRefs, validateForeignRefs→validateExternRefs, collectForeignRefTargets→collectExternRefTargets — these police 'extern LIB' library references (linkage axis), so Extern not Runtime. Snapshot-neutral; suite green.
This commit is contained in:
@@ -311,7 +311,7 @@ pub fn processCImport(
|
|||||||
|
|
||||||
// ── #foreign ref validation ───────────────────────────────────────────
|
// ── #foreign ref validation ───────────────────────────────────────────
|
||||||
|
|
||||||
fn collectForeignRefTargets(valid: *std.StringHashMap(void), decls: []const *Node) !void {
|
fn collectExternRefTargets(valid: *std.StringHashMap(void), decls: []const *Node) !void {
|
||||||
for (decls) |d| {
|
for (decls) |d| {
|
||||||
switch (d.data) {
|
switch (d.data) {
|
||||||
.library_decl => |ld| try valid.put(ld.name, {}),
|
.library_decl => |ld| try valid.put(ld.name, {}),
|
||||||
@@ -324,14 +324,14 @@ fn collectForeignRefTargets(valid: *std.StringHashMap(void), decls: []const *Nod
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try collectForeignRefTargets(valid, ns.decls);
|
try collectExternRefTargets(valid, ns.decls);
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkForeignRefs(valid: *const std.StringHashMap(void), decls: []const *Node, diags: *@import("errors.zig").DiagnosticList) void {
|
fn checkExternRefs(valid: *const std.StringHashMap(void), decls: []const *Node, diags: *@import("errors.zig").DiagnosticList) void {
|
||||||
for (decls) |d| {
|
for (decls) |d| {
|
||||||
switch (d.data) {
|
switch (d.data) {
|
||||||
.fn_decl => |fd| {
|
.fn_decl => |fd| {
|
||||||
@@ -343,7 +343,7 @@ fn checkForeignRefs(valid: *const std.StringHashMap(void), decls: []const *Node,
|
|||||||
diags.addFmt(.err, d.span, "extern library '{s}' is not declared; expected a #library constant or a named '#import c' unit", .{ref});
|
diags.addFmt(.err, d.span, "extern library '{s}' is not declared; expected a #library constant or a named '#import c' unit", .{ref});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.namespace_decl => |ns| checkForeignRefs(valid, ns.decls, diags),
|
.namespace_decl => |ns| checkExternRefs(valid, ns.decls, diags),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,12 +355,12 @@ fn checkForeignRefs(valid: *const std.StringHashMap(void), decls: []const *Node,
|
|||||||
/// namespaced into one tree, so existence is checked program-wide.
|
/// namespaced into one tree, so existence is checked program-wide.
|
||||||
/// Decls synthesized from `#include` headers carry no ref and are
|
/// Decls synthesized from `#include` headers carry no ref and are
|
||||||
/// exempt.
|
/// exempt.
|
||||||
pub fn validateForeignRefs(allocator: std.mem.Allocator, root: *const Node, diags: *@import("errors.zig").DiagnosticList) !void {
|
pub fn validateExternRefs(allocator: std.mem.Allocator, root: *const Node, diags: *@import("errors.zig").DiagnosticList) !void {
|
||||||
if (root.data != .root) return;
|
if (root.data != .root) return;
|
||||||
var valid = std.StringHashMap(void).init(allocator);
|
var valid = std.StringHashMap(void).init(allocator);
|
||||||
defer valid.deinit();
|
defer valid.deinit();
|
||||||
try collectForeignRefTargets(&valid, root.data.root.decls);
|
try collectExternRefTargets(&valid, root.data.root.decls);
|
||||||
checkForeignRefs(&valid, root.data.root.decls, diags);
|
checkExternRefs(&valid, root.data.root.decls, diags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A cached entry must at least LOOK like an object file (Mach-O,
|
/// A cached entry must at least LOOK like an object file (Mach-O,
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ pub const Compilation = struct {
|
|||||||
// Every `#foreign <ref>` must name a #library constant or a named
|
// Every `#foreign <ref>` must name a #library constant or a named
|
||||||
// `#import c` unit — a typo'd ref otherwise resolves silently
|
// `#import c` unit — a typo'd ref otherwise resolves silently
|
||||||
// through whatever image happens to carry the symbol.
|
// through whatever image happens to carry the symbol.
|
||||||
try c_import.validateForeignRefs(self.allocator, root, &self.diagnostics);
|
try c_import.validateExternRefs(self.allocator, root, &self.diagnostics);
|
||||||
if (self.diagnostics.hasErrors()) return error.CompileError;
|
if (self.diagnostics.hasErrors()) return error.CompileError;
|
||||||
|
|
||||||
var module = ir.Module.init(self.allocator);
|
var module = ir.Module.init(self.allocator);
|
||||||
|
|||||||
Reference in New Issue
Block a user