refactor(ffi-linkage): Phase 9.2b-fix — use is_extern (not new is_reference) for the runtime-class ref flag
Per user feedback: don't introduce new terminology. The RuntimeClassDecl reference-vs-define flag (set by the postfix 'extern' modifier, == old prefix '#foreign #objc_class') is named is_extern, matching the keyword that drives it and the existing is_extern on VarDecl/IR. Renamed is_reference→is_extern, is_reference_eff→is_extern_eff; updated the field comment. Snapshot-neutral; green.
This commit is contained in:
@@ -263,10 +263,10 @@ pub const Parser = struct {
|
||||
// removed — reference an existing class via the postfix `extern` modifier
|
||||
// (`X :: #objc_class("…") extern { … }`) instead. `prefix_loc` pins the
|
||||
// diagnostic to the `#foreign` token (already consumed by the lookahead).
|
||||
if (prefix.is_reference) {
|
||||
if (prefix.is_extern) {
|
||||
return self.failAt(prefix_loc, "`#foreign` has been removed; use the postfix `extern` (import) / `export` (define) linkage keyword instead");
|
||||
}
|
||||
return self.parseRuntimeClassDecl(name, start_pos, prefix.runtime, prefix.is_reference, prefix.is_main, name_is_raw);
|
||||
return self.parseRuntimeClassDecl(name, start_pos, prefix.runtime, prefix.is_extern, prefix.is_main, name_is_raw);
|
||||
}
|
||||
|
||||
// C-style union declaration
|
||||
@@ -1295,7 +1295,7 @@ pub const Parser = struct {
|
||||
|
||||
const RuntimeClassPrefix = struct {
|
||||
runtime: ast.RuntimeKind,
|
||||
is_reference: bool,
|
||||
is_extern: bool,
|
||||
is_main: bool,
|
||||
};
|
||||
|
||||
@@ -1308,13 +1308,13 @@ pub const Parser = struct {
|
||||
fn tryParseRuntimeClassPrefix(self: *Parser) ?RuntimeClassPrefix {
|
||||
// Peek ahead through modifier tokens to confirm a directive follows.
|
||||
var lookahead_idx: usize = 0;
|
||||
var is_reference = false;
|
||||
var is_extern = false;
|
||||
var is_main = false;
|
||||
while (true) {
|
||||
const tag = self.peekTag(lookahead_idx);
|
||||
switch (tag) {
|
||||
.hash_foreign => {
|
||||
is_reference = true;
|
||||
is_extern = true;
|
||||
lookahead_idx += 1;
|
||||
},
|
||||
.hash_jni_main => {
|
||||
@@ -1328,7 +1328,7 @@ pub const Parser = struct {
|
||||
// Commit: consume modifier tokens.
|
||||
var i: usize = 0;
|
||||
while (i < lookahead_idx) : (i += 1) self.advance();
|
||||
return .{ .runtime = runtime, .is_reference = is_reference, .is_main = is_main };
|
||||
return .{ .runtime = runtime, .is_extern = is_extern, .is_main = is_main };
|
||||
}
|
||||
|
||||
fn peekTag(self: *Parser, offset: usize) Tag {
|
||||
@@ -1363,7 +1363,7 @@ pub const Parser = struct {
|
||||
};
|
||||
}
|
||||
|
||||
fn parseRuntimeClassDecl(self: *Parser, name: []const u8, start_pos: u32, runtime: ast.RuntimeKind, is_reference: bool, is_main: bool, name_is_raw: bool) anyerror!*Node {
|
||||
fn parseRuntimeClassDecl(self: *Parser, name: []const u8, start_pos: u32, runtime: ast.RuntimeKind, is_extern: bool, is_main: bool, name_is_raw: bool) anyerror!*Node {
|
||||
self.advance(); // skip directive token
|
||||
|
||||
try self.expect(.l_paren);
|
||||
@@ -1380,20 +1380,20 @@ pub const Parser = struct {
|
||||
// `#foreign` modifier (mirrors `struct #compiler` postfix placement).
|
||||
// `… extern { … }` ⇒ reference an existing runtime class (== `#foreign`).
|
||||
// `… export { … }` ⇒ define + register a new sx class (== no `#foreign`).
|
||||
// Maps straight onto the existing `is_reference` decision so lowering is
|
||||
// Maps straight onto the existing `is_extern` decision so lowering is
|
||||
// unchanged. The legacy prefix `#foreign` form still works via the
|
||||
// `is_reference` argument; interplay/diagnostics for combining them is Phase 4.
|
||||
var is_reference_eff = is_reference;
|
||||
// `is_extern` argument; interplay/diagnostics for combining them is Phase 4.
|
||||
var is_extern_eff = is_extern;
|
||||
if (self.current.tag == .kw_extern or self.current.tag == .kw_export) {
|
||||
// Prefix `#foreign` and the postfix `extern`/`export` keyword are two
|
||||
// spellings of the same linkage axis — combining them is contradictory
|
||||
// (`#foreign`=import vs `export`=define) or redundant (`#foreign … extern`).
|
||||
// Reject at the postfix keyword rather than let it silently override.
|
||||
if (is_reference) {
|
||||
if (is_extern) {
|
||||
const kw = if (self.current.tag == .kw_export) "export" else "extern";
|
||||
return self.failFmt("conflicting linkage: prefix '#foreign' cannot be combined with postfix '{s}'; use either '#foreign' or postfix 'extern'/'export', not both", .{kw});
|
||||
}
|
||||
is_reference_eff = self.current.tag == .kw_extern;
|
||||
is_extern_eff = self.current.tag == .kw_extern;
|
||||
self.advance();
|
||||
}
|
||||
|
||||
@@ -1624,7 +1624,7 @@ pub const Parser = struct {
|
||||
.foreign_path = foreign_path,
|
||||
.runtime = runtime,
|
||||
.members = try members.toOwnedSlice(self.allocator),
|
||||
.is_reference = is_reference_eff,
|
||||
.is_extern = is_extern_eff,
|
||||
.is_main = is_main,
|
||||
.is_raw = name_is_raw,
|
||||
} });
|
||||
|
||||
Reference in New Issue
Block a user