feat(ffi-linkage): extern/export parser+AST plumbing, unconsumed (Phase 0.1)
Add ast.ExternExportModifier { none, extern_, export_ } beside
CallingConvention; FnDecl.extern_export and VarDecl.is_extern/extern_name
fields (all defaulting to absent); and Parser.parseOptionalExternExport()
mirroring parseOptionalCallConv.
None of this is consumed by a decl path yet — no user-facing behavior
change, corpus diff empty. Two inline parser unit tests pin the helper's
keyword mapping and the field defaults. Phase 1.0 wires the helper into
the fn-decl path. lock commit.
This commit is contained in:
19
src/ast.zig
19
src/ast.zig
@@ -123,6 +123,14 @@ pub const Root = struct {
|
||||
|
||||
pub const CallingConvention = enum { default, c };
|
||||
|
||||
/// Linkage modifier written in the postfix slot after `callconv(...)`:
|
||||
/// `name :: (sig) -> Ret [callconv(.x)] [extern | export] [;|{…}];`
|
||||
/// `extern` = import (external linkage, C ABI, no sx ctx — `#foreign`'s role);
|
||||
/// `export` = define + expose (body + external linkage + C ABI + no ctx).
|
||||
/// Both imply `callconv(.c)`. Variants carry a trailing `_` to dodge the Zig
|
||||
/// keywords. `.none` = no linkage modifier (the ordinary sx-internal decl).
|
||||
pub const ExternExportModifier = enum { none, extern_, export_ };
|
||||
|
||||
pub const FnDecl = struct {
|
||||
name: []const u8,
|
||||
params: []const Param,
|
||||
@@ -131,6 +139,10 @@ pub const FnDecl = struct {
|
||||
type_params: []const StructTypeParam = &.{},
|
||||
is_arrow: bool = false,
|
||||
call_conv: CallingConvention = .default,
|
||||
/// Postfix linkage modifier (`extern`/`export`) written after the
|
||||
/// `callconv(...)` slot. `.none` for an ordinary sx-internal function.
|
||||
/// Parsed in Phase 0.1; not consumed by the fn-decl path until Phase 1.
|
||||
extern_export: ExternExportModifier = .none,
|
||||
/// Span of the function's name token, for the reserved-type-name decl
|
||||
/// diagnostic. Synthesized decls (e.g. `#import c` foreign
|
||||
/// functions, lowering-time objc/protocol method synthesis) leave it zero.
|
||||
@@ -343,6 +355,13 @@ pub const VarDecl = struct {
|
||||
is_foreign: bool = false,
|
||||
foreign_lib: ?[]const u8 = null,
|
||||
foreign_name: ?[]const u8 = null,
|
||||
/// `extern`-global form `g : T extern ["csym"];` — a reference to a global
|
||||
/// defined elsewhere (external linkage, resolved at link time). The new
|
||||
/// extern-named surface; distinct from the legacy `#foreign` path above.
|
||||
/// `extern_name` is the optional symbol-name override. Parsed in Phase 0.1;
|
||||
/// not consumed by the var-decl path until Phase 1.2.
|
||||
is_extern: bool = false,
|
||||
extern_name: ?[]const u8 = null,
|
||||
/// True when the binding name was written as a backtick raw identifier
|
||||
/// (`` `i2 := … ``). A raw name is exempt from the reserved-type-name
|
||||
/// binding check.
|
||||
|
||||
Reference in New Issue
Block a user